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