diff options
-rwxr-xr-x | runtests.sh | 40 | ||||
-rw-r--r-- | tests/add.forth | 4 | ||||
-rw-r--r-- | tests/define-countdown.forth | 9 | ||||
-rw-r--r-- | tests/define-mult.forth | 6 | ||||
-rw-r--r-- | tests/simple-if.forth | 5 | ||||
-rw-r--r-- | tests/simple-if2.forth | 4 |
6 files changed, 68 insertions, 0 deletions
diff --git a/runtests.sh b/runtests.sh new file mode 100755 index 0000000..ddff74f --- /dev/null +++ b/runtests.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +if [ -z "$FORTH_CMD" ] ; then + FORTH_CMD="./forth" +fi + +n=0 +failed=0 + +runtest () { + file="$1" + + output="$(mktemp)" + expectedoutput="$(mktemp)" + sed '0,/^INPUT$/d;/^OUTPUT$/,$d' "$file" | "$FORTH_CMD" > "$output" &2> /dev/null + sed '0,/^OUTPUT$/d' "$file" > "$expectedoutput" + + diff="$(diff -w -y "$output" "$expectedoutput")" + + if [ "1" -eq "$?" ] ; then + echo "Test $n failed: $file" >&2 + echo "Diff:" >&2 + echo "$diff" + exitcode=1 + failed="$(expr "$failed" + 1)" + + fi +} + +for f in ./tests/*; do + n="$(expr "$n" + 1)" + runtest "$f" +done + +if [ "0" -eq "$failed" ]; then + echo "All $n tests passed" >&2 + exit 0 +else + echo "$failed/$n tests failed" >&2 +fi diff --git a/tests/add.forth b/tests/add.forth new file mode 100644 index 0000000..690bdba --- /dev/null +++ b/tests/add.forth @@ -0,0 +1,4 @@ +INPUT +1 3 + . +OUTPUT +4 diff --git a/tests/define-countdown.forth b/tests/define-countdown.forth new file mode 100644 index 0000000..539b229 --- /dev/null +++ b/tests/define-countdown.forth @@ -0,0 +1,9 @@ +INPUT +: countdown dup 0 = not if peek 1 - countdown then ; +5 countdown +OUTPUT +5 +4 +3 +2 +1 diff --git a/tests/define-mult.forth b/tests/define-mult.forth new file mode 100644 index 0000000..5b6f798 --- /dev/null +++ b/tests/define-mult.forth @@ -0,0 +1,6 @@ +INPUT +: multrec over if rot swap over + rot 1 - swap multrec then ; +: mult 0 multrec ; +6 8 mult . +OUTPUT +48 diff --git a/tests/simple-if.forth b/tests/simple-if.forth new file mode 100644 index 0000000..668ea0d --- /dev/null +++ b/tests/simple-if.forth @@ -0,0 +1,5 @@ +INPUT +1 1 = if 5 . then 8 . +OUTPUT +5 +8 diff --git a/tests/simple-if2.forth b/tests/simple-if2.forth new file mode 100644 index 0000000..92bbc6b --- /dev/null +++ b/tests/simple-if2.forth @@ -0,0 +1,4 @@ +INPUT +0 if 5 . then 8 . +OUTPUT +8 |