gtestutils: Do not allow newlines in Bail out! messages

It would break TAP parsing, so let's just print all inline
This commit is contained in:
Marco Trevisan (Treviño) 2023-01-16 21:36:15 +01:00
parent a3f26bd509
commit 9cfae23915
3 changed files with 15 additions and 5 deletions

View File

@ -1135,9 +1135,19 @@ g_test_log (GTestLogType lbit,
break;
case G_TEST_LOG_ERROR:
if (test_tap_log)
g_print ("%sBail out! %s\n", test_is_subtest ? "# " : "", string1);
{
char *message = g_strdup (string1);
char *line = message;
while ((line = strchr (line, '\n')))
*(line++) = ' ';
g_print ("%sBail out! %s\n", test_is_subtest ? "# " : "", g_strstrip (message));
}
else if (g_test_verbose ())
g_print ("(ERROR: %s)\n", string1);
{
g_print ("(ERROR: %s)\n", string1);
}
break;
default: ;
}

View File

@ -54,7 +54,7 @@ test_fail (void)
static void
test_error (void)
{
g_error ("This should error out\nBecause it's just wrong!");
g_error ("This should error out\nBecause it's just\nwrong!");
}
static void

View File

@ -1730,7 +1730,7 @@ test_tap_error (void)
g_assert_nonnull (interesting_lines);
interesting_lines += strlen (expected_tap_header);
g_assert_cmpstr (interesting_lines, ==, "# Bail out! GLib-FATAL-ERROR: This should error out\n"
g_assert_cmpstr (interesting_lines, ==, "# Bail out! GLib-FATAL-ERROR: This should error out "
"Because it's just wrong!\n");
g_free (output);
@ -1771,7 +1771,7 @@ test_tap_error_and_pass (void)
g_assert_nonnull (interesting_lines);
interesting_lines += strlen (expected_tap_header);
g_assert_cmpstr (interesting_lines, ==, "# Bail out! GLib-FATAL-ERROR: This should error out\n"
g_assert_cmpstr (interesting_lines, ==, "# Bail out! GLib-FATAL-ERROR: This should error out "
"Because it's just wrong!\n");
g_free (output);