diff --git a/glib/gtestutils.c b/glib/gtestutils.c index edf5ba1b5ed9ebfe2bb7ca9993b0bc0f835d93e3..9d92bf74e1392639fa302b557149f5d10b62dc01 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -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: @@ -994,6 +1001,10 @@ g_test_log (GTestLogType lbit, if (result == G_TEST_RUN_SKIPPED || result == G_TEST_RUN_INCOMPLETE) test_skipped_count++; 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: if (test_tap_log) g_print ("# min perf: %s\n", string1); @@ -1535,18 +1546,6 @@ void 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 */ if (1) { diff --git a/glib/tests/testing-helper.c b/glib/tests/testing-helper.c index b0e1f4a989b7f926ee710f8d1fd4470bff20558b..c472778a51f4f75205bedfd1f4c4940abb9df895 100644 --- a/glib/tests/testing-helper.c +++ b/glib/tests/testing-helper.c @@ -101,6 +101,16 @@ main (int argc, g_test_add_func ("/incomplete", test_incomplete); 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 { g_assert_not_reached (); diff --git a/glib/tests/testing.c b/glib/tests/testing.c index 03b9ca2c4dc296a2accfcf349857ae08c95b8801..28dfd86322196744f96bb3f419d74135da7142f9 100644 --- a/glib/tests/testing.c +++ b/glib/tests/testing.c @@ -1063,6 +1063,152 @@ test_tap (void) g_assert_no_error (error); 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