]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/tests/compile_test_helpers.c
Web updates.
[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_build(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, struct ccan_file *cfile)
25 {
26         char *err;
27
28         cfile->compiled = compile_object(m, cfile->name, &err);
29         if (cfile->compiled)
30                 return NULL;
31         return err;
32 }
33
34 static void *do_compile_test_helpers(struct manifest *m)
35 {
36         char *cmdout = NULL;
37         struct ccan_file *i;
38
39         list_for_each(&m->other_test_c_files, i, list) {
40                 compile_tests.total_score++;
41                 cmdout = compile(m, i);
42                 if (cmdout)
43                         return talloc_asprintf(m,
44                                                "Failed to compile helper C"
45                                                " code file %s:\n%s",
46                                                i->name, cmdout);
47         }
48         return NULL;
49 }
50
51 static const char *describe_compile_test_helpers(struct manifest *m,
52                                                  void *check_result)
53 {
54         return check_result;
55 }
56
57 struct ccanlint compile_test_helpers = {
58         .name = "Compiling test helper files",
59         .total_score = 1,
60         .check = do_compile_test_helpers,
61         .describe = describe_compile_test_helpers,
62         .can_run = can_build,
63 };
64
65 REGISTER_TEST(compile_test_helpers, &depends_built);