From b3691449460ff9ac6167e34fd56da95c4777ec82 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 6 Dec 2023 05:16:25 -0600 Subject: [PATCH] A few more shell tests. --- tests/sh.test | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/sh.test b/tests/sh.test index d13acd836..306a43928 100644 --- a/tests/sh.test +++ b/tests/sh.test @@ -100,6 +100,7 @@ export EVAL="timeout 10 $SH -c" testing 'return code' 'if false; then echo true; fi; echo $?' '0\n' '' '' testing 'return code 2' 'if true; then false; fi; echo $?' '1\n' '' '' testing 'return code 3' 'x=0; while [ $((x++)) -lt 2 ]; do echo $x; done; echo $?' '1\n2\n0\n' '' '' +testing 'return code 4' 'false; A=B; echo $?' '0\n' '' '' testing 'local var +whiteout' \ 'l=X;x(){ local l=47; echo $l;unset l; echo l=$l;};x;echo $l' '47\nl=\nX\n' \ '' '' @@ -107,18 +108,34 @@ testing 'escape passthrough' 'echo -e "a\nb\nc\td"' 'a\nb\nc\td\n' '' '' testing 'trailing $ is literal' 'echo $' '$\n' '' '' testing 'work after HERE' $'cat<<0;echo hello\npotato\n0' 'potato\nhello\n' '' '' +testing '<<\EOF' $'(cat</dev/null\nabcde\nnext\\\nEOF\nEOF' \ 'abcde\nnextEOF\n' '' '' testing '<< trailing \ 2' $'cat< ' I$'> blah\n' E"$P" \ shxpect 'line continuation2' I$'echo ABC\\\n' E'> ' I$'DEF\n' O$'ABCDEF\n' testing "line continuation3" $'ec\\\nho hello' 'hello\n' '' '' testing "line continuation4" $'if true | \\\n(true);then echo true;fi' 'true\n' '' '' +testing "line continuation5" $'XYZ=xyz; echo "abc$\\\nXYZ"' 'abcxyz\n' '' '' # Race condition (in bash, but not in toysh) can say 43. testing 'SECONDS' 'readonly SECONDS=41; sleep 1; echo $SECONDS' '42\n' '' '' @@ -696,6 +719,9 @@ testing 'quoting contexts nest' \ $'echo -n "$(echo "hello $(eval $\'echo -\\\\\\ne \\\'world\\n \\\'\')")"' \ 'hello world\n ' '' '' +testing 'if; is a syntax error but if $EMPTY; is not' \ + 'if $NONE; then echo hello; fi' 'hello\n' '' '' + # TODO finish variable list from shell init # $# $? $- $! $0 # $$