[glib] testutils: Report fatal errors and warnings as TAP



commit 23ba8aec925a6632a44d1ab47514d606210dff73
Author: Simon McVittie <smcv collabora com>
Date:   Tue Oct 3 13:31:38 2017 +0100

    testutils: Report fatal errors and warnings as TAP
    
    Lines starting with "Bail out!" are special TAP syntax: they mark
    the entire test execution (one binary or script) as failed, and stop
    processing. Automake's parallel test harness knows this, and will print
    the diagnostic in the test results, leading to clearer output.
    
    Without this change, having changed glib/tests/bytes.c to emit a
    spurious g_warning():
    
    ERROR: bytes - too few tests run (expected 15, got 0)
    ERROR: bytes - exited with status 133 (terminated by signal 5?)
    
    With this change, it's clearer what has happened:
    
    ERROR: bytes - Bail out! FATAL-WARNING: I broke this as a demonstration
    
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=788467
    Signed-off-by: Simon McVittie <smcv collabora com>
    Reviewed-by: Philip Withnall <withnall endlessm com>

 glib/gtestutils.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index 52a216f..a1109b5 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -712,6 +712,7 @@ static char       *test_argv0_dirname;
 static const char *test_disted_files_dir;
 static const char *test_built_files_dir;
 static char       *test_initial_cwd = NULL;
+static gboolean    test_in_forked_child = FALSE;
 static gboolean    test_in_subprocess = FALSE;
 static GTestConfig mutable_test_config_vars = {
   FALSE,        /* test_initialized */
@@ -865,12 +866,17 @@ g_test_log (GTestLogType lbit,
         g_print ("(MAXPERF:%s)\n", string1);
       break;
     case G_TEST_LOG_MESSAGE:
-    case G_TEST_LOG_ERROR:
       if (test_tap_log)
         g_print ("# %s\n", string1);
       else if (g_test_verbose())
         g_print ("(MSG: %s)\n", string1);
       break;
+    case G_TEST_LOG_ERROR:
+      if (test_tap_log)
+        g_print ("Bail out! %s\n", string1);
+      else if (g_test_verbose())
+        g_print ("(ERROR: %s)\n", string1);
+      break;
     default: ;
     }
 
@@ -2405,7 +2411,12 @@ g_assertion_message (const char     *domain,
                    " ", message, NULL);
   g_printerr ("**\n%s\n", s);
 
-  g_test_log (G_TEST_LOG_ERROR, s, NULL, 0, NULL);
+  /* Don't print a fatal error indication if assertions are non-fatal, or
+   * if we are a child process that might be sharing the parent's stdout. */
+  if (test_nonfatal_assertions || test_in_subprocess || test_in_forked_child)
+    g_test_log (G_TEST_LOG_MESSAGE, s, NULL, 0, NULL);
+  else
+    g_test_log (G_TEST_LOG_ERROR, s, NULL, 0, NULL);
 
   if (test_nonfatal_assertions)
     {
@@ -2838,6 +2849,7 @@ g_test_trap_fork (guint64        usec_timeout,
   if (test_trap_last_pid == 0)  /* child */
     {
       int fd0 = -1;
+      test_in_forked_child = TRUE;
       close (stdout_pipe[0]);
       close (stderr_pipe[0]);
       if (!(test_trap_flags & G_TEST_TRAP_INHERIT_STDIN))


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