tests: init.sh improvements for re-exec'ing with zsh
authorEric Blake <eblake@redhat.com>
Thu, 2 Sep 2010 19:49:41 +0000 (13:49 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 2 Sep 2010 21:00:12 +0000 (15:00 -0600)
Tom's IRIX setup had a broken bash, and proceeded to run zsh
outside of POSIX mode.  But trying to trace that setup proved
difficult, since the re-exec lost tracing.

* tests/init.sh: Borrow autoconf POSIX-mode sanitization.  Pass
-vx through shell re-exec.
Reported by Tom G. Christensen.

Signed-off-by: Eric Blake <eblake@redhat.com>
ChangeLog
tests/init.sh

index 72642d1..5be2ceb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 
 2010-09-02  Eric Blake  <eblake@redhat.com>
 
+       tests: init.sh improvements for re-exec'ing with zsh
+       * tests/init.sh: Borrow autoconf POSIX-mode sanitization.  Pass
+       -vx through shell re-exec.
+       Reported by Tom G. Christensen.
+
        wctype: fix typo in previous commit
        * m4/wctype_h.m4 (gl_WCTYPE_H): Fix spelling.
        Reported by Ludovic Courtès.
index bc82d69..fe2c224 100644 (file)
@@ -79,6 +79,19 @@ fail_() { warn_ "$ME_: failed test: $@"; Exit 1; }
 skip_() { warn_ "$ME_: skipped test: $@"; Exit 77; }
 framework_failure_() { warn_ "$ME_: set-up failure: $@"; Exit 99; }
 
+# Sanitize this shell to POSIX mode, if possible.
+DUALCASE=1; export DUALCASE
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in
+    *posix*) set -o posix ;;
+  esac
+fi
+
 # We require $(...) support unconditionally.
 # We require a few additional shell features only when $EXEEXT is nonempty,
 # in order to support automatic $EXEEXT emulation:
@@ -122,8 +135,14 @@ else
       test "$re_shell_" = fail && skip_ failed to find an adequate shell
       "$re_shell_" -c "$gl_shell_test_script_" 2>/dev/null
       if test $? = 9; then
-        # Found an acceptable shell.
-        exec "$re_shell_" "$0" --no-reexec "$@"
+        # Found an acceptable shell.  Preserve -v and -x.
+        case $- in
+          *v*x* | *x*v*) opts_=-vx ;;
+          *v*) opts_=-v ;;
+          *x*) opts_=-x ;;
+          *) opts_= ;;
+        esac
+        exec "$re_shell_" $opts_ "$0" --no-reexec "$@"
         echo "$ME_: exec failed" 1>&2
         exit 127
       fi