ref: 3a3ccd605eab52fec23689955b8f61398d739ad2
parent: 81bef8daa90ad1c1589f3ebee10b030ad248b4c7
author: Ori Bernstein <[email protected]>
date: Thu Oct 17 09:35:29 EDT 2013
Rewrite test harness. The old one was a mess.
--- a/test/Makefile
+++ b/test/Makefile
@@ -3,7 +3,7 @@
$(MAKE) -C ..
check:
- ./test.sh
+ ./runtest.sh
.PHONY: clean
clean:
@for i in `awk '/^[A-Z]/{print $$2}' tests`; do \
--- a/test/catfile.myr
+++ b/test/catfile.myr
@@ -4,7 +4,7 @@
const main = {args : byte[:][:]
var r
- r = std.slurp("data/catfile")
+ r = std.slurp("data/catfile-in")
match r
`std.Success dat: std.write(1, dat);;
`std.Failure msg: std.put("Failed to read file: %s\n", msg);;
--- a/test/data/catfile
+++ /dev/null
@@ -1,1 +1,0 @@
-Hello-世界
--- /dev/null
+++ b/test/data/catfile-expected
@@ -1,0 +1,1 @@
+Hello-世界
--- /dev/null
+++ b/test/data/catfile-in
@@ -1,0 +1,1 @@
+Hello-世界
--- /dev/null
+++ b/test/data/strtab-expected
@@ -1,0 +1,4 @@
+0: foo
+1: bar
+2: baz
+3: quux
--- a/test/data/strtab-out
+++ /dev/null
@@ -1,4 +1,0 @@
-0: foo
-1: bar
-2: baz
-3: quux
--- /dev/null
+++ b/test/runtest.sh
@@ -1,0 +1,131 @@
+#!/bin/bash
+export PATH=.:$PATH
+export MC=../6/6m
+export MU=../muse/muse
+export AS=AS
+export LD=ld
+ARGS=$*
+NFAILURES=0
+NPASSES=0
+
+function use {
+ rm -f $1 $1.o $1.s $1.use
+ echo " "$MU -I ../libstd -o $1.use $1.myr && \
+ $MU $1.myr -o $1.use
+}
+
+function build {
+ rm -f $1 $1.o $1.s $1.use
+ ../myrbuild/myrbuild -b $1 -C../6/6m -M../muse/muse -I../libstd $1.myr
+}
+
+function pass {
+ PASSED="$PASSED $1"
+ NPASSED=$[$NPASSED + 1]
+}
+
+function fail {
+ echo "FAIL: $1"
+ FAILED="$FAILED $1"
+ NFAILED=$[$NFAILED + 1]
+}
+
+function expectstatus {
+ ./$1 $3
+ if [ $? -eq $2 ]; then
+ pass $1
+ return
+ else
+ fail $1
+ fi
+}
+
+function expectprint {
+ if [ "`./$1 $3`" != "$2" ]; then
+ fail $1
+ else
+ pass $1
+ fi
+}
+
+
+function expectcompare {
+ t=`tempfile`
+ ./$1 $3 > $t
+ if cmp $t data/$1-expected; then
+ pass $1
+ else
+ fail $1
+ fi
+}
+
+function expectfcompare {
+ ./$1 $3
+ if cmp data/$1-expected $2; then
+ pass $1
+ else
+ fail $1
+ fi
+}
+
+function shouldskip {
+ if [ -z $ARGS ]; then
+ return 1
+ fi
+
+ for i in $ARGS; do
+ if [ $i = $1 ]; then
+ return 1
+ fi
+ done
+ return 0
+}
+
+
+# Should build and run
+function B {
+ if shouldskip $1; then
+ return
+ fi
+
+ test="$1"; shift
+ type="$1"; shift
+ res="$1"; shift
+ if [ $# > 0 ]; then
+ args="$1"; shift
+ fi
+ build $test
+ case $type in
+ "E") expectstatus "$test" "$res" "$input";;
+ "P") expectprint "$test" "$res" "$input";;
+ "C") expectcompare "$test" "$res" "$input";;
+ "F") expectfcompare "$test" "$res" "$args";;
+ esac
+}
+
+# Should fail
+function F {
+ if shouldskip $1; then
+ return
+ fi
+ (build $1) > /dev/null
+ if [ $? -eq '1' ]; then
+ pass $1
+ else
+ fail $1
+ fi
+}
+
+# Should generate a usefile
+function U {
+ return
+}
+
+source tests
+
+echo "PASSED ($NPASSED): $PASSED"
+if [ -z "$NFAILED" ]; then
+ echo "SUCCESS"
+else
+ echo "FAILURES ($NFAILED): $FAILED"
+fi
--- a/test/test.sh
+++ /dev/null
@@ -1,102 +1,0 @@
-#!/bin/bash
-export PATH=.:$PATH
-export MC=../6/6m
-export MU=../muse/muse
-export AS=AS
-export LD=ld
-NFAILURES=0
-
-function use {
- rm -f $1 $1.o $1.s $1.use
- echo " "$MU -I ../libstd -o $1.use $1.myr && \
- $MU $1.myr -o $1.use
-}
-
-function build {
- rm -f $1 $1.o $1.s $1.use
- ../myrbuild/myrbuild -b $1 -C../6/6m -M../muse/muse -I../libstd $1.myr
-}
-
-function comparedto {
- if [ "`./$1`" != "`cat "$2"`" ]; then
- echo "FAIL: $1"
- FAILED="$FAILED $1"
- NFAILED=$[$NFAILED + 1]
- else
- echo "PASS: $1"
- fi
-}
-
-function prints {
- if [ "`./$1`" != "$2" ]; then
- echo "FAIL: $1"
- FAILED="$FAILED $1"
- NFAILED=$[$NFAILED + 1]
- else
- echo "PASS: $1"
- fi
-}
-
-function exitswith {
- if [ -e $1 ]; then
- ./$1
- if [ $? -eq $2 ]; then
- echo "PASS: $1"
- else
- echo "FAIL: $1"
- FAILED="$FAILED $1"
- NFAILED=$[$NFAILED + 1]
- fi
- else
- echo "FAIL: $1"
- FAILED="$FAILED $1"
- NFAILED=$[$NFAILED + 1]
- fi
-}
-
-# When broken, these tests have taken down machines by
-# using all available resources. This should be disallowed.
-ulimit -c unlimited # core size
-ulimit -d 16382 # data segment: 16m
-ulimit -f 16382 # file size
-ulimit -m 32768 # total memory
-ulimit -s 8192 # 8 meg stack
-ulimit -t 30 # 30 second CPU time
-ulimit -v 32768 # virtual memory
-
-for i in `awk '/^B/{print $2}' tests`; do
- build $i
-done
-
-for i in `awk '/^U/{print $2}' tests`; do
- use $i
-done
-
-for i in `awk '/^F/{print $2}' tests`; do
- (build $i) > /dev/null
- if [ $? -eq '1' ]; then
- echo "PASS: $i"
- else
- echo "FAIL: $i"
- FAILED="$FAILED $i"
- NFAILED=$[$NFAILED + 1]
- fi
-done
-
-export IFS='
-'
-for i in `awk '/^B/{print $0}' tests`; do
- tst=`echo $i | awk '{print $2}'`
- type=`echo $i | awk '{print $3}'`
- val=`echo $i | awk '{print $4}'`
- case $type in
- E) exitswith $tst $val ;;
- P) prints $tst $val ;;
- C) comparedto $tst $val ;;
- esac
-done
-if [ -z "$NFAILED" ]; then
- echo "SUCCESS"
-else
- echo "FAILURES ($NFAILED)": $FAILED
-fi
--- a/test/tests
+++ b/test/tests
@@ -96,8 +96,8 @@
B import-type E 0
B helloworld P Hello-世界
B encodechar P 1世界äa
-B catfile C data/catfile
-B strtab C data/strtab-out
+B strtab C
+B catfile C
# B local-labels E 10 ## BUGGERED
F declmismatch
F infermismatch