From: Jim Meyering Date: Sun, 16 Jan 2011 14:36:07 +0000 (+0100) Subject: test defs: new subroutines for test skipping/failing. X-Git-Tag: v1.12.0b~340 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d8f365af42b559f1ae46544c2238febfca664f3a;p=platform%2Fupstream%2Fautomake.git test defs: new subroutines for test skipping/failing. * tests/defs.in (Exit): Move definition of this function earlier. (warn_, skip_, fail_, framework_failure_): New functions, inspired to the homonyms in gnulib's tests/init.sh. ($stderr_fileno_): New global variable, used by the new functions above. * tests/README: Updated. From a suggestion by Ralf Wildenhues. --- diff --git a/ChangeLog b/ChangeLog index 1764e86..5963deb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-04-23 Jim Meyering + Stefano Lattarini + + test defs: new subroutines for test skipping/failing + * tests/defs.in (Exit): Move definition of this function earlier. + (warn_, skip_, fail_, framework_failure_): New functions, inspired + to the homonyms in gnulib's tests/init.sh. + ($stderr_fileno_): New global variable, used by the new functions + above. + * tests/README: Updated. + From a suggestion by Ralf Wildenhues. + 2011-04-23 Stefano Lattarini tests: fix typo (copy & paste blunder) in heading comment diff --git a/tests/README b/tests/README index 93f9cbf..26ce3ff 100644 --- a/tests/README +++ b/tests/README @@ -100,6 +100,11 @@ Do Include ./defs in every test script (see existing tests for examples of how to do this). + Use the `skip_' function to skip tests, with a meaningful message if + possible. Where convenient, use the `warn_' function to print generic + warnings, and the `fail_' function for test failures. Finally, you may + use the `framework_fail_' function for hard errors. + For tests that use the `parallel-tests' Automake option, set the shell variable `parallel_tests' to "yes" before including ./defs. Also, use for them a name that ends in `-p.test' and does not clash with any diff --git a/tests/defs.in b/tests/defs.in index ef35d9f..4e0db16 100644 --- a/tests/defs.in +++ b/tests/defs.in @@ -122,6 +122,32 @@ echo "$PATH" # (See note about `export' in the Autoconf manual.) export PATH +# We use a trap below for cleanup. This requires us to go through +# hoops to get the right exit status transported through the signal. +# So use `Exit STATUS' instead of `exit STATUS' inside of the tests. +# Turn off errexit here so that we don't trip the bug with OSF1/Tru64 +# sh inside this function. +Exit () +{ + set +e + (exit $1) + exit $1 +} + +# Print warnings (e.g., about skipped and failed tests) to this file +# number. Override by putting, say: +# stderr_fileno_=9; export stderr_fileno_; exec 9>&2; +# in the definition of AM_TESTS_ENVIRONMENT. +# This is useful when using automake's parallel tests mode, to print the +# reason for skip/failure to console, rather than to the *.log files. +: ${stderr_fileno_=2} + +# Copied from Gnulib's `tests/init.sh'. +warn_ () { echo "$@" 1>&$stderr_fileno_; } +fail_ () { warn_ "$me: failed test: $@"; Exit 1; } +skip_ () { warn_ "$me: skipped test: $@"; Exit 77; } +framework_failure_ () { warn_ "$me: set-up failure: $@"; Exit 99; } + for tool in : $required do # Check that each required tool is present. @@ -278,18 +304,6 @@ case "$srcdir" in ;; esac -# We use a trap below for cleanup. This requires us to go through -# hoops to get the right exit status transported through the signal. -# So use `Exit STATUS' instead of `exit STATUS' inside of the tests. -# Turn off errexit here so that we don't trip the bug with OSF1/Tru64 -# sh inside this function. -Exit () -{ - set +e - (exit $1) - exit $1 -} - curdir=`pwd` testSubDir=$me.dir test ! -d $testSubDir || {