Skip to content

Commit ef347e7

Browse files
committed
tests: improve failure output of vlib/v/eval/interpret_test.v, and make it support VAUTOFIX=1
1 parent 9fcca59 commit ef347e7

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

‎vlib/v/eval/interpret_test.v‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22
import benchmark
33
import term
4+
import v.util.diff
45

56
const is_verbose = os.getenv('VTEST_SHOW_CMD') != ''
7+
const is_autofix = os.getenv('VAUTOFIX') != ''
68

79
fn test_interpret() {
810
mut bench := benchmark.new_benchmark()
@@ -18,6 +20,7 @@ fn test_interpret() {
1820
assert false
1921
}
2022
bench.set_total_expected_steps(tests.len)
23+
mut failcmds := []string{}
2124
for test in tests {
2225
test_name_without_postfix := test.replace('.vv', '')
2326
bench.step()
@@ -31,21 +34,32 @@ fn test_interpret() {
3134
res := os.execute(cmd)
3235
if res.exit_code != 0 {
3336
bench.fail()
34-
eprintln(bench.step_message_fail('${full_test_path} failed to run'))
37+
eprintln(bench.step_message_fail('${cmd} failed to run'))
3538
eprintln(res.output)
3639
continue
3740
}
38-
mut expected := os.read_file('${dir}/${test_name_without_postfix}.out')!
41+
expected_file_path := '${dir}/${test_name_without_postfix}.out'
42+
mut expected := os.read_file(expected_file_path)!
3943
expected = normalise_line_endings(expected)
4044
mut found := normalise_line_endings(res.output)
4145
found = found.trim_space()
4246
if expected != found {
43-
println(term.red('FAIL'))
44-
println('========================================================\n')
45-
println('============ expected len=${expected.len}: "${expected}"')
46-
println('============ found len=${found.len}: "${found}"')
47-
println('========================================================\n')
47+
failcmds << cmd
4848
bench.fail()
49+
eprintln(bench.step_message_fail('difference found, when running ${cmd}'))
50+
eprintln('='.repeat(80))
51+
eprintln('============ .out file: ${expected_file_path}')
52+
eprintln('============ expected len: ${expected.len}:\n${expected}')
53+
eprintln('============ found len: ${found.len}:\n${found}')
54+
if tdiff := diff.compare_text(expected, found) {
55+
eprintln('-'.repeat(80))
56+
eprintln('=== diff:')
57+
eprint(tdiff)
58+
}
59+
eprintln('='.repeat(80))
60+
if is_autofix {
61+
os.write_file(expected_file_path, found)!
62+
}
4963
continue
5064
}
5165
bench.ok()
@@ -55,6 +69,10 @@ fn test_interpret() {
5569
eprintln(term.h_divider('-'))
5670
eprintln(bench.total_message('native'))
5771
if bench.nfail > 0 {
72+
println('You can reproduce the discovered failure cases with:')
73+
for fcmd in failcmds {
74+
println(' > ${fcmd}')
75+
}
5876
exit(1)
5977
}
6078
}

0 commit comments

Comments
 (0)