Skip to content

Commit

Permalink
Misc regression test fixes
Browse files Browse the repository at this point in the history
src/cmd/ksh93/tests/basic.sh:
- Fix syntax error (unbalanced single quote) in two -c script
  invocations. It only failed to throw a syntax error due to a
  problematic hack in ksh that may be removed soon.
  See: #199

src/cmd/ksh93/tests/builtins.sh,
src/cmd/ksh93/tests/io.sh:
- Redirect standard error on two ksh -i invocations to /dev/null
  to work around the test hanging on AIX.

src/cmd/ksh93/tests/comvario.sh:
- Remove duplicate copyright header.
- Fix warning format.

src/cmd/ksh93/tests/functions.sh:
- Fix the 'TERM signal sent to last process of function kills the
  script' test so that it works on AIX. We cannot rely on grepping
  'ps' output as the external 'sleep' command does not show the
  command name on AIX. Instead, find it by its parent PID.

src/cmd/ksh93/tests/locale.sh,
src/cmd/ksh93/tests/substring.sh:
- Rewrite the very broken multibyte locale tests (two outright
  syntax errors due to unbalanced quotes, and none of the tests
  actually worked).
- Since they set LC_ALL, move them to locale.sh.

src/cmd/ksh93/tests/variables.sh:
- Redirect stderr on some 'ulimit -t unlimited' invocations (which
  fork subshells as the intended side effect) to /dev/null in case
  that exceeds a system-defined limit.
  • Loading branch information
McDutchie committed Feb 28, 2021
1 parent 7ad274f commit 5d82004
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/cmd/ksh93/tests/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ fi
print cat > $tmp/scriptx
chmod +x $tmp/scriptx
[[ $($SHELL -c "print foo | $tmp/scriptx ;:" 2> /dev/null ) == foo ]] || err_exit 'piping into script fails'
[[ $($SHELL -c 'X=1;print -r -- ${X:=$(expr "a(0)" : '"'a*(\([^)]\))')}'" 2> /dev/null) == 1 ]] || err_exit 'x=1;${x:=$(..."...")} failure'
[[ $($SHELL -c 'print -r -- ${X:=$(expr "a(0)" : '"'a*(\([^)]\))')}'" 2> /dev/null) == 0 ]] || err_exit '${x:=$(..."...")} failure'
[[ $($SHELL -c 'X=1;print -r -- ${X:=$(expr "a(0)" : '"'a*(\([^)]\))')}" 2> /dev/null) == 1 ]] || err_exit 'x=1;${x:=$(..."...")} failure'
[[ $($SHELL -c 'print -r -- ${X:=$(expr "a(0)" : '"'a*(\([^)]\))')}" 2> /dev/null) == 0 ]] || err_exit '${x:=$(..."...")} failure'
if cat /dev/fd/3 >/dev/null 2>&1 || whence mkfifo > /dev/null
then [[ $(cat <(print hello) ) == hello ]] || err_exit "process substitution not working outside for or while loop"
$SHELL -c '[[ $(for i in 1;do cat <(print hello);done ) == hello ]]' 2> /dev/null|| err_exit "process substitution not working in for or while loop"
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/tests/builtins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ then (
fi
cd "$tmp"
$SHELL +E -i <<- \! && err_exit 'interactive shell should not exit 0 after false'
$SHELL +E -i 2>/dev/null <<- \! && err_exit 'interactive shell should not exit 0 after false'
false
exit
!
Expand Down
23 changes: 3 additions & 20 deletions src/cmd/ksh93/tests/comvario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,6 @@
# Florham Park NJ #
# #
# David Korn <dgk@research.att.com> #
# #
########################################################################
########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# http://www.eclipse.org/org/documents/epl-v10.html #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# Roland Mainz <roland.mainz@nrubsig.org> #
# #
########################################################################
Expand All @@ -41,10 +23,11 @@
function err_exit
{
print -u2 -n '\t'
print -u2 -r ${Command}[$1]: "${@:2}"
print -u2 -r "${Command}[$1]: ${@:2}"
(( Errors++ ))
}
alias err_exit='err_exit $LINENO'
alias warning='err\_exit $((Errors--,LINENO)) warning:'

Command=${0##*/}
integer Errors=0
Expand All @@ -58,7 +41,7 @@ integer Errors=0 HAVE_signbit=0

if typeset -f .sh.math.signbit >/dev/null && (( signbit(-NaN) ))
then HAVE_signbit=1
else print -u2 "$0: warning: -lm does not support signbit(-NaN)"
else warning "-lm does not support signbit(-NaN)"
fi

compound bracketstat=(
Expand Down
15 changes: 12 additions & 3 deletions src/cmd/ksh93/tests/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ read -n4 c < $0 2> /dev/null

ulimit -c 0

binecho=$(whence -p echo)
bin_echo=$(whence -p echo)
bin_sleep=$(whence -p sleep)
bin_kill=$(whence -p kill)

integer foo=33
bar=bye
Expand Down Expand Up @@ -138,7 +139,7 @@ fi
if [[ $PWD != "$dir" ]]
then err_exit 'cd inside nested subshell changes $PWD'
fi
fun() "$binecho" hello
fun() "$bin_echo" hello
if [[ $(fun) != hello ]]
then err_exit one line functions not working
fi
Expand Down Expand Up @@ -1126,7 +1127,15 @@ function gosleep
"$bin_sleep" 1
}
x=$(
(sleep .25; pid=; ps 2>/dev/null | grep sleep | read pid extra; [[ $pid ]] && kill -- "$pid") &
ulimit -t unlimited 2>/dev/null # fork this subshell
mysubpid=${.sh.pid} # this subshell's new PID (new 93u+m feature)
(
sleep .25
# kill 'gosleep' by getting the PIDs that have $mysubpid as their parent PID
# (which includes this background process itself, but that's fine as we're invoking external 'kill')
pids=$(UNIX95=1 ps -o ppid= -o pid= 2>/dev/null | awk -v p=$mysubpid '$1==p { print $2 }')
[[ -n $pids ]] && "$bin_kill" $pids
) &
gosleep 2> /dev/null
print ok
)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/tests/io.sh
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ err=$(
# ======
# A redirection with a null command could crash under certain circumstances (rhbz#1200534)
"$SHELL" -i >/dev/null -c '
"$SHELL" -i >/dev/null 2>&1 -c '
function dlog
{
fc -ln -0
Expand Down
23 changes: 23 additions & 0 deletions src/cmd/ksh93/tests/locale.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,29 @@ b=$($SHELL -c '(LC_ALL=debug / 2>/dev/null); /' 2>&1 | sed -e "s,.*: *,," -e "s,
b=$($SHELL -c '(LC_ALL=debug; / 2>/dev/null); /' 2>&1 | sed -e "s,.*: *,," -e "s, *\[.*,,")
[[ "$b" == "$a" ]] || err_exit "locale not restored after subshell -- expected '$a', got '$b'"

# multibyte locale tests
if ((SHOPT_MULTIBYTE))
then LC_ALL=debug
x='a<2b|>c<3d|\>e'
typeset -A exp=(
['${x:0:1}']=a
['${x:1:1}']='<2b|>'
['${x:3:1}']='<3d|\>'
['${x:4:1}']=e
['${x:1}']='<2b|>c<3d|\>e'
['${x: -1:1}']=e
['${x: -2:1}']='<3d|\>'
['${x:1:3}']='<2b|>c<3d|\>'
['${x:1:20}']='<2b|>c<3d|\>e'
['${x#??}']='c<3d|\>e'
)
for i in "${!exp[@]}"
do eval "got=$i"
test "$got" = "${exp[$i]}" || err_exit "$i: expected '${exp[$i]}', got '$got'"
done
unset exp LC_ALL
fi # SHOPT_MULTIBYTE

# test shift-jis \x81\x40 ... \x81\x7E encodings
# (shift char followed by 7 bit ascii)

Expand Down
14 changes: 0 additions & 14 deletions src/cmd/ksh93/tests/substring.sh
Original file line number Diff line number Diff line change
Expand Up @@ -585,20 +585,6 @@ do i=$1
shift 4
done

#multibyte locale tests
if((SHOPT_MULTIBYTE)); then
x='a<2b|>c<3d|\>e' LC_ALL=debug $SHELL -c 'test "${x:0:1}" == a || err_exit ${x:0:1} should be a'
x='a<2b|>c<3d|\>e' LC_ALL=debug $SHELL -c 'test "${x:1:1}" == "<2b|>" || err_exit ${x:1:1} should be <2b|>'
x='a<2b|>c<3d|\>e' LC_ALL=debug $SHELL -c 'test "${x:3:1}" == "<3d|\\>" || err_exit ${x:3:1} should be <3d|\>'
x='a<2b|>c<3d|\>e' LC_ALL=debug $SHELL -c 'test "${x:4:1}" == e || err_exit ${x:4:1} should bee'
x='a<2b|>c<3d|\>e' LC_ALL=debug $SHELL -c 'test "${x:1}" == "<2b|>c<3d|\\>e" || print -u2 ${x:1}" should be <2b|>c<3d|\>e'
x='a<2b|>c<3d|\>e' LC_ALL=debug $SHELL -c 'test "${x: -1:1}" == e || err_exit ${x: -1:1} should be e'
x='a<2b|>c<3d|\>e' LC_ALL=debug $SHELL -c 'test "${x: -2:1}" == "<3d|\\>" || err_exit ${x: -2:1} == <3d|\>'
x='a<2b|>c<3d|\>e' LC_ALL=debug $SHELL -c 'test "${x:1:3}" == "<2b|>c<3d|\\>" || err_exit ${x:1:3} should be <2b|>c<3d|\>'
x='a<2b|>c<3d|\>e' LC_ALL=debug $SHELL -c 'test "${x:1:20}" == "<2b|>c<3d|\\>e" || err_exit ${x:1:20} should be <2b|>c<3d|\>e'
x='a<2b|>c<3d|\>e' LC_ALL=debug $SHELL -c 'test "${x#??}" == "c<3d|\\>e" || err_exit "${x#??} should be c<3d|\>e'
fi # SHOPT_MULTIBYTE

x='a one and a two'
[[ "${x//~(E)\<.\>/}" == ' one and two' ]] || err_exit "\< and \> not working in with ere's"

Expand Down
6 changes: 3 additions & 3 deletions src/cmd/ksh93/tests/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ actual=$(
(
echo ${.sh.subshell} | cat # left element of pipe should increase ${.sh.subshell}
echo ${.sh.subshell}
ulimit -t unlimited # fork
ulimit -t unlimited 2>/dev/null # fork
echo ${.sh.subshell} # should be same after forking existing virtual subshell
)
echo ${.sh.subshell} # a background job should also increase ${.sh.subshell}
Expand All @@ -730,7 +730,7 @@ set --

unset r v x
(
ulimit -t unlimited # TODO: this test messes up LINENO past the subshell unless we fork it
ulimit -t unlimited 2>/dev/null # TODO: this test messes up LINENO past the subshell unless we fork it
x=foo
for v in EDITOR VISUAL OPTIND CDPATH FPATH PATH ENV RANDOM SECONDS _ LINENO
do nameref r=$v
Expand Down Expand Up @@ -1082,7 +1082,7 @@ $SHELL -c '
# ======
# ${.sh.pid} should be the forked subshell's PID
(
ulimit -t unlimited
ulimit -t unlimited 2>/dev/null # fork the subshell
[[ ${.sh.pid} == $$ ]]
) && err_exit "\${.sh.pid} is the same as \$$ (both are $$)"

Expand Down

0 comments on commit 5d82004

Please sign in to comment.