]> git.draconx.ca Git - cdecl99.git/blobdiff - t/crossparse.c
tests: Consolidate error messaging a bit.
[cdecl99.git] / t / crossparse.c
index f66ca62dab16c2171b7e861d7d0714528a5535e3..e77a1cc9f21b846d6f46866affd5181d82e717b8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Test that libcdecl can parse its own output.
- * Copyright © 2012, 2020, 2022-2023 Nick Bowler
+ * Copyright © 2012, 2020, 2022-2024 Nick Bowler
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <errno.h>
 #include <stdbool.h>
 #include <getopt.h>
-#include <cdecl.h>
-#include "test.h"
+
+#include "cdecl.h"
 
 #define PROGNAME "crossparse"
-static const char *progname = PROGNAME;
+#include "test.h"
+
 static const char sopts[] = "f:ECVH";
 static const struct option lopts[] = {
        { "cdecl",   0, NULL, 'C' },
@@ -67,16 +68,15 @@ char *rerender(const char *str, const char *parse_name,  parse_func *parse,
 
        decl = parse(str);
        if (!decl) {
-               fprintf(stderr, "%s: %s: failed to parse input: %s\n",
-                               progname, parse_name, cdecl_get_error()->str);
+               print_error("%s: failed to parse input: %s", parse_name,
+                           cdecl_get_error()->str);
                goto err;
        }
 
        len = render(NULL, 0, decl);
        buf = malloc_nofail(len+1);
        if (render(buf, len+1, decl) != len) {
-               fprintf(stderr, "%s: %s: inconsistent length returned\n",
-                               progname, render_name);
+               print_error("%s: inconsistent length returned", render_name);
                goto err;
        }
 
@@ -86,7 +86,7 @@ err:
        cdecl_free(decl);
        free(buf);
 
-       fprintf(stderr, "%s: the failed input was: %s\n", progname, str);
+       print_error("the failed input was: %s", str);
        return NULL;
 }
 #define rerender(str, p, r) (rerender(str, #p, p, #r, r))
@@ -126,8 +126,7 @@ out:
        free(buf3);
 
        if (!ret) {
-               fprintf(stderr, "%s: failed cross-parse check of: %s\n",
-                               progname, str);
+               print_error("failed cross-parse check of: %s", str);
        }
 
        return ret;
@@ -176,8 +175,8 @@ int main(int argc, char **argv)
                if (filename) {
                        infile = fopen(filename, "r");
                        if (!infile) {
-                               fprintf(stderr, "%s: %s: %s\n", progname,
-                                               filename, strerror(errno));
+                               print_error("%s: %s", filename,
+                                           strerror(errno));
                                return EXIT_FAILURE;
                        }
                }