From cb738e17c9751fadc990fda75fa023a8fe9fd671 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 13 Jul 2024 12:34:33 +0100 Subject: add iota tests --- run_tests.sh | 11 +++++------ tests/iota_imp.bth | 4 ++++ tests/iota_imp.out | 1 + tests/iota_rec.bth | 7 +++++++ tests/iota_rec.out | 1 + 5 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 tests/iota_imp.bth create mode 100644 tests/iota_imp.out create mode 100644 tests/iota_rec.bth create mode 100644 tests/iota_rec.out diff --git a/run_tests.sh b/run_tests.sh index 18885da..16201b5 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -12,9 +12,8 @@ for testfile in tests/*.bth; do printf '\033[33mSKIP\033[0m %s (no output file)\n' "$testname" skip=$((skip + 1)) else - output="$(./bth $testfile 2>&1)" - run_res=$? - echo "$output" | diff $outfile - >/dev/null + output="$(./bth "$testfile" 2>&1)" + echo "$output" | diff "$outfile" - >/dev/null diff_res=$? case $diff_res in 0) printf '\033[32m\033[1mPASS\033[0m %s\n' "$testname" @@ -22,7 +21,7 @@ for testfile in tests/*.bth; do 1) printf '\033[31m\033[1mFAIL\033[0m %s\n' "$testname" printf "\tgot output: %s\n" "$(echo "$output" | head -n4)" printf "\texpected: " - cat $outfile + cat "$outfile" fail=$((fail + 1)) ;; esac fi @@ -31,10 +30,10 @@ done echo pnum () { - if [ $1 -eq 0 ]; then + if [ "$1" -eq 0 ]; then printf "0 %s; " "$2" else - printf "\033[3%dm%d\033[0m %s; " $3 $1 "$2" + printf "\033[3%dm%d\033[0m %s; " "$3" "$1" "$2" fi } diff --git a/tests/iota_imp.bth b/tests/iota_imp.bth new file mode 100644 index 0000000..cc62db9 --- /dev/null +++ b/tests/iota_imp.bth @@ -0,0 +1,4 @@ +(let (a []) + (for (i 10) + (append a i)) + (say a)) diff --git a/tests/iota_imp.out b/tests/iota_imp.out new file mode 100644 index 0000000..0f6e04d --- /dev/null +++ b/tests/iota_imp.out @@ -0,0 +1 @@ +[ 0 1 2 3 4 5 6 7 8 9 ] diff --git a/tests/iota_rec.bth b/tests/iota_rec.bth new file mode 100644 index 0000000..8e274a4 --- /dev/null +++ b/tests/iota_rec.bth @@ -0,0 +1,7 @@ +(defn (iota' arr i max) + (if (< i max) + (iota' (append arr i) (+ i 1) max) + arr)) +(set! _G_iota' iota') +(defn (iota n) (_G_iota' [] 0 n)) +(say (iota 10)) diff --git a/tests/iota_rec.out b/tests/iota_rec.out new file mode 100644 index 0000000..0f6e04d --- /dev/null +++ b/tests/iota_rec.out @@ -0,0 +1 @@ +[ 0 1 2 3 4 5 6 7 8 9 ] -- cgit v1.2.3