Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/bin/sh Correct a systematic atf_check usage error. O...
details: https://anonhg.NetBSD.org/src/rev/6cd2d5681c27
branches: trunk
changeset: 1026282:6cd2d5681c27
user: kre <kre%NetBSD.org@localhost>
date: Tue Nov 16 11:12:14 2021 +0000
description:
Correct a systematic atf_check usage error. One must not pipe into
atf_check and simply expect it to work - the shell is permitted to,
and our shell currently does, run all commands in a pipeline in subshell
environments - when atf_check attempts to exit to indicate failure, it
only exits from that subshell, and the rest of the test continues, usually
to indicate success
Instead, when it is necessary (or just convenient) to pipe into atf_check
check the exit status of the pipeline (if atf_check is not last, which it
would usually be, then we would need the pipefail option set - there are
currently no such cases), and explicitly fail if atf_check did not exit(0).
diffstat:
tests/bin/sh/t_redir.sh | 18 ++++++++++++------
tests/bin/sh/t_syntax.sh | 31 +++++++++++++++++++++----------
2 files changed, 33 insertions(+), 16 deletions(-)
diffs (171 lines):
diff -r dede9e7e40b0 -r 6cd2d5681c27 tests/bin/sh/t_redir.sh
--- a/tests/bin/sh/t_redir.sh Tue Nov 16 09:25:51 2021 +0000
+++ b/tests/bin/sh/t_redir.sh Tue Nov 16 11:12:14 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_redir.sh,v 1.11 2021/05/19 22:43:18 kre Exp $
+# $NetBSD: t_redir.sh,v 1.12 2021/11/16 11:12:14 kre Exp $
#
# Copyright (c) 2016 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -561,9 +561,11 @@
atf_require_prog cat
echo GOOD | atf_check -s exit:0 -o inline:'GOOD\n' -e empty \
- ${TEST_SH} -c 'read var </dev/stdin; echo $var'
+ ${TEST_SH} -c 'read var </dev/stdin; echo $var' ||
+ atf_fail "/dev/stdin test 1"
echo GOOD | atf_check -s exit:0 -o inline:'GOOD\n' -e empty \
- ${TEST_SH} -c 'cat </dev/stdin'
+ ${TEST_SH} -c 'cat </dev/stdin' ||
+ atf_fail "/dev/stdin test 2"
fi
if test -c /dev/stderr
@@ -919,13 +921,16 @@
echo ". ./f-def || echo >&2 FAIL
f
printf '%s\n' stdin1
- "| atf_check -s exit:0 -o inline:'In-Func\nstdin1\n' -e empty ${TEST_SH}
+ " | atf_check -s exit:0 -o inline:'In-Func\nstdin1\n' -e empty \
+ ${TEST_SH} ||
+ atf_fail "stdin1 test failure"
echo '
. ./f-def || echo >&2 FAIL
f >&-
printf "%s\n" stdin2
- ' | atf_check -s exit:0 -o inline:'stdin2\n' -e empty ${TEST_SH}
+ ' | atf_check -s exit:0 -o inline:'stdin2\n' -e empty ${TEST_SH} ||
+ atf_fail "stdin2 test failure"
cat <<- 'DONE' > fgh.def
f() {
@@ -983,7 +988,8 @@
echo X $( f >&- & sleep 1; g >&- & sleep 1 ; h ) Y
sleep 3
exec 4>&1 || echo FD_FAIL
- ' | atf_check -s exit:0 -o inline:'fghX Y\nGF' -e empty ${TEST_SH}
+ ' | atf_check -s exit:0 -o inline:'fghX Y\nGF' -e empty ${TEST_SH} ||
+ atf_fail "48875 stdin variant failure"
}
atf_init_test_cases() {
diff -r dede9e7e40b0 -r 6cd2d5681c27 tests/bin/sh/t_syntax.sh
--- a/tests/bin/sh/t_syntax.sh Tue Nov 16 09:25:51 2021 +0000
+++ b/tests/bin/sh/t_syntax.sh Tue Nov 16 11:12:14 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_syntax.sh,v 1.10 2018/11/14 02:37:51 kre Exp $
+# $NetBSD: t_syntax.sh,v 1.11 2021/11/16 11:12:14 kre Exp $
#
# Copyright (c) 2017 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -134,35 +134,39 @@
atf_require_prog ls
atf_require_prog printf
- cat <<- 'DONE' | atf_check -s exit:0 -o ignore -e empty ${TEST_SH} -e
+ cat <<- 'DONE' | atf_check -s exit:0 -o ignore -e empty ${TEST_SH} -e ||
l\
s
DONE
+ atf_fail "#1: ls wrapped fails"
- cat <<- 'DONE' | atf_check -s exit:7 -o empty -e empty ${TEST_SH}
+ cat <<- 'DONE' | atf_check -s exit:7 -o empty -e empty ${TEST_SH} ||
e\
x\
it \
7
DONE
+ atf_fail "#2: exit7 wrapped fails"
# Have to do this twice as cannot say "any exit code but 0 or 7" ...
cat <<- 'DONE' | atf_check -s not-exit:0 -o empty -e not-empty \
- ${TEST_SH}
+ ${TEST_SH} ||
e\
x\
it\
7
DONE
+ atf_fail "#3a: !exit(0||7) badly wrapped fails (0)"
cat <<- 'DONE' | atf_check -s not-exit:7 -o empty -e not-empty \
- ${TEST_SH}
+ ${TEST_SH} ||
e\
x\
it\
7
DONE
+ atf_fail "#3b: !exit(0||7) badly wrapped fails (7)"
- cat <<- 'DONE' | atf_check -s exit:0 -o empty -e empty ${TEST_SH}
+ cat <<- 'DONE' | atf_check -s exit:0 -o empty -e empty ${TEST_SH} ||
wh\
il\
e \
@@ -173,9 +177,10 @@
;
done
DONE
+ atf_fail "#4: wrapped while fails"
cat <<- 'DONE' | atf_check -s exit:0 -o inline:'hellohellohellohello' \
- -e empty ${TEST_SH}
+ -e empty ${TEST_SH} ||
V\
AR=hel\
lo
@@ -214,8 +219,9 @@
\
FAIL}
DONE
+ atf_fail "#5: wrapped var expansions fails"
- cat <<- 'DONE' | atf_check -s exit:0 -o inline:'2\n' ${TEST_SH}
+ cat <<- 'DONE' | atf_check -s exit:0 -o inline:'2\n' ${TEST_SH} ||
l\
s=7 bi\
n\
@@ -225,6 +231,7 @@
( ls /bin )\
)
DONE
+ atf_fail "#6: wrapped command substitution fails"
# Inspired by src/etc/MAKEDEV.tmpl failure with (broken)
# sh LINENO code... avoid it happening again...
@@ -248,7 +255,7 @@
done
)
- cat <<- 'DONE' | atf_check -s exit:0 -o inline:"${R}" ${TEST_SH}
+ cat <<- 'DONE' |
case $(( $($a && echo 1 || echo 0) + \
$($b && echo 1 || echo 0) + \
$($c && echo 1 || echo 0) + \
@@ -258,12 +265,14 @@
(*) printf BAD ;;
esac
DONE
+ atf_check -s exit:0 -o inline:"${R}" ${TEST_SH} ||
+ atf_fail "#7 (${VARS}): wrapped arith fails"
done
# inspired by pkgsrc/pkgtools/cwrappers :: libnbcompat/configure
# failure with (broken) sh LINENO code .. avoid recurrence
# This test would have failed.
- cat <<- 'DONE' | atf_check -s exit:0 -o inline:'/tmp\n' ${TEST_SH}
+ cat <<- 'DONE' | atf_check -s exit:0 -o inline:'/tmp\n' ${TEST_SH} ||
dn=/tmp/foo
D=`dirname -- "${dn}" ||
@@ -292,6 +301,8 @@
echo "${D}"
DONE
+ atf_fail "#8: cwrappers/LINENO bug test failed"
+
return 0
}
Home |
Main Index |
Thread Index |
Old Index