From 56a477ed8cc446babe355f4339ec0f9ae2dfe5e0 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 25 Mar 2026 16:42:26 +0300 Subject: [PATCH] testing: fix results of tests in folder overlap (fixes #9501) --- cmd/tools/modules/testing/common.v | 30 ++++++++++++++++++++++++------ cmd/tools/modules/testing/output.v | 2 ++ cmd/tools/vtest_test.v | 15 +++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index 5517cdf76..43284ad51 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -216,6 +216,20 @@ pub fn (mut ts TestSession) print_messages() { } return } + if rmessage.kind in [.stats_output, .stats_error] { + mut msg := rmessage.message + if msg != '' && !msg.ends_with('\n') { + msg += '\n' + } + if rmessage.kind == .stats_error { + eprint(msg) + flush_stderr() + } else { + print(msg) + flush_stdout() + } + continue + } if rmessage.kind != .info { // info events can also be repeated, and should be ignored when determining // the total order of the current test file, in the following replacements: @@ -563,12 +577,11 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr { ts.append_message(.cmd_begin, cmd, mtc) d_cmd := time.new_stopwatch() mut res := ts.execute(cmd, mtc) - if res.exit_code != 0 { - eprintln(res.output) - } else { - println(res.output) - } mut status := res.exit_code + if res.output != '' { + output_kind := if status == 0 { MessageKind.stats_output } else { .stats_error } + ts.append_message(output_kind, res.output, mtc) + } cmd_duration = d_cmd.elapsed() ts.append_message_with_duration(.cmd_end, '', cmd_duration, mtc) @@ -583,7 +596,12 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr { os.setenv('VTEST_RETRY', '${retry}', true) ts.append_message(.cmd_begin, cmd, mtc) d_cmd_2 := time.new_stopwatch() - status = ts.system(cmd, mtc) + retry_res := ts.execute(cmd, mtc) + status = retry_res.exit_code + if retry_res.output != '' { + output_kind := if status == 0 { MessageKind.stats_output } else { .stats_error } + ts.append_message(output_kind, retry_res.output, mtc) + } cmd_duration = d_cmd_2.elapsed() ts.append_message_with_duration(.cmd_end, '', cmd_duration, mtc) diff --git a/cmd/tools/modules/testing/output.v b/cmd/tools/modules/testing/output.v index de65ce4f6..ac3d45a0a 100644 --- a/cmd/tools/modules/testing/output.v +++ b/cmd/tools/modules/testing/output.v @@ -7,6 +7,8 @@ pub enum MessageKind { compile_end // sent right after *each* _test.v file compilation, the message contains the output of that compilation cmd_begin // sent right before *each* _test.v file execution, the resulting status is not known yet, but the _test.v file itself is cmd_end // sent right after *each* _test.v file execution, the message contains the output of that execution + stats_output // captured `v -stats test` output that should be shown verbatim on stdout + stats_error // captured `v -stats test` output for failed commands, shown verbatim on stderr ok // success of a _test.v file fail // failed _test.v file, one or more assertions failed diff --git a/cmd/tools/vtest_test.v b/cmd/tools/vtest_test.v index b0999b3b6..b9934f890 100644 --- a/cmd/tools/vtest_test.v +++ b/cmd/tools/vtest_test.v @@ -61,6 +61,21 @@ fn test_with_stats_and_several_test_files() { assert res.output.contains('3 asserts'), res.output assert res.output.contains('2 passed, 2 total'), res.output assert res.output.count('OK') == 6, res.output + run_1 := '1_test.v\n OK' + run_2 := '2_test.v\n OK' + summary_1 := 'Summary for running V tests in "1_test.v"' + summary_2 := 'Summary for running V tests in "2_test.v"' + run_1_idx := res.output.index(run_1) or { -1 } + run_2_idx := res.output.index(run_2) or { -1 } + summary_1_idx := res.output.index(summary_1) or { -1 } + summary_2_idx := res.output.index(summary_2) or { -1 } + assert run_1_idx != -1, res.output + assert run_2_idx != -1, res.output + assert summary_1_idx != -1, res.output + assert summary_2_idx != -1, res.output + assert run_1_idx < summary_1_idx, res.output + assert run_2_idx < summary_2_idx, res.output + assert summary_1_idx < run_2_idx || summary_2_idx < run_1_idx, res.output } fn test_partial_failure() { -- 2.39.5