Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit bb5fd5e

Browse files
authored
fix linter errors (#552)
1 parent 0cd3aaf commit bb5fd5e

File tree

8 files changed

+70
-167
lines changed

8 files changed

+70
-167
lines changed

gomock/call.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ func (c *Call) matches(args []interface{}) error {
380380
// Check that all prerequisite calls have been satisfied.
381381
for _, preReqCall := range c.preReqs {
382382
if !preReqCall.satisfied() {
383-
return fmt.Errorf("Expected call at %s doesn't have a prerequisite call satisfied:\n%v\nshould be called before:\n%v",
383+
return fmt.Errorf("expected call at %s doesn't have a prerequisite call satisfied:\n%v\nshould be called before:\n%v",
384384
c.origin, preReqCall, c)
385385
}
386386
}

gomock/call_test.go

Lines changed: 47 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ var testCases []testCase = []testCase{
126126
{
127127
description: "argument to Do is not a function",
128128
doFunc: "meow",
129-
callFunc: func(x int, y int) {
130-
return
131-
},
129+
callFunc: func(x int, y int) {},
132130
args: []interface{}{0, 1},
133131
expectPanic: true,
134132
}, {
@@ -141,12 +139,8 @@ var testCases []testCase = []testCase{
141139
expectPanic: true,
142140
}, {
143141
description: "number of args for Do func don't match Call func",
144-
doFunc: func(x int) {
145-
return
146-
},
147-
callFunc: func(x int, y int) {
148-
return
149-
},
142+
doFunc: func(x int) {},
143+
callFunc: func(x int, y int) {},
150144
args: []interface{}{0, 1},
151145
expectPanic: true,
152146
}, {
@@ -161,12 +155,8 @@ var testCases []testCase = []testCase{
161155
expectPanic: true,
162156
}, {
163157
description: "arg type for Do func incompatible with Call func",
164-
doFunc: func(x int) {
165-
return
166-
},
167-
callFunc: func(x string) {
168-
return
169-
},
158+
doFunc: func(x int) {},
159+
callFunc: func(x string) {},
170160
args: []interface{}{"meow"},
171161
expectPanic: true,
172162
}, {
@@ -181,22 +171,14 @@ var testCases []testCase = []testCase{
181171
expectPanic: true,
182172
}, {
183173
description: "Do func(int) Call func(int)",
184-
doFunc: func(x int) {
185-
return
186-
},
187-
callFunc: func(x int) {
188-
return
189-
},
190-
args: []interface{}{0},
174+
doFunc: func(x int) {},
175+
callFunc: func(x int) {},
176+
args: []interface{}{0},
191177
}, {
192178
description: "Do func(int) Call func(interface{})",
193-
doFunc: func(x int) {
194-
return
195-
},
196-
callFunc: func(x interface{}) {
197-
return
198-
},
199-
args: []interface{}{0},
179+
doFunc: func(x int) {},
180+
callFunc: func(x interface{}) {},
181+
args: []interface{}{0},
200182
}, {
201183
description: "Do func(int) bool Call func(int) bool",
202184
doFunc: func(x int) bool {
@@ -217,12 +199,8 @@ var testCases []testCase = []testCase{
217199
args: []interface{}{0},
218200
}, {
219201
description: "Do func(string) Call func([]byte)",
220-
doFunc: func(x string) {
221-
return
222-
},
223-
callFunc: func(x []byte) {
224-
return
225-
},
202+
doFunc: func(x string) {},
203+
callFunc: func(x []byte) {},
226204
args: []interface{}{[]byte("meow")},
227205
expectPanic: true,
228206
}, {
@@ -237,22 +215,14 @@ var testCases []testCase = []testCase{
237215
expectPanic: true,
238216
}, {
239217
description: "Do func(map[int]string) Call func(map[interface{}]int)",
240-
doFunc: func(x map[int]string) {
241-
return
242-
},
243-
callFunc: func(x map[interface{}]int) {
244-
return
245-
},
218+
doFunc: func(x map[int]string) {},
219+
callFunc: func(x map[interface{}]int) {},
246220
args: []interface{}{map[interface{}]int{"meow": 0}},
247221
expectPanic: true,
248222
}, {
249223
description: "Do func(map[int]string) Call func(map[interface{}]interface{})",
250-
doFunc: func(x map[int]string) {
251-
return
252-
},
253-
callFunc: func(x map[interface{}]interface{}) {
254-
return
255-
},
224+
doFunc: func(x map[int]string) {},
225+
callFunc: func(x map[interface{}]interface{}) {},
256226
args: []interface{}{map[interface{}]interface{}{"meow": "meow"}},
257227
expectPanic: true,
258228
}, {
@@ -277,61 +247,37 @@ var testCases []testCase = []testCase{
277247
expectPanic: true,
278248
}, {
279249
description: "Do func([]string) Call func([]interface{})",
280-
doFunc: func(x []string) {
281-
return
282-
},
283-
callFunc: func(x []interface{}) {
284-
return
285-
},
250+
doFunc: func(x []string) {},
251+
callFunc: func(x []interface{}) {},
286252
args: []interface{}{[]interface{}{0}},
287253
expectPanic: true,
288254
}, {
289255
description: "Do func([]string) Call func([]int)",
290-
doFunc: func(x []string) {
291-
return
292-
},
293-
callFunc: func(x []int) {
294-
return
295-
},
256+
doFunc: func(x []string) {},
257+
callFunc: func(x []int) {},
296258
args: []interface{}{[]int{0, 1}},
297259
expectPanic: true,
298260
}, {
299261
description: "Do func([]int) Call func([]int)",
300-
doFunc: func(x []int) {
301-
return
302-
},
303-
callFunc: func(x []int) {
304-
return
305-
},
306-
args: []interface{}{[]int{0, 1}},
262+
doFunc: func(x []int) {},
263+
callFunc: func(x []int) {},
264+
args: []interface{}{[]int{0, 1}},
307265
}, {
308266
description: "Do func([]int) Call func([]interface{})",
309-
doFunc: func(x []int) {
310-
return
311-
},
312-
callFunc: func(x []interface{}) {
313-
return
314-
},
267+
doFunc: func(x []int) {},
268+
callFunc: func(x []interface{}) {},
315269
args: []interface{}{[]interface{}{0}},
316270
expectPanic: true,
317271
}, {
318272
description: "Do func([]int) Call func(...interface{})",
319-
doFunc: func(x []int) {
320-
return
321-
},
322-
callFunc: func(x ...interface{}) {
323-
return
324-
},
273+
doFunc: func(x []int) {},
274+
callFunc: func(x ...interface{}) {},
325275
args: []interface{}{0, 1},
326276
expectPanic: true,
327277
}, {
328278
description: "Do func([]int) Call func(...int)",
329-
doFunc: func(x []int) {
330-
return
331-
},
332-
callFunc: func(x ...int) {
333-
return
334-
},
279+
doFunc: func(x []int) {},
280+
callFunc: func(x ...int) {},
335281
args: []interface{}{0, 1},
336282
expectPanic: true,
337283
}, {
@@ -395,33 +341,21 @@ var testCases []testCase = []testCase{
395341
expectPanic: true,
396342
}, {
397343
description: "Do func(...int) Call func([]int)",
398-
doFunc: func(x ...int) {
399-
return
400-
},
401-
callFunc: func(x []int) {
402-
return
403-
},
344+
doFunc: func(x ...int) {},
345+
callFunc: func(x []int) {},
404346
args: []interface{}{[]int{0, 1}},
405347
expectPanic: true,
406348
}, {
407349
description: "Do func(...int) Call func([]interface{})",
408-
doFunc: func(x ...int) {
409-
return
410-
},
411-
callFunc: func(x []interface{}) {
412-
return
413-
},
350+
doFunc: func(x ...int) {},
351+
callFunc: func(x []interface{}) {},
414352
args: []interface{}{[]interface{}{0, 1}},
415353
expectPanic: true,
416354
}, {
417355
description: "Do func(...int) Call func(...interface{})",
418-
doFunc: func(x ...int) {
419-
return
420-
},
421-
callFunc: func(x ...interface{}) {
422-
return
423-
},
424-
args: []interface{}{0, 1},
356+
doFunc: func(x ...int) {},
357+
callFunc: func(x ...interface{}) {},
358+
args: []interface{}{0, 1},
425359
}, {
426360
description: "Do func(...int) bool Call func(...int) bool",
427361
doFunc: func(x ...int) bool {
@@ -462,40 +396,24 @@ var testCases []testCase = []testCase{
462396
args: []interface{}{0, 1},
463397
}, {
464398
description: "Do func(...int) Call func(...int)",
465-
doFunc: func(x ...int) {
466-
return
467-
},
468-
callFunc: func(x ...int) {
469-
return
470-
},
471-
args: []interface{}{0, 1},
399+
doFunc: func(x ...int) {},
400+
callFunc: func(x ...int) {},
401+
args: []interface{}{0, 1},
472402
}, {
473403
description: "Do func(foo); foo implements interface X Call func(interface X)",
474-
doFunc: func(x foo) {
475-
return
476-
},
477-
callFunc: func(x fmt.Stringer) {
478-
return
479-
},
480-
args: []interface{}{foo{}},
404+
doFunc: func(x foo) {},
405+
callFunc: func(x fmt.Stringer) {},
406+
args: []interface{}{foo{}},
481407
}, {
482408
description: "Do func(b); b does not implement interface X Call func(interface X)",
483-
doFunc: func(x b) {
484-
return
485-
},
486-
callFunc: func(x fmt.Stringer) {
487-
return
488-
},
409+
doFunc: func(x b) {},
410+
callFunc: func(x fmt.Stringer) {},
489411
args: []interface{}{foo{}},
490412
expectPanic: true,
491413
}, {
492414
description: "Do func(b) Call func(a); a and b are not aliases",
493-
doFunc: func(x b) {
494-
return
495-
},
496-
callFunc: func(x a) {
497-
return
498-
},
415+
doFunc: func(x b) {},
416+
callFunc: func(x a) {},
499417
args: []interface{}{a{}},
500418
expectPanic: true,
501419
}, {

gomock/controller_test.go

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,6 @@ func (e *ErrorReporter) assertFail(msg string) {
5454
}
5555
}
5656

57-
func (e *ErrorReporter) assertLogf(expectedErrMsgs ...string) {
58-
if len(e.log) < len(expectedErrMsgs) {
59-
e.t.Fatalf("got %d Logf messages, want %d", len(e.log), len(expectedErrMsgs))
60-
}
61-
for i, expectedErrMsg := range expectedErrMsgs {
62-
if !strings.Contains(e.log[i], expectedErrMsg) {
63-
e.t.Errorf("Error message:\ngot: %q\nwant to contain: %q\n", e.log[i], expectedErrMsg)
64-
}
65-
}
66-
}
67-
6857
// Use to check that code triggers a fatal test failure.
6958
func (e *ErrorReporter) assertFatal(fn func(), expectedErrMsgs ...string) {
7059
defer func() {
@@ -411,14 +400,14 @@ func TestMinTimes1(t *testing.T) {
411400
})
412401

413402
// It succeeds if there is one call
414-
reporter, ctrl = createFixtures(t)
403+
_, ctrl = createFixtures(t)
415404
subject = new(Subject)
416405
ctrl.RecordCall(subject, "FooMethod", "argument").MinTimes(1)
417406
ctrl.Call(subject, "FooMethod", "argument")
418407
ctrl.Finish()
419408

420409
// It succeeds if there are many calls
421-
reporter, ctrl = createFixtures(t)
410+
_, ctrl = createFixtures(t)
422411
subject = new(Subject)
423412
ctrl.RecordCall(subject, "FooMethod", "argument").MinTimes(1)
424413
for i := 0; i < 100; i++ {
@@ -473,7 +462,7 @@ func TestMinMaxTimes(t *testing.T) {
473462
})
474463

475464
// It succeeds if there is just the right number of calls
476-
reporter, ctrl = createFixtures(t)
465+
_, ctrl = createFixtures(t)
477466
subject = new(Subject)
478467
ctrl.RecordCall(subject, "FooMethod", "argument").MaxTimes(2).MinTimes(2)
479468
ctrl.Call(subject, "FooMethod", "argument")
@@ -491,7 +480,7 @@ func TestMinMaxTimes(t *testing.T) {
491480
})
492481

493482
// If MinTimes is called after MaxTimes is called with 1, MinTimes takes precedence.
494-
reporter, ctrl = createFixtures(t)
483+
_, ctrl = createFixtures(t)
495484
subject = new(Subject)
496485
ctrl.RecordCall(subject, "FooMethod", "argument").MaxTimes(1).MinTimes(2)
497486
for i := 0; i < 100; i++ {
@@ -506,7 +495,8 @@ func TestDo(t *testing.T) {
506495

507496
doCalled := false
508497
var argument string
509-
ctrl.RecordCall(subject, "FooMethod", "argument").Do(
498+
wantArg := "argument"
499+
ctrl.RecordCall(subject, "FooMethod", wantArg).Do(
510500
func(arg string) {
511501
doCalled = true
512502
argument = arg
@@ -515,12 +505,12 @@ func TestDo(t *testing.T) {
515505
t.Error("Do() callback called too early.")
516506
}
517507

518-
ctrl.Call(subject, "FooMethod", "argument")
508+
ctrl.Call(subject, "FooMethod", wantArg)
519509

520510
if !doCalled {
521511
t.Error("Do() callback not called.")
522512
}
523-
if "argument" != argument {
513+
if wantArg != argument {
524514
t.Error("Do callback received wrong argument.")
525515
}
526516

@@ -533,7 +523,8 @@ func TestDoAndReturn(t *testing.T) {
533523

534524
doCalled := false
535525
var argument string
536-
ctrl.RecordCall(subject, "FooMethod", "argument").DoAndReturn(
526+
wantArg := "argument"
527+
ctrl.RecordCall(subject, "FooMethod", wantArg).DoAndReturn(
537528
func(arg string) int {
538529
doCalled = true
539530
argument = arg
@@ -543,12 +534,12 @@ func TestDoAndReturn(t *testing.T) {
543534
t.Error("Do() callback called too early.")
544535
}
545536

546-
rets := ctrl.Call(subject, "FooMethod", "argument")
537+
rets := ctrl.Call(subject, "FooMethod", wantArg)
547538

548539
if !doCalled {
549540
t.Error("Do() callback not called.")
550541
}
551-
if "argument" != argument {
542+
if wantArg != argument {
552543
t.Error("Do callback received wrong argument.")
553544
}
554545
if len(rets) != 1 {

0 commit comments

Comments
 (0)