[vala-tests] test-common.sh: improve common test script
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala-tests] test-common.sh: improve common test script
- Date: Fri, 19 Mar 2010 23:45:26 +0000 (UTC)
commit 409b1db786cd30875e151aecc222daf9e50b68bc
Author: Marc-André Lureau <marcandre lureau gmail com>
Date: Fri Mar 19 22:27:05 2010 +0100
test-common.sh: improve common test script
common.sh | 199 +++++++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 142 insertions(+), 57 deletions(-)
---
diff --git a/common.sh b/common.sh
index 29a2757..223baa9 100644
--- a/common.sh
+++ b/common.sh
@@ -1,37 +1,27 @@
#!/bin/bash
-SRCDIR=`dirname $0`
-[ -z "$VALAC" ] && VALAC=valac
-VALACEXIT="${VALACEXIT:-0}"
-VALAFLAGS="${VALAFLAGS:-}"
-
-TESTNAME=`basename $0 .test`
-TESTSRC="${TESTSRC:-$SRCDIR/$TESTNAME.vala}"
-TESTENV="${TESTENV:-G_DEBUG=fatal_warnings}"
-[ -n "$BUGID" ] && BUGZILLA="http://bugzilla.gnome.org/show_bug.cgi?id=$BUGID"
-
-VALGRINDENV="${VALGRINDENV:-G_SLICE=always-malloc G_DEBUG=gc-friendly GLIBCPP_FORCE_NEW=1 GLIBCXX_FORCE_NEW=1}"
-VALGRINDFLAGS="${VALGRINDFLAGS:---tool=memcheck --leak-check=full --error-exitcode=1 -q}"
-
-while true ; do
- case "$1" in
- --interact)
- INTERACT=1 ;
- shift ;;
- --memcheck)
- VALGRIND="valgrind" ;
- shift ;;
- --massif)
- VALGRIND="valgrind" ;
- VALGRINDFLAGS="--tool=massif --massif-out-file=$TESTNAME.massif -q" ;
- shift ;;
- --) shift ; break ;;
- *) break ;;
- esac
-done
+function _test_get_args {
+ while true ; do
+ case "$1" in
+ --interact)
+ INTERACT=1 ;
+ shift ;;
+ --memcheck)
+ VALGRIND="valgrind" ;
+ shift ;;
+ --massif)
+ VALGRIND="valgrind" ;
+ VALGRINDFLAGS="--tool=massif --massif-out-file=$TESTNAME.massif -q" ;
+ shift ;;
+ --) shift ; break ;;
+ *) break ;;
+ esac
+ done
+}
# hackish
-function guess_packages {
+function _test_make_guesses {
+ ! grep "main" $TESTSRC >/dev/null && TESTRUN="${TESTRUN:-no}" VALAFLAGS="${VALAFLAGS:- -C}"
grep "Gtk" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg gtk+-2.0" TESTRUN="${TESTRUN:-interact}"
grep -i " gio" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg gio-2.0"
grep "DBus\." $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg dbus-glib-1" TESTRUN="${TESTRUN:-skip}"
@@ -56,31 +46,126 @@ function guess_packages {
grep "Curses" $TESTSRC >/dev/null && PACKAGES="$PACKAGES --pkg curses -X -lncurses" TESTRUN="${TESTRUN:-interact}"
}
-[ -z "$PACKAGES" ] && guess_packages
-
-sh -x -c "$VALAC $PACKAGES -o $TESTNAME $TESTSRC $VALAFLAGS"
-exitval="$?"
-
-if [ "$exitval" -ne "$VALACEXIT" ]; then
- echo ""
- echo "*** WARNING: valac was expecting to return $VALACEXIT, != $exitval ***"
- echo ""
- [ -n "$BUGZILLA" ] && echo "Visit bug: $BUGZILLA"
- exit 1
-fi
-
-export TESTENV
-export VALGRINDENV
-TESTRUN="${TESTRUN:-yes}"
-if [ -n "$INTERACT" -o "x$TESTRUN" = "xyes" ]; then
- if [ -z $VALGRIND ] ; then
- sh -c "./$TESTNAME $TESTARGS $@"
- else
- sh -c "$VALGRIND $VALGRINDFLAGS ./$TESTNAME $TESTARGS $@"
- fi
- exit $?
-else
- echo ""
- [ "x$TESTRUN" = "xinteract" ] && echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
-fi
+function _test_setup() {
+
+ TESTNAME=`basename $0 .test`
+ SRCDIR=`dirname $0`
+ TESTSRC="${TESTSRC:-$SRCDIR/$TESTNAME.vala}"
+ echo $TESTRUN
+ _test_make_guesses
+ TESTRUN="${TESTRUN:-yes}"
+ TESTENV="${TESTENV:-G_DEBUG=fatal_warnings}"
+ TESTEXIT="${TESTEXIT:-0}"
+ if [ "$TESTEXIT" -eq 0 ]; then
+ TESTV="${TESTV:-1}"
+ else
+ TESTV="${TESTV:-0}"
+ fi
+ [ "$TESTNAME" -gt 0 2>/dev/null ] && BUGID="${BUGID:-$TESTNAME}"
+ [ -n "$BUGID" ] && BUGZILLA="http://bugzilla.gnome.org/show_bug.cgi?id=$BUGID"
+
+ VALAC="${VALAC:-valac}"
+ VALACEXIT="${VALACEXIT:-0}"
+ VALAFLAGS="${VALAFLAGS:-}"
+ if [ "$VALACEXIT" -eq 0 ]; then
+ VALAV="${VALAV:-1}"
+ else
+ VALAV="${VALAV:-0}"
+ fi
+
+ VALGRINDENV="${VALGRINDENV:-G_SLICE=always-malloc G_DEBUG=gc-friendly GLIBCPP_FORCE_NEW=1 GLIBCXX_FORCE_NEW=1}"
+ VALGRINDFLAGS="${VALGRINDFLAGS:---tool=memcheck --leak-check=full --error-exitcode=1 -q}"
+
+ _test_get_args "$@"
+
+ STDOUT=`mktemp`
+ STDERR=`mktemp`
+
+ trap _test_trap SIGHUP SIGINT SIGTERM
+
+ type test_setup >/dev/null 2>&1 && test_setup
+}
+
+function _test_trap {
+ _test_teardown
+ exit $exitval
+}
+
+function _test_compile_check {
+ # discard the test run if it didn't produce an executable
+ if [ "$exitval" != 0 ]; then
+ TESTRUN=
+ fi
+
+ if [ "$exitval" -ne "$VALACEXIT" ]; then
+ echo ""
+ echo "*** WARNING: valac was expecting to return $VALACEXIT (got $exitval) ***"
+ [ -n "$BUGZILLA" ] && echo "*** Original bug: $BUGZILLA"
+ echo ""
+ else
+ exitval=0
+ fi
+
+ type test_compile_check >/dev/null 2>&1 && test_compile_check
+
+ if [ "$VALAV" = 1 ]; then
+ cat $STDOUT
+ cat $STDERR
+ fi
+}
+
+function _test_compile {
+ compile="$VALAC $PACKAGES -o $TESTNAME $TESTSRC $VALAFLAGS"
+ echo "$compile"
+ sh -c "$compile" >$STDOUT 2>$STDERR
+ exitval="$?"
+ _test_compile_check
+}
+
+function _test_run_check {
+ if [ "$exitval" -ne "$TESTEXIT" ]; then
+ echo ""
+ echo "*** WARNING: $TESTNAME was expecting to return $TESTEXIT (got $exitval) ***"
+ echo ""
+ [ -n "$BUGZILLA" ] && echo "original bug: $BUGZILLA"
+ else
+ exitval=0
+ fi
+
+ type test_run_check >/dev/null 2>&1 && test_run_check
+ if [ "$TESTV" = 1 ]; then
+ cat $STDOUT
+ cat $STDERR
+ fi
+}
+
+function _test_run {
+ [ -n "$VALGRIND" ] && TESTENV="$TESTENV $VALGRINDENV" VALGRIND="$VALGRIND $VALGRINDFLAGS"
+
+ if [ -z "$TESTRUN" -o "x$TESTRUN" = "xno" -o "x$TESTRUN" = "xskip" ]; then
+ # skip
+ true
+ elif [ -z "$INTERACT" -a "x$TESTRUN" = "xinteract" ]; then
+ echo "*** WARNING: This vala test is interactive and will not be run (try --interact) ***"
+ else
+ sh -c "$TESTENV $VALGRIND ./$TESTNAME $TESTARGS $@" >$STDOUT 2>$STDERR
+ exitval="$?"
+ _test_run_check
+ fi
+}
+
+function _test_teardown {
+ rm -f $STDOUT $STDERR $SRCDIR/$TESTNAME{,.c,.h}
+ type test_teardown >/dev/null 2>&1 && test_teardown
+}
+
+function test_fail {
+ _test_teardown
+ exit 1
+}
+_test_setup "$@"
+_test_compile
+_test_run
+_test_teardown
+exit $exitval
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]