]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/tests/tests_compile.c
ccanlint: fix dependencies on tests_pass_without_features.
[ccan] / tools / ccanlint / tests / tests_compile.c
index 4d8686798c0aa12040defb489cd28ebc4d7acd1b..6c0f9d34274195855fafc4715972a717f37b48bd 100644 (file)
@@ -14,6 +14,7 @@
 #include <err.h>
 #include <string.h>
 #include <ctype.h>
+#include "reduce_features.h"
 
 static const char *can_build(struct manifest *m)
 {
@@ -62,14 +63,17 @@ static char *lib_list(const struct manifest *m)
 static bool compile(const void *ctx,
                    struct manifest *m,
                    struct ccan_file *file,
+                   const char *flags,
                    bool fail,
                    bool link_with_module,
                    bool keep, char **output)
 {
+       char *f = talloc_asprintf(ctx, "%s%s%s",
+                                 flags, fail ? "-DFAIL " : "", cflags);
+
        file->compiled = maybe_temp_file(ctx, "", keep, file->fullname);
        if (!compile_and_link(ctx, file->fullname, ccan_dir,
-                             obj_list(m, link_with_module),
-                             fail ? "-DFAIL" : "",
+                             obj_list(m, link_with_module), compiler, f,
                              lib_list(m), file->compiled, output)) {
                talloc_free(file->compiled);
                return false;
@@ -77,9 +81,8 @@ static bool compile(const void *ctx,
        return true;
 }
 
-static void do_compile_tests(struct manifest *m,
-                            bool keep,
-                            unsigned int *timeleft, struct score *score)
+static void compile_tests(struct manifest *m, bool keep,
+                         struct score *score, const char *incl)
 {
        char *cmdout;
        struct ccan_file *i;
@@ -88,14 +91,16 @@ static void do_compile_tests(struct manifest *m,
 
        foreach_ptr(list, &m->compile_ok_tests, &m->run_tests, &m->api_tests) {
                list_for_each(list, i, list) {
-                       if (!compile(score, m, i, false, list == &m->api_tests,
-                                    keep, &cmdout)) {
-                               score->error = "Failed to compile tests";
-                               score_file_error(score, i, 0, cmdout);
+                       if (!compile(score, m, i, incl, false,
+                                    list == &m->api_tests, keep, &cmdout)) {
+                               score_file_error(score, i, 0,
+                                                "Compile failed:\n%s",
+                                                cmdout);
                                errors = true;
                        } else if (!streq(cmdout, "")) {
-                               score->error = "Test compiled with warnings";
-                               score_file_error(score, i, 0, cmdout);
+                               score_file_error(score, i, 0,
+                                                "Compile gave warnings:\n%s",
+                                                cmdout);
                                warnings = true;
                        }
                }
@@ -107,27 +112,37 @@ static void do_compile_tests(struct manifest *m,
 
        /* For historical reasons, "fail" often means "gives warnings" */
        list_for_each(&m->compile_fail_tests, i, list) {
-               if (!compile(score, m, i, false, false, false, &cmdout)) {
-                       score->error = "Failed to compile without -DFAIL";
-                       score_file_error(score, i, 0, cmdout);
+               if (!compile(score, m, i, incl, false, false, false, &cmdout)) {
+                       score_file_error(score, i, 0,
+                                        "Compile without -DFAIL failed:\n%s",
+                                        cmdout);
                        return;
                }
                if (!streq(cmdout, "")) {
-                       score->error = "Compile with warnigns without -DFAIL";
-                       score_file_error(score, i, 0, cmdout);
+                       score_file_error(score, i, 0,
+                                        "Compile gave warnings"
+                                        " without -DFAIL:\n%s",
+                                        cmdout);
                        return;
                }
-               if (compile(score, m, i, true, false, false, &cmdout)
+               if (compile(score, m, i, incl, true, false, false, &cmdout)
                    && streq(cmdout, "")) {
-                       score->error = "Compiled successfully with -DFAIL?";
-                       score_file_error(score, i, 0, NULL);
+                       score_file_error(score, i, 0,
+                                        "Compiled successfully with -DFAIL?");
                        return;
                }
+               score->total++;
        }
 
        score->pass = true;
-       score->total = 2;
-       score->score = 1 + !warnings;
+       score->score = score->total - warnings;
+}
+
+static void do_compile_tests(struct manifest *m,
+                            bool keep,
+                            unsigned int *timeleft, struct score *score)
+{
+       return compile_tests(m, keep, score, "");
 }
 
 struct ccanlint tests_compile = {
@@ -139,3 +154,27 @@ struct ccanlint tests_compile = {
 };
 
 REGISTER_TEST(tests_compile);
+
+static const char *features_reduced(struct manifest *m)
+{
+       if (features_were_reduced)
+               return NULL;
+       return "No features to turn off";
+}
+
+static void do_compile_tests_without_features(struct manifest *m,
+                                             bool keep,
+                                             unsigned int *timeleft,
+                                             struct score *score)
+{
+       compile_tests(m, keep, score, "-I. ");
+}
+
+struct ccanlint tests_compile_without_features = {
+       .key = "tests_compile_without_features",
+       .name = "Module tests compile (without features)",
+       .check = do_compile_tests_without_features,
+       .can_run = features_reduced,
+       .needs = "tests_compile reduce_features"
+};
+REGISTER_TEST(tests_compile_without_features);