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