X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Frun_tests.c;h=f32e0534ff11d1272e3e76c0ceb3498e6e155e8e;hb=03a596908b779bbb4b7c2f739c5e238f8c5d6390;hp=33daff033a74673cef2513d3bd07ee11f4c05252;hpb=0c532d80a73cae44360595c762dddefcd7e0a4ec;p=ccan diff --git a/tools/ccanlint/tests/run_tests.c b/tools/ccanlint/tests/run_tests.c index 33daff03..f32e0534 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,69 +22,54 @@ 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; - return talloc_append_string(descrip, check_result); -} + if (!ask("Should I run the first failing test under the debugger?")) + return; -/* FIXME: Handle by offering to run under debugger... */ + 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, + .key = "run", + .name = "Module's run and api tests pass", .check = do_run_tests, - .describe = describe_run_tests, + .handle = run_under_debugger, .can_run = can_run, };