tests.sh: run junit2html to render xml files
[nit.git] / tests / tests.sh
index 77da70a..2aff98a 100755 (executable)
 
 # Set lang do default to avoid failed tests because of locale
 export LANG=C.UTF-8
-export LC_ALL=C.UTF-8
+
+# Explore candidates for LC_ALL
+#
+# If C.UTF-8, the most agnostic UTF-8 locale is supported, we
+# use it, otherwise we default to the UTF-8 system locale, and
+# if unavailable, we default on C.
+#
+# Note that C however is not guaranteed to be UTF-8, and
+# some tests may fail when relying on Unicode semantics.
+locale_candidate=C.UTF-8
+if ! locale -a 2>/dev/null | grep -q C.UTF-8; then
+       locale_candidate="$(locale -a | grep -i utf8 | head -n1)"
+       if [ -z "$locale_candidate" ]; then
+               locale_candidate=C
+       fi
+fi
+export LC_ALL="$locale_candidate"
+
 if uname | grep Darwin 1>/dev/null 2>&1; then
        export LANG=en_US.UTF-8
        export LC_ALL=en_US.UTF-8
@@ -30,16 +47,28 @@ export NIT_TESTING=true
 export NIT_TESTING_ID=$$
 export NIT_SRAND=0
 
+# Identify this as a tests.sh test to differentiate from a nitunit test
+export NIT_TESTING_TESTS_SH=true
+
 unset NIT_DIR
 
 # Get the first Java lib available
 if which_java=$(which javac 2>/dev/null); then
-       JAVA_HOME=$(dirname $(dirname $(readlink -f "$which_java")))
+
+       if sh -c "readlink -f ." 1>/dev/null 2>&1; then
+               READLINK="readlink -f"
+       else
+               # Darwin?
+               READLINK="readlink"
+       fi
+       JAVA_HOME=$(dirname $(dirname $($READLINK "$which_java")))
 
        shopt -s nullglob
        paths=`echo $JAVA_HOME/jre/lib/*/{client,server}/libjvm.so`
-       paths=($paths)
-       JNI_LIB_PATH=`dirname ${paths[0]}`
+       if [ -n "$paths" ]; then
+               paths=($paths)
+               JNI_LIB_PATH=`dirname ${paths[0]}`
+       fi
        shopt -u nullglob
 fi
 
@@ -378,6 +407,11 @@ need_skip()
                echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
                return 0
        fi
+       if test -n "GITLAB_CI" && echo "$1" | grep -f "gitlab_ci.skip" >/dev/null 2>&1; then
+               echo "=> $2: [skip gitlab ci]"
+               echo >>$xml "<testcase classname='`xmlesc "$3"`' name='`xmlesc "$2"`' `timestamp`><skipped/></testcase>"
+               return 0
+       fi
 
        # Skip by OS
        local os_skip_file=$UNAME.skip
@@ -543,6 +577,7 @@ case $engine in
 esac
 
 savdirs="sav/`$HOSTNAME` sav/$UNAME sav/$engine $savdirs sav/"
+test -n "$GITLAB_CI" && savdirs="sav/gitlab_ci $savdirs"
 
 # The default nitc compiler
 [ -z "$NITC" ] && find_nitc
@@ -807,6 +842,10 @@ fi
 
 echo >>$xml "</testsuite></testsuites>"
 
+if type junit2html >/dev/null; then
+       junit2html "$xml"
+fi
+
 if [ -n "$nok" ]; then
        exit 1
 else