From c68d8eba5fe27f4e9ecf4938a6f5a5636d5872d2 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sat, 3 May 2008 13:43:17 +0100 Subject: [PATCH] lib/ tests now use Automake's test infrastructure, and are split into multiple executables. Organization: Straylight/Edgeware From: Richard Kettlewell --- .bzrignore | 27 +++++++++- lib/Makefile.am | 125 +++++++++++++++++++++++++++++++++++++++++----- lib/t-addr.c | 6 +-- lib/t-basen.c | 5 +- lib/t-bits.c | 5 +- lib/t-cache.c | 6 ++- lib/t-casefold.c | 6 +-- lib/t-cookies.c | 6 +-- lib/t-filepart.c | 6 ++- lib/t-hash.c | 5 +- lib/t-heap.c | 7 ++- lib/t-hex.c | 6 +-- lib/t-kvp.c | 7 ++- lib/t-mime.c | 6 +-- lib/t-printf.c | 5 +- lib/t-regsub.c | 6 +-- lib/t-selection.c | 6 ++- lib/t-signame.c | 5 +- lib/t-sink.c | 6 +-- lib/t-split.c | 5 +- lib/t-syscalls.c | 6 +-- lib/t-trackname.c | 5 +- lib/t-unicode.c | 5 +- lib/t-url.c | 6 +-- lib/t-utf8.c | 5 +- lib/t-vector.c | 4 +- lib/t-words.c | 5 +- lib/t-wstat.c | 5 +- lib/test.c | 76 ---------------------------- lib/test.h | 38 +++++--------- 30 files changed, 233 insertions(+), 178 deletions(-) diff --git a/.bzrignore b/.bzrignore index e4a97a8..420efc6 100644 --- a/.bzrignore +++ b/.bzrignore @@ -68,7 +68,6 @@ examples/disorder.init images/Makefile lib/Makefile lib/definitions.h -lib/test plugins/Makefile python/Makefile python/disorder.py @@ -147,3 +146,29 @@ scripts/teardown sounds/long.ogg sounds/slap.raw server/disorder-choose +lib/t-addr +lib/t-basen +lib/t-bits +lib/t-cache +lib/t-casefold +lib/t-cookies +lib/t-filepart +lib/t-hash +lib/t-heap +lib/t-hex +lib/t-kvp +lib/t-mime +lib/t-printf +lib/t-regsub +lib/t-selection +lib/t-signame +lib/t-sink +lib/t-split +lib/t-syscalls +lib/t-trackname +lib/t-unicode +lib/t-url +lib/t-utf8 +lib/t-vector +lib/t-words +lib/t-wstat diff --git a/lib/Makefile.am b/lib/Makefile.am index 91a2bf1..38d51d1 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -18,9 +18,14 @@ # USA # +TESTS=t-addr t-basen t-bits t-cache t-casefold t-cookies \ + t-filepart t-hash t-heap t-hex t-kvp t-mime t-printf \ + t-regsub t-selection t-signame t-sink t-split t-syscalls \ + t-trackname t-unicode t-url t-utf8 t-vector t-words t-wstat + noinst_LIBRARIES=libdisorder.a include_HEADERS=disorder.h -noinst_PROGRAMS=test +noinst_PROGRAMS=$(TESTS) if SERVER TRACKDB=trackdb.c @@ -115,17 +120,113 @@ definitions.h: Makefile defs.o: definitions.h versionstring.h defs.lo: definitions.h versionstring.h -test_SOURCES=test.c memgc.c test.h t-addr.c t-basen.c t-cache.c \ - t-casefold.c t-cookies.c t-filepart.c t-hash.c t-heap.c \ - t-hex.c t-kvp.c t-mime.c t-printf.c t-regsub.c t-selection.c \ - t-signame.c t-sink.c t-split.c t-unicode.c t-url.c t-utf8.c \ - t-words.c t-wstat.c t-bits.c t-vector.c t-syscalls.c \ - t-trackname.c -test_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) -test_DEPENDENCIES=libdisorder.a - -check: test #test.i - ./test +t_addr_SOURCES=t-addr.c test.c test.h +t_addr_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_addr_DEPENDENCIES=libdisorder.a + +t_basen_SOURCES=t-basen.c test.c test.h +t_basen_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_basen_DEPENDENCIES=libdisorder.a + +t_bits_SOURCES=t-bits.c test.c test.h +t_bits_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_bits_DEPENDENCIES=libdisorder.a + +t_cache_SOURCES=t-cache.c test.c test.h +t_cache_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_cache_DEPENDENCIES=libdisorder.a + +t_casefold_SOURCES=t-casefold.c test.c test.h +t_casefold_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_casefold_DEPENDENCIES=libdisorder.a + +t_cookies_SOURCES=t-cookies.c test.c test.h +t_cookies_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_cookies_DEPENDENCIES=libdisorder.a + +t_filepart_SOURCES=t-filepart.c test.c test.h +t_filepart_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_filepart_DEPENDENCIES=libdisorder.a + +t_hash_SOURCES=t-hash.c test.c test.h +t_hash_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_hash_DEPENDENCIES=libdisorder.a + +t_heap_SOURCES=t-heap.c test.c test.h +t_heap_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_heap_DEPENDENCIES=libdisorder.a + +t_hex_SOURCES=t-hex.c test.c test.h +t_hex_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_hex_DEPENDENCIES=libdisorder.a + +t_kvp_SOURCES=t-kvp.c test.c test.h +t_kvp_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_kvp_DEPENDENCIES=libdisorder.a + +t_mime_SOURCES=t-mime.c test.c test.h +t_mime_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_mime_DEPENDENCIES=libdisorder.a + +t_printf_SOURCES=t-printf.c test.c test.h +t_printf_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_printf_DEPENDENCIES=libdisorder.a + +t_regsub_SOURCES=t-regsub.c test.c test.h +t_regsub_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_regsub_DEPENDENCIES=libdisorder.a + +t_selection_SOURCES=t-selection.c test.c test.h +t_selection_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_selection_DEPENDENCIES=libdisorder.a + +t_signame_SOURCES=t-signame.c test.c test.h +t_signame_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_signame_DEPENDENCIES=libdisorder.a + +t_sink_SOURCES=t-sink.c test.c test.h +t_sink_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_sink_DEPENDENCIES=libdisorder.a + +t_split_SOURCES=t-split.c test.c test.h +t_split_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_split_DEPENDENCIES=libdisorder.a + +t_syscalls_SOURCES=t-syscalls.c test.c test.h +t_syscalls_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_syscalls_DEPENDENCIES=libdisorder.a + +t_trackname_SOURCES=t-trackname.c test.c test.h +t_trackname_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_trackname_DEPENDENCIES=libdisorder.a + +t_unicode_SOURCES=t-unicode.c test.c test.h +t_unicode_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_unicode_DEPENDENCIES=libdisorder.a + +t_url_SOURCES=t-url.c test.c test.h +t_url_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_url_DEPENDENCIES=libdisorder.a + +t_utf8_SOURCES=t-utf8.c test.c test.h +t_utf8_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_utf8_DEPENDENCIES=libdisorder.a + +t_vector_SOURCES=t-vector.c test.c test.h +t_vector_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_vector_DEPENDENCIES=libdisorder.a + +t_words_SOURCES=t-words.c test.c test.h +t_words_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_words_DEPENDENCIES=libdisorder.a + +t_wstat_SOURCES=t-wstat.c test.c test.h +t_wstat_LDADD=libdisorder.a $(LIBPCRE) $(LIBICONV) $(LIBGC) +t_wstat_DEPENDENCIES=libdisorder.a + + +#check: test #test.i +# ./test check-report: before-check check make-coverage-reports before-check: diff --git a/lib/t-addr.c b/lib/t-addr.c index e609cd9..0e495d8 100644 --- a/lib/t-addr.c +++ b/lib/t-addr.c @@ -19,7 +19,7 @@ */ #include "test.h" -void test_addr(void) { +static void test_addr(void) { struct stringlist a; const char *s[3]; struct addrinfo *ai; @@ -58,8 +58,6 @@ void test_addr(void) { .ai_addr = (struct sockaddr *)&a2, }; - printf("test_addr\n"); - insist(addrinfocmp(&p1, &p2) < 0); a.n = 1; @@ -132,6 +130,8 @@ void test_addr(void) { check_integer(multicast((struct sockaddr *)&su), 0); } +TEST(addr); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-basen.c b/lib/t-basen.c index 751d4b0..99b52f9 100644 --- a/lib/t-basen.c +++ b/lib/t-basen.c @@ -19,11 +19,10 @@ */ #include "test.h" -void test_basen(void) { +static void test_basen(void) { unsigned long v[64]; char buffer[1024]; - fprintf(stderr, "test_basen\n"); v[0] = 999; insist(basen(v, 1, buffer, sizeof buffer, 10) == 0); check_string(buffer, "999"); @@ -53,6 +52,8 @@ void test_basen(void) { insist(basen(v, 4, buffer, 10, 16) == -1); } +TEST(basen); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-bits.c b/lib/t-bits.c index 846abb8..80bfdf5 100644 --- a/lib/t-bits.c +++ b/lib/t-bits.c @@ -20,10 +20,9 @@ #include "test.h" #include "bits.h" -void test_bits(void) { +static void test_bits(void) { int n; - printf("test_bits\n"); check_integer(leftmost_bit(0), -1); check_integer(leftmost_bit(0x80000000), 31); check_integer(leftmost_bit(0xffffffff), 31); @@ -36,6 +35,8 @@ void test_bits(void) { } } +TEST(bits); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-cache.c b/lib/t-cache.c index 02da8d6..3cdb400 100644 --- a/lib/t-cache.c +++ b/lib/t-cache.c @@ -19,10 +19,10 @@ */ #include "test.h" -void test_cache(void) { +static void test_cache(void) { const struct cache_type t1 = { 1 }, t2 = { 10 }; const char v11[] = "spong", v12[] = "wibble", v2[] = "blat"; - fprintf(stderr, "test_cache\n"); + cache_put(&t1, "1_1", v11); cache_put(&t1, "1_2", v12); cache_put(&t2, "2", v2); @@ -47,6 +47,8 @@ void test_cache(void) { insist(cache_get(&t2, "2") == 0); } +TEST(cache); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-casefold.c b/lib/t-casefold.c index f86738e..449eaff 100644 --- a/lib/t-casefold.c +++ b/lib/t-casefold.c @@ -19,12 +19,10 @@ */ #include "test.h" -void test_casefold(void) { +static void test_casefold(void) { uint32_t c, l; const char *input, *canon_folded, *compat_folded, *canon_expected, *compat_expected; - fprintf(stderr, "test_casefold\n"); - /* This isn't a very exhaustive test. Unlike for normalization, there don't * seem to be any public test vectors for these algorithms. */ @@ -75,6 +73,8 @@ void test_casefold(void) { check_string(utf8_casefold_canon("", 0, 0), ""); } +TEST(casefold); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-cookies.c b/lib/t-cookies.c index 7fdde32..c8ec504 100644 --- a/lib/t-cookies.c +++ b/lib/t-cookies.c @@ -19,11 +19,9 @@ */ #include "test.h" -void test_cookies(void) { +static void test_cookies(void) { struct cookiedata cd[1]; - fprintf(stderr, "test_cookies\n"); - /* These are the examples from RFC2109 */ insist(!parse_cookie("$Version=\"1\"; Customer=\"WILE_E_COYOTE\"; $Path=\"/acme\"", cd)); insist(!strcmp(cd->version, "1")); @@ -72,6 +70,8 @@ void test_cookies(void) { insist(cd->cookies[0].domain == 0); } +TEST(cookies); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-filepart.c b/lib/t-filepart.c index 1bf55f3..d2e741b 100644 --- a/lib/t-filepart.c +++ b/lib/t-filepart.c @@ -1,3 +1,4 @@ + /* * This file is part of DisOrder. * Copyright (C) 2005, 2007, 2008 Richard Kettlewell @@ -19,8 +20,7 @@ */ #include "test.h" -void test_filepart(void) { - fprintf(stderr, "test_filepart\n"); +static void test_filepart(void) { check_string(d_dirname("/"), "/"); check_string(d_dirname("////"), "/"); check_string(d_dirname("/spong"), "/"); @@ -47,6 +47,8 @@ void test_filepart(void) { check_string(strip_extension("foo.bar/wibble.spong"), "foo.bar/wibble"); } +TEST(filepart); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-hash.c b/lib/t-hash.c index b5c0094..d9e8336 100644 --- a/lib/t-hash.c +++ b/lib/t-hash.c @@ -19,12 +19,11 @@ */ #include "test.h" -void test_hash(void) { +static void test_hash(void) { hash *h; int i, *ip; char **keys; - fprintf(stderr, "test_hash\n"); h = hash_new(sizeof(int)); for(i = 0; i < 10000; ++i) insist(hash_add(h, do_printf("%d", i), &i, HASH_INSERT) == 0); @@ -44,6 +43,8 @@ void test_hash(void) { check_integer(hash_count(h), 0); } +TEST(hash); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-heap.c b/lib/t-heap.c index c3e4a03..54d052a 100644 --- a/lib/t-heap.c +++ b/lib/t-heap.c @@ -28,13 +28,11 @@ HEAP_TYPE(iheap, int, int_lt); HEAP_DEFINE(iheap, int, int_lt); /** @brief Tests for @ref heap.h */ -void test_heap(void) { +static void test_heap(void) { struct iheap h[1]; int n; int last = -1; - fprintf(stderr, "test_heap\n"); - iheap_init(h); for(n = 0; n < 1000; ++n) iheap_insert(h, random() % 100); @@ -45,9 +43,10 @@ void test_heap(void) { insist(last <= latest); last = latest; } - putchar('\n'); } +TEST(heap); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-hex.c b/lib/t-hex.c index 3f6ba99..966d226 100644 --- a/lib/t-hex.c +++ b/lib/t-hex.c @@ -19,14 +19,12 @@ */ #include "test.h" -void test_hex(void) { +static void test_hex(void) { unsigned n; static const unsigned char h[] = { 0x00, 0xFF, 0x80, 0x7F }; uint8_t *u; size_t ul; - fprintf(stderr, "test_hex\n"); - for(n = 0; n <= UCHAR_MAX; ++n) { if(!isxdigit(n)) insist(unhexdigitq(n) == -1); @@ -69,6 +67,8 @@ void test_hex(void) { fprintf(stderr, "}\n"); } +TEST(hex); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-kvp.c b/lib/t-kvp.c index b6bcc3d..ce01a84 100644 --- a/lib/t-kvp.c +++ b/lib/t-kvp.c @@ -19,18 +19,19 @@ */ #include "test.h" -void test_kvp(void) { +static void test_kvp(void) { struct kvp *k; size_t n; - fprintf(stderr, "test_kvp\n"); /* decoding */ #define KVP_URLDECODE(S) kvp_urldecode((S), strlen(S)) + fprintf(stderr, "5 ERROR reports expected {\n"); insist(KVP_URLDECODE("=%zz") == 0); insist(KVP_URLDECODE("=%0") == 0); insist(KVP_URLDECODE("=%0z") == 0); insist(KVP_URLDECODE("=%%") == 0); insist(KVP_URLDECODE("==%") == 0); + fprintf(stderr, "}\n"); insist(KVP_URLDECODE("wibble") == 0); insist(KVP_URLDECODE("") == 0); insist(KVP_URLDECODE("wibble&") == 0); @@ -58,6 +59,8 @@ void test_kvp(void) { "abc%25%20%2b%0a"); } +TEST(kvp); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-mime.c b/lib/t-mime.c index 5c3152a..65000c7 100644 --- a/lib/t-mime.c +++ b/lib/t-mime.c @@ -34,15 +34,13 @@ static int header_callback(const char *name, const char *value, return 0; } -void test_mime(void) { +static void test_mime(void) { char *t, *n, *v; struct vector parts[1]; struct kvp *k; const char *s, *cs, *enc; hash *h; - fprintf(stderr, "test_mime\n"); - t = 0; k = 0; insist(!mime_content_type("text/plain", &t, &k)); @@ -337,6 +335,8 @@ void test_mime(void) { check_string(enc, "quoted-printable"); } +TEST(mime); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-printf.c b/lib/t-printf.c index be57bc8..85b85c9 100644 --- a/lib/t-printf.c +++ b/lib/t-printf.c @@ -19,7 +19,7 @@ */ #include "test.h" -void test_printf(void) { +static void test_printf(void) { char c; short s; int i; @@ -32,7 +32,6 @@ void test_printf(void) { char buffer[16]; FILE *fp; - fprintf(stderr, "test_printf\n"); check_string(do_printf("%d", 999), "999"); check_string(do_printf("%d", -999), "-999"); check_string(do_printf("%i", 999), "999"); @@ -132,6 +131,8 @@ void test_printf(void) { fclose(fp); } +TEST(printf); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-regsub.c b/lib/t-regsub.c index bff05dc..1497db2 100644 --- a/lib/t-regsub.c +++ b/lib/t-regsub.c @@ -19,13 +19,11 @@ */ #include "test.h" -void test_regsub(void) { +static void test_regsub(void) { pcre *re; const char *errstr; int erroffset; - printf("test_regsub\n"); - check_integer(regsub_flags(""), 0); check_integer(regsub_flags("g"), REGSUB_GLOBAL); check_integer(regsub_flags("i"), REGSUB_CASE_INDEPENDENT); @@ -65,6 +63,8 @@ void test_regsub(void) { "foo-x:bBb$aAaA:y-bar"); } +TEST(regsub); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-selection.c b/lib/t-selection.c index 975f930..0992efe 100644 --- a/lib/t-selection.c +++ b/lib/t-selection.c @@ -19,9 +19,9 @@ */ #include "test.h" -void test_selection(void) { +static void test_selection(void) { hash *h; - fprintf(stderr, "test_selection\n"); + insist((h = selection_new()) != 0); selection_set(h, "one", 1); selection_set(h, "two", 1); @@ -57,6 +57,8 @@ void test_selection(void) { insist(hash_count(h) == 0); } +TEST(selection); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-signame.c b/lib/t-signame.c index 72f1d0f..95f06b8 100644 --- a/lib/t-signame.c +++ b/lib/t-signame.c @@ -19,8 +19,7 @@ */ #include "test.h" -void test_signame(void) { - fprintf(stderr, "test_signame\n"); +static void test_signame(void) { insist(find_signal("SIGTERM") == SIGTERM); insist(find_signal("SIGHUP") == SIGHUP); insist(find_signal("SIGINT") == SIGINT); @@ -29,6 +28,8 @@ void test_signame(void) { insist(find_signal("SIGYOURMUM") == -1); } +TEST(signame); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-sink.c b/lib/t-sink.c index ad7b23c..68816b3 100644 --- a/lib/t-sink.c +++ b/lib/t-sink.c @@ -19,13 +19,11 @@ */ #include "test.h" -void test_sink(void) { +static void test_sink(void) { struct sink *s; struct dynstr d[1]; FILE *fp; char *l; - - fprintf(stderr, "test_sink\n"); fp = tmpfile(); assert(fp != 0); @@ -58,6 +56,8 @@ void test_sink(void) { check_string(d->vec, "test: 999\nwibble: foobar\n"); } +TEST(sink); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-split.c b/lib/t-split.c index 1b8aa18..3737d0c 100644 --- a/lib/t-split.c +++ b/lib/t-split.c @@ -19,11 +19,10 @@ */ #include "test.h" -void test_split(void) { +static void test_split(void) { char **v; int nv; - fprintf(stderr, "test_split\n"); insist(split("\"misquoted", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0); insist(split("\'misquoted", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0); insist(split("\'misquoted\\", &nv, SPLIT_COMMENTS|SPLIT_QUOTES, 0, 0) == 0); @@ -88,6 +87,8 @@ void test_split(void) { check_string(quoteutf8("wibble'wobble"), "\"wibble'wobble\""); } +TEST(split); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-syscalls.c b/lib/t-syscalls.c index 0566fde..a4ab19b 100644 --- a/lib/t-syscalls.c +++ b/lib/t-syscalls.c @@ -19,13 +19,11 @@ */ #include "test.h" -void test_syscalls(void) { +static void test_syscalls(void) { int p[2]; char buf[128], *e; long n; long long nn; - - printf("test_syscalls\n"); xpipe(p); nonblock(p[1]); @@ -98,6 +96,8 @@ void test_syscalls(void) { #endif } +TEST(syscalls); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-trackname.c b/lib/t-trackname.c index 23674ed..29103ae 100644 --- a/lib/t-trackname.c +++ b/lib/t-trackname.c @@ -28,8 +28,7 @@ a, (sizeof a) - 1) == -(EXPECTED)); \ } while(0) -void test_trackname(void) { - printf("test_trackname\n"); +static void test_trackname(void) { CHECK_PATH_ORDER("/a/b", "/aa/", -1); CHECK_PATH_ORDER("/a/b", "/a", 1); CHECK_PATH_ORDER("/ab", "/a", 1); @@ -38,6 +37,8 @@ void test_trackname(void) { CHECK_PATH_ORDER("/", "/", 0); } +TEST(trackname); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-unicode.c b/lib/t-unicode.c index 2d7c81c..f50454e 100644 --- a/lib/t-unicode.c +++ b/lib/t-unicode.c @@ -100,7 +100,7 @@ static void breaktest(const char *path, } /** @brief Tests for @ref lib/unicode.h */ -void test_unicode(void) { +static void test_unicode(void) { FILE *fp; int lineno = 0; char *l, *lp; @@ -108,7 +108,6 @@ void test_unicode(void) { uint32_t *c[6], *NFD_c[6], *NFKD_c[6], *NFC_c[6], *NFKC_c[6]; /* 1-indexed */ int cn, bn; - fprintf(stderr, "test_unicode\n"); fp = open_unicode_test("NormalizationTest.txt"); while(!inputline("NormalizationTest.txt", fp, &l, '\n')) { ++lineno; @@ -189,6 +188,8 @@ void test_unicode(void) { insist(utf32_combining_class(0xE0000) == 0); } +TEST(unicode); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-url.c b/lib/t-url.c index 89fb345..aa83940 100644 --- a/lib/t-url.c +++ b/lib/t-url.c @@ -19,10 +19,8 @@ */ #include "test.h" -void test_url(void) { +static void test_url(void) { struct url p; - - printf("test_url\n"); insist(parse_url("http://www.example.com/example/path", &p) == 0); check_string(p.scheme, "http"); @@ -50,6 +48,8 @@ void test_url(void) { insist(parse_url("http://www.example.com/example%2zpath", &p) == -1); } +TEST(url); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-utf8.c b/lib/t-utf8.c index de2f8b3..a98f956 100644 --- a/lib/t-utf8.c +++ b/lib/t-utf8.c @@ -19,7 +19,7 @@ */ #include "test.h" -void test_utf8(void) { +static void test_utf8(void) { /* Test validutf8, convert to UCS-4, check the answer is right, * convert back to UTF-8, check we got to where we started */ #define U8(CHARS, WORDS) do { \ @@ -36,7 +36,6 @@ void test_utf8(void) { check_string(u8, CHARS); \ } while(0) - fprintf(stderr, "test_utf8\n"); #define validutf8(S) utf8_valid((S), strlen(S)) /* empty string */ @@ -134,6 +133,8 @@ void test_utf8(void) { insist(!validutf8("\xF8")); } +TEST(utf8); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-vector.c b/lib/t-vector.c index 685f213..137ea60 100644 --- a/lib/t-vector.c +++ b/lib/t-vector.c @@ -19,13 +19,12 @@ */ #include "test.h" -void test_vector(void) { +static void test_vector(void) { struct vector v[1]; static const char *s[10] = { "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve" }; int n; - printf("test_vector\n"); vector_init(v); insist(v->nvec == 0); @@ -55,6 +54,7 @@ void test_vector(void) { insist(v->vec[12] == 0); } +TEST(vector); /* Local Variables: diff --git a/lib/t-words.c b/lib/t-words.c index 4b3ee55..30730c9 100644 --- a/lib/t-words.c +++ b/lib/t-words.c @@ -49,11 +49,10 @@ struct { }; #define NWTEST (sizeof wtest / sizeof *wtest) -void test_words(void) { +static void test_words(void) { size_t t, nexpect, ngot, i; int right; - fprintf(stderr, "test_words\n"); for(t = 0; t < NWTEST; ++t) { char **got = utf8_word_split(wtest[t].in, strlen(wtest[t].in), &ngot, 0); @@ -82,6 +81,8 @@ void test_words(void) { } } +TEST(words); + /* Local Variables: c-basic-offset:2 diff --git a/lib/t-wstat.c b/lib/t-wstat.c index 0d87472..a6746cd 100644 --- a/lib/t-wstat.c +++ b/lib/t-wstat.c @@ -19,11 +19,10 @@ */ #include "test.h" -void test_wstat(void) { +static void test_wstat(void) { pid_t pid; int w; - fprintf(stderr, "test_wstat\n"); if(!(pid = xfork())) { _exit(1); } @@ -39,6 +38,8 @@ void test_wstat(void) { check_string_prefix(wstat(w), "terminated by signal 15"); } +TEST(wstat); + /* Local Variables: c-basic-offset:2 diff --git a/lib/test.c b/lib/test.c index 0682979..63d7260 100644 --- a/lib/test.c +++ b/lib/test.c @@ -90,82 +90,6 @@ const char *do_printf(const char *fmt, ...) { return s; } -int main(void) { - mem_init(); - fail_first = !!getenv("FAIL_FIRST"); - insist('\n' == 0x0A); - insist('\r' == 0x0D); - insist(' ' == 0x20); - insist('0' == 0x30); - insist('9' == 0x39); - insist('A' == 0x41); - insist('Z' == 0x5A); - insist('a' == 0x61); - insist('z' == 0x7A); - /* addr.c */ - test_addr(); - /* asprintf.c */ - /* authhash.c */ - /* basen.c */ - test_basen(); - /* charset.c */ - /* client.c */ - /* configuration.c */ - /* event.c */ - /* filepart.c */ - test_filepart(); - /* fprintf.c */ - /* heap.c */ - test_heap(); - /* hex.c */ - test_hex(); - /* inputline.c */ - /* kvp.c */ - test_kvp(); - /* log.c */ - /* mem.c */ - /* mime.c */ - test_mime(); - test_cookies(); - /* mixer.c */ - /* plugin.c */ - /* printf.c */ - test_printf(); - /* queue.c */ - /* sink.c */ - test_sink(); - /* snprintf.c */ - /* split.c */ - test_split(); - /* syscalls.c */ - /* table.c */ - /* unicode.c */ - test_unicode(); - /* utf8.c */ - test_utf8(); - /* vector.c */ - /* words.c */ - test_casefold(); - test_words(); - /* wstat.c */ - test_wstat(); - /* signame.c */ - test_signame(); - /* cache.c */ - test_cache(); - /* selection.c */ - test_selection(); - test_hash(); - test_url(); - test_regsub(); - test_bits(); - test_vector(); - test_syscalls(); - test_trackname(); - fprintf(stderr, "%lld errors out of %lld tests\n", errors, tests); - return !!errors; -} - /* Local Variables: c-basic-offset:2 diff --git a/lib/test.h b/lib/test.h index 4fbde0b..3c43da0 100644 --- a/lib/test.h +++ b/lib/test.h @@ -131,32 +131,18 @@ const char *format_utf32(const uint32_t *s); uint32_t *ucs4parse(const char *s); const char *do_printf(const char *fmt, ...); -void test_addr(void); -void test_basen(void); -void test_cache(void); -void test_casefold(void); -void test_cookies(void); -void test_filepart(void); -void test_hash(void); -void test_heap(void); -void test_hex(void); -void test_kvp(void); -void test_mime(void); -void test_printf(void); -void test_regsub(void); -void test_selection(void); -void test_signame(void); -void test_sink(void); -void test_split(void); -void test_unicode(void); -void test_url(void); -void test_utf8(void); -void test_words(void); -void test_wstat(void); -void test_bits(void); -void test_vector(void); -void test_syscalls(void); -void test_trackname(void); +#define TEST(name) \ + int main(void) { \ + mem_init(); \ + fail_first = !!getenv("FAIL_FIRST"); \ + test_##name(); \ + if(errors) \ + fprintf(stderr, "test_"#name": %lld errors out of %lld tests\n", \ + errors, tests); \ + return !!errors; \ + } \ + \ + struct swallow_semicolon #endif /* TEST_H */ -- [mdw]