From ec0155ee65bd5faa6a59e9043516f5e29dff90d8 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Wed, 20 Jan 2021 05:38:55 +0000 Subject: [PATCH] tests/variables.sh: tweaks for special and locale variable tests src/cmd/ksh93/tests/variables.sh: - Fork the subshell with the test that includes unsetting LINENO and changing its type. Otherwise, some side effect of that leaks out of the subshell, messing up $LINENO. This is a bug, but it's low priority -- we may get to it someday. Marked with a TODO. - Do the LC_* tests in their own subshell. Skip them if changing LANG to an invalid value does not produce a diagnostic message. This occurs on OpenBSD and Alpine Linux (with musl libc). It looks like their C libraries do not verify the locale, so failures here are not a ksh problem; skip the tests in that case. --- src/cmd/ksh93/tests/variables.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cmd/ksh93/tests/variables.sh b/src/cmd/ksh93/tests/variables.sh index 428738791..2fe924da6 100755 --- a/src/cmd/ksh93/tests/variables.sh +++ b/src/cmd/ksh93/tests/variables.sh @@ -721,10 +721,11 @@ set -- {1..32768} (( $# == 32768 )) || err_exit "\$# failed -- expected 32768, got $#" set -- +unset r v x ( - unset r v x + ulimit -t unlimited # 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 LINENO RANDOM SECONDS _ + for v in EDITOR VISUAL OPTIND CDPATH FPATH PATH ENV RANDOM SECONDS _ LINENO do nameref r=$v unset $v if ( $SHELL -c "unset $v; : \$$v" ) 2>/dev/null @@ -734,7 +735,15 @@ set -- else err_exit "unset $v; : \$$v failed" fi done - + exit $Errors +) +Errors=$? # ensure error count survives subshell +( + errmsg=$({ LANG=bad_LOCALE; } 2>&1) + if [[ -z $errmsg ]] + then print -u2 -r "${Command}[$LINENO]: warning: C library does not seem to verify locales: skipping LC_* tests" + exit $Errors + fi x=x for v in LC_ALL LC_CTYPE LC_MESSAGES LC_COLLATE LC_NUMERIC do nameref r=$v @@ -747,7 +756,6 @@ set -- { g=$( r=C; r=$x; print -- $r ); } 2>/dev/null [[ $g == 'C' ]] || err_exit "$v=C; $v=$x failed -- expected 'C', got '$g'" done - exit $Errors ) Errors=$? # ensure error count survives subshell