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

shtests: Stop requiring a tty

It is desirable to be able to run the tests on a system without
a functioning tty. Since this distribution comes with its own
pseudo-tty facility, pty, it should be possible to run the few
tests that require a tty on the pseudo-tty instead. I've verified
that they fail as expected on older ksh93.

Discussion: https://github.com/ksh93/ksh/pull/171

src/cmd/ksh93/tests/basic.sh,
src/cmd/ksh93/tests/bracket.sh:
- Remove tests that require a tty.

src/cmd/ksh93/tests/pty.sh:
- Put them here, adapted to work as interactive pty scripts.

src/cmd/ksh93/tests/shtests:
- No longer refuse to run if there is no functioning tty.

.github/workflows/ci.yml:
- Since the tests no longer require a tty, no longer use script(1)
  to get a pseudo-tty. Let's see if this works...
- Re-enable the Mac runner (re: 14632361). Maybe it has improved.
This commit is contained in:
Martijn Dekker 2021-02-13 05:44:23 +00:00
parent a7121b6689
commit 5c389035d8
5 changed files with 104 additions and 61 deletions

View file

@ -14,19 +14,46 @@ jobs:
run: bin/package make
- name: Regression tests
run: |
PS4="$PS4 [ci.yml] "
PS4="$PS4[ci.yml] "
set -o xtrace
export TZ=UTC
ulimit -n 1024
: default regression tests &&
script -q -e -c "bin/shtests" &&
bin/shtests &&
: regression tests with OS-provided UTF-8 locales &&
LANG=nl_NL.UTF-8 script -q -e -c "bin/shtests --locale --nocompile" &&
LANG=ja_JP.UTF-8 script -q -e -c "bin/shtests --locale --nocompile" &&
LANG=nl_NL.UTF-8 bin/shtests --locale --nocompile &&
LANG=ja_JP.UTF-8 bin/shtests --locale --nocompile &&
: disable most SHOPTs, rebuild ksh &&
sed --regexp-extended --in-place=.orig \
'/^SHOPT (2DMATCH|AUDIT|BGX|BRACEPAT|DYNAMIC|EDPREDICT|ESH|FIXEDARRAY|HISTEXPAND|MULTIBYTE|NAMESPACE|OPTIMIZE|SUID_EXEC|STATS|VSH)=/ s/=1/=0/' \
src/cmd/ksh93/SHOPT.sh &&
bin/package make &&
: default regression tests with SHOPTs disabled &&
script -q -e -c "bin/shtests"
bin/shtests
MacOS:
name: macOS
runs-on: macos-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Build
run: bin/package make
- name: Regression tests
run: |
PS4="$PS4[ci.yml] "
set -o xtrace
export TZ=UTC
ulimit -n 1024
: default regression tests &&
bin/shtests &&
: regression tests with OS-provided UTF-8 locales &&
LANG=nl_NL.UTF-8 bin/shtests --locale --nocompile &&
LANG=ja_JP.UTF-8 bin/shtests --locale --nocompile &&
: disable most SHOPTs, rebuild ksh &&
sed -E -i.orig \
'/^SHOPT (2DMATCH|AUDIT|BGX|BRACEPAT|DYNAMIC|EDPREDICT|ESH|FIXEDARRAY|HISTEXPAND|MULTIBYTE|NAMESPACE|OPTIMIZE|SUID_EXEC|STATS|VSH)=/ s/=1/=0/' \
src/cmd/ksh93/SHOPT.sh &&
bin/package make &&
: default regression tests with SHOPTs disabled &&
bin/shtests

View file

@ -667,21 +667,6 @@ eu=$(
)
[[ ${us:1:1} == ${eu:1:1} ]] && err_exit "The time keyword ignores the locale's radix point (both are ${eu:1:1})"
# ======
# Test for bug in ksh binaries that use posix_spawn() while job control is active.
# See discussion at: https://github.com/ksh93/ksh/issues/79
actual=$(
"$SHELL" -i <<-\EOF 2>/dev/tty
printf '%s\n' 1 2 3 4 5 | while read
do ls /dev/null
done 2>&1
exit # suppress extra newline
EOF
)
expect=$'/dev/null\n/dev/null\n/dev/null\n/dev/null\n/dev/null'
[[ $actual == "$expect" ]] || err_exit 'Race condition while launching external commands' \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
# ======
# Expansion of multibyte characters after expansion of single-character names $1..$9, $?, $!, $-, etc.
function exptest

View file

@ -309,10 +309,6 @@ do if [[ ! $locales == *$'\n'"${l}"$'\n'* ]] ||
done
done
done
integer n
if ( : < /dev/tty ) 2>/dev/null && exec {n}< /dev/tty
then [[ -t $n ]] || err_exit "[[ -t n ]] fails when n > 9"
fi
foo=([1]=a [2]=b [3]=c)
[[ -v foo[1] ]] || err_exit 'foo[1] should be set'
[[ ${foo[1]+x} ]] || err_exit '${foo[1]+x} should be x'
@ -369,37 +365,6 @@ test ! ! x 2> /dev/null || err_exit 'test ! ! x should return 0'
test ! ! '' 2> /dev/null && err_exit 'test ! ! "" should return non-zero'
# ======
# Verify that [ -t 1 ] behaves sensibly inside a command substitution.
# This is the simple case that doesn't do any redirection of stdout within the command
# substitution. Thus the [ -t 1 ] test should be false.
expect=$'begin\nend'
actual=$(echo begin; [ -t 1 ] || test -t 1 || [[ -t 1 ]] && echo -t 1 is true; echo end)
[[ $actual == "$expect" ]] || err_exit 'test -t 1 in comsub fails' \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
actual=$(echo begin; [ -n X -a -t 1 ] || test -n X -a -t 1 || [[ -n X && -t 1 ]] && echo -t 1 is true; echo end)
[[ $actual == "$expect" ]] || err_exit 'test -t 1 in comsub fails (compound expression)' \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
# Same for the ancient compatibility hack for 'test -t' with no arguments.
actual=$(echo begin; [ -t ] || test -t && echo -t is true; echo end)
[[ $actual == "$expect" ]] || err_exit 'test -t in comsub fails' \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
actual=$(echo begin; [ -n X -a -t ] || test -n X -a -t && echo -t is true; echo end)
[[ $actual == "$expect" ]] || err_exit 'test -t in comsub fails (compound expression)' \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
# This is the more complex case that does redirect stdout within the command substitution to the
# actual tty. Thus the [ -t 1 ] test should be true.
actual=$(echo begin; exec >/dev/tty; [ -t 1 ] && test -t 1 && [[ -t 1 ]]) \
|| err_exit 'test -t 1 in comsub with exec >/dev/tty fails'
actual=$(echo begin; exec >/dev/tty; [ -n X -a -t 1 ] && test -n X -a -t 1 && [[ -n X && -t 1 ]]) \
|| err_exit 'test -t 1 in comsub with exec >/dev/tty fails (compound expression)'
# Same for the ancient compatibility hack for 'test -t' with no arguments.
actual=$(echo begin; exec >/dev/tty; [ -t ] && test -t) \
|| err_exit 'test -t in comsub with exec >/dev/tty fails'
actual=$(echo begin; exec >/dev/tty; [ -n X -a -t ] && test -n X -a -t) \
|| err_exit 'test -t in comsub with exec >/dev/tty fails (compound expression)'
# The POSIX mode should disable the ancient 'test -t' compatibility hack.
if [[ -o ?posix ]]
then # need 'eval' in first test, as it's a parser hack, and ksh normally parses ahead of execution

View file

@ -564,5 +564,77 @@ w set -b; sleep .01 &
u Done
!
# err_exit #
# Tests for 'test -t'. These were moved here from bracket.sh because they require a tty.
cat >test_t.sh <<"EOF"
integer n
redirect {n}< /dev/tty
[[ -t $n ]] && echo OK0 || echo "[[ -t n ]] fails when n > 9"
# _____ Verify that [ -t 1 ] behaves sensibly inside a command substitution.
# This is the simple case that doesn't do any redirection of stdout within
# the command substitution. Thus the [ -t 1 ] test should be false.
expect=$'begin\nend'
actual=$(echo begin; [ -t 1 ] || test -t 1 || [[ -t 1 ]] && echo -t 1 is true; echo end)
[[ $actual == "$expect" ]] && echo OK1 || echo 'test -t 1 in comsub fails' \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
actual=$(echo begin; [ -n X -a -t 1 ] || test -n X -a -t 1 || [[ -n X && -t 1 ]] && echo -t 1 is true; echo end)
[[ $actual == "$expect" ]] && echo OK2 || echo 'test -t 1 in comsub fails (compound expression)' \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
# Same for the ancient compatibility hack for 'test -t' with no arguments.
actual=$(echo begin; [ -t ] || test -t && echo -t is true; echo end)
[[ $actual == "$expect" ]] && echo OK3 || echo 'test -t in comsub fails' \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
actual=$(echo begin; [ -n X -a -t ] || test -n X -a -t && echo -t is true; echo end)
[[ $actual == "$expect" ]] && echo OK4 || echo 'test -t in comsub fails (compound expression)' \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
# This is the more complex case that does redirect stdout within the command
# substitution to the actual tty. Thus the [ -t 1 ] test should be true.
actual=$(echo begin; exec >/dev/tty; [ -t 1 ] && test -t 1 && [[ -t 1 ]]) \
&& echo OK5 || echo 'test -t 1 in comsub with exec >/dev/tty fails'
actual=$(echo begin; exec >/dev/tty; [ -n X -a -t 1 ] && test -n X -a -t 1 && [[ -n X && -t 1 ]]) \
&& echo OK6 || echo 'test -t 1 in comsub with exec >/dev/tty fails (compound expression)'
# Same for the ancient compatibility hack for 'test -t' with no arguments.
actual=$(echo begin; exec >/dev/tty; [ -t ] && test -t) \
&& echo OK7 || echo 'test -t in comsub with exec >/dev/tty fails'
actual=$(echo begin; exec >/dev/tty; [ -n X -a -t ] && test -n X -a -t) \
&& echo OK8 || echo 'test -t in comsub with exec >/dev/tty fails (compound expression)'
EOF
tst $LINENO <<"!"
L test -t 1 inside command substitution
p :test-1:
w . ./test_t.sh
r ^:test-1: \. \./test_t\.sh\r\n$
r ^\. \./test_t\.sh\r\n$
r ^OK0\r\n$
r ^OK1\r\n$
r ^OK2\r\n$
r ^OK3\r\n$
r ^OK4\r\n$
r ^OK5\r\n$
r ^OK6\r\n$
r ^OK7\r\n$
r ^OK8\r\n$
r ^:test-2:
!
# err_exit #
tst $LINENO <<"!"
L race condition while launching external commands
# Test for bug in ksh binaries that use posix_spawn() while job control is active.
# See discussion at: https://github.com/ksh93/ksh/issues/79
p :test-1:
w printf '%s\\n' 1 2 3 4 5 | while read; do ls /dev/null; done
r ^:test-1: printf '%s\\n' 1 2 3 4 5 | while read; do ls /dev/null; done\r\n$
r ^printf '%s\\n' 1 2 3 4 5 | while read; do ls /dev/null; done\r\n$
r ^/dev/null\r\n$
r ^/dev/null\r\n$
r ^/dev/null\r\n$
r ^/dev/null\r\n$
r ^/dev/null\r\n$
r ^:test-2:
!
# ======
exit $((Errors<125?Errors:125))

View file

@ -168,12 +168,6 @@ function valxml
return $errors
}
if ! test -t 1 2>/dev/null 1>/dev/tty
then print "The regression tests require a functioning /dev/tty." >&2
print "If not available, try script(1) to simulate a tty." >&2
exit 128
fi
command set +o posix 2>/dev/null
unset DISPLAY FIGNORE HISTFILE POSIXLY_CORRECT _AST_FEATURES
export ENV=/./dev/null