[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [BLOCKER] cannot single-step unit tests any more
From: |
Jim Meyering |
Subject: |
Re: [BLOCKER] cannot single-step unit tests any more |
Date: |
Sun, 16 May 2010 19:25:57 +0200 |
Bruno Haible wrote:
> On a glibc system, I cannot single-step unit tests that are built upon
> tests/init.sh any more. This is blocking.
...
> Two things are wrong here:
> 1) If I'm already using bash, it MUST NOT do an 'exec', because that kills the
> ability to do single-stepping.
Thanks for the report.
Besides, an unnecessary re-exec is simply wasteful.
Back when I wrote that code, I wanted to test the current shell before
any others, but my first attempt was not up to the task of accommodating
Solaris 10's twisted /bin/sh, so I stuck with the less efficient code
that worked.
Now I've tried harder, and this does the job:
>From cfa7f85bf1b1b1dcb51b27dc615f85e62710c056 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sun, 16 May 2010 18:34:08 +0200
Subject: [PATCH] init.sh: avoid unnecessary shell re-exec
* tests/init.sh: Improve the re-exec-required check to first test the
current shell. If it passes the test, do not search for a shell that
does pass, and do not re-exec. This test is particularly contorted to
avoid triggering misbehavior in Solaris 10's /bin/sh whereby any use
of $(...) evokes a syntax error and causes immediate shell exit with
status 2. Bruno Haible reported that the re-exec made it impossible
to single-step through any init.sh-using script.
---
ChangeLog | 11 +++++++++++
tests/init.sh | 41 +++++++++++++++++++++++++++--------------
2 files changed, 38 insertions(+), 14 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c365994..ea50e39 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-05-16 Jim Meyering <address@hidden>
+
+ init.sh: avoid unnecessary shell re-exec
+ * tests/init.sh: Improve the re-exec-required check to first test the
+ current shell. If it passes the test, do not search for a shell that
+ does pass, and do not re-exec. This test is particularly contorted to
+ avoid triggering misbehavior in Solaris 10's /bin/sh whereby any use
+ of $(...) evokes a syntax error and causes immediate shell exit with
+ status 2. Bruno Haible reported that the re-exec made it impossible
+ to single-step through any init.sh-using script.
+
2010-05-16 Bruno Haible <address@hidden>
Fix collision between gnulib's and libintl's printf replacements.
diff --git a/tests/init.sh b/tests/init.sh
index 05a983a..2ad385f 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -63,33 +63,46 @@
# - hyphen-containing alias names
# - we prefer to use ${var#...} substitution, rather than having
# to work around lack of support for that feature.
-# The following code attempts to find a shell with support for these features
-# and re-exec's it. If not, it skips the current test.
+# The following code attempts to find a shell with support for these features.
+# If the current shell passes the test, we're done. Otherwise, test other
+# shells until we find one that passes. If one is found, re-exec it.
+# If no acceptable shell is found, skip the current test.
+#
+# Use "9" to indicate success (rather than 0), in case some shell acts
+# like Solaris 10's /bin/sh but exits successfully instead of with status 2.
gl_shell_test_script_='
test $(echo y) = y || exit 1
-test -z "$EXEEXT" && exit 0
+test -z "$EXEEXT" && exit 9
shopt -s expand_aliases
alias a-b="echo zoo"
v=abx
test ${v%x} = ab \
&& test ${v#a} = bx \
- && test $(a-b) = zoo
+ && test $(a-b) = zoo \
+ && exit 9
'
if test "x$1" = "x--no-reexec"; then
shift
else
- for re_shell_ in "${CONFIG_SHELL:-no_shell}" /bin/sh bash dash zsh pdksh fail
- do
- test "$re_shell_" = no_shell && continue
- test "$re_shell_" = fail && skip_ failed to find an adequate shell
- if "$re_shell_" -c "$gl_shell_test_script_" 2>/dev/null; then
- exec "$re_shell_" "$0" --no-reexec "$@"
- echo "$ME_: exec failed" 1>&2
- exit 127
- fi
- done
+ # 'eval'ing the above code makes Solaris 10's /bin/sh exit with $? set to 2.
+ # It does not evaluate any of the code after the "unexpected" `('. Thus,
+ # we must run it in a subshell.
+ ( eval "$gl_shell_test_script_" ) > /dev/null 2>&1
+ if test $? != 9; then
+ for re_shell_ in "${CONFIG_SHELL:-no_shell}" /bin/sh bash dash zsh pdksh
fail
+ do
+ test "$re_shell_" = no_shell && continue
+ test "$re_shell_" = fail && skip_ failed to find an adequate shell
+ "$re_shell_" -c "$gl_shell_test_script_" 2>/dev/null
+ if test $? = 2; then
+ exec "$re_shell_" "$0" --no-reexec "$@"
+ echo "$ME_: exec failed" 1>&2
+ exit 127
+ fi
+ done
+ fi
fi
test -n "$EXEEXT" && shopt -s expand_aliases
--
1.7.1.250.g7d1e8