X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Fcompile_test_helpers.c;h=5763463ad178e709df940b168ad68b1fe9ba19b5;hb=9d511cc5b12021b6c6c079fc5b08487fdf361a26;hp=de8d4632c9fbea9aa9ff992a2b0a0eb78a879d91;hpb=687cde2a8c561b68f17609b615eb930ea02f5aac;p=ccan diff --git a/tools/ccanlint/tests/compile_test_helpers.c b/tools/ccanlint/tests/compile_test_helpers.c index de8d4632..5763463a 100644 --- a/tools/ccanlint/tests/compile_test_helpers.c +++ b/tools/ccanlint/tests/compile_test_helpers.c @@ -14,52 +14,61 @@ #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 char *compile(struct manifest *m, struct ccan_file *cfile) +static bool compile(struct manifest *m, + bool keep, + struct ccan_file *cfile, + char **output) { - char *err; - - cfile->compiled = compile_object(m, cfile->name, &err); - if (cfile->compiled) - return NULL; - return err; + cfile->compiled = maybe_temp_file(m, ".o", keep, cfile->fullname); + return compile_object(m, cfile->fullname, ccan_dir, "", + cfile->compiled, 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; + bool errors = false, warnings = false; + + if (list_empty(&m->other_test_c_files)) + score->total = 0; + else + score->total = 2; list_for_each(&m->other_test_c_files, i, list) { - compile_tests.total_score++; - cmdout = compile(m, i); - if (cmdout) - return talloc_asprintf(m, - "Failed to compile helper C" - " code file %s:\n%s", - i->name, cmdout); + char *cmdout; + + if (!compile(m, keep, i, &cmdout)) { + errors = true; + score->error = "Failed to compile helper C files"; + score_file_error(score, i, 0, cmdout); + } else if (!streq(cmdout, "")) { + warnings = true; + score->error = "Helper C files gave warnings"; + 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 (!errors) { + score->pass = true; + score->score = score->total - warnings; + } } 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);