diff --git a/cmd/tools/vtest-fmt.v b/cmd/tools/vtest-fmt.v index c3e335c2d0..2044afcb92 100644 --- a/cmd/tools/vtest-fmt.v +++ b/cmd/tools/vtest-fmt.v @@ -30,13 +30,7 @@ fn main() { fn v_test_formatting(vargs string) { all_v_files := v_files() - vexe := os.getenv('VEXE') - vroot := os.dir(vexe) - recompile_result := os.system('$vexe ' + os.join_path(vroot, 'cmd', 'tools', 'vfmt.v')) - if recompile_result != 0 { - eprintln('could not recompile cmd/tools/vfmt.v') - exit(2) - } + prepare_vfmt_when_needed() testing.eheader('Run "v fmt" over all .v files') mut vfmt_test_session := testing.new_test_session('$vargs fmt -worker') vfmt_test_session.files << all_v_files @@ -60,3 +54,16 @@ fn v_files() []string { } return files_that_can_be_formatted } + +fn prepare_vfmt_when_needed() { + vexe := os.getenv('VEXE') + vroot := os.dir(vexe) + vfmtv := os.join_path(vroot, 'cmd', 'tools', 'vfmt.v') + if os.file_last_mod_unix(vexe) <= os.file_last_mod_unix(vfmtv) { + recompile_result := os.system('$vexe ' + os.join_path(vroot, 'cmd', 'tools', 'vfmt.v')) + if recompile_result != 0 { + eprintln('could not recompile cmd/tools/vfmt.v') + exit(2) + } + } +}