Home | History | Annotate | Line # | Download | only in sh
t_expand.sh revision 1.8.4.1
      1 # $NetBSD: t_expand.sh,v 1.8.4.1 2017/04/21 16:54:09 bouyer 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 varpattern_backslashes
    160 varpattern_backslashes_head() {
    161 	atf_set "descr" "Tests that protecting wildcards with backslashes" \
    162 	                "works in variable patterns."
    163 }
    164 varpattern_backslashes_body() {
    165 	line='/foo/bar/*/baz'
    166 	stripped='/foo/bar/'
    167 	atf_check -o inline:'/foo/bar/\n' -e empty ${TEST_SH} -c \
    168 		'line="/foo/bar/*/baz"; echo ${line%%\**}'
    169 }
    170 
    171 atf_test_case arithmetic
    172 arithmetic_head() {
    173 	atf_set "descr" "POSIX requires shell arithmetic to use signed" \
    174 	                "long or a wider type.  We use intmax_t, so at" \
    175 			"least 64 bits should be available.  Make sure" \
    176 			"this is true."
    177 }
    178 arithmetic_body() {
    179 
    180 	atf_check -o inline:'3' -e empty ${TEST_SH} -c \
    181 		'printf %s $((1 + 2))'
    182 	atf_check -o inline:'2147483647' -e empty ${TEST_SH} -c \
    183 		'printf %s $((0x7fffffff))'
    184 	atf_check -o inline:'9223372036854775807' -e empty ${TEST_SH} -c \
    185 		'printf %s $(((1 << 63) - 1))'
    186 }
    187 
    188 atf_test_case iteration_on_null_parameter
    189 iteration_on_null_parameter_head() {
    190 	atf_set "descr" "Check iteration of \$@ in for loop when set to null;" \
    191 	                "the error \"sh: @: parameter not set\" is incorrect." \
    192 	                "PR bin/48202."
    193 }
    194 iteration_on_null_parameter_body() {
    195 	atf_check -o empty -e empty ${TEST_SH} -c \
    196 		'N=; set -- ${N};   for X; do echo "[$X]"; done'
    197 }
    198 
    199 atf_test_case iteration_on_quoted_null_parameter
    200 iteration_on_quoted_null_parameter_head() {
    201 	atf_set "descr" \
    202 		'Check iteration of "$@" in for loop when set to null;'
    203 }
    204 iteration_on_quoted_null_parameter_body() {
    205 	atf_check -o inline:'[]\n' -e empty ${TEST_SH} -c \
    206 		'N=; set -- "${N}"; for X; do echo "[$X]"; done'
    207 }
    208 
    209 atf_test_case iteration_on_null_or_null_parameter
    210 iteration_on_null_or_null_parameter_head() {
    211 	atf_set "descr" \
    212 		'Check expansion of null parameter as default for another null'
    213 }
    214 iteration_on_null_or_null_parameter_body() {
    215 	atf_check -o empty -e empty ${TEST_SH} -c \
    216 		'N=; E=; set -- ${N:-${E}}; for X; do echo "[$X]"; done'
    217 }
    218 
    219 atf_test_case iteration_on_null_or_missing_parameter
    220 iteration_on_null_or_missing_parameter_head() {
    221 	atf_set "descr" \
    222 	    'Check expansion of missing parameter as default for another null'
    223 }
    224 iteration_on_null_or_missing_parameter_body() {
    225 	# atf_expect_fail 'PR bin/50834'
    226 	atf_check -o empty -e empty ${TEST_SH} -c \
    227 		'N=; set -- ${N:-}; for X; do echo "[$X]"; done'
    228 }
    229 
    230 ####### The remaining tests use the following helper functions ...
    231 
    232 nl='
    233 '
    234 reset()
    235 {
    236 	TEST_NUM=0
    237 	TEST_FAILURES=''
    238 	TEST_FAIL_COUNT=0
    239 	TEST_ID="$1"
    240 }
    241 
    242 check()
    243 {
    244 	fail=false
    245 	TEMP_FILE=$( mktemp OUT.XXXXXX )
    246 	TEST_NUM=$(( $TEST_NUM + 1 ))
    247 	MSG=
    248 
    249 	# our local shell (ATF_SHELL) better do quoting correctly...
    250 	# some of the tests expect us to expand $nl internally...
    251 	CMD="$1"
    252 
    253 	result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" )"
    254 	STATUS=$?
    255 
    256 	if [ "${STATUS}" -ne "$3" ]; then
    257 		MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    258 		MSG="${MSG} expected exit code $3, got ${STATUS}"
    259 
    260 		# don't actually fail just because of wrong exit code
    261 		# unless we either expected, or received "good"
    262 		case "$3/${STATUS}" in
    263 		(*/0|0/*) fail=true;;
    264 		esac
    265 	fi
    266 
    267 	if [ "$3" -eq 0 ]; then
    268 		if [ -s "${TEMP_FILE}" ]; then
    269 			MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    270 			MSG="${MSG} Messages produced on stderr unexpected..."
    271 			MSG="${MSG}${nl}$( cat "${TEMP_FILE}" )"
    272 			fail=true
    273 		fi
    274 	else
    275 		if ! [ -s "${TEMP_FILE}" ]; then
    276 			MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    277 			MSG="${MSG} Expected messages on stderr,"
    278 			MSG="${MSG} nothing produced"
    279 			fail=true
    280 		fi
    281 	fi
    282 	rm -f "${TEMP_FILE}"
    283 
    284 	# Remove newlines (use local shell for this)
    285 	oifs="$IFS"
    286 	IFS="$nl"
    287 	result="$(echo $result)"
    288 	IFS="$oifs"
    289 	if [ "$2" != "$result" ]
    290 	then
    291 		MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    292 		MSG="${MSG} Expected output '$2', received '$result'"
    293 		fail=true
    294 	fi
    295 
    296 	if $fail
    297 	then
    298 		MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    299 		MSG="${MSG} Full command: <<${CMD}>>"
    300 	fi
    301 
    302 	$fail && test -n "$TEST_ID" && {
    303 		TEST_FAILURES="${TEST_FAILURES}${TEST_FAILURES:+${nl}}"
    304 		TEST_FAILURES="${TEST_FAILURES}${TEST_ID}[$TEST_NUM]:"
    305 		TEST_FAILURES="${TEST_FAILURES} Test of '$1' failed.";
    306 		TEST_FAILURES="${TEST_FAILURES}${nl}${MSG}"
    307 		TEST_FAIL_COUNT=$(( $TEST_FAIL_COUNT + 1 ))
    308 		return 0
    309 	}
    310 	$fail && atf_fail "Test[$TEST_NUM] of '$1' failed${nl}${MSG}"
    311 	return 0
    312 }
    313 
    314 results()
    315 {
    316 	test -n "$1" && atf_expect_fail "$1"
    317 
    318 	test -z "${TEST_ID}" && return 0
    319 	test -z "${TEST_FAILURES}" && return 0
    320 
    321 	echo >&2 "=========================================="
    322 	echo >&2 "While testing '${TEST_ID}'"
    323 	echo >&2 " - - - - - - - - - - - - - - - - -"
    324 	echo >&2 "${TEST_FAILURES}"
    325 
    326 	atf_fail \
    327  "Test ${TEST_ID}: $TEST_FAIL_COUNT (of $TEST_NUM) subtests failed - see stderr"
    328 }
    329 
    330 ####### End helpers
    331 
    332 atf_test_case shell_params
    333 shell_params_head() {
    334 	atf_set "descr" "Test correct operation of the numeric parameters"
    335 }
    336 shell_params_body() {
    337 	atf_require_prog mktemp
    338 
    339 	reset shell_params
    340 
    341 	check 'set -- a b c; echo "$#: $1 $2 $3"' '3: a b c' 0
    342 	check 'set -- a b c d e f g h i j k l m; echo "$#: ${1}0 ${10} $10"' \
    343 		'13: a0 j a0' 0
    344 	check 'x="$0"; set -- a b; y="$0";
    345 	      [ "x${x}y" = "x${y}y" ] && echo OK || echo x="$x" y="$y"' \
    346 		'OK' 0
    347 	check "${TEST_SH} -c 'echo 0=\$0 1=\$1 2=\$2' a b c" '0=a 1=b 2=c' 0
    348 
    349 	echo 'echo 0="$0" 1="$1" 2="$2"' > helper.sh
    350 	check "${TEST_SH} helper.sh a b c" '0=helper.sh 1=a 2=b' 0
    351 
    352 	check 'set -- a bb ccc dddd eeeee ffffff ggggggg hhhhhhhh \
    353 		iiiiiiiii jjjjjjjjjj kkkkkkkkkkk
    354 	       echo "${#}: ${#1} ${#2} ${#3} ${#4} ... ${#9} ${#10} ${#11}"' \
    355 		 '11: 1 2 3 4 ... 9 10 11' 0
    356 
    357 	check 'set -- a b c; echo "$#: ${1-A} ${2-B} ${3-C} ${4-D} ${5-E}"' \
    358 		'3: a b c D E' 0
    359 	check 'set -- a "" c "" e
    360 	       echo "$#: ${1:-A} ${2:-B} ${3:-C} ${4:-D} ${5:-E}"' \
    361 		'5: a B c D e' 0
    362 	check 'set -- a "" c "" e
    363 	       echo "$#: ${1:+A} ${2:+B} ${3:+C} ${4:+D} ${5:+E}"' \
    364 		'5: A  C  E' 0
    365 	check 'set -- "abab*cbb"
    366 	       echo "${1} ${1#a} ${1%b} ${1##ab} ${1%%b} ${1#*\*} ${1%\**}"' \
    367 	       'abab*cbb bab*cbb abab*cb ab*cbb abab*cb cbb abab' 0
    368 	check 'set -- "abab?cbb"
    369     echo "${1}:${1#*a}+${1%b*}-${1##*a}_${1%%b*}%${1#[ab]}=${1%?*}/${1%\?*}"' \
    370 	       'abab?cbb:bab?cbb+abab?cb-b?cbb_a%bab?cbb=abab?cb/abab' 0
    371 	check 'set -- a "" c "" e; echo "${2:=b}"' '' 1
    372 
    373 	results
    374 }
    375 
    376 atf_test_case var_with_embedded_cmdsub
    377 var_with_embedded_cmdsub_head() {
    378 	atf_set "descr" "Test expansion of vars with embedded cmdsub"
    379 }
    380 var_with_embedded_cmdsub_body() {
    381 
    382 	reset var_with_embedded_cmdsub
    383 
    384 	check 'unset x; echo ${x-$(echo a)}$(echo b)'  'ab' 0	#1
    385 	check 'unset x; echo ${x:-$(echo a)}$(echo b)' 'ab' 0	#2
    386 	check 'x=""; echo ${x-$(echo a)}$(echo b)'     'b'  0	#3
    387 	check 'x=""; echo ${x:-$(echo a)}$(echo b)'    'ab' 0	#4
    388 	check 'x=c; echo ${x-$(echo a)}$(echo b)'      'cb' 0	#5
    389 	check 'x=c; echo ${x:-$(echo a)}$(echo b)'     'cb' 0	#6
    390 
    391 	check 'unset x; echo ${x+$(echo a)}$(echo b)'  'b'  0	#7
    392 	check 'unset x; echo ${x:+$(echo a)}$(echo b)' 'b'  0	#8
    393 	check 'x=""; echo ${x+$(echo a)}$(echo b)'     'ab' 0	#9
    394 	check 'x=""; echo ${x:+$(echo a)}$(echo b)'    'b'  0	#10
    395 	check 'x=c; echo ${x+$(echo a)}$(echo b)'      'ab' 0	#11
    396 	check 'x=c; echo ${x:+$(echo a)}$(echo b)'     'ab' 0	#12
    397 
    398 	check 'unset x; echo ${x=$(echo a)}$(echo b)'  'ab' 0	#13
    399 	check 'unset x; echo ${x:=$(echo a)}$(echo b)' 'ab' 0	#14
    400 	check 'x=""; echo ${x=$(echo a)}$(echo b)'     'b'  0	#15
    401 	check 'x=""; echo ${x:=$(echo a)}$(echo b)'    'ab' 0	#16
    402 	check 'x=c; echo ${x=$(echo a)}$(echo b)'      'cb' 0	#17
    403 	check 'x=c; echo ${x:=$(echo a)}$(echo b)'     'cb' 0	#18
    404 
    405 	check 'unset x; echo ${x?$(echo a)}$(echo b)'  ''   2	#19
    406 	check 'unset x; echo ${x:?$(echo a)}$(echo b)' ''   2	#20
    407 	check 'x=""; echo ${x?$(echo a)}$(echo b)'     'b'  0	#21
    408 	check 'x=""; echo ${x:?$(echo a)}$(echo b)'    ''   2	#22
    409 	check 'x=c; echo ${x?$(echo a)}$(echo b)'      'cb' 0	#23
    410 	check 'x=c; echo ${x:?$(echo a)}$(echo b)'     'cb' 0	#24
    411 
    412 	check 'unset x; echo ${x%$(echo a)}$(echo b)'  'b'  0	#25
    413 	check 'unset x; echo ${x%%$(echo a)}$(echo b)' 'b'  0	#26
    414 	check 'x=""; echo ${x%$(echo a)}$(echo b)'     'b'  0	#27
    415 	check 'x=""; echo ${x%%$(echo a)}$(echo b)'    'b'  0	#28
    416 	check 'x=c; echo ${x%$(echo a)}$(echo b)'      'cb' 0	#29
    417 	check 'x=c; echo ${x%%$(echo a)}$(echo b)'     'cb' 0	#30
    418 	check 'x=aa; echo ${x%$(echo "*a")}$(echo b)'  'ab' 0	#31
    419 	check 'x=aa; echo ${x%%$(echo "*a")}$(echo b)' 'b'  0	#32
    420 
    421 	check 'unset x; echo ${x#$(echo a)}$(echo b)'  'b'  0	#33
    422 	check 'unset x; echo ${x##$(echo a)}$(echo b)' 'b'  0	#34
    423 	check 'x=""; echo ${x#$(echo a)}$(echo b)'     'b'  0	#35
    424 	check 'x=""; echo ${x##$(echo a)}$(echo b)'    'b'  0	#36
    425 	check 'x=c; echo ${x#$(echo a)}$(echo b)'      'cb' 0	#37
    426 	check 'x=c; echo ${x##$(echo a)}$(echo b)'     'cb' 0	#38
    427 	check 'x=aa; echo ${x#$(echo "*a")}$(echo b)'  'ab' 0	#39
    428 	check 'x=aa; echo ${x##$(echo "*a")}$(echo b)' 'b'  0	#40
    429 
    430 	results
    431 }
    432 
    433 atf_test_case dollar_star
    434 dollar_star_head() {
    435 	atf_set "descr" 'Test expansion of various aspects of $*'
    436 }
    437 dollar_star_body() {
    438 
    439 	reset # dollar_star
    440 
    441 	check 'set -- a b c; echo $# $*'		'3 a b c'	0  # 1
    442 	check 'set -- a b c; echo $# "$*"'		'3 a b c'	0  # 2
    443 	check 'set -- a "b c"; echo $# $*'		'2 a b c'	0  # 3
    444 	check 'set -- a "b c"; echo $# "$*"'		'2 a b c'	0  # 4
    445 	check 'set -- a b c; set -- $* ; echo $# $*'	'3 a b c'	0  # 5
    446 	check 'set -- a b c; set -- "$*" ; echo $# $*'	'1 a b c'	0  # 6
    447 	check 'set -- a "b c"; set -- $* ; echo $# $*'	'3 a b c'	0  # 7
    448 	check 'set -- a "b c"; set -- "$*" ; echo $# $*' \
    449 							'1 a b c'	0  # 8
    450 
    451 	check 'IFS=". "; set -- a b c; echo $# $*'	'3 a b c'	0  # 9
    452 	check 'IFS=". "; set -- a b c; echo $# "$*"'	'3 a.b.c'	0  #10
    453 	check 'IFS=". "; set -- a "b c"; echo $# $*'	'2 a b c'	0  #11
    454 	check 'IFS=". "; set -- a "b c"; echo $# "$*"'	'2 a.b c'	0  #12
    455 	check 'IFS=". "; set -- a "b.c"; echo $# $*'	'2 a b c'	0  #13
    456 	check 'IFS=". "; set -- a "b.c"; echo $# "$*"'	'2 a.b.c'	0  #14
    457 	check 'IFS=". "; set -- a b c; set -- $* ; echo $# $*' \
    458 							'3 a b c'	0  #15
    459 	check 'IFS=". "; set -- a b c; set -- "$*" ; echo $# $*' \
    460 							'1 a b c'	0  #16
    461 	check 'IFS=". "; set -- a "b c"; set -- $* ; echo $# $*' \
    462 							'3 a b c'	0  #17
    463 	check 'IFS=". "; set -- a "b c"; set -- "$*" ; echo $# $*' \
    464 							'1 a b c'	0  #18
    465 	check 'IFS=". "; set -- a b c; set -- $* ; echo $# "$*"' \
    466 							'3 a.b.c'	0  #19
    467 	check 'IFS=". "; set -- a b c; set -- "$*" ; echo $# "$*"' \
    468 							'1 a.b.c'	0  #20
    469 	check 'IFS=". "; set -- a "b c"; set -- $* ; echo $# "$*"' \
    470 							'3 a.b.c'	0  #21
    471 	check 'IFS=". "; set -- a "b c"; set -- "$*" ; echo $# "$*"' \
    472 							'1 a.b c'	0  #22
    473 
    474 	results
    475 }
    476 
    477 atf_test_case dollar_star_in_word
    478 dollar_star_in_word_head() {
    479 	atf_set "descr" 'Test expansion $* occurring in word of ${var:-word}'
    480 }
    481 dollar_star_in_word_body() {
    482 
    483 	reset dollar_star_in_word
    484 
    485 	unset xXx			; # just in case!
    486 
    487 	# Note that the expected results for these tests are identical
    488 	# to those from the dollar_star test.   It should never make
    489 	# a difference whether we expand $* or ${unset:-$*}
    490 
    491 	# (note expanding ${unset:-"$*"} is different, that is not tested here)
    492 
    493 	check 'set -- a b c; echo $# ${xXx:-$*}'		'3 a b c' 0  # 1
    494 	check 'set -- a b c; echo $# "${xXx:-$*}"'		'3 a b c' 0  # 2
    495 	check 'set -- a "b c"; echo $# ${xXx:-$*}'		'2 a b c' 0  # 3
    496 	check 'set -- a "b c"; echo $# "${xXx:-$*}"'		'2 a b c' 0  # 4
    497 	check 'set -- a b c; set -- ${xXx:-$*} ; echo $# $*'	'3 a b c' 0  # 5
    498 	check 'set -- a b c; set -- "${xXx:-$*}" ; echo $# $*'	'1 a b c' 0  # 6
    499 	check 'set -- a "b c"; set -- ${xXx:-$*} ; echo $# $*'	'3 a b c' 0  # 7
    500 	check 'set -- a "b c"; set -- "${xXx:-$*}" ; echo $# $*' \
    501 								'1 a b c' 0  # 8
    502 
    503 	check 'IFS=". "; set -- a b c; echo $# ${xXx:-$*}'	'3 a b c' 0  # 9
    504 	check 'IFS=". "; set -- a b c; echo $# "${xXx:-$*}"'	'3 a.b.c' 0  #10
    505 	check 'IFS=". "; set -- a "b c"; echo $# ${xXx:-$*}'	'2 a b c' 0  #11
    506 	check 'IFS=". "; set -- a "b c"; echo $# "${xXx:-$*}"'	'2 a.b c' 0  #12
    507 	check 'IFS=". "; set -- a "b.c"; echo $# ${xXx:-$*}'	'2 a b c' 0  #13
    508 	check 'IFS=". "; set -- a "b.c"; echo $# "${xXx:-$*}"'	'2 a.b.c' 0  #14
    509 	check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
    510 								'3 a b c' 0  #15
    511 	check 'IFS=". ";set -- a b c;set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
    512 								'1 a b c' 0  #16
    513 	check 'IFS=". ";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
    514 								'3 a b c' 0  #17
    515 	check 'IFS=". ";set -- a "b c";set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
    516 								'1 a b c' 0  #18
    517 	check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
    518 								'3 a.b.c' 0  #19
    519 	check 'IFS=". ";set -- a b c;set -- "$*";echo $# "$*"' \
    520 								'1 a.b.c' 0  #20
    521 	check 'IFS=". ";set -- a "b c";set -- $*;echo $# "$*"' \
    522 								'3 a.b.c' 0  #21
    523 	check 'IFS=". ";set -- a "b c";set -- "$*";echo $# "$*"' \
    524 								'1 a.b c' 0  #22
    525 
    526 	results
    527 }
    528 
    529 atf_test_case dollar_star_with_empty_ifs
    530 dollar_star_with_empty_ifs_head() {
    531 	atf_set "descr" 'Test expansion of $* with IFS=""'
    532 }
    533 dollar_star_with_empty_ifs_body() {
    534 
    535 	reset dollar_star_with_empty_ifs
    536 
    537 	check 'IFS=""; set -- a b c; echo $# $*'	'3 a b c'	0  # 1
    538 	check 'IFS=""; set -- a b c; echo $# "$*"'	'3 abc'		0  # 2
    539 	check 'IFS=""; set -- a "b c"; echo $# $*'	'2 a b c'	0  # 3
    540 	check 'IFS=""; set -- a "b c"; echo $# "$*"'	'2 ab c'	0  # 4
    541 	check 'IFS=""; set -- a "b.c"; echo $# $*'	'2 a b.c'	0  # 5
    542 	check 'IFS=""; set -- a "b.c"; echo $# "$*"'	'2 ab.c'	0  # 6
    543 	check 'IFS=""; set -- a b c; set -- $* ; echo $# $*' \
    544 							'3 a b c'	0  # 7
    545 	check 'IFS=""; set -- a b c; set -- "$*" ; echo $# $*' \
    546 							'1 abc'		0  # 8
    547 	check 'IFS=""; set -- a "b c"; set -- $* ; echo $# $*' \
    548 							'2 a b c'	0  # 9
    549 	check 'IFS=""; set -- a "b c"; set -- "$*" ; echo $# $*' \
    550 							'1 ab c'	0  #10
    551 	check 'IFS=""; set -- a b c; set -- $* ; echo $# "$*"' \
    552 							'3 abc'		0  #11
    553 	check 'IFS=""; set -- a b c; set -- "$*" ; echo $# "$*"' \
    554 							'1 abc'		0  #12
    555 	check 'IFS=""; set -- a "b c"; set -- $* ; echo $# "$*"' \
    556 							'2 ab c'	0  #13
    557 	check 'IFS=""; set -- a "b c"; set -- "$*" ; echo $# "$*"' \
    558 							'1 ab c'	0  #14
    559 
    560 	results	  # FIXED: 'PR bin/52090 expect 7 of 14 subtests to fail'
    561 }
    562 
    563 atf_test_case dollar_star_in_word_empty_ifs
    564 dollar_star_in_word_empty_ifs_head() {
    565 	atf_set "descr" 'Test expansion of ${unset:-$*} with IFS=""'
    566 }
    567 dollar_star_in_word_empty_ifs_body() {
    568 
    569 	reset dollar_star_in_word_empty_ifs
    570 
    571 	unset xXx			; # just in case
    572 
    573 	# Note that the expected results for these tests are identical
    574 	# to those from the dollar_star_with_empty_ifs test.   It should
    575 	# never make a difference whether we expand $* or ${unset:-$*}
    576 
    577 	# (note expanding ${unset:-"$*"} is different, that is not tested here)
    578 
    579 	check 'IFS="";set -- a b c;echo $# ${xXx:-$*}'		'3 a b c' 0  # 1
    580 	check 'IFS="";set -- a b c;echo $# "${xXx:-$*}"'	'3 abc'	  0  # 2
    581 	check 'IFS="";set -- a "b c";echo $# ${xXx:-$*}'	'2 a b c' 0  # 3
    582 	check 'IFS="";set -- a "b c";echo $# "${xXx:-$*}"'	'2 ab c'  0  # 4
    583 	check 'IFS="";set -- a "b.c";echo $# ${xXx:-$*}'	'2 a b.c' 0  # 5
    584 	check 'IFS="";set -- a "b.c";echo $# "${xXx:-$*}"'	'2 ab.c'  0  # 6
    585 	check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
    586 								'3 a b c' 0  # 7
    587 	check 'IFS="";set -- a b c;set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
    588 								'1 abc'   0  # 8
    589 	check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
    590 								'2 a b c' 0  # 9
    591 	check 'IFS="";set -- a "b c";set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
    592 								'1 ab c'  0  #10
    593 	check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
    594 								'3 abc'	  0  #11
    595 	check 'IFS="";set -- a b c;set -- "${xXx:-$*}";echo $# "${xXx:-$*}"' \
    596 								'1 abc'	  0  #12
    597 	check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
    598 								'2 ab c'  0  #13
    599 	check 'IFS="";set -- a "b c";set -- "${xXx:-$*}";echo $# "${xXx:-$*}"' \
    600 								'1 ab c'  0  #14
    601 
    602 	results	  # FIXED: 'PR bin/52090 expect 7 of 14 subtests to fail'
    603 }
    604 
    605 atf_test_case dollar_star_in_quoted_word
    606 dollar_star_in_quoted_word_head() {
    607 	atf_set "descr" 'Test expansion $* occurring in word of ${var:-"word"}'
    608 }
    609 dollar_star_in_quoted_word_body() {
    610 
    611 	reset dollar_star_in_quoted_word
    612 
    613 	unset xXx			; # just in case!
    614 
    615 	check 'set -- a b c; echo $# ${xXx:-"$*"}'		'3 a b c' 0  # 1
    616 	check 'set -- a "b c"; echo $# ${xXx:-"$*"}'		'2 a b c' 0  # 2
    617 	check 'set -- a b c; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
    618 								'1 a b c' 0  # 3
    619 	check 'set -- a "b c"; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
    620 								'1 a b c' 0  # 4
    621 	check 'set -- a b c; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
    622 								'1 a b c' 0  # 5
    623 	check 'set -- a "b c"; set -- ${xXx:-"$*"} ; echo $# ${xXx-$*}' \
    624 								'1 a b c' 0  # 6
    625 	check 'set -- a b c; set -- ${xXx:-$*} ; echo $# ${xXx-"$*"}' \
    626 								'3 a b c' 0  # 7
    627 	check 'set -- a "b c"; set -- ${xXx:-$*} ; echo $# ${xXx-"$*"}' \
    628 								'3 a b c' 0  # 8
    629 
    630 	check 'IFS=". "; set -- a b c; echo $# ${xXx:-"$*"}'	'3 a.b.c' 0  # 9
    631 	check 'IFS=". "; set -- a "b c"; echo $# ${xXx:-"$*"}'	'2 a.b c' 0  #10
    632 	check 'IFS=". "; set -- a "b.c"; echo $# ${xXx:-"$*"}'	'2 a.b.c' 0  #11
    633 	check 'IFS=". ";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
    634 								'1 a.b.c' 0  #12
    635       check 'IFS=". ";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
    636 								'1 a.b c' 0  #13
    637 	check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
    638 								'3 a.b.c' 0  #14
    639 	check 'IFS=". ";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
    640 								'3 a.b.c' 0  #15
    641 	check 'IFS=". ";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
    642 								'1 a b c' 0  #16
    643 	check 'IFS=". ";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
    644 								'1 a b c' 0  #17
    645 
    646 	check 'IFS="";set -- a b c;echo $# ${xXx:-"$*"}'	'3 abc'   0  #18
    647 	check 'IFS="";set -- a "b c";echo $# ${xXx:-"$*"}'	'2 ab c'  0  #19
    648 	check 'IFS="";set -- a "b.c";echo $# ${xXx:-"$*"}'	'2 ab.c'  0  #20
    649 	check 'IFS="";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
    650 								'1 abc'   0  #21
    651 	check 'IFS="";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
    652 								'1 ab c'  0  #22
    653 	check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
    654 								'3 abc'   0  #23
    655 	check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
    656 								'2 ab c'  0  #24
    657 	check 'IFS="";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
    658 								'1 abc'   0  #25
    659 	check 'IFS="";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
    660 								'1 ab c'  0  #26
    661 
    662 	results	  # FIXED: 'PR bin/52090 - 2 of 26 subtests expected to fail'
    663 }
    664 
    665 atf_init_test_cases() {
    666 	# Listed here in the order ATF runs them, not the order from above
    667 
    668 	atf_add_test_case arithmetic
    669 	atf_add_test_case dollar_at
    670 	atf_add_test_case dollar_at_with_text
    671 	atf_add_test_case dollar_star
    672 	atf_add_test_case dollar_star_in_quoted_word
    673 	atf_add_test_case dollar_star_in_word
    674 	atf_add_test_case dollar_star_in_word_empty_ifs
    675 	atf_add_test_case dollar_star_with_empty_ifs
    676 	atf_add_test_case iteration_on_null_parameter
    677 	atf_add_test_case iteration_on_quoted_null_parameter
    678 	atf_add_test_case iteration_on_null_or_null_parameter
    679 	atf_add_test_case iteration_on_null_or_missing_parameter
    680 	atf_add_test_case shell_params
    681 	atf_add_test_case strip
    682 	atf_add_test_case var_with_embedded_cmdsub
    683 	atf_add_test_case varpattern_backslashes
    684 }
    685