+ table = autodata_get(ccanlint_tests, &num);
+ for (i = 0; i < num; i++)
+ register_test(table[i]);
+ autodata_free(table);
+
+ strmap_iterate(&tests, init_deps, NULL);
+
+ /* Check for duplicate names. */
+ strmap_init(&names);
+ strmap_iterate(&tests, check_names, &names);
+ strmap_clear(&names);
+}
+
+static bool reset_test(struct dgraph_node *node, void *unused)
+{
+ struct ccanlint *c = container_of(node, struct ccanlint, node);
+ c->skip = NULL;
+ c->done = false;
+ return true;
+}
+
+static void reset_tests(struct dgraph_node *all)
+{
+ dgraph_traverse_to(all, reset_test, NULL);
+}
+
+static bool print_deps(const char *member, struct ccanlint *c, void *unused)
+{
+ if (!tlist_empty(&c->node.edge[DGRAPH_FROM])) {
+ struct dgraph_edge *e;
+
+ printf("These depend on %s:\n", c->key);
+ dgraph_for_each_edge(&c->node, e, DGRAPH_FROM) {
+ struct ccanlint *to = container_of(e->n[DGRAPH_TO],
+ struct ccanlint,
+ node);
+ printf("\t%s\n", to->key);
+ }
+ }
+ return true;
+}
+
+static void print_test_depends(void)
+{
+ printf("Tests:\n");
+
+ strmap_iterate(&tests, print_deps, NULL);
+}
+
+
+static int show_tmpdir(const char *dir)
+{
+ printf("You can find ccanlint working files in '%s'\n", dir);
+ return 0;
+}
+
+static char *keep_tests(void *unused)
+{
+ keep_results = true;
+
+ /* Don't automatically destroy temporary dir. */
+ talloc_set_destructor(temp_dir(NULL), show_tmpdir);
+ return NULL;
+}
+
+static bool remove_test(struct dgraph_node *node, const char *why)
+{
+ struct ccanlint *c = container_of(node, struct ccanlint, node);
+ c->skip = why;
+ dgraph_clear_node(node);
+ return true;
+}
+
+static char *exclude_test(const char *testname, void *unused)
+{
+ struct ccanlint *i = find_test(testname);
+ if (!i)
+ return talloc_asprintf(NULL, "No test %s to --exclude",
+ testname);
+
+ /* Remove this, and everything which depends on it. */
+ dgraph_traverse_from(&i->node, remove_test, "excluded on command line");
+ remove_test(&i->node, "excluded on command line");
+ return NULL;
+}
+
+static void skip_test_and_deps(struct ccanlint *c, const char *why)
+{
+ /* Skip this, and everything which depends on us. */
+ dgraph_traverse_from(&c->node, skip_test, why);
+ skip_test(&c->node, why);
+}
+
+static char *list_tests(void *arg)
+{
+ struct ccanlint *i;
+
+ printf("Tests:\n");
+ /* This makes them print in topological order. */
+ while ((i = get_next_test()) != NULL) {
+ printf(" %-25s %s\n", i->key, i->name);
+ dgraph_clear_node(&i->node);
+ strmap_del(&tests, i->key, NULL);
+ }
+ exit(0);
+}
+
+static bool draw_test(const char *member, struct ccanlint *c, const char *style)
+{
+ /*
+ * todo: escape labels in case ccanlint test keys have
+ * characters interpreted as GraphViz syntax.
+ */
+ printf("\t\"%p\" [label=\"%s\"%s]\n", c, c->key, style);
+ return true;
+}
+
+static void test_dgraph_vertices(const char *style)
+{
+ strmap_iterate(&tests, draw_test, style);
+}
+
+static bool draw_edges(const char *member, struct ccanlint *c, void *unused)
+{
+ struct dgraph_edge *e;
+
+ dgraph_for_each_edge(&c->node, e, DGRAPH_FROM) {
+ struct ccanlint *to = container_of(e->n[DGRAPH_TO],
+ struct ccanlint,
+ node);
+ printf("\t\"%p\" -> \"%p\"\n", c->name, to->name);
+ }
+ return true;
+}
+
+static void test_dgraph_edges(void)
+{
+ strmap_iterate(&tests, draw_edges, NULL);
+}
+
+static char *test_dependency_graph(void *arg)
+{
+ puts("digraph G {");
+
+ test_dgraph_vertices("");
+ test_dgraph_edges();
+
+ puts("}");
+
+ exit(0);
+}
+
+/* Remove empty lines. */
+static char **collapse(char **lines, unsigned int *nump)
+{
+ unsigned int i, j;
+ for (i = j = 0; lines[i]; i++) {
+ if (lines[i][0])
+ lines[j++] = lines[i];
+ }
+ lines[j] = NULL;
+ if (nump)
+ *nump = j;
+ return lines;
+}
+
+
+static void add_options(struct ccanlint *test, char **options,
+ unsigned int num_options)
+{
+ unsigned int num;