ccanlint: show each test as we execute it with -vv
[ccan] / tools / ccanlint / tests / tests_pass_without_features.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 /* We don't do these under valgrind: too slow! */
19 static void do_run_tests_no_features(struct manifest *m,
20                                      bool keep,
21                                      unsigned int *timeleft,
22                                      struct score *score)
23 {
24         struct list_head *list;
25         struct ccan_file *i;
26         char *cmdout;
27
28         score->total = 0;
29         foreach_ptr(list, &m->run_tests, &m->api_tests) {
30                 list_for_each(list, i, list) {
31                         score->total++;
32                         if (verbose >= 2)
33                                 printf("   %s\n", i->name);
34                         if (run_command(m, timeleft, &cmdout, "%s",
35                                         i->compiled[COMPILE_NOFEAT]))
36                                 score->score++;
37                         else
38                                 score_file_error(score, i, 0, "%s", cmdout);
39                 }
40         }
41
42         if (score->score == score->total)
43                 score->pass = true;
44 }
45
46 /* Gcc's warn_unused_result is fascist bullshit. */
47 #define doesnt_matter()
48
49 static void run_under_debugger(struct manifest *m, struct score *score)
50 {
51         char *command;
52         struct file_error *first;
53
54         first = list_top(&score->per_file_errors, struct file_error, list);
55
56         if (!ask("Should I run the first failing test under the debugger?"))
57                 return;
58
59         command = talloc_asprintf(m, "gdb -ex 'break tap.c:139' -ex 'run' %s",
60                                   first->file->compiled
61                                   [COMPILE_NOFEAT]);
62         if (system(command))
63                 doesnt_matter();
64 }
65
66 struct ccanlint tests_pass_without_features = {
67         .key = "tests_pass_without_features",
68         .name = "Module's run and api tests pass (without features)",
69         .check = do_run_tests_no_features,
70         .handle = run_under_debugger,
71         .needs = "tests_compile_without_features"
72 };
73
74 REGISTER_TEST(tests_pass_without_features);