[glib] Support TAP as an output format



commit 19aafc4ca4dba2b63d24f01d23890ff30ef9b133
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 17 14:16:37 2013 -0400

    Support TAP as an output format
    
    Initial support for the Test Anything Protocol for
    GTest output. Use the --tap option to get TAP output.
    More information about TAP can be found e.g. here:
    http://en.wikipedia.org/wiki/Test_Anything_Protocol
    
    https://bugzilla.gnome.org/show_bug.cgi?id=692125

 glib/gtestutils.c |   59 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 51 insertions(+), 8 deletions(-)
---
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index 086ff1d..e74d11e 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -570,6 +570,7 @@ static char       *test_trap_last_stdout = NULL;
 static char       *test_trap_last_stderr = NULL;
 static char       *test_uri_base = NULL;
 static gboolean    test_debug_log = FALSE;
+static gboolean    test_tap_log = FALSE;
 static DestroyEntry *test_destroy_queue = NULL;
 static char       *test_argv0 = NULL;
 static char       *test_argv0_dirname;
@@ -658,7 +659,7 @@ g_test_log (GTestLogType lbit,
             guint        n_args,
             long double *largs)
 {
-  gboolean fail = lbit == G_TEST_LOG_STOP_CASE && largs[0] != G_TEST_RUN_SUCCESS;
+  gboolean fail;
   GTestLogMsg msg;
   gchar *astrings[3] = { NULL, NULL, NULL };
   guint8 *dbuffer;
@@ -667,32 +668,67 @@ g_test_log (GTestLogType lbit,
   switch (lbit)
     {
     case G_TEST_LOG_START_BINARY:
-      if (g_test_verbose())
+      if (test_tap_log)
+        g_print ("# random seed: %s\n", string2);
+      else if (g_test_verbose())
         g_print ("GTest: random seed: %s\n", string2);
       break;
     case G_TEST_LOG_START_SUITE:
+      if (test_tap_log)
+        {
+          if (string1[0] != 0)
+            g_print ("# Start of %s tests\n", string1);
+        }
       break;
     case G_TEST_LOG_STOP_SUITE:
+      if (test_tap_log)
+        {
+          if (string1[0] != 0)
+            g_print ("# End of %s tests\n", string1);
+          else
+            g_print ("1..%d\n", test_run_count);
+        }
       break;
     case G_TEST_LOG_STOP_CASE:
-      if (g_test_verbose())
+      fail = largs[0] != G_TEST_RUN_SUCCESS && largs[0] != G_TEST_RUN_SKIPPED;
+      if (test_tap_log)
+        {
+          g_print ("%s %d %s", fail ? "not ok" : "ok", test_run_count, string1);
+          if (largs[0] == G_TEST_RUN_INCOMPLETE)
+            g_print (" # TODO %s\n", string2 ? string2 : "");
+          else if (largs[0] == G_TEST_RUN_SKIPPED)
+            g_print (" # SKIP %s\n", string2 ? string2 : "");
+          else
+            g_print ("\n");
+        }
+      else if (g_test_verbose())
         g_print ("GTest: result: %s\n", fail ? "FAIL" : "OK");
       else if (!g_test_quiet())
         g_print ("%s\n", fail ? "FAIL" : "OK");
       if (fail && test_mode_fatal)
-        abort();
+        {
+          if (test_tap_log)
+            g_print ("Bail out!\n");
+          abort();
+        }
       break;
     case G_TEST_LOG_MIN_RESULT:
-      if (g_test_verbose())
+      if (test_tap_log)
+        g_print ("# min perf: %s\n", string1);
+      else if (g_test_verbose())
         g_print ("(MINPERF:%s)\n", string1);
       break;
     case G_TEST_LOG_MAX_RESULT:
-      if (g_test_verbose())
+      if (test_tap_log)
+        g_print ("# max perf: %s\n", string1);
+      else if (g_test_verbose())
         g_print ("(MAXPERF:%s)\n", string1);
       break;
     case G_TEST_LOG_MESSAGE:
     case G_TEST_LOG_ERROR:
-      if (g_test_verbose())
+      if (test_tap_log)
+        g_print ("# %s\n", string1);
+      else if (g_test_verbose())
         g_print ("(MSG: %s)\n", string1);
       break;
     default: ;
@@ -712,7 +748,9 @@ g_test_log (GTestLogType lbit,
   switch (lbit)
     {
     case G_TEST_LOG_START_CASE:
-      if (g_test_verbose())
+      if (test_tap_log)
+        ;
+      else if (g_test_verbose())
         g_print ("GTest: run: %s\n", string1);
       else if (!g_test_quiet())
         g_print ("%s: ", string1);
@@ -756,6 +794,11 @@ parse_args (gint    *argc_p,
           test_debug_log = TRUE;
           argv[i] = NULL;
         }
+      else if (strcmp (argv[i], "--tap") == 0)
+        {
+          test_tap_log = TRUE;
+          argv[i] = NULL;
+        }
       else if (strcmp ("--GTestLogFD", argv[i]) == 0 || strncmp ("--GTestLogFD=", argv[i], 13) == 0)
         {
           gchar *equal = argv[i] + 12;


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