Skip to content

Commit 23ee301

Browse files
committed
tools: add v test-vet
1 parent 296a609 commit 23ee301

File tree

5 files changed

+117
-68
lines changed

5 files changed

+117
-68
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,51 +21,8 @@ jobs:
2121
run: echo $VFLAGS $GITHUB_SHA $GITHUB_REF
2222
- name: Build local v
2323
run: make -j4
24-
- name: v vet
25-
run: |
26-
./v vet vlib/sqlite
27-
./v vet vlib/v
28-
./v vet cmd/v
29-
./v vet cmd/tools
30-
- name: v fmt -verify
31-
run: |
32-
./v fmt -verify vlib/builtin/array.v
33-
./v fmt -verify vlib/os/file.v
34-
./v fmt -verify vlib/math/bits/bits.v
35-
./v fmt -verify vlib/time/time.v
36-
./v fmt -verify vlib/term/colors.v
37-
./v fmt -verify vlib/term/term.v
38-
./v fmt -verify vlib/v/ast/
39-
./v fmt -verify vlib/v/builder/
40-
./v fmt -verify vlib/v/cflag/
41-
./v fmt -verify vlib/v/checker/
42-
./v fmt -verify vlib/v/depgraph/
43-
./v fmt -verify vlib/v/doc/
44-
./v fmt -verify vlib/v/errors/
45-
./v fmt -verify vlib/v/eval/
46-
./v fmt -verify vlib/v/fmt/
47-
./v fmt -verify vlib/v/gen/auto_str_methods.v
48-
./v fmt -verify vlib/v/gen/cgen.v
49-
./v fmt -verify vlib/v/gen/cgen_test.v
50-
./v fmt -verify vlib/v/gen/cmain.v
51-
./v fmt -verify vlib/v/gen/comptime.v
52-
./v fmt -verify vlib/v/gen/fn.v
53-
./v fmt -verify vlib/v/gen/json.v
54-
./v fmt -verify vlib/v/gen/live.v
55-
./v fmt -verify vlib/v/gen/profile.v
56-
./v fmt -verify vlib/v/gen/sql.v
57-
./v fmt -verify vlib/v/gen/str.v
58-
./v fmt -verify vlib/v/gen/x64/elf.v
59-
./v fmt -verify vlib/v/gen/x64/elf_obj.v
60-
./v fmt -verify vlib/v/gen/x64/gen.v
61-
./v fmt -verify vlib/v/parser/
62-
./v fmt -verify vlib/v/pref/
63-
./v fmt -verify vlib/v/scanner/
64-
./v fmt -verify vlib/v/table/
65-
./v fmt -verify vlib/v/util/
66-
./v fmt -verify vlib/v/vet/
67-
./v fmt -verify vlib/v/vmod/
68-
24+
- name: v test-vet
25+
run: ./v -silent test-vet
6926
- name: v test-fmt
7027
run: ./v -silent test-fmt
7128

cmd/tools/vtest-fmt.v

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module main
22

33
import os
4-
import time
54
import testing
65
import v.util
76

@@ -33,7 +32,7 @@ fn main() {
3332

3433
fn v_test_formatting(vargs string) {
3534
all_v_files := v_files()
36-
prepare_vfmt_when_needed()
35+
util.prepare_tool_when_needed('vfmt.v')
3736
testing.eheader('Run "v fmt" over all .v files')
3837
mut vfmt_test_session := testing.new_test_session('$vargs fmt -worker')
3938
vfmt_test_session.files << all_v_files
@@ -57,23 +56,3 @@ fn v_files() []string {
5756
}
5857
return files_that_can_be_formatted
5958
}
60-
61-
fn prepare_vfmt_when_needed() {
62-
vexe := os.getenv('VEXE')
63-
vroot := os.dir(vexe)
64-
vfmtv := os.join_path(vroot, 'cmd', 'tools', 'vfmt.v')
65-
if util.should_recompile_tool(vexe, vfmtv) {
66-
time.sleep_ms(1001) // TODO: remove this when we can get mtime with a better resolution
67-
recompile_file(vexe, vfmtv)
68-
}
69-
}
70-
71-
fn recompile_file(vexe string, file string) {
72-
cmd := '$vexe $file'
73-
println('recompilation command: $cmd')
74-
recompile_result := os.system(cmd)
75-
if recompile_result != 0 {
76-
eprintln('could not recompile $file')
77-
exit(2)
78-
}
79-
}

cmd/tools/vtest-vet.v

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
module main
2+
3+
import os
4+
import testing
5+
import v.util
6+
7+
const (
8+
vet_known_failing_exceptions = [
9+
'nonexistent',
10+
]
11+
vet_folders = [
12+
'vlib/sqlite',
13+
'vlib/v',
14+
'cmd/v',
15+
'cmd/tools',
16+
]
17+
verify_known_failing_exceptions = [
18+
'nonexistant'
19+
]
20+
verify_list = [
21+
'vlib/builtin/array.v',
22+
'vlib/os/file.v',
23+
'vlib/math/bits/bits.v',
24+
'vlib/time/time.v',
25+
'vlib/term/colors.v',
26+
'vlib/term/term.v',
27+
'vlib/v/ast/',
28+
'vlib/v/builder/',
29+
'vlib/v/cflag/',
30+
'vlib/v/checker/',
31+
'vlib/v/depgraph/',
32+
'vlib/v/doc/',
33+
'vlib/v/errors/',
34+
'vlib/v/eval/',
35+
'vlib/v/fmt/',
36+
'vlib/v/gen/auto_str_methods.v',
37+
'vlib/v/gen/cgen.v',
38+
'vlib/v/gen/cgen_test.v',
39+
'vlib/v/gen/cmain.v',
40+
'vlib/v/gen/comptime.v',
41+
'vlib/v/gen/fn.v',
42+
'vlib/v/gen/json.v',
43+
'vlib/v/gen/live.v',
44+
'vlib/v/gen/profile.v',
45+
'vlib/v/gen/sql.v',
46+
'vlib/v/gen/str.v',
47+
'vlib/v/gen/x64/elf.v',
48+
'vlib/v/gen/x64/elf_obj.v',
49+
'vlib/v/gen/x64/gen.v',
50+
'vlib/v/parser/',
51+
'vlib/v/pref/',
52+
'vlib/v/scanner/',
53+
'vlib/v/table/',
54+
'vlib/v/util/',
55+
'vlib/v/vet/',
56+
'vlib/v/vmod/',
57+
]
58+
)
59+
60+
fn main() {
61+
args := os.args
62+
args_string := args[1..].join(' ')
63+
pass_args := args_string.all_before('test-vet')
64+
v_test_vetting(pass_args)
65+
}
66+
67+
fn tsession(vargs string, tool_source string, tool_cmd string, tool_args string, flist []string, slist []string) testing.TestSession {
68+
util.prepare_tool_when_needed(tool_source)
69+
testing.eheader('Run `$tool_cmd` over most .v files')
70+
mut test_session := testing.new_test_session('$vargs $tool_args')
71+
test_session.files << flist
72+
test_session.skip_files << slist
73+
test_session.test()
74+
eprintln(test_session.benchmark.total_message('running `$tool_cmd` over most .v files'))
75+
return test_session
76+
}
77+
78+
fn v_test_vetting(vargs string) {
79+
vet_session := tsession(vargs, 'vvet.v', 'v vet', 'vet', vet_folders, vet_known_failing_exceptions)
80+
verify_session := tsession(vargs, 'vfmt.v', 'v fmt -verify', 'fmt -verify', verify_list, verify_known_failing_exceptions)
81+
//
82+
if vet_session.benchmark.nfail > 0 || verify_session.benchmark.nfail > 0 {
83+
eprintln('\n')
84+
if vet_session.benchmark.nfail > 0 {
85+
eprintln('WARNING: `v vet` failed $vet_session.benchmark.nfail times.')
86+
}
87+
if verify_session.benchmark.nfail > 0 {
88+
eprintln('WARNING: `v fmt -verify` failed $verify_session.benchmark.nfail times.')
89+
}
90+
exit(1)
91+
}
92+
}

cmd/v/v.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const (
1313
simple_cmd = [
1414
'fmt', 'up', 'vet',
1515
'self', 'tracev', 'symlink', 'bin2v',
16-
'test', 'test-fmt', 'test-compiler', 'test-fixed',
16+
'test', 'test-fmt', 'test-compiler', 'test-fixed', 'test-vet',
1717
'repl',
1818
'build-tools', 'build-examples',
1919
'build-vbinaries',

vlib/v/util/util.v

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
module util
55

66
import os
7+
import time
78
import v.pref
89
import v.vmod
910

@@ -390,3 +391,23 @@ pub fn no_cur_mod(typename string, cur_mod string) string {
390391
}
391392
return res
392393
}
394+
395+
pub fn prepare_tool_when_needed(source_name string) {
396+
vexe := os.getenv('VEXE')
397+
vroot := os.dir(vexe)
398+
stool := os.join_path(vroot, 'cmd', 'tools', source_name)
399+
if should_recompile_tool(vexe, stool) {
400+
time.sleep_ms(1001) // TODO: remove this when we can get mtime with a better resolution
401+
recompile_file(vexe, stool)
402+
}
403+
}
404+
405+
pub fn recompile_file(vexe string, file string) {
406+
cmd := '$vexe $file'
407+
println('recompilation command: $cmd')
408+
recompile_result := os.system(cmd)
409+
if recompile_result != 0 {
410+
eprintln('could not recompile $file')
411+
exit(2)
412+
}
413+
}

0 commit comments

Comments
 (0)