Module Name: src Committed By: kre Date: Tue Nov 16 11:12:15 UTC 2021
Modified Files: src/tests/bin/sh: t_redir.sh t_syntax.sh Log Message: 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). To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/tests/bin/sh/t_redir.sh cvs rdiff -u -r1.10 -r1.11 src/tests/bin/sh/t_syntax.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/bin/sh/t_redir.sh diff -u src/tests/bin/sh/t_redir.sh:1.11 src/tests/bin/sh/t_redir.sh:1.12 --- src/tests/bin/sh/t_redir.sh:1.11 Wed May 19 22:43:18 2021 +++ src/tests/bin/sh/t_redir.sh Tue Nov 16 11:12:14 2021 @@ -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 @@ named_fd_redirections_body() 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 @@ validate_fn_redirects_body() 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 @@ validate_fn_redirects_body() 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() { Index: src/tests/bin/sh/t_syntax.sh diff -u src/tests/bin/sh/t_syntax.sh:1.10 src/tests/bin/sh/t_syntax.sh:1.11 --- src/tests/bin/sh/t_syntax.sh:1.10 Wed Nov 14 02:37:51 2018 +++ src/tests/bin/sh/t_syntax.sh Tue Nov 16 11:12:14 2021 @@ -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 @@ c_line_wrapping_body() { 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 @@ c_line_wrapping_body() { ; 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 @@ c_line_wrapping_body() { \ 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 @@ c_line_wrapping_body() { ( 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 @@ c_line_wrapping_body() { 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 @@ c_line_wrapping_body() { (*) 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 @@ c_line_wrapping_body() { echo "${D}" DONE + atf_fail "#8: cwrappers/LINENO bug test failed" + return 0 }