Source-Changes-HG archive

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

[src/trunk]: src/tests/bin/sh Add two new sub-tests to the echo test case of ...



details:   https://anonhg.NetBSD.org/src/rev/42f6d619be1a
branches:  trunk
changeset: 379200:42f6d619be1a
user:      kre <kre%NetBSD.org@localhost>
date:      Tue May 18 21:37:56 2021 +0000

description:
Add two new sub-tests to the echo test case of the t_builtins shell ATF test.

The first verifies that echo exits >0 when it encounters an I/O error on
its output (this part would have succeeded for a long time).  It also
verifies the POSIX requirement that when most standard utilities (or
perhaps many rather than most) exit(>0) they must write a message to stderr.
Our sh's built in echo did not do that (nor does /bin/echo but that's not
relevant here).

The second demonstrates (on an unfixed built-in echo) a bug reported in
private e-mail by Oguz <oguzismailuysal%gmail.com@localhost> where once an instance of
the built-in echo has detected an I/O error, all later invocations of
the built-in echo, with no I/O errors of their own, also exit(1) (the error
status on stdout is not cleared, each echo sees the "I/O error occurred" and
does exit(1)).

In this second sub-test, the "2>&-" on the first echo command is simply
an artifact caused by the test harness - the "check" function verifies
that exit((>0) requires a message on stderr (and vice versa), but that
only applies to most (or many) utilities, echo is one, but sh is not.
In the second test, the exit status comes from sh - sh is permitted to
write to stderr (via the echo command it runs in this case) and still
exit(0).   But the check function in the test does not understand that
subtlety.   So, we simply suppress the stderr message by closing stderr
(the first of these two new sub-tests has verified that the message exists)..

diffstat:

 tests/bin/sh/t_builtins.sh |  5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diffs (19 lines):

diff -r e856da031529 -r 42f6d619be1a tests/bin/sh/t_builtins.sh
--- a/tests/bin/sh/t_builtins.sh        Tue May 18 21:34:03 2021 +0000
+++ b/tests/bin/sh/t_builtins.sh        Tue May 18 21:37:56 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_builtins.sh,v 1.5 2019/01/09 10:51:23 kre Exp $
+# $NetBSD: t_builtins.sh,v 1.6 2021/05/18 21:37:56 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -291,6 +291,9 @@ echo_body() {
                done
        done
 
+       check 'echo foo >&-' "" 1
+       check 'echo foo >&- 2>&-; echo $?; echo $?' "1${nl}0${nl}" 0
+
        results
 }
 



Home | Main Index | Thread Index | Old Index