2020-10-24 16:36:26 +03:00
|
|
|
module main
|
|
|
|
|
|
|
|
import os
|
|
|
|
import testing
|
|
|
|
import v.util
|
2021-05-08 13:32:29 +03:00
|
|
|
import arrays
|
2020-10-24 16:36:26 +03:00
|
|
|
|
2022-05-17 20:19:37 +03:00
|
|
|
const vet_known_failing = [
|
|
|
|
'do_not_delete_this',
|
|
|
|
]
|
2020-10-24 16:36:26 +03:00
|
|
|
|
2022-05-17 20:19:37 +03:00
|
|
|
const vet_known_failing_windows = [
|
|
|
|
'do_not_delete_this',
|
|
|
|
'vlib/v/gen/js/tests/testdata/byte_is_space.v',
|
|
|
|
'vlib/v/gen/js/tests/testdata/compare_ints.v',
|
|
|
|
'vlib/v/gen/js/tests/testdata/hw.v',
|
|
|
|
'vlib/v/gen/js/tests/testdata/string_methods.v',
|
2022-09-11 11:18:01 +03:00
|
|
|
'vlib/v/tests/inout/vscript_using_generics_in_os.vsh',
|
2022-05-17 20:19:37 +03:00
|
|
|
'vlib/v/tests/project_with_modules_having_submodules/bin/main.vsh',
|
|
|
|
'vlib/v/tests/valgrind/simple_interpolation_script_mode.v',
|
|
|
|
'vlib/v/tests/valgrind/simple_interpolation_script_mode_more_scopes.v',
|
|
|
|
]
|
|
|
|
|
|
|
|
const vet_folders = [
|
|
|
|
'vlib/sqlite',
|
|
|
|
'vlib/v',
|
|
|
|
'vlib/x/json2',
|
|
|
|
'vlib/x/ttf',
|
|
|
|
'cmd/v',
|
|
|
|
'cmd/tools',
|
|
|
|
'examples/2048',
|
|
|
|
'examples/tetris',
|
|
|
|
'examples/term.ui',
|
|
|
|
]
|
|
|
|
|
2022-11-05 09:08:01 +03:00
|
|
|
const verify_known_failing_exceptions = []string{}
|
2022-05-17 20:19:37 +03:00
|
|
|
|
|
|
|
const vfmt_verify_list = [
|
|
|
|
'cmd/',
|
|
|
|
'examples/',
|
|
|
|
'tutorials/',
|
|
|
|
'vlib/',
|
|
|
|
]
|
|
|
|
|
2022-11-05 09:08:01 +03:00
|
|
|
const vfmt_known_failing_exceptions = arrays.merge(verify_known_failing_exceptions, []string{})
|
2022-05-17 20:19:37 +03:00
|
|
|
|
|
|
|
const vexe = os.getenv('VEXE')
|
|
|
|
|
|
|
|
const vroot = os.dir(vexe)
|
|
|
|
|
|
|
|
const is_fix = '-fix' in os.args
|
2021-01-09 20:25:50 +03:00
|
|
|
|
2020-10-24 16:36:26 +03:00
|
|
|
fn main() {
|
2020-12-20 17:40:49 +03:00
|
|
|
args_string := os.args[1..].join(' ')
|
2020-11-15 17:24:25 +03:00
|
|
|
pass_args := args_string.all_before('test-cleancode')
|
2020-10-24 16:36:26 +03:00
|
|
|
v_test_vetting(pass_args)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tsession(vargs string, tool_source string, tool_cmd string, tool_args string, flist []string, slist []string) testing.TestSession {
|
2021-08-28 12:44:03 +03:00
|
|
|
os.chdir(vroot) or {}
|
2021-03-24 13:39:09 +03:00
|
|
|
title_message := 'running $tool_cmd over most .v files'
|
|
|
|
testing.eheader(title_message)
|
2021-05-08 13:32:29 +03:00
|
|
|
mut test_session := testing.new_test_session('$vargs $tool_args', false)
|
2020-10-24 16:36:26 +03:00
|
|
|
test_session.files << flist
|
|
|
|
test_session.skip_files << slist
|
2021-01-09 21:41:15 +03:00
|
|
|
util.prepare_tool_when_needed(tool_source)
|
|
|
|
// note that util.prepare_tool_when_needed will put its temporary files
|
|
|
|
// in the VTMP from the test session too, so they will be cleaned up
|
|
|
|
// at the end
|
2020-10-24 16:36:26 +03:00
|
|
|
test_session.test()
|
2021-03-24 13:39:09 +03:00
|
|
|
eprintln(test_session.benchmark.total_message(title_message))
|
2020-10-24 16:36:26 +03:00
|
|
|
return test_session
|
|
|
|
}
|
|
|
|
|
|
|
|
fn v_test_vetting(vargs string) {
|
2021-04-09 13:22:14 +03:00
|
|
|
expanded_vet_list := util.find_all_v_files(vet_folders) or { return }
|
2022-05-17 20:19:37 +03:00
|
|
|
mut vet_known_exceptions := vet_known_failing.clone()
|
|
|
|
if os.user_os() == 'windows' {
|
|
|
|
vet_known_exceptions << vet_known_failing_windows
|
|
|
|
}
|
2022-01-22 22:56:01 +03:00
|
|
|
vet_session := tsession(vargs, 'vvet', '${os.quoted_path(vexe)} vet', 'vet', expanded_vet_list,
|
2022-05-17 20:19:37 +03:00
|
|
|
vet_known_exceptions)
|
2021-05-08 13:32:29 +03:00
|
|
|
//
|
2022-01-22 22:56:01 +03:00
|
|
|
fmt_cmd, fmt_args := if is_fix {
|
|
|
|
'${os.quoted_path(vexe)} fmt -w', 'fmt -w'
|
|
|
|
} else {
|
|
|
|
'${os.quoted_path(vexe)} fmt -verify', 'fmt -verify'
|
|
|
|
}
|
2021-05-08 13:32:29 +03:00
|
|
|
vfmt_list := util.find_all_v_files(vfmt_verify_list) or { return }
|
|
|
|
exceptions := util.find_all_v_files(vfmt_known_failing_exceptions) or { return }
|
|
|
|
verify_session := tsession(vargs, 'vfmt.v', fmt_cmd, fmt_args, vfmt_list, exceptions)
|
2020-10-24 16:36:26 +03:00
|
|
|
//
|
|
|
|
if vet_session.benchmark.nfail > 0 || verify_session.benchmark.nfail > 0 {
|
|
|
|
eprintln('\n')
|
|
|
|
if vet_session.benchmark.nfail > 0 {
|
|
|
|
eprintln('WARNING: `v vet` failed $vet_session.benchmark.nfail times.')
|
|
|
|
}
|
|
|
|
if verify_session.benchmark.nfail > 0 {
|
|
|
|
eprintln('WARNING: `v fmt -verify` failed $verify_session.benchmark.nfail times.')
|
|
|
|
}
|
|
|
|
exit(1)
|
|
|
|
}
|
|
|
|
}
|