[ Version ( since = "2.34" ) ]
public void expect_message (string? log_domain, LogLevelFlags log_level, string pattern)

Indicates that a message with the given log_domain and log_level, with text matching pattern, is expected to be logged.

When this message is logged, it will not be printed, and the test case will not abort.

This API may only be used with the old logging API (log without g_log_use_structured defined). It will not work with the structured logging API. See Testing for Messages .

Use assert_expected_messages to assert that all previously-expected messages have been seen and suppressed.

You can call this multiple times in a row, if multiple messages are expected as a result of a single call. (The messages must appear in the same order as the calls to expect_message.)

For example:

  // g_main_context_push_thread_default() should fail if the
// context is already owned by another thread.
g_test_expect_message (G_LOG_DOMAIN,
g_main_context_push_thread_default (bad_context);
g_test_assert_expected_messages ();

Note that you cannot use this to test error messages, since error intentionally never returns even if the program doesn't abort; use trap_subprocess in this case.

If messages at g_log_level_debug are emitted, but not explicitly expected via expect_message then they will be ignored.



the log domain of the message


the log level of the message


a glob-style pattern

Namespace: GLib.Test
Package: glib-2.0