tests: sanitize 'unset' usages
authorStefano Lattarini <stefano.lattarini@gmail.com>
Fri, 17 May 2013 11:45:44 +0000 (13:45 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Fri, 17 May 2013 13:40:35 +0000 (15:40 +0200)
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:
t/aclocal-macrodir.tap
t/aclocal-macrodirs.tap
t/auxdir-autodetect.sh
t/ax/am-test-lib.sh
t/ax/test-lib.sh
t/check-tests-in-builddir.sh
t/dist-formats.tap
t/distcheck-configure-flags-am.sh
t/distcheck-configure-flags.sh
t/java-empty-classpath.sh
t/javaflags.sh
t/lflags.sh
t/lflags2.sh
t/lisp-flags.sh
t/lisp6.sh
t/missing-auxfile-stops-makefiles-creation.sh
t/parallel-am.sh
t/parallel-am2.sh
t/parallel-am3.sh
t/parallel-tests-log-override-recheck.sh
t/pkg-config-macros.sh
t/python-missing.sh
t/python-too-old.sh
t/python11.sh
t/self-check-dir.tap
t/self-check-report.sh
t/self-check-seq.tap
t/silent-configsite.sh
t/suffix6c.sh
t/tar-override.sh
t/tests-environment-and-log-compiler.sh
t/vala-configure.sh
t/werror3.sh
t/yflags-cmdline-override.sh
t/yflags.sh
t/yflags2.sh

index fb8060968b966dbca032ca12b251371eb28a4b91..4d11917b1a80c6e192ea5f1d3afbf7c17d5660dc 100644 (file)
@@ -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.
index 0898c29efb579e4114b76f933b3c5cce097981e7..1cbf6d7bc52e9a72ecdd3463b957a13ada7e5e61 100644 (file)
@@ -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.
index 17567c0fc6ec713307436eb70f5676c4a39b51ca..457e06a52d468892de4e2c7cd8020a760bb587b6 100644 (file)
@@ -21,7 +21,7 @@
 
 nil=__no_such_program
 
-unset NONESUCH || :
+unset NONESUCH
 
 cat >>configure.ac << END
 AM_MISSING_PROG([NONESUCH],[$nil])
index e14f96fabd5740122e378c5c4378fd3e8bd2f1a7..5804372ea62fdcfaed7775e63e9d18ddff1a9df8 100644 (file)
@@ -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
 }
 
 ## ---------------------------------------------------------------- ##
index 5be0cecb235747e3364352cdd5ecb187508ccfbb..ee83dcff3c1353c0645b23641e4e76ca642715a3 100644 (file)
@@ -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.  ##
 ## ------------------------------------ ##
index fad652731f2d85ee3f8d6962ce714bb88371d4fe..1c41368a13731865ec48b447404c83c7ed4218cb 100644 (file)
@@ -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
index 730fa5d0708b3ace0db3d761a34b6eff9b9a4344..78295128f74f937b81c847993692860bcae8c6d8 100644 (file)
@@ -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 \
index f38b1dca03fde923e6db2a8fcb524c771e784380..b1fd49bed9b05dcfc311a5b0805e30cef645e764 100644 (file)
@@ -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)
index b1725f24a0793229fec26fe5c0ef659054c4d534..3c23117c7211294bc9bdc4f19a7b26def4d7f0f4 100644 (file)
@@ -26,7 +26,7 @@ AS_IF([test $success = yes && test "$sentence" = 'it works :-)'],
 AC_OUTPUT
 END
 
-unset sentence || :
+unset sentence
 
 : > Makefile.am
 
index 387c4c3d00964aa4aa4ff7e33c6aa093885e7f53..cc3dae3ba1c92fec7b17848696dc95c4a9cad382 100644 (file)
@@ -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
 
 :
index c1c2671fdbe2ef4e8e298ab039eef4ef8824c17b..bb9ab26a47376a23913666bbda587e7fb6d6900c 100644 (file)
@@ -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
index 3074bdf04ae9ef3244647211f77712ab3ef32be2..18268b188d50ab58095edf557da1317567da7a87 100644 (file)
@@ -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])
index 250777814357328ccf994f0d3856fb654448cdd1..a959aeab21e274112db2862508c69c898f6d9082 100644 (file)
@@ -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])
index 1ea5b8e3495a13c3ffd2bd2ef178d4cb559ef386..a31bcfdf0c8f5e898b5b305c5089882ca500d789 100644 (file)
@@ -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
index 4b5f00669f06a51ab53e97c7b5d9895be18b84a7..0dd43446698b1ba95bf487d187937c57afc70190 100644 (file)
@@ -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
index 50aa48a712e89fc4f975b33336a98e49e58e2798..754b316fea3a3ea2dddb68f3636b8f579925385b 100644 (file)
@@ -36,7 +36,7 @@ done
 
 $ACLOCAL
 
-unset AUTOMAKE_JOBS || :
+unset AUTOMAKE_JOBS
 
 AUTOMAKE_fails
 ls -l Makefile.in */Makefile.in || : # For debugging.
index 4be5eea1d33d70f26c279498a4978ca1c045fa29..ea39518b26ee64957fa087f58c3047b50d946e86 100644 (file)
@@ -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)
index 2f8627d60b54a8aa80856f4794fb4ac6ebccf0fc..10fc51bfb7f384384bf4ad1acd1a4f8ecd29b6d6 100644 (file)
@@ -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
index 1c87e633f901dc35b52624203355590d2b64d54a..146e59f206dca0c9c3b7073b896066b019e71bb8 100644 (file)
@@ -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
index c2ea05d47312ea3ee2c9453e8807b59f7b3487b7..d1fec7f250a59530cf870e9032a90c86ccd262fe 100644 (file)
@@ -47,7 +47,7 @@ END
 
 chmod a+x *.test
 
-unset BAZ_EXIT_STATUS || :
+unset BAZ_EXIT_STATUS
 
 $ACLOCAL
 $AUTOCONF
index 5069c0887ed728bc1e198e8cc4a2491bea38028a..cfa49cf360644bb2b104094094ec838636adbab9 100644 (file)
@@ -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'
index 0a9a07381df9ac4f030dbd82012d27ee789a6435..66eca9e15a6a48382f261b6c87ea35f3c7971fa4 100644 (file)
@@ -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])
index 6a81215a3376021d820a55845b6adeae33546579..0042799fa3f0b223bd8bf7c26e8f0e712e4ab0d7 100644 (file)
@@ -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])
index c5fedf796e9da220f49f2964c08e0873ff67c44e..faf09d8ff3f048e6c79f088a6cb3ddfb324158cd 100644 (file)
@@ -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])
index b871b6679b5cabfc0974ff6b4eb188326ed4ec98..68e9edf18d4c415abb72a9b633f8bdd9dcdeef68 100644 (file)
@@ -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.
index c52c5672f416fabe8cd06d1c5890029b612f47f2..99b98387b882cd64ad14c69a3098ce4a6b8ba1fe 100644 (file)
@@ -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
index 3c5e2dc6c363683bbc3ca37b78a14f0da185e45e..4e9d58f75d4687a4996f524ae6cbe808d5d56103 100644 (file)
@@ -21,7 +21,7 @@
 
 plan_ 14
 
-unset stderr_fileno_ || :
+unset stderr_fileno_
 
 check_work ()
 {
index 1df767312b4f809ce234c170419d98851d93ef9e..6146533d96e9a048f3a4bf67285371ba91e821a0 100644 (file)
@@ -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'
 
index 353585dc5744710b0eb210d017d6e476fb55fba6..00c6da30c7750dce18501fac5e602fe5410dc2e9 100644 (file)
@@ -31,7 +31,7 @@ AC_SUBST([OBJEXT])
 AC_OUTPUT
 END
 
-unset OBJEXT || :
+unset OBJEXT
 
 cat > Makefile.am << 'END'
 SUFFIXES = .zoo .o .obj .@OBJEXT@
index bbf3fbb863d8f764221fec7d2dc0385fc0ab4559..d5bbd5676f7bbc717f27609f9279b15a532fe7ab 100644 (file)
@@ -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
index 283e7d374ef3e46ca5c8e64f7bb1d79500aa2b47..5f0e2f52770efccc116c74ef760af1690cf68ddc 100644 (file)
@@ -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; :;
index cbba4bd3d8f3c2685712bfb0965f2518e9555370..4f59d070fa1ae488576aac5211f1dec669c3b47f 100644 (file)
@@ -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
index c6007c8f89e22e5a3ce96ce150fcac0c499e91ff..c1ec28a49c681d2992fc22e9c931c8c892239500 100644 (file)
@@ -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
 
index 613c35c78c84fcf13ecb9b1347521974d94c46c6..3eea823c629eab565f08fcf1b7815a5272cfe77c 100644 (file)
@@ -20,7 +20,7 @@
 required='cc yacc'
 . test-init.sh
 
-unset YFLAGS || :
+unset YFLAGS
 
 cat >> configure.ac <<'END'
 AC_PROG_CC
index 8d17dc806fbb75112a69184f339c45905f9e507b..f8fe7a40764676c120b71ebc0b4ab536ab3f1b15 100644 (file)
@@ -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])
index 37dce3f2e8cb5a00aced0286cee6c836712fdce6..12eb5d72601df3ff59cfda3aa23fe8cde6da7f01 100644 (file)
@@ -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])