v / cmd / tools
Raw file | 102 loc (89 sloc) | 3.02 KB | Latest commit hash 6a32c8107
1module main
2
3import os
4import testing
5import v.util
6import arrays
7
8const vet_known_failing = [
9 'do_not_delete_this',
10]
11
12const vet_known_failing_windows = [
13 'do_not_delete_this',
14 'vlib/v/gen/js/tests/testdata/byte_is_space.v',
15 'vlib/v/gen/js/tests/testdata/compare_ints.v',
16 'vlib/v/gen/js/tests/testdata/hw.v',
17 'vlib/v/gen/js/tests/testdata/string_methods.v',
18 'vlib/v/slow_tests/inout/vscript_using_generics_in_os.vsh',
19 'vlib/v/tests/project_with_modules_having_submodules/bin/main.vsh',
20 'vlib/v/slow_tests/valgrind/simple_interpolation_script_mode.v',
21 'vlib/v/slow_tests/valgrind/simple_interpolation_script_mode_more_scopes.v',
22]
23
24const vet_folders = [
25 'vlib/v',
26 'vlib/x/json2',
27 'vlib/x/ttf',
28 'cmd/v',
29 'cmd/tools',
30 'examples/2048',
31 'examples/tetris',
32 'examples/term.ui',
33]
34
35const verify_known_failing_exceptions = []string{}
36
37const vfmt_verify_list = [
38 'cmd/',
39 'examples/',
40 'tutorials/',
41 'vlib/',
42]
43
44const vfmt_known_failing_exceptions = arrays.merge(verify_known_failing_exceptions, []string{})
45
46const vexe = os.getenv('VEXE')
47
48const vroot = os.dir(vexe)
49
50const is_fix = '-fix' in os.args
51
52fn main() {
53 args_string := os.args[1..].join(' ')
54 pass_args := args_string.all_before('test-cleancode')
55 v_test_vetting(pass_args)!
56}
57
58fn tsession(vargs string, tool_source string, tool_cmd string, tool_args string, flist []string, slist []string) testing.TestSession {
59 os.chdir(vroot) or {}
60 title_message := 'running ${tool_cmd} over most .v files'
61 testing.eheader(title_message)
62 mut test_session := testing.new_test_session('${vargs} ${tool_args}', false)
63 test_session.files << flist
64 test_session.skip_files << slist
65 util.prepare_tool_when_needed(tool_source)
66 // note that util.prepare_tool_when_needed will put its temporary files
67 // in the VTMP from the test session too, so they will be cleaned up
68 // at the end
69 test_session.test()
70 eprintln(test_session.benchmark.total_message(title_message))
71 return test_session
72}
73
74fn v_test_vetting(vargs string) ! {
75 expanded_vet_list := util.find_all_v_files(vet_folders)!
76 mut vet_known_exceptions := vet_known_failing.clone()
77 if os.user_os() == 'windows' {
78 vet_known_exceptions << vet_known_failing_windows
79 }
80 vet_session := tsession(vargs, 'vvet', '${os.quoted_path(vexe)} vet', 'vet', expanded_vet_list,
81 vet_known_exceptions)
82 //
83 fmt_cmd, fmt_args := if is_fix {
84 '${os.quoted_path(vexe)} fmt -w', 'fmt -w'
85 } else {
86 '${os.quoted_path(vexe)} fmt -verify', 'fmt -verify'
87 }
88 vfmt_list := util.find_all_v_files(vfmt_verify_list) or { return }
89 exceptions := util.find_all_v_files(vfmt_known_failing_exceptions) or { return }
90 verify_session := tsession(vargs, 'vfmt.v', fmt_cmd, fmt_args, vfmt_list, exceptions)
91 //
92 if vet_session.benchmark.nfail > 0 || verify_session.benchmark.nfail > 0 {
93 eprintln('\n')
94 if vet_session.benchmark.nfail > 0 {
95 eprintln('WARNING: `v vet` failed ${vet_session.benchmark.nfail} times.')
96 }
97 if verify_session.benchmark.nfail > 0 {
98 eprintln('WARNING: `v fmt -verify` failed ${verify_session.benchmark.nfail} times.')
99 }
100 exit(1)
101 }
102}