We once used that feature in our wrapper tests; but now (and probably even since commit 'v1.11-1308-g375f23d' of 2011-09-08, "testsuite: revamp generation of autogenerated tests") it is not needed anymore. By removing it we can simplify our growingly complex testsuite framework a little.
* t/ax/test-inist.sh ($me): Do not initialize it here (and only if not already set), instead ... * defs-static.in ($me): ... initialize it here unconditionally. Do not check anymore that $me doesn't come from the environment: that wouldn't cause any problem now. Now that '$me' is defined early, prefer it over 'argv0' in early error messages, both here ... * defs: ... and here. * Makefile.am (AM_TESTS_ENVIRONMENT): Do not bother "nullifying" $me anymore. * t/self-check-env-sanitize.tap: Adjust. * t/self-check-me.tap: Likewise. Signed-off-by: Stefano Lattarini <stefano.lattar...@gmail.com> --- Makefile.am | 1 - defs | 4 ++-- defs-static.in | 12 +++++++++--- t/ax/test-init.sh | 13 ------------- t/self-check-env-sanitize.tap | 3 +-- t/self-check-me.tap | 27 +++++++-------------------- 6 files changed, 19 insertions(+), 41 deletions(-) diff --git a/Makefile.am b/Makefile.am index 76f1cb3..9d58155 100644 --- a/Makefile.am +++ b/Makefile.am @@ -336,7 +336,6 @@ TESTS = ## Will be updated later. # test scripts, but not from the environment. AM_TESTS_ENVIRONMENT = \ for v in \ - me \ required \ am_using_tap \ am_serial_tests \ diff --git a/defs b/defs index 217665e..143be66 100644 --- a/defs +++ b/defs @@ -33,7 +33,7 @@ case ${AM_TESTS_REEXEC-yes} in *) # Ensure we can find ourselves. if test ! -f "$argv0"; then - echo "$argv0: unable to find myself" >&2 + echo "$me: unable to find myself: '$argv0'" >&2 exit 99 fi AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC @@ -49,7 +49,7 @@ case ${AM_TESTS_REEXEC-yes} in echo exec $AM_TEST_RUNNER_SHELL $opts "$argv0" "$*" exec $AM_TEST_RUNNER_SHELL $opts "$argv0" ${1+"$@"} # This should be dead code, unless some strange error happened. - echo "$argv0: failed to re-execute with $AM_TEST_RUNNER_SHELL" >&2 + echo "$me: failed to re-execute with $AM_TEST_RUNNER_SHELL" >&2 exit 99 ;; esac diff --git a/defs-static.in b/defs-static.in index da5dcff..781571c 100644 --- a/defs-static.in +++ b/defs-static.in @@ -53,11 +53,17 @@ else case `(set -o) 2>/dev/null || :` in *posix*) set -o posix;; esac fi +# The name of the current test (without the '.sh' or '.tap' suffix). +me=${argv0##*/} # Strip all directory components. +case $me in # Strip test suffix. + *.tap) me=${me%.tap};; + *.sh) me=${me%.sh} ;; + esac + # Check that the environment is properly sanitized. # Having variables exported to the empty string is OK, since our code # treats such variables as if they were unset. for var in \ - me \ required \ am_using_tap \ am_serial_tests \ @@ -68,7 +74,7 @@ for var in \ am_original_ACLOCAL \ ; do if eval "test x\"\$$var\" != x" && env | grep "^$var=" >/dev/null; then - echo "$argv0: variable '$var' is set in the environment:" \ + echo "$me: variable '$var' is set in the environment:" \ "this is unsafe" >&2 exit 99 fi @@ -113,7 +119,7 @@ case ${am_running_installcheck:=no} in am_system_acdir=$am_top_srcdir/m4/acdir ;; *) - echo "$argv0: variable 'am_running_installcheck' has invalid" + echo "$me: variable 'am_running_installcheck' has invalid" "value '$am_running_installcheck'" >&2 exit 99 ;; diff --git a/t/ax/test-init.sh b/t/ax/test-init.sh index 83fe6eb..d0b4cd7 100644 --- a/t/ax/test-init.sh +++ b/t/ax/test-init.sh @@ -22,19 +22,6 @@ # Enable the errexit shell flag early. set -e -# The name of the current test (without the '.sh' or '.tap' suffix). -# Test scripts can override it if they need to (but this should -# be done carefully). -if test -z "$me"; then - # Strip all directory components. - me=${argv0##*/} - # Strip test suffix. - case $me in - *.tap) me=${me%.tap};; - *.sh) me=${me%.sh} ;; - esac -fi - ## --------------------- ## ## Early sanity checks. ## diff --git a/t/self-check-env-sanitize.tap b/t/self-check-env-sanitize.tap index 4169998..3e48d89 100755 --- a/t/self-check-env-sanitize.tap +++ b/t/self-check-env-sanitize.tap @@ -24,10 +24,9 @@ am_create_testdir=no set -x exec 5>&1 -plan_ 18 # Two times the number of variable names in $vars. +plan_ 16 # Two times the number of variable names in $vars. vars=' - me required am_serial_tests am_using_tap diff --git a/t/self-check-me.tap b/t/self-check-me.tap index bd75fa9..717fe2e 100755 --- a/t/self-check-me.tap +++ b/t/self-check-me.tap @@ -15,13 +15,12 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # Sanity check for the automake testsuite. -# Make sure that $me gets automatically defined by './defs', and that it -# can be overridden by the test script. +# Make sure that $me gets automatically defined by './defs'. am_create_testdir=no . ./defs || exit 1 -plan_ 14 +plan_ 12 AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC @@ -46,28 +45,16 @@ done do_check foo.bar 'foo\.bar' do_check abc. 'abc\.' -# If we override $me, ./defs should not modify it. +# A definition of $me in the environment should be ignored. -s=$($AM_TEST_RUNNER_SHELL -c 'me=foo.sh && . ./defs && echo me=$me' bad.sh) +s=$(me=bad $AM_TEST_RUNNER_SHELL -c '. ./defs && echo me=$me' foo.sh) command_ok_ "override of \$me before ./defs causes no error" \ test $? -eq 0 r='ok' -printf '%s\n' "$s" | grep '^me=foo\.sh$' || r='not ok' -printf '%s\n' "$s" | grep 'me=bad' && r='not ok' -result_ "$r" "override of \$me before ./defs is honored" -unset r - -# Overriding $me after sourcing ./defs-static should work. -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 - -r='ok' -printf '%s\n' "$s" | grep '^me=zardoz$' || r='not ok' -printf '%s\n' "$s" | grep 'me=bad' && r='not ok' -result_ "$r" "override of \$me after ./defs-static is honored" +printf '%s\n' "$s" | grep '^me=foo$' || r='not ok' +printf '%s\n' "$s" | grep 'me=bad' && r='not ok' +result_ "$r" "\$me from the environment is ignored" unset r : -- 1.7.9.5