From 374d3d2eaa1b29dd3f3a940ca472bb209e95155d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 3 Nov 2010 23:25:57 +1030 Subject: [PATCH 1/1] ccanlint: make tests non-compulsory, always print score. No longer abort ccanlint because a test fails, but you will get a low score if there are no tests. (Note: total_score is filled in, even if it's overridden when the test is run. This means that if the prereq fails, that total counts so there is still a penalty!) --- tools/ccanlint/ccanlint.c | 3 ++- tools/ccanlint/tests/build-coverage.c | 1 + .../{compulsory_tests => tests}/compile_test_helpers.c | 5 +++-- tools/ccanlint/{compulsory_tests => tests}/compile_tests.c | 2 ++ tools/ccanlint/tests/examples_compile.c | 5 +++++ tools/ccanlint/{compulsory_tests => tests}/has_tests.c | 5 +++-- tools/ccanlint/tests/run-coverage.c | 2 +- tools/ccanlint/{compulsory_tests => tests}/run_tests.c | 2 ++ tools/ccanlint/tests/run_tests_valgrind.c | 2 ++ 9 files changed, 21 insertions(+), 6 deletions(-) rename tools/ccanlint/{compulsory_tests => tests}/compile_test_helpers.c (91%) rename tools/ccanlint/{compulsory_tests => tests}/compile_tests.c (99%) rename tools/ccanlint/{compulsory_tests => tests}/has_tests.c (98%) rename tools/ccanlint/{compulsory_tests => tests}/run_tests.c (98%) diff --git a/tools/ccanlint/ccanlint.c b/tools/ccanlint/ccanlint.c index ab805806..01a94758 100644 --- a/tools/ccanlint/ccanlint.c +++ b/tools/ccanlint/ccanlint.c @@ -407,12 +407,13 @@ int main(int argc, char *argv[]) talloc_asprintf(m, "%s/test", temp_dir(NULL))) != 0) err(1, "Creating test symlink in %s", temp_dir(NULL)); - /* If you don't pass the compulsory tests, you don't even get a score */ + /* If you don't pass the compulsory tests, you get a score of 0. */ if (verbose) printf("Compulsory tests:\n"); while ((i = get_next_test(&compulsory_tests)) != NULL) { if (!run_test(i, summary, &score, &total_score, m)) { + printf("%sTotal score: 0/%u\n", prefix, total_score); errx(1, "%s%s failed", prefix, i->name); } } diff --git a/tools/ccanlint/tests/build-coverage.c b/tools/ccanlint/tests/build-coverage.c index 7f750642..98f7948d 100644 --- a/tools/ccanlint/tests/build-coverage.c +++ b/tools/ccanlint/tests/build-coverage.c @@ -190,6 +190,7 @@ struct ccanlint compile_coverage_tests = { .key = "compile-coverage-tests", .name = "Module tests compile with profiling", .check = do_compile_coverage_tests, + .total_score = 1, .describe = describe_compile_coverage_tests, .can_run = can_run_coverage, }; diff --git a/tools/ccanlint/compulsory_tests/compile_test_helpers.c b/tools/ccanlint/tests/compile_test_helpers.c similarity index 91% rename from tools/ccanlint/compulsory_tests/compile_test_helpers.c rename to tools/ccanlint/tests/compile_test_helpers.c index 207c0b2d..0ab0cade 100644 --- a/tools/ccanlint/compulsory_tests/compile_test_helpers.c +++ b/tools/ccanlint/tests/compile_test_helpers.c @@ -21,7 +21,7 @@ static const char *can_build(struct manifest *m) return NULL; } -static char *compile(struct manifest *m, +static char *compile(struct manifest *m, bool keep, struct ccan_file *cfile) { @@ -37,6 +37,7 @@ static void *do_compile_test_helpers(struct manifest *m, char *cmdout = NULL; struct ccan_file *i; + compile_tests.total_score = 0; list_for_each(&m->other_test_c_files, i, list) { compile_tests.total_score++; cmdout = compile(m, keep, i); @@ -64,4 +65,4 @@ struct ccanlint compile_test_helpers = { .can_run = can_build, }; -REGISTER_TEST(compile_test_helpers, &depends_built); +REGISTER_TEST(compile_test_helpers, &depends_built, &has_tests, NULL); diff --git a/tools/ccanlint/compulsory_tests/compile_tests.c b/tools/ccanlint/tests/compile_tests.c similarity index 99% rename from tools/ccanlint/compulsory_tests/compile_tests.c rename to tools/ccanlint/tests/compile_tests.c index 1559bd18..3d6d3881 100644 --- a/tools/ccanlint/compulsory_tests/compile_tests.c +++ b/tools/ccanlint/tests/compile_tests.c @@ -100,6 +100,7 @@ static void *do_compile_tests(struct manifest *m, list_head_init(list); + compile_tests.total_score = 0; list_for_each(&m->compile_ok_tests, i, list) { compile_tests.total_score++; cmdout = compile(list, m, i, false, false, keep); @@ -196,6 +197,7 @@ struct ccanlint compile_tests = { .key = "compile-tests", .name = "Module tests compile", .score = score_compile_tests, + .total_score = 1, .check = do_compile_tests, .describe = describe_compile_tests, .can_run = can_build, diff --git a/tools/ccanlint/tests/examples_compile.c b/tools/ccanlint/tests/examples_compile.c index 82b47962..e66379f5 100644 --- a/tools/ccanlint/tests/examples_compile.c +++ b/tools/ccanlint/tests/examples_compile.c @@ -506,6 +506,11 @@ static void *build_examples(struct manifest *m, bool keep, /* This didn't work, so not a candidate for combining. */ prev = NULL; } + + if (strcmp(score->errors, "") == 0) { + talloc_free(score); + return NULL; + } return score; } diff --git a/tools/ccanlint/compulsory_tests/has_tests.c b/tools/ccanlint/tests/has_tests.c similarity index 98% rename from tools/ccanlint/compulsory_tests/has_tests.c rename to tools/ccanlint/tests/has_tests.c index f6ef4968..56eaf2a4 100644 --- a/tools/ccanlint/compulsory_tests/has_tests.c +++ b/tools/ccanlint/tests/has_tests.c @@ -31,7 +31,7 @@ static void *check_has_tests(struct manifest *m, if (list_empty(&m->api_tests) && list_empty(&m->run_tests) && list_empty(&m->compile_ok_tests)) { - if (list_empty(&m->compile_fail_tests)) + if (list_empty(&m->compile_fail_tests)) return "You have no tests in the test directory"; else return "You have no positive tests in the test directory"; @@ -124,13 +124,14 @@ static void handle_no_tests(struct manifest *m, void *check_result) fputs("}\n", run); fclose(run); -} +} struct ccanlint has_tests = { .key = "has-tests", .name = "Module has tests", .check = check_has_tests, .describe = describe_has_tests, + .total_score = 1, .handle = handle_no_tests, }; diff --git a/tools/ccanlint/tests/run-coverage.c b/tools/ccanlint/tests/run-coverage.c index 886aebd5..a1bd8dea 100644 --- a/tools/ccanlint/tests/run-coverage.c +++ b/tools/ccanlint/tests/run-coverage.c @@ -209,4 +209,4 @@ struct ccanlint run_coverage_tests = { .describe = describe_run_coverage_tests, }; -REGISTER_TEST(run_coverage_tests, &compile_coverage_tests, NULL); +REGISTER_TEST(run_coverage_tests, &compile_coverage_tests, &run_tests, NULL); diff --git a/tools/ccanlint/compulsory_tests/run_tests.c b/tools/ccanlint/tests/run_tests.c similarity index 98% rename from tools/ccanlint/compulsory_tests/run_tests.c rename to tools/ccanlint/tests/run_tests.c index e2ab9226..559a6378 100644 --- a/tools/ccanlint/compulsory_tests/run_tests.c +++ b/tools/ccanlint/tests/run_tests.c @@ -37,6 +37,7 @@ static void *do_run_tests(struct manifest *m, char *cmdout; list_head_init(list); + run_tests.total_score = 0; list_for_each(&m->run_tests, i, list) { run_tests.total_score++; @@ -115,6 +116,7 @@ struct ccanlint run_tests = { .key = "run", .name = "Module's run and api tests pass", .score = score_run_tests, + .total_score = 1, .check = do_run_tests, .describe = describe_run_tests, .can_run = can_run, diff --git a/tools/ccanlint/tests/run_tests_valgrind.c b/tools/ccanlint/tests/run_tests_valgrind.c index 4b425ea2..caf8323c 100644 --- a/tools/ccanlint/tests/run_tests_valgrind.c +++ b/tools/ccanlint/tests/run_tests_valgrind.c @@ -41,6 +41,7 @@ static void *do_run_tests_vg(struct manifest *m, char *cmdout; list_head_init(list); + run_tests_vg.total_score = 0; list_for_each(&m->run_tests, i, list) { run_tests_vg.total_score++; @@ -123,6 +124,7 @@ struct ccanlint run_tests_vg = { .key = "valgrind-tests", .name = "Module's run and api tests succeed under valgrind", .score = score_run_tests_vg, + .total_score = 1, .check = do_run_tests_vg, .describe = describe_run_tests_vg, .can_run = can_run_vg, -- 2.39.2