Work on DEFINE command.
[pspp] / tests / language / lexer / segment-test.c
index 2cd141cfe01598972fc83f97a26cf871d4912088..cb46401b34df2326a2858375cfd7826878b8a014 100644 (file)
@@ -70,11 +70,13 @@ 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, "-")
-           ? fread_file (stdin, &length)
-           : read_file (file_name, &length));
+           ? fread_file (stdin, 0, &length)
+           : read_file (file_name, 0, &length));
   if (input == NULL)
     error (EXIT_FAILURE, errno, "reading %s failed", file_name);
 
@@ -106,8 +108,7 @@ main (int argc, char *argv[])
 static void
 check_segmentation (const char *input, size_t length, bool print_segments)
 {
-  struct segmenter s;
-  segmenter_init (&s, mode);
+  struct segmenter s = SEGMENTER_INIT (mode);
 
   size_t line_number = 1;
   size_t line_offset = 0;
@@ -157,12 +158,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)
         {
@@ -197,7 +201,7 @@ check_segmentation (const char *input, size_t length, bool print_segments)
 
           for (i = MIN (15, strlen (type_name)); i < 16; i++)
             putchar (' ');
-          for (i = 0; i < n; )
+          for (i = 0; i < n;)
             {
               const uint8_t *u_input = CHAR_CAST (const uint8_t *, input);
               ucs4_t uc;
@@ -274,6 +278,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);