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>
18 static const char *can_build(struct manifest *m)
21 return "Safe mode enabled";
25 /* FIXME: Merge this into one place. */
26 static char *obj_list(const struct manifest *m, bool link_with_module)
28 char *list = talloc_strdup(m, "");
30 struct manifest *subm;
32 /* Objects from any other C files. */
33 list_for_each(&m->other_test_c_files, i, list)
34 list = talloc_asprintf_append(list, " %s", i->compiled);
36 /* Our own object files. */
38 list_for_each(&m->c_files, i, list)
39 list = talloc_asprintf_append(list, " %s", i->compiled);
41 /* Other ccan modules. */
42 list_for_each(&m->deps, subm, list) {
44 list = talloc_asprintf_append(list, " %s",
51 static char *lib_list(const struct manifest *m)
54 char **libs = get_libs(m, m->dir, &num, &m->info_file->compiled);
55 char *ret = talloc_strdup(m, "");
57 for (i = 0; i < num; i++)
58 ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
62 static bool compile(const void *ctx,
64 struct ccan_file *file,
66 bool link_with_module,
67 bool keep, char **output)
69 file->compiled = maybe_temp_file(ctx, "", keep, file->fullname);
70 if (!compile_and_link(ctx, file->fullname, ccan_dir,
71 obj_list(m, link_with_module),
73 lib_list(m), file->compiled, output)) {
74 talloc_free(file->compiled);
80 static void do_compile_tests(struct manifest *m,
82 unsigned int *timeleft, struct score *score)
86 struct list_head *list;
87 bool errors = false, warnings = false;
89 foreach_ptr(list, &m->compile_ok_tests, &m->run_tests, &m->api_tests) {
90 list_for_each(list, i, list) {
91 if (!compile(score, m, i, false, list == &m->api_tests,
93 score->error = "Failed to compile tests";
94 score_file_error(score, i, 0, cmdout);
96 } else if (!streq(cmdout, "")) {
97 score->error = "Test compiled with warnings";
98 score_file_error(score, i, 0, cmdout);
104 /* The compile fail tests are a bit weird, handle them separately */
108 /* For historical reasons, "fail" often means "gives warnings" */
109 list_for_each(&m->compile_fail_tests, i, list) {
110 if (!compile(score, m, i, false, false, false, &cmdout)) {
111 score->error = "Failed to compile without -DFAIL";
112 score_file_error(score, i, 0, cmdout);
115 if (!streq(cmdout, "")) {
116 score->error = "Compile with warnigns without -DFAIL";
117 score_file_error(score, i, 0, cmdout);
120 if (compile(score, m, i, true, false, false, &cmdout)
121 && streq(cmdout, "")) {
122 score->error = "Compiled successfully with -DFAIL?";
123 score_file_error(score, i, 0, NULL);
130 score->score = 1 + !warnings;
133 struct ccanlint compile_tests = {
134 .key = "compile-tests",
135 .name = "Module tests compile",
136 .check = do_compile_tests,
137 .can_run = can_build,
140 REGISTER_TEST(compile_tests, &compile_test_helpers, &build_objs, NULL);