Merge branch 'fix-issue-362' into 'master'

Fix `test applications do not display invalid test selection`

Closes #362

See merge request dbus/dbus!233
This commit is contained in:
Simon McVittie 2021-12-10 12:46:13 +00:00
commit 78c18f400f

View file

@ -647,6 +647,42 @@ _dbus_check_fdleaks_leave (DBusInitialFDs *fds,
#endif
}
static void
_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);
}
static const DBusTestCase*
_dbus_test_find_test (const DBusTestCase *tests, const char *specific_test)
{
const DBusTestCase *p;
for (p = tests; p->name; p++)
{
if (strcmp (specific_test, p->name) == 0)
return p;
}
return NULL;
}
/*
* _dbus_test_main:
* @argc: number of command-line arguments
@ -684,6 +720,18 @@ _dbus_test_main (int argc,
setlocale(LC_ALL, "");
#endif
if (argc > 1 && strcmp (argv[1], "--help") == 0)
{
_dbus_test_help_page (argv[0]);
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
@ -701,8 +749,11 @@ _dbus_test_main (int argc,
if (test_data_dir != NULL)
_dbus_test_diag ("Test data in %s", test_data_dir);
else if (flags & DBUS_TEST_FLAGS_REQUIRE_DATA)
_dbus_test_fatal ("Must specify test data directory as argv[1] or "
"in DBUS_TEST_DATA environment variable");
{
_dbus_test_help_page (argv[0]);
_dbus_test_fatal ("Must specify test data directory as argv[1] or "
"in DBUS_TEST_DATA environment variable");
}
else
_dbus_test_diag ("No test data!");
@ -711,6 +762,15 @@ _dbus_test_main (int argc,
else
specific_test = strdup0_or_die (_dbus_getenv ("DBUS_TEST_ONLY"));
/* check that test is present */
if (specific_test)
{
if (_dbus_test_find_test (tests, specific_test) == NULL)
{
_dbus_test_fatal ("Invalid test name '%s' specified", specific_test);
}
}
/* Some NSS modules like those for sssd and LDAP might allocate fds
* on a one-per-process basis. Make sure those have already been
* allocated before we enter the code under test, so that they don't