From be0b921115c319186c678a054958f405b8c90a2b Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Thu, 10 Apr 2014 11:37:23 -0400 Subject: [PATCH] Fix up failure-to-see-expected-message logging When GLib had been told to expect message X, but then actually saw message Y, it would log the "did not see expected message" error with message Y's log level and domain, which makes no sense. Change it to log with domain "GLib" and G_LOG_LEVEL_CRITICAL instead. Also, include the expected domain in the error message, so that if that's the reason why the expectation didn't match, you can tell that from the error message. Update glib/tests/testing.c for these changes; for all other test programs in GLib and elsewhere, this change should not break any existing tests, it should only improve the output on failure. https://bugzilla.gnome.org/show_bug.cgi?id=727974 --- glib/gmessages.c | 10 ++++++---- glib/tests/testing.c | 12 +++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/glib/gmessages.c b/glib/gmessages.c index 53728cd..c1b5622 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -969,9 +969,10 @@ g_logv (const gchar *log_domain, gchar *expected_message; mklevel_prefix (level_prefix, expected->log_level); - expected_message = g_strdup_printf ("Did not see expected message %s: %s", + expected_message = g_strdup_printf ("Did not see expected message %s-%s: %s", + expected->log_domain ? expected->log_domain : "**", level_prefix, expected->pattern); - g_log_default_handler (log_domain, log_level, expected_message, NULL); + g_log_default_handler (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, expected_message, NULL); g_free (expected_message); log_level |= G_LOG_FLAG_FATAL; @@ -1211,9 +1212,10 @@ g_test_assert_expected_messages_internal (const char *domain, expected = expected_messages->data; mklevel_prefix (level_prefix, expected->log_level); - message = g_strdup_printf ("Did not see expected message %s: %s", + message = g_strdup_printf ("Did not see expected message %s-%s: %s", + expected->log_domain ? expected->log_domain : "**", level_prefix, expected->pattern); - g_assertion_message (domain, file, line, func, message); + g_assertion_message (G_LOG_DOMAIN, file, line, func, message); g_free (message); } } diff --git a/glib/tests/testing.c b/glib/tests/testing.c index c616f9a..85acb4a 100644 --- a/glib/tests/testing.c +++ b/glib/tests/testing.c @@ -20,6 +20,12 @@ * if advised of the possibility of such damage. */ +/* We want to distinguish between messages originating from libglib + * and messages originating from this program. + */ +#undef G_LOG_DOMAIN +#define G_LOG_DOMAIN "testing" + #include #include @@ -380,7 +386,7 @@ static void test_expected_messages_expect_error (void) { /* make sure we can't try to expect a g_error() */ - g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "*G_LOG_LEVEL_ERROR*"); + g_test_expect_message ("GLib", G_LOG_LEVEL_CRITICAL, "*G_LOG_LEVEL_ERROR*"); g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, "this won't work"); g_test_assert_expected_messages (); } @@ -433,7 +439,7 @@ test_expected_messages (void) g_test_trap_subprocess ("/misc/expected-messages/subprocess/wrong-warning", 0, 0); g_test_trap_assert_failed (); g_test_trap_assert_stderr_unmatched ("*should not be reached*"); - g_test_trap_assert_stderr ("*Did not see expected message CRITICAL*should not be *WARNING*This is a * warning*"); + g_test_trap_assert_stderr ("*GLib-CRITICAL*Did not see expected message testing-CRITICAL*should not be *WARNING*This is a * warning*"); g_test_trap_subprocess ("/misc/expected-messages/subprocess/expected", 0, 0); g_test_trap_assert_passed (); @@ -449,7 +455,7 @@ test_expected_messages (void) g_test_trap_subprocess ("/misc/expected-messages/subprocess/unexpected-extra-warning", 0, 0); g_test_trap_assert_failed (); - g_test_trap_assert_stderr ("*Did not see expected message CRITICAL*nope*"); + g_test_trap_assert_stderr ("*GLib:ERROR*Did not see expected message testing-CRITICAL*nope*"); } static void -- 2.7.4