Lines Matching +full:in +full:- +full:line

6 # Redistribution and use in source and binary forms, with or without
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # Any failures in this first test means it is not worth bothering looking
31 # for causes of failures in any other tests, make this one work first.
43 cat <<- 'DONE' |
45 atf_check -s exit:0 -o empty -e empty ${TEST_SH}
46 cat <<- 'DONE' |
48 atf_check -s exit:0 -o match:0 -e empty ${TEST_SH} -c 'wc -l'
50 cat <<- 'DONE' |
53 atf_check -s exit:0 -o match:hello -e empty ${TEST_SH}
54 cat <<- 'DONE' |
57 atf_check -s exit:0 -o match:1 -e empty ${TEST_SH} -c 'wc -l'
59 cat <<- 'DONE' |
63 atf_check -s exit:0 -o match:helloworld -e empty ${TEST_SH}
64 cat <<- 'DONE' |
68 atf_check -s exit:0 -o match:2 -e empty ${TEST_SH} -c 'wc -l'
71 atf_check -s exit:0 -o inline:'Line1\nLine2\nLine3\n' -e empty \
72 ${TEST_SH} -c 'cat File'
74 cat <<- 'DONE' |
75 set -- X "" '' Y
77 echo '' -$1- -$2- -$3- -$4-
85 atf_check -s exit:0 -o match:ARGS=4 -o match:'-X- -- -- -Y-' \
86 -o match:X=X -o match:'Y=\$4' -e empty ${TEST_SH}
96 printf '%s\n%s\n%s\nEND\n' 'First Line' 'Second Line' 'Line 3' >File
98 atf_check -s exit:0 -e empty \
99 -o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
100 ${TEST_SH} -c 'cat < File'
101 atf_check -s exit:0 -e empty \
102 -o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
103 ${TEST_SH} -c 'cat <File'
104 atf_check -s exit:0 -e empty \
105 -o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
106 ${TEST_SH} -c 'cat< File'
107 atf_check -s exit:0 -e empty \
108 -o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
109 ${TEST_SH} -c 'cat < "File"'
110 atf_check -s exit:0 -e empty \
111 -o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
112 ${TEST_SH} -c '< File cat'
115 atf_check -s exit:0 -e empty \
116 -o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
117 ${TEST_SH} -c '< wc cat'
120 atf_check -s exit:0 -e empty -o match:4 \
121 ${TEST_SH} -c '< cat wc'
124 cat <<- 'EOF' |
125 for l in 1 2 3; do
126 read line < File
127 echo "$line"
130 atf_check -s exit:0 -e empty \
131 -o inline:'First Line\nFirst Line\nFirst Line\n' \
134 cat <<- 'EOF' |
135 for l in 1 2 3; do
136 read line
137 echo "$line"
140 atf_check -s exit:0 -e empty \
141 -o inline:'First Line\nSecond Line\nLine 3\n' \
144 cat <<- 'EOF' |
145 for l in 1 2 3; do
146 read line < File
147 echo "$line"
150 atf_check -s exit:0 -e empty \
151 -o inline:'First Line\nFirst Line\nFirst Line\n' \
154 cat <<- 'EOF' |
155 line=
156 while [ "$line" != END ]; do
157 read line || exit 1
158 echo "$line"
161 atf_check -s exit:0 -e empty \
162 -o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
165 cat <<- 'EOF' |
167 read line || exit 0
168 echo "$line"
171 atf_check -s exit:0 -e empty \
172 -o inline:'First Line\nSecond Line\nLine 3\nEND\n' \
175 cat <<- 'EOF' |
177 while read line < File
179 echo "$line"
181 [ ${#l} -ge 3 ] && break
185 atf_check -s exit:0 -e empty \
186 -o inline:'First Line\nFirst Line\nFirst Line\nDONE\n' \
189 cat <<- 'EOF' |
190 while read line
192 echo "$line"
196 atf_check -s exit:0 -e empty \
197 -o inline:'First Line\nSecond Line\nLine 3\nEND\nDONE\n' \
200 cat <<- 'EOF' |
202 while read line
204 echo "$line"
206 [ ${#l} -ge 3 ] && break
210 atf_check -s exit:0 -e empty \
211 -o inline:'First Line\nSecond Line\nLine 3\nDONE\n' ${TEST_SH}
213 cat <<- 'EOF' |
220 [ ${#l} -ge 2 ] && break
224 atf_check -s exit:0 -e empty \
225 -o inline:'First Line:First Line\nFirst Line:Second Line\nDONE\n' \
241 rm -f Output 2>/dev/null || :
242 test -f Output && atf_fail "Unable to remove Output file"
244 i; atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '> Output'
245 test -f Output || atf_fail "#$T: Did not make Output file"
247 rm -f Output 2>/dev/null || :
248 i; atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '>> Output'
249 test -f Output || atf_fail "#$T: Did not make Output file"
251 rm -f Output 2>/dev/null || :
252 i; atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c '>| Output'
253 test -f Output || atf_fail "#$T: Did not make Output file"
256 rm -f Output 2>/dev/null || :
258 atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c 'echo Hello >Output'
259 test -s Output || atf_fail "#$T: Did not make non-empty Output file"
264 atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c 'echo Hello>!Output'
265 test -s Output || atf_fail "#$T: Did not make non-empty Output file"
270 atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c 'echo Bye >>Output'
271 test -s Output || atf_fail "#$T: Removed Output file"
275 i; atf_check -s exit:0 -o inline:'line 1\nline 2\n' -e empty \
276 ${TEST_SH} -c \
277 'echo line 1 > Output; echo line 2 >> Output; cat Output'
278 test "$(cat Output)" = "line 1${nl}line 2" || atf_fail \
279 "#$T: Incorrect Output: Should be 'line 1\\nline 2' is '$(cat Output)'"
281 i; atf_check -s exit:0 -o inline:'line 2\n' -e empty \
282 ${TEST_SH} -c 'echo line 1 > Output; echo line 2'
283 test "$(cat Output)" = "line 1" || atf_fail \
284 "#$T: Incorrect Output: Should be 'line 1' is '$(cat Output)'"
286 i; atf_check -s exit:0 -o empty -e empty \
287 ${TEST_SH} -c '(echo line 1; echo line 2 > Out2) > Out1'
288 test "$(cat Out1)" = "line 1" || atf_fail \
289 "#$T: Incorrect Out1: Should be 'line 1' is '$(cat Out1)'"
290 test "$(cat Out2)" = "line 2" || atf_fail \
291 "#$T: Incorrect Out2: Should be 'line 2' is '$(cat Out2)'"
293 i; atf_check -s exit:0 -o empty -e empty \
294 ${TEST_SH} -c '{ echo line 1; echo line 2 > Out2;} > Out1'
295 test "$(cat Out1)" = "line 1" || atf_fail \
296 "#$T: Incorrect Out1: Should be 'line 1' is '$(cat Out1)'"
297 test "$(cat Out2)" = "line 2" || atf_fail \
298 "#$T: Incorrect Out2: Should be 'line 2' is '$(cat Out2)'"
300 i; rm -f Out1 Out2 2>/dev/null || :
301 cat <<- 'EOF' |
302 for arg in 'line 1' 'line 2' 'line 3'
308 atf_check -s exit:0 -o empty -e empty ${TEST_SH}
309 test "$(cat Out1)" = "line 3" || atf_fail \
310 "#$T: Incorrect Out1: Should be 'line 3' is '$(cat Out1)'"
311 test "$(cat Out2)" = "line 1${nl}line 2${nl}line 3" || atf_fail \
312 "#$T: Incorrect Out2: Should be 'line 1\\nline 2\\nline 3' is '$(cat Out2)'"
314 i; rm -f Out1 Out2 2>/dev/null || :
315 cat <<- 'EOF' |
316 for arg in 'line 1' 'line 2' 'line 3'
322 atf_check -s exit:0 -o empty -e empty ${TEST_SH}
323 test "$(cat Out1)" = "line 1${nl}line 2${nl}line 3" || atf_fail \
324 "#$T: Incorrect Out1: Should be 'line 1\\nline 2\\nline 3' is '$(cat Out1)'"
325 test "$(cat Out2)" = "line 1${nl}line 2${nl}line 3" || atf_fail \
326 "#$T: Incorrect Out2: Should be 'line 1\\nline 2\\nline 3' is '$(cat Out2)'"
338 cat <<- 'DONE' > helper.sh
344 eval "f $n $n"'> file-$n'
347 cat <<- 'DONE' > reread.sh
349 (read -r var; echo "${var}") <&"$1"
353 x=$( eval "f $n $n"'< file-$n' )
362 test -e "file-$n" || atf_fail "file-$n not created"
363 C=$(cat file-"$n")
365 atf_fail "file-$n contains '$C' not 'nothing $n'"
369 atf_check -s exit:0 -e empty -o empty \
372 atf_check -s exit:0 -e empty -o empty \
375 L=$(ulimit -n)
376 if [ "$L" -ge 30 ]
378 atf_check -s exit:0 -e empty -o empty \
381 atf_check -s exit:0 -e empty -o empty \
384 if [ "$L" -ge 100 ]
386 atf_check -s exit:0 -e empty -o empty \
389 atf_check -s exit:0 -e empty -o empty \
392 if [ "$L" -ge 500 ]
394 atf_check -s exit:0 -e empty -o empty \
397 atf_check -s exit:0 -e empty -o empty \
400 if [ "$L" -gt 1005 ]
402 atf_check -s exit:0 -e empty -o empty \
405 atf_check -s exit:0 -e empty -o empty \
414 "Tests that exec can reassign file descriptors in the shell itself"
418 cat <<- 'DONE' > helper.sh
421 eval "exec $f"'> file-$f'
431 eval "exec $f"'>&-'
436 eval "exec $f"'< file-$f'
442 read -r var || echo >&2 "No data in file-$f"
443 read -r x && echo >&2 "Too much data in file-${f}: $x"
445 echo >&2 "file-$f contains '${var}' not 'Hello $f'"
449 atf_check -s exit:0 -o empty -e empty \
452 L=$(ulimit -n)
453 if [ "$L" -ge 30 ]
455 atf_check -s exit:0 -o empty -e empty \
458 if [ "$L" -ge 100 ]
460 atf_check -s exit:0 -o empty -e empty \
463 if [ "$L" -ge 500 ]
465 atf_check -s exit:0 -o empty -e empty \
468 if [ "$L" -ge 1005 ]
470 atf_check -s exit:0 -o empty -e empty \
483 if test -c /dev/stdout
485 atf_check -s exit:0 -o inline:'OK\n' -e empty \
486 ${TEST_SH} -c 'echo OK >/dev/stdout'
487 atf_check -s exit:0 -o inline:'OK\n' -e empty \
488 ${TEST_SH} -c '/bin/echo OK >/dev/stdout'
491 if test -c /dev/stdin
495 echo GOOD | atf_check -s exit:0 -o inline:'GOOD\n' -e empty \
496 ${TEST_SH} -c 'read var </dev/stdin; echo $var'
497 echo GOOD | atf_check -s exit:0 -o inline:'GOOD\n' -e empty \
498 ${TEST_SH} -c 'cat </dev/stdin'
501 if test -c /dev/stderr
503 atf_check -s exit:0 -e inline:'OK\n' -o empty \
504 ${TEST_SH} -c 'echo OK 2>/dev/stderr >&2'
505 atf_check -s exit:0 -e inline:'OK\n' -o empty \
506 ${TEST_SH} -c '/bin/echo OK 2>/dev/stderr >&2'
509 if test -c /dev/fd/8 && test -c /dev/fd/9
511 atf_check -s exit:0 -o inline:'EIGHT\n' -e empty \
512 ${TEST_SH} -c 'printf "%s\n" EIGHT 8>&1 >/dev/fd/8 |
523 "in case statements. (PR bin/48631)"
527 atf_check -s exit:0 -o empty -e empty \
528 ${TEST_SH} -c 'case x in (whatever) >foo;; esac'
530 atf_check -s exit:0 -o empty -e empty \
531 ${TEST_SH} -c 'case x in (whatever) >foo 2>&1;; esac'
533 atf_check -s exit:0 -o empty -e empty \
534 ${TEST_SH} -c 'case x in (whatever) >foo 2>&1 </dev/null;; esac'
536 atf_check -s exit:0 -o empty -e empty \
537 ${TEST_SH} -c 'case x in (whatever) >${somewhere};; esac'
543 atf_set "descr" "Tests that sh(1) correctly ignores non-redirections"
547 atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c 'echo foo>'
548 atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c 'read foo<'
549 atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c 'echo foo<>'
550 atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
552 atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
554 atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
556 atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
558 atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
560 atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
562 atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
564 atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
567 rm -f Output 2>/dev/null || :
568 atf_check -s exit:0 -e empty -o inline:'A Line > Output\n' \
569 ${TEST_SH} -c 'echo A Line \> Output'
570 test -f Output && atf_file "File 'Output' appeared and should not have"
572 rm -f Output 2>/dev/null || :
573 atf_check -s exit:0 -e empty -o empty \
574 ${TEST_SH} -c 'echo A Line \>> Output'
575 test -f Output || atf_file "File 'Output' not created when it should"
576 test "$(cat Output)" = 'A Line >' || atf_fail \
577 "Output file contains '$(cat Output)' instead of '"'A Line >'\'
579 rm -f Output \> 2>/dev/null || :
580 atf_check -s exit:0 -e empty -o empty \
581 ${TEST_SH} -c 'echo A Line >\> Output'
582 test -f Output && atf_file "File 'Output' appeared and should not have"
583 test -f '>' || atf_file "File '>' not created when it should"
584 test "$(cat '>')" = 'A Line Output' || atf_fail \
585 "Output file ('>') contains '$(cat '>')' instead of 'A Line Output'"
588 # Many more tests in t_here, so here we have just rudimentary checks
598 cat <<- 'DONE' |
603 atf_check -s exit:0 -o match:printf -o match:'hello\\n' \
604 -e empty ${TEST_SH}
611 "its sub-shell(s)"
617 LIM=$(ulimit -n)
619 cat <<- 'DONE' |
620 exec 6>output-file
624 exec 8<output-file
628 ( printf "bye-bye\n" >&6 )
630 ( exec 8<&- )
634 atf_check -s exit:0 -o match:Bye=bye-bye -e empty \
637 cat <<- 'DONE' |
638 for arg in one-4 two-24 three-14
640 fd=${arg#*-}
641 file=${arg%-*}
645 for arg in one-5 two-7 three-19
647 fd=${arg#*-}
648 file=${arg%-*}
653 echo line-1 >&4
654 echo line-2 >&24
655 echo line-3 >&14
666 atf_check -s exit:0 -o inline:'line-1\nline-2\nline-3\n' \
667 -e empty ${TEST_SH}
669 cat <<- 'DONE' |
670 for arg in one-4-5 two-6-7 three-8-9 four-11-10 five-3-12
672 ofd=${arg##*-}
673 file=${arg%-*}
674 ifd=${file#*-}
675 file=${file%-*}
680 ( ( ( echo line-1 >& 13 ) 13>&12 ) 12>&5 ) >stdout 2>errout
681 ( ( ( echo line-2 >& 4) 13>&12 ) 4>&7 ) >>stdout 2>>errout
682 ( ( ( echo line-3 >& 6) 8>&1 6>&11 >&12) 11>&9 >&7 ) >>stdout
689 atf_check -s exit:0 -o inline:'line-1\nline-2\nline-3\n' \
690 -e empty ${TEST_SH}
696 atf_set "descr" "Tests interactions between redirect and ulimit -n "
702 cat <<- 'DONE' > helper.sh
703 oLIM=$(ulimit -n)
704 HRD=$(ulimit -H -n)
705 test "${oLIM}" -lt "${HRD}" && ulimit -n "${HRD}"
706 LIM=$(ulimit -n)
709 LFD=-1
710 while [ ${LIM} -gt 16 ]
712 FD=$(( ${LIM} - 1 ))
713 if [ "${FD}" -eq "${LFD}" ]; then
731 ulimit -S -n "${LIM}"
735 for FD in ${FDs}
737 echo ${FD} in ${FDs} >&"${FD}" || exit 1
740 ulimit -S -n "${oLIM}"
746 atf_check -s exit:0 -o empty -e empty ${TEST_SH} helper.sh
760 cat <<- 'DONE' > f-def
762 printf '%s\n' In-Func
766 atf_check -s exit:0 -o inline:'In-Func\nsuccess1\n' -e empty \
767 ${TEST_SH} -c ". ./f-def; f ; printf '%s\n' success1"
768 atf_check -s exit:0 -o inline:'success2\n' -e empty \
769 ${TEST_SH} -c ". ./f-def; f >/dev/null; printf '%s\n' success2"
770 atf_check -s exit:0 -o inline:'success3\n' -e empty \
771 ${TEST_SH} -c ". ./f-def; f >&- ; printf '%s\n' success3"
772 atf_check -s exit:0 -o inline:'In-Func\nsuccess4\n' -e empty \
773 ${TEST_SH} -c ". ./f-def; f & wait; printf '%s\n' success4"
774 atf_check -s exit:0 -o inline:'success5\n' -e empty \
775 ${TEST_SH} -c ". ./f-def; f >&- & wait; printf '%s\n' success5"
776 atf_check -s exit:0 -o inline:'In-Func\nIn-Func\nsuccess6\n' -e empty \
777 ${TEST_SH} -c ". ./f-def; f;f; printf '%s\n' success6"
778 atf_check -s exit:0 -o inline:'In-Func\nIn-Func\nsuccess7\n' -e empty \
779 ${TEST_SH} -c ". ./f-def; { f;f;}; printf '%s\n' success7"
780 atf_check -s exit:0 -o inline:'In-Func\nIn-Func\nsuccess8\n' -e empty \
781 ${TEST_SH} -c ". ./f-def; { f;f;}& wait; printf '%s\n' success8"
782 atf_check -s exit:0 -o inline:'In-Func\nsuccess9\n' -e empty \
783 ${TEST_SH} -c \
784 ". ./f-def; { f>/dev/null;f;}& wait; printf '%s\n' success9"
785 atf_check -s exit:0 -o inline:'In-Func\nsuccess10\n' -e empty \
786 ${TEST_SH} -c \
787 ". ./f-def; { f;f>/dev/null;}& wait; printf '%s\n' success10"
790 atf_check -s exit:0 -o inline:'Func a\nFunc b\nFunc c\n' -e empty \
791 ${TEST_SH} -c '
796 ( echo x-a; echo y-b; echo z-c ) |
799 B=${A#?-}
804 cat <<- 'DONE' >Script
809 echo $( for i in a b c
814 atf_check -s exit:0 -e empty \
815 -o inline:' hello a hello b hello c\nfoo=@a@b@c\n' \
820 echo ". ./f-def || echo >&2 FAIL
823 "| atf_check -s exit:0 -o inline:'In-Func\nstdin1\n' -e empty ${TEST_SH}
826 . ./f-def || echo >&2 FAIL
827 f >&-
829 ' | atf_check -s exit:0 -o inline:'stdin2\n' -e empty ${TEST_SH}
831 cat <<- 'DONE' > fgh.def
833 echo -n f >&3
835 echo -n F >&3
838 echo -n g >&3
840 echo -n G >&3
843 echo -n h >&3
847 atf_check -s exit:0 -o inline:'fFgGh' -e empty \
848 ${TEST_SH} -c '. ./fgh.def || echo >&2 FAIL
852 atf_check -s exit:0 -o inline:'fghGF' -e empty \
853 ${TEST_SH} -c '. ./fgh.def || echo >&2 FAIL
857 atf_check -s exit:0 -o inline:'fFgGhX Y\n' -e empty \
858 ${TEST_SH} -c '. ./fgh.def || echo >&2 FAIL
864 # then the 'F' & 'G' will precede 'X Y' in the output.
871 atf_check -s exit:0 -o inline:'fghX Y\nGF' -e empty \
872 ${TEST_SH} -c '. ./fgh.def || echo >&2 FAIL
874 echo X $( f >&- & sleep 1; g >&- & sleep 1 ; h ) Y
884 echo X $( f >&- & sleep 1; g >&- & sleep 1 ; h ) Y
887 ' | atf_check -s exit:0 -o inline:'fghX Y\nGF' -e empty ${TEST_SH}