]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/tests/depends_accurate.c
ccanlint: list dependencies by key
[ccan] / tools / ccanlint / tests / depends_accurate.c
index 3ba19f60a3240e0385dd720b509887bd4e4b493e..a6d3a73a85dd94b6b4289f4c14dd1100b260f80b 100644 (file)
@@ -28,19 +28,16 @@ static char *strip_spaces(const void *ctx, char *line)
        return p;
 }
 
-static bool has_dep(struct manifest *m, const char *depname, bool tap_ok)
+static bool has_dep(struct manifest *m, const char *depname)
 {
-       struct ccan_file *f;
-
-       if (tap_ok && streq(depname, "ccan/tap"))
-               return true;
+       struct manifest *i;
 
        /* We can include ourselves, of course. */
-       if (streq(depname + strlen("ccan/"), m->basename))
+       if (streq(depname, m->basename))
                return true;
 
-       list_for_each(&m->dep_dirs, f, list) {
-               if (streq(f->name, depname))
+       list_for_each(&m->deps, i, list) {
+               if (streq(i->basename, depname))
                        return true;
        }
        return false;
@@ -57,10 +54,6 @@ static void check_depends_accurate(struct manifest *m,
                    &m->compile_ok_tests, &m->compile_fail_tests,
                    &m->other_test_c_files) {
                struct ccan_file *f;
-               bool tap_ok;
-
-               /* Including ccan/tap is fine for tests. */
-               tap_ok = (list != &m->c_files && list != &m->h_files);
 
                list_for_each(list, f, list) {
                        unsigned int i;
@@ -74,11 +67,11 @@ static void check_depends_accurate(struct manifest *m,
                                if (!strstarts(p, "#include<ccan/")
                                    && !strstarts(p, "#include\"ccan/"))
                                        continue;
-                               p += strlen("#include\"");
+                               p += strlen("#include\"ccan/");
                                if (!strchr(strchr(p, '/') + 1, '/'))
                                        continue;
                                *strchr(strchr(p, '/') + 1, '/') = '\0';
-                               if (has_dep(m, p, tap_ok))
+                               if (has_dep(m, p))
                                        continue;
                                score->error = "Includes a ccan module"
                                        " not listed in _info";
@@ -94,9 +87,10 @@ static void check_depends_accurate(struct manifest *m,
 }
 
 struct ccanlint depends_accurate = {
-       .key = "depends-accurate",
-       .name = "Module's CCAN dependencies are the only ccan files #included",
+       .key = "depends_accurate",
+       .name = "Module's CCAN dependencies are the only CCAN files #included",
        .check = check_depends_accurate,
+       .needs = "depends_exist"
 };
 
-REGISTER_TEST(depends_accurate, &depends_exist, NULL);
+REGISTER_TEST(depends_accurate);