Add cron for running misc tests (Closes #1036)
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Fri, 28 May 2010 23:31:49 +0000 (01:31 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Tue, 8 Jun 2010 07:19:37 +0000 (09:19 +0200)
* make test

Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
bin/cron/run_tests.sh [new file with mode: 0755]

diff --git a/bin/cron/run_tests.sh b/bin/cron/run_tests.sh
new file mode 100755 (executable)
index 0000000..9e11558
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+CRONDIR=$(dirname $0)
+PWD=$(pwd)
+PLATAL_ROOT=${CRONDIR}/../..
+
+# Executes a command and displays its output only if retcode != 0
+# @param dir Folder from which the command should be called
+# @param cmd The command to execute
+# After execution, the pwd is returned to its initial value.
+function print_if_err {
+    local dir cmd retcode tmpfile
+    dir=$1
+    cmd=$2
+
+    echo "* Running ${cmd}..."
+    # Capture output and return code
+    tmpfile=$(mktemp pl_run_tests.XXXXXX)
+    cd ${dir} && ${cmd} 2>&1 > ${tmpfile}
+    retcode=$?
+
+    if [ "x${retcode}" != "x0" ]; then
+        echo "** Error running command ${cmd} (code ${retcode})"
+        cat ${tmpfile}
+        rm -f ${tmpfile}
+        exit ${retcode}
+    fi
+
+    # Cleanup
+    rm -f ${tmpfile}
+    cd ${PWD}
+}
+
+print_if_err ${PLATAL_ROOT} "make test"