1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

Allow regression tests to pass without any /opt/ast/bin builtins (#403)

This commit primarily makes changes that allow the regression tests to
run without any of the /opt/ast/bin builtins compiled into ksh. It also
makes a minor improvement to one of the tests in locale.sh by
shellquoting an error message.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
Johnothan King 2021-12-28 08:57:50 -08:00 committed by Martijn Dekker
parent 0e197eee57
commit de795e1f9d
8 changed files with 237 additions and 211 deletions

View file

@ -184,6 +184,7 @@ x=$( ("$binecho" foo) ; ("$binecho" bar) )
if [[ $x != $'foo\nbar' ]] if [[ $x != $'foo\nbar' ]]
then err_exit " ( ("$binecho");("$binecho" bar ) failed" then err_exit " ( ("$binecho");("$binecho" bar ) failed"
fi fi
if (builtin cat) 2> /dev/null; then
cat > $tmp/script <<\! cat > $tmp/script <<\!
if [[ -p /dev/fd/0 ]] if [[ -p /dev/fd/0 ]]
then builtin cat then builtin cat
@ -204,6 +205,7 @@ chmod +x $tmp/scriptx
if [[ $($tmp/scriptx) != $tmp/scriptx ]] if [[ $($tmp/scriptx) != $tmp/scriptx ]]
then err_exit '$0 not correct for . script' then err_exit '$0 not correct for . script'
fi fi
fi
cd $tmp || { err_exit "cd $tmp failed"; exit 1; } cd $tmp || { err_exit "cd $tmp failed"; exit 1; }
print ./b > ./a; print ./c > b; print ./d > c; print ./e > d; print "echo \"hello there\"" > e print ./b > ./a; print ./c > b; print ./d > c; print ./e > d; print "echo \"hello there\"" > e
chmod 755 a b c d e chmod 755 a b c d e
@ -521,8 +523,8 @@ float sec=SECONDS
. $tmp/foo.sh | cat > /dev/null . $tmp/foo.sh | cat > /dev/null
(( (SECONDS-sec) < .07 )) && err_exit '. script does not restore output redirection with eval' (( (SECONDS-sec) < .07 )) && err_exit '. script does not restore output redirection with eval'
if builtin cat 2> /dev/null; then
file=$tmp/foobar file=$tmp/foobar
builtin cat
for ((n=0; n < 1000; n++)) for ((n=0; n < 1000; n++))
do do
> $file > $file
@ -532,6 +534,7 @@ do
break; break;
fi fi
done done
fi
$SHELL -c 'kill -0 123456789123456789123456789' 2> /dev/null && err_exit 'kill not catching process id overflows' $SHELL -c 'kill -0 123456789123456789123456789' 2> /dev/null && err_exit 'kill not catching process id overflows'

View file

@ -25,7 +25,7 @@ bincat=$(whence -p cat)
# ====== # ======
# These are regression tests for the getconf builtin. # These are regression tests for the getconf builtin.
builtin getconf if builtin getconf 2> /dev/null; then
bingetconf=$(getconf GETCONF) bingetconf=$(getconf GETCONF)
bad_result=$(getconf --version 2>&1) bad_result=$(getconf --version 2>&1)
@ -48,6 +48,7 @@ exp="GETCONF=$bingetconf"
got=$(getconf -n GETCONF) got=$(getconf -n GETCONF)
[[ $exp == "$got" ]] || err_exit "'getconf -n' doesn't match names correctly" \ [[ $exp == "$got" ]] || err_exit "'getconf -n' doesn't match names correctly" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))" "(expected $(printf %q "$exp"), got $(printf %q "$got"))"
fi
# ====== # ======
# Test shell builtin commands # Test shell builtin commands
@ -411,6 +412,7 @@ wait $pid1
wait $pid2 wait $pid2
(( $? == 127 )) || err_exit "subshell job known to parent" (( $? == 127 )) || err_exit "subshell job known to parent"
env= env=
if builtin getconf 2> /dev/null; then
v=$(getconf LIBPATH) v=$(getconf LIBPATH)
for v in ${v//,/ } for v in ${v//,/ }
do v=${v#*:} do v=${v#*:}
@ -420,6 +422,7 @@ done
if [[ $(foo=bar; eval foo=\$foo $env exec -c \$SHELL -c \'print \$foo\') != bar ]] if [[ $(foo=bar; eval foo=\$foo $env exec -c \$SHELL -c \'print \$foo\') != bar ]]
then err_exit '"name=value exec -c ..." not working' then err_exit '"name=value exec -c ..." not working'
fi fi
fi
$SHELL -c 'OPTIND=-1000000; getopts a opt -a' 2> /dev/null $SHELL -c 'OPTIND=-1000000; getopts a opt -a' 2> /dev/null
[[ $? == 1 ]] || err_exit 'getopts with negative OPTIND not working' [[ $? == 1 ]] || err_exit 'getopts with negative OPTIND not working'
getopts 'n#num' opt -n 3 getopts 'n#num' opt -n 3
@ -583,8 +586,10 @@ fi
while (( i <2)) while (( i <2))
do (( i++)) do (( i++))
done) == $'0\n0\n1\n1\n2' ]] || err_exit "DEBUG trap not working" done) == $'0\n0\n1\n1\n2' ]] || err_exit "DEBUG trap not working"
if builtin getconf 2> /dev/null; then
getconf UNIVERSE - ucb getconf UNIVERSE - ucb
[[ $($SHELL -c 'echo -3') == -3 ]] || err_exit "echo -3 not working in ucb universe" [[ $($SHELL -c 'echo -3') == -3 ]] || err_exit "echo -3 not working in ucb universe"
fi
typeset -F3 start_x=SECONDS total_t delay=0.02 typeset -F3 start_x=SECONDS total_t delay=0.02
typeset reps=50 leeway=5 typeset reps=50 leeway=5
sleep $(( 2 * leeway * reps * delay )) | sleep $(( 2 * leeway * reps * delay )) |
@ -635,11 +640,11 @@ t=$(ulimit -t)
$SHELL 2> /dev/null -c 'cd ""' && err_exit 'cd "" not producing an error' $SHELL 2> /dev/null -c 'cd ""' && err_exit 'cd "" not producing an error'
[[ $($SHELL 2> /dev/null -c 'cd "";print hi') != hi ]] && err_exit 'cd "" should not terminate script' [[ $($SHELL 2> /dev/null -c 'cd "";print hi') != hi ]] && err_exit 'cd "" should not terminate script'
builtin cat if builtin cat 2> /dev/null; then
out=$tmp/seq.out out=$tmp/seq.out
for ((i=1; i<=11; i++)); do print "$i"; done >$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" cmp -s <(print -- "$($bincat<( $bincat $out ) )") <(print -- "$(cat <( cat $out ) )") || err_exit "builtin cat differs from $bincat"
builtin -d cat fi
[[ $($SHELL -c '{ printf %R "["; print ok;}' 2> /dev/null) == ok ]] || err_exit $'\'printf %R "["\' causes shell to abort' [[ $($SHELL -c '{ printf %R "["; print ok;}' 2> /dev/null) == ok ]] || err_exit $'\'printf %R "["\' causes shell to abort'
@ -859,7 +864,8 @@ for w in 'whence -t' 'type -t' 'whence -t -v'; do
got=$($w export) got=$($w export)
[[ $exp == "$got" ]] || err_exit "'$w' has the wrong output for special builtins" \ [[ $exp == "$got" ]] || err_exit "'$w' has the wrong output for special builtins" \
"(expected $(printf %q "$exp"); got $(printf %q "$got"))" "(expected $(printf %q "$exp"); got $(printf %q "$got"))"
if [[ $(PATH=/opt/ast/bin type cat) != "cat is a shell builtin version of /opt/ast/bin/cat" ]] builtin -d cat
if [[ $(set +x; PATH=/opt/ast/bin type cat 2>&1) != "cat is a shell builtin version of /opt/ast/bin/cat" ]]
then warning "/opt/ast/bin/cat isn't a builtin; skipping path-bound builtin tests" then warning "/opt/ast/bin/cat isn't a builtin; skipping path-bound builtin tests"
else else
got=$(PATH=/opt/ast/bin $w cat) got=$(PATH=/opt/ast/bin $w cat)
@ -899,7 +905,9 @@ for w in 'whence -t' 'type -t' 'whence -t -v'; do
"(expected $(printf %q "$exp"); got $(printf %q "$got"))" "(expected $(printf %q "$exp"); got $(printf %q "$got"))"
# The final few tests are for '-t -a' # The final few tests are for '-t -a'
exp="alias builtin -d cat
if [[ $(set +x; PATH=/opt/ast/bin type cat 2>&1) == "cat is a shell builtin version of /opt/ast/bin/cat" ]]
then exp="alias
function function
builtin builtin
$($w -pa cat)" $($w -pa cat)"
@ -908,6 +916,7 @@ $($w -pa cat)"
PATH=/opt/ast/bin:$PATH $w -a cat) PATH=/opt/ast/bin:$PATH $w -a cat)
[[ $exp == "$got" ]] || err_exit "'$w -a' output is incorrect (cat command)" \ [[ $exp == "$got" ]] || err_exit "'$w -a' output is incorrect (cat command)" \
"(expected $(printf %q "$exp"); got $(printf %q "$got"))" "(expected $(printf %q "$exp"); got $(printf %q "$got"))"
fi
if [[ -n $($w -pa time) ]] if [[ -n $($w -pa time) ]]
then exp="keyword then exp="keyword
alias alias

View file

@ -39,9 +39,9 @@ function ping # id
} }
bincat=$(whence -p cat) bincat=$(whence -p cat)
builtin cat builtin cat 2> /dev/null && builtincat=cat
for cat in cat $bincat for cat in $builtincat $bincat
do do
$cat |& $cat |&

View file

@ -30,7 +30,7 @@ function abspath
print $newdir/$base print $newdir/$base
} }
# test for proper exit of shell # test for proper exit of shell
builtin getconf if builtin getconf 2> /dev/null; then
ABSHELL=$(abspath) ABSHELL=$(abspath)
print exit 0 >.profile print exit 0 >.profile
${ABSHELL} <<! ${ABSHELL} <<!
@ -53,6 +53,7 @@ then err_exit 'exit in .profile is ignored'
elif [[ -o privileged && $status == 0 ]] elif [[ -o privileged && $status == 0 ]]
then err_exit 'privileged .profile not ignored' then err_exit 'privileged .profile not ignored'
fi fi
fi
if [[ $(trap 'code=$?; echo $code; trap 0; exit $code' 0; exit 123) != 123 ]] if [[ $(trap 'code=$?; echo $code; trap 0; exit $code' 0; exit 123) != 123 ]]
then err_exit 'exit not setting $?' then err_exit 'exit not setting $?'
fi fi
@ -65,7 +66,9 @@ then err_exit 'subshell trap on exit overwrites parent trap'
fi fi
cd / cd /
cd ~- || err_exit "cd back failed" cd ~- || err_exit "cd back failed"
if builtin getconf 2> /dev/null; then
$SHELL -c 'builtin -f cmd getconf; getconf --"?-version"; exit 0' >/dev/null 2>&1 || err_exit 'ksh plugin exit failed -- was ksh built with CCFLAGS+=$(CC.EXPORT.DYNAMIC)?' $SHELL -c 'builtin -f cmd getconf; getconf --"?-version"; exit 0' >/dev/null 2>&1 || err_exit 'ksh plugin exit failed -- was ksh built with CCFLAGS+=$(CC.EXPORT.DYNAMIC)?'
fi
# ====== # ======
# Verify the 'exit' command behaves as expected # Verify the 'exit' command behaves as expected

View file

@ -100,6 +100,7 @@ do ((x = x+1))
EOF EOF
done done
' 2> /dev/null || err_exit '100 empty here docs fails' ' 2> /dev/null || err_exit '100 empty here docs fails'
if (builtin cat) 2> /dev/null; then
{ {
print 'builtin -d cat print 'builtin -d cat
cat <<- EOF' cat <<- EOF'
@ -111,6 +112,7 @@ done
} > $f } > $f
chmod +x "$f" chmod +x "$f"
$SHELL "$f" > /dev/null || err_exit "large here-doc with command substitution fails" $SHELL "$f" > /dev/null || err_exit "large here-doc with command substitution fails"
fi
x=$("$bincat" <<! x=$("$bincat" <<!
$0 $0
! !
@ -138,6 +140,7 @@ abc
EOF) != $'#abc\nabc' ]] EOF) != $'#abc\nabc' ]]
then err_exit 'comments not preserved in here-documents' then err_exit 'comments not preserved in here-documents'
fi fi
if (builtin cat) 2> /dev/null; then
cat > "$f" <<- '!!!!' cat > "$f" <<- '!!!!'
builtin cat builtin cat
: << EOF : << EOF
@ -168,6 +171,7 @@ chmod 755 "$f"
if [[ $($SHELL "$f") != abc ]] if [[ $($SHELL "$f") != abc ]]
then err_exit 'here document descriptor was closed' then err_exit 'here document descriptor was closed'
fi fi
fi
cat > "$f" <<- '!!!!' cat > "$f" <<- '!!!!'
exec 0<&- exec 0<&-
foobar() foobar()

View file

@ -234,19 +234,21 @@ do exp=$1
shift 4 shift 4
done done
# setocale(LC_ALL,"") after setlocale() initialization # setlocale(LC_ALL,"") after setlocale() initialization
if builtin cut 2> /dev/null; then
printf 'f1\357\274\240f2\n' > input1 printf 'f1\357\274\240f2\n' > input1
printf 't2\357\274\240f1\n' > input2 printf 't2\357\274\240f1\n' > input2
printf '\357\274\240\n' > delim printf '\357\274\240\n' > delim
print "export LC_ALL=$locale print "export LC_ALL=$locale
builtin cut || exit builtin cut
cut -f 1 -d \$(cat delim) input1 input2 > out" > script cut -f 1 -d \$(cat delim) input1 input2 > out" > script
$SHELL -c 'unset LANG ${!LC_*}; $SHELL ./script' || $SHELL -c 'unset LANG ${!LC_*}; $SHELL ./script' || err_exit "'cut' builtin failed -- exit code $?"
err_exit "'cut' builtin failed -- exit code $?"
exp=$'f1\nt2' exp=$'f1\nt2'
got="$(<out)" got="$(<out)"
[[ $got == "$exp" ]] || err_exit "LC_ALL test script failed -- expected '$exp', got '$got'" [[ $got == "$exp" ]] || err_exit "LC_ALL test script failed" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
fi
# multibyte identifiers # multibyte identifiers

View file

@ -288,7 +288,7 @@ typeset foo=$(PATH=/xyz:/abc :)
y=$(whence rm) y=$(whence rm)
[[ $x != "$y" ]] && err_exit 'PATH not restored after command substitution' [[ $x != "$y" ]] && err_exit 'PATH not restored after command substitution'
whence getconf > /dev/null && err_exit 'getconf should not be found' whence getconf > /dev/null && err_exit 'getconf should not be found'
builtin /bin/getconf builtin /bin/getconf 2> /dev/null
PATH=/bin PATH=/bin
PATH=$(getconf PATH) PATH=$(getconf PATH)
x=$(whence ls) x=$(whence ls)
@ -309,11 +309,12 @@ status=$($SHELL -c $'trap \'print $?\' ERR;/dev/null 2> /dev/null')
# universe via PATH # universe via PATH
builtin getconf if builtin getconf 2> /dev/null; then
getconf UNIVERSE - att # override sticky default 'UNIVERSE = foo' getconf UNIVERSE - att # override sticky default 'UNIVERSE = foo'
[[ $(PATH=/usr/ucb/bin:/usr/bin echo -n ucb) == 'ucb' ]] || err_exit "ucb universe echo ignores -n option" [[ $(PATH=/usr/ucb/bin:/usr/bin echo -n ucb) == 'ucb' ]] || err_exit "ucb universe echo ignores -n option"
[[ $(PATH=/usr/xpg/bin:/usr/bin echo -n att) == '-n att' ]] || err_exit "att universe echo does not ignore -n option" [[ $(PATH=/usr/xpg/bin:/usr/bin echo -n att) == '-n att' ]] || err_exit "att universe echo does not ignore -n option"
fi
PATH=$path PATH=$path
@ -435,7 +436,7 @@ x=$(whence -p echo 2> /dev/null)
[[ $x == "$tmp/new/bin/echo" ]] || err_exit 'nonexistent FPATH directory in .paths file causes path search to fail' [[ $x == "$tmp/new/bin/echo" ]] || err_exit 'nonexistent FPATH directory in .paths file causes path search to fail'
$SHELL 2> /dev/null <<- \EOF || err_exit 'path search problem with non-existent directories in PATH' $SHELL 2> /dev/null <<- \EOF || err_exit 'path search problem with non-existent directories in PATH'
builtin getconf builtin getconf 2> /dev/null
PATH=$(getconf PATH) PATH=$(getconf PATH)
PATH=/dev/null/nogood1/bin:/dev/null/nogood2/bin:$PATH PATH=/dev/null/nogood1/bin:/dev/null/nogood2/bin:$PATH
tail /dev/null && tail /dev/null tail /dev/null && tail /dev/null
@ -489,7 +490,7 @@ actual=$(set +x; PATH=$tmp; redirect 2>&1; hash ls; command -p ls /dev/null)
actual=$(set +x; PATH=$tmp; redirect 2>&1; hash ls; command -p ls /dev/null; exit) # the 'exit' disables subshell optimization actual=$(set +x; PATH=$tmp; redirect 2>&1; hash ls; command -p ls /dev/null; exit) # the 'exit' disables subshell optimization
[[ $actual == "$expect" ]] || err_exit "'command -p' fails to search default path if tracked alias exists" \ [[ $actual == "$expect" ]] || err_exit "'command -p' fails to search default path if tracked alias exists" \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))" "(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
expect=$(builtin getconf; PATH=$(getconf PATH); whence -p ls) expect=$(builtin getconf 2> /dev/null; PATH=$(getconf PATH); whence -p ls)
actual=$(set +x; PATH=$tmp; redirect 2>&1; hash ls; command -p -v ls) actual=$(set +x; PATH=$tmp; redirect 2>&1; hash ls; command -p -v ls)
[[ $actual == "$expect" ]] || err_exit "'command -p -v' fails to search default path if tracked alias exists" \ [[ $actual == "$expect" ]] || err_exit "'command -p -v' fails to search default path if tracked alias exists" \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))" "(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
@ -527,7 +528,8 @@ sleep_pid=$!
( (
export LC_ALL=C export LC_ALL=C
unset IFS; set +f unset IFS; set +f
builtin getconf && arg_max=$(getconf ARG_MAX) && let arg_max || { err_exit "getconf ARG_MAX not working"; exit 1; } builtin getconf 2> /dev/null
arg_max=$(getconf ARG_MAX) && let arg_max || { err_exit "getconf ARG_MAX not working"; exit 1; }
set +x # trust me, you don't want to xtrace what follows set +x # trust me, you don't want to xtrace what follows
# let's try to use a good variety of argument lengths # let's try to use a good variety of argument lengths
set -- $(typeset -p) $(functions) /dev/* /tmp/* /* * set -- $(typeset -p) $(functions) /dev/* /tmp/* /* *
@ -576,6 +578,7 @@ fi
# whence -a/-v tests # whence -a/-v tests
# wrong path to tracked aliases after loading builtin: https://github.com/ksh93/ksh/pull/25 # wrong path to tracked aliases after loading builtin: https://github.com/ksh93/ksh/pull/25
if (builtin cat) 2> /dev/null; then
actual=$("$SHELL" -c ' actual=$("$SHELL" -c '
hash cat hash cat
builtin cat builtin cat
@ -584,6 +587,7 @@ actual=$("$SHELL" -c '
expect=$'cat is a shell builtin\n'$(all_paths cat | sed '1 s/^/cat is a tracked alias for /; 2,$ s/^/cat is /') expect=$'cat is a shell builtin\n'$(all_paths cat | sed '1 s/^/cat is a tracked alias for /; 2,$ s/^/cat is /')
[[ $actual == "$expect" ]] || err_exit "'whence -a' does not work correctly with tracked aliases" \ [[ $actual == "$expect" ]] || err_exit "'whence -a' does not work correctly with tracked aliases" \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))" "(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
fi
# spurious 'undefined function' message: https://github.com/ksh93/ksh/issues/26 # spurious 'undefined function' message: https://github.com/ksh93/ksh/issues/26
actual=$("$SHELL" -c 'whence -a printf') actual=$("$SHELL" -c 'whence -a printf')

View file

@ -23,7 +23,7 @@
typeset -F SECONDS # for fractional seconds in PS4 typeset -F SECONDS # for fractional seconds in PS4
builtin getconf builtin getconf 2> /dev/null
bincat=$(PATH=$(getconf PATH) whence -p cat) bincat=$(PATH=$(getconf PATH) whence -p cat)
binecho=$(PATH=$(getconf PATH) whence -p echo) binecho=$(PATH=$(getconf PATH) whence -p echo)
# make an external 'sleep' command that supports fractional seconds # make an external 'sleep' command that supports fractional seconds
@ -344,7 +344,7 @@ actual=$(
# #
# the tests and timeouts are done in async subshells to prevent # the tests and timeouts are done in async subshells to prevent
# the test harness from hanging # the test harness from hanging
if builtin cat 2> /dev/null; then
SUB=( SUB=(
( BEG='$( ' END=' )' ) ( BEG='$( ' END=' )' )
( BEG='${ ' END='; }' ) ( BEG='${ ' END='; }' )
@ -430,6 +430,7 @@ do cat $tmp/buf $tmp/buf > $tmp/tmp
done done
done done
done done
fi
# specifics -- there's more? # specifics -- there's more?
@ -606,7 +607,7 @@ trap ERR ERR
[[ $(trap -p) == *ERR* ]] || err_exit 'trap -p in subshell does not contain ERR' [[ $(trap -p) == *ERR* ]] || err_exit 'trap -p in subshell does not contain ERR'
trap - USR1 ERR trap - USR1 ERR
( builtin getconf && PATH=$(getconf PATH) ( builtin getconf 2> /dev/null && PATH=$(getconf PATH)
dot=$(cat <<-EOF dot=$(cat <<-EOF
$(ls -d .) $(ls -d .)
EOF EOF