]> git.ozlabs.org Git - ccan/commitdiff
ccanlint: use ccan/autodata
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 5 Dec 2011 12:48:50 +0000 (23:18 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 5 Dec 2011 12:48:50 +0000 (23:18 +1030)
Gets rid of generated file.

tools/ccanlint/Makefile
tools/ccanlint/ccanlint.c
tools/ccanlint/ccanlint.h
tools/ccanlint/tests/info_documentation_exists.c
tools/ccanlint/tests/tests_exist.c
tools/ccanlint/tests/tests_pass_valgrind.c

index f079f8da438ce5a3475fedf26f3eedeae5a18365..c263d0d616d19220ba419b8ca3b73119140846a8 100644 (file)
@@ -3,6 +3,7 @@ TEST_OBJS := $(TEST_CFILES:.c=.o)
 
 CORE_OBJS := \
        ccan/asort/asort.o \
 
 CORE_OBJS := \
        ccan/asort/asort.o \
+       ccan/autodata/autodata.o \
        ccan/dgraph/dgraph.o \
        ccan/foreach/foreach.o \
        ccan/grab_file/grab_file.o \
        ccan/dgraph/dgraph.o \
        ccan/foreach/foreach.o \
        ccan/grab_file/grab_file.o \
@@ -14,6 +15,7 @@ CORE_OBJS := \
        ccan/opt/opt.o \
        ccan/opt/parse.o \
        ccan/opt/usage.o \
        ccan/opt/opt.o \
        ccan/opt/parse.o \
        ccan/opt/usage.o \
+       ccan/ptr_valid/ptr_valid.o \
        ccan/read_write_all/read_write_all.o \
        ccan/str/str.o ccan/str/debug.o \
        ccan/str_talloc/str_talloc.o \
        ccan/read_write_all/read_write_all.o \
        ccan/str/str.o ccan/str/debug.o \
        ccan/str_talloc/str_talloc.o \
@@ -32,17 +34,9 @@ CORE_OBJS := \
 
 OBJS := $(CORE_OBJS) $(TEST_OBJS)
 
 
 OBJS := $(CORE_OBJS) $(TEST_OBJS)
 
-# FIXME: write a trivial C program to do this
-tools/ccanlint/generated-testlist: $(TEST_CFILES)
-       cat $^ | grep ^REGISTER_TEST > $@
-
-$(TEST_OBJS): tools/ccanlint/generated-testlist
-
-# Otherwise, ccanlint.c et al. may fail to build
-$(CORE_OBJS): tools/ccanlint/generated-testlist config.h
+$(CORE_OBJS): config.h
 
 tools/ccanlint/ccanlint: $(OBJS)
 
 ccanlint-clean:
 
 tools/ccanlint/ccanlint: $(OBJS)
 
 ccanlint-clean:
-       $(RM) tools/ccanlint/generated-testlist
        $(RM) tools/ccanlint/ccanlint
        $(RM) tools/ccanlint/ccanlint
index d31ef94058f6d63b0030f5e85c6e971edbc60189..8c6ee1e4080410075a408efc1621041ab7637fb3 100644 (file)
@@ -279,19 +279,18 @@ static bool check_names(const char *member, struct ccanlint *c,
        return true;
 }
 
        return true;
 }
 
-#undef REGISTER_TEST
-#define REGISTER_TEST(name, ...) extern struct ccanlint name
-#include "generated-testlist"
-
 static void init_tests(void)
 {
        struct ccanlint_map names;
 static void init_tests(void)
 {
        struct ccanlint_map names;
+       struct ccanlint **table;
+       size_t i, num;
 
        strmap_init(&tests);
 
 
        strmap_init(&tests);
 
-#undef REGISTER_TEST
-#define REGISTER_TEST(name) register_test(&name)
-#include "generated-testlist"
+       table = autodata_get(ccanlint_tests, &num);
+       for (i = 0; i < num; i++)
+               register_test(table[i]);
+       autodata_free(table);
 
        strmap_iterate(&tests, init_deps, NULL);
 
 
        strmap_iterate(&tests, init_deps, NULL);
 
index fc92cd783c7dcd26a4717af2bbcca40d37f02351..b0acc910e164eef3361f3172b79964afbad01b8f 100644 (file)
@@ -3,11 +3,13 @@
 #include "config.h"
 #include <ccan/list/list.h>
 #include <ccan/dgraph/dgraph.h>
 #include "config.h"
 #include <ccan/list/list.h>
 #include <ccan/dgraph/dgraph.h>
+#include <ccan/autodata/autodata.h>
 #include <stdbool.h>
 #include "../doc_extract.h"
 #include "licenses.h"
 
 #include <stdbool.h>
 #include "../doc_extract.h"
 #include "licenses.h"
 
-#define REGISTER_TEST(name, ...) extern struct ccanlint name
+AUTODATA_TYPE(ccanlint_tests, struct ccanlint);
+#define REGISTER_TEST(test) AUTODATA(ccanlint_tests, &test)
 
 /* 0 == Describe failed tests.
    1 == Describe results for partial failures.
 
 /* 0 == Describe failed tests.
    1 == Describe results for partial failures.
index 6d914648ca19e3852de76632d3b2fac69523f476..7be0b797532727a6fe1acd8f9af7e1ac52780837 100644 (file)
 #include <ccan/noerr/noerr.h>
 #include <ccan/grab_file/grab_file.h>
 
 #include <ccan/noerr/noerr.h>
 #include <ccan/grab_file/grab_file.h>
 
-REGISTER_TEST(info_documentation_exists);
+static void check_info_documentation_exists(struct manifest *m,
+                                           unsigned int *timeleft,
+                                           struct score *score);
+
+static struct ccanlint info_documentation_exists = {
+       .key = "info_documentation_exists",
+       .name = "Module has documentation in _info",
+       .check = check_info_documentation_exists,
+       .needs = "info_exists"
+};
 
 static void create_info_template_doc(struct manifest *m, struct score *score)
 {
 
 static void create_info_template_doc(struct manifest *m, struct score *score)
 {
@@ -95,10 +104,5 @@ static void check_info_documentation_exists(struct manifest *m,
        }
 }
 
        }
 }
 
-struct ccanlint info_documentation_exists = {
-       .key = "info_documentation_exists",
-       .name = "Module has documentation in _info",
-       .check = check_info_documentation_exists,
-       .needs = "info_exists"
-};
+REGISTER_TEST(info_documentation_exists);
 
 
index 2fc1664fd254adda189ffd4a181bb9eeae3363a8..efa997536c969ee3373b4c6193664f99028bd9ed 100644 (file)
 #include <err.h>
 #include <ccan/talloc/talloc.h>
 
 #include <err.h>
 #include <ccan/talloc/talloc.h>
 
+static void check_tests_exist(struct manifest *m,
+                             unsigned int *timeleft, struct score *score);
+
+static struct ccanlint tests_exist = {
+       .key = "tests_exist",
+       .name = "Module has test directory with tests in it",
+       .check = check_tests_exist,
+       .needs = "info_exists"
+};
 REGISTER_TEST(tests_exist);
 
 static void handle_no_tests(struct manifest *m, struct score *score)
 REGISTER_TEST(tests_exist);
 
 static void handle_no_tests(struct manifest *m, struct score *score)
@@ -126,11 +135,3 @@ static void check_tests_exist(struct manifest *m,
        score->pass = true;
        score->score = score->total;
 }
        score->pass = true;
        score->score = score->total;
 }
-
-struct ccanlint tests_exist = {
-       .key = "tests_exist",
-       .name = "Module has test directory with tests in it",
-       .check = check_tests_exist,
-       .needs = "info_exists"
-};
-
index 8ccdad963ee072e88a32400ce3b3cba9f29ff987..773a85e66a5a17aca87595bb0ca8f67441158a2e 100644 (file)
@@ -18,9 +18,6 @@
 #include <string.h>
 #include <ctype.h>
 
 #include <string.h>
 #include <ctype.h>
 
-REGISTER_TEST(tests_pass_valgrind);
-REGISTER_TEST(tests_pass_valgrind_noleaks);
-
 /* Note: we already test safe_mode in run_tests.c */
 static const char *can_run_vg(struct manifest *m)
 {
 /* Note: we already test safe_mode in run_tests.c */
 static const char *can_run_vg(struct manifest *m)
 {
@@ -29,6 +26,20 @@ static const char *can_run_vg(struct manifest *m)
        return NULL;
 }
 
        return NULL;
 }
 
+static void do_leakcheck_vg(struct manifest *m,
+                           unsigned int *timeleft,
+                           struct score *score);
+
+static struct ccanlint tests_pass_valgrind_noleaks = {
+       .key = "tests_pass_valgrind_noleaks",
+       .name = "Module's run and api tests have no memory leaks",
+       .check = do_leakcheck_vg,
+       .takes_options = true,
+       .needs = "tests_pass_valgrind"
+};
+REGISTER_TEST(tests_pass_valgrind_noleaks);
+
+
 /* Example output:
 ==2749== Conditional jump or move depends on uninitialised value(s)
 ==2749==    at 0x4026C60: strnlen (mc_replace_strmem.c:263)
 /* Example output:
 ==2749== Conditional jump or move depends on uninitialised value(s)
 ==2749==    at 0x4026C60: strnlen (mc_replace_strmem.c:263)
@@ -257,12 +268,4 @@ struct ccanlint tests_pass_valgrind = {
        .takes_options = true,
        .needs = "tests_pass"
 };
        .takes_options = true,
        .needs = "tests_pass"
 };
-
-struct ccanlint tests_pass_valgrind_noleaks = {
-       .key = "tests_pass_valgrind_noleaks",
-       .name = "Module's run and api tests have no memory leaks",
-       .check = do_leakcheck_vg,
-       .takes_options = true,
-       .needs = "tests_pass_valgrind"
-};
-
+REGISTER_TEST(tests_pass_valgrind);