INSERT: Add testing-only feature for ignoring cascading failures.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 12 Sep 2022 00:24:42 +0000 (17:24 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 12 Sep 2022 00:24:42 +0000 (17:24 -0700)
This makes it easier to write tests that cause a lot of cascading failures.

src/language/lexer/lexer.c
src/language/lexer/lexer.h
src/language/utilities/include.c
src/ui/terminal/main.c

index 24f901d3c04569eec6af73a3a1cfe5efdebc3647..f9236af19fc394cb55d63f90ded975f2218f10d1 100644 (file)
@@ -1866,9 +1866,11 @@ void
 lex_discard_noninteractive (struct lexer *lexer)
 {
   struct lex_source *src = lex_source__ (lexer);
-
   if (src != NULL)
     {
+      if (src->reader->error == LEX_ERROR_IGNORE)
+        return;
+
       lex_stage_clear (&src->pp);
       lex_stage_clear (&src->merge);
       lex_source_clear_parse (src);
index a23e4bf693af5eb6ff3b3b87ed99ba8f95f7853a..b172ac610fb80c119f5b12db11a7492786c11ac0 100644 (file)
@@ -40,7 +40,8 @@ enum lex_error_mode
     LEX_ERROR_TERMINAL,        /* Discard input line and continue reading. */
     LEX_ERROR_CONTINUE,        /* Continue to next command, except for
                                   cascading failures. */
-    LEX_ERROR_STOP             /* Stop processing. */
+    LEX_ERROR_IGNORE,          /* Continue, even for cascading failures. */
+    LEX_ERROR_STOP,            /* Stop processing. */
   };
 
 /* Reads a single syntax file as a stream of bytes encoded in UTF-8.
index eefbde6158bc2bbeba81b11a19161c8df52da42d..f0d9efb5da24f4d4f5242d2b9d74289949708c4e 100644 (file)
@@ -130,13 +130,12 @@ do_insert (struct lexer *lexer, struct dataset *ds, enum variant variant)
        {
          lex_match (lexer, T_EQUALS);
          if (lex_match_id (lexer, "CONTINUE"))
-           {
-             error_mode = LEX_ERROR_CONTINUE;
-           }
+            error_mode = LEX_ERROR_CONTINUE;
          else if (lex_match_id (lexer, "STOP"))
-           {
-             error_mode = LEX_ERROR_STOP;
-           }
+            error_mode = LEX_ERROR_STOP;
+          else if (settings_get_testing_mode ()
+                   && lex_match_id (lexer, "IGNORE"))
+            error_mode = LEX_ERROR_IGNORE;
          else
            {
              lex_error_expecting (lexer, "CONTINUE", "STOP");
index d2336472bfb98a0b19d6bc10a8f8864dc38788a6..60f9313840c625daca70cea1ed66d603c1bbe57b 100644 (file)
@@ -142,17 +142,25 @@ main (int argc, char **argv)
        break;
       else if (cmd_result_is_failure (result) && lex_token (lexer) != T_STOP)
         {
-          if (lex_get_error_mode (lexer) == LEX_ERROR_STOP)
+          switch (lex_get_error_mode (lexer))
             {
+            case LEX_ERROR_STOP:
               msg (MW, _("Error encountered while ERROR=STOP is effective."));
               lex_discard_noninteractive (lexer);
-            }
-          else if (result == CMD_CASCADING_FAILURE
-                   && lex_get_error_mode (lexer) != LEX_ERROR_TERMINAL)
-            {
-              msg (SE, _("Stopping syntax file processing here to avoid "
-                         "a cascade of dependent command failures."));
-              lex_discard_noninteractive (lexer);
+              break;
+
+            case LEX_ERROR_CONTINUE:
+              if (result == CMD_CASCADING_FAILURE)
+                {
+                  msg (SE, _("Stopping syntax file processing here to avoid "
+                             "a cascade of dependent command failures."));
+                  lex_discard_noninteractive (lexer);
+                }
+              break;
+
+            case LEX_ERROR_TERMINAL:
+            case LEX_ERROR_IGNORE:
+              break;
             }
         }