From b98713b1e706f37ff01e9a0dd88caf0cfe0a7d59 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 16 Apr 2020 10:27:41 -0500 Subject: Yet more shell tests. --- tests/sh.test | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) mode change 100755 => 100644 tests/sh.test (limited to 'tests') diff --git a/tests/sh.test b/tests/sh.test old mode 100755 new mode 100644 index f9122e34..7a614775 --- a/tests/sh.test +++ b/tests/sh.test @@ -17,7 +17,6 @@ # run sufficiently isolated shell child process to get predictable results SS="env -i PATH=${PATH@Q} PS1='\\$ ' $SH --noediting --noprofile --norc -is" - shxpect() { X="$1" shift @@ -44,6 +43,8 @@ testing 'exec exitval' "$SH -c 'exec echo hello' && echo \$?" "hello\n0\n" "" "" testing 'simple script' '$SH input' 'input\n' 'echo $0' '' testing 'simple script2' '$SH ./input two;echo $?' './input+two\n42\n' \ '\necho $0+$1\n\nexit 42' '' +testing 'shift' "$SH -c '"'for i in "" 2 1 1 1; do echo $? $1; shift $i; done'"' one two three four five" \ + "0 two\n0 three\n0 five\n0\n1\n" "" "" mkdir sub echo echo hello > sub/script @@ -90,6 +91,9 @@ testing "redir7" "ls out /not/exist |& wc -l" "2\n" "" "" testing "redir8" 'echo -n $( out 2>/does/not/exist\n' E E"$P" \ I$'wc -l < out\n' O$'0\n' +testing "redir10" 'echo hello 3<&3' "hello\n" "" "" +testing "redir11" 'if :;then echo one;fi {abc}A variable occurred @@ -254,6 +261,15 @@ testing 'here3' 'abc(){ cat <<< x"$@"yz;};abc one two "three four"' \ testing '${#}' 'X=abcdef; echo ${#X}' "6\n" "" "" +# Race condition, can say 43. +#testing 'SECONDS' 'SECONDS=41; sleep 1; echo $SECONDS' '42\n' '' '' +testing 'SECONDS2' 'readonly SECONDS; SECONDS=0; echo $SECONDS' '' '' '' # bash! +testing 'SECONDS3' 'SECONDS=123+456; echo $SECONDS' '0\n' '' '' #bash!! +testing 'LINENO' $'echo $LINENO\necho $LINENO' '0\n1\n' '' '' +testing 'EUID' 'echo $EUID' "$(id -u)\n" '' '' +testing 'UID' 'echo $UID' "$(id -ur)\n" '' '' +# TODO finish variable list from shell init + # $# $? $- $$ $! $0 # always exported: PWD SHLVL _ # ./bash -c 'echo $_' prints $BASH, but PATH search shows path? Hmmm... -- cgit v1.2.3