diff --git a/glib/gtestutils.c b/glib/gtestutils.c index 40d420c3a..84d4bca93 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -1094,17 +1094,34 @@ g_test_log (GTestLogType lbit, case G_TEST_LOG_MESSAGE: if (test_tap_log) { - if (strstr (string1, "\n") == NULL) + if (strchr (string1, '\n') == NULL) g_print ("# %s\n", string1); else { - char **lines = g_strsplit (string1, "\n", -1); - gsize i; + GString *output = g_string_new (NULL); + const char *line = string1; - for (i = 0; lines[i] != NULL; i++) - g_print ("# %s\n", lines[i]); + do + { + const char *next = strchr (line, '\n'); + g_string_append (output, "# "); - g_strfreev (lines); + if (next) + { + g_string_append_len (output, line, next - line + 1); + line = next + 1; + } + else + { + g_string_append (output, line); + g_string_append_c (output, '\n'); + line = next; + } + } + while (line != NULL); + + g_print ("%s", output->str); + g_string_free (g_steal_pointer (&output), TRUE); } } else if (g_test_verbose ()) diff --git a/glib/tests/testing-helper.c b/glib/tests/testing-helper.c index 647aabf4e..4479bc7be 100644 --- a/glib/tests/testing-helper.c +++ b/glib/tests/testing-helper.c @@ -83,8 +83,8 @@ static void test_message (void) { g_test_message ("Tests that single line message works"); - g_test_message ("Tests that multi\nline\nmessage\nworks"); - g_test_message ("Tests that multi\nline\nmessage\nworks with trailing too\n"); + g_test_message ("Tests that multi\n\nline\nmessage\nworks"); + g_test_message ("\nTests that multi\nline\nmessage\nworks with leading and trailing too\n"); } int diff --git a/glib/tests/testing.c b/glib/tests/testing.c index 28f92cec1..c97f9db62 100644 --- a/glib/tests/testing.c +++ b/glib/tests/testing.c @@ -1676,18 +1676,20 @@ test_tap_message (void) interesting_lines += strlen (expected_tap_header); output_lines = g_strsplit (interesting_lines, "\n", -1); - g_assert_cmpuint (g_strv_length (output_lines), >=, 10); + g_assert_cmpuint (g_strv_length (output_lines), >=, 12); guint i = 0; g_assert_cmpstr (output_lines[i++], ==, "# Tests that single line message works"); g_assert_cmpstr (output_lines[i++], ==, "# Tests that multi"); + g_assert_cmpstr (output_lines[i++], ==, "# "); g_assert_cmpstr (output_lines[i++], ==, "# line"); g_assert_cmpstr (output_lines[i++], ==, "# message"); g_assert_cmpstr (output_lines[i++], ==, "# works"); + g_assert_cmpstr (output_lines[i++], ==, "# "); g_assert_cmpstr (output_lines[i++], ==, "# Tests that multi"); g_assert_cmpstr (output_lines[i++], ==, "# line"); g_assert_cmpstr (output_lines[i++], ==, "# message"); - g_assert_cmpstr (output_lines[i++], ==, "# works with trailing too"); + g_assert_cmpstr (output_lines[i++], ==, "# works with leading and trailing too"); g_assert_cmpstr (output_lines[i++], ==, "# "); g_free (output);