test defs: fix ksh-related portability bug in warning messages
authorStefano Lattarini <stefano.lattarini@gmail.com>
Mon, 13 Jun 2011 20:42:25 +0000 (22:42 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Tue, 14 Jun 2011 15:15:49 +0000 (17:15 +0200)
Running "make check" normally prints a diagnostic to the outermost
stderr (usually a tty) to explain why a test is skipped, thus
giving better and faster feedback to the user.  It used to do
so by redirecting file descriptor 9 to stderr (via "exec 9>&2")
before invoking the test scripts, which then would write any skip
explanation to file descriptor 9 via the `skip_' function defined
in `tests/defs'.

However, various Korn Shells (at least Solaris 10's /bin/ksh and
Debian GNU/Linux's /bin/ksh) and the HP-UX's /bin/sh close open
file descriptors > 2 upon an `exec' system call; thus the effects
of "exec 9>&2" are cancelled upon fork-and-exec, so we would get
a "Bad file number" diagnostic and no skip explanation with those
shells.

The present change remedies this situation.

* tests/Makefile.am (AM_TESTS_ENVIRONMENT): Redirect more portably,
via a trailing "9>&2", rather than the prior "exec 9>&2; ...".  Add
explanatory comments.
* tests/defs (stderr_fileno_): Update the advice in comments.

Based on commit v8.12-82-g6b68745 "tests: accommodate HP-UX and
ksh-derived shells" in GNU coreutils.

Further references, with lots of discussion:
 <http://lists.gnu.org/archive/html/bug-autoconf/2011-06/msg00002.html>
 <http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/22488>
 <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8846>

ChangeLog
tests/Makefile.am
tests/Makefile.in
tests/defs

index 37c0a69..751410a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2011-06-14  Stefano Lattarini  <stefano.lattarini@gmail.com>
+           Jim Meyering  <meyering@redhat.com>
+
+       test defs: fix ksh-related portability bug in warning messages
+       Running "make check" normally prints a diagnostic to the outermost
+       stderr (usually a tty) to explain why a test is skipped, thus
+       giving better and faster feedback to the user.  It used to do
+       so by redirecting file descriptor 9 to stderr (via "exec 9>&2")
+       before invoking the test scripts, which then would write any skip
+       explanation to file descriptor 9 via the `skip_' function defined
+       in `tests/defs'.
+       However, various Korn Shells (at least Solaris 10's /bin/ksh and
+       Debian GNU/Linux's /bin/ksh) and the HP-UX's /bin/sh close open
+       file descriptors > 2 upon an `exec' system call; thus the effects
+       of "exec 9>&2" are cancelled upon fork-and-exec, so we would get
+       a "Bad file number" diagnostic and no skip explanation with those
+       shells.
+       The present change remedies this situation.
+       * tests/Makefile.am (AM_TESTS_ENVIRONMENT): Redirect more portably,
+       via a trailing "9>&2", rather than the prior "exec 9>&2; ...".  Add
+       explanatory comments.
+       * tests/defs (stderr_fileno_): Update the advice in comments.
+       Based on commit v8.12-82-g6b68745 "tests: accommodate HP-UX and
+       ksh-derived shells" in GNU coreutils.
+       Further references, with lots of discussion:
+        <http://lists.gnu.org/archive/html/bug-autoconf/2011-06/msg00002.html>
+        <http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/22488>
+        <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8846>
+
 2011-06-13  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
        tests: don't hard-code test name in txinfo21.test
index 9b979d4..e9172d2 100644 (file)
@@ -124,12 +124,19 @@ $(config_shell_tests):
 
 # Some testsuite-influential variables should be overridable from the
 # test scripts, but not from the environment.
-# We want warning messages and explanations for skipped tests to go to
-# the console if possible, so set up `stderr_fileno_' properly.
 # The `AM_TESTS_REEXEC=no' setting tells the tests not to needlessly
 # re-execute themselves with the shell detected at configure time, since
 # we are already running them under it explicitly in our setup (see e.g.
 # the definition of TEST_LOG_COMPILER above).
+# We want warning messages and explanations for skipped tests to go to
+# the console if possible, so set up `stderr_fileno_' properly.
+# The `9>&2' redirection *must* be placed at the end, and without a
+# following semicolon, because some shells (e.g., various Korn Shells
+# or HP-HX /bin/sh) close any file descriptor > 2 upon `exec' sycall.
+# For more references, with lots of discussion, see:
+#  - http://lists.gnu.org/archive/html/bug-autoconf/2011-06/msg00002.html
+#  - http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/22488
+#  - http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8846
 AM_TESTS_ENVIRONMENT = \
   test x"$$me" = x || unset me; \
   test x"$$required" = x || unset required; \
@@ -137,7 +144,7 @@ AM_TESTS_ENVIRONMENT = \
   test x"$$original_AUTOMAKE" = x || unset original_AUTOMAKE; \
   test x"$$original_ACLOCAL" = x || unset original_ACLOCAL; \
   AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC; \
-  exec 9>&2; stderr_fileno_=9; export stderr_fileno_;
+  stderr_fileno_=9; export stderr_fileno_; 9>&2
 
 TESTS = \
   $(handwritten_tests) \
index 92daaf3..57791f3 100644 (file)
@@ -409,12 +409,19 @@ config_shell_tests = \
 
 # Some testsuite-influential variables should be overridable from the
 # test scripts, but not from the environment.
-# We want warning messages and explanations for skipped tests to go to
-# the console if possible, so set up `stderr_fileno_' properly.
 # The `AM_TESTS_REEXEC=no' setting tells the tests not to needlessly
 # re-execute themselves with the shell detected at configure time, since
 # we are already running them under it explicitly in our setup (see e.g.
 # the definition of TEST_LOG_COMPILER above).
+# We want warning messages and explanations for skipped tests to go to
+# the console if possible, so set up `stderr_fileno_' properly.
+# The `9>&2' redirection *must* be placed at the end, and without a
+# following semicolon, because some shells (e.g., various Korn Shells
+# or HP-HX /bin/sh) close any file descriptor > 2 upon `exec' sycall.
+# For more references, with lots of discussion, see:
+#  - http://lists.gnu.org/archive/html/bug-autoconf/2011-06/msg00002.html
+#  - http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/22488
+#  - http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8846
 AM_TESTS_ENVIRONMENT = \
   test x"$$me" = x || unset me; \
   test x"$$required" = x || unset required; \
@@ -422,7 +429,7 @@ AM_TESTS_ENVIRONMENT = \
   test x"$$original_AUTOMAKE" = x || unset original_AUTOMAKE; \
   test x"$$original_ACLOCAL" = x || unset original_ACLOCAL; \
   AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC; \
-  exec 9>&2; stderr_fileno_=9; export stderr_fileno_;
+  stderr_fileno_=9; export stderr_fileno_; 9>&2
 
 TESTS = \
   $(handwritten_tests) \
index df62751..4f6f3b2 100644 (file)
@@ -169,8 +169,9 @@ Exit ()
 
 # Print warnings (e.g., about skipped and failed tests) to this file
 # number.  Override by putting, say:
-#   stderr_fileno_=9; export stderr_fileno_; exec 9>&2;
-# in the definition of AM_TESTS_ENVIRONMENT.
+#   stderr_fileno_=9; export stderr_fileno_; 9>&2
+# at the *end* (yes, this is mandatory; see comments in Makefile.am) of
+# the definition of AM_TESTS_ENVIRONMENT.
 # This is useful when using automake's parallel tests mode, to print the
 # reason for skip/failure to console, rather than to the *.log files.
 : ${stderr_fileno_=2}