1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
17 static const char *can_run(struct manifest *m)
20 return "Safe mode enabled";
24 struct run_tests_result {
25 struct list_node list;
26 struct ccan_file *file;
30 static void *do_run_tests(struct manifest *m,
32 unsigned int *timeleft)
34 struct list_head *list = talloc(m, struct list_head);
35 struct run_tests_result *res;
40 run_tests.total_score = 0;
42 list_for_each(&m->run_tests, i, list) {
43 run_tests.total_score++;
44 cmdout = run_command(m, timeleft, i->compiled);
46 res = talloc(list, struct run_tests_result);
48 res->output = talloc_steal(res, cmdout);
49 list_add_tail(list, &res->list);
53 list_for_each(&m->api_tests, i, list) {
54 run_tests.total_score++;
55 cmdout = run_command(m, timeleft, i->compiled);
57 res = talloc(list, struct run_tests_result);
59 res->output = talloc_steal(res, cmdout);
60 list_add_tail(list, &res->list);
64 if (list_empty(list)) {
72 static unsigned int score_run_tests(struct manifest *m, void *check_result)
74 struct list_head *list = check_result;
75 struct run_tests_result *i;
76 unsigned int score = run_tests.total_score;
78 list_for_each(list, i, list)
83 static const char *describe_run_tests(struct manifest *m,
86 struct list_head *list = check_result;
87 char *descrip = talloc_strdup(check_result, "Running tests failed:\n");
88 struct run_tests_result *i;
90 list_for_each(list, i, list)
91 descrip = talloc_asprintf_append(descrip, "Running %s:\n%s",
92 i->file->name, i->output);
96 /* Gcc's warn_unused_result is fascist bullshit. */
97 #define doesnt_matter()
99 static void run_under_debugger(struct manifest *m, void *check_result)
102 struct list_head *list = check_result;
103 struct run_tests_result *first;
105 if (!ask("Should I run the first failing test under the debugger?"))
108 first = list_top(list, struct run_tests_result, list);
109 command = talloc_asprintf(m, "gdb -ex 'break tap.c:136' -ex 'run' %s",
110 first->file->compiled);
115 struct ccanlint run_tests = {
117 .name = "Module's run and api tests pass",
118 .score = score_run_tests,
120 .check = do_run_tests,
121 .describe = describe_run_tests,
123 .handle = run_under_debugger
126 REGISTER_TEST(run_tests, &compile_tests, NULL);