From: Stefano Lattarini Date: Fri, 3 Dec 2010 14:24:14 +0000 (+0100) Subject: testsuite: use $SHELL to run tests which are shell scripts X-Git-Tag: ng-0.5a~89^2~221 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1321be7068464238d1c626abad0f52cb1cd6cba2;p=thirdparty%2Fautomake.git testsuite: use $SHELL to run tests which are shell scripts * tests/Makefile.am (TEST_LOG_COMPILER): Define so that the configure-time $SHELL is used to run the tests. * tests/defs: Add code to re-execute by default the running test script with configure-time $SHELL. Updated comments. * configure.ac: Check that `set -e' is working for $SHELL, not for /bin/sh. * tests/defs-static.in: Update comments. * tests/README (Supported shells): Updated. (Getting details from failures): Don't tell that tests are run by /bin/sh by default. --- diff --git a/ChangeLog b/ChangeLog index 24183b73d..d3219af15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2011-05-27 Stefano Lattarini + + testsuite: use $SHELL to run tests which are shell scripts + * tests/Makefile.am (TEST_LOG_COMPILER): Define so that the + configure-time $SHELL is used to run the tests. + * tests/defs: Add code to re-execute by default the running + test script with configure-time $SHELL. Updated comments. + * configure.ac: Check that `set -e' is working for $SHELL, + not for /bin/sh. + * tests/defs-static.in: Update comments. + * tests/README (Supported shells): Updated. + (Getting details from failures): Don't tell that tests are + run by /bin/sh by default. + 2011-05-26 Stefano Lattarini tests: split 'subst2.test' to improve modularity and coverage diff --git a/configure b/configure index 084d8d254..723491cf1 100755 --- a/configure +++ b/configure @@ -2796,12 +2796,12 @@ $as_echo "$ac_cv_path_FGREP" >&6; } -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether /bin/sh has working 'set -e' with exit trap" >&5 -$as_echo_n "checking whether /bin/sh has working 'set -e' with exit trap... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $SHELL has working 'set -e' with exit trap" >&5 +$as_echo_n "checking whether $SHELL has working 'set -e' with exit trap... " >&6; } if ${am_cv_sh_errexit_works+:} false; then : $as_echo_n "(cached) " >&6 else - if /bin/sh -ec "trap 'exit \$?' 0; (exit 77); exit 77"; test $? = 77 + if $SHELL -ec "trap 'exit \$?' 0; (exit 77); exit 77"; test $? = 77 then am_cv_sh_errexit_works=yes else diff --git a/configure.ac b/configure.ac index 857177bb0..b6a5586d6 100644 --- a/configure.ac +++ b/configure.ac @@ -179,9 +179,9 @@ AC_SUBST([MODIFICATION_DELAY]) AC_PROG_EGREP AC_PROG_FGREP -AC_CACHE_CHECK([whether /bin/sh has working 'set -e' with exit trap], +AC_CACHE_CHECK([whether $SHELL has working 'set -e' with exit trap], [am_cv_sh_errexit_works], -[if /bin/sh -ec "trap 'exit \$?' 0; (exit 77); exit 77"; test $? = 77 +[if $SHELL -ec "trap 'exit \$?' 0; (exit 77); exit 77"; test $? = 77 then am_cv_sh_errexit_works=yes else diff --git a/tests/Makefile.am b/tests/Makefile.am index 09adc6517..d8f859901 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -20,6 +20,8 @@ MAINTAINERCLEANFILES = EXTRA_DIST = ChangeLog-old TEST_EXTENSIONS = .test +# Run the tests with the shell detected at configure time. +TEST_LOG_COMPILER = $(SHELL) XFAIL_TESTS = \ all.test \ @@ -109,12 +111,17 @@ $(depmod_tests): # test scripts, but not from the environment. # We want warning messages and explanations for skipped tests to go to # the console if possible, so set up `stderr_fileno_' properly. +# The `AM_TESTS_REEXEC=no' setting tells the tests not to needlessly +# re-execute themselves with the shell detected at configure time, since +# we are already running them under it explicitly in our setup (see e.g. +# the definition of TEST_LOG_COMPILER above). AM_TESTS_ENVIRONMENT = \ test x"$$me" = x || unset me; \ test x"$$required" = x || unset required; \ test x"$$parallel_tests" = x || unset parallel_tests; \ test x"$$original_AUTOMAKE" = x || unset original_AUTOMAKE; \ test x"$$original_ACLOCAL" = x || unset original_ACLOCAL; \ + AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC; \ exec 9>&2; stderr_fileno_=9; export stderr_fileno_; TESTS = \ diff --git a/tests/Makefile.in b/tests/Makefile.in index ad8b2c03c..b64da1f1f 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -299,6 +299,8 @@ MAINTAINERCLEANFILES = $(parallel_tests) EXTRA_DIST = ChangeLog-old gen-parallel-tests instspc-tests.sh \ depmod-tests.sh $(handwritten_tests) $(generated_tests) TEST_EXTENSIONS = .test .instspc .depmod +# Run the tests with the shell detected at configure time. +TEST_LOG_COMPILER = $(SHELL) XFAIL_TESTS = all.test auxdir2.test cond17.test gcj6.test \ override-conditional-2.test pr8365-remake-timing.test \ yacc-dist-nobuild-subdir.test txinfo5.test \ @@ -377,12 +379,17 @@ DEPMOD_LOG_COMPILER = $(SHELL) $(srcdir)/depmod-tests.sh # test scripts, but not from the environment. # We want warning messages and explanations for skipped tests to go to # the console if possible, so set up `stderr_fileno_' properly. +# The `AM_TESTS_REEXEC=no' setting tells the tests not to needlessly +# re-execute themselves with the shell detected at configure time, since +# we are already running them under it explicitly in our setup (see e.g. +# the definition of TEST_LOG_COMPILER above). AM_TESTS_ENVIRONMENT = \ test x"$$me" = x || unset me; \ test x"$$required" = x || unset required; \ test x"$$parallel_tests" = x || unset parallel_tests; \ test x"$$original_AUTOMAKE" = x || unset original_AUTOMAKE; \ test x"$$original_ACLOCAL" = x || unset original_ACLOCAL; \ + AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC; \ exec 9>&2; stderr_fileno_=9; export stderr_fileno_; TESTS = \ diff --git a/tests/README b/tests/README index 14a128d32..2db4e2256 100644 --- a/tests/README +++ b/tests/README @@ -61,10 +61,10 @@ Interpretation Getting details from failures ----------------------------- - Each test is a shell script, and by default is run by /bin/sh. - In a non-VPATH build you can run them directly, they will be verbose. - By default, verbose output of a test foo.test is retained in the log - file foo.log. A summary log is created in the file test-suite.log. + Each test is a shell script. In a non-VPATH build you can run the + tests directly, they will be verbose. By default, verbose output of + a test foo.test is retained in the log file foo.log. A summary log + is created in the file test-suite.log. You can limit the set of files using the TESTS variable, and enable detailed test output at the end of the test run with the VERBOSE @@ -76,6 +76,20 @@ Getting details from failures Supported shells ---------------- + By default, the tests are run by the $SHELL detected at configure + time. They also take care to re-execute themselves with that shell, + unless told not to. So, to run the tests with a different shell, say + `/path/to/another/sh', the user must use: + + AM_TESTS_REEXEC=no /path/to/another/sh ./foo.test + + to run a test directly, and: + + make check TEST_LOG_COMPILER=/path/to/sh (GNU make) + TEST_LOG_COMPILER=/path/to/sh make -e check (non-GNU make) + + to run the test(s) through the makefile test driver. + The test scripts are written with portability in mind, so that they should run with any decent Bourne-compatible shell. @@ -87,7 +101,7 @@ Supported shells version of Zsh is used. Thus, if you want to run a test script, say foo.test, with Zsh 4.2, you *can't* simply do `zsh foo.test', but you *must* resort to: - zsh -o no_function_argzero foo.test + AM_TESTS_REEXEC=no zsh -o no_function_argzero foo.test Note that this problem does not occur if Zsh is executed through a symlink with a basename of `sh', since in that case Zsh starts diff --git a/tests/defs b/tests/defs index e3c922c6b..5494625b0 100644 --- a/tests/defs +++ b/tests/defs @@ -17,6 +17,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . + +# IMPORTANT NOTE: This file should execute correctly with any system's +# /bin/sh shell, and not only with configure-time detected $CONFIG_SHELL, +# until differently and explicitly specified. + + ## -------------------------------------------------------- ## ## Source static setup and definitions for the testsuite. ## ## -------------------------------------------------------- ## @@ -42,9 +48,9 @@ if test -z "$me"; then || { echo "$argv0: failed to define \$me" >&2; exit 99; } fi -## ---------------------------------------- ## -## Sanity checks and environment cleanup. ## -## ---------------------------------------- ## +## ---------------------- ## +## Early sanity checks. ## +## ---------------------- ## # A single whitespace character. sp=' ' @@ -70,6 +76,48 @@ test -f "$testbuilddir/defs-static" || { exit 99 } +# Ensure we can find ourselves. +test -f "$0" || { + echo "$me: unable to find myself: $0" >&2 + exit 1 +} + + +## ------------------------------------ ## +## Ensure we run with a proper shell. ## +## ------------------------------------ ## + +# Make sure we run with the shell detected at configure time (unless +# the user forbids it). +case ${AM_TESTS_REEXEC-yes} in + n|no|false|0) + ;; + *) + AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC + # Cannot simply do `opts=$-', since the content of $- is not + # portable among different shells. So try to propagate only + # the portable and interesting options. + case $- in + *x*v*|*v*x) opts=-vx;; + *v*) opts=-v;; + *x*) opts=-x;; + *) opts=;; + esac + echo $me: exec $SHELL $opts "$0" "$*" + exec $SHELL $opts "$0" ${1+"$@"} + echo "$me: failed to re-execute with $SHELL" >&2 + exit 99 + ;; +esac + +# NOTE: From this point on, we can assume this file is being executed +# by the configure-time detected $CONFIG_SHELL. + + +## ---------------------- ## +## Environment cleanup. ## +## ---------------------- ## + # Unset some MAKE... variables that may cause $MAKE to act like a # recursively invoked sub-make. Any $MAKE invocation in a test is # conceptually an independent invocation, not part of the main diff --git a/tests/defs-static.in b/tests/defs-static.in index df5072f3c..8f64dc624 100644 --- a/tests/defs-static.in +++ b/tests/defs-static.in @@ -19,8 +19,12 @@ # along with this program. If not, see . # Defines and minimal setup for Automake testing environment. -# Multiple inclusions of this file should be idempotent! -# This code needs to be 'set -e' clean. + +# IMPORTANT NOTES AND REQUIREMENTS +# - Multiple inclusions of this file should be idempotent. +# - This code has to be 'set -e' clean. +# - This file should execute correctly with any system's /bin/sh +# shell, not only with configure-time detected $CONFIG_SHELL. # Be more Bourne compatible. # (Snippet inspired to configure's initialization in Autoconf 2.64) @@ -133,7 +137,7 @@ FGREP='@FGREP@' # this variable. TEX='@TEX@' -# Whether /bin/sh has working 'set -e' with exit trap. +# Whether $SHELL has working 'set -e' with exit trap. sh_errexit_works='@sh_errexit_works@' # The amount we should wait after modifying files depends on the platform.