win32: suppress fatal error dialog box when running tests
authorDan Winship <danw@gnome.org>
Fri, 16 Nov 2012 03:26:54 +0000 (22:26 -0500)
committerDan Winship <danw@gnome.org>
Wed, 5 Dec 2012 16:15:19 +0000 (11:15 -0500)
When running a test program (ie, if g_test_init() has been called),
don't pop up a dialog box when a fatal error occurs. Just print the
message to stderr and exit.

https://bugzilla.gnome.org/show_bug.cgi?id=679683

docs/reference/glib/glib-sections.txt
glib/gmessages.c
glib/gtestutils.c
glib/gtestutils.h

index 546bc98..e4e9df4 100644 (file)
@@ -2877,6 +2877,7 @@ g_compute_hmac_for_string
 g_test_minimized_result
 g_test_maximized_result
 g_test_init
+g_test_initialized
 g_test_quick
 g_test_slow
 g_test_thorough
index e2be9ab..91d7a21 100644 (file)
@@ -820,7 +820,8 @@ mklevel_prefix (gchar          level_prefix[STRING_BUFFER_SIZE],
     strcat (level_prefix, " **");
 
 #ifdef G_OS_WIN32
-  win32_keep_fatal_message = (log_level & G_LOG_FLAG_FATAL) != 0;
+  if ((log_level & G_LOG_FLAG_FATAL) != 0 && !g_test_initialized ())
+    win32_keep_fatal_message = TRUE;
 #endif
   return to_stdout ? 1 : 2;
 }
@@ -954,10 +955,13 @@ g_logv (const gchar   *log_domain,
          if ((test_level & G_LOG_FLAG_FATAL) && !masquerade_fatal)
             {
 #ifdef G_OS_WIN32
-             gchar *locale_msg = g_locale_from_utf8 (fatal_msg_buf, -1, NULL, NULL, NULL);
-             
-             MessageBox (NULL, locale_msg, NULL,
-                         MB_ICONERROR|MB_SETFOREGROUND);
+              if (win32_keep_fatal_message)
+                {
+                  gchar *locale_msg = g_locale_from_utf8 (fatal_msg_buf, -1, NULL, NULL, NULL);
+
+                  MessageBox (NULL, locale_msg, NULL,
+                              MB_ICONERROR|MB_SETFOREGROUND);
+                }
              if (IsDebuggerPresent () && !(test_level & G_LOG_FLAG_RECURSION))
                G_BREAKPOINT ();
              else
index 5fba96f..c7b7249 100644 (file)
  */
 
 /**
+ * g_test_initialized:
+ *
+ * Returns %TRUE if g_test_init() has been called.
+ *
+ * Returns: %TRUE if g_test_init() has been called.
+ *
+ * Since: 2.36
+ */
+
+/**
  * g_test_quick:
  *
  * Returns %TRUE if tests are run in quick mode.
index 967fa63..3721519 100644 (file)
@@ -92,6 +92,7 @@ void    g_test_init                     (int            *argc,
                                          char         ***argv,
                                          ...);
 /* query testing framework config */
+#define g_test_initialized()            (g_test_config_vars->test_initialized)
 #define g_test_quick()                  (g_test_config_vars->test_quick)
 #define g_test_slow()                   (!g_test_config_vars->test_quick)
 #define g_test_thorough()               (!g_test_config_vars->test_quick)