...
1[short] skip
2
3# Test file
4! go test p1_test.go
5stderr 'Logf format %d'
6go test -vet=off
7stdout '^ok'
8
9# Non-test file
10! go test p1.go
11stderr 'Printf format %d'
12go test -x -vet=shift p1.go
13stderr '[\\/]vet.*-shift'
14stdout '\[no test files\]'
15go test -vet=off p1.go
16! stderr '[\\/]vet.*-shift'
17stdout '\[no test files\]'
18
19# ensure all runs non-default vet
20! go test -vet=all ./vetall/...
21stderr 'using resp before checking for errors'
22
23# Test issue #47309
24! go test -vet=bools,xyz ./vetall/...
25stderr '-vet argument must be a supported analyzer'
26
27# Test with a single analyzer
28! go test -vet=httpresponse ./vetall/...
29stderr 'using resp before checking for errors'
30
31# Test with a list of analyzers
32go test -vet=atomic,bools,nilfunc ./vetall/...
33stdout 'm/vetall.*\[no tests to run\]'
34
35# Test issue #22890
36go test m/vetcycle
37stdout 'm/vetcycle.*\[no test files\]'
38
39# Test with ...
40! go test ./vetfail/...
41stderr 'Printf format %d'
42stdout 'ok\s+m/vetfail/p2'
43
44# Check there's no diagnosis of a bad build constraint in vetxonly mode.
45# Use -a so that we need to recompute the vet-specific export data for
46# vetfail/p1.
47go test -a m/vetfail/p2
48! stderr 'invalid.*constraint'
49
50-- go.mod --
51module m
52
53go 1.16
54-- p1_test.go --
55package p
56
57import "testing"
58
59func Test(t *testing.T) {
60 t.Logf("%d") // oops
61}
62-- p1.go --
63package p
64
65import "fmt"
66
67func F() {
68 fmt.Printf("%d") // oops
69}
70-- vetall/p.go --
71package p
72
73import "net/http"
74
75func F() {
76 resp, err := http.Head("example.com")
77 defer resp.Body.Close()
78 if err != nil {
79 panic(err)
80 }
81 // (defer statement belongs here)
82}
83-- vetall/p_test.go --
84package p
85-- vetcycle/p.go --
86package p
87
88type (
89 _ interface{ m(B1) }
90 A1 interface{ a(D1) }
91 B1 interface{ A1 }
92 C1 interface {
93 B1 /* ERROR issue #18395 */
94 }
95 D1 interface{ C1 }
96)
97
98var _ A1 = C1 /* ERROR cannot use C1 */ (nil)
99-- vetfail/p1/p1.go --
100// +build !foo-bar
101
102package p1
103
104import "fmt"
105
106func F() {
107 fmt.Printf("%d", "hello") // causes vet error
108}
109-- vetfail/p2/p2.go --
110package p2
111
112import _ "m/vetfail/p1"
113
114func F() {
115}
116-- vetfail/p2/p2_test.go --
117package p2
118
119import "testing"
120
121func TestF(t *testing.T) {
122 F()
123}
View as plain text