summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2021-04-01 14:26:32 +0100
committerEmmanuele Bassi <ebassi@gnome.org>2021-04-01 14:26:32 +0100
commit10e1d7f11d1b5ea636c0abeca5decaf853055cc4 (patch)
treec241c0d1b97fd6cc4d3eb257069ff5e6aea549a8
parent32fc1e6bbfd15fe5051d72e99614197fe2be8053 (diff)
downloadglib-ebassi/test-tap-lines.tar.gz
Split g_test_log() messages that contain multiple linesebassi/test-tap-lines
When using TAP we want every single line to be one of the following: - a valid TAP clause - a comment - a blank line Typical explicit test logs are single line comments, but in some cases we might end up printing debug messages from libraries, and those may contain multiple lines. When that happens, we break the TAP and fail the test in conditions entirely outside of our control. One option to avoid outright failure is to always prepend each line of a messge with `#`, to ensure that the whole thing is considered a comment.
-rw-r--r--glib/gtestutils.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index d24c6e186..dc153d1af 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -1072,7 +1072,20 @@ g_test_log (GTestLogType lbit,
break;
case G_TEST_LOG_MESSAGE:
if (test_tap_log)
- g_print ("# %s\n", string1);
+ {
+ if (strstr (string1, "\n") == NULL)
+ g_print ("# %s\n", string1);
+ else
+ {
+ char **lines = g_strsplit (string1, "\n", -1);
+ guint n_lines = g_strv_length (lines);
+
+ for (guint i = 0; i < n_lines; i++)
+ g_print ("# %s\n", lines[i]);
+
+ g_strfreev (lines);
+ }
+ }
else if (g_test_verbose ())
g_print ("(MSG: %s)\n", string1);
break;