Sun Mar 27 14:50:01 2016 UTC ()
Finish TEST_SH - all tests should support it now.
Misc other KNF changes, minor bug fixes, and a few minor
extra tests added. (from kre@)


(christos)
diff -r1.1 -r1.2 src/tests/bin/sh/t_evaltested.sh
diff -r1.3 -r1.4 src/tests/bin/sh/t_fsplit.sh
diff -r1.2 -r1.3 src/tests/bin/sh/t_set_e.sh
diff -r1.2 -r1.3 src/tests/bin/sh/t_ulimit.sh
diff -r1.4 -r1.5 src/tests/bin/sh/t_varquote.sh

cvs diff -r1.1 -r1.2 src/tests/bin/sh/t_evaltested.sh (switch to unified diff)

--- src/tests/bin/sh/t_evaltested.sh 2012/03/17 16:33:11 1.1
+++ src/tests/bin/sh/t_evaltested.sh 2016/03/27 14:50:01 1.2
@@ -1,60 +1,62 @@ @@ -1,60 +1,62 @@
1# $NetBSD: t_evaltested.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $ 1# $NetBSD: t_evaltested.sh,v 1.2 2016/03/27 14:50:01 christos Exp $
2# 2#
3# Copyright (c) 2011 The NetBSD Foundation, Inc. 3# Copyright (c) 2011 The NetBSD Foundation, Inc.
4# All rights reserved. 4# All rights reserved.
5# 5#
6# Redistribution and use in source and binary forms, with or without 6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions 7# modification, are permitted provided that the following conditions
8# are met: 8# are met:
9# 1. Redistributions of source code must retain the above copyright 9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer. 10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright 11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the 12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution. 13# documentation and/or other materials provided with the distribution.
14# 14#
15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE. 25# POSSIBILITY OF SUCH DAMAGE.
26# 26#
 27# the implementation of "sh" to test
 28: ${TEST_SH:="/bin/sh"}
27 29
28atf_test_case evaltested 30atf_test_case evaltested
29 31
30evaltested_head() { 32evaltested_head() {
31 atf_set "descr" "Tests that eval in a tested context does not exit" 33 atf_set "descr" "Tests that eval in a tested context does not exit"
32} 34}
33 35
34evaltested_body() { 36evaltested_body() {
35 set -e 37 set -e
36cat > helper.sh << EOF 38cat > helper.sh << EOF
37set -e 39set -e
38if eval false 40if eval false
39then 41then
40 echo "'eval false' returned true" 42 echo "'eval false' returned true"
41 exit 1 43 exit 1
42fi 44fi
43echo "passed" 45echo "passed"
44exit 0 46exit 0
45EOF 47EOF
46 output="$(/bin/sh helper.sh)" 48 output="$($TEST_SH helper.sh)"
47 [ $? = 0 ] && return 49 [ $? = 0 ] && return
48 50
49 if [ -n "$output" ] 51 if [ -n "$output" ]
50 then 52 then
51 atf_fail "$output" 53 atf_fail "$output"
52 else 54 else
53 atf_fail "'eval false' exited from a tested context" 55 atf_fail "'eval false' exited from a tested context"
54 fi 56 fi
55 57
56} 58}
57 59
58atf_init_test_cases() { 60atf_init_test_cases() {
59 atf_add_test_case evaltested 61 atf_add_test_case evaltested
60} 62}

cvs diff -r1.3 -r1.4 src/tests/bin/sh/t_fsplit.sh (switch to unified diff)

--- src/tests/bin/sh/t_fsplit.sh 2016/03/10 22:30:57 1.3
+++ src/tests/bin/sh/t_fsplit.sh 2016/03/27 14:50:01 1.4
@@ -1,355 +1,360 @@ @@ -1,355 +1,360 @@
1# $NetBSD: t_fsplit.sh,v 1.3 2016/03/10 22:30:57 christos Exp $ 1# $NetBSD: t_fsplit.sh,v 1.4 2016/03/27 14:50:01 christos Exp $
2# 2#
3# Copyright (c) 2007-2016 The NetBSD Foundation, Inc. 3# Copyright (c) 2007-2016 The NetBSD Foundation, Inc.
4# All rights reserved. 4# All rights reserved.
5# 5#
6# Redistribution and use in source and binary forms, with or without 6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions 7# modification, are permitted provided that the following conditions
8# are met: 8# are met:
9# 1. Redistributions of source code must retain the above copyright 9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer. 10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright 11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the 12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution. 13# documentation and/or other materials provided with the distribution.
14# 14#
15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE. 25# POSSIBILITY OF SUCH DAMAGE.
26# 26#
27 27
28# The standard 28# The standard
29# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html 29# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
30# explains (section 2.6) that Field splitting should be performed on the 30# explains (section 2.6) that Field splitting should be performed on the
31# result of variable expansions. 31# result of variable expansions.
32# In particular this means that in ${x-word}, 'word' must be expanded as if 32# In particular this means that in ${x-word}, 'word' must be expanded as if
33# the "${x-" and "}" were absent from the input line. 33# the "${x-" and "}" were absent from the input line.
34# 34#
35# So: sh -c 'set ${x-a b c}; echo $#' should give 3. 35# So: sh -c 'set ${x-a b c}; echo $#' should give 3.
36# and: sh -c 'set -- ${x-}' echo $#' shold give 0 36# and: sh -c 'set -- ${x-}' echo $#' shold give 0
37# 37#
38 38
39# the implementation of "sh" to test 39# the implementation of "sh" to test
40: ${TEST_SH:="/bin/sh"} 40: ${TEST_SH:="/bin/sh"}
41 41
42nl=' 42nl='
43' 43'
44 44
45check() 45check()
46{ 46{
47 TEST=$((${TEST} + 1)) 47 TEST=$((${TEST} + 1))
48 48
49 case "$#" in 49 case "$#" in
50 (2) ;; 50 (2) ;;
51 (*) atf_fail "Internal test error, $# args to check test ${TEST}";; 51 (*) atf_fail "Internal test error, $# args to check test ${TEST}";;
52 esac 52 esac
53 53
54 result=$( ${TEST_SH} -c "unset x; $1" ) 54 result=$( ${TEST_SH} -c "unset x; $1" )
55 STATUS="$?" 55 STATUS="$?"
56 56
57 # Remove newlines 57 # Remove newlines
58 oifs="$IFS" 58 oifs="$IFS"
59 IFS="$nl" 59 IFS="$nl"
60 result="$(echo $result)" 60 result="$(echo $result)"
61 IFS="$oifs" 61 IFS="$oifs"
62 62
63 # trim the test text in case we use it in a message below 63 # trim the test text in case we use it in a message below
64 case "$1" in 64 case "$1" in
65 ????????????????*) 65 ????????????????*)
66 set -- "$(expr "$1" : '\(............\).*')..." "$2" ;; 66 set -- "$(expr "$1" : '\(............\).*')..." "$2" ;;
67 esac 67 esac
68 68
69 if [ "$2" != "$result" ] 69 if [ "$2" != "$result" ]
70 then 70 then
71 if [ "${STATUS}" = "0" ] 71 if [ "${STATUS}" = "0" ]
72 then 72 then
73 atf_fail "Test ${TEST} '$1': expected [$2], found [$result]" 73 atf_fail "Test ${TEST} '$1': expected [$2], found [$result]"
74 else 74 else
75 atf_fail \ 75 atf_fail \
76 "TEST ${TEST} '$1' failed ($STATUS): expected [$2], found [$result]" 76 "TEST ${TEST} '$1' failed ($STATUS): expected [$2], found [$result]"
77 fi 77 fi
78 elif [ "${STATUS}" != 0 ] 78 elif [ "${STATUS}" != 0 ]
79 then 79 then
80 atf_fail "TEST ${TEST} '$1' failed ($STATUS)" 80 atf_fail "TEST ${TEST} '$1' failed ($STATUS)"
81 fi 81 fi
82} 82}
83 83
84atf_test_case for 84atf_test_case for
85for_head() { 85for_head() {
86 atf_set "descr" "Checks field splitting in for loops" 86 atf_set "descr" "Checks field splitting in for loops"
87} 87}
88for_body() { 88for_body() {
89 unset x 89 unset x
90 90
91 TEST=0 91 TEST=0
92 # Since I managed to break this, leave the test in 92 # Since I managed to break this, leave the test in
93 check 'for f in $x; do echo x${f}y; done' '' 93 check 'for f in $x; do echo x${f}y; done' ''
94} 94}
95 95
96atf_test_case default_val 96atf_test_case default_val
97default_val_head() { 97default_val_head() {
98 atf_set "descr" "Checks field splitting in variable default values" 98 atf_set "descr" "Checks field splitting in variable default values"
99} 99}
100default_val_body() { 100default_val_body() {
101 TEST=0 101 TEST=0
102 # Check that IFS is applied to text from ${x-...} unless it is inside 102 # Check that IFS is applied to text from ${x-...} unless it is inside
103 # any set of "..." 103 # any set of "..."
104 check 'set -- ${x-a b c}; echo $#' 3 104 check 'set -- ${x-a b c}; echo $#' 3
105 105
106 check 'set -- ${x-"a b" c}; echo $#' 2 106 check 'set -- ${x-"a b" c}; echo $#' 2
107 check 'set -- ${x-a "b c"}; echo $#' 2 107 check 'set -- ${x-a "b c"}; echo $#' 2
108 check 'set -- ${x-"a b c"}; echo $#' 1 108 check 'set -- ${x-"a b c"}; echo $#' 1
109 109
110 check "set -- \${x-'a b' c}; echo \$#" 2 110 check "set -- \${x-'a b' c}; echo \$#" 2
111 check "set -- \${x-a 'b c'}; echo \$#" 2 111 check "set -- \${x-a 'b c'}; echo \$#" 2
112 check "set -- \${x-'a b c'}; echo \$#" 1 112 check "set -- \${x-'a b c'}; echo \$#" 1
113 113
114 check 'set -- ${x-a\ b c}; echo $#' 2 114 check 'set -- ${x-a\ b c}; echo $#' 2
115 check 'set -- ${x-a b\ c}; echo $#' 2 115 check 'set -- ${x-a b\ c}; echo $#' 2
116 check 'set -- ${x-a\ b\ c}; echo $#' 1 116 check 'set -- ${x-a\ b\ c}; echo $#' 1
117 117
118 check 'set -- ${x}; echo $#' 0 118 check 'set -- ${x}; echo $#' 0
119 check 'set -- ${x-}; echo $#' 0 119 check 'set -- ${x-}; echo $#' 0
120 check 'set -- ${x-""}; echo $#' 1 120 check 'set -- ${x-""}; echo $#' 1
121 check 'set -- ""${x}; echo $#' 1 121 check 'set -- ""${x}; echo $#' 1
122 check 'set -- ""${x-}; echo $#' 1 122 check 'set -- ""${x-}; echo $#' 1
123 check 'set -- ""${x-""}; echo $#' 1 123 check 'set -- ""${x-""}; echo $#' 1
124 check 'set -- ${x}""; echo $#' 1 124 check 'set -- ${x}""; echo $#' 1
125 check 'set -- ${x-}""; echo $#' 1 125 check 'set -- ${x-}""; echo $#' 1
126 check 'set -- ${x-""}""; echo $#' 1 126 check 'set -- ${x-""}""; echo $#' 1
127 check 'set -- ""${x}""; echo $#' 1 127 check 'set -- ""${x}""; echo $#' 1
128 check 'set -- ""${x-}""; echo $#' 1 128 check 'set -- ""${x-}""; echo $#' 1
129 check 'set -- ""${x-""}""; echo $#' 1 129 check 'set -- ""${x-""}""; echo $#' 1
130 130
131 check 'for i in ${x-a b c}; do echo "z${i}z"; done' \ 131 check 'for i in ${x-a b c}; do echo "z${i}z"; done' \
132 'zaz zbz zcz' 132 'zaz zbz zcz'
133 check 'for i in ${x-"a b" c}; do echo "z${i}z"; done' \ 133 check 'for i in ${x-"a b" c}; do echo "z${i}z"; done' \
134 'za bz zcz' 134 'za bz zcz'
135 check 'for i in ${x-"a ${x-b c}" d}; do echo "z${i}z"; done' \ 135 check 'for i in ${x-"a ${x-b c}" d}; do echo "z${i}z"; done' \
136 'za b cz zdz' 136 'za b cz zdz'
137 check 'for i in ${x-a ${x-b c} d}; do echo "z${i}z"; done' \ 137 check 'for i in ${x-a ${x-b c} d}; do echo "z${i}z"; done' \
138 'zaz zbz zcz zdz' 138 'zaz zbz zcz zdz'
139 139
140 # I am not sure these two are correct, the rules on quoting word 140 # I am not sure these two are correct, the rules on quoting word
141 # in ${var-word} are peculiar, and hard to fathom... 141 # in ${var-word} are peculiar, and hard to fathom...
142 # They are what the NetBSD shell does, and bash, not the freebsd shell 142 # They are what the NetBSD shell does, and bash, not the freebsd shell
143 # (as of Mar 1, 2016) 143 # (as of Mar 1, 2016)
144 144
145 check 'for i in ${x-"a ${x-"b c"}" d}; do echo "z${i}z"; done' \ 145 check 'for i in ${x-"a ${x-"b c"}" d}; do echo "z${i}z"; done' \
146 'za b cz zdz' 146 'za b cz zdz'
147 check 'for i in ${x-a ${x-"b c"} d}; do echo "z${i}z"; done' \ 147 check 'for i in ${x-a ${x-"b c"} d}; do echo "z${i}z"; done' \
148 'zaz zb cz zdz' 148 'zaz zb cz zdz'
149} 149}
150 150
151atf_test_case replacement_val 151atf_test_case replacement_val
152replacement_val_head() { 152replacement_val_head() {
153 atf_set "descr" "Checks field splitting in variable replacement values" 153 atf_set "descr" "Checks field splitting in variable replacement values"
154} 154}
155replacement_val_body() { 155replacement_val_body() {
156 TEST=0 156 TEST=0
157 157
158 # Check that IFS is applied to text from ${x+...} unless it is inside 158 # Check that IFS is applied to text from ${x+...} unless it is inside
159 # any set of "...", or whole expansion is quoted, or both... 159 # any set of "...", or whole expansion is quoted, or both...
160 160
161 check 'x=BOGUS; set -- ${x+a b c}; echo $#' 3 161 check 'x=BOGUS; set -- ${x+a b c}; echo $#' 3
162 162
163 check 'x=BOGUS; set -- ${x+"a b" c}; echo $#' 2 163 check 'x=BOGUS; set -- ${x+"a b" c}; echo $#' 2
164 check 'x=BOGUS; set -- ${x+a "b c"}; echo $#' 2 164 check 'x=BOGUS; set -- ${x+a "b c"}; echo $#' 2
165 check 'x=BOGUS; set -- ${x+"a b c"}; echo $#' 1 165 check 'x=BOGUS; set -- ${x+"a b c"}; echo $#' 1
166 166
167 check "x=BOGUS; set -- \${x+'a b' c}; echo \$#" 2 167 check "x=BOGUS; set -- \${x+'a b' c}; echo \$#" 2
168 check "x=BOGUS; set -- \${x+a 'b c'}; echo \$#" 2 168 check "x=BOGUS; set -- \${x+a 'b c'}; echo \$#" 2
169 check "x=BOGUS; set -- \${x+'a b c'}; echo \$#" 1 169 check "x=BOGUS; set -- \${x+'a b c'}; echo \$#" 1
170 170
171 check 'x=BOGUS; set -- ${x+a\ b c}; echo $#' 2 171 check 'x=BOGUS; set -- ${x+a\ b c}; echo $#' 2
172 check 'x=BOGUS; set -- ${x+a b\ c}; echo $#' 2 172 check 'x=BOGUS; set -- ${x+a b\ c}; echo $#' 2
173 check 'x=BOGUS; set -- ${x+a\ b\ c}; echo $#' 1 173 check 'x=BOGUS; set -- ${x+a\ b\ c}; echo $#' 1
174 174
175 check 'x=BOGUS; set -- ${x+}; echo $#' 0 175 check 'x=BOGUS; set -- ${x+}; echo $#' 0
176 check 'x=BOGUS; set -- ${x+""}; echo $#' 1 176 check 'x=BOGUS; set -- ${x+""}; echo $#' 1
177 check 'x=BOGUS; set -- ""${x+}; echo $#' 1 177 check 'x=BOGUS; set -- ""${x+}; echo $#' 1
178 check 'x=BOGUS; set -- ""${x+""}; echo $#' 1 178 check 'x=BOGUS; set -- ""${x+""}; echo $#' 1
179 check 'x=BOGUS; set -- ${x+}""; echo $#' 1 179 check 'x=BOGUS; set -- ${x+}""; echo $#' 1
180 check 'x=BOGUS; set -- ${x+""}""; echo $#' 1 180 check 'x=BOGUS; set -- ${x+""}""; echo $#' 1
181 check 'x=BOGUS; set -- ""${x+}""; echo $#' 1 181 check 'x=BOGUS; set -- ""${x+}""; echo $#' 1
182 check 'x=BOGUS; set -- ""${x+""}""; echo $#' 1 182 check 'x=BOGUS; set -- ""${x+""}""; echo $#' 1
183 183
184 # verify that the value of $x does not affecty the value of ${x+...} 184 # verify that the value of $x does not affecty the value of ${x+...}
185 check 'x=BOGUS; set -- ${x+}; echo X$1' X 185 check 'x=BOGUS; set -- ${x+}; echo X$1' X
186 check 'x=BOGUS; set -- ${x+""}; echo X$1' X 186 check 'x=BOGUS; set -- ${x+""}; echo X$1' X
187 check 'x=BOGUS; set -- ""${x+}; echo X$1' X 187 check 'x=BOGUS; set -- ""${x+}; echo X$1' X
188 check 'x=BOGUS; set -- ""${x+""}; echo X$1' X 188 check 'x=BOGUS; set -- ""${x+""}; echo X$1' X
189 check 'x=BOGUS; set -- ${x+}""; echo X$1' X 189 check 'x=BOGUS; set -- ${x+}""; echo X$1' X
190 check 'x=BOGUS; set -- ${x+""}""; echo X$1' X 190 check 'x=BOGUS; set -- ${x+""}""; echo X$1' X
191 check 'x=BOGUS; set -- ""${x+}""; echo X$1' X 191 check 'x=BOGUS; set -- ""${x+}""; echo X$1' X
192 check 'x=BOGUS; set -- ""${x+""}""; echo X$1' X 192 check 'x=BOGUS; set -- ""${x+""}""; echo X$1' X
193 193
194 check 'x=BOGUS; set -- ${x+}; echo X${1-:}X' X:X 194 check 'x=BOGUS; set -- ${x+}; echo X${1-:}X' X:X
195 check 'x=BOGUS; set -- ${x+""}; echo X${1-:}X' XX 195 check 'x=BOGUS; set -- ${x+""}; echo X${1-:}X' XX
196 check 'x=BOGUS; set -- ""${x+}; echo X${1-:}X' XX 196 check 'x=BOGUS; set -- ""${x+}; echo X${1-:}X' XX
197 check 'x=BOGUS; set -- ""${x+""}; echo X${1-:}X' XX 197 check 'x=BOGUS; set -- ""${x+""}; echo X${1-:}X' XX
198 check 'x=BOGUS; set -- ${x+}""; echo X${1-:}X' XX 198 check 'x=BOGUS; set -- ${x+}""; echo X${1-:}X' XX
199 check 'x=BOGUS; set -- ${x+""}""; echo X${1-:}X' XX 199 check 'x=BOGUS; set -- ${x+""}""; echo X${1-:}X' XX
200 check 'x=BOGUS; set -- ""${x+}""; echo X${1-:}X' XX 200 check 'x=BOGUS; set -- ""${x+}""; echo X${1-:}X' XX
201 check 'x=BOGUS; set -- ""${x+""}""; echo X${1-:}X' XX 201 check 'x=BOGUS; set -- ""${x+""}""; echo X${1-:}X' XX
202 202
203 # and validate that the replacement can be used as expected 203 # and validate that the replacement can be used as expected
204 check 'x=BOGUS; for i in ${x+a b c}; do echo "z${i}z"; done'\ 204 check 'x=BOGUS; for i in ${x+a b c}; do echo "z${i}z"; done'\
205 'zaz zbz zcz' 205 'zaz zbz zcz'
206 check 'x=BOGUS; for i in ${x+"a b" c}; do echo "z${i}z"; done'\ 206 check 'x=BOGUS; for i in ${x+"a b" c}; do echo "z${i}z"; done'\
207 'za bz zcz' 207 'za bz zcz'
208 check 'x=BOGUS; for i in ${x+"a ${x+b c}" d}; do echo "z${i}z"; done'\ 208 check 'x=BOGUS; for i in ${x+"a ${x+b c}" d}; do echo "z${i}z"; done'\
209 'za b cz zdz' 209 'za b cz zdz'
210 check 'x=BOGUS; for i in ${x+"a ${x+"b c"}" d}; do echo "z${i}z"; done'\ 210 check 'x=BOGUS; for i in ${x+"a ${x+"b c"}" d}; do echo "z${i}z"; done'\
211 'za b cz zdz' 211 'za b cz zdz'
212 check 'x=BOGUS; for i in ${x+a ${x+"b c"} d}; do echo "z${i}z"; done'\ 212 check 'x=BOGUS; for i in ${x+a ${x+"b c"} d}; do echo "z${i}z"; done'\
213 'zaz zb cz zdz' 213 'zaz zb cz zdz'
214 check 'x=BOGUS; for i in ${x+a ${x+b c} d}; do echo "z${i}z"; done'\ 214 check 'x=BOGUS; for i in ${x+a ${x+b c} d}; do echo "z${i}z"; done'\
215 'zaz zbz zcz zdz' 215 'zaz zbz zcz zdz'
216} 216}
217 217
218atf_test_case ifs_alpha 218atf_test_case ifs_alpha
219ifs_alpha_head() { 219ifs_alpha_head() {
220 atf_set "descr" "Checks that field splitting works with alphabetic" \ 220 atf_set "descr" "Checks that field splitting works with alphabetic" \
221 "characters" 221 "characters"
222} 222}
223ifs_alpha_body() { 223ifs_alpha_body() {
224 unset x 224 unset x
225 225
226 TEST=0 226 TEST=0
227 # repeat with an alphabetic in IFS 227 # repeat with an alphabetic in IFS
228 check 'IFS=q; set ${x-aqbqc}; echo $#' 3 228 check 'IFS=q; set ${x-aqbqc}; echo $#' 3
229 check 'IFS=q; for i in ${x-aqbqc}; do echo "z${i}z"; done' \ 229 check 'IFS=q; for i in ${x-aqbqc}; do echo "z${i}z"; done' \
230 'zaz zbz zcz' 230 'zaz zbz zcz'
231 check 'IFS=q; for i in ${x-"aqb"qc}; do echo "z${i}z"; done' \ 231 check 'IFS=q; for i in ${x-"aqb"qc}; do echo "z${i}z"; done' \
232 'zaqbz zcz' 232 'zaqbz zcz'
233 check 'IFS=q; for i in ${x-"aq${x-bqc}"qd}; do echo "z${i}z"; done' \ 233 check 'IFS=q; for i in ${x-"aq${x-bqc}"qd}; do echo "z${i}z"; done' \
234 'zaqbqcz zdz' 234 'zaqbqcz zdz'
235 check 'IFS=q; for i in ${x-"aq${x-"bqc"}"qd}; do echo "z${i}z"; done' \ 235 check 'IFS=q; for i in ${x-"aq${x-"bqc"}"qd}; do echo "z${i}z"; done' \
236 'zaqbqcz zdz' 236 'zaqbqcz zdz'
237 check 'IFS=q; for i in ${x-aq${x-"bqc"}qd}; do echo "z${i}z"; done' \ 237 check 'IFS=q; for i in ${x-aq${x-"bqc"}qd}; do echo "z${i}z"; done' \
238 'zaz zbqcz zdz' 238 'zaz zbqcz zdz'
239} 239}
240 240
241atf_test_case quote 241atf_test_case quote
242quote_head() { 242quote_head() {
243 atf_set "descr" "Checks that field splitting works with multi-word" \ 243 atf_set "descr" "Checks that field splitting works with multi-word" \
244 "fields" 244 "fields"
245} 245}
246quote_body() { 246quote_body() {
247 unset x 247 unset x
248 248
249 TEST=0 249 TEST=0
250 # Some quote propagation checks 250 # Some quote propagation checks
251 check 'set "${x-a b c}"; echo $#' 1 251 check 'set "${x-a b c}"; echo $#' 1
252 check 'set "${x-"a b" c}"; echo $1' 'a b c' 252 check 'set "${x-"a b" c}"; echo $1' 'a b c'
253 check 'for i in "${x-a b c}"; do echo "z${i}z"; done' 'za b cz' 253 check 'for i in "${x-a b c}"; do echo "z${i}z"; done' 'za b cz'
254} 254}
255 255
256atf_test_case dollar_at 256atf_test_case dollar_at
257dollar_at_head() { 257dollar_at_head() {
258 atf_set "descr" "Checks that field splitting works when expanding" \ 258 atf_set "descr" "Checks that field splitting works when expanding" \
259 "\$@" 259 "\$@"
260} 260}
261dollar_at_body() { 261dollar_at_body() {
262 unset x 262 unset x
263 263
264 TEST=0 264 TEST=0
265 # Check we get "$@" right 265 # Check we get "$@" right
266 266
267 check 'set --; for i in x"$@"x; do echo "z${i}z"; done' 'zxxz' 267 check 'set --; for i in x"$@"x; do echo "z${i}z"; done' 'zxxz'
268 check 'set a; for i in x"$@"x; do echo "z${i}z"; done' 'zxaxz' 268 check 'set a; for i in x"$@"x; do echo "z${i}z"; done' 'zxaxz'
269 check 'set a b; for i in x"$@"x; do echo "z${i}z"; done' 'zxaz zbxz' 269 check 'set a b; for i in x"$@"x; do echo "z${i}z"; done' 'zxaz zbxz'
270 270
271 check 'set --; for i; do echo "z${i}z"; done' '' 271 check 'set --; for i; do echo "z${i}z"; done' ''
272 check 'set --; for i in $@; do echo "z${i}z"; done' '' 272 check 'set --; for i in $@; do echo "z${i}z"; done' ''
273 check 'set --; for i in "$@"; do echo "z${i}z"; done' '' 273 check 'set --; for i in "$@"; do echo "z${i}z"; done' ''
274 # atf_expect_fail "PR bin/50834" 274 # atf_expect_fail "PR bin/50834"
275 check 'set --; for i in ""$@; do echo "z${i}z"; done' 'zz' 275 check 'set --; for i in ""$@; do echo "z${i}z"; done' 'zz'
276 # atf_expect_pass 276 # atf_expect_pass
277 check 'set --; for i in $@""; do echo "z${i}z"; done' 'zz' 277 check 'set --; for i in $@""; do echo "z${i}z"; done' 'zz'
278 check 'set --; for i in ""$@""; do echo "z${i}z"; done' 'zz' 278 check 'set --; for i in ""$@""; do echo "z${i}z"; done' 'zz'
279 check 'set --; for i in """$@"; do echo "z${i}z"; done' 'zz' 279 check 'set --; for i in """$@"; do echo "z${i}z"; done' 'zz'
280 check 'set --; for i in "$@"""; do echo "z${i}z"; done' 'zz' 280 check 'set --; for i in "$@"""; do echo "z${i}z"; done' 'zz'
281 check 'set --; for i in """$@""";do echo "z${i}z"; done' 'zz' 281 check 'set --; for i in """$@""";do echo "z${i}z"; done' 'zz'
282 282
283 check 'set ""; for i; do echo "z${i}z"; done' 'zz' 283 check 'set ""; for i; do echo "z${i}z"; done' 'zz'
284 check 'set ""; for i in "$@"; do echo "z${i}z"; done' 'zz' 284 check 'set ""; for i in "$@"; do echo "z${i}z"; done' 'zz'
285 check 'set "" ""; for i; do echo "z${i}z"; done' 'zz zz' 285 check 'set "" ""; for i; do echo "z${i}z"; done' 'zz zz'
286 check 'set "" ""; for i in "$@"; do echo "z${i}z"; done' 'zz zz' 286 check 'set "" ""; for i in "$@"; do echo "z${i}z"; done' 'zz zz'
287 check 'set "" ""; for i in $@; do echo "z${i}z"; done' '' 287 check 'set "" ""; for i in $@; do echo "z${i}z"; done' ''
288 288
289 check 'set "a b" c; for i; do echo "z${i}z"; done' \ 289 check 'set "a b" c; for i; do echo "z${i}z"; done' \
290 'za bz zcz' 290 'za bz zcz'
291 check 'set "a b" c; for i in "$@"; do echo "z${i}z"; done' \ 291 check 'set "a b" c; for i in "$@"; do echo "z${i}z"; done' \
292 'za bz zcz' 292 'za bz zcz'
293 check 'set "a b" c; for i in $@; do echo "z${i}z"; done' \ 293 check 'set "a b" c; for i in $@; do echo "z${i}z"; done' \
294 'zaz zbz zcz' 294 'zaz zbz zcz'
295 check 'set " a b " c; for i in "$@"; do echo "z${i}z"; done' \ 295 check 'set " a b " c; for i in "$@"; do echo "z${i}z"; done' \
296 'z a b z zcz' 296 'z a b z zcz'
 297
 298 check 'set a b c; for i in "$@$@"; do echo "z${i}z"; done' \
 299 'zaz zbz zcaz zbz zcz'
 300 check 'set a b c; for i in "$@""$@";do echo "z${i}z"; done' \
 301 'zaz zbz zcaz zbz zcz'
297} 302}
298 303
299atf_test_case ifs 304atf_test_case ifs
300ifs_head() { 305ifs_head() {
301 atf_set "descr" "Checks that IFS correctly configures field" \ 306 atf_set "descr" "Checks that IFS correctly configures field" \
302 "splitting behavior" 307 "splitting behavior"
303} 308}
304ifs_body() { 309ifs_body() {
305 unset x 310 unset x
306 311
307 TEST=0 312 TEST=0
308 # Some IFS tests 313 # Some IFS tests
309 check 't="-- "; IFS=" "; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '0' 314 check 't="-- "; IFS=" "; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '0'
310 check 't=" x"; IFS=" x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '1' 315 check 't=" x"; IFS=" x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '1'
311 check 't=" x "; IFS=" x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '1' 316 check 't=" x "; IFS=" x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '1'
312 check 't=axb; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 a:b' 317 check 't=axb; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 a:b'
313 check 't="a x b"; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 a : b' 318 check 't="a x b"; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 a : b'
314 check 't="a xx b"; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '3 a :: b' 319 check 't="a xx b"; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '3 a :: b'
315 check 't="a xx b"; IFS="x "; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '3 a::b' 320 check 't="a xx b"; IFS="x "; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '3 a::b'
316 # A recent 'clarification' means that a single trailing IFS non-whitespace 321 # A recent 'clarification' means that a single trailing IFS non-whitespace
317 # doesn't generate an empty parameter 322 # doesn't generate an empty parameter
318 check 't="xax"; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 :a' 323 check 't="xax"; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 :a'
319 check 't="xax "; IFS="x "; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 :a' 324 check 't="xax "; IFS="x "; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 :a'
320 # Verify that IFS isn't being applied where it shouldn't be. 325 # Verify that IFS isn't being applied where it shouldn't be.
321 check 'IFS="x"; set axb; IFS=":"; r="$*"; IFS=; echo $# $r' '1 axb' 326 check 'IFS="x"; set axb; IFS=":"; r="$*"; IFS=; echo $# $r' '1 axb'
322} 327}
323 328
324atf_test_case var_length 329atf_test_case var_length
325var_length_head() { 330var_length_head() {
326 atf_set "descr" "Checks that field splitting works when expanding" \ 331 atf_set "descr" "Checks that field splitting works when expanding" \
327 "a variable's length" 332 "a variable's length"
328} 333}
329var_length_body() { 334var_length_body() {
330 TEST=0 335 TEST=0
331 336
332 long=12345678123456781234567812345678 337 long=12345678123456781234567812345678
333 long=$long$long$long$long 338 long=$long$long$long$long
334 export long 339 export long
335 340
336 # first test that the test method works... 341 # first test that the test method works...
337 check 'set -u; : ${long}; echo ${#long}' '128' 342 check 'set -u; : ${long}; echo ${#long}' '128'
338 343
339 # Check that we apply IFS to ${#var} 344 # Check that we apply IFS to ${#var}
340 check 'echo ${#long}; IFS=2; echo ${#long}; set 1 ${#long};echo $#' \ 345 check 'echo ${#long}; IFS=2; echo ${#long}; set 1 ${#long};echo $#' \
341 '128 1 8 3' 346 '128 1 8 3'
342 check 'IFS=2; set ${x-${#long}}; IFS=" "; echo $* $#' '1 8 2' 347 check 'IFS=2; set ${x-${#long}}; IFS=" "; echo $* $#' '1 8 2'
343 check 'IFS=2; set ${x-"${#long}"}; IFS=" "; echo $* $#' '128 1' 348 check 'IFS=2; set ${x-"${#long}"}; IFS=" "; echo $* $#' '128 1'
344} 349}
345 350
346atf_init_test_cases() { 351atf_init_test_cases() {
347 atf_add_test_case for 352 atf_add_test_case for
348 atf_add_test_case default_val 353 atf_add_test_case default_val
349 atf_add_test_case replacement_val 354 atf_add_test_case replacement_val
350 atf_add_test_case ifs_alpha 355 atf_add_test_case ifs_alpha
351 atf_add_test_case quote 356 atf_add_test_case quote
352 atf_add_test_case dollar_at 357 atf_add_test_case dollar_at
353 atf_add_test_case ifs 358 atf_add_test_case ifs
354 atf_add_test_case var_length 359 atf_add_test_case var_length
355} 360}

cvs diff -r1.2 -r1.3 src/tests/bin/sh/t_set_e.sh (switch to unified diff)

--- src/tests/bin/sh/t_set_e.sh 2016/03/08 14:20:22 1.2
+++ src/tests/bin/sh/t_set_e.sh 2016/03/27 14:50:01 1.3
@@ -1,305 +1,305 @@ @@ -1,305 +1,305 @@
1# $NetBSD: t_set_e.sh,v 1.2 2016/03/08 14:20:22 christos Exp $ 1# $NetBSD: t_set_e.sh,v 1.3 2016/03/27 14:50:01 christos Exp $
2# 2#
3# Copyright (c) 2007 The NetBSD Foundation, Inc. 3# Copyright (c) 2007 The NetBSD Foundation, Inc.
4# All rights reserved. 4# All rights reserved.
5# 5#
6# Redistribution and use in source and binary forms, with or without 6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions 7# modification, are permitted provided that the following conditions
8# are met: 8# are met:
9# 1. Redistributions of source code must retain the above copyright 9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer. 10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright 11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the 12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution. 13# documentation and/or other materials provided with the distribution.
14# 14#
15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE. 25# POSSIBILITY OF SUCH DAMAGE.
26# 26#
27 27
28# references: 28# references:
29# http://www.opengroup.org/onlinepubs/009695399/utilities/set.html 29# http://www.opengroup.org/onlinepubs/009695399/utilities/set.html
30# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html 30# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
31 31
32# the implementation of "sh" to test 32# the implementation of "sh" to test
33: ${TEST_SH:="/bin/sh"} 33: ${TEST_SH:="/bin/sh"}
34 34
35failwith() 35failwith()
36{ 36{
37 case "$SH_FAILS" in 37 case "$SH_FAILS" in
38 "") SH_FAILS=`echo "$1"`;; 38 "") SH_FAILS=`echo "$1"`;;
39 *) SH_FAILS="$SH_FAILS"`echo; echo "$1"`;; 39 *) SH_FAILS="$SH_FAILS"`echo; echo "$1"`;;
40 esac 40 esac
41} 41}
42 42
43check1() 43check1()
44{ 44{
45 #echo "$TEST_SH -c $1" 45 #echo "$TEST_SH -c $1"
46 result=`$TEST_SH -c "$1" 2>/dev/null | tr '\n' ' ' | sed 's/ *$//'` 46 result=`$TEST_SH -c "$1" 2>/dev/null | tr '\n' ' ' | sed 's/ *$//'`
47 if [ "$result" != "$2" ]; then 47 if [ "$result" != "$2" ]; then
48 MSG=`printf "%-56s %-8s %s" "$3" "$result" "$2"` 48 MSG=`printf "%-56s %-8s %s" "$3" "$result" "$2"`
49 failwith "$MSG" 49 failwith "$MSG"
50 failcount=`expr $failcount + 1` 50 failcount=`expr $failcount + 1`
51 fi 51 fi
52 count=`expr $count + 1` 52 count=`expr $count + 1`
53} 53}
54 54
55# direct check: try the given expression. 55# direct check: try the given expression.
56dcheck() 56dcheck()
57{ 57{
58 check1 "$1" "$2" "$1" 58 check1 "$1" "$2" "$1"
59} 59}
60 60
61# eval check: indirect through eval. 61# eval check: indirect through eval.
62# as of this writing, this changes the behavior pretty drastically and 62# as of this writing, this changes the behavior pretty drastically and
63# is thus important to test. (PR bin/29861) 63# is thus important to test. (PR bin/29861)
64echeck() 64echeck()
65{ 65{
66 check1 'eval '"'($1)'" "$2" "eval '($1)'" 66 check1 'eval '"'($1)'" "$2" "eval '($1)'"
67} 67}
68 68
69atf_test_case all 69atf_test_case all
70all_head() { 70all_head() {
71 atf_set "descr" "Tests that 'set -e' works correctly" 71 atf_set "descr" "Tests that 'set -e' works correctly"
72} 72}
73all_body() { 73all_body() {
74 count=0 74 count=0
75 failcount=0 75 failcount=0
76 76
77 # make sure exiting from a subshell behaves as expected 77 # make sure exiting from a subshell behaves as expected
78 dcheck '(set -e; exit 1; echo ERR$?); echo OK$?' 'OK1' 78 dcheck '(set -e; exit 1; echo ERR$?); echo OK$?' 'OK1'
79 echeck '(set -e; exit 1; echo ERR$?); echo OK$?' 'OK1' 79 echeck '(set -e; exit 1; echo ERR$?); echo OK$?' 'OK1'
80 80
81 # first, check basic functioning. 81 # first, check basic functioning.
82 # The ERR shouldn't print; the result of the () should be 1. 82 # The ERR shouldn't print; the result of the () should be 1.
83 # Henceforth we'll assume that we don't need to check $?. 83 # Henceforth we'll assume that we don't need to check $?.
84 dcheck '(set -e; false; echo ERR$?); echo -n OK$?' 'OK1' 84 dcheck '(set -e; false; echo ERR$?); echo OK$?' 'OK1'
85 echeck '(set -e; false; echo ERR$?); echo -n OK$?' 'OK1' 85 echeck '(set -e; false; echo ERR$?); echo OK$?' 'OK1'
86 86
87 # these cases should be equivalent to the preceding. 87 # these cases should be equivalent to the preceding.
88 dcheck '(set -e; /nonexistent; echo ERR); echo OK' 'OK' 88 dcheck '(set -e; /nonexistent; echo ERR); echo OK' 'OK'
89 echeck '(set -e; /nonexistent; echo ERR); echo OK' 'OK' 89 echeck '(set -e; /nonexistent; echo ERR); echo OK' 'OK'
90 dcheck '(set -e; nonexistent-program-on-path; echo ERR); echo OK' 'OK' 90 dcheck '(set -e; nonexistent-program-on-path; echo ERR); echo OK' 'OK'
91 echeck '(set -e; nonexistent-program-on-path; echo ERR); echo OK' 'OK' 91 echeck '(set -e; nonexistent-program-on-path; echo ERR); echo OK' 'OK'
92 dcheck 'f() { false; }; (set -e; f; echo ERR); echo OK' 'OK' 92 dcheck 'f() { false; }; (set -e; f; echo ERR); echo OK' 'OK'
93 echeck 'f() { false; }; (set -e; f; echo ERR); echo OK' 'OK' 93 echeck 'f() { false; }; (set -e; f; echo ERR); echo OK' 'OK'
94 dcheck 'f() { return 1; }; (set -e; f; echo ERR); echo OK' 'OK' 94 dcheck 'f() { return 1; }; (set -e; f; echo ERR); echo OK' 'OK'
95 echeck 'f() { return 1; }; (set -e; f; echo ERR); echo OK' 'OK' 95 echeck 'f() { return 1; }; (set -e; f; echo ERR); echo OK' 'OK'
96 96
97 # but! with set -e, the false should cause an *immediate* exit. 97 # but! with set -e, the false should cause an *immediate* exit.
98 # The return form should not, as such, but there's no way to 98 # The return form should not, as such, but there's no way to
99 # distinguish it. 99 # distinguish it.
100 dcheck 'f() { false; echo ERR; }; (set -e; f); echo OK' 'OK' 100 dcheck 'f() { false; echo ERR; }; (set -e; f); echo OK' 'OK'
101 echeck 'f() { false; echo ERR; }; (set -e; f); echo OK' 'OK' 101 echeck 'f() { false; echo ERR; }; (set -e; f); echo OK' 'OK'
102 102
103 # set is not scoped, so these should not exit at all. 103 # set is not scoped, so these should not exit at all.
104 dcheck 'f() { set +e; false; echo OK; }; (set -e; f); echo OK' 'OK OK' 104 dcheck 'f() { set +e; false; echo OK; }; (set -e; f); echo OK' 'OK OK'
105 echeck 'f() { set +e; false; echo OK; }; (set -e; f); echo OK' 'OK OK' 105 echeck 'f() { set +e; false; echo OK; }; (set -e; f); echo OK' 'OK OK'
106 106
107 # according to the standard, only failing *simple* commands 107 # according to the standard, only failing *simple* commands
108 # cause an exit under -e. () is not a simple command. 108 # cause an exit under -e. () is not a simple command.
109 # Correct (per POSIX): 109 # Correct (per POSIX):
110 #dcheck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK OK' 110 #dcheck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK OK'
111 #echeck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK OK' 111 #echeck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK OK'
112 # Wrong current behavior: 112 # Wrong current behavior:
113 dcheck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK' 113 dcheck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK'
114 echeck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK' 114 echeck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK'
115 115
116 # make sure an inner nested shell does exit though. 116 # make sure an inner nested shell does exit though.
117 dcheck '(set -e; (false; echo ERR)); echo OK' 'OK' 117 dcheck '(set -e; (false; echo ERR)); echo OK' 'OK'
118 118
119 # The left hand side of an || or && is explicitly tested and 119 # The left hand side of an || or && is explicitly tested and
120 # thus should not cause an exit. Furthermore, because a || or 120 # thus should not cause an exit. Furthermore, because a || or
121 # && expression is not a simple command, there should be no 121 # && expression is not a simple command, there should be no
122 # exit even if the overall result is false. 122 # exit even if the overall result is false.
123 dcheck '(set -e; false || true; echo OK); echo OK' 'OK OK' 123 dcheck '(set -e; false || true; echo OK); echo OK' 'OK OK'
124 echeck '(set -e; false || true; echo OK); echo OK' 'OK OK' 124 echeck '(set -e; false || true; echo OK); echo OK' 'OK OK'
125 dcheck '(set -e; false && true; echo OK); echo OK' 'OK OK' 125 dcheck '(set -e; false && true; echo OK); echo OK' 'OK OK'
126 echeck '(set -e; false && true; echo OK); echo OK' 'OK OK' 126 echeck '(set -e; false && true; echo OK); echo OK' 'OK OK'
127 127
128 # However, the right hand side is not tested, so a failure 128 # However, the right hand side is not tested, so a failure
129 # there *should* cause an exit, regardless of whether it 129 # there *should* cause an exit, regardless of whether it
130 # appears inside a non-simple command. 130 # appears inside a non-simple command.
131 # 131 #
132 # Note that in at least one place the standard does not 132 # Note that in at least one place the standard does not
133 # distinguish between the left and right hand sides of 133 # distinguish between the left and right hand sides of
134 # logical operators. It is possible that for strict 134 # logical operators. It is possible that for strict
135 # compliance these need to not exit; however, if so that 135 # compliance these need to not exit; however, if so that
136 # should probably be limited to when some strict-posix setting 136 # should probably be limited to when some strict-posix setting
137 # is in effect and tested accordingly. 137 # is in effect and tested accordingly.
138 # 138 #
139 dcheck '(set -e; false || false; echo ERR); echo OK' 'OK' 139 dcheck '(set -e; false || false; echo ERR); echo OK' 'OK'
140 dcheck '(set -e; true && false; echo ERR); echo OK' 'OK' 140 dcheck '(set -e; true && false; echo ERR); echo OK' 'OK'
141 echeck '(set -e; false || false; echo ERR); echo OK' 'OK' 141 echeck '(set -e; false || false; echo ERR); echo OK' 'OK'
142 echeck '(set -e; true && false; echo ERR); echo OK' 'OK' 142 echeck '(set -e; true && false; echo ERR); echo OK' 'OK'
143 143
144 # correct: 144 # correct:
145 #dcheck '(set -e; false && false; echo ERR); echo OK' 'OK' 145 #dcheck '(set -e; false && false; echo ERR); echo OK' 'OK'
146 #echeck '(set -e; false && false; echo ERR); echo OK' 'OK' 146 #echeck '(set -e; false && false; echo ERR); echo OK' 'OK'
147 147
148 # wrong current behavior: 148 # wrong current behavior:
149 dcheck '(set -e; false && false; echo ERR); echo OK' 'ERR OK' 149 dcheck '(set -e; false && false; echo ERR); echo OK' 'ERR OK'
150 echeck '(set -e; false && false; echo ERR); echo OK' 'ERR OK' 150 echeck '(set -e; false && false; echo ERR); echo OK' 'ERR OK'
151 151
152 # A failure that is not reached because of short-circuit 152 # A failure that is not reached because of short-circuit
153 # evaluation should not cause an exit, however. 153 # evaluation should not cause an exit, however.
154 dcheck '(set -e; true || false; echo OK); echo OK' 'OK OK' 154 dcheck '(set -e; true || false; echo OK); echo OK' 'OK OK'
155 echeck '(set -e; true || false; echo OK); echo OK' 'OK OK' 155 echeck '(set -e; true || false; echo OK); echo OK' 'OK OK'
156 156
157 # For completeness, test the other two combinations. 157 # For completeness, test the other two combinations.
158 dcheck '(set -e; true || true; echo OK); echo OK' 'OK OK' 158 dcheck '(set -e; true || true; echo OK); echo OK' 'OK OK'
159 dcheck '(set -e; true && true; echo OK); echo OK' 'OK OK' 159 dcheck '(set -e; true && true; echo OK); echo OK' 'OK OK'
160 echeck '(set -e; true || true; echo OK); echo OK' 'OK OK' 160 echeck '(set -e; true || true; echo OK); echo OK' 'OK OK'
161 echeck '(set -e; true && true; echo OK); echo OK' 'OK OK' 161 echeck '(set -e; true && true; echo OK); echo OK' 'OK OK'
162 162
163 # likewise, none of these should exit. 163 # likewise, none of these should exit.
164 dcheck '(set -e; while false; do :; done; echo OK); echo OK' 'OK OK' 164 dcheck '(set -e; while false; do :; done; echo OK); echo OK' 'OK OK'
165 dcheck '(set -e; if false; then :; fi; echo OK); echo OK' 'OK OK' 165 dcheck '(set -e; if false; then :; fi; echo OK); echo OK' 'OK OK'
166 # problematic :-) 166 # problematic :-)
167 #dcheck '(set -e; until false; do :; done; echo OK); echo OK' 'OK OK' 167 #dcheck '(set -e; until false; do :; done; echo OK); echo OK' 'OK OK'
168 dcheck '(set -e; until [ "$t" = 1 ]; do t=1; done; echo OK); echo OK' \ 168 dcheck '(set -e; until [ "$t" = 1 ]; do t=1; done; echo OK); echo OK' \
169 'OK OK' 169 'OK OK'
170 echeck '(set -e; while false; do :; done; echo OK); echo OK' 'OK OK' 170 echeck '(set -e; while false; do :; done; echo OK); echo OK' 'OK OK'
171 echeck '(set -e; if false; then :; fi; echo OK); echo OK' 'OK OK' 171 echeck '(set -e; if false; then :; fi; echo OK); echo OK' 'OK OK'
172 echeck '(set -e; until [ "$t" = 1 ]; do t=1; done; echo OK); echo OK' \ 172 echeck '(set -e; until [ "$t" = 1 ]; do t=1; done; echo OK); echo OK' \
173 'OK OK' 173 'OK OK'
174 174
175 # the bang operator tests its argument and thus the argument 175 # the bang operator tests its argument and thus the argument
176 # should not cause an exit. it is also not a simple command (I 176 # should not cause an exit. it is also not a simple command (I
177 # believe) so it also shouldn't exit even if it yields a false 177 # believe) so it also shouldn't exit even if it yields a false
178 # result. 178 # result.
179 dcheck '(set -e; ! false; echo OK); echo OK' 'OK OK' 179 dcheck '(set -e; ! false; echo OK); echo OK' 'OK OK'
180 dcheck '(set -e; ! true; echo OK); echo OK' 'OK OK' 180 dcheck '(set -e; ! true; echo OK); echo OK' 'OK OK'
181 echeck '(set -e; ! false; echo OK); echo OK' 'OK OK' 181 echeck '(set -e; ! false; echo OK); echo OK' 'OK OK'
182 echeck '(set -e; ! true; echo OK); echo OK' 'OK OK' 182 echeck '(set -e; ! true; echo OK); echo OK' 'OK OK'
183 183
184 # combined case with () and &&; the inner expression is false 184 # combined case with () and &&; the inner expression is false
185 # but does not itself exit, and the () should not cause an  185 # but does not itself exit, and the () should not cause an
186 # exit even when failing. 186 # exit even when failing.
187 # correct: 187 # correct:
188 #dcheck '(set -e; (false && true); echo OK); echo OK' 'OK OK' 188 #dcheck '(set -e; (false && true); echo OK); echo OK' 'OK OK'
189 #echeck '(set -e; (false && true); echo OK); echo OK' 'OK OK' 189 #echeck '(set -e; (false && true); echo OK); echo OK' 'OK OK'
190 # wrong current behavior: 190 # wrong current behavior:
191 dcheck '(set -e; (false && true); echo OK); echo OK' 'OK' 191 dcheck '(set -e; (false && true); echo OK); echo OK' 'OK'
192 echeck '(set -e; (false && true); echo OK); echo OK' 'OK' 192 echeck '(set -e; (false && true); echo OK); echo OK' 'OK'
193 193
194 # pipelines. only the right-hand end is significant. 194 # pipelines. only the right-hand end is significant.
195 dcheck '(set -e; false | true; echo OK); echo OK' 'OK OK' 195 dcheck '(set -e; false | true; echo OK); echo OK' 'OK OK'
196 echeck '(set -e; false | true; echo OK); echo OK' 'OK OK' 196 echeck '(set -e; false | true; echo OK); echo OK' 'OK OK'
197 dcheck '(set -e; true | false; echo ERR); echo OK' 'OK' 197 dcheck '(set -e; true | false; echo ERR); echo OK' 'OK'
198 echeck '(set -e; true | false; echo ERR); echo OK' 'OK' 198 echeck '(set -e; true | false; echo ERR); echo OK' 'OK'
199 199
200 dcheck '(set -e; while true | false; do :; done; echo OK); echo OK' \ 200 dcheck '(set -e; while true | false; do :; done; echo OK); echo OK' \
201 'OK OK' 201 'OK OK'
202 dcheck '(set -e; if true | false; then :; fi; echo OK); echo OK' \ 202 dcheck '(set -e; if true | false; then :; fi; echo OK); echo OK' \
203 'OK OK' 203 'OK OK'
204 204
205 205
206 # According to dsl@ in PR bin/32282, () is not defined as a 206 # According to dsl@ in PR bin/32282, () is not defined as a
207 # subshell, only as a grouping operator [and a scope, I guess] 207 # subshell, only as a grouping operator [and a scope, I guess]
208 208
209 # (This is incorrect. () is definitely a sub-shell) 209 # (This is incorrect. () is definitely a sub-shell)
210 210
211 # so the nested false ought to cause the whole shell to exit, 211 # so the nested false ought to cause the whole shell to exit,
212 # not just the subshell. dholland@ would like to see C&V, 212 # not just the subshell. dholland@ would like to see C&V,
213 # because that seems like a bad idea. (Among other things, it 213 # because that seems like a bad idea. (Among other things, it
214 # would break all the above test logic, which relies on being 214 # would break all the above test logic, which relies on being
215 # able to isolate set -e behavior inside ().) However, I'm 215 # able to isolate set -e behavior inside ().) However, I'm
216 # going to put these tests here to make sure the issue gets 216 # going to put these tests here to make sure the issue gets
217 # dealt with sometime. 217 # dealt with sometime.
218 # 218 #
219 # XXX: the second set has been disabled in the name of making 219 # XXX: the second set has been disabled in the name of making
220 # all tests "pass". 220 # all tests "pass".
221 # 221 #
222 # As they should be, they are utter nonsense. 222 # As they should be, they are utter nonsense.
223 223
224 # 1. error if the whole shell exits (current correct behavior) 224 # 1. error if the whole shell exits (current correct behavior)
225 dcheck 'echo OK; (set -e; false); echo OK' 'OK OK' 225 dcheck 'echo OK; (set -e; false); echo OK' 'OK OK'
226 echeck 'echo OK; (set -e; false); echo OK' 'OK OK' 226 echeck 'echo OK; (set -e; false); echo OK' 'OK OK'
227 # 2. error if the whole shell does not exit (dsl's suggested behavior) 227 # 2. error if the whole shell does not exit (dsl's suggested behavior)
228 #dcheck 'echo OK; (set -e; false); echo ERR' 'OK' 228 #dcheck 'echo OK; (set -e; false); echo ERR' 'OK'
229 #echeck 'echo OK; (set -e; false); echo ERR' 'OK' 229 #echeck 'echo OK; (set -e; false); echo ERR' 'OK'
230 230
231 # The current behavior of the shell is that it exits out as 231 # The current behavior of the shell is that it exits out as
232 # far as -e is set and then stops. This is probably a 232 # far as -e is set and then stops. This is probably a
233 # consequence of it handling () wrong, but it's a somewhat 233 # consequence of it handling () wrong, but it's a somewhat
234 # curious compromise position between 1. and 2. above. 234 # curious compromise position between 1. and 2. above.
235 dcheck '(set -e; (false; echo ERR); echo ERR); echo OK' 'OK' 235 dcheck '(set -e; (false; echo ERR); echo ERR); echo OK' 'OK'
236 echeck '(set -e; (false; echo ERR); echo ERR); echo OK' 'OK' 236 echeck '(set -e; (false; echo ERR); echo ERR); echo OK' 'OK'
237 237
238 # backquote expansion (PR bin/17514) 238 # backquote expansion (PR bin/17514)
239 239
240 # (in-)correct 240 # (in-)correct
241 #dcheck '(set -e; echo ERR `false`; echo ERR); echo OK' 'OK' 241 #dcheck '(set -e; echo ERR `false`; echo ERR); echo OK' 'OK'
242 #dcheck '(set -e; echo ERR $(false); echo ERR); echo OK' 'OK' 242 #dcheck '(set -e; echo ERR $(false); echo ERR); echo OK' 'OK'
243 #dcheck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'OK' 243 #dcheck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'OK'
244 #dcheck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'OK' 244 #dcheck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'OK'
245 # Not-wrong current behavior 245 # Not-wrong current behavior
246 # the exit status of ommand substitution is ignored in most cases 246 # the exit status of ommand substitution is ignored in most cases
247 # None of these should be causing the shell to exit. 247 # None of these should be causing the shell to exit.
248 dcheck '(set -e; echo ERR `false`; echo ERR); echo OK' 'ERR ERR OK' 248 dcheck '(set -e; echo ERR `false`; echo ERR); echo OK' 'ERR ERR OK'
249 dcheck '(set -e; echo ERR $(false); echo ERR); echo OK' 'ERR ERR OK' 249 dcheck '(set -e; echo ERR $(false); echo ERR); echo OK' 'ERR ERR OK'
250 dcheck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'ERR ERR OK' 250 dcheck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'ERR ERR OK'
251 dcheck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'ERR ERR OK' 251 dcheck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'ERR ERR OK'
252 252
253 # This is testing one case (the case?) where the exit status is used 253 # This is testing one case (the case?) where the exit status is used
254 dcheck '(set -e; x=`false`; echo ERR); echo OK' 'OK' 254 dcheck '(set -e; x=`false`; echo ERR); echo OK' 'OK'
255 dcheck '(set -e; x=$(false); echo ERR); echo OK' 'OK' 255 dcheck '(set -e; x=$(false); echo ERR); echo OK' 'OK'
256 dcheck '(set -e; x=`exit 3`; echo ERR); echo OK' 'OK' 256 dcheck '(set -e; x=`exit 3`; echo ERR); echo OK' 'OK'
257 dcheck '(set -e; x=$(exit 3); echo ERR); echo OK' 'OK' 257 dcheck '(set -e; x=$(exit 3); echo ERR); echo OK' 'OK'
258 258
259 # correct (really just commented out incorrect nonsense) 259 # correct (really just commented out incorrect nonsense)
260 #echeck '(set -e; echo ERR `false`; echo ERR); echo OK' 'OK' 260 #echeck '(set -e; echo ERR `false`; echo ERR); echo OK' 'OK'
261 #echeck '(set -e; echo ERR $(false); echo ERR); echo OK' 'OK' 261 #echeck '(set -e; echo ERR $(false); echo ERR); echo OK' 'OK'
262 #echeck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'OK' 262 #echeck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'OK'
263 #echeck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'OK' 263 #echeck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'OK'
264 264
265 # not-wrong current behavior (as above) 265 # not-wrong current behavior (as above)
266 echeck '(set -e; echo ERR `false`; echo ERR); echo OK' 'ERR ERR OK' 266 echeck '(set -e; echo ERR `false`; echo ERR); echo OK' 'ERR ERR OK'
267 echeck '(set -e; echo ERR $(false); echo ERR); echo OK' 'ERR ERR OK' 267 echeck '(set -e; echo ERR $(false); echo ERR); echo OK' 'ERR ERR OK'
268 echeck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'ERR ERR OK' 268 echeck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'ERR ERR OK'
269 echeck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'ERR ERR OK' 269 echeck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'ERR ERR OK'
270 270
271 echeck '(set -e; x=`false`; echo ERR); echo OK' 'OK' 271 echeck '(set -e; x=`false`; echo ERR); echo OK' 'OK'
272 echeck '(set -e; x=$(false); echo ERR); echo OK' 'OK' 272 echeck '(set -e; x=$(false); echo ERR); echo OK' 'OK'
273 echeck '(set -e; x=`exit 3`; echo ERR); echo OK' 'OK' 273 echeck '(set -e; x=`exit 3`; echo ERR); echo OK' 'OK'
274 echeck '(set -e; x=$(exit 3); echo ERR); echo OK' 'OK' 274 echeck '(set -e; x=$(exit 3); echo ERR); echo OK' 'OK'
275 275
276 # shift (PR bin/37493) 276 # shift (PR bin/37493)
277 # correct 277 # correct
278 # Actually, both ways are correct, both are permitted 278 # Actually, both ways are correct, both are permitted
279 #dcheck '(set -e; shift || true; echo OK); echo OK' 'OK OK' 279 #dcheck '(set -e; shift || true; echo OK); echo OK' 'OK OK'
280 #echeck '(set -e; shift || true; echo OK); echo OK' 'OK OK' 280 #echeck '(set -e; shift || true; echo OK); echo OK' 'OK OK'
281 # (not-) wrong current behavior 281 # (not-) wrong current behavior
282 #dcheck '(set -e; shift || true; echo OK); echo OK' 'OK' 282 #dcheck '(set -e; shift || true; echo OK); echo OK' 'OK'
283 #echeck '(set -e; shift || true; echo OK); echo OK' 'OK' 283 #echeck '(set -e; shift || true; echo OK); echo OK' 'OK'
284 284
285 # what is wrong is this test assuming one behaviour or the other 285 # what is wrong is this test assuming one behaviour or the other
286 # (and incidentally this has nothing whatever to do with "-e", 286 # (and incidentally this has nothing whatever to do with "-e",
287 # the test should really be moved elsewhere...) 287 # the test should really be moved elsewhere...)
288 # But for now, leave it here, and correct it: 288 # But for now, leave it here, and correct it:
289 dcheck '(set -e; shift && echo OK); echo OK' 'OK' 289 dcheck '(set -e; shift && echo OK); echo OK' 'OK'
290 echeck '(set -e; shift && echo OK); echo OK' 'OK' 290 echeck '(set -e; shift && echo OK); echo OK' 'OK'
291 291
292 # Done. 292 # Done.
293 293
294 if [ "x$SH_FAILS" != x ]; then 294 if [ "x$SH_FAILS" != x ]; then
295 printf '%-56s %-8s %s\n' "Expression" "Result" "Should be" 295 printf '%-56s %-8s %s\n' "Expression" "Result" "Should be"
296 echo "$SH_FAILS" 296 echo "$SH_FAILS"
297 atf_fail "$failcount of $count failed cases" 297 atf_fail "$failcount of $count failed cases"
298 else 298 else
299 atf_pass 299 atf_pass
300 fi 300 fi
301} 301}
302 302
303atf_init_test_cases() { 303atf_init_test_cases() {
304 atf_add_test_case all 304 atf_add_test_case all
305} 305}

cvs diff -r1.2 -r1.3 src/tests/bin/sh/t_ulimit.sh (switch to unified diff)

--- src/tests/bin/sh/t_ulimit.sh 2015/12/30 22:24:44 1.2
+++ src/tests/bin/sh/t_ulimit.sh 2016/03/27 14:50:01 1.3
@@ -1,57 +1,57 @@ @@ -1,57 +1,57 @@
1# $NetBSD: t_ulimit.sh,v 1.2 2015/12/30 22:24:44 christos Exp $ 1# $NetBSD: t_ulimit.sh,v 1.3 2016/03/27 14:50:01 christos Exp $
2# 2#
3# Copyright (c) 2012 The NetBSD Foundation, Inc. 3# Copyright (c) 2012 The NetBSD Foundation, Inc.
4# All rights reserved. 4# All rights reserved.
5# 5#
6# Redistribution and use in source and binary forms, with or without 6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions 7# modification, are permitted provided that the following conditions
8# are met: 8# are met:
9# 1. Redistributions of source code must retain the above copyright 9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer. 10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright 11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the 12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution. 13# documentation and/or other materials provided with the distribution.
14# 14#
15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE. 25# POSSIBILITY OF SUCH DAMAGE.
26# 26#
 27# the implementation of "sh" to test
 28: ${TEST_SH:="/bin/sh"}
27 29
28# ulimit builtin test. 30# ulimit builtin test.
29 31
30atf_test_case limits 32atf_test_case limits
31limits_head() { 33limits_head() {
32 atf_set "descr" "Checks for limits flags" 34 atf_set "descr" "Checks for limits flags"
33} 35}
34 36
35get_ulimits() { 37get_ulimits() {
36 local limits=$(ulimit -a | 38 local limits=$(${TEST_SH} -c 'ulimit -a' |
37 sed -e 's/.*\(-[A-Za-z0-9]\)[^A-Za-z0-9].*/\1/' | sort -u) 39 sed -e 's/.*\(-[A-Za-z0-9]\)[^A-Za-z0-9].*/\1/' | sort -u)
38 if [ -z "$limits" ]; then 40 if [ -z "$limits" ]; then
39 # grr ksh 41 # grr ksh
40 limits="-a -b -c -d -f -l -m -n -p -r -s -t -v" 42 limits="-a -b -c -d -f -l -m -n -p -r -s -t -v"
41 fi 43 fi
42 echo "$limits" 44 echo "$limits"
43} 45}
44 46
45limits_body() { 47limits_body() {
46 atf_check -s eq:0 -o ignore -e empty \ 48 atf_check -s eq:0 -o ignore -e empty ${TEST_SH} -c "ulimit -a"
47 /bin/sh -c "ulimit -a" 
48 for l in $(get_ulimits) 49 for l in $(get_ulimits)
49 do 50 do
50 atf_check -s eq:0 -o ignore -e empty \ 51 atf_check -s eq:0 -o ignore -e empty ${TEST_SH} -c "ulimit $l"
51 /bin/sh -c "ulimit $l" 
52 done 52 done
53} 53}
54 54
55atf_init_test_cases() { 55atf_init_test_cases() {
56 atf_add_test_case limits 56 atf_add_test_case limits
57} 57}

cvs diff -r1.4 -r1.5 src/tests/bin/sh/t_varquote.sh (switch to unified diff)

--- src/tests/bin/sh/t_varquote.sh 2016/03/12 14:58:03 1.4
+++ src/tests/bin/sh/t_varquote.sh 2016/03/27 14:50:01 1.5
@@ -1,135 +1,134 @@ @@ -1,135 +1,134 @@
1# $NetBSD: t_varquote.sh,v 1.4 2016/03/12 14:58:03 christos Exp $ 1# $NetBSD: t_varquote.sh,v 1.5 2016/03/27 14:50:01 christos Exp $
2# 2#
3# Copyright (c) 2007 The NetBSD Foundation, Inc. 3# Copyright (c) 2007 The NetBSD Foundation, Inc.
4# All rights reserved. 4# All rights reserved.
5# 5#
6# Redistribution and use in source and binary forms, with or without 6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions 7# modification, are permitted provided that the following conditions
8# are met: 8# are met:
9# 1. Redistributions of source code must retain the above copyright 9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer. 10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright 11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the 12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution. 13# documentation and/or other materials provided with the distribution.
14# 14#
15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE. 25# POSSIBILITY OF SUCH DAMAGE.
26# 26#
27# the implementation of "sh" to test 27# the implementation of "sh" to test
28: ${TEST_SH:="/bin/sh"} 28: ${TEST_SH:="/bin/sh"}
29 29
30# Variable quoting test. 30# Variable quoting test.
31 31
32check() { 32check() {
33 if [ "$1" != "$2" ] 33 if [ "$1" != "$2" ]
34 then 34 then
35 atf_fail "expected [$2], found [$1]" 1>&2 35 atf_fail "expected [$2], found [$1]" 1>&2
36 fi 36 fi
37} 37}
38 38
39atf_test_case all 39atf_test_case all
40all_head() { 40all_head() {
41 atf_set "descr" "Basic checks for variable quoting" 41 atf_set "descr" "Basic checks for variable quoting"
42} 42}
43all_body() { 43all_body() {
44 44
45 cat <<-'EOF' > script.sh 45 cat <<-'EOF' > script.sh
46 T=0 46 T=0
47 check() { 47 check() {
48 T=$((${T} + 1)) 48 T=$((${T} + 1))
49 49
50 if [ "$1" != "$2" ] 50 if [ "$1" != "$2" ]
51 then 51 then
52 printf '%s\n' "T${T}: expected [$2], found [$1]" 52 printf '%s\n' "T${T}: expected [$2], found [$1]"
53 exit 1 53 exit 1
54 fi 54 fi
55 } 55 }
56 56
57 #1 57 #1
58 foo='${a:-foo}' 58 foo='${a:-foo}'
59 check "$foo" '${a:-foo}' 59 check "$foo" '${a:-foo}'
60 #2 60 #2
61 foo="${a:-foo}" 61 foo="${a:-foo}"
62 check "$foo" "foo" 62 check "$foo" "foo"
63 #3 63 #3
64 foo=${a:-"'{}'"}  64 foo=${a:-"'{}'"}
65 check "$foo" "'{}'" 65 check "$foo" "'{}'"
66 #4 66 #4
67 foo=${a:-${b:-"'{}'"}} 67 foo=${a:-${b:-"'{}'"}}
68 check "$foo" "'{}'" 68 check "$foo" "'{}'"
69 #5 69 #5
70 # ${ } The ' are inside ".." so are literal (not quotes). 70 # ${ } The ' are inside ".." so are literal (not quotes).
71 foo="${a-'}'}" 71 foo="${a-'}'}"
72 check "$foo" "''}" 72 check "$foo" "''}"
73 #6 73 #6
74 # The rules for quoting in ${var-word} expressions are somewhat 74 # The rules for quoting in ${var-word} expressions are somewhat
75 # weird, in the following there is not one quoted string being 75 # weird, in the following there is not one quoted string being
76 # assigned to foo (with internally quoted sub-strings), rather 76 # assigned to foo (with internally quoted sub-strings), rather
77 # it is a mixed quoted/unquoted string, with parts that are 77 # it is a mixed quoted/unquoted string, with parts that are
78 # quoted, separated by 2 unquoted sections... 78 # quoted, separated by 2 unquoted sections...
79 # qqqqqqqqqq uuuuuuuuuu qq uuuu qqqq 79 # qqqqqqqqqq uuuuuuuuuu qq uuuu qqqq
80 foo="${a:-${b:-"${c:-${d:-"x}"}}y}"}}z}" 80 foo="${a:-${b:-"${c:-${d:-"x}"}}y}"}}z}"
81 # " z*" 81 # " z*"
82 # ${a:- } 82 # ${a:- }
83 # ${b:- } 83 # ${b:- }
84 # " y*" 84 # " y*"
85 # ${c:- } 85 # ${c:- }
86 # ${d:- } 86 # ${d:- }
87 # "x*" 87 # "x*"
88 check "$foo" "x}y}z}" 88 check "$foo" "x}y}z}"
89 #7 89 #7
90 # And believe it or not, this is the one that gives 90 # And believe it or not, this is the one that gives
91 # most problems, with 3 different observed outputs... 91 # most problems, with 3 different observed outputs...
92 # qqqqq qq q is one interpretation 92 # qqqqq qq q is one interpretation
93 # qqqqq QQQQ q is another (most common) 93 # qqqqq QQQQ q is another (most common)
94 # (the third is syntax error...) 94 # (the third is syntax error...)
95 foo="${a:-"'{}'"}" 95 foo="${a:-"'{}'"}"
96 check "$foo" "'{}'" 96 check "$foo" "'{}'"
97 97
98 EOF 98 EOF
99 99
100 OUT=$( ${TEST_SH} script.sh 2>&1 ) 100 OUT=$( ${TEST_SH} script.sh 2>&1 )
101 if [ $? -ne 0 ] 101 if [ $? -ne 0 ]
102 then 102 then
103 atf_fail "${OUT}" 103 atf_fail "${OUT}"
104 elif [ -n "${OUT}" ] 104 elif [ -n "${OUT}" ]
105 then 105 then
106 atf_fail "script.sh unexpectedly said: ${OUT}" 106 atf_fail "script.sh unexpectedly said: ${OUT}"
107 fi 107 fi
108} 108}
109 109
110atf_test_case nested_quotes_multiword 110atf_test_case nested_quotes_multiword
111nested_quotes_multiword_head() { 111nested_quotes_multiword_head() {
112 atf_set "descr" "Tests that having nested quoting in a multi-word" \ 112 atf_set "descr" "Tests that having nested quoting in a multi-word" \
113 "string works (PR bin/43597)" 113 "string works (PR bin/43597)"
114} 114}
115nested_quotes_multiword_body() { 115nested_quotes_multiword_body() {
116 atf_check -s eq:0 -o match:"first-word second-word" -e empty \ 116 atf_check -s eq:0 -o match:"first-word second-word" -e empty \
117 ${TEST_SH} -c 'echo "${foo:="first-word"} second-word"' 117 ${TEST_SH} -c 'echo "${foo:="first-word"} second-word"'
118} 118}
119 119
120atf_test_case default_assignment_with_arith 120atf_test_case default_assignment_with_arith
121default_assignment_with_arith_head() { 121default_assignment_with_arith_head() {
122 atf_set "descr" "Tests default variable assignment with arithmetic" \ 122 atf_set "descr" "Tests default variable assignment with arithmetic" \
123 "string works (PR bin/50827)" 123 "string works (PR bin/50827)"
124} 124}
125default_assignment_with_arith_body() { 125default_assignment_with_arith_body() {
126 atf_check -s eq:0 -o empty -e empty ${TEST_SH} -c ': "${x=$((1))}"' 126 atf_check -s eq:0 -o empty -e empty ${TEST_SH} -c ': "${x=$((1))}"'
127 atf_check -s eq:0 -o match:1 -e empty ${TEST_SH} -c 'echo "${x=$((1))}"' 127 atf_check -s eq:0 -o match:1 -e empty ${TEST_SH} -c 'echo "${x=$((1))}"'
128 
129} 128}
130 129
131atf_init_test_cases() { 130atf_init_test_cases() {
132 atf_add_test_case all 131 atf_add_test_case all
133 atf_add_test_case nested_quotes_multiword 132 atf_add_test_case nested_quotes_multiword
134 atf_add_test_case default_assignment_with_arith 133 atf_add_test_case default_assignment_with_arith
135} 134}