mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vvet: move to own subdir, prepare richer suggestions (#7989)
This commit is contained in:
@ -11,7 +11,7 @@ import v.util
|
||||
// should be compiled (v folder).
|
||||
// To implement that, these folders are initially skipped, then added
|
||||
// as a whole *after the testing.prepare_test_session call*.
|
||||
const tools_in_subfolders = ['vdoc']
|
||||
const tools_in_subfolders = ['vdoc', 'vvet']
|
||||
|
||||
// non_packaged_tools are tools that should not be packaged with
|
||||
// prebuild versions of V, to keep the size smaller.
|
||||
|
@ -20,6 +20,7 @@ const (
|
||||
vfmt_verify_list = [
|
||||
'cmd/v/v.v',
|
||||
'cmd/tools/vdoc/',
|
||||
'cmd/tools/vvet/',
|
||||
'vlib/arrays/',
|
||||
'vlib/benchmark/',
|
||||
'vlib/bitfield/',
|
||||
@ -92,7 +93,7 @@ fn tsession(vargs string, tool_source string, tool_cmd string, tool_args string,
|
||||
}
|
||||
|
||||
fn v_test_vetting(vargs string) {
|
||||
vet_session := tsession(vargs, 'vvet.v', 'v vet', 'vet', vet_folders, vet_known_failing_exceptions)
|
||||
vet_session := tsession(vargs, 'vvet', 'v vet', 'vet', vet_folders, vet_known_failing_exceptions)
|
||||
verify_session := tsession(vargs, 'vfmt.v', 'v fmt -verify', 'fmt -verify', vfmt_verify_list,
|
||||
verify_known_failing_exceptions)
|
||||
//
|
||||
|
2
cmd/tools/vvet/tests/array_init_one_val.out
Normal file
2
cmd/tools/vvet/tests/array_init_one_val.out
Normal file
@ -0,0 +1,2 @@
|
||||
cmd/tools/vvet/tests/array_init_one_val.vv:2: Use `var == value` instead of `var in [value]`
|
||||
NB: You can run `v fmt -w file.v` to fix these automatically
|
5
cmd/tools/vvet/tests/array_init_one_val.vv
Normal file
5
cmd/tools/vvet/tests/array_init_one_val.vv
Normal file
@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
if 1 in [1] {
|
||||
println('hello world')
|
||||
}
|
||||
}
|
2
cmd/tools/vvet/tests/indent_with_space.out
Normal file
2
cmd/tools/vvet/tests/indent_with_space.out
Normal file
@ -0,0 +1,2 @@
|
||||
cmd/tools/vvet/tests/indent_with_space.vv:2: Looks like you are using spaces for indentation.
|
||||
NB: You can run `v fmt -w file.v` to fix these automatically
|
3
cmd/tools/vvet/tests/indent_with_space.vv
Normal file
3
cmd/tools/vvet/tests/indent_with_space.vv
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
_ = 1 == 2
|
||||
}
|
2
cmd/tools/vvet/tests/parens_space_a.out
Normal file
2
cmd/tools/vvet/tests/parens_space_a.out
Normal file
@ -0,0 +1,2 @@
|
||||
cmd/tools/vvet/tests/parens_space_a.vv:1: Looks like you are adding a space after `(`
|
||||
NB: You can run `v fmt -w file.v` to fix these automatically
|
4
cmd/tools/vvet/tests/parens_space_a.vv
Normal file
4
cmd/tools/vvet/tests/parens_space_a.vv
Normal file
@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
_ = 1 + ( 1 + 2)
|
||||
}
|
||||
|
2
cmd/tools/vvet/tests/parens_space_b.out
Normal file
2
cmd/tools/vvet/tests/parens_space_b.out
Normal file
@ -0,0 +1,2 @@
|
||||
cmd/tools/vvet/tests/parens_space_b.vv:1: Looks like you are adding a space before `)`
|
||||
NB: You can run `v fmt -w file.v` to fix these automatically
|
4
cmd/tools/vvet/tests/parens_space_b.vv
Normal file
4
cmd/tools/vvet/tests/parens_space_b.vv
Normal file
@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
_ = 1 + (1 + 2 )
|
||||
}
|
||||
|
56
cmd/tools/vvet/vet_test.v
Normal file
56
cmd/tools/vvet/vet_test.v
Normal file
@ -0,0 +1,56 @@
|
||||
import os
|
||||
import term
|
||||
import v.util.vtest
|
||||
|
||||
fn test_vet() {
|
||||
vexe := os.getenv('VEXE')
|
||||
vroot := os.dir(vexe)
|
||||
os.chdir(vroot)
|
||||
test_dir := 'cmd/tools/vvet/tests'
|
||||
tests := get_tests_in_dir(test_dir)
|
||||
fails := check_path(vexe, test_dir, tests)
|
||||
assert fails == 0
|
||||
}
|
||||
|
||||
fn get_tests_in_dir(dir string) []string {
|
||||
files := os.ls(dir) or { panic(err) }
|
||||
mut tests := files.filter(it.ends_with('.vv'))
|
||||
tests.sort()
|
||||
return tests
|
||||
}
|
||||
|
||||
fn check_path(vexe string, dir string, tests []string) int {
|
||||
mut nb_fail := 0
|
||||
paths := vtest.filter_vtest_only(tests, basepath: dir)
|
||||
for path in paths {
|
||||
program := path
|
||||
print(path + ' ')
|
||||
res := os.exec('$vexe vet $program') or { panic(err) }
|
||||
mut expected := os.read_file(program.replace('.vv', '') + '.out') or { panic(err) }
|
||||
expected = clean_line_endings(expected)
|
||||
found := clean_line_endings(res.output)
|
||||
if expected != found {
|
||||
println(term.red('FAIL'))
|
||||
println('============')
|
||||
println('expected:')
|
||||
println(expected)
|
||||
println('============')
|
||||
println('found:')
|
||||
println(found)
|
||||
println('============\n')
|
||||
nb_fail++
|
||||
} else {
|
||||
println(term.green('OK'))
|
||||
}
|
||||
}
|
||||
return nb_fail
|
||||
}
|
||||
|
||||
fn clean_line_endings(s string) string {
|
||||
mut res := s.trim_space()
|
||||
res = res.replace(' \n', '\n')
|
||||
res = res.replace(' \r\n', '\n')
|
||||
res = res.replace('\r\n', '\n')
|
||||
res = res.trim('\n')
|
||||
return res
|
||||
}
|
@ -13,7 +13,7 @@ import os.cmdline
|
||||
struct VetOptions {
|
||||
is_verbose bool
|
||||
mut:
|
||||
errors []string
|
||||
errors []vet.Error
|
||||
}
|
||||
|
||||
fn (vet_options &VetOptions) vprintln(s string) {
|
||||
@ -34,7 +34,8 @@ fn main() {
|
||||
eprintln('File/folder $path does not exist')
|
||||
continue
|
||||
}
|
||||
if path.ends_with('_test.v') || (path.contains('/tests/') && !path.contains('vlib/v/vet/')) {
|
||||
if path.ends_with('_test.v') ||
|
||||
(path.contains('/tests/') && !path.contains('cmd/tools/vvet/tests/')) {
|
||||
eprintln('skipping $path')
|
||||
continue
|
||||
}
|
||||
@ -56,10 +57,15 @@ fn main() {
|
||||
}
|
||||
}
|
||||
if vet_options.errors.len > 0 {
|
||||
for err in vet_options.errors {
|
||||
eprintln(err)
|
||||
for err in vet_options.errors.filter(it.kind == .error) {
|
||||
eprintln('$err.file_path:$err.pos.line_nr: $err.message')
|
||||
}
|
||||
eprintln('NB: You can run `v fmt -w file.v` to fix these automatically')
|
||||
/*
|
||||
for err in vet_options.errors.filter(it.kind == .warning) {
|
||||
eprintln('$err.file_path:$err.pos.line_nr: err.message')
|
||||
}
|
||||
*/
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
@ -70,6 +76,6 @@ fn (mut vet_options VetOptions) vet_file(path string) {
|
||||
table := table.new_table()
|
||||
vet_options.vprintln("vetting file '$path'...")
|
||||
file_ast, errors := parser.parse_vet_file(path, table, prefs)
|
||||
// Transfer errors from scanner and parser
|
||||
vet_options.errors << errors
|
||||
vet.vet(file_ast, table, true)
|
||||
}
|
Reference in New Issue
Block a user