11import os
22import benchmark
33import term
4+ import v.util.diff
45
56const is_verbose = os.getenv ('VTEST_SHOW_CMD' ) != ''
7+ const is_autofix = os.getenv ('VAUTOFIX' ) != ''
68
79fn 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