1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

regress tests: remove use of unportable direct paths to commands

Many tests used direct paths to some commands, mostly /bin/echo and
/bin/cat. This is unportable (breaks on e.g. NixOS).
The correct way is to obtain the direct path using 'whence -p'.

There was also one use of '/usr/bin/pstack' in tests/comvario.sh
that seemed bogus. Apparently this was supposed to analyse a core
file after a crash. Even on Solaris and Linux, where that command
exists, the argument is documented to be a PID, not a core file. If
this ever worked anywhere, then it was system-specific enough to be
useless here, so I've removed it.

(cherry picked from commit 4563b8bc651cd9cb18dc73f56a041f7ac5534395)
This commit is contained in:
Martijn Dekker 2020-06-04 22:49:37 +02:00
parent 3552a2bafd
commit b6b8b522a7
13 changed files with 53 additions and 48 deletions

View file

@ -36,6 +36,8 @@ tmp=$(
exit 1
}
trap 'cd / && rm -rf "$tmp"' EXIT
bincat=$(whence -p cat)
binecho=$(whence -p echo)
# test basic file operations like redirection, pipes, file expansion
set -- \
@ -155,7 +157,7 @@ then err_exit "$foobar is not foobar"
fi
{
print foo
/bin/echo bar
"$binecho" bar
print bam
} > $tmp/foobar
if [[ $( < $tmp/foobar) != $'foo\nbar\nbam' ]]
@ -163,17 +165,17 @@ then err_exit "output file pointer not shared correctly"
fi
cat > $tmp/foobar <<\!
print foo
/bin/echo bar
"$binecho" bar
print bam
!
chmod +x $tmp/foobar
if [[ $($tmp/foobar) != $'foo\nbar\nbam' ]]
if [[ $(export binecho; $tmp/foobar) != $'foo\nbar\nbam' ]]
then err_exit "script not working"
fi
if [[ $($tmp/foobar | /bin/cat) != $'foo\nbar\nbam' ]]
if [[ $(export binecho; $tmp/foobar | "$bincat") != $'foo\nbar\nbam' ]]
then err_exit "script | cat not working"
fi
if [[ $( $tmp/foobar) != $'foo\nbar\nbam' ]]
if [[ $(export binecho; $tmp/foobar) != $'foo\nbar\nbam' ]]
then err_exit "output file pointer not shared correctly"
fi
rm -f $tmp/foobar
@ -181,13 +183,13 @@ x=$( (print foo) ; (print bar) )
if [[ $x != $'foo\nbar' ]]
then err_exit " ( (print foo);(print bar ) failed"
fi
x=$( (/bin/echo foo) ; (print bar) )
x=$( ("$binecho" foo) ; (print bar) )
if [[ $x != $'foo\nbar' ]]
then err_exit " ( (/bin/echo);(print bar ) failed"
then err_exit " ( ("$binecho");(print bar ) failed"
fi
x=$( (/bin/echo foo) ; (/bin/echo bar) )
x=$( ("$binecho" foo) ; ("$binecho" bar) )
if [[ $x != $'foo\nbar' ]]
then err_exit " ( (/bin/echo);(/bin/echo bar ) failed"
then err_exit " ( ("$binecho");("$binecho" bar ) failed"
fi
cat > $tmp/script <<\!
if [[ -p /dev/fd/0 ]]
@ -221,7 +223,7 @@ if [[ $x != "hello there" ]]
then err_exit "scripts in subshells fail"
fi
cd ~- || err_exit "cd back failed"
x=$( (/bin/echo foo) 2> /dev/null )
x=$( ("$binecho" foo) 2> /dev/null )
if [[ $x != foo ]]
then err_exit "subshell in command substitution fails"
fi
@ -233,15 +235,15 @@ then err_exit "command substitution with stdout closed failed"
fi
exec >& 9
cd $pwd
x=$(cat <<\! | $SHELL
/bin/echo | /bin/cat
/bin/echo hello
x=$(export binecho bincat; cat <<\! | $SHELL
"$binecho" | "$bincat"
"$binecho" hello
!
)
if [[ $x != $'\n'hello ]]
then err_exit "$SHELL not working when standard input is a pipe"
fi
x=$( (/bin/echo hello) 2> /dev/null )
x=$( ("$binecho" hello) 2> /dev/null )
if [[ $x != hello ]]
then err_exit "subshell in command substitution with 1 closed fails"
fi
@ -265,22 +267,22 @@ fi
trap - INT
cat > $tmp/script <<- \!
read line
/bin/cat
"$bincat"
!
if [[ $($SHELL $tmp/script <<!
if [[ $(export bincat; $SHELL $tmp/script <<!
one
two
!
) != two ]]
then err_exit "standard input not positioned correctly"
fi
word=$(print $'foo\nbar' | { read line; /bin/cat;})
word=$(print $'foo\nbar' | { read line; "$bincat";})
if [[ $word != bar ]]
then err_exit "pipe to { read line; /bin/cat;} not working"
then err_exit "pipe to { read line; $bincat;} not working"
fi
word=$(print $'foo\nbar' | ( read line; /bin/cat) )
word=$(print $'foo\nbar' | ( read line; "$bincat") )
if [[ $word != bar ]]
then err_exit "pipe to ( read line; /bin/cat) not working"
then err_exit "pipe to ( read line; $bincat) not working"
fi
if [[ $(print x{a,b}y) != 'xay xby' ]]
then err_exit 'brace expansion not working'

View file

@ -36,6 +36,7 @@ tmp=$(
exit 1
}
trap 'cd / && rm -rf "$tmp"' EXIT
bincat=$(whence -p cat)
# test shell builtin commands
builtin getconf
@ -101,7 +102,7 @@ hello \
!
[[ $REPLY == 'hello world' ]] || err_exit "read continuation2 failed"
print "one\ntwo" | { read line
print $line | /bin/cat > /dev/null
print $line | "$bincat" > /dev/null
read line
}
read <<\!
@ -559,6 +560,7 @@ builtin cat
out=$tmp/seq.out
for ((i=1; i<=11; i++)); do print "$i"; done >$out
cmp -s <(print -- "$($bincat<( $bincat $out ) )") <(print -- "$(cat <( cat $out ) )") || err_exit "builtin cat differs from $bincat"
builtin -d cat
[[ $($SHELL -c '{ printf %R "["; print ok;}' 2> /dev/null) == ok ]] || err_exit $'\'printf %R "["\' causes shell to abort'

View file

@ -529,11 +529,6 @@ print -v c2
[[ "${out.stdout}" != '' ]] || err_exit "$0: Expected nonempty stdout."
[[ "${out.stderr}" == '' ]] || err_exit "$0: Expected empty stderr, got $(printf '%q\n' "${out.stderr}")"
if [[ -f 'core' && -x '/usr/bin/pstack' ]] ; then
pstack 'core'
rm 'core'
fi
return 0
}

View file

@ -41,6 +41,7 @@ tmp=$(
exit 1
}
trap 'cd / && rm -rf "$tmp"' EXIT
binecho=$(whence -p echo)
integer foo=33
bar=bye
@ -141,7 +142,7 @@ fi
if [[ $PWD != "$dir" ]]
then err_exit 'cd inside nested subshell changes $PWD'
fi
fun() /bin/echo hello
fun() "$binecho" hello
if [[ $(fun) != hello ]]
then err_exit one line functions not working
fi

View file

@ -105,7 +105,7 @@ case $* in
'b B') contrary=1 ;;
b|B) ignorant=1 ;;
esac
set -- $(LC_ALL=C /bin/sh -c 'echo [a-c]')
set -- $(LC_ALL=C sh -c 'echo [a-c]')
case $* in
B) aware=1 ;;
esac

View file

@ -36,6 +36,7 @@ tmp=$(
exit 1
}
trap 'cd / && rm -rf "$tmp"' EXIT
bincat=$(whence -p cat)
f=$tmp/here1
g=$tmp/here2
@ -125,7 +126,7 @@ done
} > $f
chmod +x "$f"
$SHELL "$f" > /dev/null || err_exit "large here-doc with command substitution fails"
x=$(/bin/cat <<!
x=$("$bincat" <<!
$0
!
)
@ -186,7 +187,7 @@ cat > "$f" <<- '!!!!'
exec 0<&-
foobar()
{
/bin/cat <<- !
"$bincat" <<- !
foobar
!
}
@ -212,7 +213,7 @@ cat > "$f" <<- '!!!!'
EOF
print -r -- "$(foobar)"
!!!!
if [[ $($SHELL "$f") != foobar ]]
if [[ $(export bincat; "$SHELL" "$f") != foobar ]]
then err_exit 'here document with stdin closed failed'
fi
printf $'cat <<# \\!!!\n\thello\n\t\tworld\n!!!' > $f

View file

@ -478,9 +478,9 @@ print hello there world > $tmp/foobar
$SHELL -c "sed -e 's/there //' $tmp/foobar >; $tmp/foobar"
[[ $(<$tmp/foobar) == 'hello world' ]] || err_exit '>; redirection not working with -c on a simple command'
rm -f "$tmp/junk"
binfalse=$(whence -p false)
for (( i=1; i < 50; i++ ))
do out=$(/bin/ls "$tmp/junk" 2>/dev/null)
do out=$("$binfalse" 2>/dev/null)
if (( $? == 0 ))
then err_exit 'wrong error code with redirection'
break

View file

@ -41,6 +41,7 @@ tmp=$(
exit 1
}
trap 'cd / && rm -rf "$tmp"' EXIT
bincat=$(whence -p cat)
if [[ $( ${SHELL-ksh} -s hello<<-\!
print $1
@ -367,7 +368,7 @@ pipeline=(
( nopipefail=1 pipefail=1 command='true|true|false' )
( nopipefail=1 pipefail=1 command='false|false|false' )
( nopipefail=0 pipefail=0 command='true|true|true' )
( nopipefail=0 pipefail=0 command='print hi|(sleep 1;/bin/cat)>/dev/null' )
( nopipefail=0 pipefail=0 command='print hi|(sleep 1;"$bincat")>/dev/null' )
)
set --nopipefail
for ((i = 0; i < ${#pipeline[@]}; i++ ))

View file

@ -27,6 +27,8 @@ alias err_exit='err_exit $LINENO'
Command=${0##*/}
integer Errors=0
binecho=$(whence -p echo)
if [[ 'hi there' != "hi there" ]]
then err_exit "single quotes not the same as double quotes"
fi
@ -184,7 +186,7 @@ fi
if [[ $x$ != '$hi$' ]]
then err_exit ' $x$, with x=$hi, does not expand to $hi$'
fi
set -- $(/bin/echo foo;sleep 1;/bin/echo bar)
set -- $("$binecho" foo; sleep 1; "$binecho" bar)
if [[ $# != 2 ]]
then err_exit 'word splitting after command substitution not working'
fi

View file

@ -36,6 +36,7 @@ tmp=$(
exit 1
}
trap 'cd / && rm -rf "$tmp"' EXIT
binecho=$(whence -p echo)
# test restricted shell
pwd=$PWD
@ -57,7 +58,7 @@ ln -s $SHELL rksh
PATH=$PWD:$PATH
rksh -c '[[ -o restricted ]]' || err_exit 'restricted option not set'
[[ $(rksh -c 'print hello') == hello ]] || err_exit 'unable to run print'
check_restricted /bin/echo || err_exit '/bin/echo not resticted'
check_restricted "$binecho" || err_exit "$binecho not resticted"
check_restricted ./echo || err_exit './echo not resticted'
check_restricted 'SHELL=ksh' || err_exit 'SHELL assignment not resticted'
check_restricted 'PATH=/bin' || err_exit 'PATH assignment not resticted'
@ -70,7 +71,7 @@ print 'echo hello' > script
chmod +x ./script
! check_restricted script || err_exit 'script without builtins should run in restricted mode'
check_restricted ./script || err_exit 'script with / in name should not run in restricted mode'
print '/bin/echo hello' > script
printf '%q hello\n' "$binecho" > script
! check_restricted script || err_exit 'script with pathnames should run in restricted mode'
print 'echo hello> file' > script
! check_restricted script || err_exit 'script with output redirection should run in restricted mode'

View file

@ -155,7 +155,7 @@ done
(( d==2000 )) || err_exit "trap '' CHLD causes side effects d=$d"
trap - CHLD
x=$($SHELL 2> /dev/null -ic '/bin/notfound; sleep .5 & sleep 1;jobs')
x=$($SHELL 2> /dev/null -ic '/dev/null/notfound; sleep .5 & sleep 1;jobs')
[[ $x == *Done* ]] || err_exit 'SIGCHLD blocked after notfound'
x=$($SHELL 2> /dev/null -ic 'kill -0 12345678901234567876; sleep .5 & sleep 1;jobs')
[[ $x == *Done* ]] || err_exit 'SIGCHLD blocked after error message'

View file

@ -283,18 +283,18 @@ then float s=$SECONDS
(( SECONDS-s < 4 )) && err_exit 'parent completes early'
fi
yes=$(whence -p yes)
if [[ $yes ]]
then for exp in TERM VTALRM PIPE
yes() for ((;;)); do print y; done
for exp in TERM VTALRM PIPE
do if [[ ${SIG[$exp]} ]]
then {
$SHELL <<- EOF
bindate=$(whence -p date) "$SHELL" <<- EOF
foo() { return 0; }
trap foo EXIT
{ sleep 2; kill -$exp \$\$; sleep 3; kill -0 \$\$ && kill -KILL \$\$; } &
$yes |
yes |
while read yes
do (/bin/date; sleep .1)
do ("\$bindate"; sleep .1)
done > /dev/null
EOF
} 2>> /dev/null
@ -302,7 +302,6 @@ then for exp in TERM VTALRM PIPE
[[ $exp == $got ]] || err_exit "kill -$exp \$\$ failed, required termination by signal '$got'"
fi
done
fi
SECONDS=0
$SHELL 2> /dev/null -c 'sleep 2 && kill $$ & trap "print done; exit 3" EXIT; (sleep 5); print finished' > $tmp/sig

View file

@ -39,6 +39,7 @@ trap 'cd / && rm -rf "$tmp"' EXIT
builtin getconf
bincat=$(PATH=$(getconf PATH) whence -p cat)
binecho=$(PATH=$(getconf PATH) whence -p echo)
z=()
z.foo=( [one]=hello [two]=(x=3 y=4) [three]=hi)
@ -466,9 +467,9 @@ exp=ok
got=$($SHELL -c "$cmd" 2>&1)
[[ $got == "$exp" ]] || err_exit "'$cmd' failed -- expected '$exp', got '$got'"
cmd='eval "for i in 1 2; do eval /bin/echo x; done"'
cmd='eval '\''for i in 1 2; do eval "\"\$binecho\" x"; done'\'
exp=$'x\nx'
got=$($SHELL -c "$cmd")
got=$(export binecho; $SHELL -c "$cmd")
if [[ $got != "$exp" ]]
then EXP=$(printf %q "$exp")
GOT=$(printf %q "$got")
@ -482,7 +483,7 @@ $SHELL -c 'sleep 20 & pid=$!; { x=$( ( seq 60000 ) );kill -9 $pid;}&;wait $pid'
(.sh.foo=foobar)
[[ ${.sh.foo} == foobar ]] && err_exit '.sh subvariables in subshells remain set'
[[ $($SHELL -c 'print 1 | : "$(/bin/cat <(/bin/cat))"') ]] && err_exit 'process substitution not working correctly in subshells'
[[ $($SHELL -c 'print 1 | : "$("$bincat" <("$bincat"))"') ]] && err_exit 'process substitution not working correctly in subshells'
# config hang bug
integer i