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