From 44f13124c9d6d66760bd800d7d1ce68dc53ad5f2 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 28 Oct 2013 10:12:29 +0100 Subject: [PATCH] test: g_debug messages shouldn't affect g_assert_expected_messages Debug messages are meant to give insight into how a process is proceeding, and are unpredictable in nature. They also often have line numbers in them. This patch ignores debug messages in g_test_assert_expected_messages(). https://bugzilla.gnome.org/show_bug.cgi?id=710991 --- glib/gmessages.c | 12 +++++++++--- glib/tests/testing.c | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/glib/gmessages.c b/glib/gmessages.c index d09552e..26018cd 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -922,19 +922,19 @@ g_logv (const gchar *log_domain, { GTestExpectedMessage *expected = expected_messages->data; - expected_messages = g_slist_delete_link (expected_messages, - expected_messages); if (g_strcmp0 (expected->log_domain, log_domain) == 0 && ((log_level & expected->log_level) == expected->log_level) && g_pattern_match_simple (expected->pattern, msg)) { + expected_messages = g_slist_delete_link (expected_messages, + expected_messages); g_free (expected->log_domain); g_free (expected->pattern); g_free (expected); g_free (msg_alloc); return; } - else + else if ((log_level & G_LOG_LEVEL_DEBUG) != G_LOG_LEVEL_DEBUG) { gchar level_prefix[STRING_BUFFER_SIZE]; gchar *expected_message; @@ -1148,6 +1148,9 @@ g_assert_warning (const char *log_domain, * g_error() intentionally never returns even if the program doesn't * abort; use g_test_trap_subprocess() in this case. * + * If messages at %G_LOG_LEVEL_DEBUG are emitted, but not explicitly + * expected via g_test_expect_message() then they will be ignored. + * * Since: 2.34 */ void @@ -1197,6 +1200,9 @@ g_test_assert_expected_messages_internal (const char *domain, * Asserts that all messages previously indicated via * g_test_expect_message() have been seen and suppressed. * + * If messages at %G_LOG_LEVEL_DEBUG are emitted, but not explicitly + * expected via g_test_expect_message() then they will be ignored. + * * Since: 2.34 */ diff --git a/glib/tests/testing.c b/glib/tests/testing.c index 2adc003..90f11bb 100644 --- a/glib/tests/testing.c +++ b/glib/tests/testing.c @@ -457,6 +457,19 @@ test_expected_messages (void) } static void +test_expected_messages_debug (void) +{ + g_test_expect_message ("Test", G_LOG_LEVEL_WARNING, "warning message"); + g_log ("Test", G_LOG_LEVEL_DEBUG, "should be ignored"); + g_log ("Test", G_LOG_LEVEL_WARNING, "warning message"); + g_test_assert_expected_messages (); + + g_test_expect_message ("Test", G_LOG_LEVEL_DEBUG, "debug message"); + g_log ("Test", G_LOG_LEVEL_DEBUG, "debug message"); + g_test_assert_expected_messages (); +} + +static void test_dash_p_hidden (void) { if (!g_test_subprocess ()) @@ -600,6 +613,7 @@ main (int argc, g_test_add_func ("/misc/expected-messages/subprocess/extra-warning", test_expected_messages_extra_warning); g_test_add_func ("/misc/expected-messages/subprocess/unexpected-extra-warning", test_expected_messages_unexpected_extra_warning); g_test_add_func ("/misc/expected-messages/expect-error", test_expected_messages_expect_error); + g_test_add_func ("/misc/expected-messages/skip-debug", test_expected_messages_debug); g_test_add_func ("/misc/dash-p", test_dash_p); g_test_add_func ("/misc/dash-p/child", test_dash_p_child); -- 2.7.4