aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/run.sh
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-11-16 12:11:18 +0100
committerlemon <lsof@mailbox.org>2025-11-16 12:11:18 +0100
commit111e71e1511b2abff9176bd6c714c8da796f770e (patch)
tree352b723c9144c844037447bd865a8366378df7a5 /test/run.sh
parentb0c0f2d2d885c5901de08ed08dba9fff079bf6e3 (diff)
basic automated testing
Diffstat (limited to 'test/run.sh')
-rwxr-xr-xtest/run.sh51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/run.sh b/test/run.sh
new file mode 100755
index 0000000..dd8f431
--- /dev/null
+++ b/test/run.sh
@@ -0,0 +1,51 @@
+#!/bin/env sh
+
+cd $(dirname "$0")
+ANTCC=../antcc
+ntest=0
+npass=0
+
+x() {
+ echo X $@>>log.txt
+ $@ 2>> log.txt
+}
+run() {
+ ntest=$(expr $ntest + 1)
+ f="$(basename "$1")"
+ expected=build/"$(echo "$f" | sed -s 's/\.c$/.expected/')"
+ echo ---- $f ---- >> log.txt
+ args=$(awk '/\/\* ARGS:.*$/ {ORS=" ";for (i=3;i<NF;++i)print $i;ORS="\n";print""}' "$f")
+ awk '/\/\* EXPECT:$/ {x=k=any=1} x && /\*\// {x=0} x {if (!k)print $0;k=0} END{if(x||!any)exit 1;}' "$f" > "$expected"
+ if [ $? == 0 ]; then
+ mkdir -p build/
+ obj=build/"$(echo "$f" | sed -s 's/\.c$/.o/')"
+ exe=build/"$(echo "$f" | sed -s 's/\.c$//')"
+ if ! ( x $ANTCC "$f" -c -o "$obj" && x $ANTCC "$obj" -o "$exe" ); then
+ echo !TEST ERROR $f
+ echo !FAILED TO COMPILE
+ echo '-------'
+ else
+ actual=build/"$(echo "$f" | sed -s 's/\.c$/.actual/')"
+ x "$exe" $args > "$actual"
+ if [ "$(md5sum < "$actual")" != "$(md5sum < "$expected")" ]; then
+ echo --- !TEST ERROR $f
+ diff --unified=0 --color=auto "$expected" "$actual"
+ echo '-------'
+ else
+ npass=$(expr $npass + 1)
+ fi
+ fi
+ else
+ echo --- !ignore $f
+ fi
+}
+
+< /dev/null > log.txt
+tests=$(find . -regex '\./[0-9]+-.*\.c' | sort)
+for test in $tests; do
+ run $test
+done
+
+echo TESTS PASSED: $npass/$ntest
+printf 'wc log.txt;'
+wc log.txt