tests: fix errlist
[nit.git] / tests / tests.sh
index c89adf7..f1daadd 100755 (executable)
@@ -19,7 +19,9 @@
 
 # Set lang do default to avoid failed tests because of locale
 export LANG=C
+export LC_ALL=C
 export NIT_TESTING=true
+export MNIT_SRAND=0
 
 unset NIT_DIR
 
@@ -214,6 +216,7 @@ function process_result()
                cat -v >>$xml out/$pattern.res
                echo >>$xml "]]></system-out>"
                nos="$nos $pattern"
+               echo "$ii" >> "$ERRLIST"
        else
                # no sav but empty res
                echo "[0k] out/$pattern.res is empty"
@@ -235,7 +238,7 @@ need_skip()
                echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
                return 0
        fi
-       if test $engine = niti && echo "$1" | grep -f "exec.skip" >/dev/null 2>&1; then
+       if test -n "$isinterpret" && echo "$1" | grep -f "exec.skip" >/dev/null 2>&1; then
                echo "=> $2: [skip exec]"
                echo >>$xml "<testcase classname='$3' name='$2'><skipped/></testcase>"
                return 0
@@ -290,6 +293,7 @@ while [ $stop = false ]; do
        esac
 done
 enginebinname=$engine
+isinterpret=
 case $engine in
        nitg)
                engine=nitg-s;
@@ -304,15 +308,30 @@ case $engine in
                enginebinname=nitg;
                OPT="--erasure $OPT"
                ;;
+       nitg-sg)
+               enginebinname=nitg;
+               OPT="--semi-global $OPT"
+               ;;
        nitg-g)
                enginebinname=nitg;
                OPT="--global $OPT"
                ;;
        nit)
                engine=niti
+               isinterpret=true
                ;;
        niti)
                enginebinname=nit
+               isinterpret=true
+               ;;
+       nitvm)
+               isinterpret=true
+               savdirs="sav/niti/"
+               ;;
+       emscripten)
+               enginebinname=nitg
+               OPT="-m emscripten_nodejs.nit --semi-global $OPT"
+               savdirs="sav/nitg-sg/"
                ;;
        nitc)
                echo "disabled engine $engine"
@@ -401,11 +420,18 @@ for ii in "$@"; do
 
                if [ -f "$f.inputs" ]; then
                        inputs="$f.inputs"
+                       export MNIT_READ_INPUT="$f.inputs"
                else
                        inputs=/dev/null
+                       export MNIT_READ_INPUT=/dev/null
+               fi
+
+               ffout="$ff.bin"
+               if [ "$engine" = "emscripten" ]; then
+                       ffout="$ff.bin.js"
                fi
 
-               if [ "$engine" = "niti" ]; then
+               if [ -n "$isinterpret" ]; then
                        cat > "./$ff.bin" <<END
 exec $NITC --no-color $OPT "$i" $includes -- "\$@"
 END
@@ -422,30 +448,41 @@ END
                        # Compile
                        if [ "x$verbose" = "xtrue" ]; then
                                echo ""
-                               echo $NITC --no-color $OPT -o "$ff.bin" "$i" "$includes" $nocc
+                               echo $NITC --no-color $OPT -o "$ffout" "$i" "$includes" $nocc
                        fi
                        NIT_NO_STACK=1 JNI_LIB_PATH=$JNI_LIB_PATH JAVA_HOME=$JAVA_HOME \
-                               $TIMEOUT $NITC --no-color $OPT -o "$ff.bin" "$i" $includes $nocc 2> "$ff.cmp.err" > "$ff.compile.log"
+                               $TIMEOUT $NITC --no-color $OPT -o "$ffout" "$i" $includes $nocc 2> "$ff.cmp.err" > "$ff.compile.log"
                        ERR=$?
                        if [ "x$verbose" = "xtrue" ]; then
                                cat "$ff.compile.log"
                                cat >&2 "$ff.cmp.err"
                        fi
                fi
+               if [ "$engine" = "emscripten" ]; then
+                       echo > "./$ff.bin" "nodejs $ffout \"\$@\""
+                       chmod +x "$ff.bin"
+                       if grep "Fatal Error: more than one primitive class" "$ff.compile.log" > /dev/null; then
+                               echo " [skip] do no not imports kernel"
+                               echo >>$xml "<testcase classname='$pack' name='$bf'><skipped/></testcase>"
+                               continue
+                       fi
+               fi
                if [ "$ERR" != 0 ]; then
                        echo -n "! "
                        cat "$ff.compile.log" "$ff.cmp.err" > "$ff.res"
                        process_result $bf $bf $pack
-               elif skip_exec "$bf"; then
-                       # No exec
-                       > "$ff.res"
-                       process_result $bf $bf $pack
                elif [ -n "$nocc" ]; then
                        # not compiled
                        echo -n "nocc "
                        > "$ff.res"
                        process_result $bf $bf $pack
                elif [ -x "./$ff.bin" ]; then
+                       if skip_exec "$bf"; then
+                               # No exec
+                               > "$ff.res"
+                               process_result $bf $bf $pack
+                               break
+                       fi
                        echo -n ". "
                        # Execute
                        args=""
@@ -544,10 +581,11 @@ fi
 
 # write $ERRLIST
 if [ "x$ERRLIST" != "x" ]; then
-       if [ -x "$ERRLIST_TARGET" ]; then
+       if [ -f "$ERRLIST_TARGET" ]; then
                mv "$ERRLIST_TARGET" "${ERRLIST_TARGET}.bak"
        fi
-       mv $ERRLIST $ERRLIST_TARGET
+       uniq $ERRLIST > $ERRLIST_TARGET
+       rm $ERRLIST
 fi
 
 echo >>$xml "</testsuite></testsuites>"