Merge: Nit for mac
[nit.git] / tests / tests.sh
index 6483969..6cfb9be 100755 (executable)
@@ -19,6 +19,7 @@
 
 # Set lang do default to avoid failed tests because of locale
 export LANG=C
+export LC_ALL=C
 export NIT_TESTING=true
 
 unset NIT_DIR
@@ -44,7 +45,6 @@ Usage: $e [options] modulenames
 -h          This help
 --engine    Use a specific engine (default=nitg)
 --noskip    Do not skip a test even if the .skip file matches
---[no]soso  Force enable (or disable) SOSO
 END
 }
 
@@ -60,16 +60,16 @@ function compare_to_result()
        local pattern="$1"
        local sav="$2"
        if [ ! -r "$sav" ]; then return 0; fi
+       test "`cat "$sav"`" = "UNDEFINED" && return 1
        diff -u "$sav" "out/$pattern.res" > "out/$pattern.diff.sav.log"
        if [ "$?" == 0 ]; then
                return 1
        fi
-       [ -z "$soso" ] && return 3
        sed '/[Ww]arning/d;/[Ee]rror/d' "out/$pattern.res" > "out/$pattern.res2"
        sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "out/$pattern.sav2"
        grep '[Ee]rror' "out/$pattern.res" >/dev/null && echo "Error" >> "out/$pattern.res2"
        grep '[Ee]rror' "$sav" >/dev/null && echo "Error" >> "out/$pattern.sav2"
-       diff -u "out/$pattern.sav2" "out/$pattern.res2" > "out/$pattern.diff.sav.log"
+       diff -u "out/$pattern.sav2" "out/$pattern.res2" > "out/$pattern.diff.sav.log2"
        if [ "$?" == 0 ]; then
                return 2
        else
@@ -109,7 +109,10 @@ function process_result()
                                LIST="$LIST $sav"
                                ;;
                        2)
-                               SOSOF="$sav"
+                               if [ -z "$FIRST" ]; then
+                                       SOSOF="$sav"
+                                       FIRST="$sav"
+                               fi
                                LIST="$LIST $sav"
                                ;;
                        3)
@@ -132,7 +135,10 @@ function process_result()
                                LIST="$LIST $sav"
                                ;;
                        2)
-                               SOSO="$sav"
+                               if [ -z "$FIRST" ]; then
+                                       SOSO="$sav"
+                                       FIRST="$sav"
+                               fi
                                LIST="$LIST $sav"
                                ;;
                        3)
@@ -166,17 +172,26 @@ function process_result()
                        echo >>$xml "<skipped/>"
                fi
                todos="$todos $pattern"
-       elif [ -n "$SOSO" ]; then
-               echo "[soso] out/$pattern.res $SOSO"
-               ok="$ok $pattern"
        elif [ "x$NYI" = "x0" ]; then
                echo "[todo] out/$pattern.res -> not yet implemented"
                echo >>$xml "<skipped/>"
                todos="$todos $pattern"
+       elif [ -n "$SOSO" ]; then
+               echo "[======= soso out/$pattern.res $SOSO =======]"
+               echo >>$xml "<error message='soso out/$pattern.res $SOSO'/>"
+               echo >>$xml "<system-out><![CDATA["
+               cat -v out/$pattern.diff.sav.log | head >>$xml -n 50
+               echo >>$xml "]]></system-out>"
+               nok="$nok $pattern"
+               echo "$ii" >> "$ERRLIST"
        elif [ -n "$SOSOF" ]; then
-               echo "[fixme soso] out/$pattern.res $SOSOF"
-               echo >>$xml "<skipped/>"
-               todos="$todos $pattern"
+               echo "[======= fixme soso out/$pattern.res $SOSOF =======]"
+               echo >>$xml "<error message='soso out/$pattern.res $SOSO'/>"
+               echo >>$xml "<system-out><![CDATA["
+               cat -v out/$pattern.diff.sav.log | head >>$xml -n 50
+               echo >>$xml "]]></system-out>"
+               nok="$nok $pattern"
+               echo "$ii" >> "$ERRLIST"
        elif [ -n "$NSAV" ]; then
                echo "[======= fail out/$pattern.res $NSAV =======]"
                echo >>$xml "<error message='fail out/$pattern.res $NSAV'/>"
@@ -272,8 +287,6 @@ while [ $stop = false ]; do
                -h) usage; exit;;
                --engine) engine="$2"; shift; shift;;
                --noskip) noskip=true; shift;;
-               --soso) soso=true; shift;;
-               --nososo) nososo=true; shift;;
                *) stop=true
        esac
 done
@@ -292,6 +305,10 @@ case $engine in
                enginebinname=nitg;
                OPT="--erasure $OPT"
                ;;
+       nitg-sg)
+               enginebinname=nitg;
+               OPT="--semi-global $OPT"
+               ;;
        nitg-g)
                enginebinname=nitg;
                OPT="--global $OPT"
@@ -302,6 +319,11 @@ case $engine in
        niti)
                enginebinname=nit
                ;;
+       emscripten)
+               enginebinname=nitg
+               OPT="-m emscripten_nodejs.nit --semi-global $OPT"
+               savdirs="sav/nitg-sg/"
+               ;;
        nitc)
                echo "disabled engine $engine"
                exit 0
@@ -393,6 +415,11 @@ for ii in "$@"; do
                        inputs=/dev/null
                fi
 
+               ffout="$ff.bin"
+               if [ "$engine" = "emscripten" ]; then
+                       ffout="$ff.bin.js"
+               fi
+
                if [ "$engine" = "niti" ]; then
                        cat > "./$ff.bin" <<END
 exec $NITC --no-color $OPT "$i" $includes -- "\$@"
@@ -410,16 +437,25 @@ 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"