[glib: 4/8] gtestutils: Allow combining --tap with -p



commit b24cdffd5cb0954e7b2dd24f6d65058fec7f9c83
Author: Simon McVittie <smcv collabora com>
Date:   Fri Jan 4 12:53:04 2019 +0000

    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>

 glib/gtestutils.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
---
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index 2418ac6da..9d92bf74e 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:
@@ -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)
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]