diff options
author | Stefano Lattarini <stefano.lattarini@gmail.com> | 2013-05-17 13:45:44 +0200 |
---|---|---|
committer | Stefano Lattarini <stefano.lattarini@gmail.com> | 2013-05-17 15:40:35 +0200 |
commit | 84e12c32964ef8454be946b4b2eeb46766ca9add (patch) | |
tree | b397fb95a2b599f73e9fc19e228178881c0c3ce9 | |
parent | 176d229b5136806a6f34d18f08dfc986e6c26c76 (diff) | |
download | automake-84e12c32964ef8454be946b4b2eeb46766ca9add.tar.gz |
tests: sanitize 'unset' usages
In some shells (e.g., Solaris 10 /bin/ksh, or NetBSD 5.1 /bin/sh),
"unset VAR" returns a non-zero exit status in case the VAR variable
is already unset. This doesn't interact well with our usage of
"set -e" in the testsuite. So far, we've avoided spurious failures
by either explicitly ignoring the exit status from unset:
unset VAR || :
or explicitly ensuring that a variable is set, before trying to
unset it:
VAR=; unset VAR
But we can do better, by aliasing the 'unset' command to a custom
function that will take care of these details for us. This will
avoid us annoying spurious failures in the future, failures that
have already bitten us too much times. For an example, refer to
commit 'v1.12.2-88-g5b1dae5' of 2012-08-05 (tests: avoid tons of
spurious failures on NetBSD).
* t/ax/test-lib.sh (_am_unset): New function.
(unset): New alias to it.
(_am_exit): Adjust comments.
* t/ax/am-test-lib.sh: No need to temporary disable the 'errexit'
shell flag when unsetting variables that are potentially already
unset.
(am_process_requirements): Adjust to remove a now-useless
workaround related to unset.
* t/aclocal-macrodir.tap: Likewise.
* t/aclocal-macrodirs.tap: Likewise.
* t/auxdir-autodetect.sh: Likewise.
* t/ax/am-test-lib.sh: Likewise.
* t/ax/test-lib.sh: Likewise.
* t/check-tests-in-builddir.sh: Likewise.
* t/dist-formats.tap: Likewise.
* t/distcheck-configure-flags-am.sh: Likewise.
* t/distcheck-configure-flags.sh: Likewise.
* t/java-empty-classpath.sh: Likewise.
* t/javaflags.sh: Likewise.
* t/lflags.sh: Likewise.
* t/lflags2.sh: Likewise.
* t/lisp-flags.sh: Likewise.
* t/lisp6.sh: Likewise.
* t/missing-auxfile-stops-makefiles-creation.sh: Likewise.
* t/parallel-am.sh: Likewise.
* t/parallel-am2.sh: Likewise.
* t/parallel-am3.sh: Likewise.
* t/parallel-tests-log-override-recheck.sh: Likewise.
* t/pkg-config-macros.sh: Likewise.
* t/python-missing.sh: Likewise.
* t/python-too-old.sh: Likewise.
* t/python11.sh: Likewise.
* t/self-check-dir.tap: Likewise.
* t/self-check-report.sh: Likewise.
* t/self-check-seq.tap: Likewise.
* t/silent-configsite.sh: Likewise.
* t/suffix6c.sh: Likewise.
* t/tar-override.sh: Likewise.
* t/tests-environment-and-log-compiler.sh: Likewise.
* t/vala-configure.sh: Likewise.
* t/werror3.sh: Likewise.
* t/yflags-cmdline-override.sh: Likewise.
* t/yflags.sh: Likewise.
* t/yflags2.sh: Likewise.
Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
36 files changed, 54 insertions, 45 deletions
diff --git a/t/aclocal-macrodir.tap b/t/aclocal-macrodir.tap index fb8060968..4d11917b1 100644 --- a/t/aclocal-macrodir.tap +++ b/t/aclocal-macrodir.tap @@ -23,7 +23,7 @@ am_create_testdir=empty plan_ 7 ocwd=$(pwd) || fatal_ "getting current working directory" -ACLOCAL_PATH=; unset ACLOCAL_PATH +unset ACLOCAL_PATH # # General utility functions and variables. diff --git a/t/aclocal-macrodirs.tap b/t/aclocal-macrodirs.tap index 0898c29ef..1cbf6d7bc 100644 --- a/t/aclocal-macrodirs.tap +++ b/t/aclocal-macrodirs.tap @@ -23,7 +23,7 @@ am_create_testdir=empty plan_ 15 ocwd=$(pwd) || fatal_ "getting current working directory" -ACLOCAL_PATH=; unset ACLOCAL_PATH +unset ACLOCAL_PATH # # General utility functions and variables. diff --git a/t/auxdir-autodetect.sh b/t/auxdir-autodetect.sh index 17567c0fc..457e06a52 100644 --- a/t/auxdir-autodetect.sh +++ b/t/auxdir-autodetect.sh @@ -21,7 +21,7 @@ nil=__no_such_program -unset NONESUCH || : +unset NONESUCH cat >>configure.ac << END AM_MISSING_PROG([NONESUCH],[$nil]) diff --git a/t/ax/am-test-lib.sh b/t/ax/am-test-lib.sh index e14f96fab..5804372ea 100644 --- a/t/ax/am-test-lib.sh +++ b/t/ax/am-test-lib.sh @@ -34,11 +34,6 @@ distdir=$me-1.0 ## Environment cleanup. ## ## ---------------------- ## -# Temporarily disable this, since some shells (e.g., older version -# of Bash) can return a non-zero exit status upon the when a non-set -# variable is unset. -set +e - # Unset some make-related 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 @@ -85,9 +80,6 @@ for pfx in TEST_ SH_ TAP_ ''; do done unset pfx -# Re-enable, it had been temporarily disabled above. -set -e - # cross_compiling # --------------- # Tell whether we are cross-compiling. This is especially useful to skip @@ -805,7 +797,7 @@ process_requirements () *" $am_tool"*) . ./t/$am_tool-macros.dir/get.sh;; esac done - am_tool=; unset am_tool + unset am_tool } ## ---------------------------------------------------------------- ## diff --git a/t/ax/test-lib.sh b/t/ax/test-lib.sh index 5be0cecb2..ee83dcff3 100644 --- a/t/ax/test-lib.sh +++ b/t/ax/test-lib.sh @@ -92,7 +92,7 @@ _am_exit () set +e # See comments in the exit trap for the reason we do this. test 77 = $1 && am__test_skipped=yes - # Spurious escaping to ensure we do not call our 'exit' alias. + # Extra escaping to ensure we do not call our 'exit' alias. (\exit $1); \exit $1 } # Avoid interferences from the environment @@ -101,6 +101,23 @@ am__test_skipped=no # just inside a function definition. Weird, but real. alias exit=_am_exit +# In some shells (e.g., Solaris 10 /bin/ksh, or NetBSD 5.1 /bin/sh), +# "unset VAR" returns a non-zero exit status in case the VAR variable +# is already unset. This doesn't interact well with our usage of +# "set -e" in the testsuite. This function and the alias below help +# to work around the issue. +_am_unset () +{ + for _am_v + do + # Extra escaping (here and below) to ensure we do not call our + # 'unset' alias. + eval ${_am_v}=dummy && \unset ${_am_v} || exit 1 + done + \unset _am_v +} +alias unset=_am_unset + ## ------------------------------------ ## ## General testsuite shell functions. ## ## ------------------------------------ ## diff --git a/t/check-tests-in-builddir.sh b/t/check-tests-in-builddir.sh index fad652731..1c41368a1 100644 --- a/t/check-tests-in-builddir.sh +++ b/t/check-tests-in-builddir.sh @@ -35,7 +35,7 @@ exit ${FOO_EXIT_STATUS-0} END chmod a+x foo.test -unset FOO_EXIT_STATUS || : +unset FOO_EXIT_STATUS $ACLOCAL $AUTOCONF diff --git a/t/dist-formats.tap b/t/dist-formats.tap index 730fa5d07..78295128f 100644 --- a/t/dist-formats.tap +++ b/t/dist-formats.tap @@ -28,7 +28,7 @@ plan_ 70 ocwd=$(pwd) || fatal_ "getting current working directory" -TAR='' && unset TAR +unset TAR # Create common aclocal.m4 file, for later tests. mkdir setup \ diff --git a/t/distcheck-configure-flags-am.sh b/t/distcheck-configure-flags-am.sh index f38b1dca0..b1fd49bed 100644 --- a/t/distcheck-configure-flags-am.sh +++ b/t/distcheck-configure-flags-am.sh @@ -27,7 +27,7 @@ AS_IF([test $success = yes && test "$sentence" = 'it works :-)'], AC_OUTPUT END -unset sentence || : +unset sentence cat > Makefile.am << 'END' AM_DISTCHECK_CONFIGURE_FLAGS = $(dc_flags1) $(dc_flags2) diff --git a/t/distcheck-configure-flags.sh b/t/distcheck-configure-flags.sh index b1725f24a..3c23117c7 100644 --- a/t/distcheck-configure-flags.sh +++ b/t/distcheck-configure-flags.sh @@ -26,7 +26,7 @@ AS_IF([test $success = yes && test "$sentence" = 'it works :-)'], AC_OUTPUT END -unset sentence || : +unset sentence : > Makefile.am diff --git a/t/java-empty-classpath.sh b/t/java-empty-classpath.sh index 387c4c3d0..cc3dae3ba 100644 --- a/t/java-empty-classpath.sh +++ b/t/java-empty-classpath.sh @@ -74,7 +74,7 @@ $AUTOCONF $AUTOMAKE ./configure -unset CLASSPATH || : +unset CLASSPATH $MAKE $MAKE clean @@ -82,7 +82,7 @@ CLASSPATH=''; export CLASSPATH $MAKE $MAKE clean -unset CLASSPATH || : +unset CLASSPATH $MAKE distcheck : diff --git a/t/javaflags.sh b/t/javaflags.sh index c1c2671fd..bb9ab26a4 100644 --- a/t/javaflags.sh +++ b/t/javaflags.sh @@ -26,7 +26,7 @@ chmod a+x fake-javac # Remove JAVAC from the environment, so that it won't interfere # with 'make -e' below. -unset JAVAC || : +unset JAVAC cat >> configure.ac <<'END' AC_PROG_CC diff --git a/t/lflags.sh b/t/lflags.sh index 3074bdf04..18268b188 100644 --- a/t/lflags.sh +++ b/t/lflags.sh @@ -31,7 +31,7 @@ chmod a+x fake-lex # Remove Lex from the environment, so that it won't interfere # with 'make -e' below. -unset LEX || : +unset LEX cat >> configure.ac <<'END' AC_SUBST([CC], [false]) diff --git a/t/lflags2.sh b/t/lflags2.sh index 250777814..a959aeab2 100644 --- a/t/lflags2.sh +++ b/t/lflags2.sh @@ -30,7 +30,7 @@ chmod a+x fake-lex # Remove Lex from the environment, so that it won't interfere # with 'make -e' below. -unset LEX || : +unset LEX cat >> configure.ac <<'END' AC_SUBST([CXX], [false]) diff --git a/t/lisp-flags.sh b/t/lisp-flags.sh index 1ea5b8e34..a31bcfdf0 100644 --- a/t/lisp-flags.sh +++ b/t/lisp-flags.sh @@ -20,7 +20,7 @@ # Don't get fooled when running as an Emacs subprocess. This is # for the benefit of the "make -e" invocation below. -EMACS=; unset EMACS +unset EMACS cat > Makefile.am << 'EOF' lisp_LISP = foo.el diff --git a/t/lisp6.sh b/t/lisp6.sh index 4b5f00669..0dd434466 100644 --- a/t/lisp6.sh +++ b/t/lisp6.sh @@ -39,7 +39,7 @@ AC_OUTPUT EOF # Avoid possible spurious influences from the environment. -want_two=; unset want_two +unset want_two echo "(provide 'am-one)" > am-one.el echo "(require 'am-one)" > am-two.el diff --git a/t/missing-auxfile-stops-makefiles-creation.sh b/t/missing-auxfile-stops-makefiles-creation.sh index 50aa48a71..754b316fe 100644 --- a/t/missing-auxfile-stops-makefiles-creation.sh +++ b/t/missing-auxfile-stops-makefiles-creation.sh @@ -36,7 +36,7 @@ done $ACLOCAL -unset AUTOMAKE_JOBS || : +unset AUTOMAKE_JOBS AUTOMAKE_fails ls -l Makefile.in */Makefile.in || : # For debugging. diff --git a/t/parallel-am.sh b/t/parallel-am.sh index 4be5eea1d..ea39518b2 100644 --- a/t/parallel-am.sh +++ b/t/parallel-am.sh @@ -80,7 +80,7 @@ $ACLOCAL # Further, automake output should be stable. # Generate expected output using the non-threaded code. -unset AUTOMAKE_JOBS || : +unset AUTOMAKE_JOBS AUTOMAKE_run --add-missing mv stderr expected Makefile_ins=$(find . -name Makefile.in) diff --git a/t/parallel-am2.sh b/t/parallel-am2.sh index 2f8627d60..10fc51bfb 100644 --- a/t/parallel-am2.sh +++ b/t/parallel-am2.sh @@ -60,7 +60,7 @@ $ACLOCAL # Thus we install the auxiliary files in a prior step. # Generate expected output using non-threaded code. -unset AUTOMAKE_JOBS || : +unset AUTOMAKE_JOBS rm -f install-sh missing depcomp AUTOMAKE_fails --add-missing mv stderr expected diff --git a/t/parallel-am3.sh b/t/parallel-am3.sh index 1c87e633f..146e59f20 100644 --- a/t/parallel-am3.sh +++ b/t/parallel-am3.sh @@ -56,7 +56,7 @@ mkdir build-aux $ACLOCAL # Generate expected output using the non-threaded code. -unset AUTOMAKE_JOBS || : +unset AUTOMAKE_JOBS AUTOMAKE_run --add-missing mv stderr expected mv Makefile.in Makefile.in.exp diff --git a/t/parallel-tests-log-override-recheck.sh b/t/parallel-tests-log-override-recheck.sh index c2ea05d47..d1fec7f25 100644 --- a/t/parallel-tests-log-override-recheck.sh +++ b/t/parallel-tests-log-override-recheck.sh @@ -47,7 +47,7 @@ END chmod a+x *.test -unset BAZ_EXIT_STATUS || : +unset BAZ_EXIT_STATUS $ACLOCAL $AUTOCONF diff --git a/t/pkg-config-macros.sh b/t/pkg-config-macros.sh index 5069c0887..cfa49cf36 100644 --- a/t/pkg-config-macros.sh +++ b/t/pkg-config-macros.sh @@ -78,7 +78,7 @@ else echo "skip_all_ \"pkg-config m4 macros not found\"" >> get.sh fi -ACLOCAL_PATH=; unset ACLOCAL_PATH +unset ACLOCAL_PATH . ./get.sh $ACLOCAL --force -I m4 || cat >> get.sh <<'END' diff --git a/t/python-missing.sh b/t/python-missing.sh index 0a9a07381..66eca9e15 100644 --- a/t/python-missing.sh +++ b/t/python-missing.sh @@ -22,7 +22,7 @@ am_create_testdir=empty # An actual python is *not* required in this test. . test-init.sh -PYTHON=; unset PYTHON +unset PYTHON cat > configure.ac <<END AC_INIT([$me], [1.0]) diff --git a/t/python-too-old.sh b/t/python-too-old.sh index 6a81215a3..0042799fa 100644 --- a/t/python-too-old.sh +++ b/t/python-too-old.sh @@ -35,7 +35,7 @@ py_too_old () } saved_PYTHON=$PYTHON; export saved_PYTHON -PYTHON=; unset PYTHON +unset PYTHON cat > configure.ac <<END AC_INIT([$me], [1.0]) diff --git a/t/python11.sh b/t/python11.sh index c5fedf796..faf09d8ff 100644 --- a/t/python11.sh +++ b/t/python11.sh @@ -20,7 +20,7 @@ . test-init.sh # We don't want to allow user overrides in this test. -PYTHON=; unset PYTHON +unset PYTHON cat >>configure.ac <<'EOF' m4_define([_AM_PYTHON_INTERPRETER_LIST], [IShouldNotExist1 IShouldNotExist2]) diff --git a/t/self-check-dir.tap b/t/self-check-dir.tap index b871b6679..68e9edf18 100644 --- a/t/self-check-dir.tap +++ b/t/self-check-dir.tap @@ -24,7 +24,7 @@ am_create_testdir=no plan_ 5 -keep_testdirs=; unset keep_testdirs +unset keep_testdirs # This needs to be consistent with what $AM_TEST_RUNNER_SHELL # deems to be the current working directory. diff --git a/t/self-check-report.sh b/t/self-check-report.sh index c52c5672f..99b98387b 100644 --- a/t/self-check-report.sh +++ b/t/self-check-report.sh @@ -18,7 +18,7 @@ # Test subroutines to report warnings, and to signal failures, skips # and hard errors. -unset stderr_fileno_ || : +unset stderr_fileno_ am_create_testdir=empty . test-init.sh diff --git a/t/self-check-seq.tap b/t/self-check-seq.tap index 3c5e2dc6c..4e9d58f75 100644 --- a/t/self-check-seq.tap +++ b/t/self-check-seq.tap @@ -21,7 +21,7 @@ plan_ 14 -unset stderr_fileno_ || : +unset stderr_fileno_ check_work () { diff --git a/t/silent-configsite.sh b/t/silent-configsite.sh index 1df767312..6146533d9 100644 --- a/t/silent-configsite.sh +++ b/t/silent-configsite.sh @@ -33,7 +33,7 @@ test-nosilent: test x'$(AM_DEFAULT_VERBOSITY)' = x'1' EOF -unset enable_silent_rules || : +unset enable_silent_rules : 'No explicit default in configure.ac, enable by default in config.site' diff --git a/t/suffix6c.sh b/t/suffix6c.sh index 353585dc5..00c6da30c 100644 --- a/t/suffix6c.sh +++ b/t/suffix6c.sh @@ -31,7 +31,7 @@ AC_SUBST([OBJEXT]) AC_OUTPUT END -unset OBJEXT || : +unset OBJEXT cat > Makefile.am << 'END' SUFFIXES = .zoo .o .obj .@OBJEXT@ diff --git a/t/tar-override.sh b/t/tar-override.sh index bbf3fbb86..d5bbd5676 100644 --- a/t/tar-override.sh +++ b/t/tar-override.sh @@ -59,7 +59,7 @@ test "$(cat am--tar-has-run)" = foo clean_temp -TAR=; unset TAR +unset TAR # Creative use of eval to pacify maintainer checks. eval \$'MAKE dist "TAR=./am--tar mu"' test -f $distdir.tar.gz diff --git a/t/tests-environment-and-log-compiler.sh b/t/tests-environment-and-log-compiler.sh index 283e7d374..5f0e2f527 100644 --- a/t/tests-environment-and-log-compiler.sh +++ b/t/tests-environment-and-log-compiler.sh @@ -24,7 +24,7 @@ cat >> configure.ac << 'END' AC_OUTPUT END -unset v0 v1 v2 v3 v4 || : +unset v0 v1 v2 v3 v4 cat > Makefile.am << 'END' TESTS_ENVIRONMENT = am__f3 () { echo 3; }; v0='$(srcdir)' v1=1; :; diff --git a/t/vala-configure.sh b/t/vala-configure.sh index cbba4bd3d..4f59d070f 100644 --- a/t/vala-configure.sh +++ b/t/vala-configure.sh @@ -53,7 +53,7 @@ chmod +x bin/valac.old PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH # Avoid interferences from the environment. -VALAC= vala_version=; unset VALAC vala_version +unset VALAC vala_version $ACLOCAL $AUTOMAKE -a diff --git a/t/werror3.sh b/t/werror3.sh index c6007c8f8..c1ec28a49 100644 --- a/t/werror3.sh +++ b/t/werror3.sh @@ -36,7 +36,7 @@ END $ACLOCAL # The issue would not manifest with threaded execution. -unset AUTOMAKE_JOBS || : +unset AUTOMAKE_JOBS AUTOMAKE_run -Wno-error grep 'VAR multiply defined' stderr diff --git a/t/yflags-cmdline-override.sh b/t/yflags-cmdline-override.sh index 613c35c78..3eea823c6 100644 --- a/t/yflags-cmdline-override.sh +++ b/t/yflags-cmdline-override.sh @@ -20,7 +20,7 @@ required='cc yacc' . test-init.sh -unset YFLAGS || : +unset YFLAGS cat >> configure.ac <<'END' AC_PROG_CC diff --git a/t/yflags.sh b/t/yflags.sh index 8d17dc806..f8fe7a407 100644 --- a/t/yflags.sh +++ b/t/yflags.sh @@ -30,7 +30,7 @@ chmod a+x fake-yacc # Remove Yacc from the environment, so that it won't interfere # with 'make -e' below. -unset YACC || : +unset YACC cat >> configure.ac <<'END' AC_SUBST([CC], [false]) diff --git a/t/yflags2.sh b/t/yflags2.sh index 37dce3f2e..12eb5d726 100644 --- a/t/yflags2.sh +++ b/t/yflags2.sh @@ -30,7 +30,7 @@ chmod a+x fake-yacc # Remove Yacc from the environment, so that it won't interfere # with 'make -e' below. -unset YACC || : +unset YACC cat >> configure.ac <<'END' AC_SUBST([CXX], [false]) |