ccanlint: list dependencies by key
[ccan] / tools / ccanlint / tests / run_tests.c
1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
5 #include <ccan/foreach/foreach.h>
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <fcntl.h>
9 #include <unistd.h>
10 #include <limits.h>
11 #include <errno.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <err.h>
15 #include <string.h>
16 #include <ctype.h>
17
18 static const char *can_run(struct manifest *m)
19 {
20         if (safe_mode)
21                 return "Safe mode enabled";
22         return NULL;
23 }
24
25 static void do_run_tests(struct manifest *m,
26                          bool keep,
27                          unsigned int *timeleft,
28                          struct score *score)
29 {
30         struct list_head *list;
31         struct ccan_file *i;
32         char *cmdout;
33
34         score->total = 0;
35         foreach_ptr(list, &m->run_tests, &m->api_tests) {
36                 list_for_each(list, i, list) {
37                         score->total++;
38                         if (run_command(m, timeleft, &cmdout, "%s",
39                                         i->compiled))
40                                 score->score++;
41                         else
42                                 score_file_error(score, i, 0, cmdout);
43                 }
44         }
45
46         if (score->score == score->total)
47                 score->pass = true;
48 }
49
50 /* Gcc's warn_unused_result is fascist bullshit. */
51 #define doesnt_matter()
52
53 static void run_under_debugger(struct manifest *m, struct score *score)
54 {
55         char *command;
56         struct file_error *first;
57
58         if (!ask("Should I run the first failing test under the debugger?"))
59                 return;
60
61         first = list_top(&score->per_file_errors, struct file_error, list);
62         command = talloc_asprintf(m, "gdb -ex 'break tap.c:136' -ex 'run' %s",
63                                   first->file->compiled);
64         if (system(command))
65                 doesnt_matter();
66 }
67
68 struct ccanlint run_tests = {
69         .key = "tests_pass",
70         .name = "Module's run and api tests pass",
71         .check = do_run_tests,
72         .handle = run_under_debugger,
73         .can_run = can_run,
74         .needs = "tests_compile"
75 };
76
77 REGISTER_TEST(run_tests);