* configure.ac: Generate tests/regression/jasmin/Makefile.
[cacao.git] / tests / regression / jasmin / runtest
index e3e0c3f18adaf260c15299b8ea676b31d4f83c52..c1c5c3f5372abf9e2891bfa8e49074447579fddb 100755 (executable)
@@ -2,12 +2,42 @@
 
 VERBOSE=0
 EXITCODE=0
+COLOR=0
+PASSCOLOR=''
+FAILCOLOR=''
+NOCOLOR=''
+ECHOFLAGS=''
+
+if [ -z "$JAVA" ] ; then
+       JAVA=../../../src/cacao/cacao
+fi
 
 if [ "$1" = "--verbose" ] ; then
        shift
        VERBOSE=1
 fi
 
+if [ "$1" = "--color" ] ; then
+       shift
+       COLOR=1
+       PASSCOLOR='\033[1;32m'
+       FAILCOLOR='\033[1;31m'
+       NOCOLOR='\033[0m'
+       ECHOFLAGS='-e'
+fi
+
+JASMIN_JAR=/usr/share/java/jasmin-sable.jar
+
+if [ ! -r "$JASMIN_JAR" ] ; then
+       echo >&2 "$0: warning: jasmin .jar is not available at $JASMIN_JAR"
+       exit 0
+fi
+
+JASMIN="$JAVA $JAVAFLAGS -cp $JASMIN_JAR jasmin.Main"
+
+echo "java command: $JAVA $JAVAFLAGS"
+echo "jasmin command: $JASMIN"
+
 while [ -n "$1" ]
 do
     TEST="$1"
@@ -16,27 +46,58 @@ do
     TESTOUT="TESTOUT"
     TESTEXPECT="TESTEXPECT"
     TESTLOG="TESTLOG"
+    TESTERR="TESTERR"
+
+       EXPECTSTATUS=0
+
+       # compile the test
+
+    $JASMIN "$TEST" || exit 2
 
-    jasmin "$TEST" || exit 2
-    cacao "$TESTBASENAME" >"$TESTOUT" || exit 2
+       if grep 'ERROR:' "$TEST" >/dev/null ; then
+               EXPECTSTATUS=1
+               EXPECTERROR=$(grep -o 'ERROR:.*' "$TEST" | sed 's,ERROR:\s*,,')
+       fi
 
-    grep 'OUTPUT:' "$TEST" | sed 's,.*OUTPUT:\s*,,' >"$TESTEXPECT"
+       # run the test
 
-    if diff -u "$TESTEXPECT" "$TESTOUT" ; then
-       echo "PASS: $TEST"
-    else
-       echo "FAIL: $TEST"
-       EXITCODE=1
-    fi
+    $JAVA $JAVAFLAGS "$TESTBASENAME" >"$TESTOUT" 2>"$TESTERR"
+       TESTSTATUS=$?
 
-    if [ "$VERBOSE" -eq "1" ] ; then
-       cacao -sia "$TESTBASENAME" >"$TESTLOG" || exit 2
-       ./show "$TESTLOG"
-    fi
+       if [ $TESTSTATUS -ne $EXPECTSTATUS ] ; then
+               echo $ECHOFLAGS "${FAILCOLOR}FAIL: $TEST - expected status $EXPECTSTATUS, but got $TESTSTATUS${NOCOLOR}"
+               EXITCODE=1
+       fi
+
+       if [ $EXPECTSTATUS -eq 0 ] ; then
+               grep 'OUTPUT:' "$TEST" | sed 's,.*OUTPUT:\s*,,' >"$TESTEXPECT"
+
+               if diff -u "$TESTEXPECT" "$TESTOUT" ; then
+                       if [ $TESTSTATUS -eq 0 ] ; then
+                               echo $ECHOFLAGS "${PASSCOLOR}PASS: $TEST${NOCOLOR}"
+                       fi
+               else
+                       echo $ECHOFLAGS "${FAILCOLOR}FAIL: $TEST - wrong output${NOCOLOR}"
+                       EXITCODE=1
+               fi
+
+               if [ "$VERBOSE" -eq "1" ] ; then
+                       $JAVA $JAVAFLAGS -sia "$TESTBASENAME" >"$TESTLOG" || exit 2
+                       ./show "$TESTLOG"
+               fi
+       else
+               if grep "$EXPECTERROR" "$TESTERR" >/dev/null ; then
+                       echo $ECHOFLAGS "${PASSCOLOR}PASS: $TEST - got expected error: $EXPECTERROR${NOCOLOR}"
+               else
+                       echo $ECHOFLAGS "${FAILCOLOR}FAIL: $TEST - did not get expected error: $EXPECTERROR${NOCOLOR}"
+                       EXITCODE=1
+               fi
+       fi
 
     shift
 done
 
-#rm -f "$TESTOUT" "$TESTEXPECT" "$TESTLOG"
+rm -f "$TESTOUT" "$TESTEXPECT" "$TESTLOG" "$TESTERR"
 
 exit $EXITCODE
+