From 51421b967af1f557f93a59e0057aaf15ca02e29c Mon Sep 17 00:00:00 2001 From: poy Date: Wed, 5 Dec 2018 10:17:00 -0700 Subject: [PATCH] mockgen: use Controller.Helper() in generated mocks Using T.Helper() better directs the callstack to point at the offending line in the production code. fixes #239 --- gomock/internal/mock_matcher/mock_matcher.go | 4 + .../bugreport_mock.go | 2 + .../greeter/greeter_mock_test.go | 2 + mockgen/internal/tests/dot_imports/mock.go | 6 ++ .../bugreport_mock.go | 4 + .../import_source/definition/source_mock.go | 2 + .../tests/import_source/source_mock.go | 2 + .../internal/pkg/reflect_output/mock.go | 2 + .../subdir/internal/pkg/source_output/mock.go | 4 + .../tests/unexported_method/bugreport_mock.go | 2 + mockgen/internal/tests/vendor_dep/mock.go | 2 + .../vendor_dep/source_mock_package/mock.go | 2 + mockgen/internal/tests/vendor_pkg/mock.go | 12 +++ mockgen/mockgen.go | 2 + mockgen/mockgen_test.go | 88 +++++++++++++++++++ sample/concurrent/mock/concurrent_mock.go | 2 + sample/mock_user/mock_user.go | 54 ++++++++++++ 17 files changed, 192 insertions(+) diff --git a/gomock/internal/mock_matcher/mock_matcher.go b/gomock/internal/mock_matcher/mock_matcher.go index 7e4b4c8a..5462f4dd 100644 --- a/gomock/internal/mock_matcher/mock_matcher.go +++ b/gomock/internal/mock_matcher/mock_matcher.go @@ -34,6 +34,7 @@ func (m *MockMatcher) EXPECT() *MockMatcherMockRecorder { // Matches mocks base method func (m *MockMatcher) Matches(arg0 interface{}) bool { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Matches", arg0) ret0, _ := ret[0].(bool) return ret0 @@ -41,11 +42,13 @@ func (m *MockMatcher) Matches(arg0 interface{}) bool { // Matches indicates an expected call of Matches func (mr *MockMatcherMockRecorder) Matches(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Matches", reflect.TypeOf((*MockMatcher)(nil).Matches), arg0) } // String mocks base method func (m *MockMatcher) String() string { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "String") ret0, _ := ret[0].(string) return ret0 @@ -53,5 +56,6 @@ func (m *MockMatcher) String() string { // String indicates an expected call of String func (mr *MockMatcherMockRecorder) String() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "String", reflect.TypeOf((*MockMatcher)(nil).String)) } diff --git a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go index f90c2592..548e7643 100644 --- a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go +++ b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go @@ -35,6 +35,7 @@ func (m *MockSource) EXPECT() *MockSourceMockRecorder { // Method mocks base method func (m *MockSource) Method() faux.Return { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Method") ret0, _ := ret[0].(faux.Return) return ret0 @@ -42,5 +43,6 @@ func (m *MockSource) Method() faux.Return { // Method indicates an expected call of Method func (mr *MockSourceMockRecorder) Method() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Method", reflect.TypeOf((*MockSource)(nil).Method)) } diff --git a/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go b/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go index fe6139b7..0885f3d5 100644 --- a/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go +++ b/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go @@ -35,6 +35,7 @@ func (m *MockInputMaker) EXPECT() *MockInputMakerMockRecorder { // MakeInput mocks base method func (m *MockInputMaker) MakeInput() v1.GreetInput { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "MakeInput") ret0, _ := ret[0].(v1.GreetInput) return ret0 @@ -42,5 +43,6 @@ func (m *MockInputMaker) MakeInput() v1.GreetInput { // MakeInput indicates an expected call of MakeInput func (mr *MockInputMakerMockRecorder) MakeInput() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MakeInput", reflect.TypeOf((*MockInputMaker)(nil).MakeInput)) } diff --git a/mockgen/internal/tests/dot_imports/mock.go b/mockgen/internal/tests/dot_imports/mock.go index bc9982c3..78331623 100644 --- a/mockgen/internal/tests/dot_imports/mock.go +++ b/mockgen/internal/tests/dot_imports/mock.go @@ -37,6 +37,7 @@ func (m *MockWithDotImports) EXPECT() *MockWithDotImportsMockRecorder { // Method1 mocks base method func (m *MockWithDotImports) Method1() Request { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Method1") ret0, _ := ret[0].(Request) return ret0 @@ -44,11 +45,13 @@ func (m *MockWithDotImports) Method1() Request { // Method1 indicates an expected call of Method1 func (mr *MockWithDotImportsMockRecorder) Method1() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Method1", reflect.TypeOf((*MockWithDotImports)(nil).Method1)) } // Method2 mocks base method func (m *MockWithDotImports) Method2() *bytes.Buffer { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Method2") ret0, _ := ret[0].(*bytes.Buffer) return ret0 @@ -56,11 +59,13 @@ func (m *MockWithDotImports) Method2() *bytes.Buffer { // Method2 indicates an expected call of Method2 func (mr *MockWithDotImportsMockRecorder) Method2() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Method2", reflect.TypeOf((*MockWithDotImports)(nil).Method2)) } // Method3 mocks base method func (m *MockWithDotImports) Method3() Context { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Method3") ret0, _ := ret[0].(Context) return ret0 @@ -68,5 +73,6 @@ func (m *MockWithDotImports) Method3() Context { // Method3 indicates an expected call of Method3 func (mr *MockWithDotImportsMockRecorder) Method3() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Method3", reflect.TypeOf((*MockWithDotImports)(nil).Method3)) } diff --git a/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go b/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go index 114f967c..2ed1aeb9 100644 --- a/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go +++ b/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go @@ -34,16 +34,19 @@ func (m *MockExample) EXPECT() *MockExampleMockRecorder { // Method mocks base method func (m_2 *MockExample) Method(_m, _mr, m, mr int) { + m_2.ctrl.T.Helper() m_2.ctrl.Call(m_2, "Method", _m, _mr, m, mr) } // Method indicates an expected call of Method func (mr_2 *MockExampleMockRecorder) Method(_m, _mr, m, mr interface{}) *gomock.Call { + mr_2.mock.ctrl.T.Helper() return mr_2.mock.ctrl.RecordCallWithMethodType(mr_2.mock, "Method", reflect.TypeOf((*MockExample)(nil).Method), _m, _mr, m, mr) } // VarargMethod mocks base method func (m *MockExample) VarargMethod(_s, _x, a, ret int, varargs ...int) { + m.ctrl.T.Helper() varargs_2 := []interface{}{_s, _x, a, ret} for _, a_2 := range varargs { varargs_2 = append(varargs_2, a_2) @@ -53,6 +56,7 @@ func (m *MockExample) VarargMethod(_s, _x, a, ret int, varargs ...int) { // VarargMethod indicates an expected call of VarargMethod func (mr *MockExampleMockRecorder) VarargMethod(_s, _x, a, ret interface{}, varargs ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() varargs_2 := append([]interface{}{_s, _x, a, ret}, varargs...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VarargMethod", reflect.TypeOf((*MockExample)(nil).VarargMethod), varargs_2...) } diff --git a/mockgen/internal/tests/import_source/definition/source_mock.go b/mockgen/internal/tests/import_source/definition/source_mock.go index e8c99966..c808ea6d 100644 --- a/mockgen/internal/tests/import_source/definition/source_mock.go +++ b/mockgen/internal/tests/import_source/definition/source_mock.go @@ -34,10 +34,12 @@ func (m *MockS) EXPECT() *MockSMockRecorder { // F mocks base method func (m *MockS) F(arg0 X) { + m.ctrl.T.Helper() m.ctrl.Call(m, "F", arg0) } // F indicates an expected call of F func (mr *MockSMockRecorder) F(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "F", reflect.TypeOf((*MockS)(nil).F), arg0) } diff --git a/mockgen/internal/tests/import_source/source_mock.go b/mockgen/internal/tests/import_source/source_mock.go index 24649e0b..d7c47692 100644 --- a/mockgen/internal/tests/import_source/source_mock.go +++ b/mockgen/internal/tests/import_source/source_mock.go @@ -35,10 +35,12 @@ func (m *MockS) EXPECT() *MockSMockRecorder { // F mocks base method func (m *MockS) F(arg0 definition.X) { + m.ctrl.T.Helper() m.ctrl.Call(m, "F", arg0) } // F indicates an expected call of F func (mr *MockSMockRecorder) F(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "F", reflect.TypeOf((*MockS)(nil).F), arg0) } diff --git a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go index fb494997..df234bf0 100644 --- a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go +++ b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go @@ -35,6 +35,7 @@ func (m *MockIntf) EXPECT() *MockIntfMockRecorder { // F mocks base method func (m *MockIntf) F() pkg.Arg { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "F") ret0, _ := ret[0].(pkg.Arg) return ret0 @@ -42,5 +43,6 @@ func (m *MockIntf) F() pkg.Arg { // F indicates an expected call of F func (mr *MockIntfMockRecorder) F() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "F", reflect.TypeOf((*MockIntf)(nil).F)) } diff --git a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go index a4bbf855..4ba902f9 100644 --- a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go +++ b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go @@ -35,6 +35,7 @@ func (m *MockArg) EXPECT() *MockArgMockRecorder { // Foo mocks base method func (m *MockArg) Foo() int { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Foo") ret0, _ := ret[0].(int) return ret0 @@ -42,6 +43,7 @@ func (m *MockArg) Foo() int { // Foo indicates an expected call of Foo func (mr *MockArgMockRecorder) Foo() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Foo", reflect.TypeOf((*MockArg)(nil).Foo)) } @@ -70,6 +72,7 @@ func (m *MockIntf) EXPECT() *MockIntfMockRecorder { // F mocks base method func (m *MockIntf) F() pkg.Arg { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "F") ret0, _ := ret[0].(pkg.Arg) return ret0 @@ -77,5 +80,6 @@ func (m *MockIntf) F() pkg.Arg { // F indicates an expected call of F func (mr *MockIntfMockRecorder) F() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "F", reflect.TypeOf((*MockIntf)(nil).F)) } diff --git a/mockgen/internal/tests/unexported_method/bugreport_mock.go b/mockgen/internal/tests/unexported_method/bugreport_mock.go index 8ba218fc..bd65a161 100644 --- a/mockgen/internal/tests/unexported_method/bugreport_mock.go +++ b/mockgen/internal/tests/unexported_method/bugreport_mock.go @@ -34,6 +34,7 @@ func (m *MockExample) EXPECT() *MockExampleMockRecorder { // someMethod mocks base method func (m *MockExample) someMethod(arg0 string) string { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "someMethod", arg0) ret0, _ := ret[0].(string) return ret0 @@ -41,5 +42,6 @@ func (m *MockExample) someMethod(arg0 string) string { // someMethod indicates an expected call of someMethod func (mr *MockExampleMockRecorder) someMethod(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "someMethod", reflect.TypeOf((*MockExample)(nil).someMethod), arg0) } diff --git a/mockgen/internal/tests/vendor_dep/mock.go b/mockgen/internal/tests/vendor_dep/mock.go index d33cba8a..8ff53d06 100644 --- a/mockgen/internal/tests/vendor_dep/mock.go +++ b/mockgen/internal/tests/vendor_dep/mock.go @@ -35,6 +35,7 @@ func (m *MockVendorsDep) EXPECT() *MockVendorsDepMockRecorder { // Foo mocks base method func (m *MockVendorsDep) Foo() a.Ifc { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Foo") ret0, _ := ret[0].(a.Ifc) return ret0 @@ -42,5 +43,6 @@ func (m *MockVendorsDep) Foo() a.Ifc { // Foo indicates an expected call of Foo func (mr *MockVendorsDepMockRecorder) Foo() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Foo", reflect.TypeOf((*MockVendorsDep)(nil).Foo)) } diff --git a/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go b/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go index b4732592..892496fd 100644 --- a/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go +++ b/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go @@ -35,6 +35,7 @@ func (m *MockVendorsDep) EXPECT() *MockVendorsDepMockRecorder { // Foo mocks base method func (m *MockVendorsDep) Foo() a.Ifc { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Foo") ret0, _ := ret[0].(a.Ifc) return ret0 @@ -42,5 +43,6 @@ func (m *MockVendorsDep) Foo() a.Ifc { // Foo indicates an expected call of Foo func (mr *MockVendorsDepMockRecorder) Foo() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Foo", reflect.TypeOf((*MockVendorsDep)(nil).Foo)) } diff --git a/mockgen/internal/tests/vendor_pkg/mock.go b/mockgen/internal/tests/vendor_pkg/mock.go index e5e78e51..1f4bdb82 100644 --- a/mockgen/internal/tests/vendor_pkg/mock.go +++ b/mockgen/internal/tests/vendor_pkg/mock.go @@ -34,6 +34,7 @@ func (m *MockIfc) EXPECT() *MockIfcMockRecorder { // A mocks base method func (m *MockIfc) A(arg0 string) string { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "A", arg0) ret0, _ := ret[0].(string) return ret0 @@ -41,11 +42,13 @@ func (m *MockIfc) A(arg0 string) string { // A indicates an expected call of A func (mr *MockIfcMockRecorder) A(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "A", reflect.TypeOf((*MockIfc)(nil).A), arg0) } // B mocks base method func (m *MockIfc) B(arg0 int) int { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "B", arg0) ret0, _ := ret[0].(int) return ret0 @@ -53,11 +56,13 @@ func (m *MockIfc) B(arg0 int) int { // B indicates an expected call of B func (mr *MockIfcMockRecorder) B(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "B", reflect.TypeOf((*MockIfc)(nil).B), arg0) } // C mocks base method func (m *MockIfc) C(arg0 chan int) chan int { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "C", arg0) ret0, _ := ret[0].(chan int) return ret0 @@ -65,35 +70,42 @@ func (m *MockIfc) C(arg0 chan int) chan int { // C indicates an expected call of C func (mr *MockIfcMockRecorder) C(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "C", reflect.TypeOf((*MockIfc)(nil).C), arg0) } // D mocks base method func (m *MockIfc) D(arg0 interface{}) { + m.ctrl.T.Helper() m.ctrl.Call(m, "D", arg0) } // D indicates an expected call of D func (mr *MockIfcMockRecorder) D(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "D", reflect.TypeOf((*MockIfc)(nil).D), arg0) } // E mocks base method func (m *MockIfc) E(arg0 map[string]interface{}) { + m.ctrl.T.Helper() m.ctrl.Call(m, "E", arg0) } // E indicates an expected call of E func (mr *MockIfcMockRecorder) E(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "E", reflect.TypeOf((*MockIfc)(nil).E), arg0) } // F mocks base method func (m *MockIfc) F(arg0 []float64) { + m.ctrl.T.Helper() m.ctrl.Call(m, "F", arg0) } // F indicates an expected call of F func (mr *MockIfcMockRecorder) F(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "F", reflect.TypeOf((*MockIfc)(nil).F), arg0) } diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index cd887a82..3a169487 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -407,6 +407,7 @@ func (g *generator) GenerateMockMethod(mockType string, m *model.Method, pkgOver g.p("// %v mocks base method", m.Name) g.p("func (%v *%v) %v(%v)%v {", idRecv, mockType, m.Name, argString, retString) g.in() + g.p("%s.ctrl.T.Helper()", idRecv) var callArgs string if m.Variadic == nil { @@ -474,6 +475,7 @@ func (g *generator) GenerateMockRecorderMethod(mockType string, m *model.Method) g.p("// %v indicates an expected call of %v", m.Name, m.Name) g.p("func (%s *%vMockRecorder) %v(%v) *gomock.Call {", idRecv, mockType, m.Name, argString) g.in() + g.p("%s.mock.ctrl.T.Helper()", idRecv) var callArgs string if m.Variadic == nil { diff --git a/mockgen/mockgen_test.go b/mockgen/mockgen_test.go index bcb2a97f..573cc2b4 100644 --- a/mockgen/mockgen_test.go +++ b/mockgen/mockgen_test.go @@ -2,7 +2,11 @@ package main import ( "fmt" + "regexp" + "strings" "testing" + + "github.com/golang/mock/mockgen/model" ) func TestMakeArgString(t *testing.T) { @@ -179,3 +183,87 @@ func TestIdentifierAllocator_allocateIdentifier(t *testing.T) { t.Fatalf("allocator doesn't contain the expected items - allocator: %#v, expected items: %#v", a, expected) } } + +func TestGenerateMockInterface_Helper(t *testing.T) { + for _, test := range []struct { + Name string + Identifier string + HelperLine string + Methods []*model.Method + }{ + {Name: "mock", Identifier: "MockSomename", HelperLine: "m.ctrl.T.Helper()"}, + {Name: "recorder", Identifier: "MockSomenameMockRecorder", HelperLine: "mr.mock.ctrl.T.Helper()"}, + { + Name: "mock identifier conflict", + Identifier: "MockSomename", + HelperLine: "m_2.ctrl.T.Helper()", + Methods: []*model.Method{ + { + Name: "MethodA", + In: []*model.Parameter{ + { + Name: "m", + Type: &model.NamedType{Type: "int"}, + }, + }, + }, + }, + }, + { + Name: "recorder identifier conflict", + Identifier: "MockSomenameMockRecorder", + HelperLine: "mr_2.mock.ctrl.T.Helper()", + Methods: []*model.Method{ + { + Name: "MethodA", + In: []*model.Parameter{ + { + Name: "mr", + Type: &model.NamedType{Type: "int"}, + }, + }, + }, + }, + }, + } { + t.Run(test.Name, func(t *testing.T) { + g := generator{} + + if len(test.Methods) == 0 { + test.Methods = []*model.Method{ + {Name: "MethodA"}, + {Name: "MethodB"}, + } + } + + if err := g.GenerateMockInterface(&model.Interface{ + Name: "Somename", + Methods: test.Methods, + }, "somepackage"); err != nil { + t.Fatal(err) + } + + lines := strings.Split(g.buf.String(), "\n") + + // T.Helper() should be the first line + for _, method := range test.Methods { + if strings.TrimSpace(lines[findMethod(t, test.Identifier, method.Name, lines)+1]) != test.HelperLine { + t.Fatalf("method %s.%s did not declare itself a Helper method", test.Identifier, method.Name) + } + } + }) + } +} + +func findMethod(t *testing.T, identifier, methodName string, lines []string) int { + t.Helper() + r := regexp.MustCompile(fmt.Sprintf(`func\s+\(.+%s\)\s*%s`, identifier, methodName)) + for i, line := range lines { + if r.MatchString(line) { + return i + } + } + + t.Fatalf("unable to find 'func (m %s) %s'", identifier, methodName) + panic("unreachable") +} diff --git a/sample/concurrent/mock/concurrent_mock.go b/sample/concurrent/mock/concurrent_mock.go index 92005631..57b079df 100644 --- a/sample/concurrent/mock/concurrent_mock.go +++ b/sample/concurrent/mock/concurrent_mock.go @@ -34,6 +34,7 @@ func (m *MockMath) EXPECT() *MockMathMockRecorder { // Sum mocks base method func (m *MockMath) Sum(arg0, arg1 int) int { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Sum", arg0, arg1) ret0, _ := ret[0].(int) return ret0 @@ -41,5 +42,6 @@ func (m *MockMath) Sum(arg0, arg1 int) int { // Sum indicates an expected call of Sum func (mr *MockMathMockRecorder) Sum(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sum", reflect.TypeOf((*MockMath)(nil).Sum), arg0, arg1) } diff --git a/sample/mock_user/mock_user.go b/sample/mock_user/mock_user.go index 13b74b32..4cf24bb7 100644 --- a/sample/mock_user/mock_user.go +++ b/sample/mock_user/mock_user.go @@ -45,26 +45,31 @@ func (m *MockIndex) EXPECT() *MockIndexMockRecorder { // Anon mocks base method func (m *MockIndex) Anon(arg0 string) { + m.ctrl.T.Helper() m.ctrl.Call(m, "Anon", arg0) } // Anon indicates an expected call of Anon func (mr *MockIndexMockRecorder) Anon(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Anon", reflect.TypeOf((*MockIndex)(nil).Anon), arg0) } // Chan mocks base method func (m *MockIndex) Chan(arg0 chan int, arg1 chan<- hash.Hash) { + m.ctrl.T.Helper() m.ctrl.Call(m, "Chan", arg0, arg1) } // Chan indicates an expected call of Chan func (mr *MockIndexMockRecorder) Chan(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Chan", reflect.TypeOf((*MockIndex)(nil).Chan), arg0, arg1) } // ConcreteRet mocks base method func (m *MockIndex) ConcreteRet() chan<- bool { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ConcreteRet") ret0, _ := ret[0].(chan<- bool) return ret0 @@ -72,11 +77,13 @@ func (m *MockIndex) ConcreteRet() chan<- bool { // ConcreteRet indicates an expected call of ConcreteRet func (mr *MockIndexMockRecorder) ConcreteRet() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConcreteRet", reflect.TypeOf((*MockIndex)(nil).ConcreteRet)) } // Ellip mocks base method func (m *MockIndex) Ellip(arg0 string, arg1 ...interface{}) { + m.ctrl.T.Helper() varargs := []interface{}{arg0} for _, a := range arg1 { varargs = append(varargs, a) @@ -86,12 +93,14 @@ func (m *MockIndex) Ellip(arg0 string, arg1 ...interface{}) { // Ellip indicates an expected call of Ellip func (mr *MockIndexMockRecorder) Ellip(arg0 interface{}, arg1 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() varargs := append([]interface{}{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ellip", reflect.TypeOf((*MockIndex)(nil).Ellip), varargs...) } // EllipOnly mocks base method func (m *MockIndex) EllipOnly(arg0 ...string) { + m.ctrl.T.Helper() varargs := []interface{}{} for _, a := range arg0 { varargs = append(varargs, a) @@ -101,61 +110,73 @@ func (m *MockIndex) EllipOnly(arg0 ...string) { // EllipOnly indicates an expected call of EllipOnly func (mr *MockIndexMockRecorder) EllipOnly(arg0 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EllipOnly", reflect.TypeOf((*MockIndex)(nil).EllipOnly), arg0...) } // ForeignFour mocks base method func (m *MockIndex) ForeignFour(arg0 imp4.Imp4) { + m.ctrl.T.Helper() m.ctrl.Call(m, "ForeignFour", arg0) } // ForeignFour indicates an expected call of ForeignFour func (mr *MockIndexMockRecorder) ForeignFour(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ForeignFour", reflect.TypeOf((*MockIndex)(nil).ForeignFour), arg0) } // ForeignOne mocks base method func (m *MockIndex) ForeignOne(arg0 imp1.Imp1) { + m.ctrl.T.Helper() m.ctrl.Call(m, "ForeignOne", arg0) } // ForeignOne indicates an expected call of ForeignOne func (mr *MockIndexMockRecorder) ForeignOne(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ForeignOne", reflect.TypeOf((*MockIndex)(nil).ForeignOne), arg0) } // ForeignThree mocks base method func (m *MockIndex) ForeignThree(arg0 imp3.Imp3) { + m.ctrl.T.Helper() m.ctrl.Call(m, "ForeignThree", arg0) } // ForeignThree indicates an expected call of ForeignThree func (mr *MockIndexMockRecorder) ForeignThree(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ForeignThree", reflect.TypeOf((*MockIndex)(nil).ForeignThree), arg0) } // ForeignTwo mocks base method func (m *MockIndex) ForeignTwo(arg0 imp2.Imp2) { + m.ctrl.T.Helper() m.ctrl.Call(m, "ForeignTwo", arg0) } // ForeignTwo indicates an expected call of ForeignTwo func (mr *MockIndexMockRecorder) ForeignTwo(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ForeignTwo", reflect.TypeOf((*MockIndex)(nil).ForeignTwo), arg0) } // Func mocks base method func (m *MockIndex) Func(arg0 func(http.Request) (int, bool)) { + m.ctrl.T.Helper() m.ctrl.Call(m, "Func", arg0) } // Func indicates an expected call of Func func (mr *MockIndexMockRecorder) Func(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Func", reflect.TypeOf((*MockIndex)(nil).Func), arg0) } // Get mocks base method func (m *MockIndex) Get(arg0 string) interface{} { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", arg0) ret0, _ := ret[0].(interface{}) return ret0 @@ -163,11 +184,13 @@ func (m *MockIndex) Get(arg0 string) interface{} { // Get indicates an expected call of Get func (mr *MockIndexMockRecorder) Get(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockIndex)(nil).Get), arg0) } // GetTwo mocks base method func (m *MockIndex) GetTwo(arg0, arg1 string) (interface{}, interface{}) { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetTwo", arg0, arg1) ret0, _ := ret[0].(interface{}) ret1, _ := ret[1].(interface{}) @@ -176,21 +199,25 @@ func (m *MockIndex) GetTwo(arg0, arg1 string) (interface{}, interface{}) { // GetTwo indicates an expected call of GetTwo func (mr *MockIndexMockRecorder) GetTwo(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTwo", reflect.TypeOf((*MockIndex)(nil).GetTwo), arg0, arg1) } // Map mocks base method func (m *MockIndex) Map(arg0 map[int]hash.Hash) { + m.ctrl.T.Helper() m.ctrl.Call(m, "Map", arg0) } // Map indicates an expected call of Map func (mr *MockIndexMockRecorder) Map(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Map", reflect.TypeOf((*MockIndex)(nil).Map), arg0) } // NillableRet mocks base method func (m *MockIndex) NillableRet() error { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "NillableRet") ret0, _ := ret[0].(error) return ret0 @@ -198,11 +225,13 @@ func (m *MockIndex) NillableRet() error { // NillableRet indicates an expected call of NillableRet func (mr *MockIndexMockRecorder) NillableRet() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NillableRet", reflect.TypeOf((*MockIndex)(nil).NillableRet)) } // Other mocks base method func (m *MockIndex) Other() hash.Hash { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Other") ret0, _ := ret[0].(hash.Hash) return ret0 @@ -210,31 +239,37 @@ func (m *MockIndex) Other() hash.Hash { // Other indicates an expected call of Other func (mr *MockIndexMockRecorder) Other() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Other", reflect.TypeOf((*MockIndex)(nil).Other)) } // Ptr mocks base method func (m *MockIndex) Ptr(arg0 *int) { + m.ctrl.T.Helper() m.ctrl.Call(m, "Ptr", arg0) } // Ptr indicates an expected call of Ptr func (mr *MockIndexMockRecorder) Ptr(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ptr", reflect.TypeOf((*MockIndex)(nil).Ptr), arg0) } // Put mocks base method func (m *MockIndex) Put(arg0 string, arg1 interface{}) { + m.ctrl.T.Helper() m.ctrl.Call(m, "Put", arg0, arg1) } // Put indicates an expected call of Put func (mr *MockIndexMockRecorder) Put(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Put", reflect.TypeOf((*MockIndex)(nil).Put), arg0, arg1) } // Slice mocks base method func (m *MockIndex) Slice(arg0 []int, arg1 []byte) [3]int { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Slice", arg0, arg1) ret0, _ := ret[0].([3]int) return ret0 @@ -242,46 +277,55 @@ func (m *MockIndex) Slice(arg0 []int, arg1 []byte) [3]int { // Slice indicates an expected call of Slice func (mr *MockIndexMockRecorder) Slice(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Slice", reflect.TypeOf((*MockIndex)(nil).Slice), arg0, arg1) } // Struct mocks base method func (m *MockIndex) Struct(arg0 struct{}) { + m.ctrl.T.Helper() m.ctrl.Call(m, "Struct", arg0) } // Struct indicates an expected call of Struct func (mr *MockIndexMockRecorder) Struct(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Struct", reflect.TypeOf((*MockIndex)(nil).Struct), arg0) } // StructChan mocks base method func (m *MockIndex) StructChan(arg0 chan struct{}) { + m.ctrl.T.Helper() m.ctrl.Call(m, "StructChan", arg0) } // StructChan indicates an expected call of StructChan func (mr *MockIndexMockRecorder) StructChan(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StructChan", reflect.TypeOf((*MockIndex)(nil).StructChan), arg0) } // Summary mocks base method func (m *MockIndex) Summary(arg0 *bytes.Buffer, arg1 io.Writer) { + m.ctrl.T.Helper() m.ctrl.Call(m, "Summary", arg0, arg1) } // Summary indicates an expected call of Summary func (mr *MockIndexMockRecorder) Summary(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Summary", reflect.TypeOf((*MockIndex)(nil).Summary), arg0, arg1) } // Templates mocks base method func (m *MockIndex) Templates(arg0 template.CSS, arg1 template0.FuncMap) { + m.ctrl.T.Helper() m.ctrl.Call(m, "Templates", arg0, arg1) } // Templates indicates an expected call of Templates func (mr *MockIndexMockRecorder) Templates(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Templates", reflect.TypeOf((*MockIndex)(nil).Templates), arg0, arg1) } @@ -310,16 +354,19 @@ func (m *MockEmbed) EXPECT() *MockEmbedMockRecorder { // EmbeddedMethod mocks base method func (m *MockEmbed) EmbeddedMethod() { + m.ctrl.T.Helper() m.ctrl.Call(m, "EmbeddedMethod") } // EmbeddedMethod indicates an expected call of EmbeddedMethod func (mr *MockEmbedMockRecorder) EmbeddedMethod() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmbeddedMethod", reflect.TypeOf((*MockEmbed)(nil).EmbeddedMethod)) } // ForeignEmbeddedMethod mocks base method func (m *MockEmbed) ForeignEmbeddedMethod() *bufio.Reader { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ForeignEmbeddedMethod") ret0, _ := ret[0].(*bufio.Reader) return ret0 @@ -327,26 +374,31 @@ func (m *MockEmbed) ForeignEmbeddedMethod() *bufio.Reader { // ForeignEmbeddedMethod indicates an expected call of ForeignEmbeddedMethod func (mr *MockEmbedMockRecorder) ForeignEmbeddedMethod() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ForeignEmbeddedMethod", reflect.TypeOf((*MockEmbed)(nil).ForeignEmbeddedMethod)) } // ImplicitPackage mocks base method func (m *MockEmbed) ImplicitPackage(arg0 string, arg1 imp1.ImpT, arg2 []imp1.ImpT, arg3 *imp1.ImpT, arg4 chan imp1.ImpT) { + m.ctrl.T.Helper() m.ctrl.Call(m, "ImplicitPackage", arg0, arg1, arg2, arg3, arg4) } // ImplicitPackage indicates an expected call of ImplicitPackage func (mr *MockEmbedMockRecorder) ImplicitPackage(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImplicitPackage", reflect.TypeOf((*MockEmbed)(nil).ImplicitPackage), arg0, arg1, arg2, arg3, arg4) } // RegularMethod mocks base method func (m *MockEmbed) RegularMethod() { + m.ctrl.T.Helper() m.ctrl.Call(m, "RegularMethod") } // RegularMethod indicates an expected call of RegularMethod func (mr *MockEmbedMockRecorder) RegularMethod() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegularMethod", reflect.TypeOf((*MockEmbed)(nil).RegularMethod)) } @@ -375,10 +427,12 @@ func (m *MockEmbedded) EXPECT() *MockEmbeddedMockRecorder { // EmbeddedMethod mocks base method func (m *MockEmbedded) EmbeddedMethod() { + m.ctrl.T.Helper() m.ctrl.Call(m, "EmbeddedMethod") } // EmbeddedMethod indicates an expected call of EmbeddedMethod func (mr *MockEmbeddedMockRecorder) EmbeddedMethod() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EmbeddedMethod", reflect.TypeOf((*MockEmbedded)(nil).EmbeddedMethod)) }