This is just a preparatory refactoring for future changes. * configure.ac (AM_TEST_RUNNER_SHELL): New variable, defined to $SHEL', and AC_SUBST'd. * Makefile.am (LOG_COMPILER): Redefine from $(SHELL) to $(AM_TEST_RUNNER_SHELL). * defs: Adjust to use $AM_TEST_RUNNER_SHELL instead of $CONFIG_SHELL and/or $SHELL, where appropriate. Minor opportunistic changes. * t/self-check-explicit-skips.sh: Likewise. * t/self-check-sanity.sh: Likewise. * t/self-check-tap.sh: Likewise. * t/self-check-cleanup.tap: Likewise. * t/self-check-dir.tap: Likewise. * t/self-check-env-sanitize.tap: Likewise. * t/self-check-exit.tap: Likewise. * t/self-check-me.tap: Likewise. * t/self-check-reexec.tap: Likewise.
Signed-off-by: Stefano Lattarini <stefano.lattar...@gmail.com> --- Makefile.am | 4 ++-- configure.ac | 4 ++++ defs | 10 +++++----- defs-static.in | 8 +++++++- t/self-check-cleanup.tap | 17 ++++++++++------- t/self-check-dir.tap | 9 +++++---- t/self-check-env-sanitize.tap | 4 ++-- t/self-check-exit.tap | 22 ++++++++++++---------- t/self-check-explicit-skips.sh | 15 +++++++++------ t/self-check-me.tap | 8 ++++---- t/self-check-reexec.tap | 18 ++++++++++++------ t/self-check-sanity.sh | 8 ++++---- t/self-check-tap.sh | 16 +++++++++------- 13 files changed, 85 insertions(+), 58 deletions(-) diff --git a/Makefile.am b/Makefile.am index aab2786..0b79a16 100644 --- a/Makefile.am +++ b/Makefile.am @@ -315,8 +315,8 @@ EXTRA_DIST += m4/amversion.in ## Testsuite. ## ## ------------ ## -# Run the tests with the shell detected at configure time. -LOG_COMPILER = $(SHELL) +# Run the tests with a proper shell detected at configure time. +LOG_COMPILER = $(AM_TEST_RUNNER_SHELL) TEST_EXTENSIONS = .pl .sh .tap SH_LOG_COMPILER = $(LOG_COMPILER) diff --git a/configure.ac b/configure.ac index bda0328..8f3d40f 100644 --- a/configure.ac +++ b/configure.ac @@ -209,6 +209,10 @@ AC_SUBST([MODIFICATION_DELAY]) AC_PROG_EGREP AC_PROG_FGREP +# Shell used to run our test scripts. The same as $SHELL/$CONFIG_SHELL +# for the moment. +AC_SUBST([AM_TEST_RUNNER_SHELL], [$SHELL]) + AC_CACHE_CHECK([whether $SHELL has working 'set -e' with exit trap], [am_cv_sh_errexit_works], [if $SHELL -ec "trap 'exit \$?' 0; (exit 77); exit 77"; test $? = 77 diff --git a/defs b/defs index 7e9a554..dd1631a 100644 --- a/defs +++ b/defs @@ -20,7 +20,7 @@ ######################################################## # NOTE: This file should execute correctly with any system's /bin/sh -# shell, and not only with configure-time detected $CONFIG_SHELL, +# shell, and not only with configure-time detected $AM_TEST_RUNNER_SHELL, # *until differently and explicitly specified*. ## -------------------------------------------------------- ## @@ -105,16 +105,16 @@ case ${AM_TESTS_REEXEC-yes} in *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 + echo $me: exec $AM_TEST_RUNNER_SHELL $opts "$0" "$*" + exec $AM_TEST_RUNNER_SHELL $opts "$0" ${1+"$@"} || { + echo "$me: failed to re-execute with $AM_TEST_RUNNER_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. +# by the configure-time detected $AM_TEST_RUNNER_SHELL. ## ----------------------- ## diff --git a/defs-static.in b/defs-static.in index a8a17f0..30e3253 100644 --- a/defs-static.in +++ b/defs-static.in @@ -22,7 +22,8 @@ # - 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. +# shell, not only with configure-time detected $SHELL and/or +# $AM_TEST_RUNNER_SHELL. # Be more Bourne compatible. # (Snippet inspired to configure's initialization in Autoconf 2.64) @@ -137,6 +138,11 @@ PATH_SEPARATOR='@PATH_SEPARATOR@' host_alias=${host_alias-'@host_alias@'}; export host_alias build_alias=${build_alias-'@build_alias@'}; export build_alias +# The shell we use to run our own test scripts, determined at configure +# time. It is required in the self tests, and most importantly for the +# the automatic re-execution of test scripts. +AM_TEST_RUNNER_SHELL='@AM_TEST_RUNNER_SHELL@' + # Make sure we override the user shell. And do not read the value of # $SHELL from the environment (think to the non-uncommon situation where # e.g., $SHELL=/bin/tcsh). diff --git a/t/self-check-cleanup.tap b/t/self-check-cleanup.tap index a56854b..215472a 100755 --- a/t/self-check-cleanup.tap +++ b/t/self-check-cleanup.tap @@ -58,7 +58,8 @@ do_clean () # the cleanup code not to be run, so that the temporary directories # are left on disk. command_ok_ '"keep_testdirs=yes" causes testdir to be kept around' eval ' - keep_testdirs=yes $SHELL -c ". ./defs && echo okok >foo" t/dummy.sh \ + env keep_testdirs=yes \ + $AM_TEST_RUNNER_SHELL -c ". ./defs && echo okok >foo" t/dummy.sh \ && test -f t/dummy.dir/foo \ && test okok = `cat t/dummy.dir/foo`' @@ -79,7 +80,7 @@ chmod 000 t/dummy.dir/sub/* t/dummy.dir/file test $have_symlinks = yes && chmod 000 t/dummy.dir/symlink chmod 500 t/dummy.dir/sub t/dummy.dir command_ok_ "pre-cleanup can deal with low-perms testdir" \ - $SHELL -c '. ./defs' t/dummy.sh + $AM_TEST_RUNNER_SHELL -c '. ./defs' t/dummy.sh command_ok_ "pre-cleanup removed low-perms testdir" \ eval 'test ! -f t/dummy.dir \ && test ! -d t/dummy.dir \ @@ -90,7 +91,7 @@ do_clean # Check that post-test cleanup works also with directories with # "null" permissions, and containing broken symlinks. command_ok_ "post-cleanup can deal with low-perms testdir" \ - $SHELL -c ' + $AM_TEST_RUNNER_SHELL -c ' stderr_fileno_=2 . ./defs || Exit 1 set -e @@ -127,7 +128,7 @@ if test $have_symlinks = yes; then (cd t/dummy.dir && ln -s ../../dir ../../file .) command_ok_ "pre-cleanup with testdir with zero-perms symlinks" \ - $SHELL -c '. ./defs' t/dummy.sh + $AM_TEST_RUNNER_SHELL -c '. ./defs' t/dummy.sh ls -l # For debugging. command_ok_ "pre-cleanup chmod doesn't follow symlinks to files" \ eval 'ls -l file | grep "^----------.*file"' @@ -135,7 +136,7 @@ if test $have_symlinks = yes; then eval 'ls -ld dir | grep "^d---------.*dir"' command_ok_ "post-cleanup with testdir with zero-perms symlinks" \ - $SHELL -c ' + $AM_TEST_RUNNER_SHELL -c ' ocwd=`pwd` || exit 1 stderr_fileno_=2 . ./defs || Exit 1 @@ -162,7 +163,8 @@ do_clean # or when receiving a signal. for st in 1 2 3 10 77 99 126 127 130 255; do - command_ok_ "exit trap doesn't clobber exit status $st" not $SHELL -c " + command_ok_ "exit trap doesn't clobber exit status $st" \ + not $AM_TEST_RUNNER_SHELL -c " stderr_fileno_=2 . ./defs : > foo @@ -178,7 +180,8 @@ for sig in 1 2 3 9 13 15; do skip_row_ 2 -r "signal $sig seems blocked" continue fi - command_ok_ "exit trap doesn't clobber signal $sig" not $SHELL -c " + command_ok_ "exit trap doesn't clobber signal $sig" \ + not $AM_TEST_RUNNER_SHELL -c " stderr_fileno_=2 . ./defs : > foo diff --git a/t/self-check-dir.tap b/t/self-check-dir.tap index 736238c..424367e 100755 --- a/t/self-check-dir.tap +++ b/t/self-check-dir.tap @@ -27,16 +27,17 @@ plan_ 5 AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC keep_testdirs=; unset keep_testdirs -# This needs to be consistent with what $SHELL deems to be the -# current working directory. -cwd=`$SHELL -c 'pwd'` || fatal_ "can't get current working directory" +# This needs to be consistent with what $AM_TEST_RUNNER_SHELL +# deems to be the current working directory. +cwd=`$AM_TEST_RUNNER_SHELL -c 'pwd'` \ + || fatal_ "can't get current working directory" echo "$cwd" do_check () { test ! -d _self.dir || rm -rf _self.dir \ || framework_failure_ "cleaning up _self.dir" - command_ok_ "$1 [$2]" $SHELL -c " + command_ok_ "$1 [$2]" $AM_TEST_RUNNER_SHELL -c " $2 . ./defs || Exit 99 # Don't fail if 'ls -l' fails; avoids possible racy spurious failures. diff --git a/t/self-check-env-sanitize.tap b/t/self-check-env-sanitize.tap index d4e6cdb..bc78186 100755 --- a/t/self-check-env-sanitize.tap +++ b/t/self-check-env-sanitize.tap @@ -40,12 +40,12 @@ vars=' do_run () { - env "$1=foo" $SHELL -c '. ./defs' foo.test + env "$1=foo" $AM_TEST_RUNNER_SHELL -c '. ./defs' foo.test } do_grep () { - env "$1=foo" $SHELL -c '. ./defs' foo.test 2>&1 1>&5 \ + env "$1=foo" $AM_TEST_RUNNER_SHELL -c '. ./defs' foo.test 2>&1 1>&5 \ | grep "foo\.test:.* variable '$1'.* in the environment.*unsafe" } diff --git a/t/self-check-exit.tap b/t/self-check-exit.tap index c866dbc..e8d96df 100755 --- a/t/self-check-exit.tap +++ b/t/self-check-exit.tap @@ -38,12 +38,12 @@ AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC init='stderr_fileno_=2; unset am_explicit_skips; . ./defs' # Required so that the code in defs doesn't go crazy trying to creating a -# temporary directory in the absolute dir of $SHELL. +# temporary directory in the absolute dir of $AM_TEST_RUNNER_SHELL. dummy_test_script=t/$me.sh for st in 1 2 3 4 5 77 99 126 127 128 129 130 255; do for exit_cmd in "Exit $st" "sh -c 'exit $st'"; do - $SHELL -c "$init; $exit_cmd; :" "$dummy_test_script" + $AM_TEST_RUNNER_SHELL -c "$init; $exit_cmd; :" "$dummy_test_script" command_ok_ "$exit_cmd" test $? -eq $st done done @@ -54,12 +54,12 @@ for sig in 1 2 13 15; do continue fi if test $sig -eq 2; then - # Some Korn shells might otherwise get a spurious SIGINT signal when - # one is sent to the child $SHELL. For more details, see: + # Some Korn shells might otherwise get a spurious SIGINT when one is + # sent to the child $AM_TEST_RUNNER_SHELL. For more details, see: # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html> trap : 2 fi - $SHELL -c "$init; kill -$sig \$\$; :" "$dummy_test_script" + $AM_TEST_RUNNER_SHELL -c "$init; kill -$sig \$\$; :" "$dummy_test_script" rc=$? if test $sig -eq 2; then # Reset default SIGINT handler as portably as possible. @@ -88,25 +88,27 @@ done # 3. a non-existing command is issued. # Note that the non-existent command is issued as the last command to # the shell in the next line; this is deliberate. -if $SHELL -c 'set -e; trap "exit \$?" 0; non-existent-program'; then +# FIXME: remove this workaround once we have a better configure-time +# determination of `$AM_TEST_RUNNER_SHELL'. +if $AM_TEST_RUNNER_SHELL -c 'set -e; trap "exit \$?" 0; non-existent-program'; then maybe_todo=TODO reason="known Solaris /bin/sh bug" else maybe_todo="" reason="" fi -$SHELL -c "$init; non-existent-program; :" "$dummy_test_script" +$AM_TEST_RUNNER_SHELL -c "$init; non-existent-prog; :" "$dummy_test_script" command_ok_ "command not found" -D "$maybe_todo" -r "$reason" \ -- test $? -gt 0 : Non-executable command. test -f Makefile && test ! -x Makefile || \ framowork_failure_ "no proper Makefile in the current directory" -$SHELL -c "$init; ./Makefile; :" "$dummy_test_script" +$AM_TEST_RUNNER_SHELL -c "$init; ./Makefile; :" "$dummy_test_script" command_ok_ "permission denied" test $? -gt 0 : Syntax errors in the test code. -$SHELL -c "$init; if :; then" "$dummy_test_script" +$AM_TEST_RUNNER_SHELL -c "$init; if :; then" "$dummy_test_script" command_ok_ "syntax error 1" test $? -gt 0 -$SHELL -c "$init; fi" "$dummy_test_script" +$AM_TEST_RUNNER_SHELL -c "$init; fi" "$dummy_test_script" command_ok_ "syntax error 2" test $? -gt 0 : diff --git a/t/self-check-explicit-skips.sh b/t/self-check-explicit-skips.sh index 3e7a77c..2b64fe1 100755 --- a/t/self-check-explicit-skips.sh +++ b/t/self-check-explicit-skips.sh @@ -35,22 +35,25 @@ set +e unset am_explicit_skips stderr_fileno_ AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC -$SHELL -c '. ./defs; (exit 77); exit 77' dummy.test +# I'm a lazy typist. +sh=$AM_TEST_RUNNER_SHELL + +$sh -c '. ./defs; (exit 77); exit 77' dummy.test test $? -eq 77 || Exit 1 -am_explicit_skips=no $SHELL -c '. ./defs; sh -c "exit 77"' dummy.test +am_explicit_skips=no $sh -c '. ./defs; sh -c "exit 77"' dummy.test test $? -eq 77 || Exit 1 -am_explicit_skips=yes $SHELL -c '. ./defs; (exit 77); exit 77' dummy.test +am_explicit_skips=yes $sh -c '. ./defs; (exit 77); exit 77' dummy.test test $? -eq 78 || Exit 1 -am_explicit_skips=y $SHELL -c '. ./defs; sh -c "exit 77"' dummy.test +am_explicit_skips=y $sh -c '. ./defs; sh -c "exit 77"' dummy.test test $? -eq 78 || Exit 1 -am_explicit_skips=yes $SHELL -c '. ./defs; Exit 77' dummy.test +am_explicit_skips=yes $sh -c '. ./defs; Exit 77' dummy.test test $? -eq 77 || Exit 1 -am_explicit_skips=y $SHELL -c '. ./defs; skip_ "foo"' dummy.test +am_explicit_skips=y $sh -c '. ./defs; skip_ "foo"' dummy.test test $? -eq 77 || Exit 1 : diff --git a/t/self-check-me.tap b/t/self-check-me.tap index 5c83ee6..cddc9b5 100755 --- a/t/self-check-me.tap +++ b/t/self-check-me.tap @@ -32,7 +32,7 @@ set +e do_check () { - $SHELL -c '. ./defs && echo me=$me' "$1" | grep "^me=$2$" + $AM_TEST_RUNNER_SHELL -c '. ./defs && echo me=$me' "$1" | grep "^me=$2$" command_ok_ "me=$1" test $? -eq 0 } @@ -48,7 +48,7 @@ do_check abc. 'abc\.' # If we override $me, ./defs should not modify it. -s=`$SHELL -c 'me=foo.sh && . ./defs && echo me=$me' bad.sh` +s=`$AM_TEST_RUNNER_SHELL -c 'me=foo.sh && . ./defs && echo me=$me' bad.sh` command_ok_ "override of \$me before ./defs causes no error" \ test $? -eq 0 @@ -59,8 +59,8 @@ result_ "$r" "override of \$me before ./defs is honored" unset r # Overriding $me after sourcing ./defs-static should work. -s=`$SHELL -c '. ./defs-static && me=zardoz && - . ./defs && echo me=$me' bad.sh` +s=`$AM_TEST_RUNNER_SHELL -c '. ./defs-static && me=zardoz && + . ./defs && echo me=$me' bad.sh` command_ok_ "override of \$me after ./defs-static causes no error" \ test $? -eq 0 diff --git a/t/self-check-reexec.tap b/t/self-check-reexec.tap index 8237c08..7b91008 100755 --- a/t/self-check-reexec.tap +++ b/t/self-check-reexec.tap @@ -16,7 +16,7 @@ # Sanity check for the automake testsuite. # Check that automatic re-execution of test script with the -# configure-time $SHELL. +# configure-time $AM_TEST_RUNNER_SHELL. am_create_testdir=empty . ./defs || Exit 1 @@ -32,7 +32,9 @@ cp "$am_top_builddir"/defs . || fatal_ "fetching 'defs' from top_builddir" # Search for required bash and non-bash shells. # -for bash_shell in "$SHELL" bash bash3 bash4 :; do +for bash_shell in \ + "$SHELL" "$AM_TEST_RUNNER_SHELL" bash bash3 bash4 : +do test "$bash_shell" = : && break $bash_shell --version || continue $bash_shell -c 'test -n "$BASH_VERSION"' || continue @@ -41,7 +43,9 @@ done # This might not be optimal, but it's much better than writing wrapper # scripts acting as "fake" shells. -for non_bash_shell in /bin/sh /bin/ksh "$SHELL" sh ksh ash dash pdksh :; do +for non_bash_shell in \ + /bin/sh /bin/ksh sh ksh ash dash pdksh "$SHELL" "$AM_TEST_RUNNER_SHELL" : +do test "$non_bash_shell" = : && break $non_bash_shell -c 'exit 0' || continue $non_bash_shell -c 'test -n "$BASH_VERSION"' && continue @@ -97,8 +101,9 @@ cat > need-bash.sh <<'END' (foo=abac && test xbxc = ${foo//a/x} && test -n "$BASH_VERSION") END +sh_var=AM_TEST_RUNNER_SHELL sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd'|" \ - -e 's|^SHELL=.*$|SHELL=bash; export SHELL|' \ + -e "s|^$sh_var=.*$|$sh_var=bash; export $sh_var|" \ < "$am_top_builddir"/defs-static >defs-static do_reexec () @@ -169,12 +174,13 @@ check_reexec_message () dir=$1; shift get_ddata "$dir" $sh "${dir}${dsep}dummy.sh" "$@" \ - | grep "^dummy: exec $SHELL ${dir}${dsep}dummy\\.sh $*\$" \ + | grep "^dummy: exec $AM_TEST_RUNNER_SHELL ${dir}${dsep}dummy\\.sh $*\$" \ && r='ok' || r='not ok' result_ "$r" "$sh display re-exec message [$dname] [args: $*]" } -./dummy.sh a b | grep "^dummy: exec $SHELL \\./dummy\\.sh a b$" \ +./dummy.sh a b \ + | grep "^dummy: exec $AM_TEST_RUNNER_SHELL \\./dummy\\.sh a b$" \ && r='ok' || r='not ok' result_ "$r" "direct run display re-exec message [args: a b]" diff --git a/t/self-check-sanity.sh b/t/self-check-sanity.sh index 64e489c..8e31afa 100755 --- a/t/self-check-sanity.sh +++ b/t/self-check-sanity.sh @@ -32,7 +32,7 @@ AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC source_defs=". '$am_top_builddir/defs'" -if $SHELL -c "$source_defs" dummy.test 2>stderr; then +if $AM_TEST_RUNNER_SHELL -c "$source_defs" dummy.sh 2>stderr; then show_stderr Exit 1 else @@ -42,7 +42,7 @@ fi sed 's|^am_top_srcdir=.*|am_top_srcdir=foo|' \ "$am_top_builddir"/defs-static > defs-static -if $SHELL -c "$source_defs" t/dummy.test 2>stderr; then +if $AM_TEST_RUNNER_SHELL -c "$source_defs" t/dummy.sh 2>stderr; then show_stderr Exit 1 else @@ -52,7 +52,7 @@ fi sed 's|^am_top_builddir=.*|am_top_builddir=foo|' \ "$am_top_builddir"/defs-static > defs-static -if $SHELL -c "$source_defs" t/dummy.test 2>stderr; then +if $AM_TEST_RUNNER_SHELL -c "$source_defs" t/dummy.sh 2>stderr; then show_stderr Exit 1 else @@ -71,7 +71,7 @@ env \ top_builddir=bad-dir top_srcdir=bad-dir \ abs_builddir=bad-dir abs_srcdir=bad-dir \ abs_top_builddir=bad-dir abs_top_srcdir=bad-dir \ - $SHELL -c "$source_defs && echo '!OK!' > ../foo" t/dummy.test + $AM_TEST_RUNNER_SHELL -c "$source_defs && echo '!OK!' > ../foo" t/dummy.sh $FGREP '!OK!' t/foo : diff --git a/t/self-check-tap.sh b/t/self-check-tap.sh index 6a2d132..d7f788c 100755 --- a/t/self-check-tap.sh +++ b/t/self-check-tap.sh @@ -22,19 +22,21 @@ set -ex -$SHELL -c '. ./defs-static && test $am_using_tap = yes' foo.tap -$SHELL -c '. ./defs-static && test $am_using_tap = no' foo.test -$SHELL -c '. ./defs-static && test $am_using_tap = no' tap -$SHELL -c '. ./defs-static && test $am_using_tap = no' tap.test -$SHELL -c '. ./defs-static && test $am_using_tap = no' foo-tap +$AM_TEST_RUNNER_SHELL -c \ + '. ./defs-static && test $am_using_tap = yes' foo.tap -$SHELL -c ' +for name in foo.test tap tap.test foo-tap; do + $AM_TEST_RUNNER_SHELL -c \ + '. ./defs-static && test $am_using_tap = no' $name +done + +$AM_TEST_RUNNER_SHELL -c ' am_using_tap=no . ./defs-static test $am_using_tap = no ' foo.tap -$SHELL -c ' +$AM_TEST_RUNNER_SHELL -c ' am_using_tap=yes . ./defs-static test $am_using_tap = yes -- 1.7.9.5