X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Fcompile_test_helpers.c;h=3d5a8a74548a3c83f9213d4ae8a7fedac1e4b23a;hp=017a5308cbc4b48f6cba5b5f7bb6cae615efbdcc;hb=03a596908b779bbb4b7c2f739c5e238f8c5d6390;hpb=4e0dfdadf206c74dc9e5f302545b2419cc4798f4 diff --git a/tools/ccanlint/tests/compile_test_helpers.c b/tools/ccanlint/tests/compile_test_helpers.c index 017a5308..3d5a8a74 100644 --- a/tools/ccanlint/tests/compile_test_helpers.c +++ b/tools/ccanlint/tests/compile_test_helpers.c @@ -14,62 +14,56 @@ #include #include -static const char *can_build(struct manifest *m) +static const char *can_run(struct manifest *m) { if (safe_mode) return "Safe mode enabled"; return NULL; } -static int cleanup_testfile(char *testfile) +static char *compile(struct manifest *m, + bool keep, + struct ccan_file *cfile) { - unlink(testfile); - return 0; -} - -static char *objname(const void *ctx, const char *cfile) -{ - return talloc_asprintf(ctx, "%.*s.o ", strlen(cfile) - 2, cfile); -} - -static char *compile(struct manifest *m, const char *cfile) -{ - char *obj; - - obj = objname(m, cfile); - talloc_set_destructor(obj, cleanup_testfile); - return run_command(m, "cc " CFLAGS " -c -o %s %s", obj, cfile); + char *output; + cfile->compiled = maybe_temp_file(m, ".o", keep, cfile->fullname); + if (compile_object(m, cfile->fullname, ccan_dir, "", + cfile->compiled, &output)) { + talloc_free(output); + return NULL; + } + return output; } -static void *do_compile_test_helpers(struct manifest *m) +static void do_compile_test_helpers(struct manifest *m, + bool keep, + unsigned int *timeleft, + struct score *score) { - char *cmdout = NULL; struct ccan_file *i; + if (list_empty(&m->other_test_c_files)) + score->total = 0; + list_for_each(&m->other_test_c_files, i, list) { - compile_tests.total_score++; - cmdout = compile(m, i->name); - if (cmdout) - return talloc_asprintf(m, - "Failed to compile helper C" - " code file %s:\n%s", - i->name, cmdout); + char *cmdout = compile(m, keep, i); + if (cmdout) { + score->error = "Failed to compile helper C files"; + score_file_error(score, i, 0, cmdout); + } } - return NULL; -} -static const char *describe_compile_test_helpers(struct manifest *m, - void *check_result) -{ - return check_result; + if (!score->error) { + score->pass = true; + score->score = score->total; + } } struct ccanlint compile_test_helpers = { - .name = "Compiling test helper files", - .total_score = 1, + .key = "compile-helpers", + .name = "Module test helper objects compile", .check = do_compile_test_helpers, - .describe = describe_compile_test_helpers, - .can_run = can_build, + .can_run = can_run, }; -REGISTER_TEST(compile_test_helpers, &depends_built); +REGISTER_TEST(compile_test_helpers, &depends_built, &has_tests, NULL);