1- // Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved.
1+ // Copyright (c) 2025 Alexander Medvednikov. All rights reserved.
22// Use of this source code is governed by an MIT license
33// that can be found in the LICENSE file.
44import os
5- import term
65import benchmark
76import v.ast
87import v.fmt
@@ -11,20 +10,18 @@ import v.pref
1110import v.util.diff
1211import v.util.vtest
1312
14- const vroot = @VEXEROOT
15- const tdir = os.join_path (vroot, 'vlib' , 'v' , 'fmt' )
13+ const tmpfolder = os.temp_dir ()
1614const fpref = & pref.Preferences{
1715 is_fmt: true
1816}
1917
20- fn run_fmt ( mut input_files [] string ) {
21- fmt_message := 'vfmt new_int tests '
22- eprintln (term. header (fmt_message, '-' ))
23- tmpfolder := os.temp_dir ( )
24- assert input_files.len > 0
18+ fn test_new_int_fmt ( ) {
19+ suffix_for_expected := '_expected_new_int.vv '
20+ suffix_for_input := '_input.vv'
21+ mut input_files := os.walk_ext (os. join_path (@VEXEROOT, 'vlib/v/fmt/tests' ), suffix_for_expected )
22+ input_files = input_files.map ( it . replace (suffix_for_expected, suffix_for_input))
2523 input_files = vtest.filter_vtest_only (input_files)
2624 if input_files.len == 0 {
27- // No need to produce a failing test here.
2825 eprintln ('no tests found with VTEST_ONLY filter set to: ' + os.getenv ('VTEST_ONLY' ))
2926 exit (0 )
3027 }
@@ -34,10 +31,6 @@ fn run_fmt(mut input_files []string) {
3431 fmt_bench.cstep = istep
3532 fmt_bench.step ()
3633 opath := ipath.replace ('_input.vv' , '_expected_new_int.vv' )
37- if ! os.exists (opath) {
38- // skip not exist files
39- continue
40- }
4134 expected_ocontent := os.read_file (opath) or {
4235 fmt_bench.fail ()
4336 eprintln (fmt_bench.step_message_fail ('cannot read from ${opath }' ))
@@ -49,7 +42,7 @@ fn run_fmt(mut input_files []string) {
4942 result_ocontent := fmt.fmt (file_ast, mut table, fpref, false )
5043 if expected_ocontent != result_ocontent {
5144 fmt_bench.fail ()
52- eprintln (fmt_bench.step_message_fail ('file ${ipath } after formatting, does not look as expected.' ))
45+ eprintln (fmt_bench.step_message_fail ('file ${ipath } after formatting, does not look as expected ${ opath } .' ))
5346 vfmt_result_file := os.join_path (tmpfolder, 'vfmt_run_over_${os .file_name (ipath )}' )
5447 os.write_file (vfmt_result_file, result_ocontent) or { panic (err) }
5548 println (diff.compare_files (opath, vfmt_result_file) or { err.msg () })
@@ -59,12 +52,6 @@ fn run_fmt(mut input_files []string) {
5952 eprintln (fmt_bench.step_message_ok (ipath))
6053 }
6154 fmt_bench.stop ()
62- eprintln (term.h_divider ('-' ))
63- eprintln (fmt_bench.total_message (fmt_message))
55+ println (fmt_bench.total_message ('vfmt new_int tests' ))
6456 assert fmt_bench.nfail == 0
6557}
66-
67- fn test_new_int_fmt () {
68- mut input_files := os.walk_ext (os.join_path (tdir, 'tests' ), '_input.vv' )
69- run_fmt (mut input_files)
70- }
0 commit comments