segment-test: Make debugging easier for some kinds of test failures.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 30 May 2021 19:49:45 +0000 (12:49 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 30 May 2021 20:00:48 +0000 (13:00 -0700)
tests/language/lexer/segment-test.c
tests/language/lexer/segment.at

index e7a6db11e87ecb158b5a8f6b000ab2e11649c71d..a3b67b89b24b2cd4eb59eb73617d1bd3682b7f4a 100644 (file)
@@ -70,6 +70,8 @@ main (int argc, char *argv[])
   set_program_name (argv[0]);
   file_name = parse_options (argc, argv);
 
+  setvbuf (stdout, NULL, _IONBF, 0);
+
   /* Read from stdin into 'input'.  Ensure that 'input' ends in a new-line
      followed by a null byte. */
   input = (!strcmp (file_name, "-")
@@ -157,12 +159,15 @@ check_segmentation (const char *input, size_t length, bool print_segments)
 
       if (type == SEG_NEWLINE)
         {
-          assert ((n == 1 && input[offset] == '\n')
-                  || (n == 2
-                      && input[offset] == '\r' && input[offset + 1] == '\n'));
+          if (n == 1 ? input[offset] != '\n'
+              : n == 2 ? input[offset] != '\r' || input[offset + 1] != '\n'
+              : false)
+            error (EXIT_FAILURE, 0, "NEWLINE segment at offset %zu contains "
+                   "non-newline content \"%.*s\"", offset, n, &input[offset]);
         }
-      else
-        assert (memchr (&input[offset], '\n', n) == NULL);
+      else if (memchr (&input[offset], '\n', n))
+        error (EXIT_FAILURE, 0, "%s segment \"%.*s\" contains new-line",
+               segment_type_to_string (type), n, &input[offset]);
 
       if (!print_segments)
         {
@@ -274,6 +279,7 @@ check_segmentation (const char *input, size_t length, bool print_segments)
           prompt = segmenter_get_prompt (&s);
           printf (" (%s)\n", prompt_style_to_string (prompt));
         }
+      fflush (stdout);
     }
   while (type != SEG_END);
 
index 8f82dd2e6e13f05b08dd11cfc9af43e0ca730dfe..86d967b5c58bab116b30e09c6606e3b340603e2e 100644 (file)
@@ -16,7 +16,8 @@ dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
 dnl
 AT_BANNER([syntax segmentation])
 m4_define([PSPP_CHECK_SEGMENT],
-  [for strip in "" "-s"; do
+  [AT_CAPTURE_FILE([input])
+   for strip in "" "-s"; do
      case $strip in # (
         '') sed 's/^-//' < expout-base > expout ;; # (
        -s) sed '/^-/d' < expout-base > expout ;;