X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Fcheck_depends_exist.c;fp=tools%2Fccanlint%2Ftests%2Fcheck_depends_exist.c;h=0978340f8c8a117680e04eaff74c5a72f221614b;hp=0000000000000000000000000000000000000000;hb=61088f5c752c555172e2ab6cf93a7967f79f3f2c;hpb=3460418c419dfcc84316ad65497b0a00950480b9 diff --git a/tools/ccanlint/tests/check_depends_exist.c b/tools/ccanlint/tests/check_depends_exist.c new file mode 100644 index 00000000..0978340f --- /dev/null +++ b/tools/ccanlint/tests/check_depends_exist.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static char *add_dep(char *sofar, struct manifest *m, const char *dep) +{ + char *dir; + struct stat st; + struct ccan_file *f; + + dir = talloc_asprintf(m, "../%s", dep); + if (stat(dir, &st) != 0) { + return talloc_asprintf_append(sofar, + "ccan/%s: expected it in" + " directory %s\n", + dep, dir); + } + + f = new_ccan_file(m, dir); + list_add_tail(&m->dep_dirs, &f->list); + return sofar; +} + +static void *check_depends_exist(struct manifest *m) +{ + unsigned int i; + char *report = NULL; + char **deps; + + if (safe_mode) + deps = get_safe_ccan_deps(m, "..", m->basename, true); + else + deps = get_deps(m, "..", m->basename, true); + + for (i = 0; deps[i]; i++) { + if (!strstarts(deps[i], "ccan/")) + continue; + + report = add_dep(report, m, deps[i] + strlen("ccan/")); + } + 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); +} + +struct ccanlint depends_exist = { + .name = "CCAN dependencies are present", + .total_score = 1, + .check = check_depends_exist, + .describe = describe_depends_exist, +}; + +REGISTER_TEST(depends_exist, NULL);