+
+ printf("\nNormal Tests\n");
+ list_for_each(&normal_tests, i, list) {
+ printf("%s depends on %u others\n", i->name, i->num_depends);
+ if (!list_empty(&i->dependencies)) {
+ const struct dependent *d;
+ printf("These depend on us:\n");
+ list_for_each(&i->dependencies, d, node)
+ printf("\t%s\n", d->dependent->name);
+ }
+ }
+}
+
+static struct ccanlint *find_test(const char *key)
+{
+ struct ccanlint *i;
+
+ list_for_each(&compulsory_tests, i, list)
+ if (streq(i->key, key))
+ return i;
+
+ list_for_each(&normal_tests, i, list)
+ if (streq(i->key, key))
+ return i;
+
+ return NULL;
+}
+
+static char *keep_test(const char *testname, void *unused)
+{
+ struct ccanlint *i = find_test(testname);
+ if (!i)
+ errx(1, "No test %s to --keep", testname);
+ i->keep_results = true;
+ return NULL;
+}
+
+static char *skip_test(const char *testname, void *unused)
+{
+ btree_insert(cmdline_exclude, optarg);
+ return NULL;
+}
+
+static void print_tests(struct list_head *tests, const char *type)
+{
+ struct ccanlint *i;
+
+ 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 char *strip(const void *ctx, const char *line)
+{
+ line += strcspn(line, IDENT_CHARS "-");
+ return talloc_strndup(ctx, line, strspn(line, IDENT_CHARS "-"));
+}
+
+static void add_info_fails(struct ccan_file *info)
+{
+ struct doc_section *d;
+ unsigned int i;
+
+ list_for_each(get_ccan_file_docs(info), d, list) {
+ if (!streq(d->type, "fails"))
+ continue;
+
+ for (i = 0; i < d->num_lines; i++)
+ btree_insert(info_exclude, strip(info, d->lines[i]));
+ break;
+ }
+}
+
+static bool depends_on(struct ccanlint *i, struct ccanlint *target)
+{
+ const struct dependent *d;
+
+ if (i == target)
+ return true;
+
+ list_for_each(&i->dependencies, d, node) {
+ if (depends_on(d->dependent, target))
+ return true;
+ }
+ return false;
+}
+
+/* O(N^2), who cares? */
+static void skip_unrelated_tests(struct ccanlint *target)
+{
+ struct ccanlint *i;
+ struct list_head *list;
+
+ foreach_ptr(list, &compulsory_tests, &normal_tests)
+ list_for_each(list, i, list)
+ if (!depends_on(i, target))
+ i->skip = "not relevant to target";