diff options
Diffstat (limited to 'lisc')
-rw-r--r-- | lisc/test/cup.ssa | 5 | ||||
-rwxr-xr-x | lisc/test/go.sh | 96 |
2 files changed, 101 insertions, 0 deletions
diff --git a/lisc/test/cup.ssa b/lisc/test/cup.ssa index 3ffe198..96649e6 100644 --- a/lisc/test/cup.ssa +++ b/lisc/test/cup.ssa @@ -10,3 +10,8 @@ function $test() { @end ret } + +# >>> driver +# extern void test(); +# int main() { test(); return 0; } +# <<< diff --git a/lisc/test/go.sh b/lisc/test/go.sh new file mode 100755 index 0000000..b65f2d2 --- /dev/null +++ b/lisc/test/go.sh @@ -0,0 +1,96 @@ +#!/bin/sh + +QBE=./lisc +CC=cc + +TMP=/tmp/qbe.zzzz + +DRV=$TMP.c +ASM=$TMP.s +BIN=$TMP.bin +OUT=$TMP.out + +cleanup() { + rm -f $DRV $ASM $BIN $OUT +} + +extract() { + WHAT="$1" + FILE="$2" + + awk " + /^# >>> $WHAT/ { + p = 1 + next + } + /^# <<</ { + if (p) + p = 0 + } + p + " $FILE \ + | sed -e 's/# //' \ + | sed -e 's/#$//' +} + +once() { + T="$1" + + if ! test -f $T + then + echo "invalid test file $T" >&2 + exit 1 + fi + + printf "$T... " + + if ! $QBE $T -o $ASM 2> /dev/null + then + echo "[qbe fail]" + return 1 + fi + + extract driver $T > $DRV + extract output $T > $OUT + + if test -s $DRV + then + LNK="$DRV $ASM" + else + LNK="$ASM" + fi + + if ! $CC -o $BIN $LNK + then + echo "[cc fail]" + return 1 + fi + + echo "[ok]" +} + + +#trap cleanup TERM QUIT + +case $1 in + "all") + F=0 + for T in test/* + do + once $T + F=`expr $F + $?` + done + if test $F -ge 1 + then + echo + echo "$F test(s) failed!" + else + echo + echo "All is fine!" + fi + ;; + *) + once $1 + exit $? + ;; +esac |