summary refs log tree commit diff
path: root/lisc
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-03-02 22:11:50 -0500
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-03-02 22:11:50 -0500
commit3a12c94b738b654537a2cd830d6af668b6c74e9b (patch)
tree6a0e0cf53e0fbf80cd5935c88796bf5786d1668d /lisc
parent7e1b7fccd8a6ff99f5b2e427f550f5f7e5b51e84 (diff)
downloadroux-3a12c94b738b654537a2cd830d6af668b6c74e9b.tar.gz
start work on automating tests
Diffstat (limited to 'lisc')
-rw-r--r--lisc/test/cup.ssa5
-rwxr-xr-xlisc/test/go.sh96
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