]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/compulsory_tests/check_depends_exist.c
ccanlint: rename test keys
[ccan] / tools / ccanlint / compulsory_tests / check_depends_exist.c
index 28f581c5758e01b3aa335e3744757996d1f659a8..ffbf4539bf6f07ad31a3e8aaaf8390ceb8b2f9f0 100644 (file)
 #include <string.h>
 #include <ctype.h>
 
-static char *add_dep(char *sofar, struct manifest *m, const char *dep)
+static bool add_dep(struct manifest *m, const char *dep, struct score *score)
 {
-       char *dir;
        struct stat st;
-       struct ccan_file *f;
+       struct manifest *subm;
+       char *dir = talloc_asprintf(m, "%s/%s", ccan_dir, dep);
 
-       dir = talloc_asprintf(m, "%s/%s", ccan_dir, dep);
+       /* FIXME: get_manifest has a tendency to exit. */
        if (stat(dir, &st) != 0) {
-               return talloc_asprintf_append(sofar,
-                                             "ccan/%s: expected it in"
-                                             " directory %s\n",
-                                             dep, dir);
+               score->error
+                       = talloc_asprintf(m,
+                                         "Could not stat dependency %s: %s",
+                                         dir, strerror(errno));
+               return false;
        }
-
-       f = new_ccan_file(m, "", dir);
-       list_add_tail(&m->dep_dirs, &f->list);
-       return sofar;
+       subm = get_manifest(m, dir);
+       list_add_tail(&m->deps, &subm->list);
+       return true;
 }
 
-static void *check_depends_exist(struct manifest *m)
+static void check_depends_exist(struct manifest *m,
+                               bool keep,
+                               unsigned int *timeleft, struct score *score)
 {
        unsigned int i;
-       char *report = NULL;
        char **deps;
        char *updir = talloc_strdup(m, m->dir);
 
@@ -52,25 +53,25 @@ static void *check_depends_exist(struct manifest *m)
                if (!strstarts(deps[i], "ccan/"))
                        continue;
 
-               report = add_dep(report, m, deps[i]);
+               if (!add_dep(m, deps[i], score))
+                       return;
        }
-       return report;
-}
 
-static const char *describe_depends_exist(struct manifest *m,
-                                         void *check_result)
-{
-       return talloc_asprintf(check_result,
-                              "The following dependencies are are expected:\n"
-                              "%s", (char *)check_result);
+       /* We may need libtap for testing, unless we're "tap" */
+       if (!streq(m->basename, "tap")
+           && (!list_empty(&m->run_tests) || !list_empty(&m->api_tests))) {
+               if (!add_dep(m, "ccan/tap", score))
+                       return;
+       }
+
+       score->pass = true;
+       score->score = score->total;
 }
 
 struct ccanlint depends_exist = {
-       .key = "depends-exist",
-       .name = "CCAN dependencies are present",
-       .total_score = 1,
+       .key = "depends_exist",
+       .name = "Module's CCAN dependencies can be found",
        .check = check_depends_exist,
-       .describe = describe_depends_exist,
 };
 
-REGISTER_TEST(depends_exist, NULL);
+REGISTER_TEST(depends_exist, &has_info, NULL);