1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

tests/variables.sh: fix problems with tracing ('bin/shtests -x')

src/cmd/ksh93/tests/variables.sh:
- Unset -x in a command substitution that redirects stderr to
  stdout; this caused a spurious failure with tracing active.
- Execute the nameref tests in a subshell. They modified LINENO, so
  that all the line numbers after this test were traced and/or
  reported as 'foo'.
  . This exposed a bug in namerefs: this is yet another thing that
    is broken in non-forked/virtual subshells! That is for another
    commit. For now, fork the subshell and leave a TODO.

(cherry picked from commit 8b7f8f9b14523a66bdf337612daef2501c2bb5ba)
This commit is contained in:
Martijn Dekker 2020-06-04 03:42:15 +02:00
parent 80126062cc
commit a9351320ed

View file

@ -474,7 +474,7 @@ chmod +x $tmp/script
(( .sh.subshell == 1 )) || err_exit ".sh.subshell not working in a subshell"
)
TIMEFORMAT='this is a test'
[[ $({ { time :;} 2>&1;}) == "$TIMEFORMAT" ]] || err_exit 'TIMEFORMAT not working'
[[ $(set +x; { { time :;} 2>&1;}) == "$TIMEFORMAT" ]] || err_exit 'TIMEFORMAT not working'
: ${.sh.version}
[[ $(alias integer) == *.sh.* ]] && err_exit '.sh. prefixed to alias name'
: ${.sh.version}
@ -541,6 +541,8 @@ esac
}
} 2> /dev/null || err_exit "cannot add get discipline to .sh.foobar"
[[ ${.sh.foobar} == world ]] || err_exit 'get discipline for .sh.foobar not working'
[[ -o xtrace ]] && opt_x=-x || opt_x=+x
x='a|b'
IFS='|'
set -- $x
@ -548,10 +550,11 @@ set -- $x
exec 3>&2 2> /dev/null
set -x
( IFS= ) 2> /dev/null
set +x
set "$opt_x"
exec 2>&3-
set -- $x
[[ $2 == b ]] || err_exit '$2 should be b after subshell'
: & pid=$!
( : & )
[[ $pid == $! ]] || err_exit '$! value not preserved across subshells'
@ -616,8 +619,12 @@ set -- {1..32768}
(( $# == 32768 )) || err_exit "\$# failed -- expected 32768, got $#"
set --
(
# TODO: namerefs are broken in non-forked/virtual subshells.
# For now, fork it using ulimit; remove the ulimit to expose the test failures.
ulimit -t unlimited
unset r v x
path=$PATH
x=foo
for v in EDITOR VISUAL OPTIND CDPATH FPATH PATH ENV LINENO RANDOM SECONDS _
do nameref r=$v
@ -642,7 +649,10 @@ do nameref r=$v
{ g=$( r=C; r=$x; print -- $r ); } 2>/dev/null
[[ $g == 'C' ]] || err_exit "$v=C; $v=$x failed -- expected 'C', got '$g'"
done
PATH=$path
exit $Errors
)
Errors=$? # in case of failures, ensure error count survives subshell
cd $tmp