From 5c799ff01d87f5553b2ceed154fcb54e83e9b22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 13 Jan 2023 18:33:38 +0100 Subject: [PATCH] gtestutils: Write tap test results atomically When running multiple tests in parallel using meson, the output could be mixed and if we write the TAP reports in multiple steps the output could be mangled together with other results. An example is: https://gitlab.gnome.org/3v1n0/glib/-/jobs/2507620 Where we have: ok 5 /cancellable/poll-fd# GLib-GIO-DEBUG: Collecting capable appnames: 0ms # Allocating hashtables:...... 0ms # Reading capable apps: 63ms # Reading URL associations:... 0ms # Reading extension assocs: 78ms # Reading exe-only apps:...... 47ms # Reading classes: 312ms # Reading UWP apps: 47ms # Postprocessing:..............16ms # TOTAL: 563ms # SKIP Platform not supported Leading to a clear TAP parsing error --- glib/gtestutils.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/glib/gtestutils.c b/glib/gtestutils.c index 7009e8e59..ed1f087d3 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -1034,7 +1034,7 @@ g_test_log (GTestLogType lbit, fail = result == G_TEST_RUN_FAILURE; if (test_tap_log) { - const gchar *ok; + GString *tap_output; /* The TAP representation for an expected failure starts with * "not ok", even though it does not actually count as failing @@ -1043,19 +1043,20 @@ g_test_log (GTestLogType lbit, * for which GTestResult does not currently have a * representation. */ if (fail || result == G_TEST_RUN_INCOMPLETE) - ok = "not ok"; + tap_output = g_string_new ("not ok"); else - ok = "ok"; + tap_output = g_string_new ("ok"); - g_print ("%s %d %s", ok, test_run_count, string1); + g_string_append_printf (tap_output, " %d %s", test_run_count, string1); if (result == G_TEST_RUN_INCOMPLETE) - g_print (" # TODO %s\n", string2 ? string2 : ""); + g_string_append_printf (tap_output, " # TODO %s", string2 ? string2 : ""); else if (result == G_TEST_RUN_SKIPPED) - g_print (" # SKIP %s\n", string2 ? string2 : ""); + g_string_append_printf (tap_output, " # SKIP %s", string2 ? string2 : ""); else if (result == G_TEST_RUN_FAILURE && string2 != NULL) - g_print (" - %s\n", string2); - else - g_print ("\n"); + g_string_append_printf (tap_output, " - %s", string2); + + g_print ("%s\n", tap_output->str); + g_string_free (tap_output, TRUE); } else if (g_test_verbose ()) g_print ("GTest: result: %s\n", g_test_result_names[result]);