Merge branch 'tap-skip' into 'master'

gtestutils: Make --tap compatible with -p and --GTestSkipCount

See merge request GNOME/glib!556
This commit is contained in:
Philip Withnall 2019-04-29 15:45:59 +00:00
commit 0e999f37d0
3 changed files with 168 additions and 13 deletions

View File

@ -942,17 +942,24 @@ g_test_log (GTestLogType lbit,
case G_TEST_LOG_START_SUITE: case G_TEST_LOG_START_SUITE:
if (test_tap_log) 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) if (string1[0] != 0)
g_print ("# Start of %s tests\n", string1); g_print ("# Start of %s tests\n", string1);
else else if (test_paths == NULL)
g_print ("1..%d\n", test_count); g_print ("1..%d\n", test_count);
} }
break; break;
case G_TEST_LOG_STOP_SUITE: case G_TEST_LOG_STOP_SUITE:
if (test_tap_log) 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) if (string1[0] != 0)
g_print ("# End of %s tests\n", string1); g_print ("# End of %s tests\n", string1);
else if (test_paths != NULL)
g_print ("1..%d\n", test_run_count);
} }
break; break;
case G_TEST_LOG_STOP_CASE: case G_TEST_LOG_STOP_CASE:
@ -994,6 +1001,10 @@ g_test_log (GTestLogType lbit,
if (result == G_TEST_RUN_SKIPPED || result == G_TEST_RUN_INCOMPLETE) if (result == G_TEST_RUN_SKIPPED || result == G_TEST_RUN_INCOMPLETE)
test_skipped_count++; test_skipped_count++;
break; break;
case G_TEST_LOG_SKIP_CASE:
if (test_tap_log)
g_print ("ok %d %s # SKIP\n", test_run_count, string1);
break;
case G_TEST_LOG_MIN_RESULT: case G_TEST_LOG_MIN_RESULT:
if (test_tap_log) if (test_tap_log)
g_print ("# min perf: %s\n", string1); g_print ("# min perf: %s\n", string1);
@ -1535,18 +1546,6 @@ void
test_tmpdir = g_getenv ("G_TEST_TMPDIR"); test_tmpdir = g_getenv ("G_TEST_TMPDIR");
} }
/* sanity check */
if (test_tap_log)
{
if (test_paths || test_startup_skip_count)
{
/* Not invoking every test (even if SKIPped) breaks the "1..XX" plan */
g_printerr ("%s: -p and --GTestSkipCount options are incompatible with --tap\n",
(*argv)[0]);
exit (1);
}
}
/* verify GRand reliability, needed for reliable seeds */ /* verify GRand reliability, needed for reliable seeds */
if (1) if (1)
{ {

View File

@ -101,6 +101,16 @@ main (int argc,
g_test_add_func ("/incomplete", test_incomplete); g_test_add_func ("/incomplete", test_incomplete);
g_test_add_func ("/fail", test_fail); g_test_add_func ("/fail", test_fail);
} }
else if (g_strcmp0 (argv1, "skip-options") == 0)
{
/* The caller is expected to skip some of these with
* -p, -s and/or --GTestSkipCount */
g_test_add_func ("/a", test_pass);
g_test_add_func ("/b/a", test_pass);
g_test_add_func ("/b/b", test_pass);
g_test_add_func ("/c/a", test_pass);
g_test_add_func ("/d/a", test_pass);
}
else else
{ {
g_assert_not_reached (); g_assert_not_reached ();

View File

@ -1063,6 +1063,152 @@ test_tap (void)
g_assert_no_error (error); g_assert_no_error (error);
g_ptr_array_unref (argv); g_ptr_array_unref (argv);
g_test_message ("--GTestSkipCount");
argv = g_ptr_array_new ();
g_ptr_array_add (argv, (char *) testing_helper);
g_ptr_array_add (argv, "skip-options");
g_ptr_array_add (argv, "--tap");
g_ptr_array_add (argv, "--GTestSkipCount");
g_ptr_array_add (argv, "2");
g_ptr_array_add (argv, NULL);
g_spawn_sync (NULL, (char **) argv->pdata, NULL,
G_SPAWN_STDERR_TO_DEV_NULL,
NULL, NULL, &output, NULL, &status,
&error);
g_assert_no_error (error);
g_assert_nonnull (strstr (output, "1..5\n"));
g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP\n"));
g_assert_nonnull (strstr (output, "\nok 2 /b/a # SKIP\n"));
g_assert_nonnull (strstr (output, "\nok 3 /b/b\n"));
g_assert_nonnull (strstr (output, "\nok 4 /c/a\n"));
g_assert_nonnull (strstr (output, "\nok 5 /d/a\n"));
g_spawn_check_exit_status (status, &error);
g_assert_no_error (error);
g_free (output);
g_ptr_array_unref (argv);
g_test_message ("--GTestSkipCount=0 is the same as omitting it");
argv = g_ptr_array_new ();
g_ptr_array_add (argv, (char *) testing_helper);
g_ptr_array_add (argv, "skip-options");
g_ptr_array_add (argv, "--tap");
g_ptr_array_add (argv, "--GTestSkipCount");
g_ptr_array_add (argv, "0");
g_ptr_array_add (argv, NULL);
g_spawn_sync (NULL, (char **) argv->pdata, NULL,
G_SPAWN_STDERR_TO_DEV_NULL,
NULL, NULL, &output, NULL, &status,
&error);
g_assert_no_error (error);
g_assert_nonnull (strstr (output, "1..5\n"));
g_assert_nonnull (strstr (output, "\nok 1 /a\n"));
g_assert_nonnull (strstr (output, "\nok 2 /b/a\n"));
g_assert_nonnull (strstr (output, "\nok 3 /b/b\n"));
g_assert_nonnull (strstr (output, "\nok 4 /c/a\n"));
g_assert_nonnull (strstr (output, "\nok 5 /d/a\n"));
g_spawn_check_exit_status (status, &error);
g_assert_no_error (error);
g_free (output);
g_ptr_array_unref (argv);
g_test_message ("--GTestSkipCount > number of tests skips all");
argv = g_ptr_array_new ();
g_ptr_array_add (argv, (char *) testing_helper);
g_ptr_array_add (argv, "skip-options");
g_ptr_array_add (argv, "--tap");
g_ptr_array_add (argv, "--GTestSkipCount");
g_ptr_array_add (argv, "6");
g_ptr_array_add (argv, NULL);
g_spawn_sync (NULL, (char **) argv->pdata, NULL,
G_SPAWN_STDERR_TO_DEV_NULL,
NULL, NULL, &output, NULL, &status,
&error);
g_assert_no_error (error);
g_assert_nonnull (strstr (output, "1..5\n"));
g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP\n"));
g_assert_nonnull (strstr (output, "\nok 2 /b/a # SKIP\n"));
g_assert_nonnull (strstr (output, "\nok 3 /b/b # SKIP\n"));
g_assert_nonnull (strstr (output, "\nok 4 /c/a # SKIP\n"));
g_assert_nonnull (strstr (output, "\nok 5 /d/a # SKIP\n"));
g_spawn_check_exit_status (status, &error);
g_assert_no_error (error);
g_free (output);
g_ptr_array_unref (argv);
g_test_message ("-p");
argv = g_ptr_array_new ();
g_ptr_array_add (argv, (char *) testing_helper);
g_ptr_array_add (argv, "skip-options");
g_ptr_array_add (argv, "--tap");
g_ptr_array_add (argv, "-p");
g_ptr_array_add (argv, "/c/a");
g_ptr_array_add (argv, "-p");
g_ptr_array_add (argv, "/c/a");
g_ptr_array_add (argv, "-p");
g_ptr_array_add (argv, "/b");
g_ptr_array_add (argv, NULL);
g_spawn_sync (NULL, (char **) argv->pdata, NULL,
G_SPAWN_STDERR_TO_DEV_NULL,
NULL, NULL, &output, NULL, &status,
&error);
g_assert_no_error (error);
/* FIXME: Tests are run in an order that is the reverse of the order
* of -p options. */
g_assert_nonnull (strstr (output, "\nok 1 /b/a\n"));
g_assert_nonnull (strstr (output, "\nok 2 /b/b\n"));
g_assert_nonnull (strstr (output, "\nok 3 /c/a\n"));
g_assert_nonnull (strstr (output, "\nok 4 /c/a\n"));
g_assert_nonnull (strstr (output, "\n1..4\n"));
g_spawn_check_exit_status (status, &error);
g_assert_no_error (error);
g_free (output);
g_ptr_array_unref (argv);
g_test_message ("-s");
argv = g_ptr_array_new ();
g_ptr_array_add (argv, (char *) testing_helper);
g_ptr_array_add (argv, "skip-options");
g_ptr_array_add (argv, "--tap");
g_ptr_array_add (argv, "-s");
g_ptr_array_add (argv, "/a");
g_ptr_array_add (argv, "-s");
g_ptr_array_add (argv, "/b");
g_ptr_array_add (argv, "-s");
g_ptr_array_add (argv, "/c/a");
g_ptr_array_add (argv, NULL);
g_spawn_sync (NULL, (char **) argv->pdata, NULL,
G_SPAWN_STDERR_TO_DEV_NULL,
NULL, NULL, &output, NULL, &status,
&error);
g_assert_no_error (error);
g_assert_nonnull (strstr (output, "1..5\n"));
g_assert_nonnull (strstr (output, "\nok 1 /a # SKIP by request"));
/* "-s /b" would skip a test named exactly /b, but not a test named
* /b/anything */
g_assert_nonnull (strstr (output, "\nok 2 /b/a\n"));
g_assert_nonnull (strstr (output, "\nok 3 /b/b\n"));
g_assert_nonnull (strstr (output, "\nok 4 /c/a # SKIP by request"));
g_assert_nonnull (strstr (output, "\nok 5 /d/a\n"));
g_spawn_check_exit_status (status, &error);
g_assert_no_error (error);
g_free (output);
g_ptr_array_unref (argv);
} }
int int