On 06/03/2014 04:36 PM, Eric Blake wrote:
> On 06/03/2014 09:14 AM, Pádraig Brady wrote:
> 
>> Or just leave it as is?
>> I.E. true can return false in the edge cases where it needs to.
> 
> I'm liking this idea more - and we can extend it to make 'false
> --version' return a different status for write failure than its normal
> always-1 status for successfully reporting false.

We can do that, though I'm not sure we should bother
since users would probably never need the separated values
for this extreme edge case.

>> I can fix up the test issues I noticed separately.
> 
> Yes, at this point, separating the test snafu of only covering the
> builtin from any change in exit status behavior is wise.

Attached.

thanks,
Pádraig.
>From 55f57ea69ec2fd08394c9107fe09afeea92c8436 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Tue, 3 Jun 2014 10:50:09 +0100
Subject: [PATCH] tests: consolidate tests for true and false

* src/true.c (main): Add a comment about the possibility
of true returning EXIT_FAILURE due to write failure.
* tests/misc/false-status.sh: Fix so we're testing
the tool and not the shell builtin.  Add a case for true(1).
* tests/misc/help-version.sh: Skip /dev/full test
for true as well as false since the exit status is tested separately.
Also remove the iterations for different LC_MESSAGES, as this was only
apploed for false(1).  Translations are not honored in the test dir
and so would need separate handling in any case.
---
 src/true.c                 |    2 +
 tests/misc/false-status.sh |   12 ++++++--
 tests/misc/help-version.sh |   65 ++++++++++++++++++++-----------------------
 3 files changed, 41 insertions(+), 38 deletions(-)

diff --git a/src/true.c b/src/true.c
index 219f98c..8a1c4f9 100644
--- a/src/true.c
+++ b/src/true.c
@@ -64,6 +64,8 @@ main (int argc, char **argv)
       bindtextdomain (PACKAGE, LOCALEDIR);
       textdomain (PACKAGE);
 
+      /* Note true(1) will return EXIT_FAILURE in the
+         edge case where writes fail with GNU specific options.  */
       atexit (close_stdout);
 
       if (STREQ (argv[1], "--help"))
diff --git a/tests/misc/false-status.sh b/tests/misc/false-status.sh
index b943040..77bea45 100755
--- a/tests/misc/false-status.sh
+++ b/tests/misc/false-status.sh
@@ -1,5 +1,6 @@
 #!/bin/sh
 # ensure that false exits nonzero even with --help or --version
+# and ensure that true exits nonzero when it can't write --help or --version
 
 # Copyright (C) 2003-2014 Free Software Foundation, Inc.
 
@@ -17,9 +18,14 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
-print_ver_ false
+print_ver_ false true
 
-false --version > /dev/null && fail=1
-false --help > /dev/null && fail=1
+env false --version > /dev/null && fail=1
+env false --help > /dev/null && fail=1
+
+if test -w /dev/full && test -c /dev/full; then
+  env true --version > /dev/full && fail=1
+  env true --help > /dev/full && fail=1
+fi
 
 Exit $fail
diff --git a/tests/misc/help-version.sh b/tests/misc/help-version.sh
index 4bc02d8..b4939f7 100755
--- a/tests/misc/help-version.sh
+++ b/tests/misc/help-version.sh
@@ -70,43 +70,38 @@ done
 test "x$v" = "x$VERSION" \
   || fail_ "--version-\$VERSION mismatch"
 
-for lang in C fr da; do
-  for i in $built_programs; do
-
-    # Skip 'test'; it doesn't accept --help or --version.
-    test $i = test && continue;
-
-    # false fails even when invoked with --help or --version.
-    if test $i = false; then
-      env LC_MESSAGES=$lang $i --help >/dev/null && fail=1
-      env LC_MESSAGES=$lang $i --version >/dev/null && fail=1
-      continue
-    fi
+for i in $built_programs; do
 
-    # The just-built install executable is always named 'ginstall'.
-    test $i = install && i=ginstall
-
-    # Make sure they exit successfully, under normal conditions.
-    env $i --help    >/dev/null || fail=1
-    env $i --version >/dev/null || fail=1
-
-    # Make sure they fail upon 'disk full' error.
-    if test -w /dev/full && test -c /dev/full; then
-      env $i --help    >/dev/full 2>/dev/null && fail=1
-      env $i --version >/dev/full 2>/dev/null && fail=1
-      status=$?
-      test $i = [ && prog=lbracket || prog=$(echo $i|sed "s/$EXEEXT$//")
-      eval "expected=\$expected_failure_status_$prog"
-      test x$expected = x && expected=1
-      if test $status = $expected; then
-        : # ok
-      else
-        fail=1
-        echo "*** $i: bad exit status '$status' (expected $expected)," 1>&2
-        echo "  with --help or --version output redirected to /dev/full" 1>&2
-      fi
+  # Skip 'test'; it doesn't accept --help or --version.
+  test $i = test && continue
+
+  # false fails even when invoked with --help or --version.
+  # true and false are tested with these options separately.
+  test $i = false || test $i = true && continue
+
+  # The just-built install executable is always named 'ginstall'.
+  test $i = install && i=ginstall
+
+  # Make sure they exit successfully, under normal conditions.
+  env $i --help    >/dev/null || fail=1
+  env $i --version >/dev/null || fail=1
+
+  # Make sure they fail upon 'disk full' error.
+  if test -w /dev/full && test -c /dev/full; then
+    env $i --help    >/dev/full 2>/dev/null && fail=1
+    env $i --version >/dev/full 2>/dev/null && fail=1
+    status=$?
+    test $i = [ && prog=lbracket || prog=$(echo $i|sed "s/$EXEEXT$//")
+    eval "expected=\$expected_failure_status_$prog"
+    test x$expected = x && expected=1
+    if test $status = $expected; then
+      : # ok
+    else
+      fail=1
+      echo "*** $i: bad exit status '$status' (expected $expected)," 1>&2
+      echo "  with --help or --version output redirected to /dev/full" 1>&2
     fi
-  done
+  fi
 done
 
 bigZ_in=bigZ-in.Z
-- 
1.7.7.6

Reply via email to