Rename REAMDE to README.md
[nit.git] / tests / tests.sh
index 8720ca3..2769eba 100755 (executable)
@@ -21,7 +21,7 @@
 export LANG=C
 export LC_ALL=C
 export NIT_TESTING=true
-export MNIT_SRAND=0
+export NIT_SRAND=0
 
 unset NIT_DIR
 
@@ -29,11 +29,9 @@ unset NIT_DIR
 shopt -s nullglob
 JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac))))
 
-paths=`echo $JAVA_HOME/jre/lib/*/{client,server}/`
-paths=($paths) 
-JNI_LIB_PATH=${paths[0]}
-echo $JAVA_HOME
-echo $JNI_LIB_PATH
+paths=`echo $JAVA_HOME/jre/lib/*/{client,server}/libjvm.so`
+paths=($paths)
+JNI_LIB_PATH=`dirname ${paths[0]}`
 shopt -u nullglob
 
 outdir="out"
@@ -47,11 +45,12 @@ Usage: $e [options] modulenames
 -o option   Pass option to the engine
 -v          Verbose (show tests steps)
 -h          This help
---engine    Use a specific engine (default=nitg)
+--engine    Use a specific engine (default=nitc)
 --noskip    Do not skip a test even if the .skip file matches
 --outdir    Use a specific output folder (default=out/)
 --compdir   Use a specific temporary compilation folder (default=.nit_compile)
 --node      Run as a node in parallel, will not output context information
+--autosav   Copy the .res files directly in the sav folder overriding existing .res files
 END
 }
 
@@ -71,7 +70,9 @@ saferun()
                        *) stop=true
                esac
        done
-       if test -n "$TIME"; then
+       if test -d "$1"; then
+               find $1 | sort
+       elif test -n "$TIME"; then
                $TIME -o "$o" $a $TIMEOUT "$@"
        else
                if test -n "$a"; then echo 0 >> "$o"; else echo 0 > "$o"; fi
@@ -234,6 +235,7 @@ function process_result()
                        echo "[*ok*] $outdir/$pattern.res $SAV - but $OLD remains!"
                        echo >>$xml "<error message='`xmlesc "ok $outdir/$pattern.res - but $OLD remains"`'/>"
                        remains="$remains $OLD"
+                       test "$autosav" = "true" && rm "$OLD"
                else
                        echo "[ok] $outdir/$pattern.res $SAV"
                fi
@@ -243,6 +245,7 @@ function process_result()
                        echo "[*fixme*] $outdir/$pattern.res $FIXME - but $OLD remains!"
                        echo >>$xml "<error message='`xmlesc "ok $outdir/$pattern.res - but $OLD remains"`'/>"
                        remains="$remains $OLD"
+                       test "$autosav" = "true" && rm "$OLD"
                else
                        echo "[fixme] $outdir/$pattern.res $FIXME"
                        echo >>$xml "<skipped/>"
@@ -260,6 +263,7 @@ function process_result()
                echo >>$xml "]]></system-out>"
                nok="$nok $pattern"
                echo "$ii" >> "$ERRLIST"
+               test "$autosav" = "true" && cp "$outdir/$pattern.res" "$SOSO"
        elif [ -n "$SOSOF" ]; then
                echo "[======= fixme soso $outdir/$pattern.res $SOSOF =======]"
                echo >>$xml "<error message='`xmlesc "soso $outdir/$pattern.res $SOSO"`'/>"
@@ -268,6 +272,7 @@ function process_result()
                echo >>$xml "]]></system-out>"
                nok="$nok $pattern"
                echo "$ii" >> "$ERRLIST"
+               test "$autosav" = "true" && cp "$outdir/$pattern.res" && "$SOSO"
        elif [ -n "$NSAV" ]; then
                echo "[======= fail $outdir/$pattern.res $NSAV =======]"
                echo >>$xml "<error message='`xmlesc "fail $outdir/$pattern.res $NSAV"`'/>"
@@ -276,6 +281,7 @@ function process_result()
                echo >>$xml "]]></system-out>"
                nok="$nok $pattern"
                echo "$ii" >> "$ERRLIST"
+               test "$autosav" = "true" && cp "$outdir/$pattern.res" "$NSAV"
        elif [ -n "$NFIXME" ]; then
                echo "[======= changed $outdir/$pattern.res $NFIXME ======]"
                echo >>$xml "<error message='`xmlesc "changed $outdir/$pattern.res $NFIXME"`'/>"
@@ -284,6 +290,7 @@ function process_result()
                echo >>$xml "]]></system-out>"
                nok="$nok $pattern"
                echo "$ii" >> "$ERRLIST"
+               test "$autosav" = "true" && cp "$outdir/$pattern.res" "$NFIXME"
        elif [ -s "$outdir/$pattern.res" ]; then
                echo "[=== no sav ===] $outdir/$pattern.res is not empty"
                echo >>$xml "<error message='no sav and not empty'/>"
@@ -292,6 +299,7 @@ function process_result()
                echo >>$xml "]]></system-out>"
                nos="$nos $pattern"
                echo "$ii" >> "$ERRLIST"
+               test "$autosav" = "true" && cp "$outdir/$pattern.res" "sav/"
        else
                # no sav but empty res
                echo "[0k] $outdir/$pattern.res is empty"
@@ -318,6 +326,14 @@ need_skip()
                echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
                return 0
        fi
+
+       # Skip by OS
+       os_skip_file=`uname`.skip
+       if test -e $os_skip_file && echo "$1" | grep -f "$os_skip_file" >/dev/null 2>&1; then
+               echo "=> $2: [skip os]"
+               echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
+               return 0
+       fi
        return 1
 }
 
@@ -356,8 +372,9 @@ find_nitc()
 
 verbose=false
 isnode=false
+autosav=false
 stop=false
-engine=nitg
+engine=nitc
 noskip=
 savdirs=
 while [ $stop = false ]; do
@@ -370,35 +387,36 @@ while [ $stop = false ]; do
                --outdir) outdir="$2"; shift; shift;;
                --compdir) compdir="$2"; shift; shift;;
                --node) isnode=true; shift;;
+               --autosav) autosav=true; shift;;
                *) stop=true
        esac
 done
 enginebinname=$engine
 isinterpret=
 case $engine in
-       nitg)
+       nitc|nitg)
                engine=nitg-s;
-               enginebinname=nitg;
+               enginebinname=nitc;
                OPT="--separate $OPT --compile-dir $compdir"
                savdirs="sav/nitg-common/"
                ;;
-       nitg-s)
-               enginebinname=nitg;
+       nitcs|nitg-s)
+               enginebinname=nitc;
                OPT="--separate $OPT --compile-dir $compdir"
                savdirs="sav/nitg-common/"
                ;;
-       nitg-e)
-               enginebinname=nitg;
+       nitce|nitg-e)
+               enginebinname=nitc;
                OPT="--erasure $OPT --compile-dir $compdir"
                savdirs="sav/nitg-common/"
                ;;
-       nitg-sg)
-               enginebinname=nitg;
+       nitcsg|nitg-sg)
+               enginebinname=nitc;
                OPT="--semi-global $OPT --compile-dir $compdir"
                savdirs="sav/nitg-common/"
                ;;
-       nitg-g)
-               enginebinname=nitg;
+       nitcg|nitg-g)
+               enginebinname=nitc;
                OPT="--global $OPT --compile-dir $compdir"
                savdirs="sav/nitg-common/"
                ;;
@@ -412,10 +430,12 @@ case $engine in
                ;;
        nitvm)
                isinterpret=true
+               enginebinname=nit
+               OPT="--vm $OPT"
                savdirs="sav/niti/"
                ;;
        emscripten)
-               enginebinname=nitg
+               enginebinname=nitc
                OPT="-m emscripten_nodejs.nit --semi-global $OPT --compile-dir $compdir"
                savdirs="sav/nitg-sg/"
                ;;