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 /* We run tests in the module directory, so any paths
41 * referenced can all be module-local. */
42 olddir = talloc_getcwd(m);
44 err(1, "Could not save cwd");
45 if (chdir(m->dir) != 0)
46 err(1, "Could not chdir to %s", m->dir);
50 list_for_each(&m->run_tests, i, list) {
51 run_tests.total_score++;
52 cmdout = run_command(m, timeleft, i->compiled);
54 res = talloc(list, struct run_tests_result);
56 res->output = talloc_steal(res, cmdout);
57 list_add_tail(list, &res->list);
61 list_for_each(&m->api_tests, i, list) {
62 run_tests.total_score++;
63 cmdout = run_command(m, timeleft, i->compiled);
65 res = talloc(list, struct run_tests_result);
67 res->output = talloc_steal(res, cmdout);
68 list_add_tail(list, &res->list);
72 if (list_empty(list)) {
77 if (chdir(olddir) != 0)
78 err(1, "Could not chdir to %s", olddir);
83 static unsigned int score_run_tests(struct manifest *m, void *check_result)
85 struct list_head *list = check_result;
86 struct run_tests_result *i;
87 unsigned int score = run_tests.total_score;
89 list_for_each(list, i, list)
94 static const char *describe_run_tests(struct manifest *m,
97 struct list_head *list = check_result;
98 char *descrip = talloc_strdup(check_result, "Running tests failed:\n");
99 struct run_tests_result *i;
101 list_for_each(list, i, list)
102 descrip = talloc_asprintf_append(descrip, "Running %s:\n%s",
103 i->file->name, i->output);
107 /* Gcc's warn_unused_result is fascist bullshit. */
108 #define doesnt_matter()
110 static void run_under_debugger(struct manifest *m, void *check_result)
113 struct list_head *list = check_result;
114 struct run_tests_result *first;
116 if (!ask("Should I run the first failing test under the debugger?"))
119 first = list_top(list, struct run_tests_result, list);
120 command = talloc_asprintf(m, "gdb -ex 'break tap.c:136' -ex 'run' %s",
121 first->file->compiled);
126 struct ccanlint run_tests = {
128 .name = "Module's run and api tests pass",
129 .score = score_run_tests,
130 .check = do_run_tests,
131 .describe = describe_run_tests,
133 .handle = run_under_debugger
136 REGISTER_TEST(run_tests, &compile_tests, NULL);