tests: update sav for test_parser
[nit.git] / tests / tests.sh
index 768b698..738ccd2 100755 (executable)
 export LANG=C
 export LC_ALL=C
 export NIT_TESTING=true
+# Use the pid as a collision prevention
+export NIT_TESTING_ID=$$
 export NIT_SRAND=0
 
 unset NIT_DIR
 
 # Get the first Java lib available
-shopt -s nullglob
-JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac))))
-
-paths=`echo $JAVA_HOME/jre/lib/*/{client,server}/libjvm.so`
-paths=($paths)
-JNI_LIB_PATH=`dirname ${paths[0]}`
-shopt -u nullglob
+if which_java=$(which javac 2>/dev/null); then
+       JAVA_HOME=$(dirname $(dirname $(readlink -f "$which_java")))
+
+       shopt -s nullglob
+       paths=`echo $JAVA_HOME/jre/lib/*/{client,server}/libjvm.so`
+       paths=($paths)
+       JNI_LIB_PATH=`dirname ${paths[0]}`
+       shopt -u nullglob
+fi
 
 outdir="out"
 compdir="nit_compile"
@@ -90,8 +94,8 @@ saferun()
                esac
        done
        (
-       ulimit -f "$filelimit"
-       ulimit -t "$usertimelimit"
+       ulimit -f "$filelimit" 2> /dev/null
+       ulimit -t "$usertimelimit" 2> /dev/null
        if test -d "$1"; then
                find $1 | sort
        elif test -n "$TIME"; then
@@ -141,6 +145,13 @@ else
        TIMESTAMP=
 fi
 
+# Detect a working hostname command
+if hostname --version | grep coreutils >/dev/null 2>&1; then
+       HOSTNAME="hostname"
+else
+       HOSTNAME="hostname -s"
+fi
+
 # $1 is the pattern of the test
 # $2 is the file to compare to
 # the result is:
@@ -154,7 +165,7 @@ function compare_to_result()
        local sav="$2"
        if [ ! -r "$sav" ]; then return 0; fi
        test "`cat -- "$sav"`" = "UNDEFINED" && return 1
-       diff -u -- "$sav" "$outdir/$pattern.res" > "$outdir/$pattern.diff.sav.log"
+       diff -u --strip-trailing-cr -- "$sav" "$outdir/$pattern.res" > "$outdir/$pattern.diff.sav.log"
        if [ "$?" == 0 ]; then
                return 1
        fi
@@ -162,7 +173,7 @@ function compare_to_result()
        sed '/[Ww]arning/d;/[Ee]rror/d' "$sav" > "$outdir/$pattern.sav2"
        grep '[Ee]rror' "$outdir/$pattern.res" >/dev/null && echo "Error" >> "$outdir/$pattern.res2"
        grep '[Ee]rror' "$sav" >/dev/null && echo "Error" >> "$outdir/$pattern.sav2"
-       diff -u "$outdir/$pattern.sav2" "$outdir/$pattern.res2" > "$outdir/$pattern.diff.sav.log2"
+       diff -u --strip-trailing-cr "$outdir/$pattern.sav2" "$outdir/$pattern.res2" > "$outdir/$pattern.diff.sav.log2"
        if [ "$?" == 0 ]; then
                return 2
        else
@@ -368,7 +379,7 @@ need_skip()
        fi
 
        # Skip by hostname
-       local host_skip_file=`hostname -s`.skip
+       local host_skip_file=`$HOSTNAME`.skip
        if test -e $host_skip_file && echo "$1" | grep -f "$host_skip_file" >/dev/null 2>&1; then
                echo "=> $2: [skip hostname]"
                echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
@@ -517,7 +528,7 @@ case $engine in
                ;;
 esac
 
-savdirs="sav/`hostname -s` sav/`uname` sav/$engine $savdirs sav/"
+savdirs="sav/`$HOSTNAME` sav/`uname` sav/$engine $savdirs sav/"
 
 # The default nitc compiler
 [ -z "$NITC" ] && find_nitc
@@ -576,9 +587,9 @@ for ii in "$@"; do
        # Sould we skip the file for this engine?
        need_skip "$f" "$f" "$pack" && continue
 
-       tmp=${ii/../AA}
-       if [ "x$tmp" = "x$ii" ]; then
-               includes="-I . -I ../lib/standard -I ../lib/standard/collection -I alt"
+       local_tmp=${ii/../AA}
+       if [ "x$local_tmp" = "x$ii" ]; then
+               includes="-I . -I ../lib/core -I ../lib/core/collection -I alt"
        else
                includes="-I alt"
        fi