/*
* 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' },
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;
}
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))
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;
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;
}
}
/*
* Helper application to test normalization of declaration specifiers.
- * Copyright © 2021-2023 Nick Bowler
+ * Copyright © 2021-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 "cdecl.h"
#include "cdecl-internal.h"
-#include "test.h"
#define PROGNAME "normalize"
-static const char *progname = PROGNAME;
+#include "test.h"
+
static const char sopts[] = "f:VH";
static const struct option lopts[] = {
{ "file", 1, NULL, 'f' },
/*
* Generate random C declarations for testing.
- * 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 <stdbool.h>
#include <errno.h>
#include <getopt.h>
-#include <cdecl.h>
+#include "cdecl.h"
#include "declgen.h"
-#include "test.h"
#define PROGNAME "randomdecl"
-static const char *progname = PROGNAME;
+#include "test.h"
+
static const char sopts[] = "s:n:ECVH";
static const struct option lopts[] = {
{ "seed", 1, NULL, 's' },
}
if (count_str && !test_strtoul(&count, count_str)) {
- fprintf(stderr, "%s: invalid count: %s\n", progname, count_str);
+ print_error("invalid count: %s", count_str);
return EXIT_FAILURE;
}
/*
* 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' },
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;
}
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;
}
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;
/*
* Simple random number generator for testing.
- * Copyright © 2022-2023 Nick Bowler
+ * Copyright © 2022-2024 Nick Bowler
*
* Directly compare the test lib RNG against the reference implementation.
*
tap_skip_all("cannot compile reference xoshiro256+");
}
#else
+#define TEST_RNG_NO_EXTERNAL_API 1
#include "rng.c"
#include "xos256p.c"
#include <errno.h>
#include <limits.h>
-#include "test.h"
+#if !TEST_RNG_NO_EXTERNAL_API
+# include "test.h"
+#endif
#define B64(x) ((x) & 0xffffffffffffffff)
return z ^ (z >> 31);
}
+#if !TEST_RNG_NO_EXTERNAL_API
struct test_rng *test_rng_alloc(const char *seed_str)
{
unsigned long long seed;
limit |= (limit << 16 << 16);
if (!test_strtoumax(&seed_val, seed_str, limit)) {
- fprintf(stderr, "%s: invalid seed\n", seed_str);
+ print_error("%s: invalid seed", seed_str);
return NULL;
}
seed = seed_val;
return val;
}
+#endif
/*
* Helper to verify scanner output.
- * 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 "scan.h"
#include "cdecl-internal.h"
+
+#define PROGNAME "scantest"
#include "test.h"
/* Stubs */
abort();
}
-#define PROGNAME "scantest"
-static const char *progname = PROGNAME;
static const char sopts[] = "ECVH";
static const struct option lopts[] = {
{ "cdecl", 0, NULL, 'C' },
/*
- * 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
struct test_rng;
+void print_error(const char *fmt, ...);
+
void *malloc_nofail(size_t size);
void *realloc_nofail(void *ptr, size_t size);
#define VERSION_NO_COPYRIGHT_SYMBOL 1
#include "version.h"
+#ifdef PROGNAME
+const char *progname = PROGNAME;
+#endif
+
#define test_print_version(s) \
do_print_version(s " (" PACKAGE_NAME ") " PACKAGE_VERSION)
/*
* Miscellaneous functions used by the cdecl99 test suite.
- * Copyright © 2011-2012, 2021-2023 Nick Bowler
+ * Copyright © 2011-2012, 2021-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 <string.h>
#include <errno.h>
#include <getopt.h>
-#include <cdecl.h>
+
+#include "cdecl.h"
#include "help.h"
#include "test.h"
#include "intconv.h"
+void print_error(const char *fmt, ...)
+{
+ extern const char *progname;
+ va_list ap;
+
+ fprintf(stderr, "%s: ", progname);
+
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+
+ fprintf(stderr, "\n");
+}
+
void *realloc_nofail(void *ptr, size_t size)
{
void *p;
-AT_COPYRIGHT([Copyright © 2020-2021, 2023 Nick Bowler])
+AT_COPYRIGHT([Copyright (C) 2020-2021, 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