mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 19:52:20 +00:00
Add more regression tests, mostly from ksh93v- and ksh2020 (#216)
src/cmd/ksh93/tests/arrays.sh,
src/cmd/ksh93/tests/arrays2.sh:
- Backport some regression tests from ksh93v- for associative
arrays.
src/cmd/ksh93/tests/basic.sh:
- Add ksh93v- regression tests for background process output in
backtick and shared-state command substitutions as well as
functions used in command substitutions.
- Add regression tests for using EXIT traps in subshells. In
ksh93v- and ksh2020 EXIT traps don't work in forked subshells:
https://github.com/att/ast/issues/1452
- The trap builtin shouldn't segfault after receiving an invalid
signal name. ksh2020 regression:
https://github.com/att/ast/issues/1403
- Add a test to make sure invalid flags don't crash ksh.
ksh2020 regression: https://github.com/att/ast/issues/1284
- Test for an illegal seek error when using the 'join' command with
process substitutions. ksh93v- regression:
https://www.mail-archive.com/ast-users@lists.research.att.com/msg00816.html
src/cmd/ksh93/tests/bracket.sh:
- Add some regression tests from ksh93v- for the -eq test operator.
src/cmd/ksh93/tests/builtins.sh:
- Move the regression test for 'exit' in an interactive shell to
the exit.sh script.
- Test for assignments preceding the command builtin persisting
after an error. ksh2020 regression:
https://github.com/att/ast/issues/1402
- The chmod builtin should modify the permissions of all files
passed to it. ksh2020 regression:
https://github.com/att/ast/issues/949
- Add regression tests for the cd builtin. In ksh93v- 2013-10-10
alpha, using cd on a directory without an execute bit doesn't
cause an error. The test for using cd on a normal file was
backported from ksh93v-.
- Backport a ksh93v- regression test for the exit status
from 'kill %'.
src/cmd/ksh93/tests/case.sh:
- Test for a segfault when ksh handles an invalid character class
in a pattern. ksh2020 regression:
https://github.com/att/ast/issues/1409
src/cmd/ksh93/tests/exit.sh:
- Add regression tests from ksh2020 for the 'exit' builtin:
https://github.com/att/ast/commit/d9491d46
src/cmd/ksh93/tests/io.sh:
- Add a regression test from ksh93v- for a process substitution
hang. This test fails in the 93v- 2013 alpha but succeeds in
the 2014 beta.
src/cmd/ksh93/tests/math.sh:
- 'typeset -s foo=30000' adds garbage to $foo in ksh93u+, ksh93v-
and ksh2020:
$ typeset -s foo=30000
$ echo $foo
5#1430000
This bug was fixed in commit 88a6baa1
, but that commit didn't
add a regression test for it.
src/cmd/ksh93/tests/variables.sh:
- Add a regression test for $PS4 incorrectly unsetting
${.sh.subshell}: https://github.com/att/ast/issues/1092
This commit is contained in:
parent
5939964725
commit
59bacfd494
10 changed files with 206 additions and 7 deletions
|
@ -524,6 +524,7 @@ typeset -m 'a[0]=a[1]'
|
|||
typeset -m 'a[1]=j'
|
||||
[[ ${a[@]} == 'bb aa cc' ]] || err_exit 'moving index array elements not working'
|
||||
unset a j
|
||||
[[ $(typeset -p a) ]] && err_exit 'unset associative array after typeset -m not working'
|
||||
|
||||
typeset -A a=( [0]="aa" [1]="bb" [2]="cc" )
|
||||
typeset -m 'j=a[0]'
|
||||
|
|
|
@ -224,6 +224,15 @@ print -v cx > /dev/null
|
|||
print -v cx | read -C l 2> /dev/null || err_exit 'read -C fails from output of print -v'
|
||||
((SHOPT_FIXEDARRAY)) && [[ ${cx%cx=} != "${l%l=}" ]] && err_exit 'print -v for compound variable with fixed 2d array not working'
|
||||
|
||||
unset foo
|
||||
typeset -A foo
|
||||
typeset -A foo[bar]
|
||||
foo[bar][x]=2
|
||||
(( foo[bar][x]++ ))
|
||||
exp=3
|
||||
[[ ${foo[bar][x]} == $exp ]] || err_ext "subscript gets added incorrectly to an associative array when ++ operator is called" \
|
||||
"(expected '$exp', got '${foo[bar][x]}')"
|
||||
|
||||
# ======
|
||||
# Multidimensional arrays with an unset method shouldn't cause a crash.
|
||||
# The test itself must be run inside of a function.
|
||||
|
|
|
@ -419,8 +419,16 @@ unset foo
|
|||
unset foo
|
||||
foo=$(false) > /dev/null && err_exit 'failed command substitution with redirection not returning false'
|
||||
expected=foreback
|
||||
got=`print -n fore; (sleep 2;print back)&`
|
||||
[[ $got == $expected ]] || err_exit "\`\` command substitution background process output error (expected '$expected', got '$got')"
|
||||
got=$(print -n fore; (sleep .2;print back)&)
|
||||
[[ $got == $expected ]] || err_exit "command substitution background process output error -- got '$got', expected '$expected'"
|
||||
[[ $got == $expected ]] || err_exit "\$() command substitution background process output error (expected '$expected', got '$got')"
|
||||
got=${ print -n fore; (sleep 2;print back)& }
|
||||
[[ $got == $expected ]] || err_exit "\${} shared-state command substitution background process output error (expected '$expected', got '$got')"
|
||||
function abc { sleep 2; print back; }
|
||||
function abcd { abc & }
|
||||
got=$(print -n fore;abcd)
|
||||
[[ $got == $expected ]] || err_exit "\$() command substitution background with function process output error (expected '$expected', got '$got')"
|
||||
|
||||
for false in false $binfalse
|
||||
do x=$($false) && err_exit "x=\$($false) should fail"
|
||||
|
@ -790,5 +798,46 @@ trap - DEBUG # bug compat
|
|||
[[ $got == "$exp" ]] || err_exit "DEBUG trap did not trigger return from POSIX function on status 255" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
# In ksh93v- and ksh2020 EXIT traps don't work in forked subshells
|
||||
# https://github.com/att/ast/issues/1452
|
||||
exp="forked subshell EXIT trap okay"
|
||||
got="$(ulimit -t unlimited; trap 'echo forked subshell EXIT trap okay' EXIT)"
|
||||
[[ $got == $exp ]] || err_exit "EXIT trap did not trigger in forked subshell" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
|
||||
exp="virtual subshell EXIT trap okay"
|
||||
got="$(trap 'echo virtual subshell EXIT trap okay' EXIT)"
|
||||
[[ $got == $exp ]] || err_exit "EXIT trap did not trigger in virtual subshell" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
# Regression test for https://github.com/att/ast/issues/1403
|
||||
for t in {A..Z}; do
|
||||
$SHELL -c "trap - $t 2> /dev/null"
|
||||
[[ $? == 1 ]] || err_exit "'trap' throws segfault when given invalid signal name '$t'"
|
||||
done
|
||||
|
||||
# ======
|
||||
# Is an invalid flag handled correctly?
|
||||
# ksh2020 regression: https://github.com/att/ast/issues/1284
|
||||
actual=$($SHELL --verson 2>&1)
|
||||
actual_status=$?
|
||||
expect='ksh: verson: bad option(s)'
|
||||
expect_status=2
|
||||
[[ "$actual" == ${expect}* ]] || err_exit "failed to get version string" \
|
||||
"(expected $(printf %q ${expect}*), got $(printf %q "$actual"))"
|
||||
[[ $actual_status == $expect_status ]] ||
|
||||
err_exit "wrong exit status (expected '$expect_status', got '$actual_status')"
|
||||
|
||||
# ======
|
||||
# Test for illegal seek error (ksh93v- regression)
|
||||
# https://www.mail-archive.com/ast-users@lists.research.att.com/msg00816.html
|
||||
exp='1
|
||||
2'
|
||||
got="$(join <(printf '%d\n' 1 2) <(printf '%d\n' 1 2))"
|
||||
[[ $exp == $got ]] || err_exit "pipeline fails with illegal seek error" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
|
@ -408,5 +408,13 @@ do unset var
|
|||
[[ -n ${var+s} ]] || err_exit "[[ -n \${var+s} ]] should be true for empty var with attribute -$flag"
|
||||
done
|
||||
|
||||
# ======
|
||||
# Tests from ksh93v- for the -eq operator
|
||||
[[ 010 -eq 10 ]] || err_exit '010 is not 10 in [[...]]'
|
||||
|
||||
unset foo
|
||||
foo=10
|
||||
([[ foo -eq 10 ]]) || err_exit 'foo -eq 10 fails in [[...]] with foo=10'
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
|
@ -686,11 +686,6 @@ then (
|
|||
fi
|
||||
cd "$tmp"
|
||||
|
||||
$SHELL +E -i 2>/dev/null <<- \! && err_exit 'interactive shell should not exit 0 after false'
|
||||
false
|
||||
exit
|
||||
!
|
||||
|
||||
if kill -L > /dev/null 2>&1
|
||||
then [[ $(kill -l HUP) == "$(kill -L HUP)" ]] || err_exit 'kill -l and kill -L are not the same when given a signal name'
|
||||
[[ $(kill -l 9) == "$(kill -L 9)" ]] || err_exit 'kill -l and kill -L are not the same when given a signal number'
|
||||
|
@ -974,7 +969,7 @@ fi
|
|||
EOF
|
||||
"$SHELL" -i "$sleepsig" 2> /dev/null || err_exit "'sleep -s' doesn't work with intervals of more than 30 seconds"
|
||||
|
||||
# ==========
|
||||
# ======
|
||||
# Builtins should handle unrecognized options correctly
|
||||
while IFS= read -r bltin <&3
|
||||
do case $bltin in
|
||||
|
@ -1013,5 +1008,42 @@ then got=$( { "$SHELL" -c '
|
|||
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
|
||||
fi
|
||||
|
||||
# ======
|
||||
# Regression test for https://github.com/att/ast/issues/1402
|
||||
#
|
||||
# We throw away stderr because we only want the value of '$t', not the error text from running
|
||||
# 'command' with an invalid flag.
|
||||
exp='good'
|
||||
got=$($SHELL -c 't=good; t=bad command -@; print $t' 2>/dev/null)
|
||||
[[ $exp == $got ]] || err_exit "temp var assignment with 'command'" \
|
||||
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
|
||||
|
||||
# ======
|
||||
# Regression test for https://github.com/att/ast/issues/949
|
||||
foo_script='#!/bin/sh
|
||||
exit 0'
|
||||
echo "$foo_script" > "$tmp/foo1.sh"
|
||||
echo "$foo_script" > "$tmp/foo2.sh"
|
||||
builtin chmod
|
||||
chmod +x "$tmp/foo1.sh" "$tmp/foo2.sh"
|
||||
$SHELL "$tmp/foo1.sh" || err_exit "builtin 'chmod +x' doesn't work on first script"
|
||||
$SHELL "$tmp/foo2.sh" || err_exit "builtin 'chmod +x' doesn't work on second script"
|
||||
|
||||
# ======
|
||||
# In ksh93v- 2013-10-10 alpha cd doesn't fail on directories without execute permission.
|
||||
# Additionally, ksh93v- added a regression test for attempting to use cd on a file.
|
||||
mkdir "$tmp/noexecute"
|
||||
chmod -x "$tmp/noexecute"
|
||||
$SHELL -c "cd $tmp/noexecute" 2> /dev/null && err_exit "'cd' on directories without an execute bit doesn't fail"
|
||||
touch "$tmp/notadir"
|
||||
$SHELL -c "cd $tmp/notadir" 2> /dev/null && err_exit "'cd' on a normal file doesn't fail"
|
||||
|
||||
# ======
|
||||
# 'kill %' should fail with exit status 1
|
||||
{ $SHELL -c 'kill %' ;} 2> /dev/null
|
||||
got=$?
|
||||
exp=1
|
||||
[[ $got == $exp ]] || err_exit "'kill %' has the wrong exit status (expected '$exp'; got '$got')"
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
|
@ -102,5 +102,11 @@ got=$(eval 'case x in (if);; esac' 2>&1) || err_exit "'(' + 'if' as first patter
|
|||
got=$(eval 'case x in foo);; if);; esac' 2>&1) || err_exit "'if' as nth pattern fails: got $(printf %q "$got")"
|
||||
got=$(eval 'case x in (foo);; (if);; esac' 2>&1) || err_exit "'(' + 'if' as nth pattern fails: got $(printf %q "$got")"
|
||||
|
||||
# ======
|
||||
# Verify an invalid character class name is handled without a SIGSEGV or similar failure
|
||||
# https://github.com/att/ast/issues/1409
|
||||
got="$($SHELL -c 'case x in [x[:bogus:]]) echo x ;; esac')"
|
||||
[[ -z $got ]] || err_exit "invalid char class name (got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
|
@ -76,4 +76,65 @@ cd /
|
|||
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)?'
|
||||
|
||||
# ======
|
||||
# Verify the 'exit' command behaves as expected
|
||||
|
||||
got=$($SHELL -c 'exit' 2>&1)
|
||||
status=$?
|
||||
exp=0
|
||||
[[ -z $got ]] || err_exit 'bare exit' \
|
||||
"(got $(printf %q "$got"))"
|
||||
[[ $exp == $status ]] || err_exit 'bare exit' \
|
||||
"(expected '$exp', got '$status')"
|
||||
|
||||
got=$($SHELL -c 'exit 0' 2>&1)
|
||||
status=$?
|
||||
exp=0
|
||||
[[ -z $got ]] || err_exit 'exit 0' \
|
||||
"(got $(printf %q "$got"))"
|
||||
[[ $exp == $status ]] || err_exit 'exit 0' \
|
||||
"(expected '$exp', got '$status')"
|
||||
|
||||
got=$($SHELL -c 'exit 1' 2>&1)
|
||||
status=$?
|
||||
exp=1
|
||||
[[ -z $got ]] || err_exit 'exit 1' \
|
||||
"(got $(printf %q "$got"))"
|
||||
[[ $exp == $status ]] || err_exit 'exit 1' \
|
||||
"(expected '$exp', got '$status')"
|
||||
|
||||
got=$($SHELL -c 'function e37 { return 37; } ; e37' 2>&1)
|
||||
status=$?
|
||||
exp=37
|
||||
[[ -z $got ]] || err_exit 'exit 37' \
|
||||
"(got $(printf %q "$got"))"
|
||||
[[ $exp == $status ]] || err_exit 'exit 37' \
|
||||
"(expected '$exp', got '$status')"
|
||||
|
||||
got=$($SHELL -c 'exit -1' 2>&1)
|
||||
status=$?
|
||||
exp=255
|
||||
[[ -z $got ]] || err_exit 'exit -1' \
|
||||
"(got $(printf %q "$got"))"
|
||||
[[ $exp == $status ]] || err_exit 'exit -1' \
|
||||
"(expected '$exp', got '$status')"
|
||||
|
||||
got=$($SHELL -c 'exit -2' 2>&1)
|
||||
status=$?
|
||||
exp=254
|
||||
[[ -z $got ]] || err_exit 'exit -2' \
|
||||
"(got $(printf %q "$got"))"
|
||||
[[ $exp == $status ]] || err_exit 'exit -2' \
|
||||
"(expected '$exp', got '$status')"
|
||||
|
||||
$SHELL +E -i 2>/dev/null <<- \!
|
||||
false
|
||||
exit
|
||||
!
|
||||
status=$?
|
||||
exp=1
|
||||
[[ $exp == $status ]] || err_exit 'bare exit after false' \
|
||||
"(expected '$exp', got '$status')"
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
|
@ -715,6 +715,24 @@ got=$(export tmp; "$SHELL" -ec \
|
|||
(redirect {v}>$tmp/v.out; echo ok2 >&$v) 2>/dev/null
|
||||
[[ -r $tmp/v.out && $(<$tmp/v.out) == ok2 ]] || err_exit 'redirect {varname}>file not working in a subshell'
|
||||
|
||||
# ======
|
||||
# Process substitution hang in ksh93v- 2013-10-10 alpha
|
||||
{
|
||||
producer() {
|
||||
for ((i = 0; i < 20000; i++ )) do
|
||||
print xxxxx${i}xxxxx
|
||||
done
|
||||
}
|
||||
consumer() {
|
||||
while read var; do
|
||||
print ${var}
|
||||
done < ${1}
|
||||
}
|
||||
consumer <(producer) > /dev/null
|
||||
} & pid=$!
|
||||
(sleep 5; kill -HUP $pid) 2> /dev/null &
|
||||
wait $pid 2> /dev/null || err_exit "process substitution hangs"
|
||||
|
||||
# ======
|
||||
# Test for looping or lingering process substitution processes
|
||||
# https://github.com/ksh93/ksh/issues/213
|
||||
|
|
|
@ -260,5 +260,12 @@ unset x
|
|||
[[ $(typeset -lE 0 x=5.67; typeset -p x) == 'typeset -l -E 0 x=6' ]] || err_exit 'typeset -lE 0 with assignment failed to round.'
|
||||
[[ $(typeset -lX 0 x=5.67; typeset -p x) == 'typeset -l -X 0 x=0x1p+2' ]] || err_exit 'typeset -lX 0 with assignment failed to round.'
|
||||
|
||||
# ======
|
||||
# typeset -s used without -i shouldn't set foo to garbage
|
||||
exp=30000
|
||||
got="$(typeset -s foo=30000; echo $foo)"
|
||||
[[ $exp == $got ]] || err_exit "unexpected output from typeset -s without -i" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
|
@ -1258,5 +1258,13 @@ exp='foo/foobar/fool'
|
|||
got=$(IFS=/; foo=bar foobar=fbar fool=pity; print -r -- "${!foo*}")
|
||||
[[ $got == "$exp" ]] || err_exit "\${!foo*}: expected $(printf %q "$exp"), got $(printf %q "$got")"
|
||||
|
||||
# ======
|
||||
# In ksh93v- ${.sh.subshell} is unset by the $PS4 prompt
|
||||
# https://github.com/att/ast/issues/1092
|
||||
exp='0'
|
||||
got="$($SHELL -c 'PS4="${.sh.subshell}"; echo ${.sh.subshell}')"
|
||||
[[ "$exp" == "$got" ]] || err_exit "\${.sh.subshell} is wrongly unset in the \$PS4 prompt" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
Loading…
Reference in a new issue