@@ -14,7 +14,8 @@ import (
14
14
)
15
15
16
16
func TestAutogeneratedExclude_isGeneratedFileLax_generated (t * testing.T ) {
17
- p := NewAutogeneratedExclude (false )
17
+ p , err := NewAutogeneratedExclude (false , nil )
18
+ require .NoError (t , err )
18
19
19
20
comments := []string {
20
21
` // generated by stringer -type Pill pill.go; DO NOT EDIT` ,
@@ -56,7 +57,8 @@ func TestAutogeneratedExclude_isGeneratedFileLax_generated(t *testing.T) {
56
57
}
57
58
58
59
func TestAutogeneratedExclude_isGeneratedFileLax_nonGenerated (t * testing.T ) {
59
- p := NewAutogeneratedExclude (false )
60
+ p , err := NewAutogeneratedExclude (false , nil )
61
+ require .NoError (t , err )
60
62
61
63
comments := []string {
62
64
"code not generated by" ,
@@ -75,7 +77,8 @@ func TestAutogeneratedExclude_isGeneratedFileLax_nonGenerated(t *testing.T) {
75
77
}
76
78
77
79
func TestAutogeneratedExclude_isGeneratedFileStrict (t * testing.T ) {
78
- p := NewAutogeneratedExclude (true )
80
+ p , err := NewAutogeneratedExclude (true , nil )
81
+ require .NoError (t , err )
79
82
80
83
testCases := []struct {
81
84
desc string
@@ -153,22 +156,25 @@ func Test_getComments_fileWithLongLine(t *testing.T) {
153
156
154
157
func Test_shouldPassIssue (t * testing.T ) {
155
158
testCases := []struct {
156
- desc string
157
- strict bool
158
- issue * result.Issue
159
- assert assert.BoolAssertionFunc
159
+ desc string
160
+ include []string
161
+ strict bool
162
+ issue * result.Issue
163
+ assert assert.BoolAssertionFunc
160
164
}{
161
165
{
162
- desc : "typecheck issue" ,
163
- strict : false ,
166
+ desc : "typecheck issue" ,
167
+ include : nil ,
168
+ strict : false ,
164
169
issue : & result.Issue {
165
170
FromLinter : "typecheck" ,
166
171
},
167
172
assert : assert .True ,
168
173
},
169
174
{
170
- desc : "lax " ,
171
- strict : false ,
175
+ desc : "lax " ,
176
+ include : nil ,
177
+ strict : false ,
172
178
issue : & result.Issue {
173
179
FromLinter : "example" ,
174
180
Pos : token.Position {
@@ -178,8 +184,9 @@ func Test_shouldPassIssue(t *testing.T) {
178
184
assert : assert .False ,
179
185
},
180
186
{
181
- desc : "strict " ,
182
- strict : true ,
187
+ desc : "strict " ,
188
+ include : nil ,
189
+ strict : true ,
183
190
issue : & result.Issue {
184
191
FromLinter : "example" ,
185
192
Pos : token.Position {
@@ -188,14 +195,39 @@ func Test_shouldPassIssue(t *testing.T) {
188
195
},
189
196
assert : assert .True ,
190
197
},
198
+ {
199
+ desc : "include " ,
200
+ include : []string {"(.*)?invalid.go" },
201
+ strict : false ,
202
+ issue : & result.Issue {
203
+ FromLinter : "example" ,
204
+ Pos : token.Position {
205
+ Filename : filepath .FromSlash ("testdata/autogen_go_strict_invalid.go" ),
206
+ },
207
+ },
208
+ assert : assert .True ,
209
+ },
210
+ {
211
+ desc : "include other pattern" ,
212
+ include : []string {"(.*)?.pb.go" },
213
+ strict : false ,
214
+ issue : & result.Issue {
215
+ FromLinter : "example" ,
216
+ Pos : token.Position {
217
+ Filename : filepath .FromSlash ("testdata/autogen_go_strict_invalid.go" ),
218
+ },
219
+ },
220
+ assert : assert .False ,
221
+ },
191
222
}
192
223
193
224
for _ , test := range testCases {
194
225
test := test
195
226
t .Run (test .desc , func (t * testing.T ) {
196
227
t .Parallel ()
197
228
198
- p := NewAutogeneratedExclude (test .strict )
229
+ p , err := NewAutogeneratedExclude (test .strict , test .include )
230
+ require .NoError (t , err )
199
231
200
232
pass , err := p .shouldPassIssue (test .issue )
201
233
require .NoError (t , err )
@@ -213,13 +245,15 @@ func Test_shouldPassIssue_error(t *testing.T) {
213
245
214
246
testCases := []struct {
215
247
desc string
248
+ include []string
216
249
strict bool
217
250
issue * result.Issue
218
251
expected string
219
252
}{
220
253
{
221
- desc : "non-existing file (lax)" ,
222
- strict : false ,
254
+ desc : "non-existing file (lax)" ,
255
+ include : nil ,
256
+ strict : false ,
223
257
issue : & result.Issue {
224
258
FromLinter : "example" ,
225
259
Pos : token.Position {
@@ -230,8 +264,9 @@ func Test_shouldPassIssue_error(t *testing.T) {
230
264
filepath .FromSlash ("no-existing.go" ), notFoundMsg ),
231
265
},
232
266
{
233
- desc : "non-existing file (strict)" ,
234
- strict : true ,
267
+ desc : "non-existing file (strict)" ,
268
+ include : nil ,
269
+ strict : true ,
235
270
issue : & result.Issue {
236
271
FromLinter : "example" ,
237
272
Pos : token.Position {
@@ -248,7 +283,8 @@ func Test_shouldPassIssue_error(t *testing.T) {
248
283
t .Run (test .desc , func (t * testing.T ) {
249
284
t .Parallel ()
250
285
251
- p := NewAutogeneratedExclude (test .strict )
286
+ p , err := NewAutogeneratedExclude (test .strict , test .include )
287
+ require .NoError (t , err )
252
288
253
289
pass , err := p .shouldPassIssue (test .issue )
254
290
@@ -258,3 +294,46 @@ func Test_shouldPassIssue_error(t *testing.T) {
258
294
})
259
295
}
260
296
}
297
+
298
+ func Test_NewAutogeneratedExclude (t * testing.T ) {
299
+ testCases := []struct {
300
+ desc string
301
+ include []string
302
+ strict bool
303
+ assert assert.ValueAssertionFunc
304
+ expectedError string
305
+ }{
306
+ {
307
+ desc : "success " ,
308
+ include : []string {".pb.go" },
309
+ strict : false ,
310
+
311
+ assert : assert .NotNil ,
312
+ expectedError : "" ,
313
+ },
314
+ {
315
+ desc : "regexp compilation error " ,
316
+ include : []string {"*bad_regexp*" },
317
+ strict : false ,
318
+
319
+ assert : assert .Nil ,
320
+ expectedError : "can't compile regexp \" *bad_regexp*\" : error parsing regexp: missing argument to repetition operator: `*`" ,
321
+ },
322
+ }
323
+
324
+ for _ , test := range testCases {
325
+ test := test
326
+ t .Run (test .desc , func (t * testing.T ) {
327
+ t .Parallel ()
328
+
329
+ p , err := NewAutogeneratedExclude (test .strict , test .include )
330
+ test .assert (t , p )
331
+
332
+ if test .expectedError == "" {
333
+ assert .NoError (t , err )
334
+ } else {
335
+ assert .EqualError (t , err , test .expectedError )
336
+ }
337
+ })
338
+ }
339
+ }
0 commit comments