Skip to content

Commit fbc3fc6

Browse files
authored
tools: cleanup the output for failing tests with v test . (#22921)
1 parent 2fbb3df commit fbc3fc6

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

cmd/tools/modules/testing/common.v

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub const all_processes = get_all_processes()
4848

4949
pub const header_bytes_to_search_for_module_main = 500
5050

51-
pub const separator = '-'.repeat(max_header_len)
51+
pub const separator = '-'.repeat(max_header_len) + '\n'
5252

5353
pub const max_compilation_retries = get_max_compilation_retries()
5454

@@ -531,6 +531,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
531531
} else {
532532
fname_without_extension
533533
}
534+
reproduce_options := cmd_options.clone()
534535
generated_binary_fpath := os.join_path_single(test_folder_path, generated_binary_fname)
535536
if produces_file_output {
536537
if ts.rm_binaries {
@@ -548,6 +549,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
548549
if ts.show_stats {
549550
skip_running = ''
550551
}
552+
reproduce_cmd := '${os.quoted_path(ts.vexe)} ${reproduce_options.join(' ')} ${os.quoted_path(file)}'
551553
cmd := '${os.quoted_path(ts.vexe)} ${skip_running} ${cmd_options.join(' ')} ${os.quoted_path(file)}'
552554
run_cmd := if run_js {
553555
'node ${os.quoted_path(generated_binary_fpath)}'
@@ -620,7 +622,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
620622
}
621623
ts.benchmark.fail()
622624
tls_bench.fail()
623-
ts.add_failed_cmd(cmd)
625+
ts.add_failed_cmd(reproduce_cmd)
624626
return pool.no_result
625627
}
626628
} else {
@@ -650,7 +652,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
650652
cmd_duration,
651653
preparation: compile_cmd_duration
652654
), cmd_duration, mtc)
653-
ts.add_failed_cmd(cmd)
655+
ts.add_failed_cmd(reproduce_cmd)
654656
return pool.no_result
655657
}
656658
tls_bench.step_restart()
@@ -678,8 +680,10 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
678680
// retry running at least 1 more time, to avoid CI false positives as much as possible
679681
details.retry++
680682
}
681-
failure_output.write_string(separator)
682-
failure_output.writeln('\n retry: 0 ; max_retry: ${details.retry} ; r.exit_code: ${r.exit_code} ; trimmed_output.len: ${trimmed_output.len}')
683+
if details.retry != 0 {
684+
failure_output.write_string(separator)
685+
failure_output.writeln(' retry: 0 ; max_retry: ${details.retry} ; r.exit_code: ${r.exit_code} ; trimmed_output.len: ${trimmed_output.len}')
686+
}
683687
failure_output.writeln(trimmed_output)
684688
os.setenv('VTEST_RETRY_MAX', '${details.retry}', true)
685689
for retry = 1; retry <= details.retry; retry++ {
@@ -702,7 +706,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
702706
}
703707
trimmed_output = r.output.trim_space()
704708
failure_output.write_string(separator)
705-
failure_output.writeln('\n retry: ${retry} ; max_retry: ${details.retry} ; r.exit_code: ${r.exit_code} ; trimmed_output.len: ${trimmed_output.len}')
709+
failure_output.writeln(' retry: ${retry} ; max_retry: ${details.retry} ; r.exit_code: ${r.exit_code} ; trimmed_output.len: ${trimmed_output.len}')
706710
failure_output.writeln(trimmed_output)
707711
time.sleep(fail_retry_delay_ms)
708712
}
@@ -722,11 +726,10 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
722726
tls_bench.fail()
723727
cmd_duration = d_cmd.elapsed() - (fail_retry_delay_ms * details.retry)
724728
ts.append_message_with_duration(.fail, tls_bench.step_message_with_label_and_duration(benchmark.b_fail,
725-
'${normalised_relative_file}\n retry: ${retry}\n comp_cmd: ${cmd}\n run_cmd: ${run_cmd}\nfailure code: ${r.exit_code}; foutput.len: ${full_failure_output.len}; failure output:\n${full_failure_output}',
726-
cmd_duration,
729+
'${normalised_relative_file}\n${full_failure_output}', cmd_duration,
727730
preparation: compile_cmd_duration
728731
), cmd_duration, mtc)
729-
ts.add_failed_cmd(cmd)
732+
ts.add_failed_cmd(reproduce_cmd)
730733
return pool.no_result
731734
}
732735
}

cmd/tools/modules/testing/output_normal.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ pub fn (r NormalReporter) worker_threads_finish(mut ts TestSession) {
7878

7979
pub fn (r NormalReporter) list_of_failed_commands(failed_cmds []string) {
8080
for i, cmd in failed_cmds {
81-
eprintln(term.failed('Failed command ${i + 1}:') + ' ${cmd}')
81+
eprintln(term.failed('To reproduce just failure ${i + 1} run:') + ' ${cmd}')
8282
}
8383
}

cmd/tools/vcreate/vcreate_new_test.v

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ fn prepare_test_path() ! {
3232
fn test_new_with_no_arg_input() {
3333
prepare_test_path()!
3434
project_name := 'my_project'
35-
os.execute_opt('${expect_exe} ${os.join_path(expect_tests_path, 'new_with_no_arg.expect')} ${vroot} ${project_name}') or {
35+
cmd := '${expect_exe} ${os.join_path(expect_tests_path, 'new_with_no_arg.expect')} ${vroot} ${project_name}'
36+
os.execute_opt(cmd) or {
37+
dump(cmd)
3638
assert false, err.msg()
3739
}
3840
// Assert mod data set in `new_no_arg.expect`.
@@ -49,7 +51,9 @@ fn test_new_with_no_arg_input() {
4951
fn test_new_with_name_arg_input() {
5052
prepare_test_path()!
5153
project_name := 'my_other_project'
52-
os.execute_opt('${expect_exe} ${os.join_path(expect_tests_path, 'new_with_name_arg.expect')} ${vroot} ${project_name}') or {
54+
cmd := '${expect_exe} ${os.join_path(expect_tests_path, 'new_with_name_arg.expect')} ${vroot} ${project_name}'
55+
os.execute_opt(cmd) or {
56+
dump(cmd)
5357
assert false, err.msg()
5458
}
5559
// Assert mod data set in `new_with_name_arg.expect`.
@@ -67,7 +71,9 @@ fn test_new_with_model_arg_input() {
6771
prepare_test_path()!
6872
project_name := 'my_lib'
6973
model := '--lib'
70-
os.execute_opt('${expect_exe} ${os.join_path(expect_tests_path, 'new_with_model_arg.expect')} ${vroot} ${model} ${project_name}') or {
74+
cmd := '${expect_exe} ${os.join_path(expect_tests_path, 'new_with_model_arg.expect')} ${vroot} ${model} ${project_name}'
75+
os.execute_opt(cmd) or {
76+
dump(cmd)
7177
assert false, err.msg()
7278
}
7379
project_path := os.join_path(test_module_path, project_name)

cmd/tools/vtest_test.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ fn test_partial_failure() {
7171
assert res.exit_code == 1
7272
assert res.output.contains('assert 5 == 7'), res.output
7373
assert res.output.contains(' 1 failed, 1 passed, 2 total'), res.output
74-
assert res.output.contains('Failed command'), res.output
74+
assert res.output.contains('To reproduce just failure'), res.output
7575
}
7676

7777
fn test_with_stats_and_partial_failure() {
7878
res := os.execute('${os.quoted_path(mytest_exe)} -stats test ${os.quoted_path(tpath_partial)}')
7979
assert res.exit_code == 1
8080
assert res.output.contains('assert 5 == 7'), res.output
8181
assert res.output.contains(' 1 failed, 1 passed, 2 total'), res.output
82-
assert res.output.contains('Failed command'), res.output
82+
assert res.output.contains('To reproduce just failure'), res.output
8383
}

0 commit comments

Comments
 (0)