]> git.draconx.ca Git - cdecl99.git/blobdiff - t/rendertest.c
tests: Consolidate error messaging a bit.
[cdecl99.git] / t / rendertest.c
index 42a2c5e9e38a701b93843f4c8e7b6567e96874e2..cd142298e6b43fef345913453b8311f56c9cbd12 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Helper to verify the output rendering routines.
- * Copyright © 2023 Nick Bowler
+ * Copyright © 2023-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 <getopt.h>
 #include <assert.h>
 
-#include <cdecl.h>
-#include "test.h"
+#include "cdecl.h"
 
 #define PROGNAME "rendertest"
-static const char *progname = PROGNAME;
+#include "test.h"
+
 static const char sopts[] = "n:ECVH";
 static const struct option lopts[] = {
        { "count",   1, NULL, 'n' },
@@ -63,9 +63,8 @@ static int do_test(char *line, unsigned long n, int mode)
                decl = cdecl_parse_decl(line);
 
        if (!decl) {
-               fprintf(stderr, "%s: %s\n", progname, cdecl_get_error()->str);
-               fprintf(stderr, "%s: the failed input was: %s\n",
-                               progname, line);
+               print_error("%s", cdecl_get_error()->str);
+               print_error("the failed input was: %s", line);
                return -1;
        }
 
@@ -76,12 +75,12 @@ static int do_test(char *line, unsigned long n, int mode)
                rc = cdecl_declare(line, n, decl);
 
        if (n && ( rc < n ? line[rc] : line[n-1] ) != '\0') {
-               fprintf(stderr, "%s: output is not 0-terminated\n", progname);
+               print_error("output is not 0-terminated");
                return -1;
        }
 
        if (line[n] != '\a') {
-               fprintf(stderr, "%s: output overflow\n", progname);
+               print_error("output overflow");
                return -1;
        }
 
@@ -110,8 +109,7 @@ int main(int argc, char **argv)
                        break;
                case 'n':
                        if (!test_strtoul(&n, optarg) || n > (size_t)-2) {
-                               fprintf(stderr, "%s: invalid count: %s\n",
-                                       progname, optarg);
+                               print_error("invalid count: %s", optarg);
                                return EXIT_FAILURE;
                        }
                        break;