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

Backport ksh93v- regression tests and fix various regression test bugs (#472)

- tests/*.sh: Backported many additional regression tests and test
  fixes from the alpha and beta releases of ksh93v-.

- tests/alias.sh: Avoid trying to add vi to the hash table, as some
  platforms do not provide a vi(1) implementation installed as part
  of the default system. This fixes a regression test failure I was
  getting in one of my Linux virtual machines.

- tests/builtins.sh: Fixed a bug in one of the regression tests that
  caused an incorrect total error count if any of the tests failed.

- tests/sh_match.sh: Fixed a regression test failure on DragonFly
  BSD caused by the diff command printing an extra 'No differences
  encountered' line.
This commit is contained in:
Johnothan King 2022-02-23 21:01:44 -08:00 committed by Martijn Dekker
parent bb3527aea5
commit dccf6b5ea8
25 changed files with 313 additions and 32 deletions

View file

@ -163,14 +163,14 @@ got=$(
# Listing members of the hash table with 'alias -pt' should work # Listing members of the hash table with 'alias -pt' should work
exp='alias -t cat exp='alias -t cat
vi: tracked alias not found ls: tracked alias not found
alias -t cat alias -t cat
alias -t chmod' alias -t chmod'
got=$( got=$(
set +x set +x
redirect 2>&1 redirect 2>&1
hash -r cat chmod hash -r cat chmod
alias -pt cat vi # vi shouldn't be added to the hash table alias -pt cat ls # ls shouldn't be added to the hash table
alias -pt alias -pt
) )
[[ $exp == $got ]] || err_exit "Listing members of the hash table with 'alias -pt' doesn't work" \ [[ $exp == $got ]] || err_exit "Listing members of the hash table with 'alias -pt' doesn't work" \
@ -228,12 +228,12 @@ ret=$?
"(expected 2, got $ret)" "(expected 2, got $ret)"
# Detect zombie aliases with 'alias'. # Detect zombie aliases with 'alias'.
exp='vi: alias not found exp='ls: alias not found
chmod: alias not found' chmod: alias not found'
got=$($SHELL -c ' got=$($SHELL -c '
hash vi chmod hash ls chmod
hash -r hash -r
alias vi chmod alias ls chmod
' 2>&1) ' 2>&1)
ret=$? ret=$?
[[ $exp == $got ]] || err_exit "Listing removed tracked aliases with 'alias' should fail with an error message" \ [[ $exp == $got ]] || err_exit "Listing removed tracked aliases with 'alias' should fail with an error message" \
@ -242,12 +242,12 @@ ret=$?
"(expected 2, got $ret)" "(expected 2, got $ret)"
# Detect zombie aliases with 'alias -p'. # Detect zombie aliases with 'alias -p'.
exp='vi: alias not found exp='ls: alias not found
chmod: alias not found' chmod: alias not found'
got=$($SHELL -c ' got=$($SHELL -c '
hash vi chmod hash ls chmod
hash -r hash -r
alias -p vi chmod alias -p ls chmod
' 2>&1) ' 2>&1)
ret=$? ret=$?
[[ $exp == $got ]] || err_exit "Listing removed tracked aliases with 'alias -p' should fail with an error message" \ [[ $exp == $got ]] || err_exit "Listing removed tracked aliases with 'alias -p' should fail with an error message" \
@ -256,12 +256,12 @@ ret=$?
"(expected 2, got $ret)" "(expected 2, got $ret)"
# Detect zombie tracked aliases. # Detect zombie tracked aliases.
exp='vi: tracked alias not found exp='ls: tracked alias not found
chmod: tracked alias not found' chmod: tracked alias not found'
got=$($SHELL -c ' got=$($SHELL -c '
hash vi chmod hash ls chmod
hash -r hash -r
alias -pt vi chmod alias -pt ls chmod
' 2>&1) ' 2>&1)
ret=$? ret=$?
[[ $exp == $got ]] || err_exit "Listing removed tracked aliases with 'alias -pt' should fail with an error message" \ [[ $exp == $got ]] || err_exit "Listing removed tracked aliases with 'alias -pt' should fail with an error message" \

View file

@ -2,7 +2,7 @@
# # # #
# This software is part of the ast package # # This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property # # Copyright (c) 1982-2012 AT&T Intellectual Property #
# Copyright (c) 2020-2021 Contributors to ksh 93u+m # # Copyright (c) 2020-2022 Contributors to ksh 93u+m #
# and is licensed under the # # and is licensed under the #
# Eclipse Public License, Version 1.0 # # Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property # # by AT&T Intellectual Property #
@ -947,5 +947,40 @@ got=$(typeset -Z x=0x15; set +x; { echo $((x)); } 2>&1)
[[ $got == "$exp" ]] || err_exit "typeset -Z corrupts hexadecimal number in arithmetic context" \ [[ $got == "$exp" ]] || err_exit "typeset -Z corrupts hexadecimal number in arithmetic context" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))" "(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# ======
# Test for 'set -u' backported from ksh93v- 2013-09-26
unset IFS i
set -u
float -a ar
function f
{
integer i=0 ar_i=0
for (( i=0 ; i < 3 ; i++ ))
do (( ar[ar_i++]=i))
done
printf "%q\n" "${ar[*]}"
}
[[ $(f) == "'0 1 2'" ]] || err_exit '0 value for variable in arithmetic expression inside function with set -u fails'
set +u
# Test for unset x.NOT_KNOWN floating point variable (backported
# from ksh93v- 2013-09-13).
unset x
float x
((x.NOT_KNOWN == 0)) || err_exit 'x.NOT_KNOWN is unknown and should have value 0'
# Test for a bug with short integers that causes core dumps
# (backported from ksh93v- 2013-08-07).
"$SHELL" <<- \EOF || err_exit 'detected short integer bug that causes core dumps'
typeset -s -i -a t
typeset -s -i p
(( p=2**17 )) # tape start position
(( t[p]+=13))
while (( t[p] != 0 ))
do ((t[p]-=1 , p+=1))
done
exit 0
EOF
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))

View file

@ -819,5 +819,9 @@ got=$(typeset -p foo)
[[ $exp == "$got" ]] || err_exit "Output from 'typeset -p' for indexed array cannot be used for reinput" \ [[ $exp == "$got" ]] || err_exit "Output from 'typeset -p' for indexed array cannot be used for reinput" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))" "(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# ======
# Regression test for 'typeset -a' from ksh93v- 2013-04-02
"$SHELL" -c 'a=(foo bar); [[ $(typeset -a) == *"a=("*")"* ]]' || err_exit "'typeset -a' doesn't work correctly"
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))

View file

@ -224,6 +224,13 @@ exp=3
[[ ${foo[bar][x]} == $exp ]] || err_exit "subscript gets added incorrectly to an associative array when ++ operator is called" \ [[ ${foo[bar][x]} == $exp ]] || err_exit "subscript gets added incorrectly to an associative array when ++ operator is called" \
"(expected '$exp', got '${foo[bar][x]}')" "(expected '$exp', got '${foo[bar][x]}')"
unset A
typeset -A A
typeset -A A[a]
A[a][z]=1
[[ ${!A[a][@]} == z ]] || err_exit 'A[a] should only have subscript z' \
"(got $(printf %q "${!A[a][@]}"))"
# ====== # ======
# Multidimensional arrays with an unset method shouldn't cause a crash. # Multidimensional arrays with an unset method shouldn't cause a crash.
# The test itself must be run inside of a function. # The test itself must be run inside of a function.

View file

@ -737,5 +737,18 @@ got=$(env | grep '^\.foo[.=]')
unset .foo.bar .foo unset .foo.bar .foo
set +o allexport set +o allexport
# ======
# Regression test from ksh93v- 2012-10-24 for testing the zerofill width
# after exporting a variable.
unset exp got
typeset -Z4 VAR1
VAR1=1
exp=$(typeset -p VAR1)
export VAR1
got=$(typeset -p VAR1)
got=${got/ -x/}
[[ $got == "$exp" ]] || err_exit 'typeset -x causes zerofill width to change' \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))

View file

@ -347,7 +347,7 @@ then [[ $($SHELL -c 'cat <(print foo)' 2> /dev/null) == foo ]] || err_exit 'proc
[[ $({ $SHELL -c 'cat <(for i in x y z; do print $i; done)';} 2> /dev/null) == $'x\ny\nz' ]] || [[ $({ $SHELL -c 'cat <(for i in x y z; do print $i; done)';} 2> /dev/null) == $'x\ny\nz' ]] ||
err_exit 'process substitution of compound commands not working' err_exit 'process substitution of compound commands not working'
fi fi
[[ $($SHELL -r 'command -p :' 2>&1) == *restricted* ]] || err_exit 'command -p not restricted' [[ $($SHELL -cr 'command -p :' 2>&1) == *restricted* ]] || err_exit 'command -p not restricted'
print cat > $tmp/scriptx print cat > $tmp/scriptx
chmod +x $tmp/scriptx chmod +x $tmp/scriptx
[[ $($SHELL -c "print foo | $tmp/scriptx ;:" 2> /dev/null ) == foo ]] || err_exit 'piping into script fails' [[ $($SHELL -c "print foo | $tmp/scriptx ;:" 2> /dev/null ) == foo ]] || err_exit 'piping into script fails'

View file

@ -355,6 +355,9 @@ test ! ! ! 2> /dev/null || err_exit 'test ! ! ! should return 0'
test ! ! x 2> /dev/null || err_exit 'test ! ! x should return 0' test ! ! x 2> /dev/null || err_exit 'test ! ! x should return 0'
test ! ! '' 2> /dev/null && err_exit 'test ! ! "" should return non-zero' test ! ! '' 2> /dev/null && err_exit 'test ! ! "" should return non-zero'
x=10
([[ x -eq 10 ]]) 2> /dev/null || err_exit 'x -eq 10 fails in [[...]] with x=10'
# ====== # ======
# The POSIX mode should disable the ancient 'test -t' compatibility hack. # The POSIX mode should disable the ancient 'test -t' compatibility hack.
if [[ -o ?posix ]] if [[ -o ?posix ]]

View file

@ -801,19 +801,41 @@ integer foo=1
exp=4 exp=4
got=$(foo+=3 command eval 'echo $foo') got=$(foo+=3 command eval 'echo $foo')
[[ $exp == $got ]] || err_exit "Test 1: += assignment for environment variables doesn't work with 'command special_builtin'" \ [[ $exp == $got ]] || err_exit "Test 1: += assignment for environment variables doesn't work with 'command special_builtin'" \
"(expected $exp, got $got)" "(expected $(printf %q "$exp"), got $(printf %q "$got"))"
foo+=3 command eval 'test $foo' foo+=3 command eval 'test $foo'
(( foo == 1 )) || err_exit "environment isn't restored after 'command special_builtin'" \ exp=1
"(expected 1, got $foo)" (( foo == exp )) || err_exit "environment isn't restored after 'command special_builtin'" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
got=$(foo+=3 eval 'echo $foo') got=$(foo+=3 eval 'echo $foo')
exp=4
[[ $exp == $got ]] || err_exit "+= assignment for environment variables doesn't work with builtins" \ [[ $exp == $got ]] || err_exit "+= assignment for environment variables doesn't work with builtins" \
"(expected $exp, got $got)" "(expected $(printf %q "$exp"), got $(printf %q "$got"))"
unset foo unset foo
exp=barbaz exp=barbaz
got=$(foo=bar; foo+=baz command eval 'echo $foo') got=$(foo=bar; foo+=baz command eval 'echo $foo')
[[ $exp == $got ]] || err_exit "Test 2: += assignment for environment variables doesn't work with 'command special_builtin'" \ [[ $exp == $got ]] || err_exit "Test 2: += assignment for environment variables doesn't work with 'command special_builtin'" \
"(expected $exp, got $got)" "(expected $(printf %q "$exp"), got $(printf %q "$got"))"
unset y
exp='outside f, 1, 2, 3, outside f'
got=$(
f() {
if [ -n "${_called_f+_}" ]; then
for y; do
printf '%s, ' "$y"
done
else
_called_f= y= command eval '{ typeset +x y; } 2>/dev/null; f "$@"'
fi
}
y='outside f'
printf "$y, "
f 1 2 3
echo "$y"
)
[[ $got == "$exp" ]] || err_exit 'assignments to "command special_built-in" leaving side effects' \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# Attempting to modify a readonly variable with the += operator should fail # Attempting to modify a readonly variable with the += operator should fail
exp=2 exp=2
@ -1027,7 +1049,9 @@ unset foo
[[ $expect != $actual ]] && err_exit "Specifying $padding padding with format '%$i' doesn't work (expected '$expect', got '$actual')" [[ $expect != $actual ]] && err_exit "Specifying $padding padding with format '%$i' doesn't work (expected '$expect', got '$actual')"
done done
done done
exit $Errors
) )
Errors=$? # Ensure error count survives subshell
# ====== # ======
# Test various AST getopts usage/manual outputs # Test various AST getopts usage/manual outputs
@ -1544,5 +1568,21 @@ kill "$sleep_pid" 2>/dev/null
(echo ok |& read -p .sh.foo"?dummy prompt: " && [[ ${.sh.foo} == ok ]]) </dev/null \ (echo ok |& read -p .sh.foo"?dummy prompt: " && [[ ${.sh.foo} == ok ]]) </dev/null \
|| err_exit "'read -p' co-process usage is not fully backward compatible with ksh 93u+" || err_exit "'read -p' co-process usage is not fully backward compatible with ksh 93u+"
# Backported ksh93v- 2014-06-25 test for eval bug when called
# from . script in a startup file.
print $'eval : foo\nprint ok' > "$tmp/evalbug"
print ". $tmp/evalbug" > "$tmp/envfile"
[[ $(ENV=$tmp/envfile "$SHELL" -i -c : 2> /dev/null) == ok ]] || err_exit 'eval inside dot script called from profile file not working'
# Backported ksh93v- 2013-03-18 test for 'read -A', where
# IFS sets the delimiter to a newline while -d specifies
# no delimiter (-d takes priority over IFS).
if ((SHOPT_BRACEPAT)); then
got=$(printf %s\\n {a..f} | IFS=$'\n' read -rd '' -A a; typeset -p a)
exp=$'typeset -a a=($\'a\\nb\\nc\\nd\\ne\\nf\\n\')'
[[ $got == "$exp" ]] || err_exit "IFS overrides the delimiter specified by the read command's -d option" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
fi
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))

View file

@ -2,7 +2,7 @@
# # # #
# This software is part of the ast package # # This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property # # Copyright (c) 1982-2012 AT&T Intellectual Property #
# Copyright (c) 2020-2021 Contributors to ksh 93u+m # # Copyright (c) 2020-2022 Contributors to ksh 93u+m #
# and is licensed under the # # and is licensed under the #
# Eclipse Public License, Version 1.0 # # Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property # # by AT&T Intellectual Property #
@ -652,6 +652,11 @@ test_read_type_crash
test_read_C_into_array test_read_C_into_array
test_read_C_special_shell_keywords test_read_C_special_shell_keywords
unset bar
enum bool=(false true)
bool -a bar
bar[3]=true
[[ $((5+bar[3])) != 6 ]] && err_exit '$((5+bar[3])) should be 6'
# tests done # tests done
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))

View file

@ -57,7 +57,7 @@ done
typeset -T X_t=( typeset name=aha ) typeset -T X_t=( typeset name=aha )
typeset -a[X_t] arr typeset -a[X_t] arr
) 2> /dev/null ) 2> /dev/null
[[ $? == 1 ]] || err_exit 'typeset -a[X_t] should generate an error message when X-t is not an enumeration type' [[ $? == 1 ]] || err_exit 'typeset -a[X_t] should generate an error message when X_t is not an enumeration type'
typeset -a [Color_t] arr typeset -a [Color_t] arr
arr[green]=foo arr[green]=foo
@ -168,5 +168,27 @@ exp=': trap: is a special shell builtin'
[[ $got == *"$exp" ]] || err_exit "enum overrides special builtin" \ [[ $got == *"$exp" ]] || err_exit "enum overrides special builtin" \
"(expected match of *$(printf %q "$exp"); got $(printf %q "$got"))" "(expected match of *$(printf %q "$exp"); got $(printf %q "$got"))"
# ======
# Various tests backported from ksh93v- for enum type arrays.
enum bool=(false true)
bool -A a=( [2]=true [4]=false )
exp=true
got=${a[2]}
[[ $got == $exp ]] || err_exit 'associative array assignment failure when using enums' \
"(expected $(printf %q "$exp"); got $(printf %q "$got"))"
exp=2
got=${#a[@]}
[[ $got == $exp ]] || err_exit 'bool -A a should only have two elements' \
"(expected $(printf %q "$exp"); got $(printf %q "$got"))"
bool -a bia
(( bia[4]=false ))
[[ ${bia[3]} ]] && err_exit 'empty index array element should not produce a value'
(( bia[3] == 0 )) || err_exit 'empty index array element should be numerically 0'
bool -A baa
(( baa[4]=false ))
[[ ${baa[3]} ]] && err_exit 'empty associative array element should not produce a value'
(( baa[3] == 0 )) || err_exit 'empty associative array element should be numerically 0'
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))

View file

@ -2,7 +2,7 @@
# # # #
# This software is part of the ast package # # This software is part of the ast package #
# Copyright (c) 1982-2011 AT&T Intellectual Property # # Copyright (c) 1982-2011 AT&T Intellectual Property #
# Copyright (c) 2020-2021 Contributors to ksh 93u+m # # Copyright (c) 2020-2022 Contributors to ksh 93u+m #
# and is licensed under the # # and is licensed under the #
# Eclipse Public License, Version 1.0 # # Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property # # by AT&T Intellectual Property #
@ -182,5 +182,26 @@ done
(fn() { false; }; fn >/dev/null/nonexistent; true) 2>/dev/null \ (fn() { false; }; fn >/dev/null/nonexistent; true) 2>/dev/null \
|| err_exit 'Redirection error with function execution causes shell to exit' || err_exit 'Redirection error with function execution causes shell to exit'
# ======
# Backported regression test from ksh93v- 2014-09-29 for the
# exit status of functions in command substitutions.
foo() {
print -r foo | read
return 1
}
o1=$(foo "foo")
status=$?
exp=1
((exp == status)) || err_exit 'function which fails inside of a command substitution returns wrong exit status' \
"(expected '$exp', got '$status')"
# Backported test from ksh93v- 2014-07-21 for the exit status
# of subshells with a failing command without pipefail enabled.
x=$({ sleep .1; false;} | true)
status=$?
exp=0
(( exp == status )) || err_exit 'without pipefail, non-zero exit in pipeline causes command substitution to fail' \
"(expected '$exp', got '$status')"
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))

View file

@ -392,7 +392,7 @@ function closure
done done
return $r return $r
} }
closure 0 || err_exit -u2 'for loop function optimization bug2' closure 0 || err_exit 'for loop function optimization bug'
dir=$tmp/dir dir=$tmp/dir
mkdir $dir mkdir $dir
cd $dir || { err_exit "cd $dir failed"; exit 1; } cd $dir || { err_exit "cd $dir failed"; exit 1; }

View file

@ -2,7 +2,7 @@
# # # #
# This software is part of the ast package # # This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property # # Copyright (c) 1982-2012 AT&T Intellectual Property #
# Copyright (c) 2020-2021 Contributors to ksh 93u+m # # Copyright (c) 2020-2022 Contributors to ksh 93u+m #
# and is licensed under the # # and is licensed under the #
# Eclipse Public License, Version 1.0 # # Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property # # by AT&T Intellectual Property #
@ -515,6 +515,14 @@ EOF' 2>&1)
$SHELL -c '$(true << !) $SHELL -c '$(true << !)
!' 2> /dev/null && err_exit "a here-doc that isn't completed before the closing ) in a command substitution doesn't cause an error" !' 2> /dev/null && err_exit "a here-doc that isn't completed before the closing ) in a command substitution doesn't cause an error"
# Here-document test backported from ksh93v- 2014-04-15 for backtick
# command substitutions.
x=$("$SHELL" -c 'test=`"$SHELL" 2>&1 << EOF
print $?
EOF`
print $test')
[[ $x == 0 ]] || err_exit '`` command substitution containing here-doc not working'
# ====== # ======
# Check that ${p}, where p is a special parameter, does not cause a syntax error in a here-document. # Check that ${p}, where p is a special parameter, does not cause a syntax error in a here-document.
# Bug for ${!} and ${$} reported at: https://github.com/ksh93/ksh/issues/127 # Bug for ${!} and ${$} reported at: https://github.com/ksh93/ksh/issues/127
@ -525,5 +533,14 @@ EOF
' 2>&1) || err_exit "special parameter \${$p} throws syntax error in here-document (got \"$err\")" ' 2>&1) || err_exit "special parameter \${$p} throws syntax error in here-document (got \"$err\")"
done done
# ======
# Regression test for the cat builtin backported from
# ksh93v- 2013-08-29.
if builtin cat 2> /dev/null; then
exp='foo bar baz bork blah blarg'
got=$(cat <<<"foo bar baz" 3<&0 <<<"$(</dev/fd/3) bork blah blarg")
[[ $got == "$exp" ]] || '3<%0 does not work when 0 is <<< here-doc'
fi
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))

View file

@ -2,7 +2,7 @@
# # # #
# This software is part of the ast package # # This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property # # Copyright (c) 1982-2012 AT&T Intellectual Property #
# Copyright (c) 2020-2021 Contributors to ksh 93u+m # # Copyright (c) 2020-2022 Contributors to ksh 93u+m #
# and is licensed under the # # and is licensed under the #
# Eclipse Public License, Version 1.0 # # Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property # # by AT&T Intellectual Property #

View file

@ -2,7 +2,7 @@
# # # #
# This software is part of the ast package # # This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property # # Copyright (c) 1982-2012 AT&T Intellectual Property #
# Copyright (c) 2020-2021 Contributors to ksh 93u+m # # Copyright (c) 2020-2022 Contributors to ksh 93u+m #
# and is licensed under the # # and is licensed under the #
# Eclipse Public License, Version 1.0 # # Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property # # by AT&T Intellectual Property #
@ -400,7 +400,6 @@ then LC_ALL=en_US.UTF-8
== "$got" ]] \ == "$got" ]] \
|| err_exit "incorrect string from printf %q" || err_exit "incorrect string from printf %q"
fi fi
fi fi
# ====== # ======

View file

@ -2,7 +2,7 @@
# # # #
# This software is part of the ast package # # This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property # # Copyright (c) 1982-2012 AT&T Intellectual Property #
# Copyright (c) 2020-2021 Contributors to ksh 93u+m # # Copyright (c) 2020-2022 Contributors to ksh 93u+m #
# and is licensed under the # # and is licensed under the #
# Eclipse Public License, Version 1.0 # # Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property # # by AT&T Intellectual Property #
@ -573,5 +573,37 @@ got=$("$SHELL" -o pipefail -c 'trap "print ERR\ trap" ERR; true | exit 3 | false
let "(e=$?)==1" && [[ $got == 'ERR trap' ]] || err_exit 'ERR trap + pipefail failed' \ let "(e=$?)==1" && [[ $got == 'ERR trap' ]] || err_exit 'ERR trap + pipefail failed' \
"(expected status 1, 'ERR trap'; got status $e, $(printf %q "$got"))" "(expected status 1, 'ERR trap'; got status $e, $(printf %q "$got"))"
# ======
# Basic test for 'ksh -v' backported from ksh93v- 2013-09-13
exp=:
got=$("$SHELL" -vc : 2>&1)
[[ $exp == $got ]] || err_exit 'incorrect output with ksh -v' \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# ======
# Tests that set -m puts background jobs in a separate process group.
LINENO=$LINENO "$SHELL" -m <<- \EOF
. "${SHTESTS_COMMON:-${0%/*}/_common}"
[[ $- == *m* ]] || err_exit '$- does not contain m when monitor mode specified'
float t=SECONDS
sleep 2 & pid=$!
kill -KILL -$pid 2> /dev/null || err_exit 'kill to background group failed'
wait 2> /dev/null
(( (SECONDS-t) > 1 )) && err_exit 'kill did not kill background sleep'
exit $Errors
EOF
((Errors+=$?))
# ======
# Test for 'set -u' from ksh93v- 2013-04-09
"$SHELL" 2> /dev/null <<- \EOF && err_exit 'unset variable with set -u on does not terminate script'
set -e -u -o pipefail
ls | while read file
do
files[${#files[*]}]=$fil
done
exit
EOF
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))

View file

@ -954,5 +954,18 @@ exp=$PWD$'\n'$PWD
[[ $got == "$exp" ]] || err_exit "child shell failed to obtain PWD" \ [[ $got == "$exp" ]] || err_exit "child shell failed to obtain PWD" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))" "(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# ======
# Test backported from ksh93v- 2013-06-28 for deleting
# a loaded libcmd builtin.
if builtin cat 2> /dev/null
then path=$PATH
PATH=/bin:/usr/bin
if [[ $(type -t cat) == builtin ]]
then builtin -d cat
[[ $(type -t cat) == builtin ]] && err_exit 'builtin -d does not delete builtin libcmd builtin'
fi
fi
PATH=$path
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))

View file

@ -2,7 +2,7 @@
# # # #
# This software is part of the ast package # # This software is part of the ast package #
# Copyright (c) 1982-2011 AT&T Intellectual Property # # Copyright (c) 1982-2011 AT&T Intellectual Property #
# Copyright (c) 2020-2021 Contributors to ksh 93u+m # # Copyright (c) 2020-2022 Contributors to ksh 93u+m #
# and is licensed under the # # and is licensed under the #
# Eclipse Public License, Version 1.0 # # Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property # # by AT&T Intellectual Property #
@ -362,4 +362,13 @@ ARGS=("$@")
set -- "${ARGS[@]}" set -- "${ARGS[@]}"
(( $# )) && err_exit 'set -- "${ARGS[@]}" for empty array should not produce arguments' (( $# )) && err_exit 'set -- "${ARGS[@]}" for empty array should not produce arguments'
# ======
# Backported tests from ksh93v- 2013-04-22 for using
# backslashes in variables.
x=\\x
[[ x == $x ]] && err_exit "\$x='$x' should not match x"
case x in
$x) err_exit "case \$x='$x' should not match x";;
esac
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))

View file

@ -210,7 +210,7 @@ cat >"${testscript}" <<-TEST1SCRIPT
printf '\\n' printf '\\n'
} >"\${tmpfile}" } >"\${tmpfile}"
diff -u <( printf '%s\\n' "\${xtext}") "\${tmpfile}" diff -u <( printf '%s\\n' "\${xtext}") "\${tmpfile}" | sed '/No differences encountered/d'
if cmp <( printf '%s\\n' "\${xtext}") "\${tmpfile}" ; then if cmp <( printf '%s\\n' "\${xtext}") "\${tmpfile}" ; then
printf "#input and output OK (%d characters).\\n" "\$(wc -m <"\${tmpfile}")" printf "#input and output OK (%d characters).\\n" "\$(wc -m <"\${tmpfile}")"
else else

View file

@ -13,7 +13,7 @@ USAGE=$'
[-author?David Korn <dgk@research.att.com>] [-author?David Korn <dgk@research.att.com>]
[-author?Glenn Fowler <gsf@research.att.com>] [-author?Glenn Fowler <gsf@research.att.com>]
[-copyright?(c) 2000-2012 AT&T Intellectual Property] [-copyright?(c) 2000-2012 AT&T Intellectual Property]
[-copyright?(c) 2020-2021 Contributors to https://github.com/ksh93/ksh] [-copyright?(c) 2020-2022 Contributors to https://github.com/ksh93/ksh]
[-license?http://www.eclipse.org/org/documents/epl-v10.html] [-license?http://www.eclipse.org/org/documents/epl-v10.html]
[+NAME?shtests - ksh regression test harness] [+NAME?shtests - ksh regression test harness]
[+DESCRIPTION?\bshtests\b is the \bksh\b(1) regression test harness for [+DESCRIPTION?\bshtests\b is the \bksh\b(1) regression test harness for

View file

@ -568,5 +568,11 @@ got=$("$SHELL" -c 'trap + INT; "$SHELL" -c '\''kill -s INT $$'\''; echo "$?, con
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))" "(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
trap - INT trap - INT
# Test for 'trap - INT' backported from ksh93v- 2013-07-27
float s=SECONDS
(trap - INT; exec sleep 2) & sleep .5; kill -sINT $!
wait $!
(( (SECONDS-s) < 1.8)) && err_exit "'trap - INT' causing trap to not be ignored"
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))

View file

@ -1112,5 +1112,46 @@ e1=$( (f() { return 267; }; f); echo $? )
e2=$( (ulimit -t unlimited 2>/dev/null; f() { return 267; }; f); echo $? ) e2=$( (ulimit -t unlimited 2>/dev/null; f() { return 267; }; f); echo $? )
((e1==11 && e2==11)) || err_exit "exit status of virtual ($e1) and real ($e2) subshell should both be clipped to 8 bits (11)" ((e1==11 && e2==11)) || err_exit "exit status of virtual ($e1) and real ($e2) subshell should both be clipped to 8 bits (11)"
# ======
# Regression test backported from ksh93v- 2014-04-15 for
# a nonexistent command at the end of a pipeline in ``
"$SHELL" -c 'while((SECONDS<3)); do test -z `/bin/false | /bin/false | /bin/doesnotexist`; done; :' 2> /dev/null || \
err_exit 'nonexistent last command in pipeline causes `` command substitution to fail'
# Regression test backported from ksh93v- 2013-07-19 for the
# effects of .sh.value on shared-state command substitutions.
function foo
{
.sh.value=bam
}
got=${ foo; }
[[ $got ]] && err_exit "setting .sh.value in a function affects shared-state command substitution output when it shouldn't print anything" \
"(got $(printf %q "$got"))"
# Regression test from ksh93v- 2012-11-21 for testing nested
# command substitutions with a 2>&1 redirection.
fun()
{
echo=$(whence -p echo)
foo=` $echo foo`
print -n stdout=$foo
print -u2 stderr=$foo
}
[[ `fun 2>&1` == 'stdout=foostderr=foo' ]] || err_exit 'nested command substitution with 2>&1 not working'
# Various regression tests from ksh93v- 2012-10-04 and 2012-10-24
$SHELL > /dev/null -c 'echo $(for x in whatever; do case y in *) true;; esac; done)' || err_exit 'syntax error with case in command substitution'
print 'print OK' | got=$("$SHELL")
exp=OK
[[ $got == $exp ]] || err_exit '$() command substitution not waiting for process completion' \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
print 'print OK' | out=$( "$SHELL" 2>&1 )
got="${out}$?"
exp=OK0
[[ $got == $exp ]] || err_exit "capturing output from ksh when piped doesn't work correctly" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))

View file

@ -306,7 +306,7 @@ done
( (
PS4=$tmpPS4 PS4=$tmpPS4
[[ $(string=$string $SHELL -c ": \${string/$pattern/}; print \${.sh.match[26]}") == Z ]] || err_exit -u2 'sh.match[26] not Z' [[ $(string=$string $SHELL -c ": \${string/$pattern/}; print \${.sh.match[26]}") == Z ]] || err_exit 'sh.match[26] not Z'
: ${string/$pattern/} : ${string/$pattern/}
(( ${#.sh.match[@]} == 53 )) || err_exit '.sh.match has wrong number of elements' (( ${#.sh.match[@]} == 53 )) || err_exit '.sh.match has wrong number of elements'
[[ ${.sh.match[@]:2:4} == 'B C D E' ]] || err_exit '${.sh.match[@]:2:4} incorrect' [[ ${.sh.match[@]:2:4} == 'B C D E' ]] || err_exit '${.sh.match[@]:2:4} incorrect'

View file

@ -621,7 +621,6 @@ function main
for ((i=2 ; i < 8 ; i++ )) ; do for ((i=2 ; i < 8 ; i++ )) ; do
pawn_t c.board[1][$i] pawn_t c.board[1][$i]
done done
} }
main 2> /dev/null && err_exit 'type assignment to compound array instance should generate an error' main 2> /dev/null && err_exit 'type assignment to compound array instance should generate an error'
@ -724,5 +723,16 @@ exp=$'start1\ntypeset -x a=one\nstart2\ntypeset -x a=one\nend2\nend1'
[[ $got == "$exp" ]] || err_exit 'exporting variable to #!-less script' \ [[ $got == "$exp" ]] || err_exit 'exporting variable to #!-less script' \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))" "(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# Backported regression test from ksh93v- 2013-08-07 for
# short integer arrays in types.
got=$("$SHELL" 2>&1 <<- \EOF
typeset -T X_t=(typeset -si -a arr=(7 8) )
X_t x
print -r -- $((x.arr[1]))
EOF) || err_exit "short integer arrays in types fails (got exit status $?)"
exp=8
[[ $got == $exp ]] || err_exit "short integer arrays in types isn't working correctly" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))

View file

@ -561,6 +561,10 @@ actual=$*
[[ $actual == "$expect" ]] || err_exit "IFS failed with invalid multi-byte character" \ [[ $actual == "$expect" ]] || err_exit "IFS failed with invalid multi-byte character" \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))" "(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
# Backported test from ksh93v- 2013-06-28 for 'unset IFS'
unset IFS
[[ ${IFS+abc} ]] && err_exit "testing for unset IFS not working"
# ^^^ end: IFS tests ^^^ # ^^^ end: IFS tests ^^^
# restore default split: # restore default split:
unset IFS unset IFS