From: Rusty Russell Date: Mon, 3 Dec 2012 11:36:40 +0000 (+1030) Subject: ccanlint: print module name properly for nested modules. X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=756407b43540926c39181e5c61425d5daf1970db ccanlint: print module name properly for nested modules. eg: tal/str: Module's tests cover all the code (tests_coverage): PASS (+3/6) tal/str: Total score: 55/58 Signed-off-by: Rusty Russell --- diff --git a/tools/ccanlint/ccanlint.c b/tools/ccanlint/ccanlint.c index 196f75f4..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,48 +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 = path_join(NULL, temp_dir(), "test"); - - /* Defaults to pwd. */ - if (argc == 1) { - i = 1; - goto got_dir; - } - - for (i = 1; i < argc; i++) { - dir = path_simplify(NULL, - take(path_join(NULL, base_dir, argv[i]))); - - 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(path_join(m, dir, "test"), 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; }