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, unsigned int *timeleft)
32 struct list_head *list = talloc(m, struct list_head);
33 struct run_tests_result *res;
38 /* We run tests in the module directory, so any paths
39 * referenced can all be module-local. */
40 olddir = talloc_getcwd(m);
42 err(1, "Could not save cwd");
43 if (chdir(m->dir) != 0)
44 err(1, "Could not chdir to %s", m->dir);
48 list_for_each(&m->run_tests, i, list) {
49 run_tests.total_score++;
50 cmdout = run_command(m, timeleft, i->compiled);
52 res = talloc(list, struct run_tests_result);
54 res->output = talloc_steal(res, cmdout);
55 list_add_tail(list, &res->list);
59 list_for_each(&m->api_tests, i, list) {
60 run_tests.total_score++;
61 cmdout = run_command(m, timeleft, i->compiled);
63 res = talloc(list, struct run_tests_result);
65 res->output = talloc_steal(res, cmdout);
66 list_add_tail(list, &res->list);
70 if (list_empty(list)) {
75 if (chdir(olddir) != 0)
76 err(1, "Could not chdir to %s", olddir);
81 static unsigned int score_run_tests(struct manifest *m, void *check_result)
83 struct list_head *list = check_result;
84 struct run_tests_result *i;
85 unsigned int score = run_tests.total_score;
87 list_for_each(list, i, list)
92 static const char *describe_run_tests(struct manifest *m,
95 struct list_head *list = check_result;
96 char *descrip = talloc_strdup(check_result, "Running tests failed:\n");
97 struct run_tests_result *i;
99 list_for_each(list, i, list)
100 descrip = talloc_asprintf_append(descrip, "Running %s:\n%s",
101 i->file->name, i->output);
105 /* Gcc's warn_unused_result is fascist bullshit. */
106 #define doesnt_matter()
108 static void run_under_debugger(struct manifest *m, void *check_result)
111 struct list_head *list = check_result;
112 struct run_tests_result *first;
114 if (!ask("Should I run the first failing test under the debugger?"))
117 first = list_top(list, struct run_tests_result, list);
118 command = talloc_asprintf(m, "gdb -ex 'break tap.c:136' -ex 'run' %s",
119 first->file->compiled);
124 struct ccanlint run_tests = {
126 .name = "Module's run and api tests pass",
127 .score = score_run_tests,
128 .check = do_run_tests,
129 .describe = describe_run_tests,
131 .handle = run_under_debugger
134 REGISTER_TEST(run_tests, &compile_tests, NULL);