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:
parent
0e197eee57
commit
de795e1f9d
8 changed files with 237 additions and 211 deletions
|
@ -184,25 +184,27 @@ 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
|
||||||
cat > $tmp/script <<\!
|
if (builtin cat) 2> /dev/null; then
|
||||||
if [[ -p /dev/fd/0 ]]
|
cat > $tmp/script <<\!
|
||||||
then builtin cat
|
if [[ -p /dev/fd/0 ]]
|
||||||
cat - > /dev/null
|
then builtin cat
|
||||||
[[ -p /dev/fd/0 ]] && print ok
|
cat - > /dev/null
|
||||||
else print no
|
[[ -p /dev/fd/0 ]] && print ok
|
||||||
fi
|
else print no
|
||||||
|
fi
|
||||||
!
|
!
|
||||||
chmod +x $tmp/script
|
chmod +x $tmp/script
|
||||||
case $( (print) | $tmp/script;:) in
|
case $( (print) | $tmp/script;:) in
|
||||||
ok) ;;
|
ok) ;;
|
||||||
no) err_exit "[[ -p /dev/fd/0 ]] fails for standard input pipe" ;;
|
no) err_exit "[[ -p /dev/fd/0 ]] fails for standard input pipe" ;;
|
||||||
*) err_exit "builtin replaces standard input pipe" ;;
|
*) err_exit "builtin replaces standard input pipe" ;;
|
||||||
esac
|
esac
|
||||||
print 'print $0' > $tmp/script
|
print 'print $0' > $tmp/script
|
||||||
print ". $tmp/script" > $tmp/scriptx
|
print ". $tmp/script" > $tmp/scriptx
|
||||||
chmod +x $tmp/scriptx
|
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
|
||||||
|
@ -521,17 +523,18 @@ 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'
|
||||||
|
|
||||||
file=$tmp/foobar
|
if builtin cat 2> /dev/null; then
|
||||||
builtin cat
|
file=$tmp/foobar
|
||||||
for ((n=0; n < 1000; n++))
|
for ((n=0; n < 1000; n++))
|
||||||
do
|
do
|
||||||
> $file
|
> $file
|
||||||
{ sleep .001;echo $? >$file;} | cat > /dev/null
|
{ sleep .001;echo $? >$file;} | cat > /dev/null
|
||||||
if [[ ! -s $file ]]
|
if [[ ! -s $file ]]
|
||||||
then err_exit 'output from pipe is lost with pipe to builtin'
|
then err_exit 'output from pipe is lost with pipe to builtin'
|
||||||
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'
|
||||||
|
|
||||||
|
|
|
@ -25,29 +25,30 @@ 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)
|
||||||
|
|
||||||
# The -l option should convert all variable names to lowercase.
|
# The -l option should convert all variable names to lowercase.
|
||||||
# https://github.com/att/ast/issues/1171
|
# https://github.com/att/ast/issues/1171
|
||||||
got=$(getconf -lq | awk '{ gsub(/=.*/, "") } /[[:upper:]]/ { print }')
|
got=$(getconf -lq | awk '{ gsub(/=.*/, "") } /[[:upper:]]/ { print }')
|
||||||
[[ -n $got ]] && err_exit "'getconf -l' doesn't convert all variable names to lowercase" \
|
[[ -n $got ]] && err_exit "'getconf -l' doesn't convert all variable names to lowercase" \
|
||||||
"(got $(printf %q "$got"))"
|
"(got $(printf %q "$got"))"
|
||||||
|
|
||||||
# The -q option should quote all string values.
|
# The -q option should quote all string values.
|
||||||
# https://github.com/att/ast/issues/1173
|
# https://github.com/att/ast/issues/1173
|
||||||
exp="GETCONF=\"$bingetconf\""
|
exp="GETCONF=\"$bingetconf\""
|
||||||
got=$(getconf -q | grep 'GETCONF=')
|
got=$(getconf -q | grep 'GETCONF=')
|
||||||
[[ $exp == "$got" ]] || err_exit "'getconf -q' fails to quote string values" \
|
[[ $exp == "$got" ]] || err_exit "'getconf -q' fails to quote string values" \
|
||||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||||
|
|
||||||
# The -n option should only return matching names.
|
# The -n option should only return matching names.
|
||||||
# https://github.com/ksh93/ksh/issues/279
|
# https://github.com/ksh93/ksh/issues/279
|
||||||
exp="GETCONF=$bingetconf"
|
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,14 +412,16 @@ wait $pid1
|
||||||
wait $pid2
|
wait $pid2
|
||||||
(( $? == 127 )) || err_exit "subshell job known to parent"
|
(( $? == 127 )) || err_exit "subshell job known to parent"
|
||||||
env=
|
env=
|
||||||
v=$(getconf LIBPATH)
|
if builtin getconf 2> /dev/null; then
|
||||||
for v in ${v//,/ }
|
v=$(getconf LIBPATH)
|
||||||
do v=${v#*:}
|
for v in ${v//,/ }
|
||||||
v=${v%%:*}
|
do v=${v#*:}
|
||||||
eval [[ \$$v ]] && env="$env $v=\"\$$v\""
|
v=${v%%:*}
|
||||||
done
|
eval [[ \$$v ]] && env="$env $v=\"\$$v\""
|
||||||
if [[ $(foo=bar; eval foo=\$foo $env exec -c \$SHELL -c \'print \$foo\') != bar ]]
|
done
|
||||||
then err_exit '"name=value exec -c ..." not working'
|
if [[ $(foo=bar; eval foo=\$foo $env exec -c \$SHELL -c \'print \$foo\') != bar ]]
|
||||||
|
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'
|
||||||
|
@ -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"
|
||||||
getconf UNIVERSE - ucb
|
if builtin getconf 2> /dev/null; then
|
||||||
[[ $($SHELL -c 'echo -3') == -3 ]] || err_exit "echo -3 not working in ucb universe"
|
getconf UNIVERSE - ucb
|
||||||
|
[[ $($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,15 +905,18 @@ 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)"
|
||||||
got=$(alias cat=false
|
got=$(alias cat=false
|
||||||
autoload cat
|
autoload 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
|
||||||
|
|
|
@ -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 |&
|
||||||
|
|
|
@ -30,28 +30,29 @@ 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} <<!
|
||||||
HOME=$PWD \
|
HOME=$PWD \
|
||||||
PATH=$PATH \
|
PATH=$PATH \
|
||||||
SHELL=$ABSSHELL \
|
SHELL=$ABSSHELL \
|
||||||
$(
|
$(
|
||||||
v=$(getconf LIBPATH)
|
v=$(getconf LIBPATH)
|
||||||
for v in ${v//,/ }
|
for v in ${v//,/ }
|
||||||
do v=${v#*:}
|
do v=${v#*:}
|
||||||
v=${v%%:*}
|
v=${v%%:*}
|
||||||
eval [[ \$$v ]] && eval print -n \" \"\$v=\"\$$v\"
|
eval [[ \$$v ]] && eval print -n \" \"\$v=\"\$$v\"
|
||||||
done
|
done
|
||||||
) \
|
) \
|
||||||
exec -c -a -ksh ${ABSHELL} -c "exit 1" 1>/dev/null 2>&1
|
exec -c -a -ksh ${ABSHELL} -c "exit 1" 1>/dev/null 2>&1
|
||||||
!
|
!
|
||||||
status=$(echo $?)
|
status=$(echo $?)
|
||||||
if [[ -o noprivileged && $status != 0 ]]
|
if [[ -o noprivileged && $status != 0 ]]
|
||||||
then err_exit 'exit in .profile is ignored'
|
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 $?'
|
||||||
|
@ -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"
|
||||||
$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)?'
|
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)?'
|
||||||
|
fi
|
||||||
|
|
||||||
# ======
|
# ======
|
||||||
# Verify the 'exit' command behaves as expected
|
# Verify the 'exit' command behaves as expected
|
||||||
|
|
|
@ -100,17 +100,19 @@ 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
|
{
|
||||||
cat <<- EOF'
|
print 'builtin -d cat
|
||||||
for ((i=0; i < 100; i++))
|
cat <<- EOF'
|
||||||
do print XXXXXXXXXXXXXXXXXXXX
|
for ((i=0; i < 100; i++))
|
||||||
done
|
do print XXXXXXXXXXXXXXXXXXXX
|
||||||
print ' XXX$(date)XXXX
|
done
|
||||||
EOF'
|
print ' XXX$(date)XXXX
|
||||||
} > $f
|
EOF'
|
||||||
chmod +x "$f"
|
} > $f
|
||||||
$SHELL "$f" > /dev/null || err_exit "large here-doc with command substitution fails"
|
chmod +x "$f"
|
||||||
|
$SHELL "$f" > /dev/null || err_exit "large here-doc with command substitution fails"
|
||||||
|
fi
|
||||||
x=$("$bincat" <<!
|
x=$("$bincat" <<!
|
||||||
$0
|
$0
|
||||||
!
|
!
|
||||||
|
@ -138,35 +140,37 @@ 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
|
||||||
cat > "$f" <<- '!!!!'
|
if (builtin cat) 2> /dev/null; then
|
||||||
builtin cat
|
cat > "$f" <<- '!!!!'
|
||||||
: << EOF
|
builtin cat
|
||||||
$PWD
|
: << EOF
|
||||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
$PWD
|
||||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xx
|
||||||
EOF
|
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
command exec 3>&- 4>&- 5>&- 6>&- 7>&- 8>&- 9>&-
|
EOF
|
||||||
x=abc
|
command exec 3>&- 4>&- 5>&- 6>&- 7>&- 8>&- 9>&-
|
||||||
cat << EOF
|
x=abc
|
||||||
$x
|
cat << EOF
|
||||||
EOF
|
$x
|
||||||
!!!!
|
EOF
|
||||||
chmod 755 "$f"
|
!!!!
|
||||||
if [[ $($SHELL "$f") != abc ]]
|
chmod 755 "$f"
|
||||||
then err_exit 'here document descriptor was closed'
|
if [[ $($SHELL "$f") != abc ]]
|
||||||
|
then err_exit 'here document descriptor was closed'
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
cat > "$f" <<- '!!!!'
|
cat > "$f" <<- '!!!!'
|
||||||
exec 0<&-
|
exec 0<&-
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
printf 'f1\357\274\240f2\n' > input1
|
if builtin cut 2> /dev/null; then
|
||||||
printf 't2\357\274\240f1\n' > input2
|
printf 'f1\357\274\240f2\n' > input1
|
||||||
printf '\357\274\240\n' > delim
|
printf 't2\357\274\240f1\n' > input2
|
||||||
print "export LC_ALL=$locale
|
printf '\357\274\240\n' > delim
|
||||||
builtin cut || exit
|
print "export LC_ALL=$locale
|
||||||
cut -f 1 -d \$(cat delim) input1 input2 > out" > script
|
builtin cut
|
||||||
$SHELL -c 'unset LANG ${!LC_*}; $SHELL ./script' ||
|
cut -f 1 -d \$(cat delim) input1 input2 > out" > script
|
||||||
err_exit "'cut' builtin failed -- exit code $?"
|
$SHELL -c 'unset LANG ${!LC_*}; $SHELL ./script' || 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
|
||||||
|
|
||||||
|
|
|
@ -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,14 +578,16 @@ 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
|
||||||
actual=$("$SHELL" -c '
|
if (builtin cat) 2> /dev/null; then
|
||||||
hash cat
|
actual=$("$SHELL" -c '
|
||||||
builtin cat
|
hash cat
|
||||||
whence -a cat
|
builtin cat
|
||||||
')
|
whence -a cat
|
||||||
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" \
|
expect=$'cat is a shell builtin\n'$(all_paths cat | sed '1 s/^/cat is a tracked alias for /; 2,$ s/^/cat is /')
|
||||||
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
|
[[ $actual == "$expect" ]] || err_exit "'whence -a' does not work correctly with tracked aliases" \
|
||||||
|
"(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')
|
||||||
|
|
|
@ -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,54 +344,54 @@ 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=(
|
||||||
|
( BEG='$( ' END=' )' )
|
||||||
|
( BEG='${ ' END='; }' )
|
||||||
|
)
|
||||||
|
CAT=( cat $bincat )
|
||||||
|
INS=( "" "builtin cat; " "builtin -d cat $bincat; " ": > /dev/null; " )
|
||||||
|
APP=( "" "; :" )
|
||||||
|
TST=(
|
||||||
|
( CMD='print foo | $cat' EXP=3 )
|
||||||
|
( CMD='$cat < $tmp/lin' )
|
||||||
|
( CMD='cat $tmp/lin | $cat' )
|
||||||
|
( CMD='read v < $tmp/buf; print $v' LIM=4*1024 )
|
||||||
|
( CMD='cat $tmp/buf | read v; print $v' LIM=4*1024 )
|
||||||
|
)
|
||||||
|
|
||||||
SUB=(
|
if cat /dev/fd/3 3</dev/null >/dev/null 2>&1 || whence mkfifo > /dev/null
|
||||||
( BEG='$( ' END=' )' )
|
then T=${#TST[@]}
|
||||||
( BEG='${ ' END='; }' )
|
TST[T].CMD='$cat <(print foo)'
|
||||||
)
|
TST[T].EXP=3
|
||||||
CAT=( cat $bincat )
|
fi
|
||||||
INS=( "" "builtin cat; " "builtin -d cat $bincat; " ": > /dev/null; " )
|
|
||||||
APP=( "" "; :" )
|
|
||||||
TST=(
|
|
||||||
( CMD='print foo | $cat' EXP=3 )
|
|
||||||
( CMD='$cat < $tmp/lin' )
|
|
||||||
( CMD='cat $tmp/lin | $cat' )
|
|
||||||
( CMD='read v < $tmp/buf; print $v' LIM=4*1024 )
|
|
||||||
( CMD='cat $tmp/buf | read v; print $v' LIM=4*1024 )
|
|
||||||
)
|
|
||||||
|
|
||||||
if cat /dev/fd/3 3</dev/null >/dev/null 2>&1 || whence mkfifo > /dev/null
|
# prime the two data files to 512 bytes each
|
||||||
then T=${#TST[@]}
|
# $tmp/lin has newlines every 16 bytes and $tmp/buf has no newlines
|
||||||
TST[T].CMD='$cat <(print foo)'
|
# the outer loop doubles the file size at top
|
||||||
TST[T].EXP=3
|
|
||||||
fi
|
|
||||||
|
|
||||||
# prime the two data files to 512 bytes each
|
buf=$'1234567890abcdef'
|
||||||
# $tmp/lin has newlines every 16 bytes and $tmp/buf has no newlines
|
lin=$'\n1234567890abcde'
|
||||||
# the outer loop doubles the file size at top
|
for ((i=0; i<5; i++))
|
||||||
|
do buf=$buf$buf
|
||||||
|
lin=$lin$lin
|
||||||
|
done
|
||||||
|
print -n "$buf" > $tmp/buf
|
||||||
|
print -n "$lin" > $tmp/lin
|
||||||
|
|
||||||
buf=$'1234567890abcdef'
|
unset SKIP
|
||||||
lin=$'\n1234567890abcde'
|
for ((n=1024; n<=1024*1024; n*=2))
|
||||||
for ((i=0; i<5; i++))
|
do cat $tmp/buf $tmp/buf > $tmp/tmp
|
||||||
do buf=$buf$buf
|
mv $tmp/tmp $tmp/buf
|
||||||
lin=$lin$lin
|
cat $tmp/lin $tmp/lin > $tmp/tmp
|
||||||
done
|
mv $tmp/tmp $tmp/lin
|
||||||
print -n "$buf" > $tmp/buf
|
for ((S=0; S<${#SUB[@]}; S++))
|
||||||
print -n "$lin" > $tmp/lin
|
do for ((C=0; C<${#CAT[@]}; C++))
|
||||||
|
do cat=${CAT[C]}
|
||||||
unset SKIP
|
for ((I=0; I<${#INS[@]}; I++))
|
||||||
for ((n=1024; n<=1024*1024; n*=2))
|
do for ((A=0; A<${#APP[@]}; A++))
|
||||||
do cat $tmp/buf $tmp/buf > $tmp/tmp
|
do for ((T=0; T<${#TST[@]}; T++))
|
||||||
mv $tmp/tmp $tmp/buf
|
do #undent...#
|
||||||
cat $tmp/lin $tmp/lin > $tmp/tmp
|
|
||||||
mv $tmp/tmp $tmp/lin
|
|
||||||
for ((S=0; S<${#SUB[@]}; S++))
|
|
||||||
do for ((C=0; C<${#CAT[@]}; C++))
|
|
||||||
do cat=${CAT[C]}
|
|
||||||
for ((I=0; I<${#INS[@]}; I++))
|
|
||||||
do for ((A=0; A<${#APP[@]}; A++))
|
|
||||||
do for ((T=0; T<${#TST[@]}; T++))
|
|
||||||
do #undent...#
|
|
||||||
|
|
||||||
if [[ ! ${SKIP[S][C][I][A][T]} ]]
|
if [[ ! ${SKIP[S][C][I][A][T]} ]]
|
||||||
then eval "{ x=${SUB[S].BEG}${INS[I]}${TST[T].CMD}${APP[A]}${SUB[S].END}; print \${#x}; } >\$tmp/out &"
|
then eval "{ x=${SUB[S].BEG}${INS[I]}${TST[T].CMD}${APP[A]}${SUB[S].END}; print \${#x}; } >\$tmp/out &"
|
||||||
|
@ -423,13 +423,14 @@ do cat $tmp/buf $tmp/buf > $tmp/tmp
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#...indent#
|
#...indent#
|
||||||
|
done
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
done
|
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
|
||||||
|
|
Loading…
Reference in a new issue