• Home
  • Raw
  • Download

Lines Matching full:testing

35 # Testing shell corner cases _within_ a shell script is kind of hard.
37 [ -f testing.sh ] && . testing.sh
41 #testing "name" "command" "result" "infile" "stdin"
64 testing '-c "" exit status 0' '$SH -c "" && echo $?' '0\n' '' ''
65 testing '-c args' "\$SH -c 'echo \$0,\$1,\$2,\$3' one two three four five" \
67 testing '-c args2' "\$SH -c 'echo \${10}' a b c d e f g h i j k l" "k\n" "" ""
68 testing '-c arg split' \
71 testing '-c arg split2' \
74 testing '-c arg count' "$SH -c 'echo \$#' 9 8 7 6 1 2 3 4" "7\n" "" ""
75 testing "exec3" '$C -c "{ exec readlink /proc/self/fd/0;} < /proc/self/exe"' \
77 testing 'arg shift' "$SH -c '"'for i in "" 2 1 1 1; do echo $? $1; shift $i; done'"' one two three …
79 testing '(subshell)' '$SH -c "(echo hello)"' 'hello\n' '' ''
80 testing 'syntax' '$SH -c "if true; then echo hello | fi" 2>/dev/null || echo x'\
82 testing 'syntax2' '$SH -c "for;i 0" 2>&1 | { grep -qi syntax && echo yes; }' \
87 testing 'non-absolute $_' "./bash -c 'echo \$_'" './bash\n' '' ''
90 testing 'exec exitval' "$SH -c 'exec echo hello' && echo \$?" "hello\n0\n" "" ""
91 testing 'simple script' '$SH input' 'input\n' 'echo $0' ''
92 testing 'simple script2' '$SH ./input two;echo $?' './input+two\n42\n' \
95 toyonly testing 'recursion guard' \
98 testing '$LINENO 1' "$SH input" "1\n" 'echo $LINENO' ''
102 testing 'simple script in $PATH' "PATH='$PWD/sub:$PATH' $SH script" \
106 testing "script file" "chmod +x input; ./input" "hello\n" "#!$C\necho hello" ""
107 testing 'IFS $*' "$SH -c 'IFS=xy; echo \"\$*\"' one two tyree" "twoxtyree\n" \
110 testing 'default exports' \
114 #testing "leading assignment fail" \
116 testing "lineno" "$SH input" "5 one\n6 one\n5 two\n6 two\n" \
118 testing "eval0" "$SH -c 'eval echo \$*' one two three" "two three\n" "" ""
124 testing 'trailing $ is literal' 'echo $' '$\n' '' ''
125 # TODO testing 'empty +() is literal' 'echo +()' '+()\n' '' ''
134 testing '$_ literal after exec' 'env >/dev/null; echo $_' 'env\n' '' ''
136 testing 'prefix is local for builtins' 'abc=123; abc=def unset abc; echo $abc' \
138 testing 'prefix localizes magic vars' \
141 testing '$NOTHING clears $_' 'true; $NOTHING; echo $_' '\n' '' ''
142 testing 'assignment with redirect is persistent, not prefix' \
144 testing '$_ with functions' 'true; x(){ echo $_;}; x abc; echo $_' \
148 testing 'cd in renamed dir' \
153 testing "smoketest" "echo hello" "hello\n" "" ""
154 testing "line break" $'ec\\\nho hello' 'hello\n' '' ''
155 testing "assignment" 'x=y; echo $x' 'y\n' '' ''
156 testing "+= assignment" 'x+=abc; y=def; y+=$x; echo $y' 'defabc\n' '' ''
157 testing "eval" "eval echo hello" "hello\n" "" ""
158 testing "eval2" "eval 'echo hello'; echo $?" "hello\n0\n" "" ""
159 testing "eval3" 'X="echo hello"; eval "$X"' "hello\n" "" ""
160 testing "eval4" 'eval printf '=%s=' \" hello \"' "= hello =" "" ""
161 NOSPACE=1 testing "eval5" 'eval echo \" hello \" | wc' ' 1 1 8' "" ""
162 testing "exec" "exec echo hello" "hello\n" "" ""
163 testing "exec2" "exec echo hello; echo $?" "hello\n" "" ""
166 testing "semicolon" "echo one;echo two" "one\ntwo\n" "" ""
167 testing "simple pipe" "echo hello | cat" "hello\n" "" ""
168 testing "&&" "true && echo hello" "hello\n" "" ""
169 testing "&&2" "false && echo hello" "" "" ""
170 testing "||" "true || echo hello" "" "" ""
171 testing "||2" "false || echo hello" "hello\n" "" ""
172 testing "&& ||" "true && false && potato || echo hello" "hello\n" "" ""
173 testing "&& after function" "x(){ false;};x && echo yes" "" "" ""
174 testing "|| after function" "x(){ false;};x || echo yes" "yes\n" "" ""
178 testing "redir1" "cat < input" "hello\n" "hello\n" ""
179 testing "redir2" "echo blah >out; cat out" "blah\n" "" ""
180 testing "redir3" "echo more >>out; cat out" "blah\nmore\n" "" ""
181 testing "redir4" "touch /not/exist 2>out||grep -o /not/exist out" \
183 testing "redir5" "ls out /not/exist &> out2 || wc -l < out2" "2\n" "" ""
184 testing "redir6" "ls out /not/exist &>>-abc || wc -l < ./-abc" "2\n" "" ""
185 testing "redir7" "ls out /not/exist |& wc -l" "2\n" "" ""
186 testing "redir8" 'echo -n $(<input)' "boing" "boing\n" ""
189 testing "redir10" 'echo hello 3<&3' "hello\n" "" ""
190 testing "redir11" 'if :;then echo one;fi {abc}<input; cat <&$abc' \
196 testing "tilde expansion" "echo ~" "$HOME\n" "" ""
197 testing "tilde2" "echo ~/dir" "$HOME/dir\n" "" ""
198 testing "bracket expansion" \
200 testing "brackets2" "echo {A{a,b}B{c,d}C,D}" "AaBcC AaBdC AbBcC AbBdC D\n" "" ""
201 testing "brackets3" 'echo {A"b,c"D}' "{Ab,cD}\n" "" ""
202 testing "brackets4" 'echo {A"bc",D}' "Abc D\n" "" ""
203 testing "brackets5" 'echo {A,B,C' "{A,B,C\n" "" ""
204 testing "brackets6" 'echo {{{{A,B},C}D},E}' "{AD} {BD} {CD} E\n" "" ""
205 testing "brackets7" 'echo {{{a,b},c,{d,e}},f}' "a b c d e f\n" "" ""
206 testing "brackets8" 'echo A{a{b,c{B,C}D}d{e,f},g{h,i}j}E' \
208 testing "brackets9" 'echo A{B{C,D}E{N,O},F{G,H}I}J{K,L}M' \
211 testing "bracket+tilde" "echo {~,~root}/pwd" "$HOME/pwd $EXPECT/pwd\n" "" ""
215 testing '${x#prefix}' 'x=abcde; echo ${x#abc}' 'de\n' '' ''
216 testing '${x#short} ${x##long}' 'x=banana; echo ${x#b*n} ${x##b*n}' \
218 toyonly testing '${x#utf8}' 'x=aそcde; echo ${x##a?c}' 'de\n' '' ''
219 testing '${x%y}' 'x=potato; echo ${x%t*o} ${x%%t*o}' 'pota po\n' '' ''
220 testing 'x=${x%y}' 'x=potato; x=${x%t*o}; echo $x' 'pota\n' '' ''
221 testing 'x=${x//y}' 'x=potato; x=${x//ta}; echo $x' 'poto\n' '' ''
222 testing '${x^y}' 'x=aaaaa; echo ${x^a}' 'Aaaaa\n' '' ''
223 testing '${x^^y}' 'x=abccdec; echo ${x^^c}; x=abcdec; echo ${x^^c}' \
225 testing '${x,y}' 'x=BBB; echo ${x,B}' 'bBB\n' '' ''
226 testing '${x,,y}' 'x=POTATO; echo ${x,,} ${x,,?} ${x,,*} ${x,,T}' \
231 testing 'wildcards' 'echo w[v-x]w w[x-v]w abc/*/ghi' \
233 testing 'hidden wildcards' \
237 testing "backtick1" 'x=fred; echo `echo $x`' 'fred\n' "" ""
238 testing "backtick2" 'x=fred; echo `x=y; echo $x`; echo $x' 'y\nfred\n' "" ""
239 testing '$(( ) )' 'echo ab$((echo hello) | tr e x)cd' "abhxllocd\n" "" ""
240 ((++SKIP)); testing '$((x=y)) lifetime' 'a=boing; echo $a $a$((a=4))$a $a' 'boing boing44 4\n' '' ''
242 testing 'quote' "echo \"'\"" "'\n" "" ""
244 testing "math" 'echo $((1+2))' '3\n' '' ''
245 testing "[oldmath]" 'echo $[1+2]' '3\n' '' ''
246 testing "math basic priority" 'echo $((1+2*3**4))' '163\n' '' ''
247 testing "math paren" 'echo $(((1+2)*3))' '9\n' '' ''
248 testing "math spaces" 'echo $(( ( 1 + 2 ) * 7 - 5 ** 2 ))' '-4\n' '' ''
249 testing "((<)) isn't redirect" '((1<2)) </dev/null && echo yes' 'yes\n' '' ''
250 testing "((>)) isn't redirect" '((1>2)) </dev/null || echo yes' 'yes\n' '' ''
251 testing "((not math) )" '((echo hello) )' 'hello\n' '' ''
252 testing "preincrement" 'echo $((++x)); echo $x' '1\n1\n' '' ''
253 testing "preincrement vs prefix plus" 'echo $((+++x)); echo $x' '1\n1\n' '' ''
254 testing "predecrement" 'echo $((--x)); echo $x' '-1\n-1\n' '' ''
255 testing "predecrement vs prefix minus" 'echo $((---x)); echo $x' '1\n-1\n' '' ''
256 testing "minus-minus-minus" 'echo $((x---7)); echo $x' '-7\n-1\n' '' ''
257 testing "x---y is x-- -y not x- --y" 'x=1 y=1; echo $((x---y)) $x $y' '0 0 1\n'\
259 testing "nesting ? :" \
262 testing "inherited assignment suppression" 'echo $((0 ? (x++) : 2)); echo $x' \
264 testing "boolean vs logical" 'echo $((2|4&&8))' '1\n' '' ''
265 testing "&& vs || priority" \
268 testing "|| vs && priority" \
277 testing "case" 'for i in A C J B; do case "$i" in A) echo got A ;; B) echo and B ;; C) echo then C …
279 testing 'case;;&' 'case wow in w?w) echo ok;;& wow) echo no; esac' 'ok\nno\n' \
281 testing "case newlines" \
284 testing "case block" \
286 testing 'loop in && ||' \
288 testing "continue" 'for i in a b c; do for j in d e f; do echo $i $j; continue 2; done; done' \
290 testing "piped loops that don't exit" \
296 testing "expand" 'echo $PWD' "$(pwd)\n" "" ""
297 testing "expand2" 'echo "$PWD"' "$(pwd)\n" "" ""
298 testing "expand3" 'echo "$"PWD' '$PWD\n' "" ""
299 testing "expand4" 'P=x; echo "$P"WD' 'xWD\n' "" ""
300 testing "dequote" "echo one 'two' ''three 'fo'ur '\\'" \
303 testing "leading variable assignment" 'abc=def env | grep ^abc=; echo $abc' \
305 testing "leading variable assignments" \
308 testing "leading assignment occurs after parsing" \
310 testing "leading assignment space" 'X="abc def"; Y=$X; echo "$Y"' \
312 testing "leading assignment space2" \
314 testing "leading assignment fail2" \
316 testing "leading assignment redirect" \
320 testing "{1..5}" "echo {1..5}" "1 2 3 4 5\n" "" ""
321 testing "{5..1}" "echo {5..1}" "5 4 3 2 1\n" "" ""
322 testing "{5..1..2}" "echo {5..1..2}" "5 3 1\n" "" ""
323 testing "{a..z..-3}" "echo {a..z..-3}" "a d g j m p s v y\n" "" ""
326 testing 'background curly block' \
331 testing 'background pipe block' \
334 testing 'background variable assignment' 'X=x; X=y & echo $X' 'x\n' '' ''
341 testing "IFS whitespace before/after" \
344 testing "quotes and whitespace" \
347 testing "quotes and whitespace2" \
350 testing "quotes and whitespace3" \
354 testing "IFS" 'IFS=x; A=abx; echo -n "$A"' "abx" "" ""
355 testing "IFS2" 'IFS=x; A=abx; echo -n $A' "ab" "" ""
356 testing "IFS3" 'IFS=x; echo "$(echo abx)"' "abx\n" "" ""
357 testing "IFS4" 'IFS=x; echo $(echo abx)y' "ab y\n" "" ""
358 testing "IFS5" 'IFS=xy; for i in abcxdefyghi; do echo =$i=; done' \
360 testing "curly bracket whitespace" 'for i in {$,} ""{$,}; do echo ="$i"=; done'\
363 testing 'empty $! is blank' 'echo $!' "\n" "" ""
364 testing '$! = jobs -p' 'true & [ $(jobs -p) = $! ] && echo yes' "yes\n" "" ""
366 testing '$*' 'cc(){ for i in $*;do echo =$i=;done;};cc "" "" "" "" ""' \
368 testing '$*2' 'cc(){ for i in "$*";do echo =$i=;done;};cc ""' \
370 testing '$*3... Flame. Flames. Flames, on the side of my face...' \
372 testing 'why... oh.' \
375 testing 'really?' 'cc() { for i in $*; do echo -$i-; done;}; cc "" "" ""' \
377 testing 'Sigh.' 'cc() { echo =$1$2=;}; cc "" ""' "==\n" "" ""
378 testing '$*4' 'cc(){ for i in "$*";do echo =$i=;done;};cc "" "" "" "" ""' \
380 testing '$*5' 'cc(){ for i in "$*";do echo =$i=;done;};cc "" "abc" ""' \
384 testing '$* + IFS' \
387 testing '$@' 'cc(){ for i in "$@";do echo =$i=;done;};cc "" "" "" "" ""' \
389 testing "IFS10" 'IFS=bcd; A=abcde; for i in $A; do echo =$i=; done' \
391 testing "IFS11" \
394 testing "IFS12" 'IFS=3;chicken(){ return 3;}; chicken;echo 3$?3' '3 3\n' "" ""
396 testing "IFS combinations" \
400 testing "! isn't special" "echo !" "!\n" "" ""
401 testing "! by itself" '!; echo $?' "1\n" "" ""
402 testing "! true" '! true; echo $?' "1\n" "" ""
403 testing "! ! true" '! ! true; echo $?' "0\n" "" ""
404 testing "! syntax err" '! echo 2>/dev/null < doesnotexist; echo $?' "0\n" "" ""
407 testing "case quoting" 'case a in "a") echo hello;; esac' 'hello\n' "" ""
409 testing "subshell splitting" 'for i in $(true); do echo =$i=; done' "" "" ""
410 testing "subshell split 2" 'for i in $(echo "one two thr"); do echo =$i=; done'\
414 testing "assignment nosplit" 'X="one two"; Y=$X; echo $Y' "one two\n" "" ""
415 testing "argument splitting" \
418 testing "assignment nosplit2" 'pop(){ X="$@";};pop one two three; echo $X' \
421 #testing "leading assignments don't affect current line" \
423 #testing "can't have space before first : but yes around arguments" \
426 testing "subshell exit err" '(exit 42); echo $?' "42\n" "" ""
429 #testing 'exec and $$' testing 'echo $$;exec readlink /proc/self'
432 testing "exec in paren" \
434 testing "exec in brackets" \
437 NOSPACE=1 testing "curly brackets and pipe" \
440 NOSPACE=1 testing "parentheses and pipe" \
443 testing "pipe into parentheses" \
447 testing "\$''" $'echo $\'abc\\\'def\\nghi\'' "abc'def\nghi\n" '' ''
448 testing "shift shift" 'shift; shift; shift; echo $? hello' "1 hello\n" "" ""
449 testing 'search cross $*' 'chicken() { echo ${*/b c/ghi}; }; chicken a b c d' \
451 testing 'eval $IFS' 'IFS=x; X=x; eval abc=a${X}b 2>/dev/null; echo $abc' \
453 testing '${@:3:5}' 'chicken() { for i in "${@:3:5}"; do echo =$i=; done; } ; chicken ab cd ef gh ij…
455 testing '${@:3:5}' 'chicken() { for i in "${*:3:5}"; do unset IFS; echo =$i=; done; } ; IFS=x chick…
457 testing 'sequence check' 'IFS=x; X=abxcd; echo ${X/bxc/g}' 'agd\n' '' ''
470 testing 'here3' 'abc(){ cat <<< x"$@"yz;};abc one two "three four"' \
472 testing 'here4' 'for i in one two three; do cat <<< "ab${i}de"; done' \
474 testing 'here5' $'cat << EOF && cat << EOF2\nEOF2\nEOF\nEOF\nEOF2' \
477 testing 'here6' $'cat << EOF""\n$POTATO\nEOF' '$POTATO\n' '' ''
479 testing 'here7' 'ABC="abc def"; cat <<< $ABC' 'abc def\n' '' ''
481 testing 'here8' $'ABC="x y"\ncat << EOF\n~root/{"$ABC",def}\nEOF' \
484 testing 'here9' $'A=$\'\\tone\'; cat <<- EOF\n$A\n\ttwo\nEOF' "\tone\ntwo\n" \
487 testing '${var}' 'X=abcdef; echo ${X}' 'abcdef\n' '' ''
488 testing '${#}' 'X=abcdef; echo ${#X}' "6\n" "" ""
489 testing 'empty ${}' '{ echo ${};} 2>&1 | grep -o bad' 'bad\n' '' ''
492 testing '${$b}' '{ echo ${$b};} 2>&1 | grep -o bad' 'bad\n' '' ''
493 testing '${!PATH*}' 'echo ${!PATH*}' 'PATH\n' '' ''
494 testing '${!PATH@}' 'echo ${!PATH@}' 'PATH\n' '' ''
495 #testing '${!PATH[@]}' 'echo ${!PATH[@]}' '0\n' '' ''
496 testing '${!x}' 'X=abcdef Y=X; echo ${!Y}' 'abcdef\n' '' ''
497 testing '${!x@}' 'ABC=def; def=ghi; echo ${!ABC@}' 'ABC\n' '' ''
498 testing '${!x} err' '{ X=abcdef Y=X:2; echo ${!Y}; echo bang;} 2>/dev/null' \
500 testing '${!x*}' 'abcdef=1 abc=2 abcq=; echo "${!abc@}" | tr " " \\n | sort' \
502 testing '${!x*} none' 'echo "${!abc*}"' '\n' '' ''
503 testing '${!x*} err' '{ echo "${!abc*x}"; echo boing;} 2>/dev/null' '' '' ''
505 #testing '${!none@Q}' 'echo ${X@Q} ${!X@Q}; X=ABC; echo ${!X@Q}' '\n\n' '' ''
506 testing '${!x@Q}' 'ABC=123 X=ABC; echo ${!X@Q}' "'123'\n" '' ''
507 testing '${#@Q}' 'echo ${#@Q}' "'0'\n" '' ''
508 testing '${!*}' 'xx() { echo ${!*};}; fruit=123; xx fruit' '123\n' '' ''
509 testing '${!*} indirect' 'xx() { echo ${!a@Q};}; a=@; xx one two three' \
511 testing '${!x@ } match' \
514 #testing '${!x@ } no match no err' 'echo ${!ABC@ }def' 'def\n' '' ''
515 testing '${!x@ } no match no err2' 'ABC=def; echo ${!ABC@ }ghi' 'ghi\n' '' ''
516 toyonly testing '${#x::}' 'ABC=abcdefghijklmno; echo ${#ABC:1:2}' '5\n' '' ''
518 testing '$""' 'ABC=def; echo $"$ABC"' 'def\n' '' ''
519 testing '"$""" does not nest' 'echo "$"abc""' '$abc\n' '' ''
520 testing '${\}}' 'ABC=ab}cd; echo ${ABC/\}/x}' 'abxcd\n' '' ''
521 testing 'bad ${^}' '{ echo ${^};} 2>&1 | grep -o bad' 'bad\n' '' ''
522 testing '${:}' 'ABC=def; echo ${ABC:1}' 'ef\n' '' ''
523 testing '${a: }' 'ABC=def; echo ${ABC: 1}' 'ef\n' '' ''
524 testing '${a :}' 'ABC=def; { echo ${ABC :1};} 2>&1 | grep -o bad' 'bad\n' '' ''
525 testing '${::}' 'ABC=defghi; echo ${ABC:1:2}' 'ef\n' '' ''
526 testing '${: : }' 'ABC=defghi; echo ${ABC: 1 : 2 }' 'ef\n' '' ''
527 testing '${::} indirect' \
530 testing '${::-}' 'ABC=defghi; echo ${ABC:1:-2}' 'efg\n' '' ''
531 testing '${:-:-}' 'ABC=defghi; echo ${ABC:-3:2}' 'defghi\n' '' ''
532 testing '${:-:-}2' 'echo ${ABC:-3:2}' '3:2\n' '' ''
533 testing '${: -:}' 'ABC=defghi; echo ${ABC: -3:2}' 'gh\n' '' ''
534 testing '${@%}' 'chicken() { for i in "${@%abc}"; do echo "=$i="; done;}; chicken 1abc 2abc 3abc' '…
535 testing '${*%}' 'chicken() { for i in "${*%abc}"; do echo "=$i="; done;}; chicken 1abc 2abc 3abc' '…
536 testing '${@@Q}' 'xx() { echo "${@@Q}"; }; xx one two three' \
546 testing 'SECONDS' 'readonly SECONDS=41; sleep 1; echo $SECONDS' '42\n' '' ''
547 # testing 'SECONDS2' 'readonly SECONDS; SECONDS=0; echo $SECONDS' '' '' '' #bash!
548 testing 'SECONDS2' 'SECONDS=123+456; echo $SECONDS' '0\n' '' '' #bash!!
549 testing '$LINENO 2' $'echo $LINENO\necho $LINENO' '0\n1\n' '' ''
550 testing '$EUID' 'echo $EUID' "$(id -u)\n" '' ''
551 testing '$UID' 'echo $UID' "$(id -ur)\n" '' ''
553 testing 'readonly leading assignment' \
556 testing 'readonly leading assignment2' \
558 testing 'readonly for' \
561 testing 'readonly {}<' \
563 testing '$_ 1' 'echo walrus; echo $_' 'walrus\nwalrus\n' '' ''
564 testing '$_ 2' 'unset _; echo $_' '_\n' '' ''
569 testing 'IFS wildcards' \
599 testing 'source file' 'source input' 'hello\n' 'echo hello \\\n' ''
600 testing '. file' '. input' 'hello\n' 'echo hello \\\n' ''
601 testing 'source no newline' 'source input' 'hello \\\n' 'echo hello \\' ''
602 testing 'source is live' \
605 testing 'source is live in functions' \
608 testing 'subshell inheritance' \
611 testing 'semicolon vs newline' \
614 testing 'syntax err pops to source but encapsulating function continues' \
617 testing '"exit shell" means exit eval but encapsulating function continues' \
622 testing 'functions() {} in same PID' \
624 testing 'functions() () different PID' \
626 testing 'function() just wants any block span' \
629 testing 'function alternate syntax' \
632 testing 'function syntax 3' \
635 testing 'function nested parentheses' \
640 testing 'local replaces/preserves magic type' \
644 testing '$$ is parent shell' \
646 testing '$PPID is parent shell' \
648 testing '$BASHPID is current PID' \
651 testing 'unexport supports +=' 'export -n ABC+=DEF; declare -p ABC' \
653 testing 'unexport existing +=' \
657 testing '$!' '{ echo $BASHPID & echo $!; echo ${!};} | sort -u | wc -l' '1\n' \
662 testing 'NOP line clears $?' 'false;$NOTHING;echo $?' '0\n' '' ''
663 testing 'run "$@"' 'false;"$@";echo $?' '0\n' '' ''
666 testing '[[split1]]' 'A="1 -lt 2"; [[ $A ]] && echo yes' 'yes\n' '' ''
667 testing '[[split2]]' 'A="2 -lt 1"; [[ $A ]] && echo yes' 'yes\n' '' ''
668 testing '[[split3]]' \
672 testing '[[split4]]' \
675 testing '[[split5]]' \
679 testing '[[1>2]] is not a redirect' '[[ 1 >2 ]] || [ -e 2 ] || echo yup' \
681 testing "[[1 >0]] doesn't need that second space" \
683 testing '[[1<2]] is alphabetical, not numeric' '[[ 123 < 19 ]] && echo yes' \
685 testing '[[~]]' '[[ ~ == $HOME ]] && echo yes' 'yes\n' '' ''