mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 11:42:21 +00:00
Fix xtrace (shtests -x) for the regression tests
src/cmd/ksh93/tests/{shtests,_common}: - When xtrace is active, set SECONDS to the float type so that the $SECONDS expansion in $PS4 shows fractional seconds. src/cmd/ksh93/tests/*.sh: - Various fixes to avoid command substitutions incorporating xtrace output into their results. Sometimes this is done by avoiding a preceding assignment on a command that redirects 2>&1 (as that will also redirect the preceding assignment and its xtrace, causing the command substitution to capture the xtrace); other times it was easiest to just turn off xtrace outright within the command substitution. src/cmd/ksh93/tests/math.sh: - Remove an obsolete 'fixme' note.
This commit is contained in:
parent
16080141c5
commit
c59d888394
11 changed files with 38 additions and 21 deletions
|
@ -30,6 +30,11 @@ alias warning='_message "$LINENO" "warning:"'
|
|||
Command=${0##*/}
|
||||
integer Errors=0
|
||||
|
||||
if [[ -o xtrace ]]
|
||||
then # PS4 is set and exported in shtests
|
||||
typeset -F SECONDS # show fractional seconds in xtrace output
|
||||
fi
|
||||
|
||||
if ! [[ -d $tmp && -w $tmp && $tmp == "$PWD" ]]
|
||||
then print -r "$Command: \$tmp not set; run this from shtests. Aborting." >&2
|
||||
exit 1
|
||||
|
|
|
@ -772,9 +772,9 @@ v=$(printf $'%.28a\n' 64)
|
|||
# https://github.com/ksh93/ksh/issues/152
|
||||
|
||||
exp='array_test_1: 1$(echo INJECTION >&2): arithmetic syntax error'
|
||||
got=$(var='1$(echo INJECTION >&2)' "$SHELL" -c 'typeset -a a; ((a[$var]++)); typeset -p a' array_test_1 2>&1)
|
||||
got=$(set +x; var='1$(echo INJECTION >&2)' "$SHELL" -c 'typeset -a a; ((a[$var]++)); typeset -p a' array_test_1 2>&1)
|
||||
[[ $got == "$exp" ]] || err_exit "Array subscript quoting test 1A: expected $(printf %q "$exp"), got $(printf %q "$got")"
|
||||
got=$(var='1$(echo INJECTION >&2)' "$SHELL" -c 'typeset -a a; ((a["$var"]++)); typeset -p a' array_test_1 2>&1)
|
||||
got=$(set +x; var='1$(echo INJECTION >&2)' "$SHELL" -c 'typeset -a a; ((a["$var"]++)); typeset -p a' array_test_1 2>&1)
|
||||
[[ $got == "$exp" ]] || err_exit "Array subscript quoting test 1B: expected $(printf %q "$exp"), got $(printf %q "$got")"
|
||||
|
||||
exp='typeset -A a=(['\''1$(echo INJECTION >&2)'\'']=1)'
|
||||
|
@ -836,6 +836,7 @@ fi
|
|||
integer loopcount=maxlevel+10
|
||||
got=$(
|
||||
typeset -r -A -i ro_arr=([a]=10 [b]=20 [c]=30)
|
||||
set +x
|
||||
for ((i=0; i<loopcount; i++)); do
|
||||
let "ro_arr[i+1] += 5"
|
||||
done 2>&1
|
||||
|
@ -843,6 +844,7 @@ got=$(
|
|||
[[ $got == *recursion* ]] && err_exit "recursion level not reset on readonly error (main shell)"
|
||||
got=$(
|
||||
typeset -r -A -i ro_arr=([a]=10 [b]=20 [c]=30)
|
||||
set +x
|
||||
for ((i=0; i<loopcount; i++)); do
|
||||
( ((ro_arr[i+1] += 5)) )
|
||||
done 2>&1
|
||||
|
|
|
@ -539,6 +539,7 @@ typeset -A expect=(
|
|||
for flag in "${!expect[@]}"
|
||||
do unset foo
|
||||
actual=$(
|
||||
set +x
|
||||
redirect 2>&1
|
||||
export foo
|
||||
(typeset "-$flag" foo; readonly foo; typeset -p foo)
|
||||
|
@ -616,6 +617,7 @@ typeset -A expect=(
|
|||
for flag in "${!expect[@]}"
|
||||
do unset a
|
||||
actual=$(
|
||||
set +x
|
||||
redirect 2>&1
|
||||
(typeset "-$flag" a=2; typeset -p a)
|
||||
leak=${ typeset -p a; }
|
||||
|
|
|
@ -667,7 +667,7 @@ got=$(eval 'x=`for i in test; do case $i in test) true;; esac; done`' 2>&1) \
|
|||
|
||||
# Redirecting disabled the DEBUG trap
|
||||
exp=$'LINENO: 4\nfoo\nLINENO: 5\nLINENO: 6\nbar\nLINENO: 7\nbaz'
|
||||
got=$({ "$SHELL" -c '
|
||||
got=$(set +x; { "$SHELL" -c '
|
||||
PATH=/dev/null
|
||||
trap "echo LINENO: \$LINENO >&1" DEBUG # 3
|
||||
echo foo # 4
|
||||
|
@ -680,7 +680,7 @@ got=$({ "$SHELL" -c '
|
|||
|
||||
# The DEBUG trap crashed when re-trapping inside a subshell
|
||||
exp=$'trap -- \': main\' EXIT\ntrap -- \': main\' ERR\ntrap -- \': main\' KEYBD\ntrap -- \': main\' DEBUG'
|
||||
got=$({ "$SHELL" -c '
|
||||
got=$(set +x; { "$SHELL" -c '
|
||||
PATH=/dev/null
|
||||
for sig in EXIT ERR KEYBD DEBUG
|
||||
do trap ": main" $sig
|
||||
|
@ -694,7 +694,7 @@ got=$({ "$SHELL" -c '
|
|||
|
||||
# Field splitting broke upon evaluating an unquoted expansion in a DEBUG trap
|
||||
exp=$'a\nb\nc'
|
||||
got=$({ "$SHELL" -c '
|
||||
got=$(set +x; { "$SHELL" -c '
|
||||
PATH=/dev/null
|
||||
v=""
|
||||
trap ": \$v" DEBUG
|
||||
|
|
|
@ -385,9 +385,13 @@ error=$(set +x; "$SHELL" -c '[[ AATAATCCCAATAAT =~ (AAT){2}CCC(AAT){2} ]]' 2>&1)
|
|||
# ======
|
||||
# The -v unary operator should work for names with all type attributes.
|
||||
empty=
|
||||
unset unset
|
||||
for flag in a b i l n s si u ui usi uli E F H L Mtolower Mtoupper R X lX S Z
|
||||
do unset var
|
||||
typeset "-$flag" var
|
||||
case $flag in
|
||||
n) typeset -n var=unset ;;
|
||||
*) typeset "-$flag" var ;;
|
||||
esac
|
||||
[[ -v var ]] && err_exit "[[ -v var ]] should be false for unset var with attribute -$flag"
|
||||
[[ -n ${var+s} ]] && err_exit "[[ -n \${var+s} ]] should be false for unset var with attribute -$flag"
|
||||
unset var
|
||||
|
|
|
@ -722,6 +722,7 @@ read baz <<< 'foo\\\\bar'
|
|||
# ======
|
||||
# Check that I/O errors are detected <https://github.com/att/ast/issues/1093>
|
||||
actual=$(
|
||||
set +x
|
||||
{
|
||||
(
|
||||
trap "" PIPE
|
||||
|
@ -1239,10 +1240,10 @@ then exp=' version cat (*) ????-??-??'
|
|||
got=$(PATH=/opt/ast/bin:$PATH; "${ whence -p cat; }" --version 2>&1)
|
||||
[[ $got == $exp ]] || err_exit "path-bound builtin not executable by canonical path resulting from expansion" \
|
||||
"(expected match of $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
got=$(PATH=/opt/ast/bin:$PATH "$SHELL" -o restricted -c 'cat --version' 2>&1)
|
||||
got=$(PATH=/opt/ast/bin:$PATH; "$SHELL" -o restricted -c 'cat --version' 2>&1)
|
||||
[[ $got == $exp ]] || err_exit "restricted shells do not recognize path-bound builtins" \
|
||||
"(expected match of $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
got=$(PATH=/opt/ast/bin cat --version 2>&1)
|
||||
got=$(set +x; PATH=/opt/ast/bin cat --version 2>&1)
|
||||
[[ $got == $exp ]] || err_exit "path-bound builtin not found on PATH in preceding assignment" \
|
||||
"(expected match of $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
else warning 'skipping path-bound builtin tests: builtin /opt/ast/bin/cat not found'
|
||||
|
|
|
@ -23,8 +23,14 @@
|
|||
|
||||
set -o nounset
|
||||
|
||||
# ksh functions reset xtrace; remember it to re-enable it
|
||||
typeset -si xtrace=0
|
||||
[[ -o xtrace ]] && ((xtrace++))
|
||||
|
||||
function test_arithmetric_expression_accesss_array_element_through_nameref
|
||||
{
|
||||
((xtrace)) && set -x
|
||||
|
||||
compound out=( typeset stdout stderr ; integer res )
|
||||
compound -r -a tests=(
|
||||
(
|
||||
|
@ -62,12 +68,6 @@ function test_arithmetric_expression_accesss_array_element_through_nameref
|
|||
typeset cmd
|
||||
|
||||
for (( i=0 ; i < ${#tests[@]} ; i++ )) ; do
|
||||
# fixme: This list should include "typeset -lX" and "typeset -X" but ast-ksh.2010-03-09 fails like this:
|
||||
# 'typeset -X -a z ; z[1][3]=90 ; function x { nameref nz=$1 ; print " $(( nz ))==$(( $nz ))" ; } ; x z[1][3]'
|
||||
# + typeset -X -a z
|
||||
# + z[1][3]=90
|
||||
# + x 'z[1][3]'
|
||||
# /home/test001/bin/ksh[1]: x: line 1: x1.68000000000000000000000000000000p: no parent
|
||||
for ty in \
|
||||
'typeset' \
|
||||
'integer' \
|
||||
|
@ -140,9 +140,9 @@ function test_arithmetric_expression_accesss_array_element_through_nameref
|
|||
esac
|
||||
|
||||
testname="${0}/${cmd}"
|
||||
#set -x
|
||||
((xtrace)) && set +x
|
||||
out.stderr="${ { out.stdout="${ ${SHELL} -o nounset -o errexit -c "${cmd}" ; (( out.res=$? )) ; }" ; } 2>&1 ; }"
|
||||
#set +x
|
||||
((xtrace)) && set -x
|
||||
|
||||
[[ "${out.stdout}" == ${tst.stdoutpattern} ]] || err_exit "${testname}: Expected stdout to match $(printf '%q\n' "${tst.stdoutpattern}"), got $(printf '%q\n' "${out.stdout}")"
|
||||
[[ "${out.stderr}" == '' ]] || err_exit "${testname}: Expected empty stderr, got $(printf '%q\n' "${out.stderr}")"
|
||||
|
@ -156,6 +156,8 @@ function test_arithmetric_expression_accesss_array_element_through_nameref
|
|||
|
||||
function test_has_iszero
|
||||
{
|
||||
((xtrace)) && set -x
|
||||
|
||||
typeset str
|
||||
integer i
|
||||
|
||||
|
|
|
@ -452,7 +452,7 @@ PATH=$PATH_orig
|
|||
# ======
|
||||
# Check that 'command -p' searches the default OS utility PATH.
|
||||
expect=/dev/null
|
||||
actual=$(PATH=/dev/null "$SHELL" -c 'command -p ls /dev/null' 2>&1)
|
||||
actual=$(set +x; PATH=/dev/null "$SHELL" -c 'command -p ls /dev/null' 2>&1)
|
||||
[[ $actual == "$expect" ]] || err_exit 'command -p fails to find standard utility' \
|
||||
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
|
||||
|
||||
|
|
|
@ -215,6 +215,7 @@ shift $OPTIND-1
|
|||
|
||||
if (( debug )) || [[ $trace ]]
|
||||
then export PS4='+ [${SECONDS:+${SECONDS%????}s|}${.sh.pid:+P${.sh.pid},}${.sh.subshell:+S${.sh.subshell},}${.sh.file:+${.sh.file#${.sh.file%/*/*}/},}${.sh.fun:+${.sh.fun},}${LINENO:+L$LINENO,}e$?] '
|
||||
typeset -F SECONDS # show fractional seconds in xtrace output
|
||||
if (( debug ))
|
||||
then set -x
|
||||
fi
|
||||
|
|
|
@ -454,7 +454,7 @@ echo begin
|
|||
# this extra comment disables an exec optimization
|
||||
EOF
|
||||
expect=$'^begin\n/.*/sigtest.sh: line 2: [1-9][0-9]*: Killed\n[1-9][0-9]{1,2}$'
|
||||
actual=$(LANG=C "$SHELL" -c '"$1" "$2" "$1"; echo "$?"' x "$SHELL" "$tmp/sigtest.sh" 2>&1)
|
||||
actual=$(export LANG=C; "$SHELL" -c '"$1" "$2" "$1"; echo "$?"' x "$SHELL" "$tmp/sigtest.sh" 2>&1)
|
||||
if ! [[ $actual =~ $expect ]]
|
||||
then [[ $actual == *Killed*Killed* ]] && msg='ksh killed itself' || msg='unexpected output'
|
||||
err_exit "$msg after child process signal (expected match to $(printf %q "$expect"); got $(printf %q "$actual"))"
|
||||
|
|
|
@ -929,19 +929,19 @@ cd "$tmp/deleted"
|
|||
tmp=$tmp "$SHELL" -c 'cd /; rmdir "$tmp/deleted"'
|
||||
|
||||
exp="subPWD: ${PWD%/deleted}"$'\n'"mainPWD: $PWD"
|
||||
got=$( { "$SHELL" -c '(subshfn() { bad; }; cd ..; echo "subPWD: $PWD"); typeset -f subshfn; echo "mainPWD: $PWD"'; } 2>&1 )
|
||||
got=$(set +x; { "$SHELL" -c '(subshfn() { bad; }; cd ..; echo "subPWD: $PWD"); typeset -f subshfn; echo "mainPWD: $PWD"'; } 2>&1)
|
||||
[[ $got == "$exp" ]] || err_exit "subshell state not restored after 'cd ..' from deleted PWD" \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
|
||||
exp="PWD=$PWD"
|
||||
got=$( { "$SHELL" -c '(cd /; (cd /)); print -r -- "PWD=$PWD"'; } 2>&1 )
|
||||
got=$(set +x; { "$SHELL" -c '(cd /; (cd /)); print -r -- "PWD=$PWD"'; } 2>&1)
|
||||
((!(e = $?))) && [[ $got == "$exp" ]] || err_exit 'failed to restore nonexistent PWD on exiting a virtual subshell' \
|
||||
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
|
||||
mkdir "$tmp/recreated"
|
||||
cd "$tmp/recreated"
|
||||
tmp=$tmp "$SHELL" -c 'cd /; rmdir "$tmp/recreated"; mkdir "$tmp/recreated"'
|
||||
exp="PWD=$PWD"
|
||||
got=$( { "$SHELL" -c '(cd /); print -r -- "PWD=$PWD"'; } 2>&1 )
|
||||
got=$(set +x; { "$SHELL" -c '(cd /); print -r -- "PWD=$PWD"'; } 2>&1)
|
||||
((!(e = $?))) && [[ $got == "$exp" ]] || err_exit 'failed to restore re-created PWD on exiting a virtual subshell' \
|
||||
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
|
||||
cd "$tmp"
|
||||
|
|
Loading…
Reference in a new issue