From a707cebcd9182386af206678a6000fffe8d169bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 20 Jan 2023 15:16:28 +0100 Subject: [PATCH] gtestutils: Improve TAP reporting on tests failures When we've a failure our TAP reporting just bails out without that is clear what is the test that has failed. So in this case, expose a "not ok" message if the test name is known, and use it to report the error message too if available. Otherwise just use the same Bail out! strategy. --- glib/gtestutils.c | 21 ++++++++++++++++++++- glib/tests/testing.c | 20 ++++++++++++-------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/glib/gtestutils.c b/glib/gtestutils.c index 597629820..4945027dc 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -1219,7 +1219,26 @@ g_test_log (GTestLogType lbit, while ((line = strchr (line, '\n'))) *(line++) = ' '; - g_test_tap_print (subtest_level, FALSE, "Bail out! %s\n", message); + if (message) + message = g_strstrip (message); + + if (test_run_name && *test_run_name != '\0') + { + if (message && *message != '\0') + g_test_tap_print (subtest_level, FALSE, "not ok %s - %s\n", + test_run_name, message); + else + g_test_tap_print (subtest_level, FALSE, "not ok %s\n", + test_run_name); + + g_clear_pointer (&message, g_free); + } + + if (message && *message != '\0') + g_test_tap_print (subtest_level, FALSE, "Bail out! %s\n", message); + else + g_test_tap_print (subtest_level, FALSE, "Bail out!\n"); + g_free (message); } else if (g_test_verbose ()) diff --git a/glib/tests/testing.c b/glib/tests/testing.c index 3f335b4ac..e7baf7ca2 100644 --- a/glib/tests/testing.c +++ b/glib/tests/testing.c @@ -2676,8 +2676,9 @@ 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 " - "Because it's just wrong!\n"); + g_assert_cmpstr (interesting_lines, ==, "not ok /error - GLib-FATAL-ERROR: This should error out " + "Because it's just wrong!\n" + "Bail out!\n"); g_free (output); g_strfreev (envp); @@ -2721,8 +2722,9 @@ test_tap_subtest_error (void) interesting_lines += strlen (expected_tap_header); g_assert_cmpstr (interesting_lines, ==, - TAP_SUBTEST_PREFIX "Bail out! GLib-FATAL-ERROR: This should error out " - "Because it's just wrong!\n"); + TAP_SUBTEST_PREFIX "not ok /error - GLib-FATAL-ERROR: This should error out " + "Because it's just wrong!\n" + TAP_SUBTEST_PREFIX "Bail out!\n"); g_free (output); g_ptr_array_unref (argv); @@ -2768,8 +2770,9 @@ 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 " - "Because it's just wrong!\n"); + g_assert_cmpstr (interesting_lines, ==, "not ok /error - GLib-FATAL-ERROR: This should error out " + "Because it's just wrong!\n" + "Bail out!\n"); g_free (output); g_strfreev (envp); @@ -2813,8 +2816,9 @@ test_tap_subtest_error_and_pass (void) interesting_lines += strlen (expected_tap_header); g_assert_cmpstr (interesting_lines, ==, - TAP_SUBTEST_PREFIX "Bail out! GLib-FATAL-ERROR: This should error out " - "Because it's just wrong!\n"); + TAP_SUBTEST_PREFIX "not ok /error - GLib-FATAL-ERROR: This should error out " + "Because it's just wrong!\n" + TAP_SUBTEST_PREFIX "Bail out!\n"); g_free (output); g_ptr_array_unref (argv);