bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [BLOCKER] cannot single-step unit tests any more


From: Bruno Haible
Subject: Re: [BLOCKER] cannot single-step unit tests any more
Date: Sun, 16 May 2010 22:25:34 +0200
User-agent: KMail/1.9.9

Hi Jim,

> > 2) The use of "$0". It is meant to denote the test-....sh filename. This 
> > CANNOT
> >    work when single-stepping, because the statements are not contained in a 
> > file
> >    but are executed interactively, one by one.
> 
> I don't see how this can cause a problem.
> 
> The only uses of $0 are in the re-exec code (which appear not to matter
> when single stepping)

If the user starts a shell other than bash interactively, and tries to do
". ./init.sh", he may fall into the re-exec code, and the init.sh script
will then kill his interactive process, which is unfriendly (it may kill
his xterm, leaving him completely clueless about what happened).

It is safer to try to re-exec and use "$0" when there is enough confidence
that the execution mode is not interactive. Here is a proposed patch.
(Btw, $ME_ was used before being initialized.) I have also no problem
indenting the big 'if/else' branch by 2 spaces.


2010-05-16  Bruno Haible  <address@hidden>

        init.sh: Avoid aborting from an interactive shell.
        * tests/init.sh (gl_better_shell_): New variable.
        When executing in an interactive shell, don't re-exec; instead, give a
        warning and skip to the end of the file.

--- tests/init.sh.orig  Sun May 16 22:16:25 2010
+++ tests/init.sh       Sun May 16 22:15:53 2010
@@ -71,6 +71,8 @@
 # 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_better_shell_=
+
 gl_shell_test_script_='
 test $(echo y) = y || exit 1
 test -z "$EXEEXT" && exit 9
@@ -98,14 +100,45 @@
       "$re_shell_" -c "$gl_shell_test_script_" 2>/dev/null
       if test $? = 9; then
         # Found a better shell than the current one.
-        exec "$re_shell_" "$0" --no-reexec "$@"
-        echo "$ME_: exec failed" 1>&2
-        exit 127
+        gl_better_shell_="$re_shell_"
+        break
       fi
     done
   fi
 fi
 
+if test -n "$gl_better_shell_"; then
+  # Try to distinguish the case where a test is executed as a script - in this
+  # case "$0" evaluates to the script, and we can use 'exec' - from the case
+  # where it is executed in single-stepping, interactively - in this case it
+  # is better to alert the user and skip the rest of this script.
+  if { if test -n "$BASH_VERSION"; then
+         # Test whether the shell is not interactive. See
+         # 
<http://www.gnu.org/software/bash/manual/html_node/Is-this-Shell-Interactive_003f.html>
+         case "$-" in
+           *i*) false;;
+           *) true;;
+         esac
+       else
+         # Test whether "$0" points to a test script.
+         case "$0" in
+           *.sh) true;;
+           *) false;;
+         esac
+       fi
+     }; then
+    # We're executing a script.
+    exec "$re_shell_" "$0" --no-reexec "$@"
+    ME_=`expr "./$0" : '.*/\(.*\)$'`
+    echo "$ME_: exec failed" 1>&2
+    exit 127
+  fi
+fi
+if test -n "$gl_better_shell_"; then
+  # We're executing interactively.
+  echo "*** init.sh: the current shell is not adequate, use a better one (such 
as bash)" 1>&2
+else # This conditional extends to the end of the file.
+
 test -n "$EXEEXT" && shopt -s expand_aliases
 
 # Enable glibc's malloc-perturbing option.
@@ -381,3 +414,5 @@
   && . "$srcdir/init.cfg"
 
 setup_ "$@"
+
+fi # End of conditional for "$gl_better_shell_".



reply via email to

[Prev in Thread] Current Thread [Next in Thread]