[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Testsuite: defs.in: work around zsh incompatibility w.r.t handli
From: |
Stefano Lattarini |
Subject: |
[PATCH] Testsuite: defs.in: work around zsh incompatibility w.r.t handling `$0' |
Date: |
Sat, 7 Nov 2009 19:59:51 +0100 |
User-agent: |
KMail/1.12.0 (Linux/2.6.26-1-686; KDE/4.3.0; i686; ; ) |
Hello automakers.
Skimming through the Zsh manpage, I found a way to work around the
incompatibility w.r.t. the way Zsh handles `$0' in sourced scripts -- the
problem being that Bourne-compatible shells always leave `$0' unchanged,
while Zsh, by default, temporarly resets `$0' to the path of the script being
sourced; more details can be found here:
http://lists.gnu.org/archive/html/bug-automake/2009-08/msg00013.html
The workaround works *only for Zsh 4.x*, but I think it's better than nothing.
A patch implementing the workaround is attached.
Regards,
Stefano
From 041b9b07f55674c08fd9c0ef6b55923ed74a2791 Mon Sep 17 00:00:00 2001
From: Stefano Lattarini <address@hidden>
Date: Fri, 6 Nov 2009 15:00:40 +0100
Subject: [PATCH] Work around zsh incompatibility w.r.t handling `$0' (testsuite
related)
* tests/README (Supported shells): When describing the manual
workaround for Zsh incompatibilties w.r.t the handling of the special
variable `$0', tell that it is now needed only with Zsh3, since we have
found an automatic workaround for Zsh4.
* tests/defs.in: For Zsh4, work around the incompatibility in the way
Zsh deal with the special variable `$0' (the workaround uses the Zsh
special variable `$functrace'). For Zsh 3, abort the script if the
option `FUNCTION_ARGZERO' is on.
---
ChangeLog | 13 +++++++++++++
tests/README | 12 +++++++-----
tests/defs.in | 31 ++++++++++++++++++++++++++-----
3 files changed, 46 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2fe0566..844b614 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2009-11-06 Stefano Lattarini <address@hidden>
+
+ In the testsuite: try to work around Zsh incompatibility w.r.t the
+ handling of the special variable `$0'.
+ * tests/README (Supported shells): When describing the manual
+ workaround for Zsh incompatibilties w.r.t the handling of the
+ special variable `$0', tell that it is now needed only with Zsh3.
+ * tests/defs.in: For Zsh4, work around the incompatibility in the
+ way Zsh deal with the special variable `$0' (the workaround uses
+ the Zsh special variable `$functrace').
+ For Zsh 3, abort the script if the option `FUNCTION_ARGZERO' is
+ on.
+
2009-10-18 Ralf Wildenhues <address@hidden>
Simplify Variable::_check_ambiguous_condition.
diff --git a/tests/README b/tests/README
index d494b10..577686a 100644
--- a/tests/README
+++ b/tests/README
@@ -71,16 +71,18 @@ Supported shells
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
+ in the handling of `$0' which conflict with our usage. Our testsuite
+ can automatically work around these incompatibilities when a version
+ 4.x or later of Zsh is used, but unfortunately not when an older (3.x)
+ version of Zsh is used. Thus, if you want to run a test script, say
+ foo.test, with Zsh 3.x, 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
+ 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.
+ /bin/sh is zsh, even a it's only a 3.x version.
Reporting failures
diff --git a/tests/defs.in b/tests/defs.in
index 6eec344..07f091a 100644
--- a/tests/defs.in
+++ b/tests/defs.in
@@ -21,7 +21,7 @@
# Tom Tromey <address@hidden>
# 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,6 +30,27 @@ 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
+ # Zsh, when not directly starting in Bourne-compatibility mode, has some
+ # incompatibilities in the handling of `$0' which conflict with our usage
+ # (e.g., `$0' inside a file sourced with the `.' builtin is temporarly
+ # set to the name of the sourced file). Work around this when possible,
+ # otherwise abort the script.
+ # Note that a bug in some versiond of Zsh prevents us from resetting $0
+ # in a sourced script, so the use of $argv0.
+ if [[ "$0" = *.'test' ]]; then
+ # Good, FUNCTION_ARGZERO option was already off when this file was
+ # sourced. Thus we've nothing to do.
+ argv0=$0
+ elif test -n "${functrace[-1]}"; then
+ # FUNCTION_ARGZERO option was on, but we have a easy workaround.
+ argv0=${functrace[-1]%:*}
+ else
+ # Give up.
+ echo "$0: (Zsh version $ZSH_VERSION) cannot determine the" \
+ "path of running test script" >&2
+ echo "$0:$LINENO: *** ABORT ***" >&2
+ exit 99
+ fi
else
case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
fi
@@ -42,8 +63,8 @@ test -f ./defs || {
if test -z "$srcdir"; then
# compute $srcdir.
- srcdir=`echo "$0" | sed -e 's,/[^\\/]*$,,'`
- test "$srcdir" = $0 && srcdir=.
+ srcdir=`echo "$argv0" | sed -e 's,/[^\\/]*$,,'`
+ test "$srcdir" = $argv0 && srcdir=.
else :; fi
# Ensure $srcdir is set correctly.
@@ -52,7 +73,7 @@ test -f "$srcdir/defs.in" || {
exit 1
}
-me=`echo "$0" | sed -e 's,.*[\\/],,;s/\.test$//'`
+me=`echo "$argv0" | sed -e 's,.*[\\/],,;s/\.test$//'`
# Make sure we override the user shell.
SHELL='@SHELL@'
@@ -321,7 +342,7 @@ unset TEST_LOGS
unset RECHECK_LOGS
unset VERBOSE
-echo "=== Running test $0"
+echo "=== Running test $argv0"
# We might need extra macros, e.g., from Libtool or Gettext.
# Find them on the system.
--
1.6.3.3
- [PATCH] Testsuite: defs.in: work around zsh incompatibility w.r.t handling `$0',
Stefano Lattarini <=