From fb652a7e50742b420d6488dfaa907ce2f63a5393 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Mon, 8 Jun 2020 23:51:57 +0200 Subject: [PATCH] shtests: fix loose ends src/cmd/ksh93/tests/variables.sh: - Tolerate a bit more time for the SECONDS verification test. src/cmd/ksh93/tests/subshell.sh: - Replace unportable 'head -c 1' by 'dd bs=1 count=1' - Remove unnecessary uses of 'whence'. src/cmd/ksh93/tests/builtins.sh: - Add a regression test for a weirdly specific 'whence' bug exposed by the aforementioned unneccessary uses of 'whence', which only shows up on my old Power Mac G5 running Mac OS X 10.3. For all I know it's a compiler bug, but let's add a more clear failure for it here, in case that happens anywhere else. (cherry picked from commit c3898bd1e6e40874845771d33a5b37220ef0b06e) --- src/cmd/ksh93/tests/builtins.sh | 7 +++++++ src/cmd/ksh93/tests/subshell.sh | 3 +-- src/cmd/ksh93/tests/variables.sh | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cmd/ksh93/tests/builtins.sh b/src/cmd/ksh93/tests/builtins.sh index 2f43aab5f..58ed91cff 100755 --- a/src/cmd/ksh93/tests/builtins.sh +++ b/src/cmd/ksh93/tests/builtins.sh @@ -679,5 +679,12 @@ expect=$'*: times: incorrect syntax' actual=$(set +x; eval 'times Extra Args' 2>&1) [[ $actual == $expect ]] || err_exit "times with args: expected $(printf %q "$expect"), got $(printf %q "$actual"))" +# ====== +# 'whence' builtin +PATH=$tmp:$PATH $SHELL <<-\EOF || err_exit "'whence' gets wrong path on init" + wc=$(whence wc) + [[ -x $wc ]] +EOF + # ====== exit $((Errors<125?Errors:125)) diff --git a/src/cmd/ksh93/tests/subshell.sh b/src/cmd/ksh93/tests/subshell.sh index 37da42fc4..8187ca933 100755 --- a/src/cmd/ksh93/tests/subshell.sh +++ b/src/cmd/ksh93/tests/subshell.sh @@ -613,8 +613,7 @@ printf=$(whence -p printf) $SHELL 2> /dev/null -c '( PATH=/bin; set -o restricted) ; exit 0' || err_exit 'restoring PATH when a subshell enables restricted exits not working' $SHELL <<- \EOF - wc=$(whence wc) head=$(whence head) - print > /dev/null $( ( $head -c 1 /dev/zero | ( $wc -c) 3>&1 ) 3>&1) & + print > /dev/null $( ( dd if=/dev/zero bs=1 count=1 2>/dev/null | ( wc -c) 3>&1 ) 3>&1) & pid=$! sleep .2 kill -9 $! 2> /dev/null && err_exit '/dev/zero in command substitution hangs' diff --git a/src/cmd/ksh93/tests/variables.sh b/src/cmd/ksh93/tests/variables.sh index ecf0347d2..db93f93ef 100755 --- a/src/cmd/ksh93/tests/variables.sh +++ b/src/cmd/ksh93/tests/variables.sh @@ -440,7 +440,7 @@ function foo } x=$(foo) -(( x >.001 && x < .01 )) +(( x >.001 && x < 1 )) ' } 2> /dev/null || err_exit 'SECONDS not working in function' cat > $tmp/script <<-\!