Home | History | Annotate | Line # | Download | only in sh
t_redir.sh revision 1.4
      1  1.4  christos # $NetBSD: t_redir.sh,v 1.4 2016/03/08 14:26:54 christos Exp $
      2  1.1  christos #
      3  1.1  christos # Copyright (c) 2016 The NetBSD Foundation, Inc.
      4  1.1  christos # All rights reserved.
      5  1.1  christos #
      6  1.1  christos # Redistribution and use in source and binary forms, with or without
      7  1.1  christos # modification, are permitted provided that the following conditions
      8  1.1  christos # are met:
      9  1.1  christos # 1. Redistributions of source code must retain the above copyright
     10  1.1  christos #    notice, this list of conditions and the following disclaimer.
     11  1.1  christos # 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  christos #    notice, this list of conditions and the following disclaimer in the
     13  1.1  christos #    documentation and/or other materials provided with the distribution.
     14  1.1  christos #
     15  1.1  christos # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16  1.1  christos # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17  1.1  christos # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18  1.1  christos # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19  1.1  christos # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20  1.1  christos # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21  1.1  christos # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22  1.1  christos # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23  1.1  christos # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24  1.1  christos # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  1.1  christos # POSSIBILITY OF SUCH DAMAGE.
     26  1.1  christos #
     27  1.2  christos # the implementation of "sh" to test
     28  1.2  christos : ${TEST_SH:="/bin/sh"}
     29  1.1  christos 
     30  1.4  christos # Any failures in this first test means it is not worth bothering looking
     31  1.4  christos # for causes of failures in any other tests, make this one work first.
     32  1.4  christos 
     33  1.4  christos # Problems with this test usually mean inadequate ATF_SHELL used for testing.
     34  1.4  christos # (though if all pass but the last, it might be a TEST_SH problem.)
     35  1.4  christos 
     36  1.4  christos atf_test_case basic_test_method_test
     37  1.4  christos basic_test_method_test_head()
     38  1.4  christos {
     39  1.4  christos 	atf_set "descr" "Tests that test method works as expected"
     40  1.4  christos }
     41  1.4  christos basic_test_method_test_body()
     42  1.4  christos {
     43  1.4  christos 	cat <<- 'DONE' |
     44  1.4  christos 	DONE
     45  1.4  christos 	atf_check -s exit:0 -o empty -e empty ${TEST_SH}
     46  1.4  christos 	cat <<- 'DONE' |
     47  1.4  christos 	DONE
     48  1.4  christos 	atf_check -s exit:0 -o match:0 -e empty ${TEST_SH} -c 'wc -l'
     49  1.4  christos 
     50  1.4  christos 	cat <<- 'DONE' |
     51  1.4  christos 		echo hello
     52  1.4  christos 	DONE
     53  1.4  christos 	atf_check -s exit:0 -o match:hello -e empty ${TEST_SH} 
     54  1.4  christos 	cat <<- 'DONE' |
     55  1.4  christos 		echo hello
     56  1.4  christos 	DONE
     57  1.4  christos 	atf_check -s exit:0 -o match:1 -e empty ${TEST_SH} -c 'wc -l'
     58  1.4  christos 
     59  1.4  christos 	cat <<- 'DONE' |
     60  1.4  christos 		echo hello\
     61  1.4  christos 					world
     62  1.4  christos 	DONE
     63  1.4  christos 	atf_check -s exit:0 -o match:helloworld -e empty ${TEST_SH} 
     64  1.4  christos 	cat <<- 'DONE' |
     65  1.4  christos 		echo hello\
     66  1.4  christos 					world
     67  1.4  christos 	DONE
     68  1.4  christos 	atf_check -s exit:0 -o match:2 -e empty ${TEST_SH} -c 'wc -l'
     69  1.4  christos 
     70  1.4  christos 	printf '%s\n%s\n%s\n' Line1 Line2 Line3 > File
     71  1.4  christos 	atf_check -s exit:0 -o inline:'Line1\nLine2\nLine3\n' -e empty \
     72  1.4  christos 		${TEST_SH} -c 'cat File'
     73  1.4  christos 
     74  1.4  christos 	cat <<- 'DONE' |
     75  1.4  christos 		set -- X "" '' Y
     76  1.4  christos 		echo ARGS="${#}"
     77  1.4  christos 		echo '' -$1- -$2- -$3- -$4-
     78  1.4  christos 		cat <<EOF
     79  1.4  christos 			X=$1
     80  1.4  christos 		EOF
     81  1.4  christos 		cat <<\EOF
     82  1.4  christos 			Y=$4
     83  1.4  christos 		EOF
     84  1.4  christos 	DONE
     85  1.4  christos 	atf_check -s exit:0 -o match:ARGS=4 -o match:'-X- -- -- -Y-' \
     86  1.4  christos 		-o match:X=X -o match:'Y=\$4' -e empty ${TEST_SH} 
     87  1.4  christos }
     88  1.4  christos 
     89  1.4  christos atf_test_case do_input_redirections
     90  1.4  christos do_input_redirections_head()
     91  1.4  christos {
     92  1.4  christos 	atf_set "descr" "Tests that simple input redirection works"
     93  1.4  christos }
     94  1.4  christos do_input_redirections_body()
     95  1.4  christos {
     96  1.4  christos 	printf '%s\n%s\n%s\nEND\n' 'First Line' 'Second Line' 'Line 3' >File
     97  1.4  christos 
     98  1.4  christos 	atf_check -s exit:0 -e empty \
     99  1.4  christos 		-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
    100  1.4  christos 		${TEST_SH} -c 'cat < File'
    101  1.4  christos 	atf_check -s exit:0 -e empty \
    102  1.4  christos 		-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
    103  1.4  christos 		${TEST_SH} -c 'cat <File'
    104  1.4  christos 	atf_check -s exit:0 -e empty \
    105  1.4  christos 		-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
    106  1.4  christos 		${TEST_SH} -c 'cat< File'
    107  1.4  christos 	atf_check -s exit:0 -e empty \
    108  1.4  christos 		-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
    109  1.4  christos 		${TEST_SH} -c 'cat < "File"'
    110  1.4  christos 	atf_check -s exit:0 -e empty \
    111  1.4  christos 		-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
    112  1.4  christos 		${TEST_SH} -c '< File cat'
    113  1.4  christos 
    114  1.4  christos 	ln File wc
    115  1.4  christos 	atf_check -s exit:0 -e empty \
    116  1.4  christos 		-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
    117  1.4  christos 		${TEST_SH} -c '< wc cat'
    118  1.4  christos 
    119  1.4  christos 	mv wc cat
    120  1.4  christos 	atf_check -s exit:0 -e empty -o match:4 \
    121  1.4  christos 		${TEST_SH} -c '< cat wc'
    122  1.4  christos 
    123  1.4  christos 
    124  1.4  christos 	cat <<- 'EOF' |
    125  1.4  christos 		i=0
    126  1.4  christos 		while [ "$i" -lt 3 ]; do
    127  1.4  christos 			i=$((i + 1))
    128  1.4  christos 			read line < File
    129  1.4  christos 			echo "$line"
    130  1.4  christos 		done
    131  1.4  christos 	EOF
    132  1.4  christos 	atf_check -s exit:0 -e empty \
    133  1.4  christos 		-o inline:'First Line\nFirst Line\nFirst Line\n' \
    134  1.4  christos 		${TEST_SH}
    135  1.4  christos 
    136  1.4  christos 	cat <<- 'EOF' |
    137  1.4  christos 		i=0
    138  1.4  christos 		while [ "$i" -lt 3 ]; do
    139  1.4  christos 			i=$((i + 1))
    140  1.4  christos 			read line
    141  1.4  christos 			echo "$line"
    142  1.4  christos 		done <File
    143  1.4  christos 	EOF
    144  1.4  christos 	atf_check -s exit:0 -e empty \
    145  1.4  christos 		-o inline:'First Line\nSecond Line\nLine 3\n' \
    146  1.4  christos 		${TEST_SH}
    147  1.4  christos 
    148  1.4  christos 	cat <<- 'EOF' |
    149  1.4  christos 		i=0
    150  1.4  christos 		while [ "$i" -lt 3 ]; do
    151  1.4  christos 			i=$((i + 1))
    152  1.4  christos 			read line < File
    153  1.4  christos 			echo "$line"
    154  1.4  christos 		done <File
    155  1.4  christos 	EOF
    156  1.4  christos 	atf_check -s exit:0 -e empty \
    157  1.4  christos 		-o inline:'First Line\nFirst Line\nFirst Line\n' \
    158  1.4  christos 		${TEST_SH}
    159  1.4  christos 
    160  1.4  christos 	cat <<- 'EOF' |
    161  1.4  christos 		line=
    162  1.4  christos 		while [ "$line" != END ]; do
    163  1.4  christos 			read line || exit 1
    164  1.4  christos 			echo "$line"
    165  1.4  christos 		done <File
    166  1.4  christos 	EOF
    167  1.4  christos 	atf_check -s exit:0 -e empty \
    168  1.4  christos 		-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
    169  1.4  christos 		${TEST_SH}
    170  1.4  christos 
    171  1.4  christos 	cat <<- 'EOF' |
    172  1.4  christos 		while :; do
    173  1.4  christos 			read line || exit 0
    174  1.4  christos 			echo "$line"
    175  1.4  christos 		done <File
    176  1.4  christos 	EOF
    177  1.4  christos 	atf_check -s exit:0 -e empty \
    178  1.4  christos 		-o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
    179  1.4  christos 		${TEST_SH}
    180  1.4  christos 
    181  1.4  christos 	cat <<- 'EOF' |
    182  1.4  christos 		i=0
    183  1.4  christos 		while read line < File
    184  1.4  christos 		do
    185  1.4  christos 			echo "$line"
    186  1.4  christos 			i=$((i + 1))
    187  1.4  christos 			[ ${i} -ge 3 ] && break
    188  1.4  christos 		done
    189  1.4  christos 		echo DONE
    190  1.4  christos 	EOF
    191  1.4  christos 	atf_check -s exit:0 -e empty \
    192  1.4  christos 		-o inline:'First Line\nFirst Line\nFirst Line\nDONE\n' \
    193  1.4  christos 		${TEST_SH}
    194  1.4  christos 
    195  1.4  christos 	cat <<- 'EOF' |
    196  1.4  christos 		i=0
    197  1.4  christos 		while read line
    198  1.4  christos 		do
    199  1.4  christos 			echo "$line"
    200  1.4  christos 		done <File
    201  1.4  christos 		echo DONE
    202  1.4  christos 	EOF
    203  1.4  christos 	atf_check -s exit:0 -e empty \
    204  1.4  christos 		-o inline:'First Line\nSecond Line\nLine 3\nEND\nDONE\n' \
    205  1.4  christos 		${TEST_SH}
    206  1.4  christos 
    207  1.4  christos 	cat <<- 'EOF' |
    208  1.4  christos 		i=0
    209  1.4  christos 		while read line
    210  1.4  christos 		do
    211  1.4  christos 			echo "$line"
    212  1.4  christos 			i=$((i + 1))
    213  1.4  christos 			[ ${i} -ge 3 ] && break
    214  1.4  christos 		done <File
    215  1.4  christos 		echo DONE
    216  1.4  christos 	EOF
    217  1.4  christos 	atf_check -s exit:0 -e empty \
    218  1.4  christos 		-o inline:'First Line\nSecond Line\nLine 3\nDONE\n' ${TEST_SH}
    219  1.4  christos 
    220  1.4  christos 	cat <<- 'EOF' |
    221  1.4  christos 		i=0
    222  1.4  christos 		while read line1 <File
    223  1.4  christos 		do
    224  1.4  christos 			read line2
    225  1.4  christos 			echo "$line1":"$line2"
    226  1.4  christos 			i=$((i + 1))
    227  1.4  christos 			[ ${i} -ge 2 ] && break
    228  1.4  christos 		done <File
    229  1.4  christos 		echo DONE
    230  1.4  christos 	EOF
    231  1.4  christos 	atf_check -s exit:0 -e empty \
    232  1.4  christos 	    -o inline:'First Line:First Line\nFirst Line:Second Line\nDONE\n' \
    233  1.4  christos 		${TEST_SH}
    234  1.4  christos }
    235  1.4  christos 
    236  1.4  christos atf_test_case do_output_redirections
    237  1.4  christos do_output_redirections_head()
    238  1.4  christos {
    239  1.4  christos 	atf_set "descr" "Test Output redirections"
    240  1.4  christos }
    241  1.4  christos do_output_redirections_body()
    242  1.4  christos {
    243  1.4  christos nl='
    244  1.4  christos '
    245  1.4  christos 	T=0
    246  1.4  christos 	i() { T=$(($T + 1)); }
    247  1.4  christos 
    248  1.4  christos 	rm -f Output 2>/dev/null || :
    249  1.4  christos 	test -f Output && atf_fail "Unable to remove Output file"
    250  1.4  christos #1
    251  1.4  christos 	i; atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '> Output'
    252  1.4  christos 	test -f Output || atf_fail "#$T: Did not make Output file"
    253  1.4  christos #2
    254  1.4  christos 	rm -f Output 2>/dev/null || :
    255  1.4  christos 	i; atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '>> Output'
    256  1.4  christos 	test -f Output || atf_fail "#$T: Did not make Output file"
    257  1.4  christos #3
    258  1.4  christos 	rm -f Output 2>/dev/null || :
    259  1.4  christos 	i; atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '>| Output'
    260  1.4  christos 	test -f Output || atf_fail "#$T: Did not make Output file"
    261  1.4  christos 
    262  1.4  christos #4
    263  1.4  christos 	rm -f Output 2>/dev/null || :
    264  1.4  christos 	i
    265  1.4  christos 	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c 'echo Hello >Output'
    266  1.4  christos 	test -s Output || atf_fail "#$T: Did not make non-empty Output file"
    267  1.4  christos 	test "$(cat Output)" = "Hello" ||
    268  1.4  christos 	  atf_fail "#$T: Incorrect Output: Should be 'Hello' is '$(cat Output)'"
    269  1.4  christos #5
    270  1.4  christos 	i
    271  1.4  christos 	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c 'echo Hello>!Output'
    272  1.4  christos 	test -s Output || atf_fail "#$T: Did not make non-empty Output file"
    273  1.4  christos 	test "$(cat Output)" = "Hello" ||
    274  1.4  christos 	  atf_fail "#$T: Incorrect Output: Should be 'Hello' is '$(cat Output)'"
    275  1.4  christos #6
    276  1.4  christos 	i
    277  1.4  christos 	atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c 'echo Bye >>Output'
    278  1.4  christos 	test -s Output || atf_fail "#$T: Removed Output file"
    279  1.4  christos 	test "$(cat Output)" = "Hello${nl}Bye" || atf_fail \
    280  1.4  christos 	  "#$T: Incorrect Output: Should be 'Hello\\nBye' is '$(cat Output)'"
    281  1.4  christos #7
    282  1.4  christos 	i; atf_check -s exit:0 -o inline:'line 1\nline 2\n' -e empty \
    283  1.4  christos 		${TEST_SH} -c \
    284  1.4  christos 		'echo line 1 > Output; echo line 2 >> Output; cat Output'
    285  1.4  christos 	test "$(cat Output)" = "line 1${nl}line 2" || atf_fail \
    286  1.4  christos 	 "#$T: Incorrect Output: Should be 'line 1\\nline 2' is '$(cat Output)'"
    287  1.4  christos #8
    288  1.4  christos 	i; atf_check -s exit:0 -o inline:'line 2\n' -e empty \
    289  1.4  christos 		${TEST_SH} -c 'echo line 1 > Output; echo line 2'
    290  1.4  christos 	test "$(cat Output)" = "line 1" || atf_fail \
    291  1.4  christos 	    "#$T: Incorrect Output: Should be 'line 1' is '$(cat Output)'"
    292  1.4  christos #9
    293  1.4  christos 	i; atf_check -s exit:0 -o empty -e empty \
    294  1.4  christos 		${TEST_SH} -c '(echo line 1; echo line 2 > Out2) > Out1'
    295  1.4  christos 	test "$(cat Out1)" = "line 1" || atf_fail \
    296  1.4  christos 	    "#$T: Incorrect Out1: Should be 'line 1' is '$(cat Out1)'"
    297  1.4  christos 	test "$(cat Out2)" = "line 2" || atf_fail \
    298  1.4  christos 	    "#$T: Incorrect Out2: Should be 'line 2' is '$(cat Out2)'"
    299  1.4  christos #10
    300  1.4  christos 	i; atf_check -s exit:0 -o empty -e empty \
    301  1.4  christos 		${TEST_SH} -c '{ echo line 1; echo line 2 > Out2;} > Out1'
    302  1.4  christos 	test "$(cat Out1)" = "line 1" || atf_fail \
    303  1.4  christos 	    "#$T: Incorrect Out1: Should be 'line 1' is '$(cat Out1)'"
    304  1.4  christos 	test "$(cat Out2)" = "line 2" || atf_fail \
    305  1.4  christos 	    "#$T: Incorrect Out2: Should be 'line 2' is '$(cat Out2)'"
    306  1.4  christos #11
    307  1.4  christos 	i; rm -f Out1 Out2 2>/dev/null || :
    308  1.4  christos 	cat <<- 'EOF' |
    309  1.4  christos 		for arg in 'line 1' 'line 2' 'line 3'
    310  1.4  christos 		do
    311  1.4  christos 			echo "$arg"
    312  1.4  christos 			echo "$arg" > Out1
    313  1.4  christos 		done > Out2
    314  1.4  christos 	EOF
    315  1.4  christos 	atf_check -s exit:0 -o empty -e empty ${TEST_SH} 
    316  1.4  christos 	test "$(cat Out1)" = "line 3" || atf_fail \
    317  1.4  christos 		"#$T:  Incorrect Out1: Should be 'line 3' is '$(cat Out1)'"
    318  1.4  christos 	test "$(cat Out2)" = "line 1${nl}line 2${nl}line 3" || atf_fail \
    319  1.4  christos     "#$T: Incorrect Out2: Should be 'line 1\\nline 2\\nline 3' is '$(cat Out2)'"
    320  1.4  christos #12
    321  1.4  christos 	i; rm -f Out1 Out2 2>/dev/null || :
    322  1.4  christos 	cat <<- 'EOF' |
    323  1.4  christos 		for arg in 'line 1' 'line 2' 'line 3'
    324  1.4  christos 		do
    325  1.4  christos 			echo "$arg"
    326  1.4  christos 			echo "$arg" >> Out1
    327  1.4  christos 		done > Out2
    328  1.4  christos 	EOF
    329  1.4  christos 	atf_check -s exit:0 -o empty -e empty ${TEST_SH} 
    330  1.4  christos 	test "$(cat Out1)" = "line 1${nl}line 2${nl}line 3" || atf_fail \
    331  1.4  christos     "#$T: Incorrect Out1: Should be 'line 1\\nline 2\\nline 3' is '$(cat Out1)'"
    332  1.4  christos 	test "$(cat Out2)" = "line 1${nl}line 2${nl}line 3" || atf_fail \
    333  1.4  christos     "#$T: Incorrect Out2: Should be 'line 1\\nline 2\\nline 3' is '$(cat Out2)'"
    334  1.4  christos }
    335  1.4  christos 
    336  1.4  christos atf_test_case fd_redirections
    337  1.4  christos fd_redirections_head()
    338  1.4  christos {
    339  1.4  christos 	atf_set "descr" "Tests redirections to/from specific descriptors"
    340  1.4  christos }
    341  1.4  christos fd_redirections_body()
    342  1.4  christos {
    343  1.4  christos 	# Or it will one day...
    344  1.4  christos } 
    345  1.4  christos 
    346  1.4  christos atf_test_case local_redirections
    347  1.4  christos local_redirections_head()
    348  1.4  christos {
    349  1.4  christos 	atf_set "descr" \
    350  1.4  christos 	    "Tests that exec can reassign file descriptors in the shell itself"
    351  1.4  christos }
    352  1.4  christos local_redirections_body()
    353  1.4  christos {
    354  1.4  christos 	# Or it will one day...
    355  1.4  christos }
    356  1.4  christos 
    357  1.1  christos atf_test_case redir_in_case
    358  1.4  christos redir_in_case_head()
    359  1.4  christos {
    360  1.4  christos 	atf_set "descr" "Tests that sh(1) allows just redirections " \
    361  1.1  christos 	                "in case statements. (PR bin/48631)"
    362  1.1  christos }
    363  1.4  christos redir_in_case_body()
    364  1.4  christos {
    365  1.2  christos 	atf_check -s exit:0 -o empty -e empty \
    366  1.2  christos 	    ${TEST_SH} -c 'case x in (whatever) >foo;; esac'
    367  1.4  christos 
    368  1.4  christos 	atf_check -s exit:0 -o empty -e empty \
    369  1.4  christos 	    ${TEST_SH} -c 'case x in (whatever) >foo 2>&1;; esac'
    370  1.4  christos 
    371  1.4  christos 	atf_check -s exit:0 -o empty -e empty \
    372  1.4  christos 	    ${TEST_SH} -c 'case x in (whatever) >foo 2>&1 </dev/null;; esac'
    373  1.4  christos 
    374  1.4  christos 	atf_check -s exit:0 -o empty -e empty \
    375  1.4  christos 	    ${TEST_SH} -c 'case x in (whatever) >${somewhere};; esac'
    376  1.2  christos }
    377  1.2  christos 
    378  1.4  christos atf_test_case incorrect_redirections
    379  1.4  christos incorrect_redirections_head()
    380  1.4  christos {
    381  1.4  christos 	atf_set "descr" "Tests that sh(1) correctly ignores non-redirections"
    382  1.4  christos }
    383  1.4  christos incorrect_redirections_body() {
    384  1.4  christos 
    385  1.4  christos 	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c 'echo foo>'
    386  1.4  christos 	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c 'read foo<'
    387  1.4  christos 	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c 'echo foo<>'
    388  1.4  christos 	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
    389  1.4  christos 		'echo x > '"$nl"
    390  1.4  christos 	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
    391  1.4  christos 		'read x < '"$nl"
    392  1.4  christos 	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
    393  1.4  christos 		'echo x <> '"$nl"
    394  1.4  christos 	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
    395  1.4  christos 		'echo x >< anything'
    396  1.4  christos 	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
    397  1.4  christos 		'echo x >>< anything'
    398  1.4  christos 	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
    399  1.4  christos 		'echo x >|< anything'
    400  1.4  christos 	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
    401  1.4  christos 		'echo x > ; read x < /dev/null || echo bad'
    402  1.4  christos 	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
    403  1.4  christos 		'read x < & echo y > /dev/null; wait && echo bad'
    404  1.4  christos 
    405  1.4  christos 	rm -f Output 2>/dev/null || :
    406  1.4  christos 	atf_check -s exit:0 -e empty -o inline:'A Line > Output\n' \
    407  1.4  christos 		${TEST_SH} -c 'echo A Line \> Output'
    408  1.4  christos 	test -f Output && atf_file "File 'Output' appeared and should not have"
    409  1.4  christos 
    410  1.4  christos 	rm -f Output 2>/dev/null || :
    411  1.4  christos 	atf_check -s exit:0 -e empty -o empty \
    412  1.4  christos 		${TEST_SH} -c 'echo A Line \>> Output'
    413  1.4  christos 	test -f Output || atf_file "File 'Output' not created when it should"
    414  1.4  christos 	test "$(cat Output)" = 'A Line >' || atf_fail \
    415  1.4  christos 		"Output file contains '$(cat Output)' instead of '"'A Line >'\'
    416  1.4  christos 
    417  1.4  christos 	rm -f Output \> 2>/dev/null || :
    418  1.4  christos 	atf_check -s exit:0 -e empty -o empty \
    419  1.4  christos 		${TEST_SH} -c 'echo A Line >\> Output'
    420  1.4  christos 	test -f Output && atf_file "File 'Output' appeared and should not have"
    421  1.4  christos 	test -f '>' || atf_file "File '>' not created when it should"
    422  1.4  christos 	test "$(cat '>')" = 'A Line Output' || atf_fail \
    423  1.4  christos 	    "Output file ('>') contains '$(cat '>')' instead of 'A Line Output'"
    424  1.4  christos }
    425  1.4  christos 
    426  1.4  christos # Many more tests in t_here, so here we have just rudimentary checks
    427  1.2  christos atf_test_case redir_here_doc
    428  1.4  christos redir_here_doc_head()
    429  1.4  christos {
    430  1.2  christos 	atf_set "descr" "Tests that sh(1) correctly processes 'here' doc " \
    431  1.2  christos 	                "input redirections"
    432  1.2  christos }
    433  1.4  christos redir_here_doc_body()
    434  1.4  christos {
    435  1.4  christos 	# nb: the printf is not executed, it is data
    436  1.3  christos 	cat <<- 'DONE' |
    437  1.3  christos 		cat <<EOF
    438  1.3  christos 			printf '%s\n' 'hello\n'
    439  1.3  christos 		EOF
    440  1.3  christos 	DONE
    441  1.4  christos 	atf_check -s exit:0 -o match:printf -o match:'hello\\n' \
    442  1.4  christos 		-e empty ${TEST_SH} 
    443  1.4  christos }
    444  1.4  christos 
    445  1.4  christos atf_test_case subshell_redirections
    446  1.4  christos subshell_redirections_head()
    447  1.4  christos {
    448  1.4  christos 	atf_set "descr" "Tests redirection interactions between shell and " \
    449  1.4  christos 			"its sub-shell(s)"
    450  1.4  christos }
    451  1.4  christos subshell_redirections_body()
    452  1.4  christos {
    453  1.4  christos 	# Or will, one day
    454  1.1  christos }
    455  1.1  christos 
    456  1.1  christos atf_init_test_cases() {
    457  1.4  christos 	atf_add_test_case basic_test_method_test
    458  1.4  christos 	atf_add_test_case do_input_redirections
    459  1.4  christos 	atf_add_test_case do_output_redirections
    460  1.4  christos 	atf_add_test_case fd_redirections
    461  1.4  christos 	atf_add_test_case local_redirections
    462  1.4  christos 	atf_add_test_case incorrect_redirections
    463  1.4  christos 	atf_add_test_case redir_here_doc
    464  1.1  christos 	atf_add_test_case redir_in_case
    465  1.4  christos 	atf_add_test_case subshell_redirections
    466  1.1  christos }
    467