shithub: mc

Download patch

ref: 8ce0032c23c61802082f2b755ff91a0801e4416b
parent: 16cf9b0feb9447367a1bf77575ef279148f6edc4
author: Ori Bernstein <[email protected]>
date: Wed Jun 6 16:23:56 EDT 2012

Simplify test framework

    Tests are only specified in one place.

--- a/test/Makefile
+++ b/test/Makefile
@@ -2,10 +2,12 @@
 all: 
 
 check:
-	./build.sh
 	./test.sh
 .PHONY: clean
 clean:
-	rm -f $(TESTBIN) $(TESTBIN:=.o) $(TESTBIN:=.s)
+	@for i in `awk '{print $$1}' tests`; do \
+	    echo rm -f $$i; \
+	    rm -f $$i; \
+	done
 
 install:
--- a/test/build.sh
+++ /dev/null
@@ -1,24 +1,0 @@
-#!/bin/bash
-
-MC=../8/8m
-ASOPT="-g"
-
-function build {
-    rm $1
-    echo $MC $1.myr && \
-    $MC $1.myr && \
-    mv a.s $1.s && \
-    cc $ASOPT -m32 -o $1 $1.s
-}
-
-build main
-build add
-build struct_oneval
-build struct
-build array
-build call
-build loop
-build fib
-build slice
-
-exit 0
--- /dev/null
+++ b/test/struct1.myr
@@ -1,0 +1,9 @@
+type val = struct
+	a : int
+;;
+
+const main = {
+	var s : val
+	s.a = 12
+	-> s.a
+}
--- a/test/struct_oneval.myr
+++ /dev/null
@@ -1,9 +1,0 @@
-type val = struct
-	a : int
-;;
-
-const main = {
-	var s : val
-	s.a = 12
-	-> s.a
-}
--- a/test/test.sh
+++ b/test/test.sh
@@ -1,6 +1,16 @@
 #!/bin/bash
 export PATH=.:$PATH
+export MC=../8/8m
+export ASOPT="-g"
 
+function build {
+    rm -f $1
+    echo $MC $1.myr && \
+    $MC $1.myr && \
+    mv a.s $1.s && \
+    cc $ASOPT -m32 -o $1 $1.s
+}
+
 function prints {
     if [ `./$1` -ne $2 ]; then
         echo "FAIL: $1"
@@ -9,7 +19,7 @@
     fi
 }
 
-function returns {
+function exitswith {
     ./$1
     if [ $? -eq $2 ]; then
         echo "PASS: $1"
@@ -18,12 +28,18 @@
     fi
 }
 
-returns main 0
-returns add 53
-returns struct_oneval 12
-returns struct 42
-returns array 7
-returns call 42
-returns loop 45
-returns fib 21
-returns slice 7
+for i in `awk '{print $1}' tests`; do
+    build $i
+done
+
+export IFS='
+'
+for i in `cat tests`; do
+    tst=`echo $i | awk '{print $1}'`
+    type=`echo $i | awk '{print $2}'`
+    val=`echo $i | awk '{print $3}'`
+    case $type in
+        E) exitswith $tst $val ;;
+        P) prints $tst $val ;;
+    esac
+done
--- /dev/null
+++ b/test/tests
@@ -1,0 +1,9 @@
+main	E	0
+add	E	53
+struct1	E	12
+struct	E	42
+array	E	7
+call	E	42
+loop	E	45
+fib	E	21
+slice	E	7