]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/tests/compile_test_helpers.c
3d5a8a74548a3c83f9213d4ae8a7fedac1e4b23a
[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 char *compile(struct manifest *m,
25                      bool keep,
26                      struct ccan_file *cfile)
27 {
28         char *output;
29         cfile->compiled = maybe_temp_file(m, ".o", keep, cfile->fullname);
30         if (compile_object(m, cfile->fullname, ccan_dir, "",
31                            cfile->compiled, &output)) {
32                 talloc_free(output);
33                 return NULL;
34         }
35         return output;
36 }
37
38 static void do_compile_test_helpers(struct manifest *m,
39                                     bool keep,
40                                     unsigned int *timeleft,
41                                     struct score *score)
42 {
43         struct ccan_file *i;
44
45         if (list_empty(&m->other_test_c_files))
46                 score->total = 0;
47
48         list_for_each(&m->other_test_c_files, i, list) {
49                 char *cmdout = compile(m, keep, i);
50                 if (cmdout) {
51                         score->error = "Failed to compile helper C files";
52                         score_file_error(score, i, 0, cmdout);
53                 }
54         }
55
56         if (!score->error) {
57                 score->pass = true;
58                 score->score = score->total;
59         }
60 }
61
62 struct ccanlint compile_test_helpers = {
63         .key = "compile-helpers",
64         .name = "Module test helper objects compile",
65         .check = do_compile_test_helpers,
66         .can_run = can_run,
67 };
68
69 REGISTER_TEST(compile_test_helpers, &depends_built, &has_tests, NULL);