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

Commit

Permalink
fix linter errors (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
codyoss committed Apr 23, 2021
1 parent 0cd3aaf commit bb5fd5e
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 167 deletions.
2 changes: 1 addition & 1 deletion gomock/call.go
Expand Up @@ -380,7 +380,7 @@ func (c *Call) matches(args []interface{}) error {
// Check that all prerequisite calls have been satisfied.
for _, preReqCall := range c.preReqs {
if !preReqCall.satisfied() {
return fmt.Errorf("Expected call at %s doesn't have a prerequisite call satisfied:\n%v\nshould be called before:\n%v",
return fmt.Errorf("expected call at %s doesn't have a prerequisite call satisfied:\n%v\nshould be called before:\n%v",
c.origin, preReqCall, c)
}
}
Expand Down
176 changes: 47 additions & 129 deletions gomock/call_test.go
Expand Up @@ -126,9 +126,7 @@ var testCases []testCase = []testCase{
{
description: "argument to Do is not a function",
doFunc: "meow",
callFunc: func(x int, y int) {
return
},
callFunc: func(x int, y int) {},
args: []interface{}{0, 1},
expectPanic: true,
}, {
Expand All @@ -141,12 +139,8 @@ var testCases []testCase = []testCase{
expectPanic: true,
}, {
description: "number of args for Do func don't match Call func",
doFunc: func(x int) {
return
},
callFunc: func(x int, y int) {
return
},
doFunc: func(x int) {},
callFunc: func(x int, y int) {},
args: []interface{}{0, 1},
expectPanic: true,
}, {
Expand All @@ -161,12 +155,8 @@ var testCases []testCase = []testCase{
expectPanic: true,
}, {
description: "arg type for Do func incompatible with Call func",
doFunc: func(x int) {
return
},
callFunc: func(x string) {
return
},
doFunc: func(x int) {},
callFunc: func(x string) {},
args: []interface{}{"meow"},
expectPanic: true,
}, {
Expand All @@ -181,22 +171,14 @@ var testCases []testCase = []testCase{
expectPanic: true,
}, {
description: "Do func(int) Call func(int)",
doFunc: func(x int) {
return
},
callFunc: func(x int) {
return
},
args: []interface{}{0},
doFunc: func(x int) {},
callFunc: func(x int) {},
args: []interface{}{0},
}, {
description: "Do func(int) Call func(interface{})",
doFunc: func(x int) {
return
},
callFunc: func(x interface{}) {
return
},
args: []interface{}{0},
doFunc: func(x int) {},
callFunc: func(x interface{}) {},
args: []interface{}{0},
}, {
description: "Do func(int) bool Call func(int) bool",
doFunc: func(x int) bool {
Expand All @@ -217,12 +199,8 @@ var testCases []testCase = []testCase{
args: []interface{}{0},
}, {
description: "Do func(string) Call func([]byte)",
doFunc: func(x string) {
return
},
callFunc: func(x []byte) {
return
},
doFunc: func(x string) {},
callFunc: func(x []byte) {},
args: []interface{}{[]byte("meow")},
expectPanic: true,
}, {
Expand All @@ -237,22 +215,14 @@ var testCases []testCase = []testCase{
expectPanic: true,
}, {
description: "Do func(map[int]string) Call func(map[interface{}]int)",
doFunc: func(x map[int]string) {
return
},
callFunc: func(x map[interface{}]int) {
return
},
doFunc: func(x map[int]string) {},
callFunc: func(x map[interface{}]int) {},
args: []interface{}{map[interface{}]int{"meow": 0}},
expectPanic: true,
}, {
description: "Do func(map[int]string) Call func(map[interface{}]interface{})",
doFunc: func(x map[int]string) {
return
},
callFunc: func(x map[interface{}]interface{}) {
return
},
doFunc: func(x map[int]string) {},
callFunc: func(x map[interface{}]interface{}) {},
args: []interface{}{map[interface{}]interface{}{"meow": "meow"}},
expectPanic: true,
}, {
Expand All @@ -277,61 +247,37 @@ var testCases []testCase = []testCase{
expectPanic: true,
}, {
description: "Do func([]string) Call func([]interface{})",
doFunc: func(x []string) {
return
},
callFunc: func(x []interface{}) {
return
},
doFunc: func(x []string) {},
callFunc: func(x []interface{}) {},
args: []interface{}{[]interface{}{0}},
expectPanic: true,
}, {
description: "Do func([]string) Call func([]int)",
doFunc: func(x []string) {
return
},
callFunc: func(x []int) {
return
},
doFunc: func(x []string) {},
callFunc: func(x []int) {},
args: []interface{}{[]int{0, 1}},
expectPanic: true,
}, {
description: "Do func([]int) Call func([]int)",
doFunc: func(x []int) {
return
},
callFunc: func(x []int) {
return
},
args: []interface{}{[]int{0, 1}},
doFunc: func(x []int) {},
callFunc: func(x []int) {},
args: []interface{}{[]int{0, 1}},
}, {
description: "Do func([]int) Call func([]interface{})",
doFunc: func(x []int) {
return
},
callFunc: func(x []interface{}) {
return
},
doFunc: func(x []int) {},
callFunc: func(x []interface{}) {},
args: []interface{}{[]interface{}{0}},
expectPanic: true,
}, {
description: "Do func([]int) Call func(...interface{})",
doFunc: func(x []int) {
return
},
callFunc: func(x ...interface{}) {
return
},
doFunc: func(x []int) {},
callFunc: func(x ...interface{}) {},
args: []interface{}{0, 1},
expectPanic: true,
}, {
description: "Do func([]int) Call func(...int)",
doFunc: func(x []int) {
return
},
callFunc: func(x ...int) {
return
},
doFunc: func(x []int) {},
callFunc: func(x ...int) {},
args: []interface{}{0, 1},
expectPanic: true,
}, {
Expand Down Expand Up @@ -395,33 +341,21 @@ var testCases []testCase = []testCase{
expectPanic: true,
}, {
description: "Do func(...int) Call func([]int)",
doFunc: func(x ...int) {
return
},
callFunc: func(x []int) {
return
},
doFunc: func(x ...int) {},
callFunc: func(x []int) {},
args: []interface{}{[]int{0, 1}},
expectPanic: true,
}, {
description: "Do func(...int) Call func([]interface{})",
doFunc: func(x ...int) {
return
},
callFunc: func(x []interface{}) {
return
},
doFunc: func(x ...int) {},
callFunc: func(x []interface{}) {},
args: []interface{}{[]interface{}{0, 1}},
expectPanic: true,
}, {
description: "Do func(...int) Call func(...interface{})",
doFunc: func(x ...int) {
return
},
callFunc: func(x ...interface{}) {
return
},
args: []interface{}{0, 1},
doFunc: func(x ...int) {},
callFunc: func(x ...interface{}) {},
args: []interface{}{0, 1},
}, {
description: "Do func(...int) bool Call func(...int) bool",
doFunc: func(x ...int) bool {
Expand Down Expand Up @@ -462,40 +396,24 @@ var testCases []testCase = []testCase{
args: []interface{}{0, 1},
}, {
description: "Do func(...int) Call func(...int)",
doFunc: func(x ...int) {
return
},
callFunc: func(x ...int) {
return
},
args: []interface{}{0, 1},
doFunc: func(x ...int) {},
callFunc: func(x ...int) {},
args: []interface{}{0, 1},
}, {
description: "Do func(foo); foo implements interface X Call func(interface X)",
doFunc: func(x foo) {
return
},
callFunc: func(x fmt.Stringer) {
return
},
args: []interface{}{foo{}},
doFunc: func(x foo) {},
callFunc: func(x fmt.Stringer) {},
args: []interface{}{foo{}},
}, {
description: "Do func(b); b does not implement interface X Call func(interface X)",
doFunc: func(x b) {
return
},
callFunc: func(x fmt.Stringer) {
return
},
doFunc: func(x b) {},
callFunc: func(x fmt.Stringer) {},
args: []interface{}{foo{}},
expectPanic: true,
}, {
description: "Do func(b) Call func(a); a and b are not aliases",
doFunc: func(x b) {
return
},
callFunc: func(x a) {
return
},
doFunc: func(x b) {},
callFunc: func(x a) {},
args: []interface{}{a{}},
expectPanic: true,
}, {
Expand Down
33 changes: 12 additions & 21 deletions gomock/controller_test.go
Expand Up @@ -54,17 +54,6 @@ func (e *ErrorReporter) assertFail(msg string) {
}
}

func (e *ErrorReporter) assertLogf(expectedErrMsgs ...string) {
if len(e.log) < len(expectedErrMsgs) {
e.t.Fatalf("got %d Logf messages, want %d", len(e.log), len(expectedErrMsgs))
}
for i, expectedErrMsg := range expectedErrMsgs {
if !strings.Contains(e.log[i], expectedErrMsg) {
e.t.Errorf("Error message:\ngot: %q\nwant to contain: %q\n", e.log[i], expectedErrMsg)
}
}
}

// Use to check that code triggers a fatal test failure.
func (e *ErrorReporter) assertFatal(fn func(), expectedErrMsgs ...string) {
defer func() {
Expand Down Expand Up @@ -411,14 +400,14 @@ func TestMinTimes1(t *testing.T) {
})

// It succeeds if there is one call
reporter, ctrl = createFixtures(t)
_, ctrl = createFixtures(t)
subject = new(Subject)
ctrl.RecordCall(subject, "FooMethod", "argument").MinTimes(1)
ctrl.Call(subject, "FooMethod", "argument")
ctrl.Finish()

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

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

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

doCalled := false
var argument string
ctrl.RecordCall(subject, "FooMethod", "argument").Do(
wantArg := "argument"
ctrl.RecordCall(subject, "FooMethod", wantArg).Do(
func(arg string) {
doCalled = true
argument = arg
Expand All @@ -515,12 +505,12 @@ func TestDo(t *testing.T) {
t.Error("Do() callback called too early.")
}

ctrl.Call(subject, "FooMethod", "argument")
ctrl.Call(subject, "FooMethod", wantArg)

if !doCalled {
t.Error("Do() callback not called.")
}
if "argument" != argument {
if wantArg != argument {
t.Error("Do callback received wrong argument.")
}

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

doCalled := false
var argument string
ctrl.RecordCall(subject, "FooMethod", "argument").DoAndReturn(
wantArg := "argument"
ctrl.RecordCall(subject, "FooMethod", wantArg).DoAndReturn(
func(arg string) int {
doCalled = true
argument = arg
Expand All @@ -543,12 +534,12 @@ func TestDoAndReturn(t *testing.T) {
t.Error("Do() callback called too early.")
}

rets := ctrl.Call(subject, "FooMethod", "argument")
rets := ctrl.Call(subject, "FooMethod", wantArg)

if !doCalled {
t.Error("Do() callback not called.")
}
if "argument" != argument {
if wantArg != argument {
t.Error("Do callback received wrong argument.")
}
if len(rets) != 1 {
Expand Down

0 comments on commit bb5fd5e

Please sign in to comment.