tools: add `v test-vet`

pull/6674/head
Delyan Angelov 2020-10-24 16:36:26 +03:00
parent 296a6095a4
commit 23ee3018c3
5 changed files with 117 additions and 68 deletions

View File

@ -21,51 +21,8 @@ jobs:
run: echo $VFLAGS $GITHUB_SHA $GITHUB_REF
- name: Build local v
run: make -j4
- name: v vet
run: |
./v vet vlib/sqlite
./v vet vlib/v
./v vet cmd/v
./v vet cmd/tools
- name: v fmt -verify
run: |
./v fmt -verify vlib/builtin/array.v
./v fmt -verify vlib/os/file.v
./v fmt -verify vlib/math/bits/bits.v
./v fmt -verify vlib/time/time.v
./v fmt -verify vlib/term/colors.v
./v fmt -verify vlib/term/term.v
./v fmt -verify vlib/v/ast/
./v fmt -verify vlib/v/builder/
./v fmt -verify vlib/v/cflag/
./v fmt -verify vlib/v/checker/
./v fmt -verify vlib/v/depgraph/
./v fmt -verify vlib/v/doc/
./v fmt -verify vlib/v/errors/
./v fmt -verify vlib/v/eval/
./v fmt -verify vlib/v/fmt/
./v fmt -verify vlib/v/gen/auto_str_methods.v
./v fmt -verify vlib/v/gen/cgen.v
./v fmt -verify vlib/v/gen/cgen_test.v
./v fmt -verify vlib/v/gen/cmain.v
./v fmt -verify vlib/v/gen/comptime.v
./v fmt -verify vlib/v/gen/fn.v
./v fmt -verify vlib/v/gen/json.v
./v fmt -verify vlib/v/gen/live.v
./v fmt -verify vlib/v/gen/profile.v
./v fmt -verify vlib/v/gen/sql.v
./v fmt -verify vlib/v/gen/str.v
./v fmt -verify vlib/v/gen/x64/elf.v
./v fmt -verify vlib/v/gen/x64/elf_obj.v
./v fmt -verify vlib/v/gen/x64/gen.v
./v fmt -verify vlib/v/parser/
./v fmt -verify vlib/v/pref/
./v fmt -verify vlib/v/scanner/
./v fmt -verify vlib/v/table/
./v fmt -verify vlib/v/util/
./v fmt -verify vlib/v/vet/
./v fmt -verify vlib/v/vmod/
- name: v test-vet
run: ./v -silent test-vet
- name: v test-fmt
run: ./v -silent test-fmt

View File

@ -1,7 +1,6 @@
module main
import os
import time
import testing
import v.util
@ -33,7 +32,7 @@ fn main() {
fn v_test_formatting(vargs string) {
all_v_files := v_files()
prepare_vfmt_when_needed()
util.prepare_tool_when_needed('vfmt.v')
testing.eheader('Run "v fmt" over all .v files')
mut vfmt_test_session := testing.new_test_session('$vargs fmt -worker')
vfmt_test_session.files << all_v_files
@ -57,23 +56,3 @@ fn v_files() []string {
}
return files_that_can_be_formatted
}
fn prepare_vfmt_when_needed() {
vexe := os.getenv('VEXE')
vroot := os.dir(vexe)
vfmtv := os.join_path(vroot, 'cmd', 'tools', 'vfmt.v')
if util.should_recompile_tool(vexe, vfmtv) {
time.sleep_ms(1001) // TODO: remove this when we can get mtime with a better resolution
recompile_file(vexe, vfmtv)
}
}
fn recompile_file(vexe string, file string) {
cmd := '$vexe $file'
println('recompilation command: $cmd')
recompile_result := os.system(cmd)
if recompile_result != 0 {
eprintln('could not recompile $file')
exit(2)
}
}

View File

@ -0,0 +1,92 @@
module main
import os
import testing
import v.util
const (
vet_known_failing_exceptions = [
'nonexistent',
]
vet_folders = [
'vlib/sqlite',
'vlib/v',
'cmd/v',
'cmd/tools',
]
verify_known_failing_exceptions = [
'nonexistant'
]
verify_list = [
'vlib/builtin/array.v',
'vlib/os/file.v',
'vlib/math/bits/bits.v',
'vlib/time/time.v',
'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/',
'vlib/v/errors/',
'vlib/v/eval/',
'vlib/v/fmt/',
'vlib/v/gen/auto_str_methods.v',
'vlib/v/gen/cgen.v',
'vlib/v/gen/cgen_test.v',
'vlib/v/gen/cmain.v',
'vlib/v/gen/comptime.v',
'vlib/v/gen/fn.v',
'vlib/v/gen/json.v',
'vlib/v/gen/live.v',
'vlib/v/gen/profile.v',
'vlib/v/gen/sql.v',
'vlib/v/gen/str.v',
'vlib/v/gen/x64/elf.v',
'vlib/v/gen/x64/elf_obj.v',
'vlib/v/gen/x64/gen.v',
'vlib/v/parser/',
'vlib/v/pref/',
'vlib/v/scanner/',
'vlib/v/table/',
'vlib/v/util/',
'vlib/v/vet/',
'vlib/v/vmod/',
]
)
fn main() {
args := os.args
args_string := args[1..].join(' ')
pass_args := args_string.all_before('test-vet')
v_test_vetting(pass_args)
}
fn tsession(vargs string, tool_source string, tool_cmd string, tool_args string, flist []string, slist []string) testing.TestSession {
util.prepare_tool_when_needed(tool_source)
testing.eheader('Run `$tool_cmd` over most .v files')
mut test_session := testing.new_test_session('$vargs $tool_args')
test_session.files << flist
test_session.skip_files << slist
test_session.test()
eprintln(test_session.benchmark.total_message('running `$tool_cmd` over most .v files'))
return test_session
}
fn v_test_vetting(vargs string) {
vet_session := tsession(vargs, 'vvet.v', 'v vet', 'vet', vet_folders, vet_known_failing_exceptions)
verify_session := tsession(vargs, 'vfmt.v', 'v fmt -verify', 'fmt -verify', verify_list, verify_known_failing_exceptions)
//
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)
}
}

View File

@ -13,7 +13,7 @@ const (
simple_cmd = [
'fmt', 'up', 'vet',
'self', 'tracev', 'symlink', 'bin2v',
'test', 'test-fmt', 'test-compiler', 'test-fixed',
'test', 'test-fmt', 'test-compiler', 'test-fixed', 'test-vet',
'repl',
'build-tools', 'build-examples',
'build-vbinaries',

View File

@ -4,6 +4,7 @@
module util
import os
import time
import v.pref
import v.vmod
@ -390,3 +391,23 @@ pub fn no_cur_mod(typename string, cur_mod string) string {
}
return res
}
pub fn prepare_tool_when_needed(source_name string) {
vexe := os.getenv('VEXE')
vroot := os.dir(vexe)
stool := os.join_path(vroot, 'cmd', 'tools', source_name)
if should_recompile_tool(vexe, stool) {
time.sleep_ms(1001) // TODO: remove this when we can get mtime with a better resolution
recompile_file(vexe, stool)
}
}
pub fn recompile_file(vexe string, file string) {
cmd := '$vexe $file'
println('recompilation command: $cmd')
recompile_result := os.system(cmd)
if recompile_result != 0 {
eprintln('could not recompile $file')
exit(2)
}
}