From 1260ac474046e883b8e499a72739c9289097933f Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 27 Dec 2023 23:11:05 -0500 Subject: [PATCH] tests: Remove test_print_decl etc. from the common library. These functions are only used by one test application, and are now causing some grief as they force the output routines from libcdecl to be linked into every test application. Just move this into the randomdecl application. --- t/randomdecl.c | 21 +++++++++++++++++++-- t/test.h | 3 --- t/testlib.c | 33 --------------------------------- 3 files changed, 19 insertions(+), 38 deletions(-) diff --git a/t/randomdecl.c b/t/randomdecl.c index 1fbd2d9..49a3d23 100644 --- a/t/randomdecl.c +++ b/t/randomdecl.c @@ -82,6 +82,23 @@ static struct cdecl *random_decl(struct test_rng *rng) return decl; } +static void +print_decl(struct cdecl *decl, size_t func(char *, size_t, struct cdecl *)) +{ + static size_t printbuf_size; + static char *printbuf; + size_t rc; +retry: + rc = func(printbuf, printbuf_size, decl); + if (rc >= printbuf_size) { + printbuf_size = rc + 1; + printbuf = realloc_nofail(printbuf, printbuf_size); + goto retry; + } + + printf("%s\n", printbuf); +} + int main(int argc, char **argv) { const char *seed = "", *count_str = NULL; @@ -132,9 +149,9 @@ int main(int argc, char **argv) decl = random_decl(rng); if (mode == MODE_ENGLISH) { - test_explain_decl(decl); + print_decl(decl, cdecl_explain); } else { - test_print_decl(decl); + print_decl(decl, cdecl_declare); } gen_free_declspecs(decl->specifiers); diff --git a/t/test.h b/t/test.h index 2d77abc..0d009f0 100644 --- a/t/test.h +++ b/t/test.h @@ -37,9 +37,6 @@ struct test_rng; void *malloc_nofail(size_t size); void *realloc_nofail(void *ptr, size_t size); -void test_print_specifiers(struct cdecl_declspec *spec); -void test_print_decl(struct cdecl *decl); -void test_explain_decl(struct cdecl *decl); bool strict_strtoul(unsigned long *val, const char *str, int base); diff --git a/t/testlib.c b/t/testlib.c index c6b1975..5c76bb4 100644 --- a/t/testlib.c +++ b/t/testlib.c @@ -26,9 +26,6 @@ #include "help.h" #include "test.h" -static size_t printbuf_size; -static char *printbuf; - void *realloc_nofail(void *ptr, size_t size) { void *p; @@ -47,36 +44,6 @@ void *malloc_nofail(size_t size) return realloc_nofail(NULL, size); } -void test_print_decl(struct cdecl *decl) -{ - size_t rc; - -retry: - rc = cdecl_declare(printbuf, printbuf_size, decl); - if (rc >= printbuf_size) { - printbuf_size = rc + 1; - printbuf = realloc_nofail(printbuf, printbuf_size); - goto retry; - } - - printf("%s\n", printbuf); -} - -void test_explain_decl(struct cdecl *decl) -{ - size_t rc; - -retry: - rc = cdecl_explain(printbuf, printbuf_size, decl); - if (rc >= printbuf_size) { - printbuf_size = rc + 1; - printbuf = realloc_nofail(printbuf, printbuf_size); - goto retry; - } - - printf("%s\n", printbuf); -} - bool strict_strtoul(unsigned long *val, const char *str, int base) { char *end; -- 2.43.2