]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/tests/compile_tests.c
More test fixes.
[ccan] / tools / ccanlint / tests / compile_tests.c
index c9ace30dde687ec0dc889d0019e4bb5f06f592bd..57c257a2d828de68c1306dcfd1bcfbf2fe22097d 100644 (file)
@@ -23,24 +23,33 @@ static const char *can_build(struct manifest *m)
 
 static char *obj_list(const struct manifest *m, bool link_with_module)
 {
-       char *list = talloc_strdup(m, "../tap.o");
+       char *list;
        struct ccan_file *i;
 
+       /* We expect to be linked with tap, unless that's us. */
+       if (!streq(m->basename, "tap"))
+               list = talloc_strdup(m, "../tap.o");
+       else
+               list = talloc_strdup(m, "");
+
        /* Objects from any other C files. */
        list_for_each(&m->other_test_c_files, i, list)
-               list = talloc_asprintf_append(list, " %.*s.o",
-                                             strlen(i->name) - 2, i->name);
+               list = talloc_asprintf_append(list, " %s", i->compiled);
 
        if (link_with_module)
                list = talloc_asprintf_append(list, " ../%s.o", m->basename);
 
+       /* Other ccan modules. */
+       list_for_each(&m->dep_objs, i, list)
+               list = talloc_asprintf_append(list, " %s", i->name);
+
        return list;
 }
 
 static char *lib_list(const struct manifest *m)
 {
        unsigned int i, num;
-       char **libs = get_libs(m, ".", ".", &num);
+       char **libs = get_libs(m, ".", ".", &num, &m->info_file->compiled);
        char *ret = talloc_strdup(m, "");
 
        for (i = 0; i < num; i++)
@@ -48,23 +57,20 @@ static char *lib_list(const struct manifest *m)
        return ret;
 }
 
-static int cleanup_testfile(const char *testfile)
-{
-       unlink(testfile);
-       return 0;
-}
-
 static char *compile(const void *ctx,
                     struct manifest *m, struct ccan_file *file, bool fail,
                     bool link_with_module)
 {
-       file->compiled = talloc_strdup(ctx, tempnam("/tmp", "ccanlint"));
-       talloc_set_destructor(file->compiled, cleanup_testfile);
-
-       return run_command(m, "cc " CFLAGS " %s -o %s %s %s %s",
-                          fail ? "-DFAIL" : "",
-                          file->compiled, file->name,
-                          obj_list(m, link_with_module), lib_list(m));
+       char *errmsg;
+
+       file->compiled = compile_and_link(ctx, file->name,
+                                         obj_list(m, link_with_module),
+                                         fail ? "-DFAIL" : "",
+                                         lib_list(m), &errmsg);
+       if (!file->compiled)
+               return errmsg;
+       talloc_steal(ctx, file->compiled);
+       return NULL;
 }
 
 struct compile_tests_result {
@@ -83,7 +89,6 @@ static void *do_compile_tests(struct manifest *m)
 
        list_head_init(list);
 
-       compile_tests.total_score = 0;
        list_for_each(&m->compile_ok_tests, i, list) {
                compile_tests.total_score++;
                cmdout = compile(list, m, i, false, false);
@@ -122,7 +127,7 @@ static void *do_compile_tests(struct manifest *m)
 
        list_for_each(&m->compile_fail_tests, i, list) {
                compile_tests.total_score++;
-               cmdout = compile(list, m, i, true, false);
+               cmdout = compile(list, m, i, false, false);
                if (cmdout) {
                        res = talloc(list, struct compile_tests_result);
                        res->filename = i->name;
@@ -130,7 +135,7 @@ static void *do_compile_tests(struct manifest *m)
                        res->output = talloc_steal(res, cmdout);
                        list_add_tail(list, &res->list);
                } else {
-                       cmdout = compile(list, m, i, false, false);
+                       cmdout = compile(list, m, i, true, false);
                        if (!cmdout) {
                                res = talloc(list, struct compile_tests_result);
                                res->filename = i->name;
@@ -178,7 +183,6 @@ static const char *describe_compile_tests(struct manifest *m,
 
 struct ccanlint compile_tests = {
        .name = "Compile tests succeed",
-       .total_score = 1,
        .score = score_compile_tests,
        .check = do_compile_tests,
        .describe = describe_compile_tests,