Browse Source

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!)
Rusty Russell 15 years ago
parent
commit
374d3d2eaa

+ 2 - 1
tools/ccanlint/ccanlint.c

@@ -407,12 +407,13 @@ int main(int argc, char *argv[])
 		    talloc_asprintf(m, "%s/test", temp_dir(NULL))) != 0)
 		    talloc_asprintf(m, "%s/test", temp_dir(NULL))) != 0)
 		err(1, "Creating test symlink in %s", temp_dir(NULL));
 		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)
 	if (verbose)
 		printf("Compulsory tests:\n");
 		printf("Compulsory tests:\n");
 
 
 	while ((i = get_next_test(&compulsory_tests)) != NULL) {
 	while ((i = get_next_test(&compulsory_tests)) != NULL) {
 		if (!run_test(i, summary, &score, &total_score, m)) {
 		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);
 			errx(1, "%s%s failed", prefix, i->name);
 		}
 		}
 	}
 	}

+ 1 - 0
tools/ccanlint/tests/build-coverage.c

@@ -190,6 +190,7 @@ struct ccanlint compile_coverage_tests = {
 	.key = "compile-coverage-tests",
 	.key = "compile-coverage-tests",
 	.name = "Module tests compile with profiling",
 	.name = "Module tests compile with profiling",
 	.check = do_compile_coverage_tests,
 	.check = do_compile_coverage_tests,
+	.total_score = 1,
 	.describe = describe_compile_coverage_tests,
 	.describe = describe_compile_coverage_tests,
 	.can_run = can_run_coverage,
 	.can_run = can_run_coverage,
 };
 };

+ 3 - 2
tools/ccanlint/compulsory_tests/compile_test_helpers.c → tools/ccanlint/tests/compile_test_helpers.c

@@ -21,7 +21,7 @@ static const char *can_build(struct manifest *m)
 	return NULL;
 	return NULL;
 }
 }
 
 
-static char *compile(struct manifest *m, 
+static char *compile(struct manifest *m,
 		     bool keep,
 		     bool keep,
 		     struct ccan_file *cfile)
 		     struct ccan_file *cfile)
 {
 {
@@ -37,6 +37,7 @@ static void *do_compile_test_helpers(struct manifest *m,
 	char *cmdout = NULL;
 	char *cmdout = NULL;
 	struct ccan_file *i;
 	struct ccan_file *i;
 
 
+	compile_tests.total_score = 0;
 	list_for_each(&m->other_test_c_files, i, list) {
 	list_for_each(&m->other_test_c_files, i, list) {
 		compile_tests.total_score++;
 		compile_tests.total_score++;
 		cmdout = compile(m, keep, i);
 		cmdout = compile(m, keep, i);
@@ -64,4 +65,4 @@ struct ccanlint compile_test_helpers = {
 	.can_run = can_build,
 	.can_run = can_build,
 };
 };
 
 
-REGISTER_TEST(compile_test_helpers, &depends_built);
+REGISTER_TEST(compile_test_helpers, &depends_built, &has_tests, NULL);

+ 2 - 0
tools/ccanlint/compulsory_tests/compile_tests.c → tools/ccanlint/tests/compile_tests.c

@@ -100,6 +100,7 @@ static void *do_compile_tests(struct manifest *m,
 
 
 	list_head_init(list);
 	list_head_init(list);
 
 
+	compile_tests.total_score = 0;
 	list_for_each(&m->compile_ok_tests, i, list) {
 	list_for_each(&m->compile_ok_tests, i, list) {
 		compile_tests.total_score++;
 		compile_tests.total_score++;
 		cmdout = compile(list, m, i, false, false, keep);
 		cmdout = compile(list, m, i, false, false, keep);
@@ -196,6 +197,7 @@ struct ccanlint compile_tests = {
 	.key = "compile-tests",
 	.key = "compile-tests",
 	.name = "Module tests compile",
 	.name = "Module tests compile",
 	.score = score_compile_tests,
 	.score = score_compile_tests,
+	.total_score = 1,
 	.check = do_compile_tests,
 	.check = do_compile_tests,
 	.describe = describe_compile_tests,
 	.describe = describe_compile_tests,
 	.can_run = can_build,
 	.can_run = can_build,

+ 5 - 0
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. */
 		/* This didn't work, so not a candidate for combining. */
 		prev = NULL;
 		prev = NULL;
 	}
 	}
+
+	if (strcmp(score->errors, "") == 0) {
+		talloc_free(score);
+		return NULL;
+	}
 	return score;
 	return score;
 }
 }
 
 

+ 3 - 2
tools/ccanlint/compulsory_tests/has_tests.c → tools/ccanlint/tests/has_tests.c

@@ -31,7 +31,7 @@ static void *check_has_tests(struct manifest *m,
 	if (list_empty(&m->api_tests)
 	if (list_empty(&m->api_tests)
 	    && list_empty(&m->run_tests)
 	    && list_empty(&m->run_tests)
 	    && list_empty(&m->compile_ok_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";
 			return "You have no tests in the test directory";
 		else
 		else
 			return "You have no positive tests in the test directory";
 			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);
 	fputs("}\n", run);
 
 
 	fclose(run);
 	fclose(run);
-}	
+}
 
 
 struct ccanlint has_tests = {
 struct ccanlint has_tests = {
 	.key = "has-tests",
 	.key = "has-tests",
 	.name = "Module has tests",
 	.name = "Module has tests",
 	.check = check_has_tests,
 	.check = check_has_tests,
 	.describe = describe_has_tests,
 	.describe = describe_has_tests,
+	.total_score = 1,
 	.handle = handle_no_tests,
 	.handle = handle_no_tests,
 };
 };
 
 

+ 1 - 1
tools/ccanlint/tests/run-coverage.c

@@ -209,4 +209,4 @@ struct ccanlint run_coverage_tests = {
 	.describe = describe_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);

+ 2 - 0
tools/ccanlint/compulsory_tests/run_tests.c → tools/ccanlint/tests/run_tests.c

@@ -37,6 +37,7 @@ static void *do_run_tests(struct manifest *m,
 	char *cmdout;
 	char *cmdout;
 
 
 	list_head_init(list);
 	list_head_init(list);
+	run_tests.total_score = 0;
 
 
 	list_for_each(&m->run_tests, i, list) {
 	list_for_each(&m->run_tests, i, list) {
 		run_tests.total_score++;
 		run_tests.total_score++;
@@ -115,6 +116,7 @@ struct ccanlint run_tests = {
 	.key = "run",
 	.key = "run",
 	.name = "Module's run and api tests pass",
 	.name = "Module's run and api tests pass",
 	.score = score_run_tests,
 	.score = score_run_tests,
+	.total_score = 1,
 	.check = do_run_tests,
 	.check = do_run_tests,
 	.describe = describe_run_tests,
 	.describe = describe_run_tests,
 	.can_run = can_run,
 	.can_run = can_run,

+ 2 - 0
tools/ccanlint/tests/run_tests_valgrind.c

@@ -41,6 +41,7 @@ static void *do_run_tests_vg(struct manifest *m,
 	char *cmdout;
 	char *cmdout;
 
 
 	list_head_init(list);
 	list_head_init(list);
+	run_tests_vg.total_score = 0;
 
 
 	list_for_each(&m->run_tests, i, list) {
 	list_for_each(&m->run_tests, i, list) {
 		run_tests_vg.total_score++;
 		run_tests_vg.total_score++;
@@ -123,6 +124,7 @@ struct ccanlint run_tests_vg = {
 	.key = "valgrind-tests",
 	.key = "valgrind-tests",
 	.name = "Module's run and api tests succeed under valgrind",
 	.name = "Module's run and api tests succeed under valgrind",
 	.score = score_run_tests_vg,
 	.score = score_run_tests_vg,
+	.total_score = 1,
 	.check = do_run_tests_vg,
 	.check = do_run_tests_vg,
 	.describe = describe_run_tests_vg,
 	.describe = describe_run_tests_vg,
 	.can_run = can_run_vg,
 	.can_run = can_run_vg,