tests: set LANG to avoid locale perturbation
[nit.git] / tests / tests.sh
index a24bf32..94d85c4 100755 (executable)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# This shell script compile, run and verify NIT program files
+# This shell script compile, run and verify Nit program files
 
-# Ruby binary (none if you want to let the program to decide)
-#RUBY=
+# Set lang do default to avoid failed tests because of locale
+export LANG=C
+
+# The default nitc compiler
 [ -z "$NITC" ] && NITC=../bin/nitc
 
-# Options to use with the ruby compiler
-# OPT=
+usage()
+{
+       e=`basename "$0"`
+       cat<<END
+Usage: $e [options] modulenames
+-o option   Pass option to nitc
+-v          Verbose (show tests steps)
+-h          This help
+END
+}
+
+verbose=false
+stop=false
+while [ $stop = false ]; do
+       case $1 in
+               -o) OPT="$OPT $2"; shift; shift;;
+               -v) verbose=true; shift;;
+               -h) usage; exit;;
+               *) stop=true
+       esac
+done
 
 # Mark to distinguish files among tests
 # MARK=
@@ -32,7 +53,8 @@
 ERRLIST=${ERRLIST:-errlist}
 
 if [ $# = 0 ]; then
-       echo "usage: $0 file.nit ..."
+       usage;
+       exit
 fi
 
 # Backup and initiate new ERRLIST
@@ -67,8 +89,16 @@ for ii in "$@"; do
                rm "$ff.res" "$ff.err" "$ff.write" 2> /dev/null
 
                # Compile
+               if [ "x$verbose" = "xtrue" ]; then
+                       echo ""
+                       echo $NITC $OPT -o "$f.bin" "$i" -I . -I alt -I ../lib/standard
+               fi
                $NITC $OPT -o "$f.bin" "$i" -I . -I alt -I ../lib/standard 2> "$ff.cmp.err" > "$ff.compile.log"
                ERR=$?
+               if [ "x$verbose" = "xtrue" ]; then
+                       cat "$ff.compile.log"
+                       cat >&2 "$ff.cmp.err"
+               fi
                mv "$f.bin" "$ff.bin" 2> /dev/null
                egrep '^[A-Z0-9_]*$' "$ff.compile.log" > "$ff.res"
                if [ "$ERR" != 0 ]; then
@@ -82,11 +112,19 @@ for ii in "$@"; do
                        else
                                args=""
                        fi
+                       if [ "x$verbose" = "xtrue" ]; then
+                               echo ""
+                               echo "./$ff.bin" $args
+                       fi
                        if [ -f "$f.inputs" ]; then
                                "./$ff.bin" $args < "$f.inputs" > "$ff.res" 2>"$ff.err"
                        else
                                "./$ff.bin" $args > "$ff.res" 2>"$ff.err"
                        fi
+                       if [ "x$verbose" = "xtrue" ]; then
+                               cat "$ff.res"
+                               cat >&2 "$ff.err"
+                       fi
                        if [ -f "$ff.write" ]; then
                                cat "$ff.write" >> "$ff.res"
                        fi
@@ -96,16 +134,42 @@ for ii in "$@"; do
                fi
 
                # Result
+               SAV=""
+               FAIL=""
                if [ -r "sav/$ff.sav" ]; then
-                       diff -u "$ff.res" "sav/$ff.sav" > "$ff.diff.log"
+                       diff -u "$ff.res" "sav/$ff.sav" > "$ff.diff.sav.log"
                        if [ "$?" == 0 ]; then
+                               SAV=OK
+                       else
+                               SAV=NOK
+                       fi
+               fi
+               if [ -r "sav/$ff.fail" ]; then
+                       diff -u "$ff.res" "sav/$ff.fail" > "$ff.diff.fail.log"
+                       if [ "$?" == 0 ]; then
+                               FAIL=OK
+                       else
+                               FAIL=NOK
+                       fi
+               fi
+               if [ "x$SAV" = "xOK" ]; then
+                       if [ "x$FAIL" = "x" ]; then
                                echo "[ok] $ff.res"
-                               ok="$ok $ff"
                        else
-                               echo "[======= fail $ff.res sav/$ff.sav =======]"
-                               nok="$nok $ff"
-                               echo "$ii" >> "$ERRLIST"
+                               echo "[ok] $ff.res - but sav/$ff.fail remains!"
                        fi
+                       ok="$ok $ff"
+               elif [ "x$FAIL" = "xOK" ]; then
+                       echo "[fail] $ff.res"
+                       ok="$ok $ff"
+               elif [ "x$SAV" = "xNOK" ]; then
+                       echo "[======= fail $ff.res sav/$ff.sav =======]"
+                       nok="$nok $ff"
+                       echo "$ii" >> "$ERRLIST"
+               elif [ "x$FAIL" = "xNOK" ]; then
+                       echo "[======= changed $ff.res sav/$ff.fail ======]"
+                       nok="$nok $ff"
+                       echo "$ii" >> "$ERRLIST"
                else
                        echo "[=== no sav ===] $ff.res"
                        nos="$nos $ff"
@@ -117,7 +181,7 @@ echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
 
 if [ -n "$nok" ]; then
        echo "fail: $nok"
-       echo "There were errors ! (see file $ERRLIST)"
+       echo "There were $(echo $nok | wc -w) errors ! (see file $ERRLIST)"
 fi
 if [ -n "$nos" ]; then
        echo "no sav: $nos"