From 2c04a88b37ba47b8ca7fa834bdad386aaf36aac6 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sat, 13 Feb 2021 00:29:19 +0000 Subject: [PATCH] shtests: actually test /dev/tty instead of checking for existence The GitHub runners apparently provide a non-working /dev/tty. To avoid failures and confusion, shtests shold refuse to run the tests and tell people to use script(1) to simulate a tty. On Linux, it goes like this: script -q -e -c 'bin/shtests --your-options-here' On macOS and FreeBSD, the invocation is: script -q /dev/null bin/shtests --your-options-here The NetBSD and OpenBSD variants of script(1) need different invocations again. They also don't pass down the command's exit status, so would need a workaround for that. It would be nice if we could use pty for this as this comes with the distribution, so would work the same on every OS, but it seems to be broken for this use case. src/cmd/ksh93/tests/shtest: - Use 'test -t 1' with stdout (fd 1) redirected to /dev/tty to ensure the tty is actually on a terminal. src/cmd/ksh93/tests/basic.sh: - Remove superflous check for tty. All tests run through shtests. Resolves: https://github.com/ksh93/ksh/pull/171 --- src/cmd/ksh93/tests/basic.sh | 24 +++++++++++------------- src/cmd/ksh93/tests/shtests | 2 +- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/cmd/ksh93/tests/basic.sh b/src/cmd/ksh93/tests/basic.sh index 552e8f015..adfcc2371 100755 --- a/src/cmd/ksh93/tests/basic.sh +++ b/src/cmd/ksh93/tests/basic.sh @@ -670,19 +670,17 @@ eu=$( # ====== # 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 -if test -t 1 2>/dev/null 1>/dev/tty # this test only works if we have a tty -then 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"))" -fi +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. diff --git a/src/cmd/ksh93/tests/shtests b/src/cmd/ksh93/tests/shtests index 76e4660f5..7bbf58dd3 100755 --- a/src/cmd/ksh93/tests/shtests +++ b/src/cmd/ksh93/tests/shtests @@ -168,7 +168,7 @@ function valxml return $errors } -if [[ ! -c /dev/tty || ! -w /dev/tty ]] +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