X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Frun_tests.c;h=380055c0259a8bc8d393ba0b4edbfcf11a43597d;hb=11e4a54f54b4f1f39eeabc390ae51b93b7f08e36;hp=2f657d0533ee8c92e5916ca09c529407b80d5257;hpb=37ca11df87fa3cc97aca321a76e564e4058d6900;p=ccan diff --git a/tools/run_tests.c b/tools/run_tests.c index 2f657d05..380055c0 100644 --- a/tools/run_tests.c +++ b/tools/run_tests.c @@ -4,9 +4,11 @@ #include #include #include +#include +#include #include "ccan/tap/tap.h" #include "ccan/talloc/talloc.h" -#include "ccan/string/string.h" +#include "ccan/str/str.h" #include "tools.h" /* FIXME: Use build bug later. */ @@ -19,7 +21,8 @@ static int verbose; struct test_type { const char *name; - void (*testfn)(const char *dir, struct test_type *t, const char *name); + void (*buildfn)(const char *dir, struct test_type *t, const char *name); + void (*runfn)(const char *name); }; struct test @@ -102,23 +105,10 @@ static int build(const char *dir, const char *name, int fail) { const char *cmd; int ret; - char *externals = talloc_strdup(name, ""); - char **deps; - for (deps = get_deps(objs, dir); *deps; deps++) { - char *end; - if (!strstarts(*deps, "ccan/")) - continue; - - end = strrchr(*deps, '/') + 1; - /* ccan/foo -> ccan/libfoo.a */ - externals = talloc_asprintf_append(externals, - " ccan/lib%s.a", end); - } - - cmd = talloc_asprintf(name, "gcc " CFLAGS " %s -o %s %s %s%s%s", + cmd = talloc_asprintf(name, "gcc " CFLAGS " %s -o %s %s %s -L. -lccan %s", fail ? "-DFAIL" : "", - output_name(name), name, obj_list(), externals, + output_name(name), name, obj_list(), verbose ? "" : "> /dev/null 2>&1"); if (verbose) @@ -144,10 +134,14 @@ static void compile_fail(const char *dir, struct test_type *t, const char *name) ok(build(dir, name, 1) > 0, "%s %s", t->name, name); } +static void no_run(const char *name) +{ +} + static void run(const char *name) { - if (system(output_name(name)) == -1) - fail("running %s had error %m", name); + if (system(output_name(name)) != 0) + fail("running %s had error", name); } static void cleanup(const char *name) @@ -156,9 +150,10 @@ static void cleanup(const char *name) } static struct test_type test_types[] = { - { "compile_ok", compile_ok }, - { "compile_fail", compile_fail }, - { "run", compile_ok }, + { "compile_ok", compile_ok, no_run }, + { "compile_fail", compile_fail, no_run }, + { "run", compile_ok, run }, + { "api", compile_ok, run }, }; int main(int argc, char *argv[]) @@ -207,14 +202,13 @@ int main(int argc, char *argv[]) /* Do all the test compilations. */ for (test = tests; test; test = test->next) - test->type->testfn(argv[1], test->type, test->name); + test->type->buildfn(argv[1], test->type, test->name); cleanup_objs(); /* Now run all the ones which wanted to run. */ for (test = tests; test; test = test->next) { - if (streq(test->type->name, "run")) - run(test->name); + test->type->runfn(test->name); cleanup(test->name); }