]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/tests/tests_pass_without_features.c
Merge Makefile rewrite into master
[ccan] / tools / ccanlint / tests / tests_pass_without_features.c
1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/str/str.h>
4 #include <ccan/foreach/foreach.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <unistd.h>
9 #include <limits.h>
10 #include <errno.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <err.h>
14 #include <string.h>
15 #include <ctype.h>
16
17 /* We don't do these under valgrind: too slow! */
18 static void do_run_tests_no_features(struct manifest *m,
19                                      unsigned int *timeleft,
20                                      struct score *score)
21 {
22         struct list_head *list;
23         struct ccan_file *i;
24         char *cmdout;
25
26         score->total = 0;
27         foreach_ptr(list, &m->run_tests, &m->api_tests) {
28                 list_for_each(list, i, list) {
29                         score->total++;
30                         if (verbose >= 2)
31                                 printf("   %s\n", i->name);
32                         if (run_command(m, timeleft, &cmdout, "%s",
33                                         i->compiled[COMPILE_NOFEAT]))
34                                 score->score++;
35                         else
36                                 score_file_error(score, i, 0, "%s", cmdout);
37                 }
38         }
39
40         if (score->score == score->total)
41                 score->pass = true;
42 }
43
44 /* Gcc's warn_unused_result is fascist bullshit. */
45 #define doesnt_matter()
46
47 static void run_under_debugger(struct manifest *m, struct score *score)
48 {
49         char *command;
50         struct file_error *first;
51
52         first = list_top(&score->per_file_errors, struct file_error, list);
53
54         if (!ask("Should I run the first failing test under the debugger?"))
55                 return;
56
57         command = tal_fmt(m, "gdb -ex 'break tap.c:139' -ex 'run' %s",
58                           first->file->compiled[COMPILE_NOFEAT]);
59         if (system(command)) {
60                 doesnt_matter();
61         }
62 }
63
64 struct ccanlint tests_pass_without_features = {
65         .key = "tests_pass_without_features",
66         .name = "Module's run and api tests pass (without features)",
67         .check = do_run_tests_no_features,
68         .handle = run_under_debugger,
69         .needs = "tests_compile_without_features"
70 };
71
72 REGISTER_TEST(tests_pass_without_features);