+ targeting = true;
+ dgraph_add_edge(&t->node, all);
+ return NULL;
+}
+
+static bool run_tests(struct dgraph_node *all,
+ bool summary,
+ bool deps_fail_ignore,
+ struct manifest *m,
+ const char *prefix)
+{
+ struct run_info run;
+ const char *comment = "";
+
+ run.quiet = summary;
+ run.m = m;
+ run.prefix = prefix;
+ run.score = run.total = 0;
+ run.pass = true;
+
+ non_ccan_deps = build_failed = false;
+
+ dgraph_traverse_to(all, run_test, &run);
+
+ /* We can completely fail if we're missing external stuff: ignore */
+ if (deps_fail_ignore && non_ccan_deps && build_failed) {
+ comment = " (missing non-ccan dependencies?)";
+ run.pass = true;
+ } else if (!run.pass) {
+ comment = " FAIL!";
+ }
+ printf("%sTotal score: %u/%u%s\n",
+ prefix, run.score, run.total, comment);
+
+ return run.pass;
+}
+
+static bool add_to_all(const char *member, struct ccanlint *c,
+ struct dgraph_node *all)
+{
+ /* If we're excluded on cmdline, don't add. */
+ if (!c->skip)
+ dgraph_add_edge(&c->node, all);
+ return true;
+}
+
+static bool test_module(struct dgraph_node *all,
+ const char *dir, const char *prefix, bool summary,
+ bool deps_fail_ignore)
+{
+ 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, deps_fail_ignore, m, prefix);
+}
+
+int main(int argc, char *argv[])
+{
+ bool summary = false, pass = true, deps_fail_ignore = false;
+ unsigned int i;
+ const char *prefix = "";
+ char *cwd = path_cwd(NULL), *dir;
+ struct ccanlint top; /* cannot_run may try to set ->can_run */
+ const char *override_compiler = NULL, *override_cflags = NULL;
+
+ /* Empty graph node to which we attach everything else. */
+ dgraph_init_node(&top.node);
+
+ opt_register_early_noarg("--verbose|-v", opt_inc_intval, &verbose,
+ "verbose mode (up to -vvvv)");
+ opt_register_noarg("-n|--safe-mode", opt_set_bool, &safe_mode,
+ "do not compile anything");
+ opt_register_noarg("-l|--list-tests", list_tests, NULL,
+ "list tests ccanlint performs (and exit)");
+ opt_register_noarg("--test-dep-graph", test_dependency_graph, NULL,
+ "print dependency graph of tests in Graphviz .dot format");
+ opt_register_noarg("-k|--keep", keep_tests, NULL,
+ "do not delete ccanlint working files");
+ opt_register_noarg("--summary|-s", opt_set_bool, &summary,
+ "simply give one line summary");
+ opt_register_arg("-x|--exclude <testname>", exclude_test, NULL, NULL,
+ "exclude <testname> (can be used multiple times)");
+ opt_register_arg("--timeout <milleseconds>", opt_set_uintval,
+ NULL, &timeout,
+ "ignore (terminate) tests that are slower than this");
+ opt_register_arg("-t|--target <testname>", opt_set_target, NULL,
+ &top.node,
+ "only run one test (and its prerequisites)");
+ opt_register_arg("--compiler <compiler>", opt_set_const_charp,
+ NULL, &override_compiler, "set the compiler");
+ opt_register_arg("--cflags <flags>", opt_set_const_charp,
+ NULL, &override_cflags, "set the compiler flags");
+ opt_register_noarg("--deps-fail-ignore", opt_set_bool,
+ &deps_fail_ignore,
+ "don't fail if external dependencies are missing");
+ opt_register_noarg("-?|-h|--help", opt_usage_and_exit,
+ "\nA program for checking and guiding development"
+ " of CCAN modules.",
+ "This usage message");
+
+ /* Do verbose before anything else... */
+ opt_early_parse(argc, argv, opt_log_stderr_exit);
+
+ /* We move into temporary directory, so gcov dumps its files there. */
+ if (chdir(temp_dir()) != 0)
+ err(1, "Error changing to %s temporary dir", temp_dir());
+
+ init_tests();
+
+ if (verbose >= 3) {
+ compile_verbose = true;
+ print_test_depends();