From 29ca903b799b0a319f881701788f9b350ac50cc8 Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Mon, 13 Jun 2011 22:42:25 +0200 Subject: [PATCH] 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: --- ChangeLog | 29 +++++++++++++++++++++++++++++ tests/Makefile.am | 13 ++++++++++--- tests/Makefile.in | 13 ++++++++++--- tests/defs | 5 +++-- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 37c0a69..751410a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2011-06-14 Stefano Lattarini + Jim Meyering + + 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: + + + + 2011-06-13 Stefano Lattarini tests: don't hard-code test name in txinfo21.test diff --git a/tests/Makefile.am b/tests/Makefile.am index 9b979d4..e9172d2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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) \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 92daaf3..57791f3 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -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) \ diff --git a/tests/defs b/tests/defs index df62751..4f6f3b2 100644 --- a/tests/defs +++ b/tests/defs @@ -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} -- 2.7.4