]> git.ozlabs.org Git - ccan/commitdiff
ccanlint: print module name properly for nested modules.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 3 Dec 2012 11:36:40 +0000 (22:06 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 3 Dec 2012 11:36:40 +0000 (22:06 +1030)
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 <rusty@rustcorp.com.au>
tools/ccanlint/ccanlint.c

index 196f75f4352f1750f033fbfe4c63b91f3b06fcdb..2fdb8863cea9dc79c291518bb89c668a653e80c5 100644 (file)
@@ -585,13 +585,27 @@ static bool add_to_all(const char *member, struct ccanlint *c,
        return true;
 }
 
        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;
 int main(int argc, char *argv[])
 {
        bool summary = false, pass = true;
        unsigned int i;
-       struct manifest *m;
        const char *prefix = "";
        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. */
        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);
 
        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;
 }
        }
        return pass ? 0 : 1;
 }