[glib/glib-2-68: 1/2] Split g_test_log() messages that contain multiple lines
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-68: 1/2] Split g_test_log() messages that contain multiple lines
- Date: Thu, 8 Apr 2021 13:41:10 +0000 (UTC)
commit 2e3775426199ad3ac4b080251aa23b47d82d4122
Author: Emmanuele Bassi <ebassi gnome org>
Date: Thu Apr 1 14:26:32 2021 +0100
Split g_test_log() messages that contain multiple 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.
glib/gtestutils.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
---
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index d24c6e186..d9a04e044 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);
+ gsize i;
+
+ for (i = 0; lines[i] != NULL; i++)
+ g_print ("# %s\n", lines[i]);
+
+ g_strfreev (lines);
+ }
+ }
else if (g_test_verbose ())
g_print ("(MSG: %s)\n", string1);
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]