t_expand.sh revision 1.18 1 # $NetBSD: t_expand.sh,v 1.18 2017/10/06 17:05:05 kre Exp $
2 #
3 # Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
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
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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
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
25 # POSSIBILITY OF SUCH DAMAGE.
26 #
27 # the implementation of "sh" to test
28 : ${TEST_SH:="/bin/sh"}
29
30 #
31 # This file tests the functions in expand.c.
32 #
33
34 delim_argv() {
35 str=
36 while [ $# -gt 0 ]; do
37 if [ -z "${str}" ]; then
38 str=">$1<"
39 else
40 str="${str} >$1<"
41 fi
42 shift
43 done
44 echo ${str}
45 }
46
47 atf_test_case dollar_at
48 dollar_at_head() {
49 atf_set "descr" "Somewhere between 2.0.2 and 3.0 the expansion" \
50 "of the \$@ variable had been broken. Check for" \
51 "this behavior."
52 }
53 dollar_at_body() {
54 # This one should work everywhere.
55 atf_check -s exit:0 -o inline:' EOL\n' -e empty \
56 ${TEST_SH} -c 'echo "" "" | '" sed 's,\$,EOL,'"
57
58 # This code triggered the bug.
59 atf_check -s exit:0 -o inline:' EOL\n' -e empty \
60 ${TEST_SH} -c 'set -- "" ""; echo "$@" | '" sed 's,\$,EOL,'"
61
62 atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
63 'set -- -; shift; n_arg() { echo $#; }; n_arg "$@"'
64 }
65
66 atf_test_case dollar_at_with_text
67 dollar_at_with_text_head() {
68 atf_set "descr" "Test \$@ expansion when it is surrounded by text" \
69 "within the quotes. PR bin/33956."
70 }
71 dollar_at_with_text_body() {
72
73 cat <<'EOF' > h-f1
74
75 delim_argv() {
76 str=
77 while [ $# -gt 0 ]; do
78 if [ -z "${str}" ]; then
79 str=">$1<"
80 else
81 str="${str} >$1<"
82 fi
83 shift
84 done
85 echo "${str}"
86 }
87
88 EOF
89 cat <<'EOF' > h-f2
90
91 delim_argv() {
92 str=
93 while [ $# -gt 0 ]; do
94
95 str="${str}${str:+ }>$1<"
96 shift
97
98 done
99 echo "${str}"
100 }
101
102 EOF
103
104 chmod +x h-f1 h-f2
105
106 for f in 1 2
107 do
108 atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
109 ". ./h-f${f}; "'set -- ; delim_argv "$@"'
110 atf_check -s exit:0 -o inline:'>foobar<\n' -e empty \
111 ${TEST_SH} -c \
112 ". ./h-f${f}; "'set -- ; delim_argv "foo$@bar"'
113 atf_check -s exit:0 -o inline:'>foo bar<\n' -e empty \
114 ${TEST_SH} -c \
115 ". ./h-f${f}; "'set -- ; delim_argv "foo $@ bar"'
116
117 atf_check -s exit:0 -o inline:'>a< >b< >c<\n' -e empty \
118 ${TEST_SH} -c \
119 ". ./h-f${f}; "'set -- a b c; delim_argv "$@"'
120 atf_check -s exit:0 -o inline:'>fooa< >b< >cbar<\n' -e empty \
121 ${TEST_SH} -c \
122 ". ./h-f${f}; "'set -- a b c; delim_argv "foo$@bar"'
123 atf_check -s exit:0 -o inline:'>foo a< >b< >c bar<\n' -e empty \
124 ${TEST_SH} -c \
125 ". ./h-f${f}; "'set -- a b c; delim_argv "foo $@ bar"'
126 done
127 }
128
129 atf_test_case strip
130 strip_head() {
131 atf_set "descr" "Checks that the %% operator works and strips" \
132 "the contents of a variable from the given point" \
133 "to the end"
134 }
135 strip_body() {
136 line='#define bindir "/usr/bin" /* comment */'
137 stripped='#define bindir "/usr/bin" '
138
139 # atf_expect_fail "PR bin/43469" -- now fixed
140 for exp in \
141 '${line%%/\**}' \
142 '${line%%"/*"*}' \
143 '${line%%'"'"'/*'"'"'*}' \
144 '"${line%%/\**}"' \
145 '"${line%%"/*"*}"' \
146 '"${line%%'"'"'/*'"'"'*}"' \
147 '${line%/\**}' \
148 '${line%"/*"*}' \
149 '${line%'"'"'/*'"'"'*}' \
150 '"${line%/\**}"' \
151 '"${line%"/*"*}"' \
152 '"${line%'"'"'/*'"'"'*}"'
153 do
154 atf_check -o inline:":$stripped:\n" -e empty ${TEST_SH} -c \
155 "line='${line}'; echo :${exp}:"
156 done
157 }
158
159 atf_test_case wrap_strip
160 wrap_strip_head() {
161 atf_set "descr" "Checks that the %% operator works and strips" \
162 "the contents of a variable from the given point" \
163 'to the end, and that \ \n sequences do not break it'
164 }
165 wrap_strip_body() {
166 line='#define bindir "/usr/bin" /* comment */'
167 stripped='#define bindir "/usr/bin" '
168
169 for exp in \
170 '${line\
171 %%/\**}' \
172 '${line%%"/\
173 *"*}' \
174 '${line%%'"'"'/*'"'"'\
175 *}' \
176 '"${li\
177 ne%%/\**}"' \
178 '"${line%%"\
179 /*"*}"' \
180 '"${line%\
181 %'"'"'/*'"'"'*}"' \
182 '${line\
183 %\
184 /\*\
185 *\
186 }' \
187 '${line%"/*\
188 "*\
189 }' \
190 '${line\
191 %\
192 '"'"'/*'"'"'*}' \
193 '"$\
194 {li\
195 ne%\
196 '"'"'/*'"'"'*}"'
197 do
198 atf_check -o inline:":$stripped:\n" -e empty ${TEST_SH} -c \
199 "line='${line}'; echo :${exp}:"
200 done
201 }
202
203 atf_test_case tilde
204 tilde_head() {
205 atf_set "descr" "Checks that the ~ expansions work"
206 }
207 tilde_body() {
208 for HOME in '' / /home/foo \
209 /a/very/long/home/directory/path/that/might/push/the/tilde/expansion/code/beyond/what/it/would/normally/ever/see/on/any/sane/system/and/perhaps/expose/some/bugs
210 do
211 export HOME
212
213 atf_check -s exit:0 -e empty \
214 -o inline:'HOME\t'"${HOME}"'
215 ~\t'"${HOME}"'
216 ~/foobar\t'"${HOME}"'/foobar
217 "$V"\t'"${HOME}"'
218 "$X"\t~
219 "$Y"\t'"${HOME}"':'"${HOME}"'
220 "$YY"\t'"${HOME}"'/foo:'"${HOME}"'/bar
221 "$Z"\t'"${HOME}"'/~
222 ${U:-~}\t'"${HOME}"'
223 $V\t'"${HOME}"'
224 $X\t~
225 $Y\t'"${HOME}"':'"${HOME}"'
226 $YY\t'"${HOME}"'/foo:'"${HOME}"'/bar
227 $Z\t'"${HOME}"'/~
228 ${U:=~}\t'"${HOME}"'
229 ${UU:=~:~}\t'"${HOME}"':'"${HOME}"'
230 ${UUU:=~/:~}\t'"${HOME}"'/:'"${HOME}"'
231 ${U4:=~/:~/}\t'"${HOME}"'/:'"${HOME}"'/\n' \
232 ${TEST_SH} -s <<- \EOF
233 unset -v U UU UUU U4
234 V=~
235 X="~"
236 Y=~:~ YY=~/foo:~/bar
237 Z=~/~
238 printf '%s\t%s\n' \
239 'HOME' "${HOME}" \
240 '~' ~ \
241 '~/foobar' ~/foobar \
242 '"$V"' "$V" \
243 '"$X"' "$X" \
244 '"$Y"' "$Y" \
245 '"$YY"' "$YY" \
246 '"$Z"' "$Z" \
247 '${U:-~}' ''${U:-~} \
248 '$V' ''$V \
249 '$X' ''$X \
250 '$Y' ''$Y \
251 '$YY' ''$YY \
252 '$Z' ''$Z \
253 '${U:=~}' ''${U:=~} \
254 '${UU:=~:~}' ''${UU:=~:~} \
255 '${UUU:=~/:~}' ''${UUU:=~/:~} \
256 '${U4:=~/:~/}' ''${U4:=~/:~/}
257 EOF
258 done
259
260 # Testing ~user is harder, so, perhaps later...
261 }
262
263 atf_test_case varpattern_backslashes
264 varpattern_backslashes_head() {
265 atf_set "descr" "Tests that protecting wildcards with backslashes" \
266 "works in variable patterns."
267 }
268 varpattern_backslashes_body() {
269 line='/foo/bar/*/baz'
270 stripped='/foo/bar/'
271 atf_check -o inline:'/foo/bar/\n' -e empty ${TEST_SH} -c \
272 'line="/foo/bar/*/baz"; echo ${line%%\**}'
273 }
274
275 atf_test_case arithmetic
276 arithmetic_head() {
277 atf_set "descr" "POSIX requires shell arithmetic to use signed" \
278 "long or a wider type. We use intmax_t, so at" \
279 "least 64 bits should be available. Make sure" \
280 "this is true."
281 }
282 arithmetic_body() {
283
284 atf_check -o inline:'3' -e empty ${TEST_SH} -c \
285 'printf %s $((1 + 2))'
286 atf_check -o inline:'2147483647' -e empty ${TEST_SH} -c \
287 'printf %s $((0x7fffffff))'
288 atf_check -o inline:'9223372036854775807' -e empty ${TEST_SH} -c \
289 'printf %s $(((1 << 63) - 1))'
290 }
291
292 atf_test_case iteration_on_null_parameter
293 iteration_on_null_parameter_head() {
294 atf_set "descr" "Check iteration of \$@ in for loop when set to null;" \
295 "the error \"sh: @: parameter not set\" is incorrect." \
296 "PR bin/48202."
297 }
298 iteration_on_null_parameter_body() {
299 atf_check -o empty -e empty ${TEST_SH} -c \
300 'N=; set -- ${N}; for X; do echo "[$X]"; done'
301 }
302
303 atf_test_case iteration_on_quoted_null_parameter
304 iteration_on_quoted_null_parameter_head() {
305 atf_set "descr" \
306 'Check iteration of "$@" in for loop when set to null;'
307 }
308 iteration_on_quoted_null_parameter_body() {
309 atf_check -o inline:'[]\n' -e empty ${TEST_SH} -c \
310 'N=; set -- "${N}"; for X; do echo "[$X]"; done'
311 }
312
313 atf_test_case iteration_on_null_or_null_parameter
314 iteration_on_null_or_null_parameter_head() {
315 atf_set "descr" \
316 'Check expansion of null parameter as default for another null'
317 }
318 iteration_on_null_or_null_parameter_body() {
319 atf_check -o empty -e empty ${TEST_SH} -c \
320 'N=; E=; set -- ${N:-${E}}; for X; do echo "[$X]"; done'
321 }
322
323 atf_test_case iteration_on_null_or_missing_parameter
324 iteration_on_null_or_missing_parameter_head() {
325 atf_set "descr" \
326 'Check expansion of missing parameter as default for another null'
327 }
328 iteration_on_null_or_missing_parameter_body() {
329 # atf_expect_fail 'PR bin/50834'
330 atf_check -o empty -e empty ${TEST_SH} -c \
331 'N=; set -- ${N:-}; for X; do echo "[$X]"; done'
332 }
333
334 ####### The remaining tests use the following helper functions ...
335
336 nl='
337 '
338 reset()
339 {
340 TEST_NUM=0
341 TEST_FAILURES=''
342 TEST_FAIL_COUNT=0
343 TEST_ID="$1"
344 }
345
346 check()
347 {
348 fail=false
349 TEMP_FILE=$( mktemp OUT.XXXXXX )
350 TEST_NUM=$(( $TEST_NUM + 1 ))
351 MSG=
352
353 # our local shell (ATF_SHELL) better do quoting correctly...
354 # some of the tests expect us to expand $nl internally...
355 CMD="$1"
356
357 result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" )"
358 STATUS=$?
359
360 if [ "${STATUS}" -ne "$3" ]; then
361 MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
362 MSG="${MSG} expected exit code $3, got ${STATUS}"
363
364 # don't actually fail just because of wrong exit code
365 # unless we either expected, or received "good"
366 # or something else is detected as incorrect as well.
367 case "$3/${STATUS}" in
368 (*/0|0/*) fail=true;;
369 esac
370 fi
371
372 if [ "$3" -eq 0 ]; then
373 if [ -s "${TEMP_FILE}" ]; then
374 MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
375 MSG="${MSG} Messages produced on stderr unexpected..."
376 MSG="${MSG}${nl}$( cat "${TEMP_FILE}" )"
377 fail=true
378 fi
379 else
380 if ! [ -s "${TEMP_FILE}" ]; then
381 MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
382 MSG="${MSG} Expected messages on stderr,"
383 MSG="${MSG} nothing produced"
384 fail=true
385 fi
386 fi
387 rm -f "${TEMP_FILE}"
388
389 # Remove newlines (use local shell for this)
390 oifs="$IFS"
391 IFS="$nl"
392 result="$(echo $result)"
393 IFS="$oifs"
394 if [ "$2" != "$result" ]
395 then
396 MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
397 MSG="${MSG} Expected output '$2', received '$result'"
398 fail=true
399 fi
400
401 if $fail
402 then
403 MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
404 MSG="${MSG} Full command: <<${CMD}>>"
405 fi
406
407 $fail && test -n "$TEST_ID" && {
408 TEST_FAILURES="${TEST_FAILURES}${TEST_FAILURES:+${nl}}"
409 TEST_FAILURES="${TEST_FAILURES}${TEST_ID}[$TEST_NUM]:"
410 TEST_FAILURES="${TEST_FAILURES} Test of '$1' failed.";
411 TEST_FAILURES="${TEST_FAILURES}${nl}${MSG}"
412 TEST_FAIL_COUNT=$(( $TEST_FAIL_COUNT + 1 ))
413 return 0
414 }
415 $fail && atf_fail "Test[$TEST_NUM] failed: $(
416 # ATF does not like newlines in messages, so change them...
417 printf '%s' "${MSG}" | tr '\n' ';'
418 )"
419 return 0
420 }
421
422 results()
423 {
424 test -n "$1" && atf_expect_fail "$1"
425
426 test -z "${TEST_ID}" && return 0
427 test -z "${TEST_FAILURES}" && return 0
428
429 echo >&2 "=========================================="
430 echo >&2 "While testing '${TEST_ID}'"
431 echo >&2 " - - - - - - - - - - - - - - - - -"
432 echo >&2 "${TEST_FAILURES}"
433
434 atf_fail \
435 "Test ${TEST_ID}: $TEST_FAIL_COUNT (of $TEST_NUM) subtests failed - see stderr"
436 }
437
438 ####### End helpers
439
440 atf_test_case shell_params
441 shell_params_head() {
442 atf_set "descr" "Test correct operation of the numeric parameters"
443 }
444 shell_params_body() {
445 atf_require_prog mktemp
446
447 reset shell_params
448
449 check 'set -- a b c; echo "$#: $1 $2 $3"' '3: a b c' 0
450 check 'set -- a b c d e f g h i j k l m; echo "$#: ${1}0 ${10} $10"' \
451 '13: a0 j a0' 0
452 check 'x="$0"; set -- a b; y="$0";
453 [ "x${x}y" = "x${y}y" ] && echo OK || echo x="$x" y="$y"' \
454 'OK' 0
455 check "${TEST_SH} -c 'echo 0=\$0 1=\$1 2=\$2' a b c" '0=a 1=b 2=c' 0
456
457 echo 'echo 0="$0" 1="$1" 2="$2"' > helper.sh
458 check "${TEST_SH} helper.sh a b c" '0=helper.sh 1=a 2=b' 0
459
460 check 'set -- a bb ccc dddd eeeee ffffff ggggggg hhhhhhhh \
461 iiiiiiiii jjjjjjjjjj kkkkkkkkkkk
462 echo "${#}: ${#1} ${#2} ${#3} ${#4} ... ${#9} ${#10} ${#11}"' \
463 '11: 1 2 3 4 ... 9 10 11' 0
464
465 check 'set -- a b c; echo "$#: ${1-A} ${2-B} ${3-C} ${4-D} ${5-E}"' \
466 '3: a b c D E' 0
467 check 'set -- a "" c "" e
468 echo "$#: ${1:-A} ${2:-B} ${3:-C} ${4:-D} ${5:-E}"' \
469 '5: a B c D e' 0
470 check 'set -- a "" c "" e
471 echo "$#: ${1:+A} ${2:+B} ${3:+C} ${4:+D} ${5:+E}"' \
472 '5: A C E' 0
473 check 'set -- "abab*cbb"
474 echo "${1} ${1#a} ${1%b} ${1##ab} ${1%%b} ${1#*\*} ${1%\**}"' \
475 'abab*cbb bab*cbb abab*cb ab*cbb abab*cb cbb abab' 0
476 check 'set -- "abab?cbb"
477 echo "${1}:${1#*a}+${1%b*}-${1##*a}_${1%%b*}%${1#[ab]}=${1%?*}/${1%\?*}"' \
478 'abab?cbb:bab?cbb+abab?cb-b?cbb_a%bab?cbb=abab?cb/abab' 0
479 check 'set -- a "" c "" e; echo "${2:=b}"' '' 1
480
481 check 'set -- a b c d; echo ${4294967297}' '' 0 # result 'a' => ${1}
482 check 'set -- a b c; echo ${01}' 'a' 0
483 check "${TEST_SH} -c 'echo 0=\${00} 1=\${01} 2=\${02}' a b c" \
484 '0=a 1=b 2=c' 0
485
486 # by special request, for PaulG... (${0...} is not octal!)
487
488 # Posix XCU 2.5.1 (Issue 7 TC2 pg 2349 lines 74835..6):
489 # The digits denoting the positional parameters shall always
490 # be interpreted as a decimal value, even if there is a leading zero.
491
492 check \
493 'set -- a b c d e f g h i j k l m; echo "$#: ${08} ${010} ${011}"' \
494 '13: h j k' 0
495
496 results
497 }
498
499 atf_test_case var_with_embedded_cmdsub
500 var_with_embedded_cmdsub_head() {
501 atf_set "descr" "Test expansion of vars with embedded cmdsub"
502 }
503 var_with_embedded_cmdsub_body() {
504
505 reset var_with_embedded_cmdsub
506
507 check 'unset x; echo ${x-$(echo a)}$(echo b)' 'ab' 0 #1
508 check 'unset x; echo ${x:-$(echo a)}$(echo b)' 'ab' 0 #2
509 check 'x=""; echo ${x-$(echo a)}$(echo b)' 'b' 0 #3
510 check 'x=""; echo ${x:-$(echo a)}$(echo b)' 'ab' 0 #4
511 check 'x=c; echo ${x-$(echo a)}$(echo b)' 'cb' 0 #5
512 check 'x=c; echo ${x:-$(echo a)}$(echo b)' 'cb' 0 #6
513
514 check 'unset x; echo ${x+$(echo a)}$(echo b)' 'b' 0 #7
515 check 'unset x; echo ${x:+$(echo a)}$(echo b)' 'b' 0 #8
516 check 'x=""; echo ${x+$(echo a)}$(echo b)' 'ab' 0 #9
517 check 'x=""; echo ${x:+$(echo a)}$(echo b)' 'b' 0 #10
518 check 'x=c; echo ${x+$(echo a)}$(echo b)' 'ab' 0 #11
519 check 'x=c; echo ${x:+$(echo a)}$(echo b)' 'ab' 0 #12
520
521 check 'unset x; echo ${x=$(echo a)}$(echo b)' 'ab' 0 #13
522 check 'unset x; echo ${x:=$(echo a)}$(echo b)' 'ab' 0 #14
523 check 'x=""; echo ${x=$(echo a)}$(echo b)' 'b' 0 #15
524 check 'x=""; echo ${x:=$(echo a)}$(echo b)' 'ab' 0 #16
525 check 'x=c; echo ${x=$(echo a)}$(echo b)' 'cb' 0 #17
526 check 'x=c; echo ${x:=$(echo a)}$(echo b)' 'cb' 0 #18
527
528 check 'unset x; echo ${x?$(echo a)}$(echo b)' '' 2 #19
529 check 'unset x; echo ${x:?$(echo a)}$(echo b)' '' 2 #20
530 check 'x=""; echo ${x?$(echo a)}$(echo b)' 'b' 0 #21
531 check 'x=""; echo ${x:?$(echo a)}$(echo b)' '' 2 #22
532 check 'x=c; echo ${x?$(echo a)}$(echo b)' 'cb' 0 #23
533 check 'x=c; echo ${x:?$(echo a)}$(echo b)' 'cb' 0 #24
534
535 check 'unset x; echo ${x%$(echo a)}$(echo b)' 'b' 0 #25
536 check 'unset x; echo ${x%%$(echo a)}$(echo b)' 'b' 0 #26
537 check 'x=""; echo ${x%$(echo a)}$(echo b)' 'b' 0 #27
538 check 'x=""; echo ${x%%$(echo a)}$(echo b)' 'b' 0 #28
539 check 'x=c; echo ${x%$(echo a)}$(echo b)' 'cb' 0 #29
540 check 'x=c; echo ${x%%$(echo a)}$(echo b)' 'cb' 0 #30
541 check 'x=aa; echo ${x%$(echo "*a")}$(echo b)' 'ab' 0 #31
542 check 'x=aa; echo ${x%%$(echo "*a")}$(echo b)' 'b' 0 #32
543
544 check 'unset x; echo ${x#$(echo a)}$(echo b)' 'b' 0 #33
545 check 'unset x; echo ${x##$(echo a)}$(echo b)' 'b' 0 #34
546 check 'x=""; echo ${x#$(echo a)}$(echo b)' 'b' 0 #35
547 check 'x=""; echo ${x##$(echo a)}$(echo b)' 'b' 0 #36
548 check 'x=c; echo ${x#$(echo a)}$(echo b)' 'cb' 0 #37
549 check 'x=c; echo ${x##$(echo a)}$(echo b)' 'cb' 0 #38
550 check 'x=aa; echo ${x#$(echo "*a")}$(echo b)' 'ab' 0 #39
551 check 'x=aa; echo ${x##$(echo "*a")}$(echo b)' 'b' 0 #40
552
553 results
554 }
555
556 atf_test_case dollar_hash
557 dollar_hash_head() {
558 atf_set "descr" 'Test expansion of various aspects of $#'
559 }
560 dollar_hash_body() {
561
562 #
563 # $# looks like it should be so simple that it doesn't really
564 # need a test of its own, and used in that way, it really doesn't.
565 # But when we add braces ${#} we need to deal with the three
566 # (almost 4) different meanings of a # inside a ${} expansion...
567 #
568 # Note that some of these are just how we treat expansions that
569 # are unspecified by posix (as noted below.)
570 #
571 # 1. ${#} is just $# (number of params)
572 # 1.a ${\#} is nothing at all (error: invalid expansion)
573 # 1.b ${\#...} (anything after) is the same (invalid)
574 # 2. ${#VAR} is the length of the value VAR
575 # 2.a Including ${##} - the length of ${#}
576 # 3 ${VAR#pat} is the value of VAR with leading pat removed
577 # 3.a Including ${VAR#} which just removes leading nothing
578 # This is relevant in case of ${VAR#${X}} with X=''
579 # nb: not required by posix, see XCU 2.6.2
580 # 3.b ${##} is not a case of 3.a but rather 2.a
581 # 3.c Yet ${##pat} is a case of 3.a
582 # Including ${##${X}} where X='' or X='#'
583 # nb: not required by posix, see XCU 2.6.2
584 # 3.d And ${#\#} is invalid (error)
585 # 3.e But ${##\#} removes a leading # from the value of $#
586 # (so is just $# as there is no leading # there)
587 # nb: not required by posix, see XCU 2.6.2
588 # 4 ${VAR##pat} is the value of VAR with longest pat removed
589 # 4.a Including ${VAR##} which removes the longest nothing
590 # 4.b Which in this case includes ${###} (so is == $#)
591 # nb: not required by posix, see XCU 2.6.2
592 # 4.c But not ${##\#} which is $# with a leading '#' removed
593 # (and so is also == $#), i.e.: like ${###} but different.
594 # nb: not required by posix, see XCU 2.6.2
595 # 4.d As is ${###\#} or just ${####} - remove # (so just $#)
596 # nb: not required by posix, see XCU 2.6.2
597 #
598
599 reset dollar_hash
600
601 check 'set -- ; echo $#' '0' 0 # 1
602 check 'set -- a b c; echo $#' '3' 0 # 2
603 check 'set -- a b c d e f g h i j; echo $#' '10' 0 # 3
604 # rule 1
605 check 'set -- ; echo ${#}' '0' 0 # 4
606 check 'set -- a b c; echo ${#}' '3' 0 # 5
607 check 'set -- a b c d e f g h i j; echo ${#}' '10' 0 # 6
608 # rule 1.a
609 check 'set -- a b c; echo ${\#}' '' 2 # 7
610 # rule 1.b
611 check 'set -- a b c; echo ${\#:-foo}' '' 2 # 8
612 # rule 2
613 check 'VAR=12345; echo ${#VAR}' '5' 0 # 9
614 check 'VAR=123456789012; echo ${#VAR}' '12' 0 #10
615 # rule 2.a
616 check 'set -- ; echo ${##}' '1' 0 #11
617 check 'set -- a b c; echo ${##}' '1' 0 #12
618 check 'set -- a b c d e f g h i j; echo ${##}' '2' 0 #13
619 # rule 3
620 check 'VAR=12345; echo ${VAR#1}' '2345' 0 #14
621 check 'VAR=12345; echo ${VAR#2}' '12345' 0 #15
622 check 'VAR=#2345; echo ${VAR#\#}' '2345' 0 #16
623 check 'X=1; VAR=12345; echo ${VAR#${X}}' '2345' 0 #17
624 check 'X=1; VAR=#2345; echo ${VAR#${X}}' '#2345' 0 #18
625 # rule 3.a
626 check 'VAR=12345; echo ${VAR#}' '12345' 0 #19
627 check 'X=; VAR=12345; echo ${VAR#${X}}' '12345' 0 #20
628 # rule 3.b (tested above, rule 2.a)
629 # rule 3.c
630 check 'set -- ; echo ${##0}' '' 0 #21
631 check 'set -- a b c; echo ${##1}' '3' 0 #22
632 check 'set -- a b c d e f g h i j; echo ${##1}' '0' 0 #23
633 check 'X=0; set -- ; echo ${##${X}}' '' 0 #24
634 check 'X=; set -- ; echo ${##${X}}' '0' 0 #25
635 check 'X=1; set -- a b c; echo ${##${X}}' '3' 0 #26
636 check 'X=1; set -- a b c d e f g h i j; echo ${##${X}}' '0' 0 #27
637 check 'X=; set -- a b c d e f g h i j; echo ${##${X}}' '10' 0 #28
638 check 'X=#; VAR=#2345; echo ${VAR#${X}}' '2345' 0 #29
639 check 'X=#; VAR=12345; echo ${VAR#${X}}' '12345' 0 #30
640 # rule 3.d
641 check 'set -- a b c; echo ${#\#}' '' 2 #31
642 # rule 3.e
643 check 'set -- ; echo ${##\#}' '0' 0 #32
644 check 'set -- a b c d e f g h i j; echo ${##\#}' '10' 0 #33
645
646 # rule 4
647 check 'VAR=12345; echo ${VAR##1}' '2345' 0 #34
648 check 'VAR=12345; echo ${VAR##\1}' '2345' 0 #35
649 # rule 4.a
650 check 'VAR=12345; echo ${VAR##}' '12345' 0 #36
651 # rule 4.b
652 check 'set -- ; echo ${###}' '0' 0 #37
653 check 'set -- a b c d e f g h i j; echo ${###}' '10' 0 #38
654 # rule 4.c
655 check 'VAR=12345; echo ${VAR#\#}' '12345' 0 #39
656 check 'VAR=12345; echo ${VAR#\#1}' '12345' 0 #40
657 check 'VAR=#2345; echo ${VAR#\#}' '2345' 0 #41
658 check 'VAR=#12345; echo ${VAR#\#1}' '2345' 0 #42
659 check 'VAR=#2345; echo ${VAR#\#1}' '#2345' 0 #43
660 check 'set -- ; echo ${####}' '0' 0 #44
661 check 'set -- ; echo ${###\#}' '0' 0 #45
662 check 'set -- a b c d e f g h i j; echo ${####}' '10' 0 #46
663 check 'set -- a b c d e f g h i j; echo ${###\#}' '10' 0 #47
664
665 # now check for some more utter nonsense, not mentioned in the rules
666 # above (doesn't need to be)
667
668 check 'x=hello; set -- a b c; echo ${#x:-1}' '' 2 #48
669 check 'x=hello; set -- a b c; echo ${#x-1}' '' 2 #49
670 check 'x=hello; set -- a b c; echo ${#x:+1}' '' 2 #50
671 check 'x=hello; set -- a b c; echo ${#x+1}' '' 2 #51
672 check 'x=hello; set -- a b c; echo ${#x+1}' '' 2 #52
673 check 'x=hello; set -- a b c; echo ${#x:?msg}' '' 2 #53
674 check 'x=hello; set -- a b c; echo ${#x?msg}' '' 2 #54
675 check 'x=hello; set -- a b c; echo ${#x:=val}' '' 2 #55
676 check 'x=hello; set -- a b c; echo ${#x=val}' '' 2 #56
677 check 'x=hello; set -- a b c; echo ${#x#h}' '' 2 #57
678 check 'x=hello; set -- a b c; echo ${#x#*l}' '' 2 #58
679 check 'x=hello; set -- a b c; echo ${#x##*l}' '' 2 #59
680 check 'x=hello; set -- a b c; echo ${#x%o}' '' 2 #60
681 check 'x=hello; set -- a b c; echo ${#x%l*}' '' 2 #61
682 check 'x=hello; set -- a b c; echo ${#x%%l*}' '' 2 #62
683
684 # but just to be complete, these ones should work
685
686 check 'x=hello; set -- a b c; echo ${#%5}' '3' 0 #63
687 check 'x=hello; set -- a b c; echo ${#%3}' '' 0 #64
688 check 'x=hello; set -- a b c; echo ${#%?}' '' 0 #65
689 check 'X=#; set -- a b c; echo ${#%${X}}' '3' 0 #66
690 check 'X=3; set -- a b c; echo ${#%${X}}' '' 0 #67
691 check 'set -- a b c; echo ${#%%5}' '3' 0 #68
692 check 'set -- a b c; echo ${#%%3}' '' 0 #69
693 check 'set -- a b c d e f g h i j k l; echo ${#%1}' '12' 0 #70
694 check 'set -- a b c d e f g h i j k l; echo ${#%2}' '1' 0 #71
695 check 'set -- a b c d e f g h i j k l; echo ${#%?}' '1' 0 #72
696 check 'set -- a b c d e f g h i j k l; echo ${#%[012]}' '1' 0 #73
697 check 'set -- a b c d e f g h i j k l; echo ${#%[0-4]}' '1' 0 #74
698 check 'set -- a b c d e f g h i j k l; echo ${#%?2}' '' 0 #75
699 check 'set -- a b c d e f g h i j k l; echo ${#%1*}' '' 0 #76
700 check 'set -- a b c d e f g h i j k l; echo ${#%%2}' '1' 0 #77
701 check 'set -- a b c d e f g h i j k l; echo ${#%%1*}' '' 0 #78
702
703 # and this lot are stupid, as $# is never unset or null, but they do work...
704
705 check 'set -- a b c; echo ${#:-99}' '3' 0 #79
706 check 'set -- a b c; echo ${#-99}' '3' 0 #80
707 check 'set -- a b c; echo ${#:+99}' '99' 0 #81
708 check 'set -- a b c; echo ${#+99}' '99' 0 #82
709 check 'set -- a b c; echo ${#:?bogus}' '3' 0 #83
710 check 'set -- a b c; echo ${#?bogus}' '3' 0 #84
711
712 # even this utter nonsense is OK, as while special params cannot be
713 # set this way, here, as $# is not unset, or null, the assignment
714 # never happens (isn't even attempted)
715
716 check 'set -- a b c; echo ${#:=bogus}' '3' 0 #85
717 check 'set -- a b c; echo ${#=bogus}' '3' 0 #86
718
719 for n in 0 1 10 25 100 #87 #88 #89 #90 #91
720 do
721 check "(exit $n)"'; echo ${#?}' "${#n}" 0
722 done
723
724 results # results so far anyway...
725
726 # now we have some harder to verify cases, as they (must) check unknown values
727 # and hence the resuls cannot just be built into the script, but we have
728 # to use some tricks to validate them, so for these, just do regular testing
729 # and don't attempt to use the check helper function, nor to include
730 # these tests in the result summary. If anything has already failed, we
731 # do not get this far... From here on, first failure ends this test.
732
733 for opts in '' '-a' '-au' '-auf' '-aufe' # options safe enough to set
734 do
735 # Note the shell might have other (or these) opts set already
736
737 RES=$(${TEST_SH} -c "test -n '${opts}' && set ${opts};
738 printf '%s' \"\$-\";printf ' %s\\n' \"\${#-}\"") ||
739 atf_fail '${#-} test exited with status '"$?"
740 LEN="${RES##* }"
741 DMINUS="${RES% ${LEN}}"
742 if [ "${#DMINUS}" != "${LEN}" ]
743 then
744 atf_fail \
745 '${#-} test'" produced ${LEN} for opts ${DMINUS} (${RES})"
746 fi
747 done
748
749 for seq in a b c d e f g h i j
750 do
751 # now we are tryin to generate different pids for $$ and $!
752 # so we just run the test a number of times, and hope...
753 # On NetBSD pid randomisation will usually help the tests
754
755 eval "$(${TEST_SH} -c \
756 '(exit 0)& BG=$! LBG=${#!};
757 printf "SH=%s BG=%s LSH=%s LBG=%s" "$$" "$BG" "${#$}" "$LBG";
758 wait')"
759
760 if [ "${#SH}" != "${LSH}" ] || [ "${#BG}" != "${LBG}" ]
761 then
762 atf_fail \
763 '${#!] of '"${BG} was ${LBG}, expected ${#BG}"'; ${#$} of '"${SH} was ${LSH}, expected ${#SH}"
764 fi
765 done
766 }
767
768 atf_test_case dollar_star
769 dollar_star_head() {
770 atf_set "descr" 'Test expansion of various aspects of $*'
771 }
772 dollar_star_body() {
773
774 reset dollar_star
775
776 check 'set -- a b c; echo $# $*' '3 a b c' 0 # 1
777 check 'set -- a b c; echo $# "$*"' '3 a b c' 0 # 2
778 check 'set -- a "b c"; echo $# $*' '2 a b c' 0 # 3
779 check 'set -- a "b c"; echo $# "$*"' '2 a b c' 0 # 4
780 check 'set -- a b c; set -- $* ; echo $# $*' '3 a b c' 0 # 5
781 check 'set -- a b c; set -- "$*" ; echo $# $*' '1 a b c' 0 # 6
782 check 'set -- a "b c"; set -- $* ; echo $# $*' '3 a b c' 0 # 7
783 check 'set -- a "b c"; set -- "$*" ; echo $# $*' \
784 '1 a b c' 0 # 8
785
786 check 'IFS=". "; set -- a b c; echo $# $*' '3 a b c' 0 # 9
787 check 'IFS=". "; set -- a b c; echo $# "$*"' '3 a.b.c' 0 #10
788 check 'IFS=". "; set -- a "b c"; echo $# $*' '2 a b c' 0 #11
789 check 'IFS=". "; set -- a "b c"; echo $# "$*"' '2 a.b c' 0 #12
790 check 'IFS=". "; set -- a "b.c"; echo $# $*' '2 a b c' 0 #13
791 check 'IFS=". "; set -- a "b.c"; echo $# "$*"' '2 a.b.c' 0 #14
792 check 'IFS=". "; set -- a b c; set -- $* ; echo $# $*' \
793 '3 a b c' 0 #15
794 check 'IFS=". "; set -- a b c; set -- "$*" ; echo $# $*' \
795 '1 a b c' 0 #16
796 check 'IFS=". "; set -- a "b c"; set -- $* ; echo $# $*' \
797 '3 a b c' 0 #17
798 check 'IFS=". "; set -- a "b c"; set -- "$*" ; echo $# $*' \
799 '1 a b c' 0 #18
800 check 'IFS=". "; set -- a b c; set -- $* ; echo $# "$*"' \
801 '3 a.b.c' 0 #19
802 check 'IFS=". "; set -- a b c; set -- "$*" ; echo $# "$*"' \
803 '1 a.b.c' 0 #20
804 check 'IFS=". "; set -- a "b c"; set -- $* ; echo $# "$*"' \
805 '3 a.b.c' 0 #21
806 check 'IFS=". "; set -- a "b c"; set -- "$*" ; echo $# "$*"' \
807 '1 a.b c' 0 #22
808
809 results
810 }
811
812 atf_test_case dollar_star_in_word
813 dollar_star_in_word_head() {
814 atf_set "descr" 'Test expansion $* occurring in word of ${var:-word}'
815 }
816 dollar_star_in_word_body() {
817
818 reset dollar_star_in_word
819
820 unset xXx ; # just in case!
821
822 # Note that the expected results for these tests are identical
823 # to those from the dollar_star test. It should never make
824 # a difference whether we expand $* or ${unset:-$*}
825
826 # (note expanding ${unset:-"$*"} is different, that is not tested here)
827
828 check 'set -- a b c; echo $# ${xXx:-$*}' '3 a b c' 0 # 1
829 check 'set -- a b c; echo $# "${xXx:-$*}"' '3 a b c' 0 # 2
830 check 'set -- a "b c"; echo $# ${xXx:-$*}' '2 a b c' 0 # 3
831 check 'set -- a "b c"; echo $# "${xXx:-$*}"' '2 a b c' 0 # 4
832 check 'set -- a b c; set -- ${xXx:-$*} ; echo $# $*' '3 a b c' 0 # 5
833 check 'set -- a b c; set -- "${xXx:-$*}" ; echo $# $*' '1 a b c' 0 # 6
834 check 'set -- a "b c"; set -- ${xXx:-$*} ; echo $# $*' '3 a b c' 0 # 7
835 check 'set -- a "b c"; set -- "${xXx:-$*}" ; echo $# $*' \
836 '1 a b c' 0 # 8
837
838 check 'IFS=". "; set -- a b c; echo $# ${xXx:-$*}' '3 a b c' 0 # 9
839 check 'IFS=". "; set -- a b c; echo $# "${xXx:-$*}"' '3 a.b.c' 0 #10
840 check 'IFS=". "; set -- a "b c"; echo $# ${xXx:-$*}' '2 a b c' 0 #11
841 check 'IFS=". "; set -- a "b c"; echo $# "${xXx:-$*}"' '2 a.b c' 0 #12
842 check 'IFS=". "; set -- a "b.c"; echo $# ${xXx:-$*}' '2 a b c' 0 #13
843 check 'IFS=". "; set -- a "b.c"; echo $# "${xXx:-$*}"' '2 a.b.c' 0 #14
844 check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
845 '3 a b c' 0 #15
846 check 'IFS=". ";set -- a b c;set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
847 '1 a b c' 0 #16
848 check 'IFS=". ";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
849 '3 a b c' 0 #17
850 check 'IFS=". ";set -- a "b c";set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
851 '1 a b c' 0 #18
852 check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
853 '3 a.b.c' 0 #19
854 check 'IFS=". ";set -- a b c;set -- "$*";echo $# "$*"' \
855 '1 a.b.c' 0 #20
856 check 'IFS=". ";set -- a "b c";set -- $*;echo $# "$*"' \
857 '3 a.b.c' 0 #21
858 check 'IFS=". ";set -- a "b c";set -- "$*";echo $# "$*"' \
859 '1 a.b c' 0 #22
860
861 results
862 }
863
864 atf_test_case dollar_star_with_empty_ifs
865 dollar_star_with_empty_ifs_head() {
866 atf_set "descr" 'Test expansion of $* with IFS=""'
867 }
868 dollar_star_with_empty_ifs_body() {
869
870 reset dollar_star_with_empty_ifs
871
872 check 'IFS=""; set -- a b c; echo $# $*' '3 a b c' 0 # 1
873 check 'IFS=""; set -- a b c; echo $# "$*"' '3 abc' 0 # 2
874 check 'IFS=""; set -- a "b c"; echo $# $*' '2 a b c' 0 # 3
875 check 'IFS=""; set -- a "b c"; echo $# "$*"' '2 ab c' 0 # 4
876 check 'IFS=""; set -- a "b.c"; echo $# $*' '2 a b.c' 0 # 5
877 check 'IFS=""; set -- a "b.c"; echo $# "$*"' '2 ab.c' 0 # 6
878 check 'IFS=""; set -- a b c; set -- $* ; echo $# $*' \
879 '3 a b c' 0 # 7
880 check 'IFS=""; set -- a b c; set -- "$*" ; echo $# $*' \
881 '1 abc' 0 # 8
882 check 'IFS=""; set -- a "b c"; set -- $* ; echo $# $*' \
883 '2 a b c' 0 # 9
884 check 'IFS=""; set -- a "b c"; set -- "$*" ; echo $# $*' \
885 '1 ab c' 0 #10
886 check 'IFS=""; set -- a b c; set -- $* ; echo $# "$*"' \
887 '3 abc' 0 #11
888 check 'IFS=""; set -- a b c; set -- "$*" ; echo $# "$*"' \
889 '1 abc' 0 #12
890 check 'IFS=""; set -- a "b c"; set -- $* ; echo $# "$*"' \
891 '2 ab c' 0 #13
892 check 'IFS=""; set -- a "b c"; set -- "$*" ; echo $# "$*"' \
893 '1 ab c' 0 #14
894
895 results # FIXED: 'PR bin/52090 expect 7 of 14 subtests to fail'
896 }
897
898 atf_test_case dollar_star_in_word_empty_ifs
899 dollar_star_in_word_empty_ifs_head() {
900 atf_set "descr" 'Test expansion of ${unset:-$*} with IFS=""'
901 }
902 dollar_star_in_word_empty_ifs_body() {
903
904 reset dollar_star_in_word_empty_ifs
905
906 unset xXx ; # just in case
907
908 # Note that the expected results for these tests are identical
909 # to those from the dollar_star_with_empty_ifs test. It should
910 # never make a difference whether we expand $* or ${unset:-$*}
911
912 # (note expanding ${unset:-"$*"} is different, that is not tested here)
913
914 check 'IFS="";set -- a b c;echo $# ${xXx:-$*}' '3 a b c' 0 # 1
915 check 'IFS="";set -- a b c;echo $# "${xXx:-$*}"' '3 abc' 0 # 2
916 check 'IFS="";set -- a "b c";echo $# ${xXx:-$*}' '2 a b c' 0 # 3
917 check 'IFS="";set -- a "b c";echo $# "${xXx:-$*}"' '2 ab c' 0 # 4
918 check 'IFS="";set -- a "b.c";echo $# ${xXx:-$*}' '2 a b.c' 0 # 5
919 check 'IFS="";set -- a "b.c";echo $# "${xXx:-$*}"' '2 ab.c' 0 # 6
920 check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
921 '3 a b c' 0 # 7
922 check 'IFS="";set -- a b c;set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
923 '1 abc' 0 # 8
924 check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
925 '2 a b c' 0 # 9
926 check 'IFS="";set -- a "b c";set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
927 '1 ab c' 0 #10
928 check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
929 '3 abc' 0 #11
930 check 'IFS="";set -- a b c;set -- "${xXx:-$*}";echo $# "${xXx:-$*}"' \
931 '1 abc' 0 #12
932 check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
933 '2 ab c' 0 #13
934 check 'IFS="";set -- a "b c";set -- "${xXx:-$*}";echo $# "${xXx:-$*}"' \
935 '1 ab c' 0 #14
936
937 results # FIXED: 'PR bin/52090 expect 7 of 14 subtests to fail'
938 }
939
940 atf_test_case dollar_star_in_quoted_word
941 dollar_star_in_quoted_word_head() {
942 atf_set "descr" 'Test expansion $* occurring in word of ${var:-"word"}'
943 }
944 dollar_star_in_quoted_word_body() {
945
946 reset dollar_star_in_quoted_word
947
948 unset xXx ; # just in case!
949
950 check 'set -- a b c; echo $# ${xXx:-"$*"}' '3 a b c' 0 # 1
951 check 'set -- a "b c"; echo $# ${xXx:-"$*"}' '2 a b c' 0 # 2
952 check 'set -- a b c; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
953 '1 a b c' 0 # 3
954 check 'set -- a "b c"; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
955 '1 a b c' 0 # 4
956 check 'set -- a b c; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
957 '1 a b c' 0 # 5
958 check 'set -- a "b c"; set -- ${xXx:-"$*"} ; echo $# ${xXx-$*}' \
959 '1 a b c' 0 # 6
960 check 'set -- a b c; set -- ${xXx:-$*} ; echo $# ${xXx-"$*"}' \
961 '3 a b c' 0 # 7
962 check 'set -- a "b c"; set -- ${xXx:-$*} ; echo $# ${xXx-"$*"}' \
963 '3 a b c' 0 # 8
964
965 check 'IFS=". "; set -- a b c; echo $# ${xXx:-"$*"}' '3 a.b.c' 0 # 9
966 check 'IFS=". "; set -- a "b c"; echo $# ${xXx:-"$*"}' '2 a.b c' 0 #10
967 check 'IFS=". "; set -- a "b.c"; echo $# ${xXx:-"$*"}' '2 a.b.c' 0 #11
968 check 'IFS=". ";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
969 '1 a.b.c' 0 #12
970 check 'IFS=". ";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
971 '1 a.b c' 0 #13
972 check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
973 '3 a.b.c' 0 #14
974 check 'IFS=". ";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
975 '3 a.b.c' 0 #15
976 check 'IFS=". ";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
977 '1 a b c' 0 #16
978 check 'IFS=". ";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
979 '1 a b c' 0 #17
980
981 check 'IFS="";set -- a b c;echo $# ${xXx:-"$*"}' '3 abc' 0 #18
982 check 'IFS="";set -- a "b c";echo $# ${xXx:-"$*"}' '2 ab c' 0 #19
983 check 'IFS="";set -- a "b.c";echo $# ${xXx:-"$*"}' '2 ab.c' 0 #20
984 check 'IFS="";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
985 '1 abc' 0 #21
986 check 'IFS="";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
987 '1 ab c' 0 #22
988 check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
989 '3 abc' 0 #23
990 check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
991 '2 ab c' 0 #24
992 check 'IFS="";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
993 '1 abc' 0 #25
994 check 'IFS="";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
995 '1 ab c' 0 #26
996
997 results # FIXED: 'PR bin/52090 - 2 of 26 subtests expected to fail'
998 }
999
1000 atf_init_test_cases() {
1001 # Listed here in the order ATF runs them, not the order from above
1002
1003 atf_add_test_case arithmetic
1004 atf_add_test_case dollar_at
1005 atf_add_test_case dollar_at_with_text
1006 atf_add_test_case dollar_hash
1007 atf_add_test_case dollar_star
1008 atf_add_test_case dollar_star_in_quoted_word
1009 atf_add_test_case dollar_star_in_word
1010 atf_add_test_case dollar_star_in_word_empty_ifs
1011 atf_add_test_case dollar_star_with_empty_ifs
1012 atf_add_test_case iteration_on_null_parameter
1013 atf_add_test_case iteration_on_quoted_null_parameter
1014 atf_add_test_case iteration_on_null_or_null_parameter
1015 atf_add_test_case iteration_on_null_or_missing_parameter
1016 atf_add_test_case shell_params
1017 atf_add_test_case strip
1018 atf_add_test_case tilde
1019 atf_add_test_case wrap_strip
1020 atf_add_test_case var_with_embedded_cmdsub
1021 atf_add_test_case varpattern_backslashes
1022 }
1023