]> git.draconx.ca Git - cdecl99.git/commitdiff
tests: Remove test_print_decl etc. from the common library.
authorNick Bowler <nbowler@draconx.ca>
Thu, 28 Dec 2023 04:11:05 +0000 (23:11 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 28 Dec 2023 04:14:34 +0000 (23:14 -0500)
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
t/test.h
t/testlib.c

index 1fbd2d913b360114649b310a9e4983449024954c..49a3d23786df791a528439177e9de6d6f02bfebe 100644 (file)
@@ -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);
index 2d77abc5d3e84e9d0368347c8194a2cf88b04507..0d009f0e2ec306e09bcb1a0bb3892aecd4b5908b 100644 (file)
--- 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);
 
index c6b1975b1f3e8fdde8eeec655c3b0c2dae9046c1..5c76bb4dbec84bab03c3e2be23232345e109a2ab 100644 (file)
@@ -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;