From: Stefano Lattarini Date: Sat, 30 Jan 2010 13:01:39 +0000 (+0100) Subject: Fix parallel testsuite run with Zsh. X-Git-Tag: ng-0.5a~286^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7cd2094693437d3d7fbdb69d577758fe1d6e0900;p=thirdparty%2Fautomake.git Fix parallel testsuite run with Zsh. This change deals with a Zsh incompatibility in the handling of the special shell variable `$0' in sourced files; this incompatibility used to cause utter breakage when the Automake testsuite was run in parallel mode with Zsh as the $(TEST_LOG_COMPILER). For more information, please refer to the thread "Fix parallel testsuite run with zsh" on automake-patches, dated 2010-12-22: This change works around the problems described above for Zsh 4.3 or later, and offers better error messages (instead of random failures) for earlier Zsh version. * tests/README (Supported shells): When describing the manual workaround about the Zsh incompatibility in the handling of `$0', tell that it is now needed only with Zsh versions preceding 4.3. Done also some minor rewordings. * tests/defs-static.in ($argv0): New variable, offers a workaround for the Zsh incompatibility in the handling of `$0'. Abort if that variable cannot be correctly set (can happen only in older Zsh version). * tests/defs ($me): Define using `$argv0', not `$0'. --- diff --git a/ChangeLog b/ChangeLog index 378742e7f..2ea4caa7b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2010-12-22 Stefano Lattarini + + Fix parallel testsuite run with Zsh. + This change deals with a Zsh incompatibility in the handling + of the special shell variable `$0' in sourced files; this + incompatibility used to cause utter breakage when the + Automake testsuite was run in parallel mode with Zsh as + the $(TEST_LOG_COMPILER). + For more information, please refer to the thread "Fix parallel + testsuite run with zsh" on automake-patches, dated 2010-12-22: + + This change works around the problems described above for Zsh 4.3 + or later, and offers better error messages (instead of random + failures) for earlier Zsh version. + * tests/README (Supported shells): When describing the manual + workaround about the Zsh incompatibility in the handling of `$0', + tell that it is now needed only with Zsh versions preceding 4.3. + Done also some minor rewordings. + * tests/defs-static.in ($argv0): New variable, offers a workaround + for the Zsh incompatibility in the handling of `$0'. + Abort if that variable cannot be correctly set (can happen only + in older Zsh version). + * tests/defs ($me): Define using `$argv0', not `$0'. + 2010-12-22 Stefano Lattarini Tests defs: keep track of original $AUTOMAKE and $ACLOCAL values. diff --git a/tests/README b/tests/README index 88da783e7..1369bd3d2 100644 --- a/tests/README +++ b/tests/README @@ -70,17 +70,19 @@ Supported shells should run with any decent Bourne-compatible shell. However, some care must be used with Zsh, since, when not directly - starting in Bourne-compatibility mode, it has some incompatibilities - in the handling of `$0' which conflict with our usage, and which have - no easy workaround. Thus, if you want to run a test script, say - foo.test, with Zsh, you *can't* simply do `zsh foo.test', but you - *must* resort to: + started in Bourne-compatibility mode, it has some incompatibilities + in the handling of `$0' which conflict with our usage. Our testsuite + can automatically work around these incompatibilities when a version + 4.3 or later of Zsh is used, but unfortunately not when an older + 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 - Note that this problem does not occur if zsh is executed through a - symlink with a basename of `sh', since in that case it starts - in Bourne compatibility mode. So you should be perfectly safe when - /bin/sh is zsh. + 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 + in Bourne compatibility mode. So you should be perfectly safe + when /bin/sh is Zsh, even a it's version < 4.3. Reporting failures diff --git a/tests/defs b/tests/defs index 134dc78c0..f04a7560a 100644 --- a/tests/defs +++ b/tests/defs @@ -30,7 +30,7 @@ test -f ./defs-static || { . ./defs-static || exit 99 # The name of the current test (without the `.test' suffix.) -me=`echo "$0" | sed -e 's,.*[\\/],,;s/\.test$//'` +me=`echo "$argv0" | sed -e 's,.*[\\/],,;s/\.test$//'` ## ---------------------------------------- ## diff --git a/tests/defs-static.in b/tests/defs-static.in index c4ae75818..91431783d 100644 --- a/tests/defs-static.in +++ b/tests/defs-static.in @@ -21,7 +21,7 @@ # IMPORTANT: Multiple inclusions of this file should be idempotent! # Be more Bourne compatible. -# (Snippet copied from configure's initialization in Autoconf 2.64) +# (Snippet inspired to configure's initialization in Autoconf 2.64) DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then emulate sh @@ -30,7 +30,33 @@ if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST + # If Zsh is not started directly in Bourne-compatibility mode, it has + # some incompatibilities in the handling of `$0' that conflict with + # our usage: i.e., `$0' inside a file sourced with the `.' builtin is + # temporarily set to the name of the sourced file. + # Work around this when possible, otherwise abort the script. + # Note that a bug in some versions of Zsh prevents us from resetting $0 + # in a sourced script, so the use of $argv0. For more info see: + # + # Note: the apparently useless 'eval' below are needed by at least + # dash 0.5.2, to prevent it from bailing out with an error like + # "Syntax error: Bad substitution" + if eval '[[ "$0" = *."test" ]]'; then + # Good, FUNCTION_ARGZERO option was already off when this file was + # sourced. Thus we've nothing to do. + argv0=$0 + elif eval 'test -n "${functrace[-1]}"'; then + # FUNCTION_ARGZERO option was on, but we have a easy workaround. + eval 'argv0=${functrace[-1]%:*}' + else + # Give up. + echo "$0: cannot determine the path of running test script" >&2 + echo "$0: test was running with Zsh version $ZSH_VERSION" >&2 + echo "$0: did you enable the NO_FUNCTION_ARGZERO option?" >&2 + exit 99 + fi else + argv0=$0 case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac fi