chiark / gitweb /
@@@ wip
[mLib] / test / tvec-core.c
index 03873dc61e167505a8fbd3446e9e1ee61f01dcbd..92f31d38a8f8eb73c08131b108a91803b10684cf 100644 (file)
 
 /*----- Output ------------------------------------------------------------*/
 
+/* --- @tvec_error@, @tvec_error_v@ --- *
+ *
+ * Arguments:  @struct tvec_state *tv@ = test-vector state
+ *             @const char *msg@, @va_list ap@ = error message
+ *
+ * Returns:    @-1@.
+ *
+ * Use:                Report an error.  Errors are distinct from test failures,
+ *             and indicate that a problem was encountered which compromised
+ *             the activity of testing.
+ */
+
 int tvec_error(struct tvec_state *tv, const char *msg, ...)
 {
   va_list ap;
 
   va_start(ap, msg); tvec_error_v(tv, msg, &ap); va_end(ap);
-  tv->f |= TVSF_ERROR; return (-1);
+  return (-1);
 }
 int tvec_error_v(struct tvec_state *tv, const char *msg, va_list *ap)
-  { tv->output->ops->error(tv->output, msg, ap); return (-1); }
+{
+  tv->output->ops->error(tv->output, msg, ap);
+  tv->f |= TVSF_ERROR; return (-1);
+}
+
+/* --- @tvec_notice@, @tvec_notice_v@ --- *
+ *
+ * Arguments:  @struct tvec_state *tv@ = test-vector state
+ *             @const char *msg@, @va_list ap@ = message
+ *
+ * Returns:    ---
+ *
+ * Use:                Output a notice: essentially, some important information
+ *             which doesn't fit into any of the existing categories.
+ */
 
 void tvec_notice(struct tvec_state *tv, const char *msg, ...)
 {
@@ -55,35 +81,12 @@ void tvec_notice(struct tvec_state *tv, const char *msg, ...)
 void tvec_notice_v(struct tvec_state *tv, const char *msg, va_list *ap)
   { tv->output->ops->notice(tv->output, msg, ap); }
 
-int tvec_syntax(struct tvec_state *tv, int ch, const char *expect, ...)
-{
-  va_list ap;
-
-  va_start(ap, expect); tvec_syntax_v(tv, ch, expect, &ap); va_end(ap);
-  return (-1);
-}
-int tvec_syntax_v(struct tvec_state *tv, int ch,
-                  const char *expect, va_list *ap)
-{
-  dstr d = DSTR_INIT;
-  char found[8];
-
-  switch (ch) {
-    case EOF: strcpy(found, "#<eof>"); break;
-    case '\n': strcpy(found, "#<eol>"); ungetc(ch, tv->fp); break;
-    default:
-      if (isprint(ch)) sprintf(found, "`%c'", ch);
-      else sprintf(found, "#<\\x%02x>", ch);
-      break;
-  }
-  dstr_vputf(&d, expect, ap);
-  tvec_error(tv, "syntax error: expected %s but found %s", expect, found);
-  return (-1);
-}
+/*----- Test processing ---------------------------------------------------*/
 
 void tvec_skipgroup(struct tvec_state *tv, const char *excuse, ...)
 {
   va_list ap;
+
   va_start(ap, excuse); tvec_skipgroup_v(tv, excuse, &ap); va_end(ap);
 }
 void tvec_skipgroup_v(struct tvec_state *tv, const char *excuse, va_list *ap)
@@ -152,12 +155,33 @@ void tvec_mismatch(struct tvec_state *tv, unsigned f)
   }
 }
 
-/*----- Main machinery ----------------------------------------------------*/
+/*----- Parsing -----------------------------------------------------------*/
 
-struct groupstate {
-  void *ctx;
-};
-#define GROUPSTATE_INIT { 0 }
+int tvec_syntax(struct tvec_state *tv, int ch, const char *expect, ...)
+{
+  va_list ap;
+
+  va_start(ap, expect); tvec_syntax_v(tv, ch, expect, &ap); va_end(ap);
+  return (-1);
+}
+int tvec_syntax_v(struct tvec_state *tv, int ch,
+                 const char *expect, va_list *ap)
+{
+  dstr d = DSTR_INIT;
+  char found[8];
+
+  switch (ch) {
+    case EOF: strcpy(found, "#eof"); break;
+    case '\n': strcpy(found, "#eol"); ungetc(ch, tv->fp); break;
+    default:
+      if (isprint(ch)) sprintf(found, "`%c'", ch);
+      else sprintf(found, "#\\x%02x", ch);
+      break;
+  }
+  dstr_vputf(&d, expect, ap);
+  tvec_error(tv, "syntax error: expected %s but found %s", d.buf, found);
+  dstr_destroy(&d); return (-1);
+}
 
 void tvec_skipspc(struct tvec_state *tv)
 {
@@ -256,6 +280,13 @@ int tvec_readword_v(struct tvec_state *tv, dstr *d, const char *delims,
   return (0);
 }
 
+/*----- Main machinery ----------------------------------------------------*/
+
+struct groupstate {
+  void *ctx;
+};
+#define GROUPSTATE_INIT { 0 }
+
 void tvec_resetoutputs(struct tvec_state *tv)
 {
   const struct tvec_regdef *rd;