ccanlint: rename structures to match keys
[ccan] / tools / ccanlint / tests / compile_test_helpers.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 <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 static const char *can_run(struct manifest *m)
18 {
19         if (safe_mode)
20                 return "Safe mode enabled";
21         return NULL;
22 }
23
24 static bool compile(struct manifest *m,
25                     bool keep,
26                     struct ccan_file *cfile,
27                     char **output)
28 {
29         cfile->compiled = maybe_temp_file(m, ".o", keep, cfile->fullname);
30         return compile_object(m, cfile->fullname, ccan_dir, "",
31                               cfile->compiled, output);
32 }
33
34 static void do_compile_test_helpers(struct manifest *m,
35                                     bool keep,
36                                     unsigned int *timeleft,
37                                     struct score *score)
38 {
39         struct ccan_file *i;
40         bool errors = false, warnings = false;
41
42         if (list_empty(&m->other_test_c_files))
43                 score->total = 0;
44         else
45                 score->total = 2;
46
47         list_for_each(&m->other_test_c_files, i, list) {
48                 char *cmdout;
49
50                 if (!compile(m, keep, i, &cmdout)) {
51                         errors = true;
52                         score->error = "Failed to compile helper C files";
53                         score_file_error(score, i, 0, cmdout);
54                 } else if (!streq(cmdout, "")) {
55                         warnings = true;
56                         score->error = "Helper C files gave warnings";
57                         score_file_error(score, i, 0, cmdout);
58                 }
59         }
60
61         if (!errors) {
62                 score->pass = true;
63                 score->score = score->total - warnings;
64         }
65 }
66
67 struct ccanlint tests_helpers_compile = {
68         .key = "tests_helpers_compile",
69         .name = "Module test helper objects compile",
70         .check = do_compile_test_helpers,
71         .can_run = can_run,
72         .needs = "depends_build tests_exist"
73 };
74
75 REGISTER_TEST(tests_helpers_compile);