X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Frun_tests.c;h=0edfad262c4ba02299052231691b23ce40784ff7;hp=875ba758e43a70a036d3290c6ecf11effe3bc41c;hb=2926cafb52b9d95646d9dafa877d53f2368d8b2c;hpb=156dfda864bc2a0fe2ba63f69c22864b2348876f diff --git a/tools/ccanlint/tests/run_tests.c b/tools/ccanlint/tests/run_tests.c index 875ba758..0edfad26 100644 --- a/tools/ccanlint/tests/run_tests.c +++ b/tools/ccanlint/tests/run_tests.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -21,68 +22,56 @@ static const char *can_run(struct manifest *m) return NULL; } -static void *do_run_tests(struct manifest *m) +static void do_run_tests(struct manifest *m, + bool keep, + unsigned int *timeleft, + struct score *score) { - struct list_head *list = talloc(m, struct list_head); - char *failures = talloc_strdup(m, ""); + struct list_head *list; struct ccan_file *i; + char *cmdout; - list_head_init(list); - - list_for_each(&m->run_tests, i, list) { - char *testout; - run_tests.total_score++; - /* FIXME: timeout here */ - testout = run_command(m, i->compiled); - if (!testout) - continue; - failures = talloc_asprintf_append(failures, - "Running %s failed:\n", - i->name); - failures = talloc_append_string(failures, testout); - } - - list_for_each(&m->api_tests, i, list) { - char *testout; - run_tests.total_score++; - /* FIXME: timeout here */ - testout = run_command(m, i->compiled); - if (!testout) - continue; - failures = talloc_asprintf_append(failures, - "Running %s failed:\n", - i->name); - failures = talloc_append_string(failures, testout); - } - - if (streq(failures, "")) { - talloc_free(failures); - failures = NULL; + score->total = 0; + foreach_ptr(list, &m->run_tests, &m->api_tests) { + list_for_each(list, i, list) { + score->total++; + if (run_command(m, timeleft, &cmdout, "%s", + i->compiled)) + score->score++; + else + score_file_error(score, i, 0, cmdout); + } } - return failures; + if (score->score == score->total) + score->pass = true; } -static unsigned int score_run_tests(struct manifest *m, void *check_result) -{ - /* FIXME: be cleverer here */ - return 0; -} +/* Gcc's warn_unused_result is fascist bullshit. */ +#define doesnt_matter() -static const char *describe_run_tests(struct manifest *m, - void *check_result) +static void run_under_debugger(struct manifest *m, struct score *score) { - char *descrip = talloc_strdup(check_result, "Running tests failed:\n"); + char *command; + struct file_error *first; + + if (!ask("Should I run the first failing test under the debugger?")) + return; - return talloc_append_string(descrip, check_result); + first = list_top(&score->per_file_errors, struct file_error, list); + command = talloc_asprintf(m, "gdb -ex 'break tap.c:136' -ex 'run' %s", + first->file->compiled); + if (system(command)) + doesnt_matter(); } -struct ccanlint run_tests = { - .name = "run and api tests run successfully", - .score = score_run_tests, +struct ccanlint tests_pass = { + .key = "tests_pass", + .name = "Module's run and api tests pass", .check = do_run_tests, - .describe = describe_run_tests, + .handle = run_under_debugger, .can_run = can_run, + .needs = "tests_compile" }; -REGISTER_TEST(run_tests, &compile_tests, NULL); +REGISTER_TEST(tests_pass);