X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Ftests_pass.c;fp=tools%2Fccanlint%2Ftests%2Ftests_pass.c;h=0edfad262c4ba02299052231691b23ce40784ff7;hb=051db34fb275491d4d5dfa5bf7970e8e525766d8;hp=0000000000000000000000000000000000000000;hpb=2926cafb52b9d95646d9dafa877d53f2368d8b2c;p=ccan diff --git a/tools/ccanlint/tests/tests_pass.c b/tools/ccanlint/tests/tests_pass.c new file mode 100644 index 00000000..0edfad26 --- /dev/null +++ b/tools/ccanlint/tests/tests_pass.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const char *can_run(struct manifest *m) +{ + if (safe_mode) + return "Safe mode enabled"; + return NULL; +} + +static void do_run_tests(struct manifest *m, + bool keep, + unsigned int *timeleft, + struct score *score) +{ + struct list_head *list; + struct ccan_file *i; + char *cmdout; + + 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); + } + } + + if (score->score == score->total) + score->pass = true; +} + +/* Gcc's warn_unused_result is fascist bullshit. */ +#define doesnt_matter() + +static void run_under_debugger(struct manifest *m, struct score *score) +{ + char *command; + struct file_error *first; + + if (!ask("Should I run the first failing test under the debugger?")) + return; + + 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 tests_pass = { + .key = "tests_pass", + .name = "Module's run and api tests pass", + .check = do_run_tests, + .handle = run_under_debugger, + .can_run = can_run, + .needs = "tests_compile" +}; + +REGISTER_TEST(tests_pass);