util: Make meta_topic() log using the debug level in tests
Some tests expect warnings to be logged, and handle that using g_test_expect_message(). However, if debug topics are enabled, this causes g_logv() to expect expected messages to also contain entries with the debug level 'message' or higher to be listed in the expected message list. Since meta_topic() always logged using g_message(), enabling debug topics caused any test that used g_test_expect_message() and had debug logging somewhere along the code path to fail. Fix this by changing the log level of meta_topic() to 'debug' if we're in a test. This doesn't mean they won't be visible, they still will since debug log entries are printed by default during testing. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2800>
This commit is contained in:
parent
e5602062e2
commit
11d35f99be
@ -79,6 +79,7 @@ static const GDebugKey meta_debug_keys[] = {
|
||||
static gint verbose_topics = 0;
|
||||
static gboolean is_wayland_compositor = FALSE;
|
||||
static int debug_paint_flags = 0;
|
||||
static GLogLevelFlags mutter_log_level = G_LOG_LEVEL_MESSAGE;
|
||||
|
||||
#ifdef WITH_VERBOSE_MODE
|
||||
static FILE* logfile = NULL;
|
||||
@ -213,6 +214,9 @@ meta_init_debug_utils (void)
|
||||
G_N_ELEMENTS (meta_debug_keys));
|
||||
meta_add_verbose_topic (topics);
|
||||
}
|
||||
|
||||
if (g_test_initialized ())
|
||||
mutter_log_level = G_LOG_LEVEL_DEBUG;
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -584,3 +588,13 @@ meta_get_debug_paint_flags (void)
|
||||
{
|
||||
return debug_paint_flags;
|
||||
}
|
||||
|
||||
void
|
||||
meta_log (const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
g_logv (G_LOG_DOMAIN, mutter_log_level, format, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
@ -157,6 +157,9 @@ char* meta_g_utf8_strndup (const gchar *src, gsize n);
|
||||
|
||||
const char * meta_topic_to_string (MetaDebugTopic topic);
|
||||
|
||||
META_EXPORT
|
||||
void meta_log (const char *format, ...) G_GNUC_PRINTF (1, 2);
|
||||
|
||||
#define meta_topic(debug_topic, ...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
@ -165,7 +168,7 @@ const char * meta_topic_to_string (MetaDebugTopic topic);
|
||||
g_autofree char *_topic_message = NULL; \
|
||||
\
|
||||
_topic_message = g_strdup_printf (__VA_ARGS__); \
|
||||
g_message ("%s: %s", meta_topic_to_string (debug_topic), \
|
||||
meta_log ("%s: %s", meta_topic_to_string (debug_topic), \
|
||||
_topic_message); \
|
||||
} \
|
||||
} \
|
||||
|
Loading…
Reference in New Issue
Block a user