Home | History | Annotate | Line # | Download | only in sh
t_expand.sh revision 1.22
      1 # $NetBSD: t_expand.sh,v 1.22 2019/05/04 02:52:22 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_unquoted_or_conditional
     67 dollar_at_unquoted_or_conditional_head() {
     68 	atf_set descr 'Sometime during 2013 the expansion of "${1+$@}"' \
     69 			' (where $1 and $2 (and maybe more) are set)' \
     70 			' seems to have broken.  Check for this bug.'
     71 }
     72 dollar_at_unquoted_or_conditional_body() {
     73 
     74 	atf_check -s exit:0 -o inline:'a\na\nb\nb\n' -e empty \
     75 		${TEST_SH} -c 'set -- "a a" "b b"; printf %s\\n $@'
     76 	atf_check -s exit:0 -o inline:'a\na\nb\nb\n' -e empty \
     77 		${TEST_SH} -c 'set -- "a a" "b b"; printf %s\\n ${1+$@}'
     78 	atf_check -s exit:0 -o inline:'a a\nb b\n' -e empty \
     79 		${TEST_SH} -c 'set -- "a a" "b b"; printf %s\\n "$@"'
     80 	atf_check -s exit:0 -o inline:'a a\nb b\n' -e empty \
     81 		${TEST_SH} -c 'set -- "a a" "b b"; printf %s\\n ${1+"$@"}'
     82 
     83 	# This is the one that fails when the bug is present
     84 	atf_check -s exit:0 -o inline:'a a\nb b\n' -e empty \
     85 		${TEST_SH} -c 'set -- "a a" "b b"; printf %s\\n "${1+$@}"'
     86 }
     87 
     88 atf_test_case dollar_at_with_text
     89 dollar_at_with_text_head() {
     90 	atf_set descr "Test \$@ expansion when it is surrounded by text" \
     91 	                "within the quotes.  PR bin/33956."
     92 }
     93 dollar_at_with_text_body() {
     94 
     95 	cat <<'EOF' > h-f1
     96 
     97 delim_argv() {
     98 	str=
     99 	while [ $# -gt 0 ]; do
    100 		if [ -z "${str}" ]; then
    101 			str=">$1<"
    102 		else
    103 			str="${str} >$1<"
    104 		fi
    105 		shift
    106 	done
    107 	echo "${str}"
    108 }
    109 
    110 EOF
    111 	cat <<'EOF' > h-f2
    112 
    113 delim_argv() {
    114 	str=
    115 	while [ $# -gt 0 ]; do
    116 
    117 		str="${str}${str:+ }>$1<"
    118 		shift
    119 
    120 	done
    121 	echo "${str}"
    122 }
    123 
    124 EOF
    125 
    126 	chmod +x h-f1 h-f2
    127 
    128 	for f in 1 2
    129 	do
    130 		atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
    131 			". ./h-f${f}; "'set -- ; delim_argv $@'
    132 		atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
    133 			". ./h-f${f}; "'set -- ; delim_argv "$@"'
    134 		atf_check -s exit:0 -o inline:'>foobar<\n' -e empty \
    135 			${TEST_SH} -c \
    136 			". ./h-f${f}; "'set -- ; delim_argv "foo$@bar"'
    137 		atf_check -s exit:0 -o inline:'>foobar<\n' -e empty \
    138 			${TEST_SH} -c \
    139 			". ./h-f${f}; "'set -- ; delim_argv foo"$@"bar'
    140 		atf_check -s exit:0 -o inline:'>foo  bar<\n' -e empty \
    141 			${TEST_SH} -c \
    142 			". ./h-f${f}; "'set -- ; delim_argv "foo $@ bar"'
    143 		atf_check -s exit:0 -o inline:'>foo  bar<\n' -e empty \
    144 			${TEST_SH} -c \
    145 			". ./h-f${f}; "'set -- ; delim_argv foo" $@ "bar'
    146 
    147 		atf_check -s exit:0 -o inline:'>a< >b< >c<\n' -e empty \
    148 			${TEST_SH} -c \
    149 			". ./h-f${f}; "'set -- a b c; delim_argv "$@"'
    150 
    151 		atf_check -s exit:0 -o inline:'>fooa< >b< >cbar<\n' -e empty \
    152 			${TEST_SH} -c \
    153 			". ./h-f${f}; "'set -- a b c; delim_argv "foo$@bar"'
    154 
    155 		atf_check -s exit:0 -o inline:'>foo a< >b< >c bar<\n' -e empty \
    156 			${TEST_SH} -c \
    157 			". ./h-f${f}; "'set -- a b c; delim_argv "foo $@ bar"'
    158 	done
    159 }
    160 
    161 atf_test_case dollar_at_empty_and_conditional
    162 dollar_at_empty_and_conditional_head() {
    163 	atf_set descr 'Test $@ expansion when there are no args, and ' \
    164 	                'when conditionally expanded.'
    165 }
    166 dollar_at_empty_and_conditional_body() {
    167 
    168 	# same task, implementation different from previous,
    169 	# that these work is also a test...
    170 
    171 	cat <<'EOF' > h-f3
    172 
    173 delim_argv() {
    174 	str=
    175 	for Arg; do
    176 		str="${str:+${str} }>${Arg}<"
    177 	done
    178 	printf '%s\n' "${str}"
    179 }
    180 
    181 EOF
    182 
    183 	chmod +x h-f3
    184 
    185 	# in these we give printf a first arg of "", which makes
    186 	# the first output char be \n, then the $@ produces anything else
    187 	# (we need to make sure we don't end up with:
    188 	#	printf %s\\n
    189 	# -- that is, no operands for the %s, that's unspecified)
    190 
    191 	atf_check -s exit:0 -o inline:'\na a\nb b\n' -e empty \
    192 		${TEST_SH} -c 'set -- "a a" "b b"; printf %s\\n "" "$@"'
    193 	atf_check -s exit:0 -o inline:'\n' -e empty \
    194 		${TEST_SH} -c 'set -- ; printf %s\\n "" "$@"'
    195 	atf_check -s exit:0 -o inline:'\n' -e empty \
    196 		${TEST_SH} -c 'set -- ; printf %s\\n ""${1+"$@"}'
    197 	atf_check -s exit:0 -o inline:'\n' -e empty \
    198 		${TEST_SH} -c 'set -- ; printf %s\\n """${1+$@}"'
    199 
    200 	# in these we prefix (concat) the $@ expansion with "" to make
    201 	# sure there is always at least one arg for the %s in printf
    202 	# If there is anything else there, the prepended nothing vanishes
    203 	atf_check -s exit:0 -o inline:'a a\nb b\n' -e empty \
    204 		${TEST_SH} -c 'set -- "a a" "b b"; printf %s\\n """$@"'
    205 	atf_check -s exit:0 -o inline:'\n' -e empty \
    206 		${TEST_SH} -c 'set -- ; printf %s\\n """$@"'
    207 	atf_check -s exit:0 -o inline:'\n' -e empty \
    208 		${TEST_SH} -c 'set -- ; printf %s\\n ""${1+"$@"}'
    209 	atf_check -s exit:0 -o inline:'\n' -e empty \
    210 		${TEST_SH} -c 'set -- ; printf %s\\n """${1+$@}"'
    211 
    212 	atf_check -s exit:0 -o inline:'>a< >b< >c<\n' -e empty ${TEST_SH} -c \
    213 		'. ./h-f3; set -- a b c; delim_argv "${1+$@}"'
    214 	atf_check -s exit:0 -o inline:'>a< >b< >c<\n' -e empty ${TEST_SH} -c \
    215 		'. ./h-f3; set -- a b c; delim_argv ${1+"$@"}'
    216 	atf_check -s exit:0 -o inline:'>fooa< >b< >cbar<\n' -e empty \
    217 		${TEST_SH} -c \
    218 		    '. ./h-f3; set -- a b c; delim_argv "foo${1+$@}bar"'
    219 	atf_check -s exit:0 -o inline:'>fooa< >b< >cbar<\n' -e empty \
    220 		${TEST_SH} -c \
    221 		    '. ./h-f3; set -- a b c; delim_argv foo${1+"$@"}bar'
    222 	atf_check -s exit:0 -o inline:'>foo a< >b< >c bar<\n' -e empty \
    223 		${TEST_SH} -c \
    224 		     '. ./h-f3; set -- a b c; delim_argv "foo ${1+$@} bar"'
    225 	atf_check -s exit:0 -o inline:'>foo a< >b< >c bar<\n' -e empty \
    226 		${TEST_SH} -c \
    227 		     '. ./h-f3; set -- a b c; delim_argv "foo "${1+"$@"}" bar"'
    228 
    229 	# since $1 is not set, we get nothing ($@ is irrelevant)
    230 	# (note here we are not using printf, don't need to guarantee an arg)
    231 	atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
    232 		 '. ./h-f3; set -- ; delim_argv ${1+"$@"}'
    233 
    234 	# here since $1 is not set we get "" as the special $@ properties
    235 	# do not apply, and ${foo+anything} generates nothing if foo is unset
    236 	atf_check -s exit:0 -o inline:'><\n' -e empty ${TEST_SH} -c \
    237 		 '. ./h-f3; set -- ; delim_argv "${1+$@}"'
    238 
    239 	# in this one we get the initial "" followed by nothing
    240 	atf_check -s exit:0 -o inline:'><\n' -e empty ${TEST_SH} -c \
    241 		 '. ./h-f3; set -- ; delim_argv ""${1+"$@"}'
    242 	# which we verify by changing the "" to X, and including Y
    243 	atf_check -s exit:0 -o inline:'>X<\n' -e empty ${TEST_SH} -c \
    244 		 '. ./h-f3; set -- ; delim_argv X${1+"$@"Y}'
    245 	# and again, done differently (the ${1+...} produces nothing at all
    246 	atf_check -s exit:0 -o inline:'>X<\n' -e empty ${TEST_SH} -c \
    247 		 '. ./h-f3; set -- ; delim_argv X ${1+"$@"}'
    248 	# in these two we get the initial "" and then nothing
    249 	atf_check -s exit:0 -o inline:'><\n' -e empty ${TEST_SH} -c \
    250 		 '. ./h-f3; set -- ; delim_argv """${1+$@}"'
    251 	atf_check -s exit:0 -o inline:'>< ><\n' -e empty ${TEST_SH} -c \
    252 		 '. ./h-f3; set -- ; delim_argv "" "${1+$@}"'
    253 
    254 	# now we repeat all those with $1 set (so we eval the $@)
    255 	atf_check -s exit:0 -o inline:'>a<\n' -e empty ${TEST_SH} -c \
    256 		 '. ./h-f3; set -- a ; delim_argv ""${1+"$@"}'
    257 	atf_check -s exit:0 -o inline:'>XaY<\n' -e empty ${TEST_SH} -c \
    258 		 '. ./h-f3; set -- a ; delim_argv X${1+"$@"Y}'
    259 	atf_check -s exit:0 -o inline:'>X< >a<\n' -e empty ${TEST_SH} -c \
    260 		 '. ./h-f3; set -- a ; delim_argv X ${1+"$@"}'
    261 	atf_check -s exit:0 -o inline:'>a<\n' -e empty ${TEST_SH} -c \
    262 		 '. ./h-f3; set -- a ; delim_argv """${1+$@}"'
    263 	atf_check -s exit:0 -o inline:'>< >a<\n' -e empty ${TEST_SH} -c \
    264 		 '. ./h-f3; set -- a ; delim_argv "" "${1+$@}"'
    265 
    266 	# now we do all of those again, but testing $X instead of $1 (X set)
    267 	atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
    268 		 '. ./h-f3; X=1; set -- ; delim_argv ${X+"$@"}'
    269 	atf_check -s exit:0 -o inline:'><\n' -e empty ${TEST_SH} -c \
    270 		 '. ./h-f3; X=1; set -- ; delim_argv ""${X+"$@"}'
    271 	atf_check -s exit:0 -o inline:'>X<\n' -e empty ${TEST_SH} -c \
    272 		 '. ./h-f3; X=1; set -- ; delim_argv X${X+"$@"}'
    273 	atf_check -s exit:0 -o inline:'>X<\n' -e empty ${TEST_SH} -c \
    274 		 '. ./h-f3; X=1; set -- ; delim_argv X ${X+"$@"}'
    275 	atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
    276 		 '. ./h-f3; X=1; set -- ; delim_argv "${X+$@}"'
    277 	atf_check -s exit:0 -o inline:'><\n' -e empty ${TEST_SH} -c \
    278 		 '. ./h-f3; X=1; set -- ; delim_argv """${X+$@}"'
    279 	atf_check -s exit:0 -o inline:'><\n' -e empty ${TEST_SH} -c \
    280 		 '. ./h-f3; X=1; set -- ; delim_argv "" "${X+$@}"'
    281 
    282 	atf_check -s exit:0 -o inline:'>a<\n' -e empty ${TEST_SH} -c \
    283 		 '. ./h-f3; X=1; set -- a; delim_argv ${X+"$@"}'
    284 	atf_check -s exit:0 -o inline:'>a< >b<\n' -e empty ${TEST_SH} -c \
    285 		 '. ./h-f3; X=1; set -- a b; delim_argv ${X+"$@"}'
    286 	atf_check -s exit:0 -o inline:'>a<\n' -e empty ${TEST_SH} -c \
    287 		 '. ./h-f3; X=1; set -- a ; delim_argv ""${X+"$@"}'
    288 	atf_check -s exit:0 -o inline:'>Xa<\n' -e empty ${TEST_SH} -c \
    289 		 '. ./h-f3; X=1; set -- a ; delim_argv X${X+"$@"}'
    290 	atf_check -s exit:0 -o inline:'>X< >a<\n' -e empty ${TEST_SH} -c \
    291 		 '. ./h-f3; X=1; set -- a ; delim_argv X ${X+"$@"}'
    292 	atf_check -s exit:0 -o inline:'>a<\n' -e empty ${TEST_SH} -c \
    293 		 '. ./h-f3; X=1; set -- a ; delim_argv """${X+$@}"'
    294 	atf_check -s exit:0 -o inline:'>a< >b<\n' -e empty ${TEST_SH} -c \
    295 		 '. ./h-f3; X=1; set -- a b ; delim_argv """${X+$@}"'
    296 	atf_check -s exit:0 -o inline:'>< >a<\n' -e empty ${TEST_SH} -c \
    297 		 '. ./h-f3; X=1; set -- a ; delim_argv "" "${X+$@}"'
    298 	atf_check -s exit:0 -o inline:'>< >a< >b<\n' -e empty ${TEST_SH} -c \
    299 		 '. ./h-f3; X=1; set -- a b ; delim_argv "" "${X+$@}"'
    300 
    301 	# and again, but testing $X where X is unset
    302 	atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
    303 		 '. ./h-f3; unset X; set -- ; delim_argv ${X+"$@"}'
    304 	atf_check -s exit:0 -o inline:'><\n' -e empty ${TEST_SH} -c \
    305 		 '. ./h-f3; unset X; set -- ; delim_argv ""${X+"$@"}'
    306 	atf_check -s exit:0 -o inline:'>X<\n' -e empty ${TEST_SH} -c \
    307 		 '. ./h-f3; unset X; set -- ; delim_argv X${X+"$@"}'
    308 	atf_check -s exit:0 -o inline:'>X<\n' -e empty ${TEST_SH} -c \
    309 		 '. ./h-f3; unset X; set -- ; delim_argv X ${X+"$@"}'
    310 	atf_check -s exit:0 -o inline:'><\n' -e empty ${TEST_SH} -c \
    311 		 '. ./h-f3; unset X; set -- ; delim_argv "${X+$@}"'
    312 	atf_check -s exit:0 -o inline:'><\n' -e empty ${TEST_SH} -c \
    313 		 '. ./h-f3; unset X; set -- ; delim_argv """${X+$@}"'
    314 	atf_check -s exit:0 -o inline:'>< ><\n' -e empty ${TEST_SH} -c \
    315 		 '. ./h-f3; unset X; set -- ; delim_argv "" "${X+$@}"'
    316 	atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
    317 		 '. ./h-f3; unset X; set -- a; delim_argv ${X+"$@"}'
    318 	atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
    319 		 '. ./h-f3; unset X; set -- a b; delim_argv ${X+"$@"}'
    320 	atf_check -s exit:0 -o inline:'><\n' -e empty ${TEST_SH} -c \
    321 		 '. ./h-f3; unset X; set -- a ; delim_argv ""${X+"$@"}'
    322 	atf_check -s exit:0 -o inline:'>X<\n' -e empty ${TEST_SH} -c \
    323 		 '. ./h-f3; unset X; set -- a ; delim_argv X${X+"$@"}'
    324 	atf_check -s exit:0 -o inline:'>X<\n' -e empty ${TEST_SH} -c \
    325 		 '. ./h-f3; unset X; set -- a ; delim_argv X ${X+"$@"}'
    326 	atf_check -s exit:0 -o inline:'><\n' -e empty ${TEST_SH} -c \
    327 		 '. ./h-f3; unset X; set -- a ; delim_argv """${X+$@}"'
    328 	atf_check -s exit:0 -o inline:'>< ><\n' -e empty ${TEST_SH} -c \
    329 		 '. ./h-f3; unset X; set -- a; delim_argv "" "${X+$@}"'
    330 
    331 	# a few that stretch belief...
    332 
    333 	atf_check -s exit:0 -o inline:'>a< >b<\n' -e empty ${TEST_SH} -c \
    334 		 '. ./h-f3; X=1; set -- a b ; delim_argv ${X+${1+"$@"}}'
    335 	atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
    336 		 '. ./h-f3; X=1; set -- ; delim_argv ${X+${1+"$@"}}'
    337 	atf_check -s exit:0 -o inline:'\n' -e empty ${TEST_SH} -c \
    338 		 '. ./h-f3; unset X; set -- a b ; delim_argv ${X+${1+"$@"}}'
    339 
    340 	# and now for something completely different
    341 
    342 	atf_check -s exit:0 -o inline:'>a< >b< >ca< >b< >c<\n' -e empty \
    343 		${TEST_SH} -c '. ./h-f3; set -- a b c; delim_argv "$@$@"'
    344 	atf_check -s exit:0 -o inline:'>a< >b< >ca b c<\n' -e empty \
    345 		${TEST_SH} -c '. ./h-f3; set -- a b c; delim_argv "$@$*"'
    346 	atf_check -s exit:0 -o inline:'>a b ca< >b< >c<\n' -e empty \
    347 		${TEST_SH} -c '. ./h-f3; set -- a b c; delim_argv "$*$@"'
    348 	atf_check -s exit:0 -o inline:'>a a++b + ca a< >< >b < > c<\n'	\
    349 		-e empty ${TEST_SH} -c					\
    350 		'. ./h-f3; set -- "a a" "" "b " " c"; IFS=+; delim_argv "$*$@"'
    351 	atf_check -s exit:0 -o inline:'>a< >a< >< >b < > ca+a< >< >b < > c<\n' \
    352 		-e empty ${TEST_SH} -c					       \
    353 		'. ./h-f3; set -- "a+a" "" "b " " c"; IFS=+; delim_argv $*"$@"'
    354 }
    355 
    356 atf_test_case strip
    357 strip_head() {
    358 	atf_set descr "Checks that the %% operator works and strips" \
    359 	                "the contents of a variable from the given point" \
    360 			"to the end"
    361 }
    362 strip_body() {
    363 	line='#define bindir "/usr/bin" /* comment */'
    364 	stripped='#define bindir "/usr/bin" '
    365 
    366 	# atf_expect_fail "PR bin/43469" -- now fixed
    367 	for exp in 				\
    368 		'${line%%/\**}'			\
    369 		'${line%%"/*"*}'		\
    370 		'${line%%'"'"'/*'"'"'*}'	\
    371 		'"${line%%/\**}"'		\
    372 		'"${line%%"/*"*}"'		\
    373 		'"${line%%'"'"'/*'"'"'*}"'	\
    374 		'${line%/\**}'			\
    375 		'${line%"/*"*}'			\
    376 		'${line%'"'"'/*'"'"'*}'		\
    377 		'"${line%/\**}"'		\
    378 		'"${line%"/*"*}"'		\
    379 		'"${line%'"'"'/*'"'"'*}"'
    380 	do
    381 		atf_check -o inline:":$stripped:\n" -e empty ${TEST_SH} -c \
    382 			"line='${line}'; echo :${exp}:"
    383 	done
    384 }
    385 
    386 atf_test_case wrap_strip
    387 wrap_strip_head() {
    388 	atf_set descr "Checks that the %% operator works and strips" \
    389 	                "the contents of a variable from the given point" \
    390 			'to the end, and that \ \n sequences do not break it'
    391 }
    392 wrap_strip_body() {
    393 	line='#define bindir "/usr/bin" /* comment */'
    394 	stripped='#define bindir "/usr/bin" '
    395 
    396 	for exp in 				\
    397 		'${line\
    398 %%/\**}'					\
    399 		'${line%%"/\
    400 *"*}'						\
    401 		'${line%%'"'"'/*'"'"'\
    402 *}'						\
    403 		'"${li\
    404 ne%%/\**}"'					\
    405 		'"${line%%"\
    406 /*"*}"'						\
    407 		'"${line%\
    408 %'"'"'/*'"'"'*}"'				\
    409 		'${line\
    410 %\
    411 /\*\
    412 *\
    413 }'						\
    414 		'${line%"/*\
    415 "*\
    416 }'						\
    417 		'${line\
    418 %\
    419 '"'"'/*'"'"'*}'					\
    420 		'"$\
    421 {li\
    422 ne%\
    423 '"'"'/*'"'"'*}"'
    424 	do
    425 		atf_check -o inline:":$stripped:\n" -e empty ${TEST_SH} -c \
    426 			"line='${line}'; echo :${exp}:"
    427 	done
    428 }
    429 
    430 atf_test_case tilde
    431 tilde_head() {
    432 	atf_set descr "Checks that the ~ expansions work"
    433 }
    434 tilde_body() {
    435 	for HOME in '' / /home/foo \
    436 /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
    437 	do
    438 		export HOME
    439 
    440 		atf_check -s exit:0 -e empty \
    441 			-o inline:'HOME\t'"${HOME}"'
    442 ~\t'"${HOME}"'
    443 ~/foobar\t'"${HOME}"'/foobar
    444 "$V"\t'"${HOME}"'
    445 "$X"\t~
    446 "$Y"\t'"${HOME}"':'"${HOME}"'
    447 "$YY"\t'"${HOME}"'/foo:'"${HOME}"'/bar
    448 "$Z"\t'"${HOME}"'/~
    449 ${U:-~}\t'"${HOME}"'
    450 $V\t'"${HOME}"'
    451 $X\t~
    452 $Y\t'"${HOME}"':'"${HOME}"'
    453 $YY\t'"${HOME}"'/foo:'"${HOME}"'/bar
    454 $Z\t'"${HOME}"'/~
    455 ${U:=~}\t'"${HOME}"'
    456 ${UU:=~:~}\t'"${HOME}"':'"${HOME}"'
    457 ${UUU:=~/:~}\t'"${HOME}"'/:'"${HOME}"'
    458 ${U4:=~/:~/}\t'"${HOME}"'/:'"${HOME}"'/\n' \
    459 			${TEST_SH} -s <<- \EOF
    460 				unset -v U UU UUU U4
    461 				V=~
    462 				X="~"
    463 				Y=~:~ YY=~/foo:~/bar
    464 				Z=~/~
    465 				printf '%s\t%s\n' \
    466 					'HOME' "${HOME}" \
    467 					'~' ~ \
    468 					'~/foobar' ~/foobar \
    469 					'"$V"' "$V" \
    470 					'"$X"' "$X" \
    471 					'"$Y"' "$Y" \
    472 					'"$YY"' "$YY" \
    473 					'"$Z"' "$Z" \
    474 					'${U:-~}' ''${U:-~} \
    475 					'$V' ''$V \
    476 					'$X' ''$X \
    477 					'$Y' ''$Y \
    478 					'$YY' ''$YY \
    479 					'$Z' ''$Z \
    480 					'${U:=~}' ''${U:=~} \
    481 					'${UU:=~:~}' ''${UU:=~:~} \
    482 					'${UUU:=~/:~}' ''${UUU:=~/:~} \
    483 					'${U4:=~/:~/}' ''${U4:=~/:~/}
    484 			EOF
    485 	done
    486 
    487 	# Testing ~user is harder, so, perhaps later...
    488 }
    489 
    490 atf_test_case varpattern_backslashes
    491 varpattern_backslashes_head() {
    492 	atf_set descr "Tests that protecting wildcards with backslashes" \
    493 	                "works in variable patterns."
    494 }
    495 varpattern_backslashes_body() {
    496 	line='/foo/bar/*/baz'
    497 	stripped='/foo/bar/'
    498 	atf_check -o inline:'/foo/bar/\n' -e empty ${TEST_SH} -c \
    499 		'line="/foo/bar/*/baz"; echo ${line%%\**}'
    500 }
    501 
    502 atf_test_case arithmetic
    503 arithmetic_head() {
    504 	atf_set descr "POSIX requires shell arithmetic to use signed" \
    505 	                "long or a wider type.  We use intmax_t, so at" \
    506 			"least 64 bits should be available.  Make sure" \
    507 			"this is true."
    508 }
    509 arithmetic_body() {
    510 
    511 	atf_check -o inline:'3' -e empty ${TEST_SH} -c \
    512 		'printf %s $((1 + 2))'
    513 	atf_check -o inline:'2147483647' -e empty ${TEST_SH} -c \
    514 		'printf %s $((0x7fffffff))'
    515 	atf_check -o inline:'9223372036854775807' -e empty ${TEST_SH} -c \
    516 		'printf %s $(((1 << 63) - 1))'
    517 }
    518 
    519 atf_test_case iteration_on_null_parameter
    520 iteration_on_null_parameter_head() {
    521 	atf_set descr "Check iteration of \$@ in for loop when set to null;" \
    522 	                "the error \"sh: @: parameter not set\" is incorrect." \
    523 	                "PR bin/48202."
    524 }
    525 iteration_on_null_parameter_body() {
    526 	atf_check -o empty -e empty ${TEST_SH} -c \
    527 		'N=; set -- ${N};   for X; do echo "[$X]"; done'
    528 }
    529 
    530 atf_test_case iteration_on_quoted_null_parameter
    531 iteration_on_quoted_null_parameter_head() {
    532 	atf_set descr \
    533 		'Check iteration of "$@" in for loop when set to null;'
    534 }
    535 iteration_on_quoted_null_parameter_body() {
    536 	atf_check -o inline:'[]\n' -e empty ${TEST_SH} -c \
    537 		'N=; set -- "${N}"; for X; do echo "[$X]"; done'
    538 }
    539 
    540 atf_test_case iteration_on_null_or_null_parameter
    541 iteration_on_null_or_null_parameter_head() {
    542 	atf_set descr \
    543 		'Check expansion of null parameter as default for another null'
    544 }
    545 iteration_on_null_or_null_parameter_body() {
    546 	atf_check -o empty -e empty ${TEST_SH} -c \
    547 		'N=; E=; set -- ${N:-${E}}; for X; do echo "[$X]"; done'
    548 }
    549 
    550 atf_test_case iteration_on_null_or_missing_parameter
    551 iteration_on_null_or_missing_parameter_head() {
    552 	atf_set descr \
    553 	    'Check expansion of missing parameter as default for another null'
    554 }
    555 iteration_on_null_or_missing_parameter_body() {
    556 	# atf_expect_fail 'PR bin/50834'
    557 	atf_check -o empty -e empty ${TEST_SH} -c \
    558 		'N=; set -- ${N:-}; for X; do echo "[$X]"; done'
    559 }
    560 
    561 ####### The remaining tests use the following helper functions ...
    562 
    563 nl='
    564 '
    565 reset()
    566 {
    567 	TEST_NUM=0
    568 	TEST_FAILURES=''
    569 	TEST_FAIL_COUNT=0
    570 	TEST_ID="$1"
    571 }
    572 
    573 check()
    574 {
    575 	fail=false
    576 	TEMP_FILE=$( mktemp OUT.XXXXXX )
    577 	TEST_NUM=$(( $TEST_NUM + 1 ))
    578 	MSG=
    579 
    580 	# our local shell (ATF_SHELL) better do quoting correctly...
    581 	# some of the tests expect us to expand $nl internally...
    582 	CMD="$1"
    583 
    584 	result="$( ${TEST_SH} -c "${CMD}" 2>"${TEMP_FILE}" )"
    585 	STATUS=$?
    586 
    587 	if [ "${STATUS}" -ne "$3" ]; then
    588 		MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    589 		MSG="${MSG} expected exit code $3, got ${STATUS}"
    590 
    591 		# don't actually fail just because of wrong exit code
    592 		# unless we either expected, or received "good"
    593 		# or something else is detected as incorrect as well.
    594 		case "$3/${STATUS}" in
    595 		(*/0|0/*) fail=true;;
    596 		esac
    597 	fi
    598 
    599 	if [ "$3" -eq 0 ]; then
    600 		if [ -s "${TEMP_FILE}" ]; then
    601 			MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    602 			MSG="${MSG} Messages produced on stderr unexpected..."
    603 			MSG="${MSG}${nl}$( cat "${TEMP_FILE}" )"
    604 			fail=true
    605 		fi
    606 	else
    607 		if ! [ -s "${TEMP_FILE}" ]; then
    608 			MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    609 			MSG="${MSG} Expected messages on stderr,"
    610 			MSG="${MSG} nothing produced"
    611 			fail=true
    612 		fi
    613 	fi
    614 	rm -f "${TEMP_FILE}"
    615 
    616 	# Remove newlines (use local shell for this)
    617 	oifs="$IFS"
    618 	IFS="$nl"
    619 	result="$(echo $result)"
    620 	IFS="$oifs"
    621 	if [ "$2" != "$result" ]
    622 	then
    623 		MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    624 		MSG="${MSG} Expected output '$2', received '$result'"
    625 		fail=true
    626 	fi
    627 
    628 	if $fail
    629 	then
    630 		MSG="${MSG}${MSG:+${nl}}[$TEST_NUM]"
    631 		MSG="${MSG} Full command: <<${CMD}>>"
    632 	fi
    633 
    634 	$fail && test -n "$TEST_ID" && {
    635 		TEST_FAILURES="${TEST_FAILURES}${TEST_FAILURES:+${nl}}"
    636 		TEST_FAILURES="${TEST_FAILURES}${TEST_ID}[$TEST_NUM]:"
    637 		TEST_FAILURES="${TEST_FAILURES} Test of '$1' failed.";
    638 		TEST_FAILURES="${TEST_FAILURES}${nl}${MSG}"
    639 		TEST_FAIL_COUNT=$(( $TEST_FAIL_COUNT + 1 ))
    640 		return 0
    641 	}
    642 	$fail && atf_fail "Test[$TEST_NUM] failed: $(
    643 	    # ATF does not like newlines in messages, so change them...
    644 		    printf '%s' "${MSG}" | tr '\n' ';'
    645 	    )"
    646 	return 0
    647 }
    648 
    649 results()
    650 {
    651 	test -n "$1" && atf_expect_fail "$1"
    652 
    653 	test -z "${TEST_ID}" && return 0
    654 	test -z "${TEST_FAILURES}" && return 0
    655 
    656 	echo >&2 "=========================================="
    657 	echo >&2 "While testing '${TEST_ID}'"
    658 	echo >&2 " - - - - - - - - - - - - - - - - -"
    659 	echo >&2 "${TEST_FAILURES}"
    660 
    661 	atf_fail \
    662  "Test ${TEST_ID}: $TEST_FAIL_COUNT (of $TEST_NUM) subtests failed - see stderr"
    663 }
    664 
    665 ####### End helpers
    666 
    667 atf_test_case shell_params
    668 shell_params_head() {
    669 	atf_set descr "Test correct operation of the numeric parameters"
    670 }
    671 shell_params_body() {
    672 	atf_require_prog mktemp
    673 
    674 	reset shell_params
    675 
    676 	check 'set -- a b c; echo "$#: $1 $2 $3"' '3: a b c' 0
    677 	check 'set -- a b c d e f g h i j k l m; echo "$#: ${1}0 ${10} $10"' \
    678 		'13: a0 j a0' 0
    679 	check 'x="$0"; set -- a b; y="$0";
    680 	      [ "x${x}y" = "x${y}y" ] && echo OK || echo x="$x" y="$y"' \
    681 		'OK' 0
    682 	check "${TEST_SH} -c 'echo 0=\$0 1=\$1 2=\$2' a b c" '0=a 1=b 2=c' 0
    683 
    684 	echo 'echo 0="$0" 1="$1" 2="$2"' > helper.sh
    685 	check "${TEST_SH} helper.sh a b c" '0=helper.sh 1=a 2=b' 0
    686 
    687 	check 'set -- a bb ccc dddd eeeee ffffff ggggggg hhhhhhhh \
    688 		iiiiiiiii jjjjjjjjjj kkkkkkkkkkk
    689 	       echo "${#}: ${#1} ${#2} ${#3} ${#4} ... ${#9} ${#10} ${#11}"' \
    690 		 '11: 1 2 3 4 ... 9 10 11' 0
    691 
    692 	check 'set -- a b c; echo "$#: ${1-A} ${2-B} ${3-C} ${4-D} ${5-E}"' \
    693 		'3: a b c D E' 0
    694 	check 'set -- a "" c "" e
    695 	       echo "$#: ${1:-A} ${2:-B} ${3:-C} ${4:-D} ${5:-E}"' \
    696 		'5: a B c D e' 0
    697 	check 'set -- a "" c "" e
    698 	       echo "$#: ${1:+A} ${2:+B} ${3:+C} ${4:+D} ${5:+E}"' \
    699 		'5: A  C  E' 0
    700 	check 'set -- "abab*cbb"
    701 	       echo "${1} ${1#a} ${1%b} ${1##ab} ${1%%b} ${1#*\*} ${1%\**}"' \
    702 	       'abab*cbb bab*cbb abab*cb ab*cbb abab*cb cbb abab' 0
    703 	check 'set -- "abab?cbb"
    704     echo "${1}:${1#*a}+${1%b*}-${1##*a}_${1%%b*}%${1#[ab]}=${1%?*}/${1%\?*}"' \
    705 	       'abab?cbb:bab?cbb+abab?cb-b?cbb_a%bab?cbb=abab?cb/abab' 0
    706 	check 'set -- a "" c "" e; echo "${2:=b}"' '' 1
    707 
    708 	check 'set -- a b c d; echo ${4294967297}' '' 0  # result 'a' => ${1}
    709 	check 'set -- a b c; echo ${01}' 'a' 0
    710 	check "${TEST_SH} -c 'echo 0=\${00} 1=\${01} 2=\${02}' a b c" \
    711 			'0=a 1=b 2=c' 0
    712 
    713 	# by special request, for PaulG...  (${0...} is not octal!)
    714 
    715 	# Posix XCU 2.5.1 (Issue 7 TC2 pg 2349 lines 74835..6):
    716 	#   The digits denoting the positional parameters shall always
    717 	#   be interpreted as a decimal value, even if there is a leading zero.
    718 
    719 	check \
    720 	    'set -- a b c d e f g h i j k l m; echo "$#: ${08} ${010} ${011}"' \
    721 		'13: h j k' 0
    722 
    723 	results
    724 }
    725 
    726 atf_test_case var_with_embedded_cmdsub
    727 var_with_embedded_cmdsub_head() {
    728 	atf_set descr "Test expansion of vars with embedded cmdsub"
    729 }
    730 var_with_embedded_cmdsub_body() {
    731 
    732 	reset var_with_embedded_cmdsub
    733 
    734 	check 'unset x; echo ${x-$(echo a)}$(echo b)'  'ab' 0	#1
    735 	check 'unset x; echo ${x:-$(echo a)}$(echo b)' 'ab' 0	#2
    736 	check 'x=""; echo ${x-$(echo a)}$(echo b)'     'b'  0	#3
    737 	check 'x=""; echo ${x:-$(echo a)}$(echo b)'    'ab' 0	#4
    738 	check 'x=c; echo ${x-$(echo a)}$(echo b)'      'cb' 0	#5
    739 	check 'x=c; echo ${x:-$(echo a)}$(echo b)'     'cb' 0	#6
    740 
    741 	check 'unset x; echo ${x+$(echo a)}$(echo b)'  'b'  0	#7
    742 	check 'unset x; echo ${x:+$(echo a)}$(echo b)' 'b'  0	#8
    743 	check 'x=""; echo ${x+$(echo a)}$(echo b)'     'ab' 0	#9
    744 	check 'x=""; echo ${x:+$(echo a)}$(echo b)'    'b'  0	#10
    745 	check 'x=c; echo ${x+$(echo a)}$(echo b)'      'ab' 0	#11
    746 	check 'x=c; echo ${x:+$(echo a)}$(echo b)'     'ab' 0	#12
    747 
    748 	check 'unset x; echo ${x=$(echo a)}$(echo b)'  'ab' 0	#13
    749 	check 'unset x; echo ${x:=$(echo a)}$(echo b)' 'ab' 0	#14
    750 	check 'x=""; echo ${x=$(echo a)}$(echo b)'     'b'  0	#15
    751 	check 'x=""; echo ${x:=$(echo a)}$(echo b)'    'ab' 0	#16
    752 	check 'x=c; echo ${x=$(echo a)}$(echo b)'      'cb' 0	#17
    753 	check 'x=c; echo ${x:=$(echo a)}$(echo b)'     'cb' 0	#18
    754 
    755 	check 'unset x; echo ${x?$(echo a)}$(echo b)'  ''   2	#19
    756 	check 'unset x; echo ${x:?$(echo a)}$(echo b)' ''   2	#20
    757 	check 'x=""; echo ${x?$(echo a)}$(echo b)'     'b'  0	#21
    758 	check 'x=""; echo ${x:?$(echo a)}$(echo b)'    ''   2	#22
    759 	check 'x=c; echo ${x?$(echo a)}$(echo b)'      'cb' 0	#23
    760 	check 'x=c; echo ${x:?$(echo a)}$(echo b)'     'cb' 0	#24
    761 
    762 	check 'unset x; echo ${x%$(echo a)}$(echo b)'  'b'  0	#25
    763 	check 'unset x; echo ${x%%$(echo a)}$(echo b)' 'b'  0	#26
    764 	check 'x=""; echo ${x%$(echo a)}$(echo b)'     'b'  0	#27
    765 	check 'x=""; echo ${x%%$(echo a)}$(echo b)'    'b'  0	#28
    766 	check 'x=c; echo ${x%$(echo a)}$(echo b)'      'cb' 0	#29
    767 	check 'x=c; echo ${x%%$(echo a)}$(echo b)'     'cb' 0	#30
    768 	check 'x=aa; echo ${x%$(echo "*a")}$(echo b)'  'ab' 0	#31
    769 	check 'x=aa; echo ${x%%$(echo "*a")}$(echo b)' 'b'  0	#32
    770 
    771 	check 'unset x; echo ${x#$(echo a)}$(echo b)'  'b'  0	#33
    772 	check 'unset x; echo ${x##$(echo a)}$(echo b)' 'b'  0	#34
    773 	check 'x=""; echo ${x#$(echo a)}$(echo b)'     'b'  0	#35
    774 	check 'x=""; echo ${x##$(echo a)}$(echo b)'    'b'  0	#36
    775 	check 'x=c; echo ${x#$(echo a)}$(echo b)'      'cb' 0	#37
    776 	check 'x=c; echo ${x##$(echo a)}$(echo b)'     'cb' 0	#38
    777 	check 'x=aa; echo ${x#$(echo "*a")}$(echo b)'  'ab' 0	#39
    778 	check 'x=aa; echo ${x##$(echo "*a")}$(echo b)' 'b'  0	#40
    779 
    780 	results
    781 }
    782 
    783 atf_test_case dollar_hash
    784 dollar_hash_head() {
    785 	atf_set descr 'Test expansion of various aspects of $#'
    786 }
    787 dollar_hash_body() {
    788 
    789 #
    790 #	$# looks like it should be so simple that it doesn't really
    791 #	need a test of its own, and used in that way, it really doesn't.
    792 #	But when we add braces ${#} we need to deal with the three
    793 #	(almost 4) different meanings of a # inside a ${} expansion...
    794 #
    795 #	Note that some of these are just how we treat expansions that
    796 #	are unspecified by posix (as noted below.)
    797 #	
    798 #		1.   ${#} is just $# (number of params)
    799 #		1.a	${\#} is nothing at all (error: invalid expansion)
    800 #		1.b	${\#...} (anything after) is the same (invalid)
    801 #		2.   ${#VAR} is the length of the value VAR
    802 #		2.a	Including ${##} - the length of ${#}
    803 #		3    ${VAR#pat} is the value of VAR with leading pat removed
    804 #		3.a	Including ${VAR#} which just removes leading nothing
    805 #			This is relevant in case of ${VAR#${X}} with X=''
    806 #				nb: not required by posix, see XCU 2.6.2
    807 #		3.b	${##} is not a case of 3.a but rather 2.a 
    808 #		3.c	Yet ${##pat} is a case of 3.a
    809 #			Including ${##${X}} where X='' or X='#'
    810 #				nb: not required by posix, see XCU 2.6.2
    811 #		3.d	And ${#\#} is invalid (error)
    812 #		3.e	But ${##\#} removes a leading # from the value of $#
    813 #			(so is just $# as there is no leading # there)
    814 #				nb: not required by posix, see XCU 2.6.2
    815 #		4    ${VAR##pat} is the value of VAR with longest pat removed
    816 #		4.a	Including ${VAR##} which removes the longest nothing
    817 #		4.b	Which in this case includes ${###} (so is == $#)
    818 #				nb: not required by posix, see XCU 2.6.2
    819 #		4.c	But not ${##\#} which is $# with a leading '#' removed
    820 #			(and so is also == $#), i.e.: like ${###} but different.
    821 #				nb: not required by posix, see XCU 2.6.2
    822 #		4.d	As is ${###\#} or just ${####} - remove  # (so just $#)
    823 #				nb: not required by posix, see XCU 2.6.2
    824 #
    825 
    826 	reset dollar_hash
    827 
    828 	check 'set -- ; echo $#'			'0'		0  # 1
    829 	check 'set -- a b c; echo $#'			'3'		0  # 2
    830 	check 'set -- a b c d e f g h i j; echo $#'	'10'		0  # 3
    831 # rule 1
    832 	check 'set -- ; echo ${#}'			'0'		0  # 4
    833 	check 'set -- a b c; echo ${#}'			'3'		0  # 5
    834 	check 'set -- a b c d e f g h i j; echo ${#}'	'10'		0  # 6
    835 # rule 1.a
    836 	check 'set -- a b c; echo ${\#}'		''		2  # 7
    837 # rule 1.b
    838 	check 'set -- a b c; echo ${\#:-foo}'		''		2  # 8
    839 # rule 2
    840 	check 'VAR=12345; echo ${#VAR}'			'5'		0  # 9
    841 	check 'VAR=123456789012; echo ${#VAR}'		'12'		0  #10
    842 # rule 2.a
    843 	check 'set -- ; echo ${##}'			'1'		0  #11
    844 	check 'set -- a b c; echo ${##}'		'1'		0  #12
    845 	check 'set -- a b c d e f g h i j; echo ${##}'	'2'		0  #13
    846 # rule 3
    847 	check 'VAR=12345; echo ${VAR#1}'		'2345'		0  #14
    848 	check 'VAR=12345; echo ${VAR#2}'		'12345'		0  #15
    849 	check 'VAR=#2345; echo ${VAR#\#}'		'2345'		0  #16
    850 	check 'X=1; VAR=12345; echo ${VAR#${X}}'	'2345'		0  #17
    851 	check 'X=1; VAR=#2345; echo ${VAR#${X}}'	'#2345'		0  #18
    852 # rule 3.a
    853 	check 'VAR=12345; echo ${VAR#}'			'12345'		0  #19
    854 	check 'X=; VAR=12345; echo ${VAR#${X}}'		'12345'		0  #20
    855 # rule 3.b (tested above, rule 2.a)
    856 # rule 3.c
    857 	check 'set -- ; echo ${##0}'			''		0  #21
    858 	check 'set -- a b c; echo ${##1}'		'3'		0  #22
    859 	check 'set -- a b c d e f g h i j; echo ${##1}'	'0'		0  #23
    860 	check 'X=0; set -- ; echo ${##${X}}'		''		0  #24
    861 	check 'X=; set -- ; echo ${##${X}}'		'0'		0  #25
    862 	check 'X=1; set -- a b c; echo ${##${X}}'	'3'		0  #26
    863 	check 'X=1; set -- a b c d e f g h i j; echo ${##${X}}'	'0'	0  #27
    864 	check 'X=; set -- a b c d e f g h i j; echo ${##${X}}'	'10'	0  #28
    865 	check 'X=#; VAR=#2345; echo ${VAR#${X}}'	'2345'		0  #29
    866 	check 'X=#; VAR=12345; echo ${VAR#${X}}'	'12345'		0  #30
    867 # rule 3.d
    868 	check 'set -- a b c; echo ${#\#}'		''		2  #31
    869 # rule 3.e
    870 	check 'set -- ; echo ${##\#}'			'0'		0  #32
    871 	check 'set -- a b c d e f g h i j; echo ${##\#}' '10'		0  #33
    872 
    873 # rule 4
    874 	check 'VAR=12345; echo ${VAR##1}'		'2345'		0  #34
    875 	check 'VAR=12345; echo ${VAR##\1}'		'2345'		0  #35
    876 # rule 4.a
    877 	check 'VAR=12345; echo ${VAR##}'		'12345'		0  #36
    878 # rule 4.b
    879 	check 'set -- ; echo ${###}'			'0'		0  #37
    880 	check 'set -- a b c d e f g h i j; echo ${###}'	'10'		0  #38
    881 # rule 4.c
    882 	check 'VAR=12345; echo ${VAR#\#}'		'12345'		0  #39
    883 	check 'VAR=12345; echo ${VAR#\#1}'		'12345'		0  #40
    884 	check 'VAR=#2345; echo ${VAR#\#}'		'2345'		0  #41
    885 	check 'VAR=#12345; echo ${VAR#\#1}'		'2345'		0  #42
    886 	check 'VAR=#2345; echo ${VAR#\#1}'		'#2345'		0  #43
    887 	check 'set -- ; echo ${####}'			'0'		0  #44
    888 	check 'set -- ; echo ${###\#}'			'0'		0  #45
    889 	check 'set -- a b c d e f g h i j; echo ${####}' '10'		0  #46
    890 	check 'set -- a b c d e f g h i j; echo ${###\#}' '10'		0  #47
    891 
    892 # now check for some more utter nonsense, not mentioned in the rules
    893 # above (doesn't need to be)
    894 
    895 	check 'x=hello; set -- a b c; echo ${#x:-1}'	''		2  #48
    896 	check 'x=hello; set -- a b c; echo ${#x-1}'	''		2  #49
    897 	check 'x=hello; set -- a b c; echo ${#x:+1}'	''		2  #50
    898 	check 'x=hello; set -- a b c; echo ${#x+1}'	''		2  #51
    899 	check 'x=hello; set -- a b c; echo ${#x+1}'	''		2  #52
    900 	check 'x=hello; set -- a b c; echo ${#x:?msg}'	''		2  #53
    901 	check 'x=hello; set -- a b c; echo ${#x?msg}'	''		2  #54
    902 	check 'x=hello; set -- a b c; echo ${#x:=val}'	''		2  #55
    903 	check 'x=hello; set -- a b c; echo ${#x=val}'	''		2  #56
    904 	check 'x=hello; set -- a b c; echo ${#x#h}'	''		2  #57
    905 	check 'x=hello; set -- a b c; echo ${#x#*l}'	''		2  #58
    906 	check 'x=hello; set -- a b c; echo ${#x##*l}'	''		2  #59
    907 	check 'x=hello; set -- a b c; echo ${#x%o}'	''		2  #60
    908 	check 'x=hello; set -- a b c; echo ${#x%l*}'	''		2  #61
    909 	check 'x=hello; set -- a b c; echo ${#x%%l*}'	''		2  #62
    910 
    911 # but just to be complete, these ones should work
    912 
    913 	check 'x=hello; set -- a b c; echo ${#%5}'	'3'		0  #63
    914 	check 'x=hello; set -- a b c; echo ${#%3}'	''		0  #64
    915 	check 'x=hello; set -- a b c; echo ${#%?}'	''		0  #65
    916 	check 'X=#; set -- a b c; echo ${#%${X}}'	'3'		0  #66
    917 	check 'X=3; set -- a b c; echo ${#%${X}}'	''		0  #67
    918 	check 'set -- a b c; echo ${#%%5}'		'3'		0  #68
    919 	check 'set -- a b c; echo ${#%%3}'		''		0  #69
    920 	check 'set -- a b c d e f g h i j k l; echo ${#%1}' '12'	0  #70
    921 	check 'set -- a b c d e f g h i j k l; echo ${#%2}' '1'		0  #71
    922 	check 'set -- a b c d e f g h i j k l; echo ${#%?}' '1'		0  #72
    923 	check 'set -- a b c d e f g h i j k l; echo ${#%[012]}' '1'	0  #73
    924 	check 'set -- a b c d e f g h i j k l; echo ${#%[0-4]}' '1'	0  #74
    925 	check 'set -- a b c d e f g h i j k l; echo ${#%?2}' ''		0  #75
    926 	check 'set -- a b c d e f g h i j k l; echo ${#%1*}' ''		0  #76
    927 	check 'set -- a b c d e f g h i j k l; echo ${#%%2}' '1'	0  #77
    928 	check 'set -- a b c d e f g h i j k l; echo ${#%%1*}' ''	0  #78
    929 
    930 # and this lot are stupid, as $# is never unset or null, but they do work...
    931 
    932 	check 'set -- a b c; echo ${#:-99}'		'3'		0  #79
    933 	check 'set -- a b c; echo ${#-99}'		'3'		0  #80
    934 	check 'set -- a b c; echo ${#:+99}'		'99'		0  #81
    935 	check 'set -- a b c; echo ${#+99}'		'99'		0  #82
    936 	check 'set -- a b c; echo ${#:?bogus}'		'3'		0  #83
    937 	check 'set -- a b c; echo ${#?bogus}'		'3'		0  #84
    938 
    939 # even this utter nonsense is OK, as while special params cannot be
    940 # set this way, here, as $# is not unset, or null, the assignment
    941 # never happens (isn't even attempted)
    942 
    943 	check 'set -- a b c; echo ${#:=bogus}'		'3'		0  #85
    944 	check 'set -- a b c; echo ${#=bogus}'		'3'		0  #86
    945 
    946 	for n in 0 1 10 25 100				#87 #88 #89 #90 #91
    947 	do
    948 		check "(exit $n)"'; echo ${#?}'		"${#n}"		0
    949 	done
    950 
    951 	results		# results so far anyway...
    952 
    953 # now we have some harder to verify cases, as they (must) check unknown values
    954 # and hence the resuls cannot just be built into the script, but we have
    955 # to use some tricks to validate them, so for these, just do regular testing
    956 # and don't attempt to use the check helper function, nor to include
    957 # these tests in the result summary.   If anything has already failed, we
    958 # do not get this far...   From here on, first failure ends this test.
    959 
    960 	for opts in '' '-a' '-au' '-auf' '-aufe' # options safe enough to set
    961 	do
    962 		# Note the shell might have other (or these) opts set already
    963 
    964 		RES=$(${TEST_SH} -c "test -n '${opts}' && set ${opts};
    965 			printf '%s' \"\$-\";printf ' %s\\n' \"\${#-}\"") ||
    966 			atf_fail '${#-} test exited with status '"$?"
    967 		LEN="${RES##* }"
    968 		DMINUS="${RES% ${LEN}}"
    969 		if [ "${#DMINUS}" != "${LEN}" ]
    970 		then
    971 			atf_fail \
    972 		   '${#-} test'" produced ${LEN} for opts ${DMINUS} (${RES})"
    973 		fi
    974 	done
    975 
    976 	for seq in a b c d e f g h i j
    977 	do
    978 		# now we are tryin to generate different pids for $$ and $!
    979 		# so we just run the test a number of times, and hope...
    980 		# On NetBSD pid randomisation will usually help the tests
    981 
    982 		eval "$(${TEST_SH} -c \
    983 		    '(exit 0)& BG=$! LBG=${#!};
    984 	    printf "SH=%s BG=%s LSH=%s LBG=%s" "$$" "$BG" "${#$}" "$LBG";
    985 		      wait')"
    986 
    987 		if [ "${#SH}" != "${LSH}" ] || [ "${#BG}" != "${LBG}" ]
    988 		then
    989 			atf_fail \
    990 	'${#!] of '"${BG} was ${LBG}, expected ${#BG}"'; ${#$} of '"${SH} was ${LSH}, expected ${#SH}"
    991 		fi
    992 	done
    993 }
    994 
    995 atf_test_case dollar_star
    996 dollar_star_head() {
    997 	atf_set descr 'Test expansion of various aspects of $*'
    998 }
    999 dollar_star_body() {
   1000 
   1001 	reset dollar_star
   1002 
   1003 	check 'set -- a b c; echo $# $*'		'3 a b c'	0  # 1
   1004 	check 'set -- a b c; echo $# "$*"'		'3 a b c'	0  # 2
   1005 	check 'set -- a "b c"; echo $# $*'		'2 a b c'	0  # 3
   1006 	check 'set -- a "b c"; echo $# "$*"'		'2 a b c'	0  # 4
   1007 	check 'set -- a b c; set -- $* ; echo $# $*'	'3 a b c'	0  # 5
   1008 	check 'set -- a b c; set -- "$*" ; echo $# $*'	'1 a b c'	0  # 6
   1009 	check 'set -- a "b c"; set -- $* ; echo $# $*'	'3 a b c'	0  # 7
   1010 	check 'set -- a "b c"; set -- "$*" ; echo $# $*' \
   1011 							'1 a b c'	0  # 8
   1012 
   1013 	check 'IFS=". "; set -- a b c; echo $# $*'	'3 a b c'	0  # 9
   1014 	check 'IFS=". "; set -- a b c; echo $# "$*"'	'3 a.b.c'	0  #10
   1015 	check 'IFS=". "; set -- a "b c"; echo $# $*'	'2 a b c'	0  #11
   1016 	check 'IFS=". "; set -- a "b c"; echo $# "$*"'	'2 a.b c'	0  #12
   1017 	check 'IFS=". "; set -- a "b.c"; echo $# $*'	'2 a b c'	0  #13
   1018 	check 'IFS=". "; set -- a "b.c"; echo $# "$*"'	'2 a.b.c'	0  #14
   1019 	check 'IFS=". "; set -- a b c; set -- $* ; echo $# $*' \
   1020 							'3 a b c'	0  #15
   1021 	check 'IFS=". "; set -- a b c; set -- "$*" ; echo $# $*' \
   1022 							'1 a b c'	0  #16
   1023 	check 'IFS=". "; set -- a "b c"; set -- $* ; echo $# $*' \
   1024 							'3 a b c'	0  #17
   1025 	check 'IFS=". "; set -- a "b c"; set -- "$*" ; echo $# $*' \
   1026 							'1 a b c'	0  #18
   1027 	check 'IFS=". "; set -- a b c; set -- $* ; echo $# "$*"' \
   1028 							'3 a.b.c'	0  #19
   1029 	check 'IFS=". "; set -- a b c; set -- "$*" ; echo $# "$*"' \
   1030 							'1 a.b.c'	0  #20
   1031 	check 'IFS=". "; set -- a "b c"; set -- $* ; echo $# "$*"' \
   1032 							'3 a.b.c'	0  #21
   1033 	check 'IFS=". "; set -- a "b c"; set -- "$*" ; echo $# "$*"' \
   1034 							'1 a.b c'	0  #22
   1035 
   1036 	results
   1037 }
   1038 
   1039 atf_test_case dollar_star_in_word
   1040 dollar_star_in_word_head() {
   1041 	atf_set descr 'Test expansion $* occurring in word of ${var:-word}'
   1042 }
   1043 dollar_star_in_word_body() {
   1044 
   1045 	reset dollar_star_in_word
   1046 
   1047 	unset xXx			; # just in case!
   1048 
   1049 	# Note that the expected results for these tests are identical
   1050 	# to those from the dollar_star test.   It should never make
   1051 	# a difference whether we expand $* or ${unset:-$*}
   1052 
   1053 	# (note expanding ${unset:-"$*"} is different, that is not tested here)
   1054 
   1055 	check 'set -- a b c; echo $# ${xXx:-$*}'		'3 a b c' 0  # 1
   1056 	check 'set -- a b c; echo $# "${xXx:-$*}"'		'3 a b c' 0  # 2
   1057 	check 'set -- a "b c"; echo $# ${xXx:-$*}'		'2 a b c' 0  # 3
   1058 	check 'set -- a "b c"; echo $# "${xXx:-$*}"'		'2 a b c' 0  # 4
   1059 	check 'set -- a b c; set -- ${xXx:-$*} ; echo $# $*'	'3 a b c' 0  # 5
   1060 	check 'set -- a b c; set -- "${xXx:-$*}" ; echo $# $*'	'1 a b c' 0  # 6
   1061 	check 'set -- a "b c"; set -- ${xXx:-$*} ; echo $# $*'	'3 a b c' 0  # 7
   1062 	check 'set -- a "b c"; set -- "${xXx:-$*}" ; echo $# $*' \
   1063 								'1 a b c' 0  # 8
   1064 
   1065 	check 'IFS=". "; set -- a b c; echo $# ${xXx:-$*}'	'3 a b c' 0  # 9
   1066 	check 'IFS=". "; set -- a b c; echo $# "${xXx:-$*}"'	'3 a.b.c' 0  #10
   1067 	check 'IFS=". "; set -- a "b c"; echo $# ${xXx:-$*}'	'2 a b c' 0  #11
   1068 	check 'IFS=". "; set -- a "b c"; echo $# "${xXx:-$*}"'	'2 a.b c' 0  #12
   1069 	check 'IFS=". "; set -- a "b.c"; echo $# ${xXx:-$*}'	'2 a b c' 0  #13
   1070 	check 'IFS=". "; set -- a "b.c"; echo $# "${xXx:-$*}"'	'2 a.b.c' 0  #14
   1071 	check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
   1072 								'3 a b c' 0  #15
   1073 	check 'IFS=". ";set -- a b c;set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
   1074 								'1 a b c' 0  #16
   1075 	check 'IFS=". ";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
   1076 								'3 a b c' 0  #17
   1077 	check 'IFS=". ";set -- a "b c";set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
   1078 								'1 a b c' 0  #18
   1079 	check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
   1080 								'3 a.b.c' 0  #19
   1081 	check 'IFS=". ";set -- a b c;set -- "$*";echo $# "$*"' \
   1082 								'1 a.b.c' 0  #20
   1083 	check 'IFS=". ";set -- a "b c";set -- $*;echo $# "$*"' \
   1084 								'3 a.b.c' 0  #21
   1085 	check 'IFS=". ";set -- a "b c";set -- "$*";echo $# "$*"' \
   1086 								'1 a.b c' 0  #22
   1087 
   1088 	results
   1089 }
   1090 
   1091 atf_test_case dollar_star_with_empty_ifs
   1092 dollar_star_with_empty_ifs_head() {
   1093 	atf_set descr 'Test expansion of $* with IFS=""'
   1094 }
   1095 dollar_star_with_empty_ifs_body() {
   1096 
   1097 	reset dollar_star_with_empty_ifs
   1098 
   1099 	check 'IFS=""; set -- a b c; echo $# $*'	'3 a b c'	0  # 1
   1100 	check 'IFS=""; set -- a b c; echo $# "$*"'	'3 abc'		0  # 2
   1101 	check 'IFS=""; set -- a "b c"; echo $# $*'	'2 a b c'	0  # 3
   1102 	check 'IFS=""; set -- a "b c"; echo $# "$*"'	'2 ab c'	0  # 4
   1103 	check 'IFS=""; set -- a "b.c"; echo $# $*'	'2 a b.c'	0  # 5
   1104 	check 'IFS=""; set -- a "b.c"; echo $# "$*"'	'2 ab.c'	0  # 6
   1105 	check 'IFS=""; set -- a b c; set -- $* ; echo $# $*' \
   1106 							'3 a b c'	0  # 7
   1107 	check 'IFS=""; set -- a b c; set -- "$*" ; echo $# $*' \
   1108 							'1 abc'		0  # 8
   1109 	check 'IFS=""; set -- a "b c"; set -- $* ; echo $# $*' \
   1110 							'2 a b c'	0  # 9
   1111 	check 'IFS=""; set -- a "b c"; set -- "$*" ; echo $# $*' \
   1112 							'1 ab c'	0  #10
   1113 	check 'IFS=""; set -- a b c; set -- $* ; echo $# "$*"' \
   1114 							'3 abc'		0  #11
   1115 	check 'IFS=""; set -- a b c; set -- "$*" ; echo $# "$*"' \
   1116 							'1 abc'		0  #12
   1117 	check 'IFS=""; set -- a "b c"; set -- $* ; echo $# "$*"' \
   1118 							'2 ab c'	0  #13
   1119 	check 'IFS=""; set -- a "b c"; set -- "$*" ; echo $# "$*"' \
   1120 							'1 ab c'	0  #14
   1121 
   1122 	results	  # FIXED: 'PR bin/52090 expect 7 of 14 subtests to fail'
   1123 }
   1124 
   1125 atf_test_case dollar_star_in_word_empty_ifs
   1126 dollar_star_in_word_empty_ifs_head() {
   1127 	atf_set descr 'Test expansion of ${unset:-$*} with IFS=""'
   1128 }
   1129 dollar_star_in_word_empty_ifs_body() {
   1130 
   1131 	reset dollar_star_in_word_empty_ifs
   1132 
   1133 	unset xXx			; # just in case
   1134 
   1135 	# Note that the expected results for these tests are identical
   1136 	# to those from the dollar_star_with_empty_ifs test.   It should
   1137 	# never make a difference whether we expand $* or ${unset:-$*}
   1138 
   1139 	# (note expanding ${unset:-"$*"} is different, that is not tested here)
   1140 
   1141 	check 'IFS="";set -- a b c;echo $# ${xXx:-$*}'		'3 a b c' 0  # 1
   1142 	check 'IFS="";set -- a b c;echo $# "${xXx:-$*}"'	'3 abc'	  0  # 2
   1143 	check 'IFS="";set -- a "b c";echo $# ${xXx:-$*}'	'2 a b c' 0  # 3
   1144 	check 'IFS="";set -- a "b c";echo $# "${xXx:-$*}"'	'2 ab c'  0  # 4
   1145 	check 'IFS="";set -- a "b.c";echo $# ${xXx:-$*}'	'2 a b.c' 0  # 5
   1146 	check 'IFS="";set -- a "b.c";echo $# "${xXx:-$*}"'	'2 ab.c'  0  # 6
   1147 	check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
   1148 								'3 a b c' 0  # 7
   1149 	check 'IFS="";set -- a b c;set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
   1150 								'1 abc'   0  # 8
   1151 	check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-$*}' \
   1152 								'2 a b c' 0  # 9
   1153 	check 'IFS="";set -- a "b c";set -- "${xXx:-$*}";echo $# ${xXx:-$*}' \
   1154 								'1 ab c'  0  #10
   1155 	check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
   1156 								'3 abc'	  0  #11
   1157 	check 'IFS="";set -- a b c;set -- "${xXx:-$*}";echo $# "${xXx:-$*}"' \
   1158 								'1 abc'	  0  #12
   1159 	check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# "${xXx:-$*}"' \
   1160 								'2 ab c'  0  #13
   1161 	check 'IFS="";set -- a "b c";set -- "${xXx:-$*}";echo $# "${xXx:-$*}"' \
   1162 								'1 ab c'  0  #14
   1163 
   1164 	results	  # FIXED: 'PR bin/52090 expect 7 of 14 subtests to fail'
   1165 }
   1166 
   1167 atf_test_case dollar_star_in_quoted_word
   1168 dollar_star_in_quoted_word_head() {
   1169 	atf_set descr 'Test expansion $* occurring in word of ${var:-"word"}'
   1170 }
   1171 dollar_star_in_quoted_word_body() {
   1172 
   1173 	reset dollar_star_in_quoted_word
   1174 
   1175 	unset xXx			; # just in case!
   1176 
   1177 	check 'set -- a b c; echo $# ${xXx:-"$*"}'		'3 a b c' 0  # 1
   1178 	check 'set -- a "b c"; echo $# ${xXx:-"$*"}'		'2 a b c' 0  # 2
   1179 	check 'set -- a b c; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
   1180 								'1 a b c' 0  # 3
   1181 	check 'set -- a "b c"; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
   1182 								'1 a b c' 0  # 4
   1183 	check 'set -- a b c; set -- ${xXx:-"$*"} ; echo $# ${xXx-"$*"}' \
   1184 								'1 a b c' 0  # 5
   1185 	check 'set -- a "b c"; set -- ${xXx:-"$*"} ; echo $# ${xXx-$*}' \
   1186 								'1 a b c' 0  # 6
   1187 	check 'set -- a b c; set -- ${xXx:-$*} ; echo $# ${xXx-"$*"}' \
   1188 								'3 a b c' 0  # 7
   1189 	check 'set -- a "b c"; set -- ${xXx:-$*} ; echo $# ${xXx-"$*"}' \
   1190 								'3 a b c' 0  # 8
   1191 
   1192 	check 'IFS=". "; set -- a b c; echo $# ${xXx:-"$*"}'	'3 a.b.c' 0  # 9
   1193 	check 'IFS=". "; set -- a "b c"; echo $# ${xXx:-"$*"}'	'2 a.b c' 0  #10
   1194 	check 'IFS=". "; set -- a "b.c"; echo $# ${xXx:-"$*"}'	'2 a.b.c' 0  #11
   1195 	check 'IFS=". ";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
   1196 								'1 a.b.c' 0  #12
   1197       check 'IFS=". ";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
   1198 								'1 a.b c' 0  #13
   1199 	check 'IFS=". ";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
   1200 								'3 a.b.c' 0  #14
   1201 	check 'IFS=". ";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
   1202 								'3 a.b.c' 0  #15
   1203 	check 'IFS=". ";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
   1204 								'1 a b c' 0  #16
   1205 	check 'IFS=". ";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
   1206 								'1 a b c' 0  #17
   1207 
   1208 	check 'IFS="";set -- a b c;echo $# ${xXx:-"$*"}'	'3 abc'   0  #18
   1209 	check 'IFS="";set -- a "b c";echo $# ${xXx:-"$*"}'	'2 ab c'  0  #19
   1210 	check 'IFS="";set -- a "b.c";echo $# ${xXx:-"$*"}'	'2 ab.c'  0  #20
   1211 	check 'IFS="";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
   1212 								'1 abc'   0  #21
   1213 	check 'IFS="";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-"$*"}' \
   1214 								'1 ab c'  0  #22
   1215 	check 'IFS="";set -- a b c;set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
   1216 								'3 abc'   0  #23
   1217 	check 'IFS="";set -- a "b c";set -- ${xXx:-$*};echo $# ${xXx:-"$*"}' \
   1218 								'2 ab c'  0  #24
   1219 	check 'IFS="";set -- a b c;set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
   1220 								'1 abc'   0  #25
   1221 	check 'IFS="";set -- a "b c";set -- ${xXx:-"$*"};echo $# ${xXx:-$*}' \
   1222 								'1 ab c'  0  #26
   1223 
   1224 	results	  # FIXED: 'PR bin/52090 - 2 of 26 subtests expected to fail'
   1225 }
   1226 
   1227 atf_test_case dollar_at_in_field_split_context
   1228 dollar_at_in_field_split_context_head() {
   1229 	atf_set descr 'Test "$@" wth field splitting -- PR bin/54112'
   1230 }
   1231 dollar_at_in_field_split_context_body() {
   1232 	reset dollar_at_in_field_split_context
   1233 
   1234 		# the simple case (no field split) which always worked
   1235 	check 'set -- ""; set -- ${0+"$@"}; echo $#'		1	0   #1
   1236 
   1237 		# The original failure case from the bash-bug list
   1238 	check 'set -- ""; set -- ${0+"$@" "$@"}; echo $#'	2	0   #2
   1239 
   1240 		# slightly simpler cases that triggered the same issue
   1241 	check 'set -- ""; set -- ${0+"$@" }; echo $#'		1	0   #3
   1242 	check 'set -- ""; set -- ${0+ "$@"}; echo $#'		1	0   #4
   1243 	check 'set -- ""; set -- ${0+ "$@" }; echo $#'		1	0   #5
   1244 
   1245 		# and the bizarre
   1246 	check 'set -- ""; set -- ${0+"$@" "$@" "$@"}; echo $#'	3	0   #6
   1247 
   1248 	# repeat tests when there is more than one set empty numeric param
   1249 
   1250 	check 'set -- "" ""; set -- ${0+"$@"}; echo $#'		2	0   #7
   1251 	check 'set -- "" ""; set -- ${0+"$@" "$@"}; echo $#'	4	0   #8
   1252 	check 'set -- "" ""; set -- ${0+"$@" }; echo $#'	2	0   #9
   1253 	check 'set -- "" ""; set -- ${0+ "$@"}; echo $#'	2	0   #10
   1254 	check 'set -- "" ""; set -- ${0+ "$@" }; echo $#'	2	0   #11
   1255 	check 'set -- "" ""; set -- ${0+"$@" "$@" "$@"}; echo $#' \
   1256 								6	0   #12
   1257 
   1258 		# Next some checks of the way the NetBSD shell
   1259 		# interprets some expressions that are POSIX unspecified.
   1260 		# Other shells might fail these tests, without that
   1261 		# being a problem.   We retain these tests so accidental
   1262 		# changes in our behaviour can be detected.
   1263 
   1264 	check 'set --; X=; set -- "$X$@"; echo $#'		0	0   #13
   1265 	check 'set --; X=; set -- "$@$X"; echo $#'		0	0   #14
   1266 	check 'set --; X=; set -- "$X$@$X"; echo $#'		0	0   #15
   1267 	check 'set --; X=; set -- "$@$@"; echo $#'		0	0   #16
   1268 
   1269 	check 'set -- ""; X=; set -- "$X$@"; echo $#'		1	0   #17
   1270 	check 'set -- ""; X=; set -- "$@$X"; echo $#'		1	0   #19
   1271 	check 'set -- ""; X=; set -- "$X$@$X"; echo $#'		1	0   #19
   1272 	check 'set -- ""; X=; set -- "$@$@"; echo $#'		1	0   #20
   1273 
   1274 	check 'set -- "" ""; X=; set -- "$X$@"; echo $#'	2	0   #21
   1275 	check 'set -- "" ""; X=; set -- "$@$X"; echo $#'	2	0   #22
   1276 	check 'set -- "" ""; X=; set -- "$X$@$X"; echo $#'	2	0   #23
   1277 		# Yes, this next one really is (and should be) 3...
   1278 	check 'set -- "" ""; X=; set -- "$@$@"; echo $#'	3	0   #24
   1279 
   1280 	results
   1281 }
   1282 
   1283 atf_test_case embedded_nl
   1284 embedded_nl_head() {
   1285 	atf_set descr 'Test literal \n in xxx string in ${var-xxx}'
   1286 }
   1287 embedded_nl_body() {
   1288 
   1289 	atf_check -s exit:0 -o inline:'a\nb\n' -e empty ${TEST_SH} <<- 'EOF'
   1290 		unset V
   1291 		X="${V-a
   1292 		b}"
   1293 		printf '%s\n' "${X}"
   1294 		EOF
   1295 
   1296 	atf_check -s exit:0 -o inline:'a\nb\n' -e empty ${TEST_SH} <<- 'EOF'
   1297 		unset V
   1298 		X=${V-"a
   1299 		b"}
   1300 		printf '%s\n' "${X}"
   1301 		EOF
   1302 
   1303 	# This should not generate a syntax error, see PR bin/53201
   1304 	atf_check -s exit:0 -o inline:'abc\n' -e empty ${TEST_SH} <<- 'EOF'
   1305 		V=abc
   1306 		X=${V-a
   1307 		b}
   1308 		printf '%s\n' "${X}"
   1309 		EOF
   1310 
   1311 	# Nor should any of these...
   1312 	atf_check -s exit:0 -o inline:'a\nb\n' -e empty ${TEST_SH} <<- 'EOF'
   1313 		unset V
   1314 		X=${V-a
   1315 		b}
   1316 		printf '%s\n' "${X}"
   1317 		EOF
   1318 
   1319 	atf_check -s exit:0 -o inline:'a\nb\n' -e empty ${TEST_SH} <<- 'EOF'
   1320 		unset V
   1321 		X=${V:=a
   1322 		b}
   1323 		printf '%s\n' "${X}"
   1324 		EOF
   1325 
   1326 	atf_check -s exit:0 -o inline:'xa\nby\na\nb\n' -e empty \
   1327 	    ${TEST_SH} <<- 'EOF'
   1328 		unset V
   1329 		X=x${V:=a
   1330 		b}y
   1331 		printf '%s\n' "${X}" "${V}"
   1332 		EOF
   1333 }
   1334 
   1335 check3()
   1336 {
   1337 	check "X=foo; ${1}"		"$2" 0
   1338 	check "X=; ${1}"		"$3" 0
   1339 	check "unset X; ${1}"		"$4" 0
   1340 }
   1341 
   1342 atf_test_case alternative
   1343 alternative_head() {
   1344 	atf_set descr 'Test various possibilities for ${var+xxx}'
   1345 }
   1346 alternative_body() {
   1347 	reset alternative
   1348 
   1349 	# just to verify (validate) that the test method works as expected
   1350 	# (this is currently the very first test performed in this test set)
   1351 	check	'printf %s a b'				ab	0	#  1
   1352 
   1353 	check3	'set -- ${X+bar}; echo "$#:$1"'		1:bar 1:bar 0:  #  4
   1354 	check3	'set -- ${X+}; echo "$#:$1"'		0: 0: 0:	#  7
   1355 	check3	'set -- ${X+""}; echo "$#:$1"'		1: 1: 0:	# 10
   1356 	check3	'set -- "${X+}"; echo "$#:$1"'		1: 1: 1:	# 13
   1357 	check3	'set -- "${X+bar}"; echo "$#:$1"'	1:bar 1:bar 1:	# 16
   1358 
   1359 	check3	'set -- ${X+a b c}; echo "$#:$1"'	3:a 3:a 0:	# 19
   1360 	check3	'set -- ${X+"a b c"}; echo "$#:$1"'	'1:a b c' '1:a b c' 0:
   1361 	check3	'set -- "${X+a b c}"; echo "$#:$1"'	'1:a b c' '1:a b c' 1:
   1362 	check3	'set -- ${X+a b\ c}; echo "$#:$1"'	2:a 2:a 0:	# 28
   1363 	check3	'set -- ${X+"a b" c}; echo "$#:$1"'	'2:a b' '2:a b' 0:
   1364 
   1365 	check3	'printf %s "" ${X+}'			''  ''  ''	# 34
   1366 	check3	'printf %s ""${X+bar}'			bar bar ''	# 37
   1367 
   1368 	check3	'Y=bar; printf %s ${X+x}${Y+y}'		xy  xy  y	# 40
   1369 	check3	'Y=bar; printf %s ""${X+${Y+z}}'	z   z   ''	# 43
   1370 	check3	'Y=; printf %s ""${X+${Y+z}}'		z   z   ''	# 46
   1371 	check3	'unset Y; printf %s ""${X+${Y+z}}'	''  ''  ''	# 49
   1372 	check3	'Y=1; printf %s a ${X+"${Y+z}"}'	az  az	a	# 52
   1373 
   1374 	check3	'printf %s ${X+}x}'			x}  x}  x}	# 55
   1375 	check3	'printf %s ${X+}}'			 }   }   }	# 58
   1376 	check3	'printf %s "" ${X+"}"x}'		}x  }x  ''	# 61
   1377 	check3	'printf %s "" ${X+\}x}'			}x  }x  ''	# 64
   1378 	check3	'printf %s "${X+\}x}"'			}x  }x  ''	# 67
   1379 	check3	'printf %s "${X+\}}"'			 }  }   ''	# 70
   1380 
   1381 	check3	'set -- ${X:+bar}; echo "$#:$1"'	1:bar 0: 0:	# 73
   1382 	check3	'set -- ${X:+}; echo "$#:$1"'		0: 0: 0:	# 76
   1383 	check3	'set -- ${X:+""}; echo "$#:$1"'		1: 0: 0:	# 79
   1384 	check3	'set -- "${X:+}"; echo "$#:$1"'		1: 1: 1:	# 80
   1385 	check3	'set -- "${X:+bar}"; echo "$#:$1"'	1:bar 1: 1:	# 83
   1386 
   1387 	check3	'set -- ${X:+a b c}; echo "$#:$1"'	3:a 0: 0:	# 86
   1388 	check3	'set -- ${X:+"a b c"}; echo "$#:$1"'	'1:a b c' 0: 0:	# 89
   1389 	check3	'set -- "${X:+a b c}"; echo "$#:$1"'	'1:a b c' 1: 1:	# 92
   1390 	check3	'set -- ${X:+a b\ c}; echo "$#:$1"'	2:a 0: 0:	# 95
   1391 	check3	'set -- ${X:+"a b" c}; echo "$#:$1"'	'2:a b' 0: 0:	# 98
   1392 
   1393 	check3	'printf %s "" ${X:+}'			''  ''  ''	#101
   1394 	check3	'printf %s ""${X:+bar}'			bar ''  ''	#104
   1395 
   1396 	check3	'Y=bar; printf %s ${X:+x}${Y:+y}'	xy  y   y	#107
   1397 	check3	'Y=bar; printf %s ""${X:+${Y:+z}}'	z   ''  ''	#110
   1398 	check3	'Y=; printf %s ""${X:+${Y+z}}'		z   ''  ''	#113
   1399 	check3	'Y=; printf %s ""${X:+${Y:+z}}'		''  ''  ''	#116
   1400 	check3	'unset Y; printf %s ""${X:+${Y:+z}}'	''  ''  ''	#119
   1401 	check3	'Y=1; printf %s a ${X:+"${Y:+z}"}'	az  a	a	#122
   1402 
   1403 	check3	'printf %s ${X:+}x}'			x}  x}  x}	#125
   1404 	check3	'printf %s ${X:+}}'			 }   }   }	#128
   1405 	check3	'printf %s "" ${X:+"}"x}'		}x  ''  ''	#131
   1406 	check3	'printf %s "" ${X:+\}x}'		}x  ''  ''	#134
   1407 	check3	'printf %s "${X:+\}x}"'			}x  ''  ''	#137
   1408 	check3	'printf %s "${X:+\}}"'			 }  ''  ''	#140
   1409 
   1410 	results
   1411 }
   1412 
   1413 atf_test_case default
   1414 default_head() {
   1415 	atf_set descr 'Test various possibilities for ${var-xxx}'
   1416 }
   1417 default_body() {
   1418 	reset default
   1419 
   1420 	check3	'set -- ${X-bar}; echo "$#:$1"'		1:foo 0: 1:bar	#  3
   1421 	check3	'set -- ${X-}; echo "$#:$1"'		1:foo 0: 0:	#  6
   1422 	check3	'set -- ${X-""}; echo "$#:$1"'		1:foo 0: 1:	#  9
   1423 	check3	'set -- "${X-}"; echo "$#:$1"'		1:foo 1: 1:	# 12
   1424 	check3	'set -- "${X-bar}"; echo "$#:$1"'	1:foo 1: 1:bar	# 15
   1425 
   1426 	check3	'set -- ${X-a b c}; echo "$#:$1"'	1:foo 0: 3:a	# 18
   1427 	check3	'set -- ${X-"a b c"}; echo "$#:$1"'	1:foo 0: '1:a b c' #21
   1428 	check3	'set -- "${X-a b c}"; echo "$#:$1"'	1:foo 1: '1:a b c' #24
   1429 	check3	'set -- ${X-a b\ c}; echo "$#:$1"'	1:foo 0: 2:a	# 27
   1430 	check3	'set -- ${X-"a b" c}; echo "$#:$1"'	1:foo 0: '2:a b'   #30
   1431 
   1432 	check3	'printf %s "" ${X-}'			foo '' ''	# 33
   1433 	check3	'printf %s ""${X-bar}'			foo '' bar	# 36
   1434 
   1435 	check3	'Y=bar; printf %s ${X-x}${Y-y}'		foobar bar xbar	# 39
   1436 	check3	'Y=bar; printf %s ""${X-${Y-z}}'	foo '' bar	# 42
   1437 	check3	'Y=; printf %s ""${X-${Y-z}}'		foo '' ''	# 45
   1438 	check3	'unset Y; printf %s ""${X-${Y-z}}'	foo '' z	# 48
   1439 	check3	'Y=1; printf %s a ${X-"${Y-z}"}'	afoo a a1	# 51
   1440 
   1441 	check3	'printf %s ${X-}x}'			foox} x} x}	# 54
   1442 	check3	'printf %s ${X-}}'			 foo}  }  }	# 57
   1443 	check3	'printf %s ${X-{}}'			 foo}  } {}	# 60
   1444 	check3	'printf %s "" ${X-"}"x}'		foo ''  }x	# 63
   1445 	check3	'printf %s "" ${X-\}x}'			foo ''  }x	# 66
   1446 	check3	'printf %s "${X-\}x}"'			foo ''  }x	# 69
   1447 	check3	'printf %s "${X-\}}"'			foo ''  }	# 72
   1448 
   1449 	check3	'set -- ${X:-bar}; echo "$#:$1"'	1:foo 1:bar 1:bar  #75
   1450 	check3	'set -- ${X:-}; echo "$#:$1"'		1:foo 0: 0:	# 78
   1451 	check3	'set -- ${X:-""}; echo "$#:$1"'		1:foo 1: 1:	# 81
   1452 	check3	'set -- "${X:-}"; echo "$#:$1"'		1:foo 1: 1:	# 84
   1453 	check3	'set -- "${X:-bar}"; echo "$#:$1"'	1:foo 1:bar 1:bar  #87
   1454 
   1455 	check3	'set -- ${X:-a b c}; echo "$#:$1"'	1:foo 3:a 3:a	# 90
   1456 	check3	'set -- ${X:-"a b c"}; echo "$#:$1"' 1:foo '1:a b c' '1:a b c'
   1457 	check3	'set -- "${X:-a b c}"; echo "$#:$1"' 1:foo '1:a b c' '1:a b c'
   1458 	check3	'set -- ${X:-a b\ c}; echo "$#:$1"'	1:foo 2:a 2:a	# 99
   1459 	check3	'set -- ${X:-"a b" c}; echo "$#:$1"'	1:foo '2:a b' '2:a b'
   1460 
   1461 	check3	'printf %s "" ${X:-}'			foo ''  ''	#105
   1462 	check3	'printf %s ""${X:-bar}'			foo bar bar	#108
   1463 
   1464 	check3	'Y=bar; printf %s ${X:-x}${Y:-y}'	foobar xbar xbar #111
   1465 	check3	'Y=bar; printf %s ""${X:-${Y:-z}}'	foo  bar bar	#114
   1466 	check3	'Y=; printf %s ""${X:-${Y-z}}'		foo  ''  ''	#117
   1467 	check3	'Y=; printf %s ""${X:-${Y:-z}}'		foo  z   z	#120
   1468 	check3	'unset Y; printf %s ""${X:-${Y:-z}}'	foo  z   z	#123
   1469 	check3	'Y=1; printf %s a ${X:-"${Y:-z}"}'	afoo a1	 a1	#126
   1470 
   1471 	check3	'printf %s ${X:-}x}'			foox} x}  x}	#129
   1472 	check3	'printf %s ${X:-}}'			 foo}  }   }	#132
   1473 	check3	'printf %s ${X:-{}}'			 foo} {}  {}	#135
   1474 	check3	'printf %s "" ${X:-"}"x}'		 foo  }x  }x	#138
   1475 	check3	'printf %s "" ${X:-\}x}'		 foo  }x  }x	#141
   1476 	check3	'printf %s "${X:-\}x}"'			 foo  }x  }x	#144
   1477 	check3	'printf %s "${X:-\}}"'			 foo  }   }	#147
   1478 
   1479 	results
   1480 }
   1481 
   1482 atf_test_case assign
   1483 assign_head() {
   1484 	atf_set descr 'Test various possibilities for ${var=xxx}'
   1485 }
   1486 assign_body() {
   1487 	reset assign
   1488 
   1489 	check3	'set -- ${X=bar}; echo "$#:$1"'		1:foo 0: 1:bar	#  3
   1490 	check3	'set -- ${X=}; echo "$#:$1"'		1:foo 0: 0:	#  6
   1491 	check3	'set -- ${X=""}; echo "$#:$1"'		1:foo 0: 0:	#  9
   1492 	check3	'set -- "${X=}"; echo "$#:$1"'		1:foo 1: 1:	# 12
   1493 	check3	'set -- "${X=bar}"; echo "$#:$1"'	1:foo 1: 1:bar	# 15
   1494 
   1495 	check3	'set -- ${X=a b c}; echo "$#:$1"'	1:foo 0: 3:a	# 18
   1496 	check3	'set -- ${X="a b c"}; echo "$#:$1"'	1:foo 0: 3:a	# 21
   1497 	check3	'set -- "${X=a b c}"; echo "$#:$1"'	1:foo 1: '1:a b c' #24
   1498 	check3	'set -- ${X=a b\ c}; echo "$#:$1"'	1:foo 0: 3:a	# 27
   1499 	check3	'set -- ${X="a b" c}; echo "$#:$1"'	1:foo 0: 3:a	# 30
   1500 
   1501 	check3	'printf %s "" ${X=}'			foo '' ''	# 33
   1502 	check3	'printf %s ""${X=bar}'			foo '' bar	# 36
   1503 
   1504 	check3	'Y=bar; printf %s ${X=x}${Y=y}'		foobar bar xbar	# 39
   1505 	check3	'Y=bar; printf %s ""${X=${Y=z}}'	foo '' bar	# 42
   1506 	check3	'Y=; printf %s ""${X=${Y=z}}'		foo '' ''	# 45
   1507 	check3	'unset Y; printf %s ""${X=${Y=z}}'	foo '' z	# 48
   1508 	check3	'Y=1; printf %s a ${X="${Y=z}"}'	afoo a a1	# 51
   1509 
   1510 	check3	'printf %s ${X=}x}'			foox} x} x}	# 54
   1511 	check3	'printf %s ${X=}}'			 foo}  }  }	# 57
   1512 	check3	'printf %s ${X={}}'			 foo}  } {}	# 60
   1513 	check3	'printf %s "" ${X="}"x}'		foo ''  }x	# 63
   1514 	check3	'printf %s "" ${X=\}x}'			foo ''  }x	# 66
   1515 	check3	'printf %s "${X=\}x}"'			foo ''  }x	# 69
   1516 	check3	'printf %s "${X=\}}"'			foo ''  }	# 72
   1517 
   1518 	check3	'set -- ${X=a b c}; echo "$#:$1:$X"'  1:foo:foo 0:: '3:a:a b c'
   1519 	check3	'set -- ${X="a b c"}; echo "$#:$1:$X"' 1:foo:foo 0:: '3:a:a b c'
   1520 	check3	'set -- "${X=a b c}"; echo "$#:$1:$X"' \
   1521 						1:foo:foo 1:: '1:a b c:a b c'
   1522 	check3	'set -- ${X=a b\ c}; echo "$#:$1:$X"' 1:foo:foo 0:: '3:a:a b c'
   1523 	check3	'set -- ${X="a b" c}; echo "$#:$1:$X"' 1:foo:foo 0:: '3:a:a b c'
   1524 
   1525 	check3	'printf %s ${X=}x}; printf :%s "${X-U}"' foox}:foo x}: x}: #90
   1526 	check3	'printf %s ${X=}}; printf :%s "${X-U}"'  foo}:foo }:  }:   #93
   1527 	check3	'printf %s ${X={}}; printf :%s "${X-U}"' foo}:foo }: {}:{  #96
   1528 
   1529 	check3	'set -- ${X:=bar}; echo "$#:$1"'	1:foo 1:bar 1:bar # 99	
   1530 	check3	'set -- ${X:=}; echo "$#:$1"'		1:foo 0: 0:	#102
   1531 	check3	'set -- ${X:=""}; echo "$#:$1"'		1:foo 0: 0:	#105
   1532 	check3	'set -- "${X:=}"; echo "$#:$1"'		1:foo 1: 1:	#108
   1533 	check3	'set -- "${X:=bar}"; echo "$#:$1"'	1:foo 1:bar 1:bar #111
   1534 
   1535 	check3	'set -- ${X:=a b c}; echo "$#:$1"'	1:foo 3:a 3:a	#114
   1536 	check3	'set -- ${X:="a b c"}; echo "$#:$1"' 1:foo 3:a 3:a	#117
   1537 	check3	'set -- "${X:=a b c}"; echo "$#:$1"' 1:foo '1:a b c' '1:a b c'
   1538 	check3	'set -- ${X:=a b\ c}; echo "$#:$1"'	1:foo 3:a 3:a	#123
   1539 	check3	'set -- ${X:="a b" c}; echo "$#:$1"'	1:foo 3:a 3:a	#126
   1540 
   1541 	check3	'printf %s "" ${X:=}'			foo ''  ''	#129
   1542 	check3	'printf %s ""${X:=bar}'			foo bar bar	#132
   1543 
   1544 	check3	'Y=bar; printf %s ${X:=x}${Y:=y}'	foobar xbar xbar #135
   1545 	check3	'Y=bar; printf %s ""${X:=${Y:=z}}'	foo  bar bar	#138
   1546 	check3	'Y=; printf %s ""${X:=${Y=z}}'		foo  ''  ''	#141
   1547 	check3	'Y=; printf %s ""${X:=${Y:=z}}'		foo  z   z	#144
   1548 	check3	'unset Y; printf %s ""${X:=${Y:=z}}'	foo  z   z	#147
   1549 	check3	'Y=1; printf %s a ${X:="${Y:=z}"}'	afoo a1	 a1	#150
   1550 
   1551 	check3	'printf %s ${X:=}x}'			foox} x}  x}	#153
   1552 	check3	'printf %s ${X:=}}'			 foo}  }   }	#156
   1553 	check3	'printf %s ${X:={}}'			 foo} {}  {}	#159
   1554 	check3	'printf %s "" ${X:="}"x}'		 foo  }x  }x	#162
   1555 	check3	'printf %s "" ${X:=\}x}'		 foo  }x  }x	#165
   1556 	check3	'printf %s "${X:=\}x}"'			 foo  }x  }x	#168
   1557 	check3	'printf %s "${X:=\}}"'			 foo  }   }	#171
   1558 
   1559 	check3	'set -- ${X:=a b c}; echo "$#:$1:$X"' \
   1560 				1:foo:foo '3:a:a b c' '3:a:a b c'	#174
   1561 	check3	'set -- ${X:="a b c"}; echo "$#:$1:$X"' \
   1562 				1:foo:foo '3:a:a b c' '3:a:a b c'	#177
   1563 	check3	'set -- "${X:=a b c}"; echo "$#:$1:$X"' \
   1564 				1:foo:foo '1:a b c:a b c' '1:a b c:a b c' #180
   1565 	check3	'set -- ${X:=a b\ c}; echo "$#:$1:$X"' \
   1566 				1:foo:foo '3:a:a b c' '3:a:a b c'	#183
   1567 	check3	'set -- ${X:="a b" c}; echo "$#:$1:$X"' \
   1568 				1:foo:foo '3:a:a b c' '3:a:a b c'	#186
   1569 
   1570 	check3	'printf %s ${X:=}x}; printf :%s "${X-U}"' foox}:foo x}: x}:
   1571 	check3	'printf %s ${X:=}}; printf :%s "${X-U}"'  foo}:foo }:  }:
   1572 	check3	'printf %s ${X:=\}}; printf :%s "${X-U}"' foo:foo }:}  }:}
   1573 	check3	'printf %s ${X:={}}; printf :%s "${X-U}"' foo}:foo {}:{ {}:{
   1574 									#198
   1575 
   1576 	results
   1577 }
   1578 
   1579 atf_test_case error
   1580 error_head() {
   1581 	atf_set descr 'Test various possibilities for ${var?xxx}'
   1582 }
   1583 error_body() {
   1584 	reset error
   1585 
   1586 	check 'X=foo; printf %s ${X?X is not set}'	foo	0	#1
   1587 	check 'X=; printf %s ${X?X is not set}'		''	0	#2
   1588 	check 'unset X; printf %s ${X?X is not set}'	''	2	#3
   1589 
   1590 	check 'X=foo; printf %s ${X?}'			foo	0	#4
   1591 	check 'X=; printf %s ${X?}'			''	0	#5
   1592 	check 'unset X; printf %s ${X?}'		''	2	#6
   1593 
   1594 	check 'X=foo; printf %s ${X:?X is not set}'	foo	0	#7
   1595 	check 'X=; printf %s ${X:?X is not set}'	''	2	#8
   1596 	check 'unset X; printf %s ${X:?X is not set}'	''	2	#9
   1597 
   1598 	check 'X=foo; printf %s ${X:?}'			foo	0	#10
   1599 	check 'X=; printf %s ${X:?}'			''	2	#11
   1600 	check 'unset X; printf %s ${X:?}'		''	2	#12
   1601 
   1602 	results
   1603 }
   1604 
   1605 atf_init_test_cases() {
   1606 	# Listed here in the order ATF runs them, not the order from above
   1607 
   1608 	atf_add_test_case alternative
   1609 	atf_add_test_case arithmetic
   1610 	atf_add_test_case assign
   1611 	atf_add_test_case default
   1612 	atf_add_test_case dollar_at
   1613 	atf_add_test_case dollar_at_empty_and_conditional
   1614 	atf_add_test_case dollar_at_in_field_split_context
   1615 	atf_add_test_case dollar_at_unquoted_or_conditional
   1616 	atf_add_test_case dollar_at_with_text
   1617 	atf_add_test_case dollar_hash
   1618 	atf_add_test_case dollar_star
   1619 	atf_add_test_case dollar_star_in_quoted_word
   1620 	atf_add_test_case dollar_star_in_word
   1621 	atf_add_test_case dollar_star_in_word_empty_ifs
   1622 	atf_add_test_case dollar_star_with_empty_ifs
   1623 	atf_add_test_case embedded_nl
   1624 	atf_add_test_case error
   1625 	atf_add_test_case iteration_on_null_parameter
   1626 	atf_add_test_case iteration_on_quoted_null_parameter
   1627 	atf_add_test_case iteration_on_null_or_null_parameter
   1628 	atf_add_test_case iteration_on_null_or_missing_parameter
   1629 	atf_add_test_case shell_params
   1630 	atf_add_test_case strip
   1631 	atf_add_test_case tilde
   1632 	atf_add_test_case wrap_strip
   1633 	atf_add_test_case var_with_embedded_cmdsub
   1634 	atf_add_test_case varpattern_backslashes
   1635 }
   1636