tests: Stop using squish-pty.
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 1 Nov 2023 16:40:02 +0000 (09:40 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 1 Nov 2023 16:40:02 +0000 (09:40 -0700)
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
tests/atlocal.in
tests/automake.mk
tests/output/journal.at
tests/testsuite.in
tests/ui/terminal/main.at
tests/ui/terminal/squish-pty.py [deleted file]

index 95b8894bab22c80ca47711a12bea41743c21b8e2..dbb73a0520a99c693a08c5c506badd6aee9c2581 100644 (file)
@@ -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));
index 4170feda3337d2e76b4fa23cc380e6d443394c15..81260ec793b73ec3a9a898c30d0477d23e9f8d2e 100644 (file)
@@ -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
index 31634ff9336337dbc8774d5e232d45cab48955d5..eb5698738de942792af1a291d1303ccbfa5786aa 100644 (file)
@@ -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*
index 07247bd50cc4aeee0f0c6e4f93277e761afbb1e5..91e5fcf05a0493ad062e956b0a1a70055efc4cab 100644 (file)
@@ -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.
index 08390d01bdc6dd31be760db73521b657dd645b89..43d8ce4ccb94b816b9a27c06e20bd6bd8ed8168b 100644 (file)
@@ -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 >/dev/null 2>/dev/null; then
-       :
-   else
-       SQUISH_PTY=no
-   fi],
-  [SQUISH_PTY=no])
-])
index 254a5ac6d83bf82582b6628e6522cb202100e584..8a692017b7a4ae217af73937ff18b3e5692d3176 100644 (file)
@@ -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/\r$//
 /^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 (file)
index 1f0f2b1..0000000
+++ /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))
-