gtestutils: Allow combining --tap with -p

The -p option is documented, and can be used to select and repeat
test-cases. This is particularly useful when debugging a single
failure among a large number of test-cases, or when debugging a
test-case that you suspect influences another test-case by leaking
global state.

Until now, -p was only supported with GLib's default (GLib-specific)
textual output format, and not with the standardized TAP format that
we are now encouraging. If we are considering making TAP the new default
(see glib#1619) it should get feature-equivalence with the current
default.

Because -p allows test-cases to be re-ordered and repeated, and an entry
in the test_paths list can match any number of test-cases (including
zero), we don't know ahead of time how many test-cases we are going to
run. TAP allows the "plan" to be deferred to the end, exactly to support
situations like this.

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2019-01-04 12:53:04 +00:00
parent efa56aa957
commit b24cdffd5c

View File

@ -942,17 +942,24 @@ g_test_log (GTestLogType lbit,
case G_TEST_LOG_START_SUITE:
if (test_tap_log)
{
/* We only print the TAP "plan" (1..n) ahead of time if we did
* not use the -p option to select specific tests to be run. */
if (string1[0] != 0)
g_print ("# Start of %s tests\n", string1);
else
else if (test_paths == NULL)
g_print ("1..%d\n", test_count);
}
break;
case G_TEST_LOG_STOP_SUITE:
if (test_tap_log)
{
/* If we didn't print the TAP "plan" at the beginning because
* we were using -p, we need to print how many tests we ran at
* the end instead. */
if (string1[0] != 0)
g_print ("# End of %s tests\n", string1);
else if (test_paths != NULL)
g_print ("1..%d\n", test_run_count);
}
break;
case G_TEST_LOG_STOP_CASE:
@ -1539,18 +1546,6 @@ void
test_tmpdir = g_getenv ("G_TEST_TMPDIR");
}
/* sanity check */
if (test_tap_log)
{
if (test_paths)
{
/* Not invoking every test (even if SKIPped) breaks the "1..XX" plan */
g_printerr ("%s: -p option is incompatible with --tap\n",
(*argv)[0]);
exit (1);
}
}
/* verify GRand reliability, needed for reliable seeds */
if (1)
{