Improved handling of TEST_SH so that it is possible to define it

to the name of a shell, plus options that shell needs to run it
in the correct mode to be tested: eg: TEST_SH='bash -o posix'
Also finished the implementation of tests of "set -n" now that
the NetBSD shell supports that as it should. (from kre)
This commit is contained in:
christos 2016-03-01 12:39:35 +00:00
parent ce76f88f8f
commit 06f9bef68e
4 changed files with 139 additions and 73 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: t_exit.sh,v 1.4 2016/02/24 14:42:06 christos Exp $ # $NetBSD: t_exit.sh,v 1.5 2016/03/01 12:39:35 christos Exp $
# #
# Copyright (c) 2007 The NetBSD Foundation, Inc. # Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved. # All rights reserved.
@ -34,9 +34,9 @@ background_head() {
"a command in the background (PR bin/46327)" "a command in the background (PR bin/46327)"
} }
background_body() { background_body() {
atf_check -o match:0 -e empty "${TEST_SH}" -c 'true; true & echo $?' atf_check -o match:0 -e empty ${TEST_SH} -c 'true; true & echo $?'
# atf_expect_fail "PR bin/46327" (now fixed?) # atf_expect_fail "PR bin/46327" (now fixed?)
atf_check -o match:0 -e empty "${TEST_SH}" -c 'false; true & echo $?' atf_check -o match:0 -e empty ${TEST_SH} -c 'false; true & echo $?'
} }
atf_test_case function atf_test_case function
@ -46,7 +46,7 @@ function_head() {
} }
function_body() { function_body() {
atf_check -s exit:0 -o match:STATUS=1-0 -e empty \ atf_check -s exit:0 -o match:STATUS=1-0 -e empty \
"${TEST_SH}" -c ' ${TEST_SH} -c '
crud() { crud() {
test yes = no test yes = no
@ -66,7 +66,7 @@ readout_head() {
} }
readout_body() { readout_body() {
atf_check -s exit:0 -o match:0 -e empty \ atf_check -s exit:0 -o match:0 -e empty \
"${TEST_SH}" -c 'true && ! true | false; echo $?' ${TEST_SH} -c 'true && ! true | false; echo $?'
} }
atf_test_case trap_subshell atf_test_case trap_subshell
@ -87,7 +87,7 @@ trap_zero__implicit_exit_head() {
trap_zero__implicit_exit_body() { trap_zero__implicit_exit_body() {
# PR bin/6764: sh works but ksh does not # PR bin/6764: sh works but ksh does not
echo '( trap "echo exiting" 0 )' >helper.sh echo '( trap "echo exiting" 0 )' >helper.sh
atf_check -s exit:0 -o match:exiting -e empty "${TEST_SH}" helper.sh atf_check -s exit:0 -o match:exiting -e empty ${TEST_SH} helper.sh
# test ksh by setting TEST_SH to /bin/ksh and run the entire set... # test ksh by setting TEST_SH to /bin/ksh and run the entire set...
# atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh # atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh
} }
@ -100,7 +100,7 @@ trap_zero__explicit_exit_head() {
trap_zero__explicit_exit_body() { trap_zero__explicit_exit_body() {
echo '( trap "echo exiting" 0; exit; echo NO_NO_NO )' >helper.sh echo '( trap "echo exiting" 0; exit; echo NO_NO_NO )' >helper.sh
atf_check -s exit:0 -o match:exiting -o not-match:NO_NO -e empty \ atf_check -s exit:0 -o match:exiting -o not-match:NO_NO -e empty \
"${TEST_SH}" helper.sh ${TEST_SH} helper.sh
# test ksh by setting TEST_SH to /bin/ksh and run the entire set... # test ksh by setting TEST_SH to /bin/ksh and run the entire set...
# atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh # atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh
} }
@ -115,7 +115,7 @@ trap_zero__explicit_return_body() {
echo '( trap "echo exiting" 0; return; echo NO_NO_NO )' >helper.sh echo '( trap "echo exiting" 0; return; echo NO_NO_NO )' >helper.sh
atf_expect_fail "return from a sub-shell not defined and does not work" atf_expect_fail "return from a sub-shell not defined and does not work"
atf_check -s exit:0 -o match:exiting -o not-match:NO_NO -e empty \ atf_check -s exit:0 -o match:exiting -o not-match:NO_NO -e empty \
"${TEST_SH}" helper.sh ${TEST_SH} helper.sh
# test ksh by setting TEST_SH to /bin/ksh and run the entire set... # test ksh by setting TEST_SH to /bin/ksh and run the entire set...
# atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh # atf_check -s exit:0 -o match:exiting -e empty /bin/ksh helper.sh
} }
@ -129,7 +129,7 @@ simple_exit_body() {
for N in 0 1 2 3 4 5 6 42 99 101 125 126 127 128 129 200 254 255 for N in 0 1 2 3 4 5 6 42 99 101 125 126 127 128 129 200 254 255
do do
atf_check -s exit:$N -o empty -e empty \ atf_check -s exit:$N -o empty -e empty \
"${TEST_SH}" -c "exit $N; echo FOO; echo BAR >&2" ${TEST_SH} -c "exit $N; echo FOO; echo BAR >&2"
done done
} }
@ -142,7 +142,7 @@ subshell_exit_body() {
for N in 0 1 2 3 4 5 6 42 99 101 125 126 127 128 129 200 254 255 for N in 0 1 2 3 4 5 6 42 99 101 125 126 127 128 129 200 254 255
do do
atf_check -s exit:0 -o empty -e empty \ atf_check -s exit:0 -o empty -e empty \
"${TEST_SH}" -c "(exit $N); test \$? -eq $N" ${TEST_SH} -c "(exit $N); test \$? -eq $N"
done done
} }
@ -153,10 +153,10 @@ subshell_background_head() {
} }
subshell_background_body() { subshell_background_body() {
atf_check -o match:0 -e empty \ atf_check -o match:0 -e empty \
"${TEST_SH}" -c 'true; (false || true) & echo $?' ${TEST_SH} -c 'true; (false || true) & echo $?'
# atf_expect_fail "PR bin/46327" (now fixed?) # atf_expect_fail "PR bin/46327" (now fixed?)
atf_check -o match:0 -e empty \ atf_check -o match:0 -e empty \
"${TEST_SH}" -c 'false; (false || true) & echo $?' ${TEST_SH} -c 'false; (false || true) & echo $?'
} }
atf_init_test_cases() { atf_init_test_cases() {

View File

@ -1,4 +1,4 @@
# $NetBSD: t_here.sh,v 1.2 2016/02/29 23:52:53 christos Exp $ # $NetBSD: t_here.sh,v 1.3 2016/03/01 12:39:35 christos Exp $
# #
# Copyright (c) 2007 The NetBSD Foundation, Inc. # Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved. # All rights reserved.
@ -39,7 +39,6 @@ check()
# some of the tests expect us to expand $nl internally... # some of the tests expect us to expand $nl internally...
CMD="nl='${nl}'; $1" CMD="nl='${nl}'; $1"
echo "${CMD}" >/tmp/CMD
rm -f trace.* rm -f trace.*
result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" )" result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" )"
STATUS=$? STATUS=$?
@ -193,11 +192,11 @@ EOF
} }
atf_test_case viscious atf_test_case vicious
viscious_head() { vicious_head() {
atf_set "descr" "Tests for obscure and obnoxious uses of here docs" atf_set "descr" "Tests for obscure and obnoxious uses of here docs"
} }
viscious_body() { vicious_body() {
cat <<- \END_SCRIPT > script cat <<- \END_SCRIPT > script
cat <<ONE && cat \ cat <<ONE && cat \
@ -215,7 +214,7 @@ viscious_body() {
# will not check what it produces. The eventual result # will not check what it produces. The eventual result
# seems unlikely to be what we currently output, which # seems unlikely to be what we currently output, which
# is: # is:
# :echo line 1 # A:echo line 1
# B:echo line 2)" && prefix DASH_CODE <<DASH_CODE # B:echo line 2)" && prefix DASH_CODE <<DASH_CODE
# B:echo line 3 # B:echo line 3
# line 4 # line 4
@ -257,5 +256,5 @@ atf_init_test_cases() {
atf_add_test_case do_simple atf_add_test_case do_simple
atf_add_test_case incomplete atf_add_test_case incomplete
atf_add_test_case multiple # multiple << operators on one cmd atf_add_test_case multiple # multiple << operators on one cmd
atf_add_test_case viscious # evil test from the austin-l list... atf_add_test_case vicious # evil test from the austin-l list...
} }

View File

@ -1,4 +1,4 @@
# $NetBSD: t_option.sh,v 1.1 2016/02/23 16:20:42 christos Exp $ # $NetBSD: t_option.sh,v 1.2 2016/03/01 12:39:35 christos Exp $
# #
# Copyright (c) 2016 The NetBSD Foundation, Inc. # Copyright (c) 2016 The NetBSD Foundation, Inc.
# All rights reserved. # All rights reserved.
@ -52,7 +52,7 @@ test_option_on_off()
test "${#opt}" -gt 1 && test "${#opt}" -gt 1 &&
CLEAR='xx="$-" && xx=$(echo "$xx" | tr -d cs) && test -n "$xx" && set +"$xx";' CLEAR='xx="$-" && xx=$(echo "$xx" | tr -d cs) && test -n "$xx" && set +"$xx";'
atf_check -s exit:0 -o empty -e empty "${TEST_SH}" -c \ atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
"opt=${opt}"' "opt=${opt}"'
x() { x() {
echo "ERROR: Unable to $1 option $2" >&2 echo "ERROR: Unable to $1 option $2" >&2
@ -101,7 +101,7 @@ test_optional_on_off()
for opt for opt
do do
test "${opt}" = n && continue test "${opt}" = n && continue
"${TEST_SH}" -c "set -${opt}" 2>/dev/null && ${TEST_SH} -c "set -${opt}" 2>/dev/null &&
OPTS="${OPTS} ${opt}" || RET=1 OPTS="${OPTS} ${opt}" || RET=1
done done
@ -122,11 +122,11 @@ set_a_body() {
test_option_on_off a test_option_on_off a
# without -a, new variables should not be exported (so grep "fails") # without -a, new variables should not be exported (so grep "fails")
atf_check -s exit:1 -o empty -e empty "${TEST_SH}" -ce \ atf_check -s exit:1 -o empty -e empty ${TEST_SH} -ce \
'unset VAR; set +a; VAR=value; env | grep "^VAR="' 'unset VAR; set +a; VAR=value; env | grep "^VAR="'
# with -a, they should be # with -a, they should be
atf_check -s exit:0 -o match:VAR=value -e empty "${TEST_SH}" -ce \ atf_check -s exit:0 -o match:VAR=value -e empty ${TEST_SH} -ce \
'unset VAR; set -a; VAR=value; env | grep "^VAR="' 'unset VAR; set -a; VAR=value; env | grep "^VAR="'
} }
@ -150,7 +150,7 @@ set_C_body() {
echo Precious_Content > Important_File echo Precious_Content > Important_File
# Check that we can redirect onto file when -C is not set # Check that we can redirect onto file when -C is not set
atf_check -s exit:0 -o empty -e empty "${TEST_SH}" -c \ atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
' '
D=$(ls -l Junk_File) || exit 1 D=$(ls -l Junk_File) || exit 1
set +C set +C
@ -160,7 +160,7 @@ set_C_body() {
' '
# Check that we cannot redirect onto file when -C is set # Check that we cannot redirect onto file when -C is set
atf_check -s exit:0 -o empty -e not-empty "${TEST_SH}" -c \ atf_check -s exit:0 -o empty -e not-empty ${TEST_SH} -c \
' '
D=$(ls -l Important_File) || exit 1 D=$(ls -l Important_File) || exit 1
set -C set -C
@ -170,7 +170,7 @@ set_C_body() {
' '
# Check that we can append to file, even when -C is set # Check that we can append to file, even when -C is set
atf_check -s exit:0 -o empty -e empty "${TEST_SH}" -c \ atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
' '
D=$(ls -l Junk_File) || exit 1 D=$(ls -l Junk_File) || exit 1
set -C set -C
@ -180,7 +180,7 @@ set_C_body() {
' '
# Check that we abort on attempt to redirect onto file when -Ce is set # Check that we abort on attempt to redirect onto file when -Ce is set
atf_check -s not-exit:0 -o empty -e not-empty "${TEST_SH}" -c \ atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
' '
set -Ce set -Ce
echo "Fail to Overwrite it now" > Important_File echo "Fail to Overwrite it now" > Important_File
@ -188,7 +188,7 @@ set_C_body() {
' '
# Last check that we can override -C for when we really need to # Last check that we can override -C for when we really need to
atf_check -s exit:0 -o empty -e empty "${TEST_SH}" -c \ atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
' '
D=$(ls -l Junk_File) || exit 1 D=$(ls -l Junk_File) || exit 1
set -C set -C
@ -208,17 +208,17 @@ set_e_body() {
# Check that -e does nothing if no commands fail # Check that -e does nothing if no commands fail
atf_check -s exit:0 -o match:I_am_OK -e empty \ atf_check -s exit:0 -o match:I_am_OK -e empty \
"${TEST_SH}" -c \ ${TEST_SH} -c \
'false; printf "%s" I_am; set -e; true; printf "%s\n" _OK' 'false; printf "%s" I_am; set -e; true; printf "%s\n" _OK'
# and that it (silently, but with exit status) aborts if cmd fails # and that it (silently, but with exit status) aborts if cmd fails
atf_check -s not-exit:0 -o match:I_am -o not-match:Broken -e empty \ atf_check -s not-exit:0 -o match:I_am -o not-match:Broken -e empty \
"${TEST_SH}" -c \ ${TEST_SH} -c \
'false; printf "%s" I_am; set -e; false; printf "%s\n" _Broken' 'false; printf "%s" I_am; set -e; false; printf "%s\n" _Broken'
# same, except -e this time is on from the beginning # same, except -e this time is on from the beginning
atf_check -s not-exit:0 -o match:I_am -o not-match:Broken -e empty \ atf_check -s not-exit:0 -o match:I_am -o not-match:Broken -e empty \
"${TEST_SH}" -ec 'printf "%s" I_am; false; printf "%s\n" _Broken' ${TEST_SH} -ec 'printf "%s" I_am; false; printf "%s\n" _Broken'
# More checking of -e in other places, there is lots to deal with. # More checking of -e in other places, there is lots to deal with.
} }
@ -247,12 +247,12 @@ set_f_body() {
echo "$f" > "$f" echo "$f" > "$f"
done done
atf_check -s exit:0 -o empty -e empty "${TEST_SH}" -ec \ atf_check -s exit:0 -o empty -e empty ${TEST_SH} -ec \
'X=$(echo b*); Y=$(echo b*); test "${X}" != "a*"; 'X=$(echo b*); Y=$(echo b*); test "${X}" != "a*";
test "${X}" = "${Y}"' test "${X}" = "${Y}"'
# now test expansion is different when -f is set # now test expansion is different when -f is set
atf_check -s exit:0 -o empty -e empty "${TEST_SH}" -ec \ atf_check -s exit:0 -o empty -e empty ${TEST_SH} -ec \
'X=$(echo b*); Y=$(set -f; echo b*); test "${X}" != "${Y}"' 'X=$(echo b*); Y=$(set -f; echo b*); test "${X}" != "${Y}"'
} }
@ -268,18 +268,84 @@ set_n_body() {
# nothing should be executed, hence no output... # nothing should be executed, hence no output...
atf_check -s exit:0 -o empty -e empty \ atf_check -s exit:0 -o empty -e empty \
"${TEST_SH}" -enc 'echo ABANDON HOPE; echo ALL YE; echo ...' ${TEST_SH} -enc 'echo ABANDON HOPE; echo ALL YE; echo ...'
# this is true even when the "commands" do not exist # this is true even when the "commands" do not exist
atf_check -s exit:0 -o empty -e empty \ atf_check -s exit:0 -o empty -e empty \
"${TEST_SH}" -enc 'ERR; FAIL; ABANDON HOPE' ${TEST_SH} -enc 'ERR; FAIL; ABANDON HOPE'
# but if there is a syntax error, it should be detected # but if there is a syntax error, it should be detected (w or w/o -e)
atf_check -s not-exit:0 -o empty -e not-empty \ atf_check -s not-exit:0 -o empty -e not-empty \
"${TEST_SH}" -enc 'echo JUMP; for frogs swim; echo in puddles' ${TEST_SH} -enc 'echo JUMP; for frogs swim; echo in puddles'
atf_check -s not-exit:0 -o empty -e not-empty \
${TEST_SH} -nc 'echo ABANDON HOPE; echo "ALL YE; echo ...'
atf_check -s not-exit:0 -o empty -e not-empty \
${TEST_SH} -enc 'echo ABANDON HOPE;; echo ALL YE; echo ...'
atf_check -s not-exit:0 -o empty -e not-empty \
${TEST_SH} -nc 'do YOU ABANDON HOPE; for all eternity?'
# eventually add tests that enable -n during the script # now test enabling -n in the middle of a script
# but the standard NetBSD sh doesn't handle that properly yet, so ... # note that once turned on, it cannot be turned off again.
#
# omit more complex cases, as those can send some shells
# into infinite loops, and believe it or not, that might be OK!
atf_check -s exit:0 -o match:first -o not-match:second -e empty \
${TEST_SH} -c 'echo first; set -n; echo second'
atf_check -s exit:0 -o match:first -o not-match:third -e empty \
${TEST_SH} -c 'echo first; set -n; echo second; set +n; echo third'
atf_check -s exit:0 -o inline:'a\nb\n' -e empty \
${TEST_SH} -c 'for x in a b c d
do
case "$x" in
a);; b);; c) set -n;; d);;
esac
printf "%s\n" "$x"
done'
# This last one is a bit more complex to explain, so I will not try
# First, we need to know what signal number is used for SIGUSR1 on
# the local (testing) system (signal number is $(( $XIT - 128 )) )
# this will take slightly over 1 second elapsed time (the sleep 1)
# The "10" for the first sleep just needs to be something big enough
# that the rest of the commands have time to complete, even on
# very slow testing systems. 10 should be enough. Otherwise irrelevant
# The shell will usually blather to stderr about the sleep 10 being
# killed, but it affects nothing, so just allow it to cry.
(sleep 10 & sleep 1; kill -USR1 $!; wait $!)
XIT="$?"
# The exit value should be an integer > 128 and < 256 (often 158)
# If it is not just skip the test
# If we do run the test, it should take (slightly over) either 1 or 2
# seconds to complete, depending upon the shell being tested.
case "${XIT}" in
( 129 | 1[3-9][0-9] | 2[0-4][0-9] | 25[0-5] )
# The script below should exit with the same code - no output
# Or that is the result that seems best explanable.
# "set -n" in uses like this is not exactly well defined...
# This script comes from a member of the austin group
# (they author changes to the posix shell spec - and more.)
# The author is also an (occasional?) NetBSD user.
atf_check -s exit:${XIT} -o empty -e empty ${TEST_SH} -c '
trap "set -n" USR1
{ sleep 1; kill -USR1 $$; sleep 1; } &
false
wait && echo t || echo f
wait
echo foo
'
;;
esac
} }
atf_test_case set_u atf_test_case set_u
@ -291,46 +357,46 @@ set_u_body() {
test_option_on_off u test_option_on_off u
# first make sure it is OK to unset an unset variable # first make sure it is OK to unset an unset variable
atf_check -s exit:0 -o match:OK -e empty "${TEST_SH}" -ce \ atf_check -s exit:0 -o match:OK -e empty ${TEST_SH} -ce \
'unset _UNSET_VARIABLE_; echo OK' 'unset _UNSET_VARIABLE_; echo OK'
# even if -u is set # even if -u is set
atf_check -s exit:0 -o match:OK -e empty "${TEST_SH}" -cue \ atf_check -s exit:0 -o match:OK -e empty ${TEST_SH} -cue \
'unset _UNSET_VARIABLE_; echo OK' 'unset _UNSET_VARIABLE_; echo OK'
# and that without -u accessing an unset variable is harmless # and that without -u accessing an unset variable is harmless
atf_check -s exit:0 -o match:OK -e empty "${TEST_SH}" -ce \ atf_check -s exit:0 -o match:OK -e empty ${TEST_SH} -ce \
'unset X; echo ${X}; echo OK' 'unset X; echo ${X}; echo OK'
# and that the unset variable test expansion works properly # and that the unset variable test expansion works properly
atf_check -s exit:0 -o match:OKOK -e empty "${TEST_SH}" -ce \ atf_check -s exit:0 -o match:OKOK -e empty ${TEST_SH} -ce \
'unset X; printf "%s" ${X-OK}; echo OK' 'unset X; printf "%s" ${X-OK}; echo OK'
# Next test that with -u set, the shell aborts on access to unset var # Next test that with -u set, the shell aborts on access to unset var
# do not use -e, want to make sure it is -u that causes abort # do not use -e, want to make sure it is -u that causes abort
atf_check -s not-exit:0 -o not-match:ERR -e not-empty "${TEST_SH}" -c \ atf_check -s not-exit:0 -o not-match:ERR -e not-empty ${TEST_SH} -c \
'unset X; set -u; echo ${X}; echo ERR' 'unset X; set -u; echo ${X}; echo ERR'
# quoting should make no difference... # quoting should make no difference...
atf_check -s not-exit:0 -o not-match:ERR -e not-empty "${TEST_SH}" -c \ atf_check -s not-exit:0 -o not-match:ERR -e not-empty ${TEST_SH} -c \
'unset X; set -u; echo "${X}"; echo ERR' 'unset X; set -u; echo "${X}"; echo ERR'
# Now a bunch of accesses to unset vars, with -u, in ways that are OK # Now a bunch of accesses to unset vars, with -u, in ways that are OK
atf_check -s exit:0 -o match:OK -e empty "${TEST_SH}" -ce \ atf_check -s exit:0 -o match:OK -e empty ${TEST_SH} -ce \
'unset X; set -u; echo ${X-GOOD}; echo OK' 'unset X; set -u; echo ${X-GOOD}; echo OK'
atf_check -s exit:0 -o match:OK -e empty "${TEST_SH}" -ce \ atf_check -s exit:0 -o match:OK -e empty ${TEST_SH} -ce \
'unset X; set -u; echo ${X-OK}' 'unset X; set -u; echo ${X-OK}'
atf_check -s exit:0 -o not-match:ERR -o match:OK -e empty \ atf_check -s exit:0 -o not-match:ERR -o match:OK -e empty \
"${TEST_SH}" -ce 'unset X; set -u; echo ${X+ERR}; echo OK' ${TEST_SH} -ce 'unset X; set -u; echo ${X+ERR}; echo OK'
# and some more ways that are not OK # and some more ways that are not OK
atf_check -s not-exit:0 -o not-match:ERR -e not-empty "${TEST_SH}" -c \ atf_check -s not-exit:0 -o not-match:ERR -e not-empty ${TEST_SH} -c \
'unset X; set -u; echo ${X#foo}; echo ERR' 'unset X; set -u; echo ${X#foo}; echo ERR'
atf_check -s not-exit:0 -o not-match:ERR -e not-empty "${TEST_SH}" -c \ atf_check -s not-exit:0 -o not-match:ERR -e not-empty ${TEST_SH} -c \
'unset X; set -u; echo ${X%%bar}; echo ERR' 'unset X; set -u; echo ${X%%bar}; echo ERR'
# lastly, just while we are checking unset vars, test aborts w/o -u # lastly, just while we are checking unset vars, test aborts w/o -u
atf_check -s not-exit:0 -o not-match:ERR -e not-empty "${TEST_SH}" -c \ atf_check -s not-exit:0 -o not-match:ERR -e not-empty ${TEST_SH} -c \
'unset X; echo ${X?}; echo ERR' 'unset X; echo ${X?}; echo ERR'
atf_check -s not-exit:0 -o not-match:ERR -e match:X_NOT_SET \ atf_check -s not-exit:0 -o not-match:ERR -e match:X_NOT_SET \
"${TEST_SH}" -c 'unset X; echo ${X?X_NOT_SET}; echo ERR' ${TEST_SH} -c 'unset X; echo ${X?X_NOT_SET}; echo ERR'
} }
atf_test_case set_v atf_test_case set_v
@ -345,13 +411,13 @@ set_v_body() {
atf_check -s exit:0 \ atf_check -s exit:0 \
-o match:OKOK -o not-match:echo -o not-match:printf \ -o match:OKOK -o not-match:echo -o not-match:printf \
-e empty \ -e empty \
"${TEST_SH}" -ec 'printf "%s" OK; set -v; echo OK; exit 0' ${TEST_SH} -ec 'printf "%s" OK; set -v; echo OK; exit 0'
# but that it does when there are multiple lines # but that it does when there are multiple lines
atf_check -s exit:0 \ atf_check -s exit:0 \
-o match:OKOK -o not-match:echo -o not-match:printf \ -o match:OKOK -o not-match:echo -o not-match:printf \
-e match:printf -e match:OK -e match:echo \ -e match:printf -e match:OK -e match:echo \
"${TEST_SH}" -ec '{ ${TEST_SH} -ec '{
echo "set -v" echo "set -v"
echo "printf %s OK" echo "printf %s OK"
echo "echo OK" echo "echo OK"
@ -362,7 +428,7 @@ set_v_body() {
atf_check -s exit:0 \ atf_check -s exit:0 \
-o match:OKOK -o not-match:echo -o not-match:printf \ -o match:OKOK -o not-match:echo -o not-match:printf \
-e match:printf -e match:OK -e not-match:echo \ -e match:printf -e match:OK -e not-match:echo \
"${TEST_SH}" -ec '{ ${TEST_SH} -ec '{
echo "set -v" echo "set -v"
echo "printf %s OK" echo "printf %s OK"
echo "set +v" echo "set +v"
@ -376,7 +442,7 @@ set_v_body() {
-o not-match:for -o not-match:do -o not-match:done \ -o not-match:for -o not-match:do -o not-match:done \
-e match:printf -e match:111 -e not-match:111222 \ -e match:printf -e match:111 -e not-match:111222 \
-e match:for -e match:do -e match:done \ -e match:for -e match:do -e match:done \
"${TEST_SH}" -ec '{ ${TEST_SH} -ec '{
echo "set -v" echo "set -v"
echo "for i in 111 222 333" echo "for i in 111 222 333"
echo "do" echo "do"
@ -398,19 +464,19 @@ set_x_body() {
atf_check -s exit:0 \ atf_check -s exit:0 \
-o match:OKOK -o not-match:echo -o not-match:printf \ -o match:OKOK -o not-match:echo -o not-match:printf \
-e not-match:printf -e match:OK -e match:echo \ -e not-match:printf -e match:OK -e match:echo \
"${TEST_SH}" -ec 'printf "%s" OK; set -x; echo OK; exit 0' ${TEST_SH} -ec 'printf "%s" OK; set -x; echo OK; exit 0'
# and that it stops again afer -x is disabled # and that it stops again afer -x is disabled
atf_check -s exit:0 \ atf_check -s exit:0 \
-o match:OKOK -o not-match:echo -o not-match:printf \ -o match:OKOK -o not-match:echo -o not-match:printf \
-e match:printf -e match:OK -e not-match:echo \ -e match:printf -e match:OK -e not-match:echo \
"${TEST_SH}" -ec 'set -x; printf "%s" OK; set +x; echo OK; exit 0' ${TEST_SH} -ec 'set -x; printf "%s" OK; set +x; echo OK; exit 0'
# also check that PS4 is output correctly # also check that PS4 is output correctly
atf_check -s exit:0 \ atf_check -s exit:0 \
-o match:OK -o not-match:echo \ -o match:OK -o not-match:echo \
-e match:OK -e match:Run:echo \ -e match:OK -e match:Run:echo \
"${TEST_SH}" -ec 'PS4=Run:; set -x; echo OK; exit 0' ${TEST_SH} -ec 'PS4=Run:; set -x; echo OK; exit 0'
return 0 return 0
@ -423,7 +489,7 @@ set_x_body() {
-o not-match:for \ -o not-match:for \
-e match:printf -e match:111 -e not-match:111222 \ -e match:printf -e match:111 -e not-match:111222 \
-e not-match:for -e not-match:do -e not-match:done \ -e not-match:for -e not-match:do -e not-match:done \
"${TEST_SH}" -ec \ ${TEST_SH} -ec \
'set -x; for i in 111 222 333; do printf "%s" $i; done; echo; exit 0' 'set -x; for i in 111 222 333; do printf "%s" $i; done; echo; exit 0'
} }
@ -489,11 +555,11 @@ restore_local_opts_body() {
FN="test-funcs.$$" FN="test-funcs.$$"
opt_test_setup "${FN}" || atf_skip "Cannot setup test environment" opt_test_setup "${FN}" || atf_skip "Cannot setup test environment"
"${TEST_SH}" -ec ". './${FN}'; local_opt_check" 2>/dev/null || ${TEST_SH} -ec ". './${FN}'; local_opt_check" 2>/dev/null ||
atf_skip "sh extension 'local -' not supported by ${TEST_SH}" atf_skip "sh extension 'local -' not supported by ${TEST_SH}"
atf_check -s exit:0 -o match:OKOK -o not-match:ERR -e empty \ atf_check -s exit:0 -o match:OKOK -o not-match:ERR -e empty \
"${TEST_SH}" -ec ". './${FN}'; local_test" ${TEST_SH} -ec ". './${FN}'; local_test"
} }
atf_test_case vi_emacs_VE_toggle atf_test_case vi_emacs_VE_toggle
@ -506,7 +572,7 @@ vi_emacs_VE_toggle_body() {
test_optional_on_off V E || test_optional_on_off V E ||
atf_skip "One or both V & E opts unsupported by ${TEST_SH}" atf_skip "One or both V & E opts unsupported by ${TEST_SH}"
atf_check -s exit:0 -o empty -e empty "${TEST_SH}" -c ' atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '
q() { q() {
eval "case \"$-\" in eval "case \"$-\" in
(*${2}*) return 1;; (*${2}*) return 1;;
@ -535,7 +601,7 @@ xx_bogus_body() {
# Biggest problem here is picking a "nonsense option" that is # Biggest problem here is picking a "nonsense option" that is
# not implemented by any shell, anywhere. Hopefully this will do. # not implemented by any shell, anywhere. Hopefully this will do.
atf_check -s not-exit:0 -o empty -e not-empty \ atf_check -s not-exit:0 -o empty -e not-empty \
"${TEST_SH}" -c 'set -% ; echo ERR' ${TEST_SH} -c 'set -% ; echo ERR'
} }
atf_test_case Option_switching atf_test_case Option_switching
@ -580,7 +646,7 @@ atf_init_test_cases() {
# no tests for -m (no idea how to do that one) # no tests for -m (no idea how to do that one)
# -I (no easy way to generate the EOF it ignores) # -I (no easy way to generate the EOF it ignores)
# -i (not sure how to test that one at the minute) # -i (not sure how to test that one at the minute)
# -p (because we aren't going to run tests setiud) # -p (because we aren't going to run tests setuid)
# -V/-E (too much effort, and a real test would be huge) # -V/-E (too much effort, and a real test would be huge)
# -c (because almost all the other tests test it anyway) # -c (because almost all the other tests test it anyway)
# -q (because, for now, I am lazy) # -q (because, for now, I am lazy)

View File

@ -1,4 +1,4 @@
# $NetBSD: t_redir.sh,v 1.2 2016/02/23 14:21:37 christos Exp $ # $NetBSD: t_redir.sh,v 1.3 2016/03/01 12:39:35 christos Exp $
# #
# Copyright (c) 2016 The NetBSD Foundation, Inc. # Copyright (c) 2016 The NetBSD Foundation, Inc.
# All rights reserved. # All rights reserved.
@ -43,12 +43,13 @@ redir_here_doc_head() {
"input redirections" "input redirections"
} }
redir_here_doc_body() { redir_here_doc_body() {
atf_check -s exit:0 -o match:'hello\\n' -e empty \
"${TEST_SH}" -ec '{ cat <<- 'DONE' |
echo "cat <<EOF" cat <<EOF
echo '"'"'"hello\n"'"'"' printf '%s\n' 'hello\n'
echo "EOF" EOF
} | '"'${TEST_SH}'"' -e' DONE
atf_check -s exit:0 -o match:'hello\\n' -e empty ${TEST_SH}
} }
atf_init_test_cases() { atf_init_test_cases() {