X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Fccanlint.c;h=2fdb8863cea9dc79c291518bb89c668a653e80c5;hp=83549cc968ffb71feb36da499453e3a3e996deec;hb=756407b43540926c39181e5c61425d5daf1970db;hpb=09d5cd70d7e8105a003ed9583eadb077de014f3b diff --git a/tools/ccanlint/ccanlint.c b/tools/ccanlint/ccanlint.c index 83549cc9..2fdb8863 100644 --- a/tools/ccanlint/ccanlint.c +++ b/tools/ccanlint/ccanlint.c @@ -585,13 +585,27 @@ static bool add_to_all(const char *member, struct ccanlint *c, return true; } +static bool test_module(struct dgraph_node *all, + const char *dir, const char *prefix, bool summary) +{ + struct manifest *m = get_manifest(autofree(), dir); + char *testlink = path_join(NULL, temp_dir(), "test"); + + /* Create a symlink from temp dir back to src dir's + * test directory. */ + unlink(testlink); + if (symlink(path_join(m, dir, "test"), testlink) != 0) + err(1, "Creating test symlink in %s", temp_dir()); + + return run_tests(all, summary, m, prefix); +} + int main(int argc, char *argv[]) { bool summary = false, pass = true; unsigned int i; - struct manifest *m; const char *prefix = ""; - char *dir = path_cwd(NULL), *base_dir = dir, *testlink; + char *cwd = path_cwd(NULL), *dir; struct dgraph_node all; /* Empty graph node to which we attach everything else. */ @@ -646,52 +660,31 @@ int main(int argc, char *argv[]) if (!targeting) strmap_iterate(&tests, add_to_all, &all); - /* This links back to the module's test dir. */ - testlink = tal_fmt(NULL, "%s/test", temp_dir()); - - /* Defaults to pwd. */ - if (argc == 1) { - i = 1; - goto got_dir; - } - - for (i = 1; i < argc; i++) { - dir = argv[i]; - - if (dir[0] != '/') - dir = tal_fmt(NULL, "%s/%s", base_dir, dir); - while (strends(dir, "/")) - dir[strlen(dir)-1] = '\0'; - - got_dir: - /* We assume there's a ccan/ in there somewhere... */ - if (i == 1) { - ccan_dir = find_ccan_dir(dir); - if (!ccan_dir) - errx(1, "Cannot find ccan/ base directory in %s", - dir); - config_header = read_config_header(ccan_dir, - &compiler, &cflags, - verbose > 1); + if (argc == 1) + dir = cwd; + else + dir = path_join(NULL, cwd, argv[1]); + + ccan_dir = find_ccan_dir(dir); + if (!ccan_dir) + errx(1, "Cannot find ccan/ base directory in %s", dir); + config_header = read_config_header(ccan_dir, &compiler, &cflags, + verbose > 1); + + if (argc == 1) + pass = test_module(&all, cwd, "", summary); + else { + for (i = 1; i < argc; i++) { + dir = path_canon(NULL, + take(path_join(NULL, cwd, argv[i]))); + + prefix = path_join(NULL, ccan_dir, "ccan"); + prefix = path_rel(NULL, take(prefix), dir); + prefix = tal_strcat(NULL, take(prefix), ": "); + + pass &= test_module(&all, dir, prefix, summary); + reset_tests(&all); } - - if (dir != base_dir) - prefix = tal_strcat(NULL, - take(path_basename(NULL,dir)), - ": "); - - m = get_manifest(autofree(), dir); - - /* Create a symlink from temp dir back to src dir's - * test directory. */ - unlink(testlink); - if (symlink(tal_fmt(m, "%s/test", dir), testlink) != 0) - err(1, "Creating test symlink in %s", temp_dir()); - - if (!run_tests(&all, summary, m, prefix)) - pass = false; - - reset_tests(&all); } return pass ? 0 : 1; }