-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvarnamelen_test.go
149 lines (121 loc) · 3.1 KB
/
varnamelen_test.go
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package varnamelen
import (
"os"
"testing"
"golang.org/x/tools/go/analysis/analysistest"
)
func TestRun_Warnings(t *testing.T) {
runTest(t, "warnings", nil)
}
func TestRun_Warnings_Return(t *testing.T) {
runTest(t, "warningsreturn", map[string]string{
"checkReturn": "true",
})
}
func TestRun_Warnings_Receiver(t *testing.T) {
runTest(t, "warningsreceiver", map[string]string{
"checkReceiver": "true",
})
}
func TestRun_NameLen(t *testing.T) {
runTest(t, "namelen", nil)
}
func TestRun_NameLen_Return(t *testing.T) {
runTest(t, "namelenreturn", map[string]string{
"checkReturn": "true",
})
}
func TestRun_NameLen_Receiver(t *testing.T) {
runTest(t, "namelenreceiver", map[string]string{
"checkReceiver": "true",
})
}
func TestRun_Distance(t *testing.T) {
runTest(t, "distance", nil)
}
func TestRun_Distance_Return(t *testing.T) {
runTest(t, "distancereturn", map[string]string{
"checkReturn": "true",
})
}
func TestRun_Distance_Receiver(t *testing.T) {
runTest(t, "distancereceiver", map[string]string{
"checkReceiver": "true",
})
}
func TestRun_IgnoreNames(t *testing.T) {
runTest(t, "ignorenames", map[string]string{
"ignoreNames": "i, I",
})
}
func TestRun_IgnoreNames_Return(t *testing.T) {
runTest(t, "ignorenamesreturn", map[string]string{
"ignoreNames": "i",
"checkReturn": "true",
})
}
func TestRun_IgnoreNames_Receiver(t *testing.T) {
runTest(t, "ignorenamesreceiver", map[string]string{
"ignoreNames": "f",
"checkReceiver": "true",
})
}
func TestRun_IgnoreDecls(t *testing.T) {
runTest(t, "ignoredecls", map[string]string{
"ignoreDecls": "i int, i map[string]string, i *bytes.Buffer, i *strs.Builder, const I",
})
}
func TestRun_IgnoreDecls_Return(t *testing.T) {
runTest(t, "ignoredeclsreturn", map[string]string{
"ignoreDecls": "i int",
"checkReturn": "true",
})
}
func TestRun_IgnoreDecls_Receiver(t *testing.T) {
runTest(t, "ignoredeclsreceiver", map[string]string{
"ignoreDecls": "f foo, f *foo",
"checkReceiver": "true",
})
}
func TestRun_IgnoreTypeAssertOk(t *testing.T) {
runTest(t, "typeassert", map[string]string{
"ignoreTypeAssertOk": "true",
})
}
func TestRun_IgnoreChanRecvOk(t *testing.T) {
runTest(t, "chanrecv", map[string]string{
"ignoreChanRecvOk": "true",
})
}
func TestRun_IgnoreMapIndexOk(t *testing.T) {
runTest(t, "mapindex", map[string]string{
"ignoreMapIndexOk": "true",
})
}
func TestRun_Conventional(t *testing.T) {
runTest(t, "conventional", nil)
}
func TestRun_FalseNegative_TypeAssertOk(t *testing.T) {
runTest(t, "falsenegativetypeassert", map[string]string{
"ignoreTypeAssertOk": "true",
})
}
func TestRun_FalseNegative_ChanRecvOk(t *testing.T) {
runTest(t, "falsenegativechanrecv", map[string]string{
"ignoreChanRecvOk": "true",
})
}
func TestRun_FalseNegative_MapIndexOk(t *testing.T) {
runTest(t, "falsenegativemapindex", map[string]string{
"ignoreMapIndexOk": "true",
})
}
func runTest(t *testing.T, pkg string, flags map[string]string) {
t.Helper()
analyzer := NewAnalyzer()
for k, v := range flags {
_ = analyzer.Flags.Set(k, v)
}
wd, _ := os.Getwd()
analysistest.Run(t, wd+"/testdata", analyzer, pkg)
}