t_syntax.sh revision 1.3 1 1.3 kre # $NetBSD: t_syntax.sh,v 1.3 2017/06/09 23:49:58 kre Exp $
2 1.1 kre #
3 1.1 kre # Copyright (c) 2017 The NetBSD Foundation, Inc.
4 1.1 kre # All rights reserved.
5 1.1 kre #
6 1.1 kre # Redistribution and use in source and binary forms, with or without
7 1.1 kre # modification, are permitted provided that the following conditions
8 1.1 kre # are met:
9 1.1 kre # 1. Redistributions of source code must retain the above copyright
10 1.1 kre # notice, this list of conditions and the following disclaimer.
11 1.1 kre # 2. Redistributions in binary form must reproduce the above copyright
12 1.1 kre # notice, this list of conditions and the following disclaimer in the
13 1.1 kre # documentation and/or other materials provided with the distribution.
14 1.1 kre #
15 1.1 kre # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1 kre # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1 kre # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1 kre # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1 kre # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1 kre # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1 kre # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1 kre # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1 kre # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1 kre # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 kre # POSSIBILITY OF SUCH DAMAGE.
26 1.1 kre #
27 1.1 kre : ${TEST_SH:=/bin/sh}
28 1.1 kre
29 1.1 kre # This set of tests verifies various requirementgs relating to correct
30 1.1 kre # (and incorrect) syntax of shell input
31 1.1 kre #
32 1.1 kre # There is no intent in these tests to verify correct operation
33 1.1 kre # (though that sometimes cannot be separated from correct parsing.)
34 1.1 kre # That is (or should be) verified elsewhere.
35 1.1 kre #
36 1.1 kre # Also, some very basic syntax is tested in almost every test
37 1.1 kre # (they cannot work without basic parsing of elementary commands)
38 1.1 kre # so that is also not explicitly tested here.
39 1.1 kre #
40 1.1 kre # Similarly word expansion, field splitting, redirection, all have
41 1.1 kre # tests of their own (though we do test parsing of redirect ops).
42 1.1 kre #
43 1.1 kre # Note that in order to test the basic facilities, other shell operations
44 1.1 kre # are used - a test failure here does not necessarily mean that the
45 1.1 kre # operation intended to be tested is faulty, just that something is.
46 1.1 kre
47 1.1 kre atf_test_case a_basic_tokenisation
48 1.1 kre a_basic_tokenisation_head() {
49 1.1 kre atf_set "descr" "Test the shell correctly finds various tokens"
50 1.1 kre }
51 1.1 kre a_basic_tokenisation_body() {
52 1.1 kre atf_check -s exit:0 -o 'inline:3\n' -e empty ${TEST_SH} -c \
53 1.1 kre 'set -- a b c; echo $#'
54 1.1 kre atf_check -s exit:0 -o 'inline:2\n' -e empty ${TEST_SH} -c \
55 1.1 kre 'set -- a""b c; echo $#'
56 1.1 kre atf_check -s exit:0 -o 'inline:3\n' -e empty ${TEST_SH} -c \
57 1.1 kre 'set -- a"" b c; echo $#'
58 1.1 kre atf_check -s exit:0 -o 'inline:3\n' -e empty ${TEST_SH} -c \
59 1.1 kre 'set -- ""a b c\;; echo $#'
60 1.1 kre
61 1.1 kre atf_check -s exit:0 -o 'inline:3\n' -e empty ${TEST_SH} -c \
62 1.1 kre 'set -- set -- c; echo $#'
63 1.1 kre atf_check -s exit:0 -o 'inline:1\n' -e empty ${TEST_SH} -c \
64 1.1 kre 'set --;set -- c; echo $#'
65 1.1 kre atf_check -s exit:0 -o 'inline:1\n' -e empty ${TEST_SH} -c \
66 1.1 kre 'set --&set -- c; echo $#'
67 1.1 kre atf_check -s exit:0 -o 'inline:1\n' -e empty ${TEST_SH} -c \
68 1.1 kre 'set -- a b&&set -- c; echo $#'
69 1.1 kre atf_check -s exit:0 -o 'inline:2\n' -e empty ${TEST_SH} -c \
70 1.1 kre 'set -- a b||set -- c; echo $#'
71 1.1 kre }
72 1.1 kre
73 1.1 kre atf_test_case b_comments
74 1.1 kre b_comments_head() {
75 1.1 kre atf_set "descr" "Test the shell correctly handles comments"
76 1.1 kre }
77 1.1 kre b_comments_body() {
78 1.1 kre
79 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '#'
80 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '# exit 1'
81 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c 'true # exit 1'
82 1.1 kre atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c 'false # exit 0'
83 1.1 kre
84 1.1 kre atf_check -s exit:0 -o 'inline:foo\n' -e empty ${TEST_SH} -c \
85 1.1 kre 'echo foo # bar'
86 1.1 kre atf_check -s exit:0 -o 'inline:foo # bar\n' -e empty ${TEST_SH} -c \
87 1.1 kre 'echo foo \# bar'
88 1.1 kre atf_check -s exit:0 -o 'inline:foo\n' -e empty ${TEST_SH} -c \
89 1.1 kre 'echo foo; # echo bar'
90 1.1 kre atf_check -s exit:0 -o 'inline:foo#bar\n' -e empty ${TEST_SH} -c \
91 1.1 kre 'echo foo#bar'
92 1.1 kre atf_check -s exit:0 -o 'inline:foo# bar\n' -e empty ${TEST_SH} -c \
93 1.1 kre 'echo foo# bar'
94 1.1 kre atf_check -s exit:0 -o 'inline:foo\n' -e empty ${TEST_SH} -c \
95 1.1 kre 'x=foo; echo ${x#bar}'
96 1.1 kre
97 1.1 kre atf_check -s exit:0 -o 'inline:#\n' -e empty ${TEST_SH} -c \
98 1.1 kre 'echo "#"'
99 1.1 kre atf_check -s exit:0 -o 'inline:#\n' -e empty ${TEST_SH} -c \
100 1.1 kre "echo '#'"
101 1.1 kre atf_check -s exit:0 -o 'inline:#\n' -e empty ${TEST_SH} -c \
102 1.1 kre 'echo \#'
103 1.1 kre atf_check -s exit:0 -o 'inline:##\n' -e empty ${TEST_SH} -c \
104 1.1 kre 'echo "#"#'
105 1.1 kre atf_check -s exit:0 -o 'inline:##\n' -e empty ${TEST_SH} -c \
106 1.1 kre "echo '#'#"
107 1.1 kre atf_check -s exit:0 -o 'inline:##\n' -e empty ${TEST_SH} -c \
108 1.1 kre 'echo \##'
109 1.1 kre atf_check -s exit:0 -o 'inline:##\n' -e empty ${TEST_SH} -c \
110 1.1 kre 'echo "#"# #"#"'
111 1.1 kre atf_check -s exit:0 -o 'inline:##\n' -e empty ${TEST_SH} -c \
112 1.1 kre "echo '#'# #'#'"
113 1.1 kre atf_check -s exit:0 -o 'inline:##\n' -e empty ${TEST_SH} -c \
114 1.1 kre 'echo \## #\#'
115 1.1 kre
116 1.1 kre cat <<-'DONE'|atf_check -s exit:0 -o inline:'foo\n' -e empty ${TEST_SH}
117 1.1 kre # test comments do not provoke synax errors !\
118 1.1 kre echo foo # ( { " hello
119 1.1 kre while : # that's forever
120 1.1 kre do # the following command list
121 1.1 kre # starting with nothing ${unset?error}
122 1.1 kre break # done loop terminate $( echo bar; exit 1 )
123 1.1 kre done #####################################################
124 1.1 kre # "hello
125 1.1 kre exit 0
126 1.1 kre DONE
127 1.1 kre }
128 1.1 kre
129 1.1 kre atf_test_case c_line_wrapping
130 1.1 kre c_line_wrapping_head() {
131 1.1 kre atf_set "descr" "check aspects of command line wrapping"
132 1.1 kre }
133 1.1 kre c_line_wrapping_body() {
134 1.1 kre atf_require_prog ls
135 1.1 kre atf_require_prog printf
136 1.1 kre
137 1.1 kre cat <<- 'DONE' | atf_check -s exit:0 -o ignore -e empty ${TEST_SH} -e
138 1.1 kre l\
139 1.1 kre s
140 1.1 kre DONE
141 1.1 kre
142 1.1 kre cat <<- 'DONE' | atf_check -s exit:7 -o empty -e empty ${TEST_SH}
143 1.1 kre e\
144 1.1 kre x\
145 1.1 kre it \
146 1.1 kre 7
147 1.1 kre DONE
148 1.1 kre
149 1.1 kre # Have to do this twice as cannot say "any exit code but 0 or 7" ...
150 1.1 kre cat <<- 'DONE' | atf_check -s not-exit:0 -o empty -e not-empty \
151 1.1 kre ${TEST_SH}
152 1.1 kre e\
153 1.1 kre x\
154 1.1 kre it\
155 1.1 kre 7
156 1.1 kre DONE
157 1.1 kre cat <<- 'DONE' | atf_check -s not-exit:7 -o empty -e not-empty \
158 1.1 kre ${TEST_SH}
159 1.1 kre e\
160 1.1 kre x\
161 1.1 kre it\
162 1.1 kre 7
163 1.1 kre DONE
164 1.1 kre
165 1.1 kre cat <<- 'DONE' | atf_check -s exit:0 -o empty -e empty ${TEST_SH}
166 1.1 kre wh\
167 1.1 kre il\
168 1.1 kre e \
169 1.1 kre f\a\
170 1.1 kre \l\s\e
171 1.1 kre do
172 1.1 kre :\
173 1.1 kre ;
174 1.1 kre done
175 1.1 kre DONE
176 1.1 kre
177 1.1 kre cat <<- 'DONE' | atf_check -s exit:0 -o inline:'hellohellohellohello' \
178 1.1 kre -e empty ${TEST_SH}
179 1.1 kre V\
180 1.1 kre AR=hel\
181 1.1 kre lo
182 1.1 kre unset U V1
183 1.1 kre pri\
184 1.1 kre ntf '%s' ${\
185 1.1 kre VAR\
186 1.1 kre }
187 1.1 kre p\
188 1.1 kre r\
189 1.1 kre i\
190 1.1 kre n\
191 1.1 kre t\
192 1.1 kre f\
193 1.1 kre \
194 1.1 kre '%s' \
195 1.1 kre $\
196 1.1 kre {\
197 1.1 kre V\
198 1.1 kre A\
199 1.1 kre R}
200 1.1 kre printf '%s' ${U\
201 1.1 kre -\
202 1.1 kre "$\
203 1.1 kre {V\
204 1.1 kre 1:\
205 1.1 kre =$\
206 1.1 kre {V\
207 1.1 kre AR+\
208 1.1 kre ${V\
209 1.1 kre AR}\
210 1.1 kre }\
211 1.3 kre }"}
212 1.1 kre printf '%s' ${V\
213 1.1 kre 1?V1\
214 1.1 kre \
215 1.1 kre FAIL}
216 1.1 kre DONE
217 1.3 kre
218 1.1 kre cat <<- 'DONE' | atf_check -s exit:0 -o inline:'2\n' ${TEST_SH}
219 1.1 kre l\
220 1.1 kre s=7 bi\
221 1.1 kre n\
222 1.1 kre =\
223 1.1 kre 3
224 1.1 kre echo $(\
225 1.1 kre ( ls /bin )\
226 1.1 kre )
227 1.1 kre DONE
228 1.3 kre
229 1.3 kre # Inspired by src/etc/MAKEDEV.tmpl failure with (broken)
230 1.3 kre # sh LINENO code... avoid it happening again...
231 1.3 kre for VARS in 1:0:0:0 0:1:0:0 0:0:1:0 0:0:0:1 \
232 1.3 kre 1:0:0:1 1:0:1:0 1:1:0:0 0:1:1:0 \
233 1.3 kre 0:0:0:0 1:1:0:1 0:1:1:1 1:1:1:1
234 1.3 kre do
235 1.3 kre eval $(
236 1.3 kre IFS=:
237 1.3 kre set -- $VARS
238 1.3 kre test $(( $1 + $2 + $3 + $4 )) -eq 1 &&
239 1.3 kre R=OK || R=BAD
240 1.3 kre printf "R=%s;" $R
241 1.3 kre for v in a b c d
242 1.3 kre do
243 1.3 kre case $1 in
244 1.3 kre (0) printf "export %s=false;" $v;;
245 1.3 kre (1) printf "export %s=true;" $v;;
246 1.3 kre esac
247 1.3 kre shift
248 1.3 kre done
249 1.3 kre )
250 1.3 kre
251 1.3 kre cat <<- 'DONE' | atf_check -s exit:0 -o inline:"${R}" ${TEST_SH}
252 1.3 kre case $(( $($a && echo 1 || echo 0) + \
253 1.3 kre $($b && echo 1 || echo 0) + \
254 1.3 kre $($c && echo 1 || echo 0) + \
255 1.3 kre $($d && echo 1 || echo 0) ))
256 1.3 kre in
257 1.3 kre (1) printf OK ;;
258 1.3 kre (*) printf BAD ;;
259 1.3 kre esac
260 1.3 kre DONE
261 1.3 kre done
262 1.3 kre
263 1.3 kre # inspired by pkgsrc/pkgtools/cwrappers :: libnbcompat/configure
264 1.3 kre # failure with (broken) sh LINENO core .. avoid recurrence
265 1.3 kre # This test would have failed.
266 1.3 kre cat <<- 'DONE' | atf_check -s exit:0 -o inline:'/tmp\n' ${TEST_SH}
267 1.3 kre dn=/tmp/foo
268 1.3 kre
269 1.3 kre D=`dirname -- "${dn}" ||
270 1.3 kre expr X"${dn}" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
271 1.3 kre X"${dn}" : 'X\(//\)[^/]' \| \
272 1.3 kre X"${dn}" : 'X\(//\)$' \| \
273 1.3 kre X"${dn}" : 'X\(/\)' \| . 2>/dev/null ||
274 1.3 kre echo X"${dn}" |
275 1.3 kre sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
276 1.3 kre s//\1/
277 1.3 kre q
278 1.3 kre }
279 1.3 kre /^X\(\/\/\)[^/].*/{
280 1.3 kre s//\1/
281 1.3 kre q
282 1.3 kre }
283 1.3 kre /^X\(\/\/\)$/{
284 1.3 kre s//\1/
285 1.3 kre q
286 1.3 kre }
287 1.3 kre /^X\(\/\).*/{
288 1.3 kre s//\1/
289 1.3 kre q
290 1.3 kre }
291 1.3 kre s/.*/./; q'`
292 1.3 kre
293 1.3 kre echo "${D}"
294 1.3 kre DONE
295 1.3 kre return 0
296 1.1 kre }
297 1.1 kre
298 1.1 kre atf_test_case d_redirects
299 1.1 kre d_redirects_head() {
300 1.1 kre atf_set "descr" "Check parsing of redirect operators"
301 1.1 kre }
302 1.1 kre d_redirects_body() {
303 1.1 kre
304 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
305 1.1 kre '>/dev/null'
306 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
307 1.1 kre '</dev/null'
308 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
309 1.1 kre '>>/dev/null'
310 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
311 1.1 kre '<>/dev/null'
312 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
313 1.1 kre '</dev/null>/dev/null'
314 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
315 1.1 kre '>|/dev/null'
316 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
317 1.1 kre '>/dev/null>/dev/null>/dev/null'
318 1.1 kre
319 1.1 kre atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
320 1.1 kre 'echo hello >/dev/null'
321 1.1 kre atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
322 1.1 kre 'echo >/dev/null hello'
323 1.1 kre atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
324 1.1 kre '>/dev/null echo hello'
325 1.1 kre atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
326 1.1 kre 'echo hello >/dev/null world'
327 1.1 kre atf-check -s exit:0 -o 'inline:hello world\n' -e empty ${TEST_SH} -c \
328 1.1 kre 'echo hello </dev/null world'
329 1.1 kre
330 1.1 kre atf-check -s exit:0 -o 'inline:hello\n' -e empty ${TEST_SH} -c \
331 1.1 kre 'echo hello </dev/null'
332 1.1 kre atf-check -s exit:0 -o 'inline:hello\n' -e empty ${TEST_SH} -c \
333 1.1 kre 'echo hello 3</dev/null'
334 1.1 kre atf-check -s exit:0 -o 'inline:hello 3\n' -e empty ${TEST_SH} -c \
335 1.1 kre 'echo hello 3 </dev/null'
336 1.1 kre atf-check -s exit:0 -o 'inline:hello 3\n' -e empty ${TEST_SH} -c \
337 1.1 kre 'echo hello \3</dev/null'
338 1.1 kre atf-check -s exit:0 -o 'inline:hello\n' -e empty ${TEST_SH} -c \
339 1.1 kre 'echo hello</dev/null'
340 1.1 kre atf-check -s exit:0 -o 'inline:3\n' -e empty ${TEST_SH} -c \
341 1.1 kre 'hello=3; echo ${hello}</dev/null'
342 1.1 kre
343 1.1 kre atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
344 1.1 kre '2>&1'
345 1.1 kre atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
346 1.1 kre '2>& 1'
347 1.1 kre atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
348 1.1 kre 'FD=1; 2>&"${FD}"'
349 1.1 kre atf-check -s exit:0 -o 'inline:hello\n' -e empty ${TEST_SH} -c \
350 1.1 kre 'FD=1; echo hello 2>&"${FD}" >&2'
351 1.1 kre
352 1.1 kre atf-check -s exit:0 -o empty -e empty ${TEST_SH} -c \
353 1.1 kre '2>&- 3<&- 4>&-'
354 1.1 kre
355 1.1 kre return 0
356 1.1 kre }
357 1.1 kre
358 1.1 kre atf_test_case f_variable_syntax
359 1.1 kre f_variable_syntax_head() {
360 1.1 kre atf_set "descr" "Check that var names of all legal forms work"
361 1.1 kre }
362 1.1 kre f_variable_syntax_body() {
363 1.1 kre # don't test _ as a variable, it can be "unusual"
364 1.1 kre for vname in a ab _a _9 a123 a_1_2_3 __ ___ ____ __1__ _0 \
365 1.1 kre A AA AAA AaBb _A_a A_a_ a1_ abc_123 ab_12_cd_ef_34_99 \
366 1.1 kre abcdefghijklmnopqrstuvwzyz ABCDEFGHIJKLMNOPQRSTUVWXYZ_ \
367 1.1 kre A_VERY_LONG_VARIABLE_NAME_that_is_probably_longer_than_most_used_in_the_average_shell_script_already_about_100_chars_in_this_one_but_there_is_not_supposed_to_be_any_limit_on_the_length_at_all xyzzy \
368 1.1 kre _____________________________________________________________
369 1.1 kre do
370 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
371 1.1 kre "unset ${vname}"
372 1.1 kre atf_check -s exit:0 -o match:OK -e empty ${TEST_SH} -c \
373 1.1 kre "unset ${vname}; printf %s \${${vname}-OK}"
374 1.1 kre atf_check -s exit:0 -o match:GOOD -e empty ${TEST_SH} -c \
375 1.1 kre "${vname}=GOOD; printf %s \${${vname}-OK}"
376 1.1 kre atf_check -s exit:0 -o match:GOOD -e empty ${TEST_SH} -c \
377 1.1 kre "${vname}=GOOD; printf %s \$${vname}"
378 1.1 kre atf_check -s exit:0 -o match:GOOD -e empty ${TEST_SH} -c \
379 1.1 kre "unset ${vname};${vname}=GOOD;printf %s \${${vname}-OK}"
380 1.1 kre atf_check -s exit:0 -o match:OK -e empty ${TEST_SH} -c \
381 1.1 kre "${vname}=GOOD;unset ${vname};printf %s \${${vname}-OK}"
382 1.1 kre atf_check -s exit:0 -o match:GOOD -e empty ${TEST_SH} -c \
383 1.1 kre "${vname}=GOOD; unset ${vname}x; printf %s \$${vname}"
384 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
385 1.1 kre "unset ${vname}x; ${vname}=GOOD; printf %s \$${vname}x"
386 1.1 kre done
387 1.1 kre
388 1.1 kre # don't test '.' in var names, some shells permit that (in ${} anyway)
389 1.1 kre # this test also cannot check for embedded - + ? = : % or #
390 1.1 kre for vname in ,x -p +h :def 0_1 'x*x' '()' '"' "'" 'a b c' '?!' ';'
391 1.1 kre do
392 1.1 kre atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
393 1.1 kre "echo \${${vname}}"
394 1.1 kre done
395 1.1 kre
396 1.1 kre for vname in ,x -p +h :def 0_1 'x*x' '()' '"' "'" 'a b c' x,y,z '?!' \
397 1.1 kre ';' a-b a+b 'a?b' 'a:b' 'a%b' 'a#b' 0 1 99 @ '*' '!' '?'
398 1.1 kre do
399 1.1 kre # failure modes will differ, but they should all fail somehow
400 1.1 kre atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
401 1.1 kre "${vname}="
402 1.1 kre done
403 1.1 kre
404 1.1 kre }
405 1.1 kre
406 1.1 kre atf_test_case g_var_assign
407 1.1 kre g_var_assign_head() {
408 1.1 kre atf_set "descr" "Check var assignments "
409 1.1 kre }
410 1.1 kre g_var_assign_body() {
411 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
412 1.1 kre 'a=b'
413 1.1 kre atf_check -s not-exit:0 -e not-empty -o empty ${TEST_SH} -c \
414 1.1 kre '\a=b'
415 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
416 1.1 kre 'a=b c=d'
417 1.1 kre atf_check -s exit:0 -e empty -o 'inline:e=f\n' ${TEST_SH} -c \
418 1.1 kre 'a=b c=d echo e=f'
419 1.1 kre atf_check -s exit:0 -e empty -o 'inline:e=f\n' ${TEST_SH} -c \
420 1.1 kre 'a=b 2>/dev/null c=d </dev/null echo e=f'
421 1.1 kre
422 1.1 kre # We need to make sure that we do not accidentally
423 1.1 kre # find a command called 'a=b' ...
424 1.1 kre
425 1.1 kre for d in /foo /foo/bar /not-dir /no/such/directory '/!!!' \
426 1.1 kre '/-/--/#' '/"/""/"""' -
427 1.1 kre do
428 1.1 kre test -d "${d}" || break
429 1.1 kre done
430 1.1 kre test "${#d}" -gt 1 || atf-skip 'Wacky directories seem to exist!'
431 1.1 kre
432 1.1 kre atf_check -s exit:0 -e empty -o empty ${TEST_SH} -c \
433 1.1 kre "PATH='${d}';"'a=\b'
434 1.1 kre atf_check -s not-exit:0 -e not-empty -o empty ${TEST_SH} -c \
435 1.1 kre "PATH='${d}';"'a\=b'
436 1.1 kre atf_check -s not-exit:0 -e not-empty -o empty ${TEST_SH} -c \
437 1.1 kre "PATH='${d}';"'\a=b'
438 1.1 kre atf_check -s not-exit:0 -e not-empty -o empty ${TEST_SH} -c \
439 1.1 kre "PATH='${d}';"'X=; c=d ${X} a=b'
440 1.1 kre }
441 1.1 kre
442 1.1 kre atf_test_case i_pipelines
443 1.1 kre i_pipelines_head() {
444 1.1 kre atf_set "descr" "Check pipelines"
445 1.1 kre }
446 1.1 kre i_pipelines_body() {
447 1.1 kre
448 1.1 kre cmd='printf "%s\n" foo'
449 1.1 kre for n in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
450 1.1 kre do
451 1.1 kre atf_check -s exit:0 -o inline:'foo\n' -e empty ${TEST_SH} -c \
452 1.1 kre "${cmd}"
453 1.1 kre cmd="${cmd} | cat"
454 1.1 kre done
455 1.1 kre
456 1.1 kre cmd='printf "%s\n" foo'
457 1.1 kre for n in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
458 1.1 kre do
459 1.1 kre atf_check -s exit:0 -o inline:'foo\n' -e empty ${TEST_SH} -c \
460 1.1 kre "${cmd}"
461 1.1 kre cmd="${cmd} |
462 1.1 kre cat"
463 1.1 kre done
464 1.1 kre
465 1.1 kre cmd='printf "%s\n" foo'
466 1.1 kre for n in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
467 1.1 kre do
468 1.1 kre atf_check -s exit:0 -o inline:'foo\n' -e empty ${TEST_SH} -c \
469 1.1 kre "${cmd}"
470 1.1 kre cmd="${cmd} |
471 1.1 kre
472 1.1 kre
473 1.1 kre
474 1.1 kre
475 1.1 kre cat"
476 1.1 kre done
477 1.1 kre
478 1.1 kre cmd='! printf "%s\n" foo'
479 1.1 kre for n in 1 2 3 4 5 6 7 8 9 10
480 1.1 kre do
481 1.1 kre atf_check -s exit:1 -o inline:'foo\n' -e empty ${TEST_SH} -c \
482 1.1 kre "${cmd}"
483 1.1 kre cmd="${cmd} | cat"
484 1.1 kre done
485 1.1 kre
486 1.1 kre cmd='exec 4>&2 3<&0; printf "%s\n" foo'
487 1.1 kre for n in 1 2 3
488 1.1 kre do
489 1.1 kre pfx=
490 1.1 kre for xtra in 'x=y' 'a=b' '6>&1' '5<&3'
491 1.1 kre do
492 1.1 kre atf_check -s exit:0 -o inline:'foo\n' -e empty ${TEST_SH} -c \
493 1.1 kre "${cmd} | ${xtra} cat"
494 1.1 kre
495 1.1 kre atf_check -s exit:0 -o inline:'foo\n' -e empty ${TEST_SH} -c \
496 1.1 kre "${cmd} | ${pfx} cat"
497 1.1 kre
498 1.1 kre pfx="${pfx} ${xtra}"
499 1.1 kre done
500 1.1 kre cmd="${cmd} | ${pfx} cat"
501 1.1 kre done
502 1.1 kre
503 1.1 kre # pipelines are not required to contain commands ...
504 1.1 kre # they don't do anything useful (at all) but the syntax is legal
505 1.1 kre base='4>&2'; cmd="${base}"
506 1.1 kre for pipe in 'a=b' '3<&0' '>>/dev/null' 'a= b= c=' '${x}' 'cat'
507 1.1 kre do
508 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
509 1.1 kre "${base} | ${pipe}"
510 1.1 kre
511 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
512 1.1 kre "${cmd} | ${pipe}"
513 1.1 kre
514 1.1 kre cmd="${cmd} | ${pipe}"
515 1.1 kre done
516 1.1 kre
517 1.1 kre # but the command cannot be empty, or a reserved word used improperly
518 1.1 kre base='printf "%s\n" foo'; cmd="${base}"
519 1.1 kre for pipe in '' do done then else fi esac
520 1.1 kre do
521 1.1 kre atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
522 1.1 kre "${base} | ${pipe}"
523 1.1 kre
524 1.1 kre atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
525 1.1 kre "${pipe} | ${base}"
526 1.1 kre
527 1.1 kre atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
528 1.1 kre "${cmd} | ${pipe}"
529 1.1 kre
530 1.1 kre cmd="${cmd} | ${pipe}"
531 1.1 kre done
532 1.1 kre }
533 1.1 kre
534 1.1 kre atf_test_case j_and_or_lists
535 1.1 kre j_and_or_lists_head() {
536 1.1 kre atf_set "descr" "Check && and || command lists"
537 1.1 kre }
538 1.1 kre j_and_or_lists_body() {
539 1.1 kre and=true
540 1.1 kre or=false
541 1.1 kre and_or=false
542 1.1 kre for i in 1 2 3 4 5 6 7 8 9 10
543 1.1 kre do
544 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
545 1.1 kre "${and}"
546 1.1 kre
547 1.1 kre atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
548 1.1 kre "${or}"
549 1.1 kre
550 1.1 kre atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
551 1.1 kre "${and_or}"
552 1.1 kre
553 1.1 kre and="${and} && true"
554 1.1 kre or="${or} || false"
555 1.1 kre and_or="${and_or} || true && false"
556 1.1 kre done
557 1.1 kre
558 1.1 kre atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
559 1.1 kre 'true &&'
560 1.1 kre atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
561 1.1 kre '&& true'
562 1.1 kre atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
563 1.1 kre '|| true'
564 1.1 kre atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
565 1.1 kre 'true ||'
566 1.1 kre atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
567 1.1 kre 'true || && false'
568 1.1 kre atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
569 1.1 kre 'false || && true'
570 1.1 kre
571 1.1 kre cmd='printf "%s" foo | cat | cat>/dev/null'
572 1.1 kre line="${cmd}"
573 1.1 kre for i in 1 2 3 4
574 1.1 kre do
575 1.1 kre line="${line} && ! ${cmd} || ${cmd}"
576 1.1 kre
577 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
578 1.1 kre "${line}"
579 1.1 kre done
580 1.1 kre
581 1.1 kre }
582 1.1 kre
583 1.1 kre atf_test_case k_lists
584 1.1 kre k_lists_head() {
585 1.1 kre atf_set "descr" "Check ; command lists"
586 1.1 kre }
587 1.1 kre k_lists_body() {
588 1.1 kre line=
589 1.1 kre for N in 1 2 3 4
590 1.1 kre do
591 1.1 kre for cmd in \
592 1.1 kre true false : 'cat</dev/null>/dev/null' x=3 'exec 4>&-'
593 1.1 kre do
594 1.1 kre line="${line}${line:+;}${cmd}"
595 1.1 kre atf_check -s exit:0 -o 'inline:hello\nworld\n' \
596 1.1 kre -e empty ${TEST_SH} -c \
597 1.1 kre "echo hello; ${line}; echo world"
598 1.1 kre atf_check -s exit:0 -o 'inline:hello\nworld\n' \
599 1.1 kre -e empty ${TEST_SH} -c \
600 1.1 kre "echo hello; ${line}; echo world;"
601 1.1 kre done
602 1.1 kre done
603 1.1 kre
604 1.1 kre for cmd in ';' ';;' 'false ;; true' 'false; ;true' '; true'
605 1.1 kre do
606 1.1 kre atf_check -s not-exit:0 -o ignore -e not-empty \
607 1.1 kre ${TEST_SH} -c "${cmd}"
608 1.1 kre done
609 1.1 kre }
610 1.1 kre
611 1.1 kre atf_test_case l_async_lists
612 1.1 kre l_async_lists_head() {
613 1.1 kre atf_set "descr" "Check & command lists"
614 1.1 kre }
615 1.1 kre l_async_lists_body() {
616 1.1 kre line=
617 1.1 kre for N in 1 2 3 4
618 1.1 kre do
619 1.1 kre for cmd in \
620 1.1 kre true false : 'cat</dev/null>/dev/null' x=3 'exec 4>&-'
621 1.1 kre do
622 1.1 kre line="${line:+${line}&}${cmd}"
623 1.1 kre atf_check -s exit:0 -o 'inline:hello\nworld\n' \
624 1.1 kre -e empty ${TEST_SH} -c \
625 1.1 kre "echo hello; ${line}& echo world"
626 1.1 kre atf_check -s exit:0 -o 'inline:hello\nworld\n' \
627 1.1 kre -e empty ${TEST_SH} -c \
628 1.1 kre "echo hello; ${line}& echo world"
629 1.1 kre done
630 1.1 kre done
631 1.1 kre
632 1.1 kre for cmd in '&' ';&' '&;' '& true' 'false& &true'
633 1.1 kre do
634 1.1 kre atf_check -s not-exit:0 -o ignore -e not-empty \
635 1.1 kre ${TEST_SH} -c "${cmd}"
636 1.1 kre done
637 1.1 kre }
638 1.1 kre
639 1.1 kre atf_test_case m_compound_lists
640 1.1 kre m_compound_lists_head() {
641 1.1 kre atf_set "descr" "Check subshells () and { ;} command grouping"
642 1.1 kre }
643 1.1 kre m_compound_lists_body() {
644 1.1 kre # Note: (( is an unspecified (reserved) operator, don't use it...
645 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
646 1.1 kre '( true )'
647 1.1 kre atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
648 1.1 kre '( false )'
649 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
650 1.1 kre '( (:) )'
651 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
652 1.1 kre '( ( true ))'
653 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
654 1.1 kre '( ( ( ( ( true )))))'
655 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
656 1.1 kre '( ( ( ( (true);:));true))'
657 1.1 kre
658 1.1 kre atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
659 1.1 kre '()'
660 1.1 kre atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
661 1.1 kre '( )'
662 1.1 kre
663 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
664 1.1 kre '{ true; }'
665 1.1 kre atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
666 1.1 kre '{ false; }'
667 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
668 1.1 kre '{ { :; };}'
669 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
670 1.1 kre '{ { { { { :;};};};};}'
671 1.1 kre
672 1.1 kre atf_check -s exit:0 -o 'inline:}\n' -e empty ${TEST_SH} -c \
673 1.1 kre '{ echo } ; }'
674 1.1 kre atf_check -s exit:0 -o 'inline:{\n' -e empty ${TEST_SH} -c \
675 1.1 kre '{ echo { ; }'
676 1.1 kre }
677 1.1 kre
678 1.1 kre atf_test_case q_for_loop
679 1.1 kre q_for_loop_head() {
680 1.1 kre atf_set "descr" "Check for loop parsing"
681 1.1 kre }
682 1.1 kre q_for_loop_body() {
683 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
684 1.1 kre 'for x; do : ; done'
685 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
686 1.1 kre 'for x in ; do : ; done'
687 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
688 1.1 kre 'for x in a b c ; do : ; done'
689 1.1 kre
690 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
691 1.1 kre 'for x in in;do : ; done'
692 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
693 1.1 kre 'for x in for;do : ; done'
694 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
695 1.1 kre 'for x in do;do : ; done'
696 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
697 1.1 kre 'for for in in;do :;done'
698 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
699 1.1 kre 'for for in for;do :; done'
700 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
701 1.1 kre 'for for in do;do : ;done'
702 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
703 1.1 kre 'for in in in;do : ; done'
704 1.2 kre atf_check -s exit:0 -o 'inline:do\nin\ndo\n' -e empty ${TEST_SH} -c \
705 1.2 kre 'for in in in do in;do case $in in in)echo do;;do)echo in;;esac; done'
706 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
707 1.1 kre 'for in in for;do : ; done'
708 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
709 1.1 kre 'for in in do;do : ; done'
710 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
711 1.1 kre 'for do in in;do : ; done'
712 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
713 1.1 kre 'for do in for;do : ; done'
714 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
715 1.1 kre 'for do in do;do : ; done'
716 1.1 kre atf_check -s exit:0 -o 'inline:dodo\n' -e empty ${TEST_SH} -c \
717 1.1 kre 'for do in do;do echo ${do}do ; done'
718 1.1 kre }
719 1.1 kre
720 1.1 kre atf_test_case r_case
721 1.1 kre r_case_head() {
722 1.1 kre atf_set "descr" "Check case statement parsing"
723 1.1 kre }
724 1.1 kre r_case_body() {
725 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
726 1.1 kre 'case x in esac'
727 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
728 1.1 kre 'case x in x) esac'
729 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
730 1.1 kre 'case x in (x) esac'
731 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
732 1.1 kre 'case x in x) ;; esac'
733 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
734 1.1 kre 'case x in (x) ;; esac'
735 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
736 1.1 kre 'case x in x|y) ;; esac'
737 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
738 1.1 kre 'case x in (x|y) ;; esac'
739 1.1 kre
740 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
741 1.1 kre 'case x in x|esac) ;; esac'
742 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
743 1.1 kre 'case x in x|esac|y) ;; esac'
744 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
745 1.1 kre 'case x in (x|esac) ;; esac'
746 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
747 1.1 kre 'case x in (x|esac|y) ;; esac'
748 1.1 kre
749 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
750 1.1 kre 'case x in in) esac'
751 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
752 1.1 kre 'case x in in) ;; esac'
753 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
754 1.1 kre 'case x in x|in) ;; esac'
755 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
756 1.1 kre 'case x in x|in|y) ;; esac'
757 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
758 1.1 kre 'case x in (x|in) ;; esac'
759 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
760 1.1 kre 'case x in (in|x) ;; esac'
761 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
762 1.1 kre 'case x in (x|in|y) ;; esac'
763 1.1 kre
764 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
765 1.1 kre 'case case in case) esac'
766 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
767 1.1 kre 'case in in in) esac'
768 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
769 1.1 kre 'case esac in (in) esac'
770 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
771 1.1 kre 'case in in esac|cat'
772 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
773 1.1 kre 'case esac in esac|cat'
774 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
775 1.1 kre 'case in in esac|case x in u) echo foo;; esac'
776 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
777 1.1 kre 'case esac in esac|case x in u) echo foo;; esac'
778 1.1 kre atf_check -s exit:0 -o 'inline:foo\n' -e empty ${TEST_SH} -c \
779 1.1 kre 'case in in esac|case x in x) echo foo;; esac'
780 1.1 kre
781 1.1 kre atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
782 1.1 kre 'case in in (esac|cat'
783 1.1 kre
784 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
785 1.1 kre 'case x in x );;esac'
786 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
787 1.1 kre 'case x in ( x );;esac'
788 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
789 1.1 kre 'case x in x | y );;esac'
790 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
791 1.1 kre 'case x in ( x | y );;esac'
792 1.1 kre
793 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
794 1.1 kre 'case x
795 1.1 kre in
796 1.1 kre ( x | y )
797 1.1 kre
798 1.1 kre ;;
799 1.1 kre
800 1.1 kre
801 1.1 kre esac
802 1.1 kre '
803 1.1 kre }
804 1.1 kre
805 1.1 kre atf_test_case s_if
806 1.1 kre s_if_head() {
807 1.1 kre atf_set "descr" "Check if statement parsing"
808 1.1 kre }
809 1.1 kre s_if_body() {
810 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
811 1.1 kre 'if :; then :; fi'
812 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
813 1.1 kre 'if :; then :; else :; fi'
814 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
815 1.1 kre 'if :; then :; elif :; then :; else :; fi'
816 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
817 1.1 kre 'if :; then :; elif :; then :; elif :; then :; else :; fi'
818 1.1 kre
819 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
820 1.1 kre 'if :; then : else :; fi'
821 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
822 1.1 kre 'if : then :; then :; fi'
823 1.1 kre
824 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
825 1.1 kre 'if if :;then :;fi then :;fi'
826 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
827 1.1 kre 'if if :;then if :;then :;fi fi;then :;fi'
828 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
829 1.1 kre 'if if :;then :;fi;then :;else if :;then :;fi fi'
830 1.1 kre
831 1.1 kre for a in true false; do
832 1.1 kre for b in true false; do
833 1.1 kre for c in true false; do
834 1.1 kre
835 1.1 kre $a && out=a || {
836 1.1 kre $b && out=b || {
837 1.1 kre $c && out=c || {
838 1.1 kre out=d; };};}
839 1.1 kre
840 1.1 kre atf_check -s exit:0 -e empty \
841 1.1 kre -o "inline:${out}"'\n' \
842 1.1 kre ${TEST_SH} -c \
843 1.1 kre "if $a; then echo a
844 1.1 kre elif $b; then echo b
845 1.1 kre elif $c; then echo c
846 1.1 kre else echo d
847 1.1 kre fi"
848 1.1 kre done
849 1.1 kre done
850 1.1 kre done
851 1.1 kre }
852 1.1 kre
853 1.1 kre atf_test_case t_loops
854 1.1 kre t_loops_head() {
855 1.1 kre atf_set "descr" "Check while/until loop parsing"
856 1.1 kre }
857 1.1 kre t_loops_body() {
858 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
859 1.1 kre 'while false; do :; done'
860 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
861 1.1 kre 'while false; do \done; done'
862 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
863 1.1 kre 'until :; do :; done'
864 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
865 1.1 kre 'until :; do \done; done'
866 1.1 kre
867 1.1 kre atf_check -s exit:0 -o 'inline:x\n1\n' -e empty ${TEST_SH} -c \
868 1.1 kre ':; while (exit) do echo x; false; done; echo $?'
869 1.1 kre atf_check -s exit:0 -o 'inline:x\n0\n' -e empty ${TEST_SH} -c \
870 1.1 kre 'false; until (exit) do echo x; done; echo $?'
871 1.1 kre }
872 1.1 kre
873 1.1 kre atf_test_case u_case_cont
874 1.1 kre u_case_cont_head() {
875 1.1 kre atf_set "descr" "Check case stmt parsing using ;& [optional]"
876 1.1 kre }
877 1.1 kre u_case_cont_body() {
878 1.1 kre
879 1.1 kre ${TEST_SH} -c 'case x in (x) false ;& (y) : ;; esac' 2>/dev/null ||
880 1.1 kre atf_skip ";& case list terminator unsupported in ${TEST_SH}"
881 1.1 kre
882 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
883 1.1 kre 'case x in x) ;& esac'
884 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
885 1.1 kre 'case x in (x) ;& esac'
886 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
887 1.1 kre 'case x in x|y) ;& esac'
888 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
889 1.1 kre 'case x in (x|y) ;& esac'
890 1.1 kre
891 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
892 1.1 kre 'case x in x );&esac'
893 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
894 1.1 kre 'case x in ( x );&esac'
895 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
896 1.1 kre 'case x in x | y );&esac'
897 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
898 1.1 kre 'case x in ( x | y );&esac'
899 1.1 kre
900 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
901 1.1 kre 'case x in x) ;& (y) esac'
902 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
903 1.1 kre 'case x in (x) ;& esac'
904 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
905 1.1 kre 'case x in x|y) ;& esac'
906 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
907 1.1 kre 'case x in (x|y) ;& esac'
908 1.1 kre }
909 1.1 kre
910 1.1 kre atf_test_case x_functions
911 1.1 kre x_functions_head() {
912 1.1 kre atf_set "descr" "Check function definition parsing"
913 1.1 kre }
914 1.1 kre x_functions_body() {
915 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
916 1.1 kre 'func() { :; }'
917 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
918 1.1 kre 'func() { :; }; func'
919 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
920 1.1 kre 'func()(:)'
921 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
922 1.1 kre 'func()if :; then false; else true; fi'
923 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
924 1.1 kre 'func()while false; do :;done'
925 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
926 1.1 kre 'func () for a in b c; do :; done'
927 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
928 1.1 kre 'func() case x in (y) esac'
929 1.1 kre
930 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
931 1.1 kre 'f1() { f2() { :; }; }; f1; f2'
932 1.1 kre
933 1.1 kre # f2 should be not found, but f1 clears $?
934 1.1 kre atf_check -s exit:0 -o empty -e not-empty ${TEST_SH} -c \
935 1.1 kre 'f1() { f2() { :; }; }; f2; f1'
936 1.1 kre
937 1.1 kre atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
938 1.1 kre 'f1() { eval "$1() { :; }"; }; f1 f2; f2'
939 1.1 kre }
940 1.1 kre
941 1.1 kre atf_init_test_cases() {
942 1.1 kre atf_add_test_case a_basic_tokenisation
943 1.1 kre atf_add_test_case b_comments
944 1.1 kre atf_add_test_case c_line_wrapping
945 1.1 kre atf_add_test_case d_redirects
946 1.1 kre atf_add_test_case f_variable_syntax
947 1.1 kre atf_add_test_case g_var_assign
948 1.1 kre atf_add_test_case i_pipelines
949 1.1 kre atf_add_test_case j_and_or_lists
950 1.1 kre atf_add_test_case k_lists
951 1.1 kre atf_add_test_case l_async_lists
952 1.1 kre atf_add_test_case m_compound_lists
953 1.1 kre atf_add_test_case q_for_loop
954 1.1 kre atf_add_test_case r_case
955 1.1 kre atf_add_test_case s_if
956 1.1 kre atf_add_test_case t_loops
957 1.1 kre atf_add_test_case u_case_cont
958 1.1 kre atf_add_test_case x_functions
959 1.1 kre }
960