test/test-utils.c: Add command line option --list-tests to test applications

With this command line option a list of available tests is printed to
stdout.
This commit is contained in:
Ralf Habacker 2021-12-10 10:22:56 +01:00
parent 3432cd938d
commit febafd863e

View file

@ -653,12 +653,22 @@ _dbus_test_help_page (const char *appname)
fprintf(stdout, "%s [<options>] [<test-data-dir>] [<specific-test>]\n", appname);
fprintf(stdout, "Options:\n");
fprintf(stdout, " --help this page\n");
fprintf(stdout, " --list-tests show available tests\n");
fprintf(stdout, " --tap expect test data dir to be set by environment variable DBUS_TEST_DATA\n");
fprintf(stdout, "Environment variables:\n");
fprintf(stdout, " DBUS_TEST_ONLY=<specific-test> set specific test to run\n");
fprintf(stdout, " DBUS_TEST_DATA=<test-data-dir> set test data dir (required when using --tap)\n");
}
static void
_dbus_test_show_available_tests (const DBusTestCase *tests)
{
const DBusTestCase *p;
for (p = tests; p->name; p++)
fprintf(stdout, "%s\n", p->name);
}
/*
* _dbus_test_main:
* @argc: number of command-line arguments
@ -702,6 +712,12 @@ _dbus_test_main (int argc,
exit(0);
}
else if (argc > 1 && strcmp (argv[1], "--list-tests") == 0)
{
_dbus_test_show_available_tests (tests);
exit (0);
}
/* We can't assume that strings from _dbus_getenv() will remain valid
* forever, because some tests call setenv(), which is allowed to
* reallocate the entire environment block, and in Wine it seems that it