Ensure that interactive output appears without a one-command delay.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 18 Mar 2023 18:43:16 +0000 (11:43 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 18 Mar 2023 18:58:56 +0000 (11:58 -0700)
When pspp was run in the text-based mode interactively, output for a given
command only appeared after the next command was read.  This fixes the
problem and adds a test.

Thanks to the anonymous reporter.

Bug #63910.

src/language/command.c
tests/automake.mk
tests/language/commands/define.at
tests/language/commands/split-file.at
tests/output/ascii.at
tests/ui/terminal/main.at
tests/ui/terminal/squish-pty.py [new file with mode: 0644]

index e67f6ab80800352ec1132cdb9d36866c87e63c3f..0c77337695691b5ce6a5316bfe5b2f938261ffd1 100644 (file)
@@ -252,13 +252,13 @@ finish:
     result = lex_end_of_command (lexer);
 
   lex_discard_rest_of_command (lexer);
+  if (nesting_level != SIZE_MAX)
+    output_close_groups (nesting_level);
+
   if (result != CMD_EOF && result != CMD_FINISH)
     while (lex_token (lexer) == T_ENDCMD)
       lex_get (lexer);
 
-  if (nesting_level != SIZE_MAX)
-    output_close_groups (nesting_level);
-
   return result;
 }
 
index 9d9bc8bcc8013cc963eb861d1ee8a8e7bae658c1..e6782b10fc70966ec84bfc77b2dccf68be3487e6 100644 (file)
@@ -314,6 +314,7 @@ 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 2e1a7eebad2fe4678d620290d25f403984c0316d..d4803246c2cfacf081aed98c32a4388bb2fa7935 100644 (file)
@@ -1158,7 +1158,7 @@ define.sps:1-3: inside the expansion of `!macro',
 define.sps:1-3: inside the expansion of `!macro',
 define.sps:1-3: inside the expansion of `!macro',
 define.sps:1-3: inside the expansion of `!macro',
-define.sps:4.1-4.6: error: DEFINE: Maximum nesting level 50 exceeded.  (Use SET MNEST to change the limit.)
+define.sps:4.1-4.6: error: Maximum nesting level 50 exceeded.  (Use SET MNEST to change the limit.)
     4 | !macro.
       | ^~~~~~"
 
index a66671278b6ef2057d70d4337e7e87415beac750..ce12db8de9f89ded941a45da2c5359596333b483 100644 (file)
@@ -168,6 +168,7 @@ SHOW SPLIT.
 AT_CHECK([pspp show.sps -O box=unicode], [0], [dnl
 SET PRINTBACK=ON.
 
+
 SHOW SPLIT.
 
   Settings
index ce000d65fbe1ae8dee620cb07d6555623f877e14..670d311f7ab8fe172d73fbb34e3a47268bfebe6c 100644 (file)
@@ -612,6 +612,7 @@ BEGIN DATA.
 3 33 Three
 END DATA.
 
+
 REGRESSION
 /VARIABLES= a
 
index 29fef65843bebea780e02284364c40e3079618bc..e4f4ced3a32b884756c47d7056600f144cdc041a 100644 (file)
@@ -39,7 +39,6 @@ AT_CHECK([pspp main.sps & sleep 1; kill $!; wait $!], [143], [], [ignore])
 AT_CLEANUP
 
 AT_SETUP([SIGSEGV yields error report])
-
 # This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it.
 ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS
 
@@ -60,7 +59,6 @@ EOF
 AT_CHECK([sed '/proximate/q' < stderr], [0], [expout])
 AT_CLEANUP
 
-
 dnl This tests for a crash which was observed with --syntax
 AT_SETUP([argument parsing])
 
@@ -70,5 +68,27 @@ FINISH.
 ])
 
 AT_CHECK([pspp --syntax=enhanced main.sps], [0], [ignore])
+AT_CLEANUP
 
+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])
+dnl We have to use squish-pty to make PSPP think that we're running
+dnl interactively.  First make sure that squish-pty works at all.
+SQUISH_PTY="$PYTHON3 $top_srcdir/tests/ui/terminal/squish-pty.py"
+AT_CHECK([$SQUISH_PTY true </dev/null >/dev/null 2>/dev/null || exit 77])
+dnl Then do the real test.  The crucial thing to notice here is
+dnl that the SHOW output must appear before the prompt for FINISH.
+AT_CHECK([echo 'SHOW N.
+FINISH.' | $SQUISH_PTY pspp], [0], [stdout])
+AT_CHECK([sed -n 's/\r$//
+/^PSPP>/,$p' stdout], [0], [dnl
+PSPP> SHOW N.
+  Settings
++-+-------+
+|N|Unknown|
++-+-------+
+PSPP> FINISH.
+])
 AT_CLEANUP
diff --git a/tests/ui/terminal/squish-pty.py b/tests/ui/terminal/squish-pty.py
new file mode 100644 (file)
index 0000000..53132cf
--- /dev/null
@@ -0,0 +1,26 @@
+#! /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))
+