+ printf("%s tests:\n", type);
+ /* This makes them print in topological order. */
+ while ((i = get_next_test(tests)) != NULL) {
+ const struct dependent *d;
+ printf(" %-25s %s\n", i->key, i->name);
+ list_del(&i->list);
+ list_for_each(&i->dependencies, d, node)
+ d->dependent->num_depends--;
+ }
+}
+
+static char *list_tests(void *arg)
+{
+ print_tests(&compulsory_tests, "Compulsory");
+ print_tests(&normal_tests, "Normal");
+ exit(0);
+}
+
+static void test_dgraph_vertices(struct list_head *tests, const char *style)
+{
+ const struct ccanlint *i;
+
+ list_for_each(tests, i, list) {
+ /*
+ * todo: escape labels in case ccanlint test keys have
+ * characters interpreted as GraphViz syntax.
+ */
+ printf("\t\"%p\" [label=\"%s\"%s]\n", i, i->key, style);
+ }
+}
+
+static void test_dgraph_edges(struct list_head *tests)
+{
+ const struct ccanlint *i;
+ const struct dependent *d;
+
+ list_for_each(tests, i, list)
+ list_for_each(&i->dependencies, d, node)
+ printf("\t\"%p\" -> \"%p\"\n", d->dependent, i);
+}
+
+static char *test_dependency_graph(void *arg)
+{
+ puts("digraph G {");
+
+ test_dgraph_vertices(&compulsory_tests, ", style=filled, fillcolor=yellow");
+ test_dgraph_vertices(&normal_tests, "");
+
+ test_dgraph_edges(&compulsory_tests);
+ test_dgraph_edges(&normal_tests);
+
+ 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];
+ }
+ if (nump)
+ *nump = j;
+ return lines;
+}
+
+static void add_info_options(struct ccan_file *info, bool mark_fails)
+{
+ struct doc_section *d;
+ unsigned int i;
+ struct ccanlint *test;
+
+ list_for_each(get_ccan_file_docs(info), d, list) {
+ if (!streq(d->type, "ccanlint"))
+ continue;
+
+ for (i = 0; i < d->num_lines; i++) {
+ char **words = collapse(strsplit(d, d->lines[i], " \t",
+ NULL), NULL);
+ if (!words[0])
+ continue;
+
+ if (strncmp(words[0], "//", 2) == 0)
+ continue;
+
+ test = find_test(words[0]);
+ if (!test) {
+ warnx("%s: unknown ccanlint test '%s'",
+ info->fullname, words[0]);
+ continue;
+ }
+
+ if (!words[1]) {
+ warnx("%s: no argument to test '%s'",
+ info->fullname, words[0]);
+ continue;
+ }
+
+ /* Known failure? */
+ if (strcasecmp(words[1], "FAIL") == 0) {
+ if (mark_fails)
+ btree_insert(info_exclude, words[0]);
+ } else {
+ if (!test->takes_options)
+ warnx("%s: %s doesn't take options",
+ info->fullname, words[0]);
+ /* Copy line exactly into options. */
+ test->options = strstr(d->lines[i], words[0])
+ + strlen(words[0]);
+ }