Home | History | Annotate | Line # | Download | only in sh
t_expand.sh revision 1.16
      1 # $NetBSD: t_expand.sh,v 1.16 2017/06/03 11:23:01 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 varpattern_backslashes
    204 varpattern_backslashes_head() {
    205 	atf_set "descr" "Tests that protecting wildcards with backslashes" \
    206 	                "works in variable patterns."
    207 }
    208 varpattern_backslashes_body() {
    209 	line='/foo/bar/*/baz'
    210 	stripped='/foo/bar/'
    211 	atf_check -o inline:'/foo/bar/\n' -e empty ${TEST_SH} -c \
    212 		'line="/foo/bar/*/baz"; echo ${line%%\**}'
    213 }
    214 
    215 atf_test_case arithmetic
    216 arithmetic_head() {
    217 	atf_set "descr" "POSIX requires shell arithmetic to use signed" \
    218 	                "long or a wider type.  We use intmax_t, so at" \
    219 			"least 64 bits should be available.  Make sure" \
    220 			"this is true."
    221 }
    222 arithmetic_body() {
    223 
    224 	atf_check -o inline:'3' -e empty ${TEST_SH} -c \
    225 		'printf %s $((1 + 2))'
    226 	atf_check -o inline:'2147483647' -e empty ${TEST_SH} -c \
    227 		'printf %s $((0x7fffffff))'
    228 	atf_check -o inline:'9223372036854775807' -e empty ${TEST_SH} -c \
    229 		'printf %s $(((1 << 63) - 1))'
    230 }
    231 
    232 atf_test_case iteration_on_null_parameter
    233 iteration_on_null_parameter_head() {
    234 	atf_set "descr" "Check iteration of \$@ in for loop when set to null;" \
    235 	                "the error \"sh: @: parameter not set\" is incorrect." \
    236 	                "PR bin/48202."
    237 }
    238 iteration_on_null_parameter_body() {
    239 	atf_check -o empty -e empty ${TEST_SH} -c \
    240 		'N=; set -- ${N};   for X; do echo "[$X]"; done'
    241 }
    242 
    243 atf_test_case iteration_on_quoted_null_parameter
    244 iteration_on_quoted_null_parameter_head() {
    245 	atf_set "descr" \
    246 		'Check iteration of "$@" in for loop when set to null;'
    247 }
    248 iteration_on_quoted_null_parameter_body() {
    249 	atf_check -o inline:'[]\n' -e empty ${TEST_SH} -c \
    250 		'N=; set -- "${N}"; for X; do echo "[$X]"; done'
    251 }
    252 
    253 atf_test_case iteration_on_null_or_null_parameter
    254 iteration_on_null_or_null_parameter_head() {
    255 	atf_set "descr" \
    256 		'Check expansion of null parameter as default for another null'
    257 }
    258 iteration_on_null_or_null_parameter_body() {
    259 	atf_check -o empty -e empty ${TEST_SH} -c \
    260 		'N=; E=; set -- ${N:-${E}}; for X; do echo "[$X]"; done'
    261 }
    262 
    263 atf_test_case iteration_on_null_or_missing_parameter
    264 iteration_on_null_or_missing_parameter_head() {
    265 	atf_set "descr" \
    266 	    'Check expansion of missing parameter as default for another null'
    267 }
    268 iteration_on_null_or_missing_parameter_body() {
    269 	# atf_expect_fail 'PR bin/50834'
    270 	atf_check -o empty -e empty ${TEST_SH} -c \
    271 		'N=; set -- ${N:-}; for X; do echo "[$X]"; done'
    272 }
    273 
    274 ####### The remaining tests use the following helper functions ...
    275 
    276 nl='
    277 '
    278 reset()
    279 {
    280 	TEST_NUM=0
    281 	TEST_FAILURES=''
    282 	TEST_FAIL_COUNT=0
    283 	TEST_ID="$1"
    284 }
    285 
    286 check()
    287 {
    288 	fail=false
    289 	TEMP_FILE=$( mktemp OUT.XXXXXX )
    290 	TEST_NUM=$(( $TEST_NUM + 1 ))
    291 	MSG=
    292 
    293 	# our local shell (ATF_SHELL) better do quoting correctly...
    294 	# some of the tests expect us to expand $nl internally...
    295 	CMD="$1"
    296 
    297 	result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" )"
    298 	STATUS=$?
    299 
    300 	if [ "${STATUS}" -ne "$3" ]; then
    301 		MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    302 		MSG="${MSG} expected exit code $3, got ${STATUS}"
    303 
    304 		# don't actually fail just because of wrong exit code
    305 		# unless we either expected, or received "good"
    306 		# or something else is detected as incorrect as well.
    307 		case "$3/${STATUS}" in
    308 		(*/0|0/*) fail=true;;
    309 		esac
    310 	fi
    311 
    312 	if [ "$3" -eq 0 ]; then
    313 		if [ -s "${TEMP_FILE}" ]; then
    314 			MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    315 			MSG="${MSG} Messages produced on stderr unexpected..."
    316 			MSG="${MSG}${nl}$( cat "${TEMP_FILE}" )"
    317 			fail=true
    318 		fi
    319 	else
    320 		if ! [ -s "${TEMP_FILE}" ]; then
    321 			MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    322 			MSG="${MSG} Expected messages on stderr,"
    323 			MSG="${MSG} nothing produced"
    324 			fail=true
    325 		fi
    326 	fi
    327 	rm -f "${TEMP_FILE}"
    328 
    329 	# Remove newlines (use local shell for this)
    330 	oifs="$IFS"
    331 	IFS="$nl"
    332 	result="$(echo $result)"
    333 	IFS="$oifs"
    334 	if [ "$2" != "$result" ]
    335 	then
    336 		MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    337 		MSG="${MSG} Expected output '$2', received '$result'"
    338 		fail=true
    339 	fi
    340 
    341 	if $fail
    342 	then
    343 		MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    344 		MSG="${MSG} Full command: <<${CMD}>>"
    345 	fi
    346 
    347 	$fail && test -n "$TEST_ID" && {
    348 		TEST_FAILURES="${TEST_FAILURES}${TEST_FAILURES:+${nl}}"
    349 		TEST_FAILURES="${TEST_FAILURES}${TEST_ID}[$TEST_NUM]:"
    350 		TEST_FAILURES="${TEST_FAILURES} Test of '$1' failed.";
    351 		TEST_FAILURES="${TEST_FAILURES}${nl}${MSG}"
    352 		TEST_FAIL_COUNT=$(( $TEST_FAIL_COUNT + 1 ))
    353 		return 0
    354 	}
    355 	$fail && atf_fail "Test[$TEST_NUM] failed: $(
    356 	    # ATF does not like newlines in messages, so change them...
    357 		    printf '%s' "${MSG}" | tr '\n' ';'
    358 	    )"
    359 	return 0
    360 }
    361 
    362 results()
    363 {
    364 	test -n "$1" && atf_expect_fail "$1"
    365 
    366 	test -z "${TEST_ID}" && return 0
    367 	test -z "${TEST_FAILURES}" && return 0
    368 
    369 	echo >&2 "=========================================="
    370 	echo >&2 "While testing '${TEST_ID}'"
    371 	echo >&2 " - - - - - - - - - - - - - - - - -"
    372 	echo >&2 "${TEST_FAILURES}"
    373 
    374 	atf_fail \
    375  "Test ${TEST_ID}: $TEST_FAIL_COUNT (of $TEST_NUM) subtests failed - see stderr"
    376 }
    377 
    378 ####### End helpers
    379 
    380 atf_test_case shell_params
    381 shell_params_head() {
    382 	atf_set "descr" "Test correct operation of the numeric parameters"
    383 }
    384 shell_params_body() {
    385 	atf_require_prog mktemp
    386 
    387 	reset shell_params
    388 
    389 	check 'set -- a b c; echo "$#: $1 $2 $3"' '3: a b c' 0
    390 	check 'set -- a b c d e f g h i j k l m; echo "$#: ${1}0 ${10} $10"' \
    391 		'13: a0 j a0' 0
    392 	check 'x="$0"; set -- a b; y="$0";
    393 	      [ "x${x}y" = "x${y}y" ] && echo OK || echo x="$x" y="$y"' \
    394 		'OK' 0
    395 	check "${TEST_SH} -c 'echo 0=\$0 1=\$1 2=\$2' a b c" '0=a 1=b 2=c' 0
    396 
    397 	echo 'echo 0="$0" 1="$1" 2="$2"' > helper.sh
    398 	check "${TEST_SH} helper.sh a b c" '0=helper.sh 1=a 2=b' 0
    399 
    400 	check 'set -- a bb ccc dddd eeeee ffffff ggggggg hhhhhhhh \
    401 		iiiiiiiii jjjjjjjjjj kkkkkkkkkkk
    402 	       echo "${#}: ${#1} ${#2} ${#3} ${#4} ... ${#9} ${#10} ${#11}"' \
    403 		 '11: 1 2 3 4 ... 9 10 11' 0
    404 
    405 	check 'set -- a b c; echo "$#: ${1-A} ${2-B} ${3-C} ${4-D} ${5-E}"' \
    406 		'3: a b c D E' 0
    407 	check 'set -- a "" c "" e
    408 	       echo "$#: ${1:-A} ${2:-B} ${3:-C} ${4:-D} ${5:-E}"' \
    409 		'5: a B c D e' 0
    410 	check 'set -- a "" c "" e
    411 	       echo "$#: ${1:+A} ${2:+B} ${3:+C} ${4:+D} ${5:+E}"' \
    412 		'5: A  C  E' 0
    413 	check 'set -- "abab*cbb"
    414 	       echo "${1} ${1#a} ${1%b} ${1##ab} ${1%%b} ${1#*\*} ${1%\**}"' \
    415 	       'abab*cbb bab*cbb abab*cb ab*cbb abab*cb cbb abab' 0
    416 	check 'set -- "abab?cbb"
    417     echo "${1}:${1#*a}+${1%b*}-${1##*a}_${1%%b*}%${1#[ab]}=${1%?*}/${1%\?*}"' \
    418 	       'abab?cbb:bab?cbb+abab?cb-b?cbb_a%bab?cbb=abab?cb/abab' 0
    419 	check 'set -- a "" c "" e; echo "${2:=b}"' '' 1
    420 
    421 	check 'set -- a b c d; echo ${4294967297}' '' 0  # result 'a' => ${1}
    422 	check 'set -- a b c; echo ${01}' 'a' 0
    423 	check "${TEST_SH} -c 'echo 0=\${00} 1=\${01} 2=\${02}' a b c" \
    424 			'0=a 1=b 2=c' 0
    425 
    426 	# by special request, for PaulG...  (${0...} is not octal!)
    427 	check \
    428 	    'set -- a b c d e f g h i j k l m; echo "$#: ${08} ${010} ${011}"' \
    429 		'13: h j k' 0
    430 
    431 	results
    432 }
    433 
    434 atf_test_case var_with_embedded_cmdsub
    435 var_with_embedded_cmdsub_head() {
    436 	atf_set "descr" "Test expansion of vars with embedded cmdsub"
    437 }
    438 var_with_embedded_cmdsub_body() {
    439 
    440 	reset var_with_embedded_cmdsub
    441 
    442 	check 'unset x; echo ${x-$(echo a)}$(echo b)'  'ab' 0	#1
    443 	check 'unset x; echo ${x:-$(echo a)}$(echo b)' 'ab' 0	#2
    444 	check 'x=""; echo ${x-$(echo a)}$(echo b)'     'b'  0	#3
    445 	check 'x=""; echo ${x:-$(echo a)}$(echo b)'    'ab' 0	#4
    446 	check 'x=c; echo ${x-$(echo a)}$(echo b)'      'cb' 0	#5
    447 	check 'x=c; echo ${x:-$(echo a)}$(echo b)'     'cb' 0	#6
    448 
    449 	check 'unset x; echo ${x+$(echo a)}$(echo b)'  'b'  0	#7
    450 	check 'unset x; echo ${x:+$(echo a)}$(echo b)' 'b'  0	#8
    451 	check 'x=""; echo ${x+$(echo a)}$(echo b)'     'ab' 0	#9
    452 	check 'x=""; echo ${x:+$(echo a)}$(echo b)'    'b'  0	#10
    453 	check 'x=c; echo ${x+$(echo a)}$(echo b)'      'ab' 0	#11
    454 	check 'x=c; echo ${x:+$(echo a)}$(echo b)'     'ab' 0	#12
    455 
    456 	check 'unset x; echo ${x=$(echo a)}$(echo b)'  'ab' 0	#13
    457 	check 'unset x; echo ${x:=$(echo a)}$(echo b)' 'ab' 0	#14
    458 	check 'x=""; echo ${x=$(echo a)}$(echo b)'     'b'  0	#15
    459 	check 'x=""; echo ${x:=$(echo a)}$(echo b)'    'ab' 0	#16
    460 	check 'x=c; echo ${x=$(echo a)}$(echo b)'      'cb' 0	#17
    461 	check 'x=c; echo ${x:=$(echo a)}$(echo b)'     'cb' 0	#18
    462 
    463 	check 'unset x; echo ${x?$(echo a)}$(echo b)'  ''   2	#19
    464 	check 'unset x; echo ${x:?$(echo a)}$(echo b)' ''   2	#20
    465 	check 'x=""; echo ${x?$(echo a)}$(echo b)'     'b'  0	#21
    466 	check 'x=""; echo ${x:?$(echo a)}$(echo b)'    ''   2	#22
    467 	check 'x=c; echo ${x?$(echo a)}$(echo b)'      'cb' 0	#23
    468 	check 'x=c; echo ${x:?$(echo a)}$(echo b)'     'cb' 0	#24
    469 
    470 	check 'unset x; echo ${x%$(echo a)}$(echo b)'  'b'  0	#25
    471 	check 'unset x; echo ${x%%$(echo a)}$(echo b)' 'b'  0	#26
    472 	check 'x=""; echo ${x%$(echo a)}$(echo b)'     'b'  0	#27
    473 	check 'x=""; echo ${x%%$(echo a)}$(echo b)'    'b'  0	#28
    474 	check 'x=c; echo ${x%$(echo a)}$(echo b)'      'cb' 0	#29
    475 	check 'x=c; echo ${x%%$(echo a)}$(echo b)'     'cb' 0	#30
    476 	check 'x=aa; echo ${x%$(echo "*a")}$(echo b)'  'ab' 0	#31
    477 	check 'x=aa; echo ${x%%$(echo "*a")}$(echo b)' 'b'  0	#32
    478 
    479 	check 'unset x; echo ${x#$(echo a)}$(echo b)'  'b'  0	#33
    480 	check 'unset x; echo ${x##$(echo a)}$(echo b)' 'b'  0	#34
    481 	check 'x=""; echo ${x#$(echo a)}$(echo b)'     'b'  0	#35
    482 	check 'x=""; echo ${x##$(echo a)}$(echo b)'    'b'  0	#36
    483 	check 'x=c; echo ${x#$(echo a)}$(echo b)'      'cb' 0	#37
    484 	check 'x=c; echo ${x##$(echo a)}$(echo b)'     'cb' 0	#38
    485 	check 'x=aa; echo ${x#$(echo "*a")}$(echo b)'  'ab' 0	#39
    486 	check 'x=aa; echo ${x##$(echo "*a")}$(echo b)' 'b'  0	#40
    487 
    488 	results
    489 }
    490 
    491 atf_test_case dollar_hash
    492 dollar_hash_head() {
    493 	atf_set "descr" 'Test expansion of various aspects of $#'
    494 }
    495 dollar_hash_body() {
    496 
    497 #
    498 #	$# looks like it should be so simple that it doesn't really
    499 #	need a test of its own, and used in that way, it really doesn't.
    500 #	But when we add braces ${#} we need to deal with the three
    501 #	(almost 4) different meanings of a # inside a ${} expansion...
    502 #
    503 #	Note that some of these are just how we treat expansions that
    504 #	are unspecified by posix (as noted below.)
    505 #	
    506 #		1.   ${#} is just $# (number of params)
    507 #		1.a	${\#} is nothing at all (error: invalid expansion)
    508 #		1.b	${\#...} (anything after) is the same (invalid)
    509 #		2.   ${#VAR} is the length of the value VAR
    510 #		2.a	Including ${##} - the length of ${#}
    511 #		3    ${VAR#pat} is the value of VAR with leading pat removed
    512 #		3.a	Including ${VAR#} which just removes leading nothing
    513 #			This is relevant in case of ${VAR#${X}} with X=''
    514 #				nb: not required by posix, see XCU 2.6.2
    515 #		3.b	${##} is not a case of 3.a but rather 2.a 
    516 #		3.c	Yet ${##pat} is a case of 3.a
    517 #			Including ${##${X}} where X='' or X='#'
    518 #				nb: not required by posix, see XCU 2.6.2
    519 #		3.d	And ${#\#} is invalid (error)
    520 #		3.e	But ${##\#} removes a leading # from the value of $#
    521 #			(so is just $# as there is no leading # there)
    522 #				nb: not required by posix, see XCU 2.6.2
    523 #		4    ${VAR##pat} is the value of VAR with longest pat removed
    524 #		4.a	Including ${VAR##} which removes the longest nothing
    525 #		4.b	Which in this case includes ${###} (so is == $#)
    526 #				nb: not required by posix, see XCU 2.6.2
    527 #		4.c	But not ${##\#} which is $# with a leading '#' removed
    528 #			(and so is also == $#), i.e.: like ${###} but different.
    529 #				nb: not required by posix, see XCU 2.6.2
    530 #		4.d	As is ${###\#} or just ${####} - remove  # (so just $#)
    531 #				nb: not required by posix, see XCU 2.6.2
    532 #
    533 
    534 	reset dollar_hash
    535 
    536 	check 'set -- ; echo $#'			'0'		0  # 1
    537 	check 'set -- a b c; echo $#'			'3'		0  # 2
    538 	check 'set -- a b c d e f g h i j; echo $#'	'10'		0  # 3
    539 # rule 1
    540 	check 'set -- ; echo ${#}'			'0'		0  # 4
    541 	check 'set -- a b c; echo ${#}'			'3'		0  # 5
    542 	check 'set -- a b c d e f g h i j; echo ${#}'	'10'		0  # 6
    543 # rule 1.a
    544 	check 'set -- a b c; echo ${\#}'		''		2  # 7
    545 # rule 1.b
    546 	check 'set -- a b c; echo ${\#:-foo}'		''		2  # 8
    547 # rule 2
    548 	check 'VAR=12345; echo ${#VAR}'			'5'		0  # 9
    549 	check 'VAR=123456789012; echo ${#VAR}'		'12'		0  #10
    550 # rule 2.a
    551 	check 'set -- ; echo ${##}'			'1'		0  #11
    552 	check 'set -- a b c; echo ${##}'		'1'		0  #12
    553 	check 'set -- a b c d e f g h i j; echo ${##}'	'2'		0  #13
    554 # rule 3
    555 	check 'VAR=12345; echo ${VAR#1}'		'2345'		0  #14
    556 	check 'VAR=12345; echo ${VAR#2}'		'12345'		0  #15
    557 	check 'VAR=#2345; echo ${VAR#\#}'		'2345'		0  #16
    558 	check 'X=1; VAR=12345; echo ${VAR#${X}}'	'2345'		0  #17
    559 	check 'X=1; VAR=#2345; echo ${VAR#${X}}'	'#2345'		0  #18
    560 # rule 3.a
    561 	check 'VAR=12345; echo ${VAR#}'			'12345'		0  #19
    562 	check 'X=; VAR=12345; echo ${VAR#${X}}'		'12345'		0  #20
    563 # rule 3.b (tested above, rule 2.a)
    564 # rule 3.c
    565 	check 'set -- ; echo ${##0}'			''		0  #21
    566 	check 'set -- a b c; echo ${##1}'		'3'		0  #22
    567 	check 'set -- a b c d e f g h i j; echo ${##1}'	'0'		0  #23
    568 	check 'X=0; set -- ; echo ${##${X}}'		''		0  #24
    569 	check 'X=; set -- ; echo ${##${X}}'		'0'		0  #25
    570 	check 'X=1; set -- a b c; echo ${##${X}}'	'3'		0  #26
    571 	check 'X=1; set -- a b c d e f g h i j; echo ${##${X}}'	'0'	0  #27
    572 	check 'X=; set -- a b c d e f g h i j; echo ${##${X}}'	'10'	0  #28
    573 	check 'X=#; VAR=#2345; echo ${VAR#${X}}'	'2345'		0  #29
    574 	check 'X=#; VAR=12345; echo ${VAR#${X}}'	'12345'		0  #30
    575 # rule 3.d
    576 	check 'set -- a b c; echo ${#\#}'		''		2  #31
    577 # rule 3.e
    578 	check 'set -- ; echo ${##\#}'			'0'		0  #32
    579 	check 'set -- a b c d e f g h i j; echo ${##\#}' '10'		0  #33
    580 
    581 # rule 4
    582 	check 'VAR=12345; echo ${VAR##1}'		'2345'		0  #34
    583 	check 'VAR=12345; echo ${VAR##\1}'		'2345'		0  #35
    584 # rule 4.a
    585 	check 'VAR=12345; echo ${VAR##}'		'12345'		0  #36
    586 # rule 4.b
    587 	check 'set -- ; echo ${###}'			'0'		0  #37
    588 	check 'set -- a b c d e f g h i j; echo ${###}'	'10'		0  #38
    589 # rule 4.c
    590 	check 'VAR=12345; echo ${VAR#\#}'		'12345'		0  #39
    591 	check 'VAR=12345; echo ${VAR#\#1}'		'12345'		0  #40
    592 	check 'VAR=#2345; echo ${VAR#\#}'		'2345'		0  #41
    593 	check 'VAR=#12345; echo ${VAR#\#1}'		'2345'		0  #42
    594 	check 'VAR=#2345; echo ${VAR#\#1}'		'#2345'		0  #43
    595 	check 'set -- ; echo ${####}'			'0'		0  #44
    596 	check 'set -- ; echo ${###\#}'			'0'		0  #45
    597 	check 'set -- a b c d e f g h i j; echo ${####}' '10'		0  #46
    598 	check 'set -- a b c d e f g h i j; echo ${###\#}' '10'		0  #47
    599 
    600 # now check for some more utter nonsense, not mentioned in the rules
    601 # above (doesn't need to be)
    602 
    603 	check 'x=hello; set -- a b c; echo ${#x:-1}'	''		2  #48
    604 	check 'x=hello; set -- a b c; echo ${#x-1}'	''		2  #49
    605 	check 'x=hello; set -- a b c; echo ${#x:+1}'	''		2  #50
    606 	check 'x=hello; set -- a b c; echo ${#x+1}'	''		2  #51
    607 	check 'x=hello; set -- a b c; echo ${#x+1}'	''		2  #52
    608 	check 'x=hello; set -- a b c; echo ${#x:?msg}'	''		2  #53
    609 	check 'x=hello; set -- a b c; echo ${#x?msg}'	''		2  #54
    610 	check 'x=hello; set -- a b c; echo ${#x:=val}'	''		2  #55
    611 	check 'x=hello; set -- a b c; echo ${#x=val}'	''		2  #56
    612 	check 'x=hello; set -- a b c; echo ${#x#h}'	''		2  #57
    613 	check 'x=hello; set -- a b c; echo ${#x#*l}'	''		2  #58
    614 	check 'x=hello; set -- a b c; echo ${#x##*l}'	''		2  #59
    615 	check 'x=hello; set -- a b c; echo ${#x%o}'	''		2  #60
    616 	check 'x=hello; set -- a b c; echo ${#x%l*}'	''		2  #61
    617 	check 'x=hello; set -- a b c; echo ${#x%%l*}'	''		2  #62
    618 
    619 # but just to be complete, these ones should work
    620 
    621 	check 'x=hello; set -- a b c; echo ${#%5}'	'3'		0  #63
    622 	check 'x=hello; set -- a b c; echo ${#%3}'	''		0  #64
    623 	check 'x=hello; set -- a b c; echo ${#%?}'	''		0  #65
    624 	check 'X=#; set -- a b c; echo ${#%${X}}'	'3'		0  #66
    625 	check 'X=3; set -- a b c; echo ${#%${X}}'	''		0  #67
    626 	check 'set -- a b c; echo ${#%%5}'		'3'		0  #68
    627 	check 'set -- a b c; echo ${#%%3}'		''		0  #69
    628 	check 'set -- a b c d e f g h i j k l; echo ${#%1}' '12'	0  #70
    629 	check 'set -- a b c d e f g h i j k l; echo ${#%2}' '1'		0  #71
    630 	check 'set -- a b c d e f g h i j k l; echo ${#%?}' '1'		0  #72
    631 	check 'set -- a b c d e f g h i j k l; echo ${#%[012]}' '1'	0  #73
    632 	check 'set -- a b c d e f g h i j k l; echo ${#%[0-4]}' '1'	0  #74
    633 	check 'set -- a b c d e f g h i j k l; echo ${#%?2}' ''		0  #75
    634 	check 'set -- a b c d e f g h i j k l; echo ${#%1*}' ''		0  #76
    635 	check 'set -- a b c d e f g h i j k l; echo ${#%%2}' '1'	0  #77
    636 	check 'set -- a b c d e f g h i j k l; echo ${#%%1*}' ''	0  #78
    637 
    638 # and this lot are stupid, as $# is never unset or null, but they do work...
    639 
    640 	check 'set -- a b c; echo ${#:-99}'		'3'		0  #79
    641 	check 'set -- a b c; echo ${#-99}'		'3'		0  #80
    642 	check 'set -- a b c; echo ${#:+99}'		'99'		0  #81
    643 	check 'set -- a b c; echo ${#+99}'		'99'		0  #82
    644 	check 'set -- a b c; echo ${#:?bogus}'		'3'		0  #83
    645 	check 'set -- a b c; echo ${#?bogus}'		'3'		0  #84
    646 
    647 # even this utter nonsense is OK, as while special params cannot be
    648 # set this way, here, as $# is not unset, or null, the assignment
    649 # never happens (isn't even attempted)
    650 
    651 	check 'set -- a b c; echo ${#:=bogus}'		'3'		0  #85
    652 	check 'set -- a b c; echo ${#=bogus}'		'3'		0  #86
    653 
    654 	for n in 0 1 10 25 100				#87 #88 #89 #90 #91
    655 	do
    656 		check "(exit $n)"'; echo ${#?}'		"${#n}"		0
    657 	done
    658 
    659 	results		# results so far anyway...
    660 
    661 # now we have some harder to verify cases, as they (must) check unknown values
    662 # and hence the resuls cannot just be built into the script, but we have
    663 # to use some tricks to validate them, so for these, just do regular testing
    664 # and don't attempt to use the check helper function, nor to include
    665 # these tests in the result summary.   If anything has already failed, we
    666 # do not get this far...   From here on, first failure ends this test.
    667 
    668 	for opts in '' '-a' '-au' '-auf' '-aufe' # options safe enough to set
    669 	do
    670 		# Note the shell might have other (or these) opts set already
    671 
    672 		RES=$(${TEST_SH} -c "test -n '${opts}' && set ${opts};
    673 			printf '%s' \"\$-\";printf ' %s\\n' \"\${#-}\"") ||
    674 			atf_fail '${#-} test exited with status '"$?"
    675 		LEN="${RES##* }"
    676 		DMINUS="${RES% ${LEN}}"
    677 		if [ "${#DMINUS}" != "${LEN}" ]
    678 		then
    679 			atf_fail \
    680 		   '${#-} test'" produced ${LEN} for opts ${DMINUS} (${RES})"
    681 		fi
    682 	done
    683 
    684 	for seq in a b c d e f g h i j
    685 	do
    686 		# now we are tryin to generate different pids for $$ and $!
    687 		# so we just run the test a number of times, and hope...
    688 		# On NetBSD pid randomisation will usually help the tests
    689 
    690 		eval "$(${TEST_SH} -c \
    691 		    '(exit 0)& BG=$! LBG=${#!};
    692 	    printf "SH=%s BG=%s LSH=%s LBG=%s" "$$" "$BG" "${#$}" "$LBG";
    693 		      wait')"
    694 
    695 		if [ "${#SH}" != "${LSH}" ] || [ "${#BG}" != "${LBG}" ]
    696 		then
    697 			atf_fail \
    698 	'${#!] of '"${BG} was ${LBG}, expected ${#BG}"'; ${#$} of '"${SH} was ${LSH}, expected ${#SH}"
    699 		fi
    700 	done
    701 }
    702 
    703 atf_test_case dollar_star
    704 dollar_star_head() {
    705 	atf_set "descr" 'Test expansion of various aspects of $*'
    706 }
    707 dollar_star_body() {
    708 
    709 	reset dollar_star
    710 
    711 	check 'set -- a b c; echo $# $*'		'3 a b c'	0  # 1
    712 	check 'set -- a b c; echo $# "$*"'		'3 a b c'	0  # 2
    713 	check 'set -- a "b c"; echo $# $*'		'2 a b c'	0  # 3
    714 	check 'set -- a "b c"; echo $# "$*"'		'2 a b c'	0  # 4
    715 	check 'set -- a b c; set -- $* ; echo $# $*'	'3 a b c'	0  # 5
    716 	check 'set -- a b c; set -- "$*" ; echo $# $*'	'1 a b c'	0  # 6
    717 	check 'set -- a "b c"; set -- $* ; echo $# $*'	'3 a b c'	0  # 7
    718 	check 'set -- a "b c"; set -- "$*" ; echo $# $*' \
    719 							'1 a b c'	0  # 8
    720 
    721 	check 'IFS=". "; set -- a b c; echo $# $*'	'3 a b c'	0  # 9
    722 	check 'IFS=". "; set -- a b c; echo $# "$*"'	'3 a.b.c'	0  #10
    723 	check 'IFS=". "; set -- a "b c"; echo $# $*'	'2 a b c'	0  #11
    724 	check 'IFS=". "; set -- a "b c"; echo $# "$*"'	'2 a.b c'	0  #12
    725 	check 'IFS=". "; set -- a "b.c"; echo $# $*'	'2 a b c'	0  #13
    726 	check 'IFS=". "; set -- a "b.c"; echo $# "$*"'	'2 a.b.c'	0  #14
    727 	check 'IFS=". "; set -- a b c; set -- $* ; echo $# $*' \
    728 							'3 a b c'	0  #15
    729 	check 'IFS=". "; set -- a b c; set -- "$*" ; echo $# $*' \
    730 							'1 a b c'	0  #16
    731 	check 'IFS=". "; set -- a "b c"; set -- $* ; echo $# $*' \
    732 							'3 a b c'	0  #17
    733 	check 'IFS=". "; set -- a "b c"; set -- "$*" ; echo $# $*' \
    734 							'1 a b c'	0  #18
    735 	check 'IFS=". "; set -- a b c; set -- $* ; echo $# "$*"' \
    736 							'3 a.b.c'	0  #19
    737 	check 'IFS=". "; set -- a b c; set -- "$*" ; echo $# "$*"' \
    738 							'1 a.b.c'	0  #20
    739 	check 'IFS=". "; set -- a "b c"; set -- $* ; echo $# "$*"' \
    740 							'3 a.b.c'	0  #21
    741 	check 'IFS=". "; set -- a "b c"; set -- "$*" ; echo $# "$*"' \
    742 							'1 a.b c'	0  #22
    743 
    744 	results
    745 }
    746 
    747 atf_test_case dollar_star_in_word
    748 dollar_star_in_word_head() {
    749 	atf_set "descr" 'Test expansion $* occurring in word of ${var:-word}'
    750 }
    751 dollar_star_in_word_body() {
    752 
    753 	reset dollar_star_in_word
    754 
    755 	unset xXx			; # just in case!
    756 
    757 	# Note that the expected results for these tests are identical
    758 	# to those from the dollar_star test.   It should never make
    759 	# a difference whether we expand $* or ${unset:-$*}
    760 
    761 	# (note expanding ${unset:-"$*"} is different, that is not tested here)
    762 
    763 	check 'set -- a b c; echo $# ${xXx:-$*}'		'3 a b c' 0  # 1
    764 	check 'set -- a b c; echo $# "${xXx:-$*}"'		'3 a b c' 0  # 2
    765 	check 'set -- a "b c"; echo $# ${xXx:-$*}'		'2 a b c' 0  # 3
    766 	check 'set -- a "b c"; echo $# "${xXx:-$*}"'		'2 a b c' 0  # 4
    767 	check 'set -- a b c; set -- ${xXx:-$*} ; echo $# $*'	'3 a b c' 0  # 5
    768 	check 'set -- a b c; set -- "${xXx:-$*}" ; echo $# $*'	'1 a b c' 0  # 6
    769 	check 'set -- a "b c"; set -- ${xXx:-$*} ; echo $# $*'	'3 a b c' 0  # 7
    770 	check 'set -- a "b c"; set -- "${xXx:-$*}" ; echo $# $*' \
    771 								'1 a b c' 0  # 8
    772 
    773 	check 'IFS=". "; set -- a b c; echo $# ${xXx:-$*}'	'3 a b c' 0  # 9
    774 	check 'IFS=". "; set -- a b c; echo $# "${xXx:-$*}"'	'3 a.b.c' 0  #10
    775 	check 'IFS=". "; set -- a "b c"; echo $# ${xXx:-$*}'	'2 a b c' 0  #11
    776 	check 'IFS=". "; set -- a "b c"; echo $# "${xXx:-$*}"'	'2 a.b c' 0  #12
    777 	check 'IFS=". "; set -- a "b.c"; echo $# ${xXx:-$*}'	'2 a b c' 0  #13
    778 	check 'IFS=". "; set -- a "b.c"; echo $# "${xXx:-$*}"'	'2 a.b.c' 0  #14
    779 	check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
    780 								'3 a b c' 0  #15
    781 	check 'IFS=". ";set -- a b c;set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
    782 								'1 a b c' 0  #16
    783 	check 'IFS=". ";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
    784 								'3 a b c' 0  #17
    785 	check 'IFS=". ";set -- a "b c";set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
    786 								'1 a b c' 0  #18
    787 	check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
    788 								'3 a.b.c' 0  #19
    789 	check 'IFS=". ";set -- a b c;set -- "$*";echo $# "$*"' \
    790 								'1 a.b.c' 0  #20
    791 	check 'IFS=". ";set -- a "b c";set -- $*;echo $# "$*"' \
    792 								'3 a.b.c' 0  #21
    793 	check 'IFS=". ";set -- a "b c";set -- "$*";echo $# "$*"' \
    794 								'1 a.b c' 0  #22
    795 
    796 	results
    797 }
    798 
    799 atf_test_case dollar_star_with_empty_ifs
    800 dollar_star_with_empty_ifs_head() {
    801 	atf_set "descr" 'Test expansion of $* with IFS=""'
    802 }
    803 dollar_star_with_empty_ifs_body() {
    804 
    805 	reset dollar_star_with_empty_ifs
    806 
    807 	check 'IFS=""; set -- a b c; echo $# $*'	'3 a b c'	0  # 1
    808 	check 'IFS=""; set -- a b c; echo $# "$*"'	'3 abc'		0  # 2
    809 	check 'IFS=""; set -- a "b c"; echo $# $*'	'2 a b c'	0  # 3
    810 	check 'IFS=""; set -- a "b c"; echo $# "$*"'	'2 ab c'	0  # 4
    811 	check 'IFS=""; set -- a "b.c"; echo $# $*'	'2 a b.c'	0  # 5
    812 	check 'IFS=""; set -- a "b.c"; echo $# "$*"'	'2 ab.c'	0  # 6
    813 	check 'IFS=""; set -- a b c; set -- $* ; echo $# $*' \
    814 							'3 a b c'	0  # 7
    815 	check 'IFS=""; set -- a b c; set -- "$*" ; echo $# $*' \
    816 							'1 abc'		0  # 8
    817 	check 'IFS=""; set -- a "b c"; set -- $* ; echo $# $*' \
    818 							'2 a b c'	0  # 9
    819 	check 'IFS=""; set -- a "b c"; set -- "$*" ; echo $# $*' \
    820 							'1 ab c'	0  #10
    821 	check 'IFS=""; set -- a b c; set -- $* ; echo $# "$*"' \
    822 							'3 abc'		0  #11
    823 	check 'IFS=""; set -- a b c; set -- "$*" ; echo $# "$*"' \
    824 							'1 abc'		0  #12
    825 	check 'IFS=""; set -- a "b c"; set -- $* ; echo $# "$*"' \
    826 							'2 ab c'	0  #13
    827 	check 'IFS=""; set -- a "b c"; set -- "$*" ; echo $# "$*"' \
    828 							'1 ab c'	0  #14
    829 
    830 	results	  # FIXED: 'PR bin/52090 expect 7 of 14 subtests to fail'
    831 }
    832 
    833 atf_test_case dollar_star_in_word_empty_ifs
    834 dollar_star_in_word_empty_ifs_head() {
    835 	atf_set "descr" 'Test expansion of ${unset:-$*} with IFS=""'
    836 }
    837 dollar_star_in_word_empty_ifs_body() {
    838 
    839 	reset dollar_star_in_word_empty_ifs
    840 
    841 	unset xXx			; # just in case
    842 
    843 	# Note that the expected results for these tests are identical
    844 	# to those from the dollar_star_with_empty_ifs test.   It should
    845 	# never make a difference whether we expand $* or ${unset:-$*}
    846 
    847 	# (note expanding ${unset:-"$*"} is different, that is not tested here)
    848 
    849 	check 'IFS="";set -- a b c;echo $# ${xXx:-$*}'		'3 a b c' 0  # 1
    850 	check 'IFS="";set -- a b c;echo $# "${xXx:-$*}"'	'3 abc'	  0  # 2
    851 	check 'IFS="";set -- a "b c";echo $# ${xXx:-$*}'	'2 a b c' 0  # 3
    852 	check 'IFS="";set -- a "b c";echo $# "${xXx:-$*}"'	'2 ab c'  0  # 4
    853 	check 'IFS="";set -- a "b.c";echo $# ${xXx:-$*}'	'2 a b.c' 0  # 5
    854 	check 'IFS="";set -- a "b.c";echo $# "${xXx:-$*}"'	'2 ab.c'  0  # 6
    855 	check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
    856 								'3 a b c' 0  # 7
    857 	check 'IFS="";set -- a b c;set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
    858 								'1 abc'   0  # 8
    859 	check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
    860 								'2 a b c' 0  # 9
    861 	check 'IFS="";set -- a "b c";set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
    862 								'1 ab c'  0  #10
    863 	check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
    864 								'3 abc'	  0  #11
    865 	check 'IFS="";set -- a b c;set -- "${xXx:-$*}";echo $# "${xXx:-$*}"' \
    866 								'1 abc'	  0  #12
    867 	check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
    868 								'2 ab c'  0  #13
    869 	check 'IFS="";set -- a "b c";set -- "${xXx:-$*}";echo $# "${xXx:-$*}"' \
    870 								'1 ab c'  0  #14
    871 
    872 	results	  # FIXED: 'PR bin/52090 expect 7 of 14 subtests to fail'
    873 }
    874 
    875 atf_test_case dollar_star_in_quoted_word
    876 dollar_star_in_quoted_word_head() {
    877 	atf_set "descr" 'Test expansion $* occurring in word of ${var:-"word"}'
    878 }
    879 dollar_star_in_quoted_word_body() {
    880 
    881 	reset dollar_star_in_quoted_word
    882 
    883 	unset xXx			; # just in case!
    884 
    885 	check 'set -- a b c; echo $# ${xXx:-"$*"}'		'3 a b c' 0  # 1
    886 	check 'set -- a "b c"; echo $# ${xXx:-"$*"}'		'2 a b c' 0  # 2
    887 	check 'set -- a b c; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
    888 								'1 a b c' 0  # 3
    889 	check 'set -- a "b c"; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
    890 								'1 a b c' 0  # 4
    891 	check 'set -- a b c; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
    892 								'1 a b c' 0  # 5
    893 	check 'set -- a "b c"; set -- ${xXx:-"$*"} ; echo $# ${xXx-$*}' \
    894 								'1 a b c' 0  # 6
    895 	check 'set -- a b c; set -- ${xXx:-$*} ; echo $# ${xXx-"$*"}' \
    896 								'3 a b c' 0  # 7
    897 	check 'set -- a "b c"; set -- ${xXx:-$*} ; echo $# ${xXx-"$*"}' \
    898 								'3 a b c' 0  # 8
    899 
    900 	check 'IFS=". "; set -- a b c; echo $# ${xXx:-"$*"}'	'3 a.b.c' 0  # 9
    901 	check 'IFS=". "; set -- a "b c"; echo $# ${xXx:-"$*"}'	'2 a.b c' 0  #10
    902 	check 'IFS=". "; set -- a "b.c"; echo $# ${xXx:-"$*"}'	'2 a.b.c' 0  #11
    903 	check 'IFS=". ";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
    904 								'1 a.b.c' 0  #12
    905       check 'IFS=". ";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
    906 								'1 a.b c' 0  #13
    907 	check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
    908 								'3 a.b.c' 0  #14
    909 	check 'IFS=". ";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
    910 								'3 a.b.c' 0  #15
    911 	check 'IFS=". ";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
    912 								'1 a b c' 0  #16
    913 	check 'IFS=". ";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
    914 								'1 a b c' 0  #17
    915 
    916 	check 'IFS="";set -- a b c;echo $# ${xXx:-"$*"}'	'3 abc'   0  #18
    917 	check 'IFS="";set -- a "b c";echo $# ${xXx:-"$*"}'	'2 ab c'  0  #19
    918 	check 'IFS="";set -- a "b.c";echo $# ${xXx:-"$*"}'	'2 ab.c'  0  #20
    919 	check 'IFS="";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
    920 								'1 abc'   0  #21
    921 	check 'IFS="";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
    922 								'1 ab c'  0  #22
    923 	check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
    924 								'3 abc'   0  #23
    925 	check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
    926 								'2 ab c'  0  #24
    927 	check 'IFS="";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
    928 								'1 abc'   0  #25
    929 	check 'IFS="";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
    930 								'1 ab c'  0  #26
    931 
    932 	results	  # FIXED: 'PR bin/52090 - 2 of 26 subtests expected to fail'
    933 }
    934 
    935 atf_init_test_cases() {
    936 	# Listed here in the order ATF runs them, not the order from above
    937 
    938 	atf_add_test_case arithmetic
    939 	atf_add_test_case dollar_at
    940 	atf_add_test_case dollar_at_with_text
    941 	atf_add_test_case dollar_hash
    942 	atf_add_test_case dollar_star
    943 	atf_add_test_case dollar_star_in_quoted_word
    944 	atf_add_test_case dollar_star_in_word
    945 	atf_add_test_case dollar_star_in_word_empty_ifs
    946 	atf_add_test_case dollar_star_with_empty_ifs
    947 	atf_add_test_case iteration_on_null_parameter
    948 	atf_add_test_case iteration_on_quoted_null_parameter
    949 	atf_add_test_case iteration_on_null_or_null_parameter
    950 	atf_add_test_case iteration_on_null_or_missing_parameter
    951 	atf_add_test_case shell_params
    952 	atf_add_test_case strip
    953 	atf_add_test_case wrap_strip
    954 	atf_add_test_case var_with_embedded_cmdsub
    955 	atf_add_test_case varpattern_backslashes
    956 }
    957