-
Notifications
You must be signed in to change notification settings - Fork 6
/
analyzer_test.go
208 lines (203 loc) · 4.8 KB
/
analyzer_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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package ginkgolinter_test
import (
"testing"
"golang.org/x/tools/go/analysis/analysistest"
"github.com/nunnatsa/ginkgolinter"
)
func TestAllUseCases(t *testing.T) {
for _, tc := range []struct {
testName string
testData string
}{
{
testName: "find wrong length assertion",
testData: "a/len",
},
{
testName: "find HaveLen(0)",
testData: "a/havelen0",
},
{
testName: "find wrong nil assertion",
testData: "a/nil",
},
{
testName: "find Equal(nil)",
testData: "a/equalnil",
},
{
testName: "find Equal() with a boolean value",
testData: "a/boolean",
},
{
testName: "check suppress comments",
testData: "a/suppress",
},
{
testName: "check no gomega import",
testData: "a/noginkgo",
},
{
testName: "check no dot-import",
testData: "a/nodotimport",
},
{
testName: "find assertions that compare errors to nil",
testData: "a/errnil",
},
{
testName: "check gomaga without ginkgo",
testData: "a/gomegaonly",
},
{
testName: "comparison",
testData: "a/comparison",
},
{
testName: "pointers",
testData: "a/pointers",
},
{
testName: "function call in Eventually",
testData: "a/eventually",
},
{
testName: "compare pointer to value",
testData: "a/pointerval",
},
{
testName: "no assertion",
testData: "a/noassersion",
},
{
testName: "focus",
testData: "a/focus",
},
{
testName: "equal with different type",
testData: "a/comparetypes",
},
{
testName: "MatchError",
testData: "a/matcherror",
},
{
testName: "issue 124: custom matcher form other packages",
testData: "a/issue-124",
},
{
testName: "cap",
testData: "a/cap",
},
{
testName: "HaveOccurred matcher tests",
testData: "a/haveoccurred",
},
{
testName: "nil error-func variable",
testData: "a/issue-171",
},
{
testName: "respect the Error() method",
testData: "a/issue-173",
},
{
testName: "matchError with func return error-func",
testData: "a/issue-174",
},
} {
t.Run(tc.testName, func(tt *testing.T) {
analysistest.Run(tt, analysistest.TestData(), ginkgolinter.NewAnalyzer(), tc.testData)
})
}
}
func TestFlags(t *testing.T) {
for _, tc := range []struct {
testName string
testData []string
flags map[string]string
}{
{
testName: "test the suppress-len-assertion flag",
testData: []string{"a/configlen"},
flags: map[string]string{"suppress-len-assertion": "true"},
},
{
testName: "test the suppress-nil-assertion flag",
testData: []string{"a/confignil"},
flags: map[string]string{"suppress-nil-assertion": "true"},
},
{
testName: "test the suppress-err-assertion flag",
testData: []string{"a/configerr"},
flags: map[string]string{"suppress-err-assertion": "true"},
},
{
testName: "test the suppress-compare-assertion flag",
testData: []string{"a/configcompare"},
flags: map[string]string{"suppress-compare-assertion": "true"},
},
{
testName: "test the allow-havelen-0 flag",
testData: []string{"a/havelen0config"},
flags: map[string]string{"allow-havelen-0": "true"},
},
{
testName: "test the suppress-async-assertion flag",
testData: []string{"a/asyncconfig"},
flags: map[string]string{"suppress-async-assertion": "true"},
},
{
testName: "test the forbid-focus-container flag",
testData: []string{"a/focusconfig"},
flags: map[string]string{"forbid-focus-container": "true"},
},
{
testName: "test the suppress-type-compare-assertion flag",
testData: []string{"a/comparetypesconfig"},
flags: map[string]string{"suppress-type-compare-assertion": "true"},
},
{
testName: "test the force-expect-to flag",
testData: []string{"a/forceExpectTo"},
flags: map[string]string{"force-expect-to": "true"},
},
{
testName: "check async timing intervals",
testData: []string{"a/timing"},
flags: map[string]string{"validate-async-intervals": "true"},
},
{
testName: "vars in containers",
testData: []string{"a/vars-in-containers"},
flags: map[string]string{"forbid-spec-pollution": "true"},
},
{
testName: "vars in containers + focus containers",
testData: []string{"a/containers-vas-and-focus"},
flags: map[string]string{
"forbid-spec-pollution": "true",
"forbid-focus-container": "true",
},
},
{
testName: "force Succeed/HaveOccurred",
testData: []string{"a/confighaveoccurred"},
flags: map[string]string{
"force-succeed": "true",
},
},
} {
t.Run(tc.testName, func(tt *testing.T) {
analyzer := ginkgolinter.NewAnalyzer()
for flag, value := range tc.flags {
err := analyzer.Flags.Set(flag, value)
if err != nil {
tt.Errorf(`failed to set the "%s" flag; %v`, flag, err)
return
}
}
analysistest.Run(tt, analysistest.TestData(), analyzer, tc.testData...)
})
}
}