From 2a803f5f4caf1cb18937e11c3e9d67ac9f56ac5c Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 1 Nov 2023 09:40:02 -0700 Subject: [PATCH] tests: Stop using squish-pty. squish-pty seems to break easily, so switch to using another way to simulate interactive behavior. This way requires a small source code change to PSPP itself but it should be more portable. Thanks to Friedrich Beckmann for reporting the problem. The problem that Friedrich reported was a hang in the "interactive output appears immediately" test on Debian sid. I couldn't reproduce that problem on Fedora or Debian testing, but I did get failures on Debian testing. I guess it's best to just avoid ptys at all. --- src/ui/terminal/main.c | 13 ++++++++++++- tests/atlocal.in | 3 +++ tests/automake.mk | 1 - tests/output/journal.at | 3 +-- tests/testsuite.in | 17 ----------------- tests/ui/terminal/main.at | 3 +-- tests/ui/terminal/squish-pty.py | 26 -------------------------- 7 files changed, 17 insertions(+), 49 deletions(-) delete mode 100644 tests/ui/terminal/squish-pty.py diff --git a/src/ui/terminal/main.c b/src/ui/terminal/main.c index 95b8894bab..dbb73a0520 100644 --- a/src/ui/terminal/main.c +++ b/src/ui/terminal/main.c @@ -255,7 +255,18 @@ add_syntax_reader (struct lexer *lexer, const char *file_name, { struct lex_reader *reader; - reader = (!strcmp (file_name, "-") && isatty (STDIN_FILENO) + bool interactive; + if (!strcmp (file_name, "-")) + { + /* This allows the testsuite to simulate interactive behavior by setting + PSPP_INTERACTIVE=1 in the environment. */ + const char *env = getenv ("PSPP_INTERACTIVE"); + interactive = env ? strcmp (env, "0") : isatty (STDIN_FILENO); + } + else + interactive = false; + + reader = (interactive ? terminal_reader_create () : lex_reader_for_file (file_name, encoding, syntax_mode, LEX_ERROR_CONTINUE)); diff --git a/tests/atlocal.in b/tests/atlocal.in index 4170feda33..81260ec793 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -89,3 +89,6 @@ export LSAN_OPTIONS # Avoid complaints if the system doesn't have a configured paper size. export PAPERSIZE=a4 + +# Make PSPP ignore whether stdin is a tty. +export PSPP_INTERACTIVE=0 diff --git a/tests/automake.mk b/tests/automake.mk index 31634ff933..eb5698738d 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -315,7 +315,6 @@ EXTRA_DIST += \ tests/language/commands/readnames.ods \ tests/language/commands/nhtsa.sav \ tests/language/commands/llz.zsav \ - tests/ui/terminal/squish-pty.py \ tests/utilities/regress.spv CLEANFILES += *.save pspp.* foo* diff --git a/tests/output/journal.at b/tests/output/journal.at index 07247bd50c..91e5fcf05a 100644 --- a/tests/output/journal.at +++ b/tests/output/journal.at @@ -38,9 +38,8 @@ AT_CHECK([test ! -e pspp/pspp.jnl]) AT_CLEANUP AT_SETUP([journal enabled by default interactively]) -AT_SKIP_IF([test "$SQUISH_PTY" = no]) AT_CHECK([echo 'data list notable /x y 1-2. -finish.' | XDG_STATE_HOME=$PWD $SQUISH_PTY pspp], [0], [ignore]) +finish.' | XDG_STATE_HOME=$PWD PSPP_INTERACTIVE=1 pspp], [0], [ignore]) AT_CHECK([sed 's/New session at .*/New session./' pspp/pspp.jnl], [0], [dnl * New session. data list notable /x y 1-2. diff --git a/tests/testsuite.in b/tests/testsuite.in index 08390d01bd..43d8ce4ccb 100644 --- a/tests/testsuite.in +++ b/tests/testsuite.in @@ -63,20 +63,3 @@ if test X"$RUNNER" != X; then PATH=$wrapper_dir:$PATH fi ]) - -m4_divert_text([PREPARE_TESTS], [dnl -dnl ptys are pretty system-dependent and it's hard to test them -dnl everywhere. For example, on Mac OS the SHOW N and FINISH command -dnl text doesn't appear in the output. So we'll just skip them -dnl other than on the OS we know best. -AS_CASE([$host], - [*-linux*], - [dnl Make sure that squish-pty works. - SQUISH_PTY="$PYTHON3 $abs_top_srcdir/tests/ui/terminal/squish-pty.py" - if $SQUISH_PTY true /dev/null 2>/dev/null; then - : - else - SQUISH_PTY=no - fi], - [SQUISH_PTY=no]) -]) diff --git a/tests/ui/terminal/main.at b/tests/ui/terminal/main.at index 254a5ac6d8..8a692017b7 100644 --- a/tests/ui/terminal/main.at +++ b/tests/ui/terminal/main.at @@ -74,11 +74,10 @@ dnl Bug #63910 reported that command output was delayed until the dnl next command was supplied. This checks for regression against dnl that bug. AT_SETUP([interactive output appears immediately]) -AT_SKIP_IF([test "$SQUISH_PTY" = no]) dnl The crucial thing to notice below is that the SHOW output dnl must appear before the prompt for FINISH. AT_CHECK([echo 'SHOW N. -FINISH.' | $SQUISH_PTY pspp], [0], [stdout]) +FINISH.' | PSPP_INTERACTIVE=1 pspp], [0], [stdout]) AT_CHECK([sed -n 's/ $// /^PSPP>/,$p' stdout], [0], [dnl PSPP> SHOW N. diff --git a/tests/ui/terminal/squish-pty.py b/tests/ui/terminal/squish-pty.py deleted file mode 100644 index 1f0f2b1b41..0000000000 --- a/tests/ui/terminal/squish-pty.py +++ /dev/null @@ -1,26 +0,0 @@ -#! /usr/bin/python3 -import os -import pty -import signal -import sys - -def main(args): - if len(args) < 2: - sys.stderr.write('''\ -usage: squish-pty COMMAND [ARG]... -Squishes both stdin and stdout into a single pseudoterminal and -passes it as stdin and stdout to the specified COMMAND. -''') - return 1 - - status = pty.spawn(args[1:]) - if os.WIFEXITED(status): - return os.WEXITSTATUS(status) - elif os.WIFSIGNALED(status): - signal.raise_signal(os.WTERMSIG(status)) - else: - assert False - -if __name__ == '__main__': - sys.exit(main(sys.argv)) - -- 2.30.2