2020-10-24 15:36:26 +02:00
|
|
|
module main
|
|
|
|
|
|
|
|
import os
|
|
|
|
import testing
|
|
|
|
import v.util
|
|
|
|
|
|
|
|
const (
|
2021-04-09 12:22:14 +02:00
|
|
|
vet_known_failing_exceptions = [
|
|
|
|
'vlib/v/gen/js/js.v' /* trailing space */,
|
|
|
|
]
|
2020-11-11 21:53:21 +01:00
|
|
|
vet_folders = [
|
2020-10-24 15:36:26 +02:00
|
|
|
'vlib/sqlite',
|
|
|
|
'vlib/v',
|
2021-03-19 08:49:26 +01:00
|
|
|
'vlib/x/ttf/',
|
2020-10-24 15:36:26 +02:00
|
|
|
'cmd/v',
|
|
|
|
'cmd/tools',
|
2021-02-04 16:34:49 +01:00
|
|
|
'examples/2048',
|
|
|
|
'examples/tetris',
|
|
|
|
'examples/term.ui',
|
2020-10-24 15:36:26 +02:00
|
|
|
]
|
2021-03-24 11:39:09 +01:00
|
|
|
verify_known_failing_exceptions = [
|
2021-03-24 19:39:59 +01:00
|
|
|
'vlib/builtin/int_test.v' /* special number formatting that should be tested */,
|
2021-04-05 20:47:11 +02:00
|
|
|
'vlib/builtin/int.v' /* TODO byteptr: vfmt converts `pub fn (nn byteptr) str() string {` to `nn &byte` and that conflicts with `nn byte` */,
|
|
|
|
'vlib/builtin/string_charptr_byteptr_helpers.v' /* TODO byteptr: a temporary shim to ease the byteptr=>&byte transition */,
|
2021-03-24 11:39:09 +01:00
|
|
|
'vlib/gg/m4/graphic.v' /* has hand crafted meaningful formatting of matrices */,
|
|
|
|
'vlib/gg/m4/m4_test.v' /* has hand crafted meaningful formatting of matrices */,
|
|
|
|
'vlib/gg/m4/matrix.v' /* has hand crafted meaningful formatting of matrices */,
|
2021-03-27 18:29:57 +01:00
|
|
|
'vlib/v/tests/array_append_short_struct_test.v', /* extra empty line */
|
|
|
|
'vlib/v/tests/fixed_array_const_size_test.v', /* fixed arr type is changed */
|
|
|
|
'vlib/v/tests/fn_high_test.v', /* param name removed */
|
|
|
|
'vlib/v/tests/fn_test.v', /* bad comment formatting */
|
|
|
|
'vlib/v/tests/generics_return_generics_struct_test.v', /* generic fn param removed */
|
|
|
|
'vlib/v/tests/interop_test.v', /* bad comment formatting */
|
2021-04-05 20:47:11 +02:00
|
|
|
'vlib/v/tests/generics_test.v', /* multi_generic_args<Foo<int>, Foo<int> >(...) becomes .... Foo<int>>(...) which does not parse */
|
|
|
|
'vlib/v/tests/string_interpolation_test.v' /* TODO byteptr: &byte.str() behaves differently than byteptr.str() */,
|
2021-04-02 00:57:09 +02:00
|
|
|
'vlib/v/gen/js/tests/js.v', /* local `hello` fn, gets replaced with module `hello` aliased as `hl` */
|
2021-03-24 11:39:09 +01:00
|
|
|
]
|
2020-11-15 15:20:46 +01:00
|
|
|
vfmt_verify_list = [
|
2021-03-24 22:37:10 +01:00
|
|
|
'cmd/',
|
2020-12-27 14:51:55 +01:00
|
|
|
'vlib/arrays/',
|
|
|
|
'vlib/benchmark/',
|
|
|
|
'vlib/bitfield/',
|
2021-03-24 19:39:59 +01:00
|
|
|
'vlib/builtin/',
|
2021-03-24 11:39:09 +01:00
|
|
|
'vlib/cli/',
|
|
|
|
'vlib/dl/',
|
|
|
|
'vlib/flag/',
|
|
|
|
'vlib/gg/',
|
2020-10-24 15:36:26 +02:00
|
|
|
'vlib/math/bits/bits.v',
|
2020-12-26 13:40:22 +01:00
|
|
|
'vlib/orm/',
|
2021-03-24 11:39:09 +01:00
|
|
|
'vlib/runtime/',
|
2020-10-24 15:36:26 +02:00
|
|
|
'vlib/term/colors.v',
|
|
|
|
'vlib/term/term.v',
|
|
|
|
'vlib/v/ast/',
|
|
|
|
'vlib/v/builder/',
|
|
|
|
'vlib/v/cflag/',
|
|
|
|
'vlib/v/checker/',
|
|
|
|
'vlib/v/depgraph/',
|
|
|
|
'vlib/v/doc/',
|
2021-02-21 19:17:12 +01:00
|
|
|
'vlib/v/embed_file/',
|
2020-10-24 15:36:26 +02:00
|
|
|
'vlib/v/errors/',
|
|
|
|
'vlib/v/eval/',
|
|
|
|
'vlib/v/fmt/',
|
2021-02-21 19:17:12 +01:00
|
|
|
'vlib/v/gen/c/',
|
2021-04-02 00:57:09 +02:00
|
|
|
'vlib/v/gen/js/',
|
2021-02-21 19:17:12 +01:00
|
|
|
'vlib/v/gen/x64/',
|
|
|
|
'vlib/v/live/',
|
|
|
|
'vlib/v/markused/',
|
2020-10-24 15:36:26 +02:00
|
|
|
'vlib/v/parser/',
|
2021-03-14 11:17:31 +01:00
|
|
|
'vlib/v/pkgconfig/',
|
2020-10-24 15:36:26 +02:00
|
|
|
'vlib/v/pref/',
|
2021-02-21 19:17:12 +01:00
|
|
|
'vlib/v/preludes',
|
2020-10-24 15:36:26 +02:00
|
|
|
'vlib/v/scanner/',
|
2021-03-27 18:29:57 +01:00
|
|
|
'vlib/v/tests/',
|
2021-02-21 19:17:12 +01:00
|
|
|
'vlib/v/token/',
|
2020-10-24 15:36:26 +02:00
|
|
|
'vlib/v/util/',
|
2021-02-21 19:17:12 +01:00
|
|
|
'vlib/v/vcache/',
|
2020-10-24 15:36:26 +02:00
|
|
|
'vlib/v/vet/',
|
|
|
|
'vlib/v/vmod/',
|
2020-12-21 21:24:10 +01:00
|
|
|
'vlib/cli/',
|
|
|
|
'vlib/flag/',
|
2020-12-22 08:44:59 +01:00
|
|
|
'vlib/math/big/',
|
2020-12-16 13:15:11 +01:00
|
|
|
'vlib/os/',
|
2020-12-21 21:00:32 +01:00
|
|
|
'vlib/semver/',
|
|
|
|
'vlib/strings/',
|
2020-12-16 13:15:11 +01:00
|
|
|
'vlib/time/',
|
2020-12-27 10:38:12 +01:00
|
|
|
'vlib/vweb/',
|
2020-12-28 06:25:46 +01:00
|
|
|
'vlib/x/websocket/',
|
2020-10-24 15:36:26 +02:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2021-03-19 11:37:44 +01:00
|
|
|
const (
|
|
|
|
vexe = os.getenv('VEXE')
|
|
|
|
vroot = os.dir(vexe)
|
|
|
|
is_fix = '-fix' in os.args
|
|
|
|
)
|
2021-01-09 18:25:50 +01:00
|
|
|
|
2020-10-24 15:36:26 +02:00
|
|
|
fn main() {
|
2020-12-20 15:40:49 +01:00
|
|
|
args_string := os.args[1..].join(' ')
|
2020-11-15 15:24:25 +01:00
|
|
|
pass_args := args_string.all_before('test-cleancode')
|
2020-10-24 15:36:26 +02: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-01-09 18:25:50 +01:00
|
|
|
os.chdir(vroot)
|
2021-03-24 11:39:09 +01:00
|
|
|
title_message := 'running $tool_cmd over most .v files'
|
|
|
|
testing.eheader(title_message)
|
2020-10-24 15:36:26 +02:00
|
|
|
mut test_session := testing.new_test_session('$vargs $tool_args')
|
|
|
|
test_session.files << flist
|
|
|
|
test_session.skip_files << slist
|
2021-01-09 19:41:15 +01: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 15:36:26 +02:00
|
|
|
test_session.test()
|
2021-03-24 11:39:09 +01:00
|
|
|
eprintln(test_session.benchmark.total_message(title_message))
|
2020-10-24 15:36:26 +02:00
|
|
|
return test_session
|
|
|
|
}
|
|
|
|
|
|
|
|
fn v_test_vetting(vargs string) {
|
2021-04-09 12:22:14 +02:00
|
|
|
expanded_vet_list := util.find_all_v_files(vet_folders) or { return }
|
|
|
|
vet_session := tsession(vargs, 'vvet', 'v vet', 'vet', expanded_vet_list, vet_known_failing_exceptions)
|
2021-03-19 11:37:44 +01:00
|
|
|
fmt_cmd, fmt_args := if is_fix { 'v fmt -w', 'fmt -w' } else { 'v fmt -verify', 'fmt -verify' }
|
2021-03-24 11:39:09 +01:00
|
|
|
expanded_vfmt_list := util.find_all_v_files(vfmt_verify_list) or { return }
|
|
|
|
verify_session := tsession(vargs, 'vfmt.v', fmt_cmd, fmt_args, expanded_vfmt_list,
|
|
|
|
verify_known_failing_exceptions)
|
2020-10-24 15:36:26 +02: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)
|
|
|
|
}
|
|
|
|
}
|