From 5440b1833c530c29820001edb90f9d204ae67031 Mon Sep 17 00:00:00 2001 From: Dave Wyatt Date: Fri, 3 Feb 2023 20:48:51 -0500 Subject: [PATCH 1/5] Implement proposed changes to generator --- README.md | 60 +- mocks/pkg/fixtures/A.go | 23 +- mocks/pkg/fixtures/AsyncProducer.go | 3 + mocks/pkg/fixtures/Blank.go | 1 + mocks/pkg/fixtures/ConsulLock.go | 26 +- mocks/pkg/fixtures/EmbeddedGet.go | 1 + mocks/pkg/fixtures/Example.go | 2 + mocks/pkg/fixtures/Expecter.go | 53 +- mocks/pkg/fixtures/Fooer.go | 2 + mocks/pkg/fixtures/FuncArgsCollision.go | 1 + mocks/pkg/fixtures/GetGeneric.go | 1 + mocks/pkg/fixtures/GetInt.go | 1 + .../fixtures/HasConflictingNestedImports.go | 24 +- mocks/pkg/fixtures/ImportsSameAsPackage.go | 2 + mocks/pkg/fixtures/KeyManager.go | 27 +- mocks/pkg/fixtures/MapFunc.go | 1 + mocks/pkg/fixtures/MyReader.go | 23 +- mocks/pkg/fixtures/Requester.go | 23 +- mocks/pkg/fixtures/Requester2.go | 1 + mocks/pkg/fixtures/Requester3.go | 1 + .../pkg/fixtures/RequesterArgSameAsImport.go | 1 + .../fixtures/RequesterArgSameAsNamedImport.go | 1 + mocks/pkg/fixtures/RequesterArray.go | 25 +- mocks/pkg/fixtures/RequesterElided.go | 1 + mocks/pkg/fixtures/RequesterGenerics.go | 25 +- mocks/pkg/fixtures/RequesterIface.go | 1 + mocks/pkg/fixtures/RequesterNS.go | 23 +- mocks/pkg/fixtures/RequesterPtr.go | 25 +- mocks/pkg/fixtures/RequesterReturnElided.go | 80 ++- mocks/pkg/fixtures/RequesterSlice.go | 25 +- mocks/pkg/fixtures/RequesterVariadic.go | 4 + .../fixtures/RequesterVariadicOneArgument.go | 4 + mocks/pkg/fixtures/SendFunc.go | 23 +- .../comment/IfaceWithBuildTagInComment.go | 1 + .../filename/IfaceWithBuildTagInFilename.go | 1 + mocks/pkg/fixtures/example_project/Root.go | 25 +- .../example_project/bar/foo/Client.go | 25 +- mocks/pkg/fixtures/example_project/foo/Foo.go | 26 +- .../foo/PackageNameSameAsImport.go | 1 + pkg/generator.go | 48 +- pkg/generator_test.go | 515 ++++++++++++------ 41 files changed, 764 insertions(+), 392 deletions(-) diff --git a/README.md b/README.md index ab33ea5c..2cb2d618 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ func (m *Stringer) String() string { ret := m.Called() var r0 string + if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() } else { @@ -190,17 +191,22 @@ func (_m *SendFunc) Execute(data string) (int, error) { ret := _m.Called(data) var r0 int - if rf, ok := ret.Get(0).(func(string) int); ok { - r0 = rf(data) - } else { - r0 = ret.Get(0).(int) - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(data) + + if rf, ok := ret.Get(0).(func(string) (int, error); ok { + r0, r1 = rf(data) } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func(string) int); ok { + r0 = rf(data) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(data) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -237,21 +243,19 @@ import ( func main() { mockS3 := &mocks.S3API{} - mockResultFn := func(input *s3.ListObjectsInput) *s3.ListObjectsOutput { + mockResultFn := func(input *s3.ListObjectsInput) (*s3.ListObjectsOutput, error) { output := &s3.ListObjectsOutput{} output.SetCommonPrefixes([]*s3.CommonPrefix{ &s3.CommonPrefix{ Prefix: aws.String("2017-01-01"), }, }) - return output + return output, nil } - // NB: .Return(...) must return the same signature as the method being mocked. - // In this case it's (*s3.ListObjectsOutput, error). mockS3.On("ListObjects", mock.MatchedBy(func(input *s3.ListObjectsInput) bool { return input.Delimiter != nil && *input.Delimiter == "/" && input.Prefix == nil - })).Return(mockResultFn, nil) + })).Return(mockResultFn) listingInput := &s3.ListObjectsInput{ Bucket: aws.String("foo"), @@ -302,7 +306,7 @@ proxyMock.On("passthrough", mock.AnythingOfType("context.Context"), mock.Anythin #### Requirements -`Return` must be passed the same argument count and types as expected by the interface. Then, for each of the return values of the mocked function, `Return` needs a function which takes the same arguments as the mocked function, and returns one of the return values. For example, if the return argument signature of `passthrough` in the above example was instead `(string, error)` in the interface, `Return` would also need a second function argument to define the error value: +Return Value Providers can be used one of two ways. You may either define a single function with the exact same signature (number and type of input and return parameters) and pass that as a single value to `Return`, or you may pass multiple values to `Return` (one for each return parameter of the mocked function.) If you are using the second form, for each of the return values of the mocked function, `Return` needs a function which takes the same arguments as the mocked function, and returns one of the return values. For example, if the return argument signature of `passthrough` in the above example was instead `(string, error)` in the interface, `Return` would also need a second function argument to define the error value: ```go type Proxy interface { @@ -310,6 +314,21 @@ type Proxy interface { } ``` +First form: + +```go +proxyMock := mocks.NewProxy(t) +proxyMock.On("passthrough", mock.AnythingOfType("context.Context"), mock.AnythingOfType("string")). + Return( + func(ctx context.Context, s string) (string, error) { + return s, nil + } + ) +``` + + +Second form: + ```go proxyMock := mocks.NewProxy(t) proxyMock.On("passthrough", mock.AnythingOfType("context.Context"), mock.AnythingOfType("string")). @@ -323,16 +342,7 @@ proxyMock.On("passthrough", mock.AnythingOfType("context.Context"), mock.Anythin ) ``` -Note that the following is incorrect (you can't return all the return values with one function): -```go -proxyMock := mocks.NewProxy(t) -proxyMock.On("passthrough", mock.AnythingOfType("context.Context"), mock.AnythingOfType("string")). - Return(func(ctx context.Context, s string) (string, error) { - return s, nil - }) -``` - -If any return argument is missing, `github.com/stretchr/testify/mock.Arguments.Get` will emit a panic. +If using the second form and any return argument is missing, `github.com/stretchr/testify/mock.Arguments.Get` will emit a panic. For example, `panic: assert: arguments: Cannot call Get(0) because there are 0 argument(s). [recovered]` indicates that `Return` was not provided any arguments but (at least one) was expected based on the interface. `Get(1)` would indicate that the `Return` call is missing a second argument, and so on. diff --git a/mocks/pkg/fixtures/A.go b/mocks/pkg/fixtures/A.go index 4d8a4419..ab30ee2f 100644 --- a/mocks/pkg/fixtures/A.go +++ b/mocks/pkg/fixtures/A.go @@ -17,17 +17,22 @@ func (_m *A) Call() (test.B, error) { ret := _m.Called() var r0 test.B - if rf, ok := ret.Get(0).(func() test.B); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(test.B) - } - var r1 error - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() + + if rf, ok := ret.Get(0).(func() (test.B, error)); ok { + r0, r1 = rf() } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func() test.B); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(test.B) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } } return r0, r1 diff --git a/mocks/pkg/fixtures/AsyncProducer.go b/mocks/pkg/fixtures/AsyncProducer.go index b8cc9453..3c9d87d3 100644 --- a/mocks/pkg/fixtures/AsyncProducer.go +++ b/mocks/pkg/fixtures/AsyncProducer.go @@ -14,6 +14,7 @@ func (_m *AsyncProducer) Input() chan<- bool { ret := _m.Called() var r0 chan<- bool + if rf, ok := ret.Get(0).(func() chan<- bool); ok { r0 = rf() } else { @@ -30,6 +31,7 @@ func (_m *AsyncProducer) Output() <-chan bool { ret := _m.Called() var r0 <-chan bool + if rf, ok := ret.Get(0).(func() <-chan bool); ok { r0 = rf() } else { @@ -46,6 +48,7 @@ func (_m *AsyncProducer) Whatever() chan bool { ret := _m.Called() var r0 chan bool + if rf, ok := ret.Get(0).(func() chan bool); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/Blank.go b/mocks/pkg/fixtures/Blank.go index ed681cc8..2d5f097b 100644 --- a/mocks/pkg/fixtures/Blank.go +++ b/mocks/pkg/fixtures/Blank.go @@ -14,6 +14,7 @@ func (_m *Blank) Create(x interface{}) error { ret := _m.Called(x) var r0 error + if rf, ok := ret.Get(0).(func(interface{}) error); ok { r0 = rf(x) } else { diff --git a/mocks/pkg/fixtures/ConsulLock.go b/mocks/pkg/fixtures/ConsulLock.go index d5b8d27f..f19baba4 100644 --- a/mocks/pkg/fixtures/ConsulLock.go +++ b/mocks/pkg/fixtures/ConsulLock.go @@ -14,19 +14,24 @@ func (_m *ConsulLock) Lock(_a0 <-chan struct{}) (<-chan struct{}, error) { ret := _m.Called(_a0) var r0 <-chan struct{} - if rf, ok := ret.Get(0).(func(<-chan struct{}) <-chan struct{}); ok { - r0 = rf(_a0) + var r1 error + + if rf, ok := ret.Get(0).(func(<-chan struct{}) (<-chan struct{}, error)); ok { + r0, r1 = rf(_a0) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(<-chan struct{}) + if rf, ok := ret.Get(0).(func(<-chan struct{}) <-chan struct{}); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(<-chan struct{}) + } } - } - var r1 error - if rf, ok := ret.Get(1).(func(<-chan struct{}) error); ok { - r1 = rf(_a0) - } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(1).(func(<-chan struct{}) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -37,6 +42,7 @@ func (_m *ConsulLock) Unlock() error { ret := _m.Called() var r0 error + if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/EmbeddedGet.go b/mocks/pkg/fixtures/EmbeddedGet.go index dfef71f8..0dce0689 100644 --- a/mocks/pkg/fixtures/EmbeddedGet.go +++ b/mocks/pkg/fixtures/EmbeddedGet.go @@ -17,6 +17,7 @@ func (_m *EmbeddedGet[T]) Get() T { ret := _m.Called() var r0 T + if rf, ok := ret.Get(0).(func() T); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/Example.go b/mocks/pkg/fixtures/Example.go index db089172..51d18afa 100644 --- a/mocks/pkg/fixtures/Example.go +++ b/mocks/pkg/fixtures/Example.go @@ -20,6 +20,7 @@ func (_m *Example) A() http.Flusher { ret := _m.Called() var r0 http.Flusher + if rf, ok := ret.Get(0).(func() http.Flusher); ok { r0 = rf() } else { @@ -36,6 +37,7 @@ func (_m *Example) B(_a0 string) fixtureshttp.MyStruct { ret := _m.Called(_a0) var r0 fixtureshttp.MyStruct + if rf, ok := ret.Get(0).(func(string) fixtureshttp.MyStruct); ok { r0 = rf(_a0) } else { diff --git a/mocks/pkg/fixtures/Expecter.go b/mocks/pkg/fixtures/Expecter.go index 6d7ce5ee..c65fcf6c 100644 --- a/mocks/pkg/fixtures/Expecter.go +++ b/mocks/pkg/fixtures/Expecter.go @@ -22,19 +22,24 @@ func (_m *Expecter) ManyArgsReturns(str string, i int) ([]string, error) { ret := _m.Called(str, i) var r0 []string - if rf, ok := ret.Get(0).(func(string, int) []string); ok { - r0 = rf(str, i) + var r1 error + + if rf, ok := ret.Get(0).(func(string, int) ([]string, error)); ok { + r0, r1 = rf(str, i) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) + if rf, ok := ret.Get(0).(func(string, int) []string); ok { + r0 = rf(str, i) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } } - } - var r1 error - if rf, ok := ret.Get(1).(func(string, int) error); ok { - r1 = rf(str, i) - } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(1).(func(string, int) error); ok { + r1 = rf(str, i) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -64,11 +69,17 @@ func (_c *Expecter_ManyArgsReturns_Call) Return(strs []string, err error) *Expec return _c } +func (_c *Expecter_ManyArgsReturns_Call) RunAndReturn(run func(string, int) ([]string, error)) *Expecter_ManyArgsReturns_Call { + _c.Call.Return(run) + return _c +} + // NoArg provides a mock function with given fields: func (_m *Expecter) NoArg() string { ret := _m.Called() var r0 string + if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() } else { @@ -100,6 +111,11 @@ func (_c *Expecter_NoArg_Call) Return(_a0 string) *Expecter_NoArg_Call { return _c } +func (_c *Expecter_NoArg_Call) RunAndReturn(run func() string) *Expecter_NoArg_Call { + _c.Call.Return(run) + return _c +} + // NoReturn provides a mock function with given fields: str func (_m *Expecter) NoReturn(str string) { _m.Called(str) @@ -128,6 +144,11 @@ func (_c *Expecter_NoReturn_Call) Return() *Expecter_NoReturn_Call { return _c } +func (_c *Expecter_NoReturn_Call) RunAndReturn(run func(string)) *Expecter_NoReturn_Call { + _c.Call.Return(run) + return _c +} + // Variadic provides a mock function with given fields: ints func (_m *Expecter) Variadic(ints ...int) error { _va := make([]interface{}, len(ints)) @@ -139,6 +160,7 @@ func (_m *Expecter) Variadic(ints ...int) error { ret := _m.Called(_ca...) var r0 error + if rf, ok := ret.Get(0).(func(...int) error); ok { r0 = rf(ints...) } else { @@ -178,6 +200,11 @@ func (_c *Expecter_Variadic_Call) Return(_a0 error) *Expecter_Variadic_Call { return _c } +func (_c *Expecter_Variadic_Call) RunAndReturn(run func(...int) error) *Expecter_Variadic_Call { + _c.Call.Return(run) + return _c +} + // VariadicMany provides a mock function with given fields: i, a, intfs func (_m *Expecter) VariadicMany(i int, a string, intfs ...interface{}) error { var _ca []interface{} @@ -186,6 +213,7 @@ func (_m *Expecter) VariadicMany(i int, a string, intfs ...interface{}) error { ret := _m.Called(_ca...) var r0 error + if rf, ok := ret.Get(0).(func(int, string, ...interface{}) error); ok { r0 = rf(i, a, intfs...) } else { @@ -227,6 +255,11 @@ func (_c *Expecter_VariadicMany_Call) Return(_a0 error) *Expecter_VariadicMany_C return _c } +func (_c *Expecter_VariadicMany_Call) RunAndReturn(run func(int, string, ...interface{}) error) *Expecter_VariadicMany_Call { + _c.Call.Return(run) + return _c +} + type mockConstructorTestingTNewExpecter interface { mock.TestingT Cleanup(func()) diff --git a/mocks/pkg/fixtures/Fooer.go b/mocks/pkg/fixtures/Fooer.go index 1eb1eeff..ec06181a 100644 --- a/mocks/pkg/fixtures/Fooer.go +++ b/mocks/pkg/fixtures/Fooer.go @@ -19,6 +19,7 @@ func (_m *Fooer) Baz(path string) func(string) string { ret := _m.Called(path) var r0 func(string) string + if rf, ok := ret.Get(0).(func(string) func(string) string); ok { r0 = rf(path) } else { @@ -35,6 +36,7 @@ func (_m *Fooer) Foo(f func(string) string) error { ret := _m.Called(f) var r0 error + if rf, ok := ret.Get(0).(func(func(string) string) error); ok { r0 = rf(f) } else { diff --git a/mocks/pkg/fixtures/FuncArgsCollision.go b/mocks/pkg/fixtures/FuncArgsCollision.go index 6ecbf5c2..905e23bf 100644 --- a/mocks/pkg/fixtures/FuncArgsCollision.go +++ b/mocks/pkg/fixtures/FuncArgsCollision.go @@ -14,6 +14,7 @@ func (_m *FuncArgsCollision) Foo(ret interface{}) error { ret_1 := _m.Called(ret) var r0 error + if rf, ok := ret_1.Get(0).(func(interface{}) error); ok { r0 = rf(ret) } else { diff --git a/mocks/pkg/fixtures/GetGeneric.go b/mocks/pkg/fixtures/GetGeneric.go index 9b8079f4..81789778 100644 --- a/mocks/pkg/fixtures/GetGeneric.go +++ b/mocks/pkg/fixtures/GetGeneric.go @@ -17,6 +17,7 @@ func (_m *GetGeneric[T]) Get() T { ret := _m.Called() var r0 T + if rf, ok := ret.Get(0).(func() T); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/GetInt.go b/mocks/pkg/fixtures/GetInt.go index 545a5997..41dbc475 100644 --- a/mocks/pkg/fixtures/GetInt.go +++ b/mocks/pkg/fixtures/GetInt.go @@ -14,6 +14,7 @@ func (_m *GetInt) Get() int { ret := _m.Called() var r0 int + if rf, ok := ret.Get(0).(func() int); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/HasConflictingNestedImports.go b/mocks/pkg/fixtures/HasConflictingNestedImports.go index 985d6ff7..dd523ef4 100644 --- a/mocks/pkg/fixtures/HasConflictingNestedImports.go +++ b/mocks/pkg/fixtures/HasConflictingNestedImports.go @@ -20,17 +20,22 @@ func (_m *HasConflictingNestedImports) Get(path string) (http.Response, error) { ret := _m.Called(path) var r0 http.Response - if rf, ok := ret.Get(0).(func(string) http.Response); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(http.Response) - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) + + if rf, ok := ret.Get(0).(func(string) (http.Response, error)); ok { + r0, r1 = rf(path) } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func(string) http.Response); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(http.Response) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -41,6 +46,7 @@ func (_m *HasConflictingNestedImports) Z() fixtureshttp.MyStruct { ret := _m.Called() var r0 fixtureshttp.MyStruct + if rf, ok := ret.Get(0).(func() fixtureshttp.MyStruct); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/ImportsSameAsPackage.go b/mocks/pkg/fixtures/ImportsSameAsPackage.go index ff177399..836f2b53 100644 --- a/mocks/pkg/fixtures/ImportsSameAsPackage.go +++ b/mocks/pkg/fixtures/ImportsSameAsPackage.go @@ -19,6 +19,7 @@ func (_m *ImportsSameAsPackage) A() test.B { ret := _m.Called() var r0 test.B + if rf, ok := ret.Get(0).(func() test.B); ok { r0 = rf() } else { @@ -33,6 +34,7 @@ func (_m *ImportsSameAsPackage) B() fixtures.KeyManager { ret := _m.Called() var r0 fixtures.KeyManager + if rf, ok := ret.Get(0).(func() fixtures.KeyManager); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/KeyManager.go b/mocks/pkg/fixtures/KeyManager.go index da5b4bbe..beb27af6 100644 --- a/mocks/pkg/fixtures/KeyManager.go +++ b/mocks/pkg/fixtures/KeyManager.go @@ -17,20 +17,25 @@ func (_m *KeyManager) GetKey(_a0 string, _a1 uint16) ([]byte, *test.Err) { ret := _m.Called(_a0, _a1) var r0 []byte - if rf, ok := ret.Get(0).(func(string, uint16) []byte); ok { - r0 = rf(_a0, _a1) + var r1 *test.Err + + if rf, ok := ret.Get(0).(func(string, uint16) ([]byte, *test.Err)); ok { + r0, r1 = rf(_a0, _a1) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) + if rf, ok := ret.Get(0).(func(string, uint16) []byte); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } } - } - var r1 *test.Err - if rf, ok := ret.Get(1).(func(string, uint16) *test.Err); ok { - r1 = rf(_a0, _a1) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*test.Err) + if rf, ok := ret.Get(1).(func(string, uint16) *test.Err); ok { + r1 = rf(_a0, _a1) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*test.Err) + } } } diff --git a/mocks/pkg/fixtures/MapFunc.go b/mocks/pkg/fixtures/MapFunc.go index eff10a3c..a3db6ee9 100644 --- a/mocks/pkg/fixtures/MapFunc.go +++ b/mocks/pkg/fixtures/MapFunc.go @@ -14,6 +14,7 @@ func (_m *MapFunc) Get(m map[string]func(string) string) error { ret := _m.Called(m) var r0 error + if rf, ok := ret.Get(0).(func(map[string]func(string) string) error); ok { r0 = rf(m) } else { diff --git a/mocks/pkg/fixtures/MyReader.go b/mocks/pkg/fixtures/MyReader.go index f677c95d..91c2b5a1 100644 --- a/mocks/pkg/fixtures/MyReader.go +++ b/mocks/pkg/fixtures/MyReader.go @@ -14,17 +14,22 @@ func (_m *MyReader) Read(p []byte) (int, error) { ret := _m.Called(p) var r0 int - if rf, ok := ret.Get(0).(func([]byte) int); ok { - r0 = rf(p) - } else { - r0 = ret.Get(0).(int) - } - var r1 error - if rf, ok := ret.Get(1).(func([]byte) error); ok { - r1 = rf(p) + + if rf, ok := ret.Get(0).(func([]byte) (int, error)); ok { + r0, r1 = rf(p) } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func([]byte) int); ok { + r0 = rf(p) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func([]byte) error); ok { + r1 = rf(p) + } else { + r1 = ret.Error(1) + } } return r0, r1 diff --git a/mocks/pkg/fixtures/Requester.go b/mocks/pkg/fixtures/Requester.go index c22011f2..36a4b789 100644 --- a/mocks/pkg/fixtures/Requester.go +++ b/mocks/pkg/fixtures/Requester.go @@ -14,17 +14,22 @@ func (_m *Requester) Get(path string) (string, error) { ret := _m.Called(path) var r0 string - if rf, ok := ret.Get(0).(func(string) string); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(string) - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) + + if rf, ok := ret.Get(0).(func(string) (string, error)); ok { + r0, r1 = rf(path) } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } } return r0, r1 diff --git a/mocks/pkg/fixtures/Requester2.go b/mocks/pkg/fixtures/Requester2.go index f0c20e18..19237821 100644 --- a/mocks/pkg/fixtures/Requester2.go +++ b/mocks/pkg/fixtures/Requester2.go @@ -14,6 +14,7 @@ func (_m *Requester2) Get(path string) error { ret := _m.Called(path) var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(path) } else { diff --git a/mocks/pkg/fixtures/Requester3.go b/mocks/pkg/fixtures/Requester3.go index 73b0b027..50b14f89 100644 --- a/mocks/pkg/fixtures/Requester3.go +++ b/mocks/pkg/fixtures/Requester3.go @@ -14,6 +14,7 @@ func (_m *Requester3) Get() error { ret := _m.Called() var r0 error + if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/RequesterArgSameAsImport.go b/mocks/pkg/fixtures/RequesterArgSameAsImport.go index 4d783b91..ab297d79 100644 --- a/mocks/pkg/fixtures/RequesterArgSameAsImport.go +++ b/mocks/pkg/fixtures/RequesterArgSameAsImport.go @@ -18,6 +18,7 @@ func (_m *RequesterArgSameAsImport) Get(_a0 string) *json.RawMessage { ret := _m.Called(_a0) var r0 *json.RawMessage + if rf, ok := ret.Get(0).(func(string) *json.RawMessage); ok { r0 = rf(_a0) } else { diff --git a/mocks/pkg/fixtures/RequesterArgSameAsNamedImport.go b/mocks/pkg/fixtures/RequesterArgSameAsNamedImport.go index c0c5b782..4ea698c4 100644 --- a/mocks/pkg/fixtures/RequesterArgSameAsNamedImport.go +++ b/mocks/pkg/fixtures/RequesterArgSameAsNamedImport.go @@ -18,6 +18,7 @@ func (_m *RequesterArgSameAsNamedImport) Get(_a0 string) *json.RawMessage { ret := _m.Called(_a0) var r0 *json.RawMessage + if rf, ok := ret.Get(0).(func(string) *json.RawMessage); ok { r0 = rf(_a0) } else { diff --git a/mocks/pkg/fixtures/RequesterArray.go b/mocks/pkg/fixtures/RequesterArray.go index b5cac438..417e7383 100644 --- a/mocks/pkg/fixtures/RequesterArray.go +++ b/mocks/pkg/fixtures/RequesterArray.go @@ -14,19 +14,24 @@ func (_m *RequesterArray) Get(path string) ([2]string, error) { ret := _m.Called(path) var r0 [2]string - if rf, ok := ret.Get(0).(func(string) [2]string); ok { - r0 = rf(path) + var r1 error + + if rf, ok := ret.Get(0).(func(string) ([2]string, error)); ok { + r0, r1 = rf(path) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([2]string) + if rf, ok := ret.Get(0).(func(string) [2]string); ok { + r0 = rf(path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([2]string) + } } - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } } return r0, r1 diff --git a/mocks/pkg/fixtures/RequesterElided.go b/mocks/pkg/fixtures/RequesterElided.go index 3af99cb0..0edab572 100644 --- a/mocks/pkg/fixtures/RequesterElided.go +++ b/mocks/pkg/fixtures/RequesterElided.go @@ -14,6 +14,7 @@ func (_m *RequesterElided) Get(path string, url string) error { ret := _m.Called(path, url) var r0 error + if rf, ok := ret.Get(0).(func(string, string) error); ok { r0 = rf(path, url) } else { diff --git a/mocks/pkg/fixtures/RequesterGenerics.go b/mocks/pkg/fixtures/RequesterGenerics.go index 6fe44588..83f53007 100644 --- a/mocks/pkg/fixtures/RequesterGenerics.go +++ b/mocks/pkg/fixtures/RequesterGenerics.go @@ -29,6 +29,7 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG var r0 struct { Type2 test.GenericType[string, test.EmbeddedGet[int]] } + if rf, ok := ret.Get(0).(func(struct{ Type1 TExternalIntf }) struct { Type2 test.GenericType[string, test.EmbeddedGet[int]] }); ok { @@ -47,17 +48,22 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG ret := _m.Called(_a0, _a1) var r0 TSigned - if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Get(0).(TSigned) - } - var r1 TIntf - if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { - r1 = rf(_a0, _a1) + + if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { + r0, r1 = rf(_a0, _a1) } else { - r1 = ret.Get(1).(TIntf) + if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Get(0).(TSigned) + } + + if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Get(1).(TIntf) + } } return r0, r1 @@ -68,6 +74,7 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG ret := _m.Called(_a0) var r0 test.GenericType[TSigned, TIntf] + if rf, ok := ret.Get(0).(func(test.GenericType[TAny, TIntf]) test.GenericType[TSigned, TIntf]); ok { r0 = rf(_a0) } else { diff --git a/mocks/pkg/fixtures/RequesterIface.go b/mocks/pkg/fixtures/RequesterIface.go index 41d7d7d8..54fe0e98 100644 --- a/mocks/pkg/fixtures/RequesterIface.go +++ b/mocks/pkg/fixtures/RequesterIface.go @@ -18,6 +18,7 @@ func (_m *RequesterIface) Get() io.Reader { ret := _m.Called() var r0 io.Reader + if rf, ok := ret.Get(0).(func() io.Reader); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/RequesterNS.go b/mocks/pkg/fixtures/RequesterNS.go index e7a69f14..851384a3 100644 --- a/mocks/pkg/fixtures/RequesterNS.go +++ b/mocks/pkg/fixtures/RequesterNS.go @@ -18,17 +18,22 @@ func (_m *RequesterNS) Get(path string) (http.Response, error) { ret := _m.Called(path) var r0 http.Response - if rf, ok := ret.Get(0).(func(string) http.Response); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(http.Response) - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) + + if rf, ok := ret.Get(0).(func(string) (http.Response, error)); ok { + r0, r1 = rf(path) } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func(string) http.Response); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(http.Response) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } } return r0, r1 diff --git a/mocks/pkg/fixtures/RequesterPtr.go b/mocks/pkg/fixtures/RequesterPtr.go index 2d19b39b..71d41e4d 100644 --- a/mocks/pkg/fixtures/RequesterPtr.go +++ b/mocks/pkg/fixtures/RequesterPtr.go @@ -14,19 +14,24 @@ func (_m *RequesterPtr) Get(path string) (*string, error) { ret := _m.Called(path) var r0 *string - if rf, ok := ret.Get(0).(func(string) *string); ok { - r0 = rf(path) + var r1 error + + if rf, ok := ret.Get(0).(func(string) (*string, error)); ok { + r0, r1 = rf(path) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*string) + if rf, ok := ret.Get(0).(func(string) *string); ok { + r0 = rf(path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*string) + } } - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } } return r0, r1 diff --git a/mocks/pkg/fixtures/RequesterReturnElided.go b/mocks/pkg/fixtures/RequesterReturnElided.go index 82d7c6a8..79486247 100644 --- a/mocks/pkg/fixtures/RequesterReturnElided.go +++ b/mocks/pkg/fixtures/RequesterReturnElided.go @@ -22,31 +22,36 @@ func (_m *RequesterReturnElided) Get(path string) (int, int, int, error) { ret := _m.Called(path) var r0 int - if rf, ok := ret.Get(0).(func(string) int); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(int) - } - var r1 int - if rf, ok := ret.Get(1).(func(string) int); ok { - r1 = rf(path) - } else { - r1 = ret.Get(1).(int) - } - var r2 int - if rf, ok := ret.Get(2).(func(string) int); ok { - r2 = rf(path) - } else { - r2 = ret.Get(2).(int) - } - var r3 error - if rf, ok := ret.Get(3).(func(string) error); ok { - r3 = rf(path) + + if rf, ok := ret.Get(0).(func(string) (int, int, int, error)); ok { + r0, r1, r2, r3 = rf(path) } else { - r3 = ret.Error(3) + if rf, ok := ret.Get(0).(func(string) int); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(string) int); ok { + r1 = rf(path) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(string) int); ok { + r2 = rf(path) + } else { + r2 = ret.Get(2).(int) + } + + if rf, ok := ret.Get(3).(func(string) error); ok { + r3 = rf(path) + } else { + r3 = ret.Error(3) + } } return r0, r1, r2, r3 @@ -75,22 +80,32 @@ func (_c *RequesterReturnElided_Get_Call) Return(a int, b int, c int, err error) return _c } +func (_c *RequesterReturnElided_Get_Call) RunAndReturn(run func(string) (int, int, int, error)) *RequesterReturnElided_Get_Call { + _c.Call.Return(run) + return _c +} + // Put provides a mock function with given fields: path func (_m *RequesterReturnElided) Put(path string) (int, error) { ret := _m.Called(path) var r0 int - if rf, ok := ret.Get(0).(func(string) int); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(int) - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) + + if rf, ok := ret.Get(0).(func(string) (int, error)); ok { + r0, r1 = rf(path) } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func(string) int); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -119,6 +134,11 @@ func (_c *RequesterReturnElided_Put_Call) Return(_a0 int, err error) *RequesterR return _c } +func (_c *RequesterReturnElided_Put_Call) RunAndReturn(run func(string) (int, error)) *RequesterReturnElided_Put_Call { + _c.Call.Return(run) + return _c +} + type mockConstructorTestingTNewRequesterReturnElided interface { mock.TestingT Cleanup(func()) diff --git a/mocks/pkg/fixtures/RequesterSlice.go b/mocks/pkg/fixtures/RequesterSlice.go index bf4230f5..83bd9005 100644 --- a/mocks/pkg/fixtures/RequesterSlice.go +++ b/mocks/pkg/fixtures/RequesterSlice.go @@ -14,19 +14,24 @@ func (_m *RequesterSlice) Get(path string) ([]string, error) { ret := _m.Called(path) var r0 []string - if rf, ok := ret.Get(0).(func(string) []string); ok { - r0 = rf(path) + var r1 error + + if rf, ok := ret.Get(0).(func(string) ([]string, error)); ok { + r0, r1 = rf(path) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) + if rf, ok := ret.Get(0).(func(string) []string); ok { + r0 = rf(path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } } - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } } return r0, r1 diff --git a/mocks/pkg/fixtures/RequesterVariadic.go b/mocks/pkg/fixtures/RequesterVariadic.go index a5359e70..5196eb97 100644 --- a/mocks/pkg/fixtures/RequesterVariadic.go +++ b/mocks/pkg/fixtures/RequesterVariadic.go @@ -24,6 +24,7 @@ func (_m *RequesterVariadic) Get(values ...string) bool { ret := _m.Called(_ca...) var r0 bool + if rf, ok := ret.Get(0).(func(...string) bool); ok { r0 = rf(values...) } else { @@ -45,6 +46,7 @@ func (_m *RequesterVariadic) MultiWriteToFile(filename string, w ...io.Writer) s ret := _m.Called(_ca...) var r0 string + if rf, ok := ret.Get(0).(func(string, ...io.Writer) string); ok { r0 = rf(filename, w...) } else { @@ -61,6 +63,7 @@ func (_m *RequesterVariadic) OneInterface(a ...interface{}) bool { ret := _m.Called(_ca...) var r0 bool + if rf, ok := ret.Get(0).(func(...interface{}) bool); ok { r0 = rf(a...) } else { @@ -78,6 +81,7 @@ func (_m *RequesterVariadic) Sprintf(format string, a ...interface{}) string { ret := _m.Called(_ca...) var r0 string + if rf, ok := ret.Get(0).(func(string, ...interface{}) string); ok { r0 = rf(format, a...) } else { diff --git a/mocks/pkg/fixtures/RequesterVariadicOneArgument.go b/mocks/pkg/fixtures/RequesterVariadicOneArgument.go index f9cf19a7..dc98715c 100644 --- a/mocks/pkg/fixtures/RequesterVariadicOneArgument.go +++ b/mocks/pkg/fixtures/RequesterVariadicOneArgument.go @@ -18,6 +18,7 @@ func (_m *RequesterVariadicOneArgument) Get(values ...string) bool { ret := _m.Called(values) var r0 bool + if rf, ok := ret.Get(0).(func(...string) bool); ok { r0 = rf(values...) } else { @@ -32,6 +33,7 @@ func (_m *RequesterVariadicOneArgument) MultiWriteToFile(filename string, w ...i ret := _m.Called(filename, w) var r0 string + if rf, ok := ret.Get(0).(func(string, ...io.Writer) string); ok { r0 = rf(filename, w...) } else { @@ -46,6 +48,7 @@ func (_m *RequesterVariadicOneArgument) OneInterface(a ...interface{}) bool { ret := _m.Called(a) var r0 bool + if rf, ok := ret.Get(0).(func(...interface{}) bool); ok { r0 = rf(a...) } else { @@ -60,6 +63,7 @@ func (_m *RequesterVariadicOneArgument) Sprintf(format string, a ...interface{}) ret := _m.Called(format, a) var r0 string + if rf, ok := ret.Get(0).(func(string, ...interface{}) string); ok { r0 = rf(format, a...) } else { diff --git a/mocks/pkg/fixtures/SendFunc.go b/mocks/pkg/fixtures/SendFunc.go index ee4d3e0d..77fdb2cd 100644 --- a/mocks/pkg/fixtures/SendFunc.go +++ b/mocks/pkg/fixtures/SendFunc.go @@ -18,17 +18,22 @@ func (_m *SendFunc) Execute(ctx context.Context, data string) (int, error) { ret := _m.Called(ctx, data) var r0 int - if rf, ok := ret.Get(0).(func(context.Context, string) int); ok { - r0 = rf(ctx, data) - } else { - r0 = ret.Get(0).(int) - } - var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = rf(ctx, data) + + if rf, ok := ret.Get(0).(func(context.Context, string) (int, error)); ok { + r0, r1 = rf(ctx, data) } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func(context.Context, string) int); ok { + r0 = rf(ctx, data) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, data) + } else { + r1 = ret.Error(1) + } } return r0, r1 diff --git a/mocks/pkg/fixtures/buildtag/comment/IfaceWithBuildTagInComment.go b/mocks/pkg/fixtures/buildtag/comment/IfaceWithBuildTagInComment.go index 8dc5d76a..4b3727cb 100644 --- a/mocks/pkg/fixtures/buildtag/comment/IfaceWithBuildTagInComment.go +++ b/mocks/pkg/fixtures/buildtag/comment/IfaceWithBuildTagInComment.go @@ -17,6 +17,7 @@ func (_m *IfaceWithBuildTagInComment) Sprintf(format string, a ...interface{}) s ret := _m.Called(_ca...) var r0 string + if rf, ok := ret.Get(0).(func(string, ...interface{}) string); ok { r0 = rf(format, a...) } else { diff --git a/mocks/pkg/fixtures/buildtag/filename/IfaceWithBuildTagInFilename.go b/mocks/pkg/fixtures/buildtag/filename/IfaceWithBuildTagInFilename.go index 8060c7c3..f690e6ce 100644 --- a/mocks/pkg/fixtures/buildtag/filename/IfaceWithBuildTagInFilename.go +++ b/mocks/pkg/fixtures/buildtag/filename/IfaceWithBuildTagInFilename.go @@ -17,6 +17,7 @@ func (_m *IfaceWithBuildTagInFilename) Sprintf(format string, a ...interface{}) ret := _m.Called(_ca...) var r0 string + if rf, ok := ret.Get(0).(func(string, ...interface{}) string); ok { r0 = rf(format, a...) } else { diff --git a/mocks/pkg/fixtures/example_project/Root.go b/mocks/pkg/fixtures/example_project/Root.go index 0f5a11ba..422f8f46 100644 --- a/mocks/pkg/fixtures/example_project/Root.go +++ b/mocks/pkg/fixtures/example_project/Root.go @@ -17,19 +17,24 @@ func (_m *Root) ReturnsFoo() (foo.Foo, error) { ret := _m.Called() var r0 foo.Foo - if rf, ok := ret.Get(0).(func() foo.Foo); ok { - r0 = rf() + var r1 error + + if rf, ok := ret.Get(0).(func() (foo.Foo, error)); ok { + r0, r1 = rf() } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(foo.Foo) + if rf, ok := ret.Get(0).(func() foo.Foo); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(foo.Foo) + } } - } - var r1 error - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } } return r0, r1 diff --git a/mocks/pkg/fixtures/example_project/bar/foo/Client.go b/mocks/pkg/fixtures/example_project/bar/foo/Client.go index a8b6f07d..98c8e2ab 100644 --- a/mocks/pkg/fixtures/example_project/bar/foo/Client.go +++ b/mocks/pkg/fixtures/example_project/bar/foo/Client.go @@ -14,19 +14,24 @@ func (_m *Client) Search(query string) ([]string, error) { ret := _m.Called(query) var r0 []string - if rf, ok := ret.Get(0).(func(string) []string); ok { - r0 = rf(query) + var r1 error + + if rf, ok := ret.Get(0).(func(string) ([]string, error)); ok { + r0, r1 = rf(query) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) + if rf, ok := ret.Get(0).(func(string) []string); ok { + r0 = rf(query) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } } - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(query) - } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(query) + } else { + r1 = ret.Error(1) + } } return r0, r1 diff --git a/mocks/pkg/fixtures/example_project/foo/Foo.go b/mocks/pkg/fixtures/example_project/foo/Foo.go index 1470e204..7f056c48 100644 --- a/mocks/pkg/fixtures/example_project/foo/Foo.go +++ b/mocks/pkg/fixtures/example_project/foo/Foo.go @@ -17,6 +17,7 @@ func (_m *Foo) DoFoo() string { ret := _m.Called() var r0 string + if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() } else { @@ -31,19 +32,24 @@ func (_m *Foo) GetBaz() (*foo.Baz, error) { ret := _m.Called() var r0 *foo.Baz - if rf, ok := ret.Get(0).(func() *foo.Baz); ok { - r0 = rf() + var r1 error + + if rf, ok := ret.Get(0).(func() (*foo.Baz, error)); ok { + r0, r1 = rf() } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*foo.Baz) + if rf, ok := ret.Get(0).(func() *foo.Baz); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*foo.Baz) + } } - } - var r1 error - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } } return r0, r1 diff --git a/mocks/pkg/fixtures/example_project/foo/PackageNameSameAsImport.go b/mocks/pkg/fixtures/example_project/foo/PackageNameSameAsImport.go index 54278823..9c7263c1 100644 --- a/mocks/pkg/fixtures/example_project/foo/PackageNameSameAsImport.go +++ b/mocks/pkg/fixtures/example_project/foo/PackageNameSameAsImport.go @@ -17,6 +17,7 @@ func (_m *PackageNameSameAsImport) NewClient() foo.Client { ret := _m.Called() var r0 foo.Client + if rf, ok := ret.Get(0).(func() foo.Client); ok { r0 = rf() } else { diff --git a/pkg/generator.go b/pkg/generator.go index 69fc94b2..f838ea79 100644 --- a/pkg/generator.go +++ b/pkg/generator.go @@ -611,26 +611,47 @@ func (g *Generator) Generate(ctx context.Context) error { ret := make([]string, len(returns.Types)) for idx, typ := range returns.Types { + ret[idx] = fmt.Sprintf("r%d", idx) g.printf("\tvar r%d %s\n", idx, typ) - g.printf("\tif rf, ok := %s.Get(%d).(func(%s) %s); ok {\n", - retVariable, idx, strings.Join(params.Types, ", "), typ) - g.printf("\t\tr%d = rf(%s)\n", idx, formattedParamNames) + } + + g.printf("\n") + + var tab string + if len(returns.Types) > 1 { + tab = "\t" + g.printf("\tif rf, ok := %s.Get(0).(func(%s) (%s)); ok {\n", + retVariable, strings.Join(params.Types, ", "), strings.Join(returns.Types, ", ")) + g.printf("\t\t%s = rf(%s)\n", strings.Join(ret, ", "), formattedParamNames) g.printf("\t} else {\n") + } + + for idx, typ := range returns.Types { + if idx > 0 { + g.printf("\n") + } + + g.printf("%s\tif rf, ok := %s.Get(%d).(func(%s) %s); ok {\n", + tab, retVariable, idx, strings.Join(params.Types, ", "), typ) + g.printf("%s\t\tr%d = rf(%s)\n", tab, idx, formattedParamNames) + g.printf("%s\t} else {\n", tab) if typ == "error" { - g.printf("\t\tr%d = %s.Error(%d)\n", idx, retVariable, idx) + g.printf("%s\t\tr%d = %s.Error(%d)\n", tab, idx, retVariable, idx) } else if returns.Nilable[idx] { - g.printf("\t\tif %s.Get(%d) != nil {\n", retVariable, idx) - g.printf("\t\t\tr%d = %s.Get(%d).(%s)\n", idx, retVariable, idx, typ) - g.printf("\t\t}\n") + g.printf("%s\t\tif %s.Get(%d) != nil {\n", tab, retVariable, idx) + g.printf("%s\t\t\tr%d = %s.Get(%d).(%s)\n", tab, idx, retVariable, idx, typ) + g.printf("%s\t\t}\n", tab) } else { - g.printf("\t\tr%d = %s.Get(%d).(%s)\n", idx, retVariable, idx, typ) + g.printf("%s\t\tr%d = %s.Get(%d).(%s)\n", tab, idx, retVariable, idx, typ) } - g.printf("\t}\n\n") + g.printf("%s\t}\n", tab) + } - ret[idx] = fmt.Sprintf("r%d", idx) + if len(returns.Types) > 1 { + g.printf("\t}\n") } - g.printf("\treturn %s\n", strings.Join(ret, ", ")) + g.printf("\n\treturn %s\n", strings.Join(ret, ", ")) } else { g.printf("\t%s\n", called) } @@ -750,6 +771,11 @@ func (_c *{{.CallStruct}}{{ .InstantiatedTypeString }}) Return({{range .Returns. _c.Call.Return({{range .Returns.Names}}{{.}},{{end}}) return _c } + +func (_c *{{.CallStruct}}{{ .InstantiatedTypeString }}) RunAndReturn(run func({{range .Params.Types}}{{.}},{{end}})({{range .Returns.Types}}{{.}},{{end}})) *{{.CallStruct}}{{ .InstantiatedTypeString }} { + _c.Call.Return(run) + return _c +} `) } diff --git a/pkg/generator_test.go b/pkg/generator_test.go index efe92eac..d58b33c1 100644 --- a/pkg/generator_test.go +++ b/pkg/generator_test.go @@ -127,17 +127,22 @@ func (_m *Requester) Get(path string) (string, error) { ret := _m.Called(path) var r0 string - if rf, ok := ret.Get(0).(func(string) string); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(string) - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) + + if rf, ok := ret.Get(0).(func(string) (string, error)); ok { + r0, r1 = rf(path) } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -180,17 +185,22 @@ func (_m *Requester) Get(path string) (string, error) { ret := _m.Called(path) var r0 string - if rf, ok := ret.Get(0).(func(string) string); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(string) - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) + + if rf, ok := ret.Get(0).(func(string) (string, error)); ok { + r0, r1 = rf(path) } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -219,6 +229,11 @@ func (_c *Requester_Get_Call) Return(_a0 string, _a1 error) *Requester_Get_Call return _c } +func (_c *Requester_Get_Call) RunAndReturn(run func(string) (string, error)) *Requester_Get_Call { + _c.Call.Return(run) + return _c +} + type mockConstructorTestingTNewRequester interface { mock.TestingT Cleanup(func()) @@ -261,19 +276,24 @@ func (_m *Expecter) ManyArgsReturns(str string, i int) ([]string, error) { ret := _m.Called(str, i) var r0 []string - if rf, ok := ret.Get(0).(func(string, int) []string); ok { - r0 = rf(str, i) + var r1 error + + if rf, ok := ret.Get(0).(func(string, int) ([]string, error)); ok { + r0, r1 = rf(str, i) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) + if rf, ok := ret.Get(0).(func(string, int) []string); ok { + r0 = rf(str, i) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } } - } - var r1 error - if rf, ok := ret.Get(1).(func(string, int) error); ok { - r1 = rf(str, i) - } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(1).(func(string, int) error); ok { + r1 = rf(str, i) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -303,11 +323,17 @@ func (_c *Expecter_ManyArgsReturns_Call) Return(strs []string, err error) *Expec return _c } +func (_c *Expecter_ManyArgsReturns_Call) RunAndReturn(run func(string, int) ([]string, error)) *Expecter_ManyArgsReturns_Call { + _c.Call.Return(run) + return _c +} + // NoArg provides a mock function with given fields: func (_m *Expecter) NoArg() string { ret := _m.Called() var r0 string + if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() } else { @@ -339,6 +365,11 @@ func (_c *Expecter_NoArg_Call) Return(_a0 string) *Expecter_NoArg_Call { return _c } +func (_c *Expecter_NoArg_Call) RunAndReturn(run func() string) *Expecter_NoArg_Call { + _c.Call.Return(run) + return _c +} + // NoReturn provides a mock function with given fields: str func (_m *Expecter) NoReturn(str string) { _m.Called(str) @@ -367,6 +398,11 @@ func (_c *Expecter_NoReturn_Call) Return() *Expecter_NoReturn_Call { return _c } +func (_c *Expecter_NoReturn_Call) RunAndReturn(run func(string)) *Expecter_NoReturn_Call { + _c.Call.Return(run) + return _c +} + // Variadic provides a mock function with given fields: ints func (_m *Expecter) Variadic(ints ...int) error { _va := make([]interface{}, len(ints)) @@ -378,6 +414,7 @@ func (_m *Expecter) Variadic(ints ...int) error { ret := _m.Called(_ca...) var r0 error + if rf, ok := ret.Get(0).(func(...int) error); ok { r0 = rf(ints...) } else { @@ -417,6 +454,11 @@ func (_c *Expecter_Variadic_Call) Return(_a0 error) *Expecter_Variadic_Call { return _c } +func (_c *Expecter_Variadic_Call) RunAndReturn(run func(...int) error) *Expecter_Variadic_Call { + _c.Call.Return(run) + return _c +} + // VariadicMany provides a mock function with given fields: i, a, intfs func (_m *Expecter) VariadicMany(i int, a string, intfs ...interface{}) error { var _ca []interface{} @@ -425,6 +467,7 @@ func (_m *Expecter) VariadicMany(i int, a string, intfs ...interface{}) error { ret := _m.Called(_ca...) var r0 error + if rf, ok := ret.Get(0).(func(int, string, ...interface{}) error); ok { r0 = rf(i, a, intfs...) } else { @@ -466,6 +509,11 @@ func (_c *Expecter_VariadicMany_Call) Return(_a0 error) *Expecter_VariadicMany_C return _c } +func (_c *Expecter_VariadicMany_Call) RunAndReturn(run func(int, string, ...interface{}) error) *Expecter_VariadicMany_Call { + _c.Call.Return(run) + return _c +} + type mockConstructorTestingTNewExpecter interface { mock.TestingT Cleanup(func()) @@ -512,17 +560,22 @@ func (_m *SendFunc) Execute(ctx context.Context, data string) (int, error) { ret := _m.Called(ctx, data) var r0 int - if rf, ok := ret.Get(0).(func(context.Context, string) int); ok { - r0 = rf(ctx, data) - } else { - r0 = ret.Get(0).(int) - } - var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = rf(ctx, data) + + if rf, ok := ret.Get(0).(func(context.Context, string) (int, error)); ok { + r0, r1 = rf(ctx, data) } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func(context.Context, string) int); ok { + r0 = rf(ctx, data) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, data) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -557,6 +610,7 @@ func (_m *Requester2) Get(path string) error { ret := _m.Called(path) var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(path) } else { @@ -595,6 +649,7 @@ func (_m *Requester3) Get() error { ret := _m.Called() var r0 error + if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() } else { @@ -879,6 +934,7 @@ func (_m *RequesterIface) Get() io.Reader { ret := _m.Called() var r0 io.Reader + if rf, ok := ret.Get(0).(func() io.Reader); ok { r0 = rf() } else { @@ -919,19 +975,24 @@ func (_m *RequesterPtr) Get(path string) (*string, error) { ret := _m.Called(path) var r0 *string - if rf, ok := ret.Get(0).(func(string) *string); ok { - r0 = rf(path) + var r1 error + + if rf, ok := ret.Get(0).(func(string) (*string, error)); ok { + r0, r1 = rf(path) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*string) + if rf, ok := ret.Get(0).(func(string) *string); ok { + r0 = rf(path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*string) + } } - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -966,19 +1027,24 @@ func (_m *RequesterSlice) Get(path string) ([]string, error) { ret := _m.Called(path) var r0 []string - if rf, ok := ret.Get(0).(func(string) []string); ok { - r0 = rf(path) + var r1 error + + if rf, ok := ret.Get(0).(func(string) ([]string, error)); ok { + r0, r1 = rf(path) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) + if rf, ok := ret.Get(0).(func(string) []string); ok { + r0 = rf(path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } } - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -1013,19 +1079,24 @@ func (_m *RequesterArray) Get(path string) ([2]string, error) { ret := _m.Called(path) var r0 [2]string - if rf, ok := ret.Get(0).(func(string) [2]string); ok { - r0 = rf(path) + var r1 error + + if rf, ok := ret.Get(0).(func(string) ([2]string, error)); ok { + r0, r1 = rf(path) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([2]string) + if rf, ok := ret.Get(0).(func(string) [2]string); ok { + r0 = rf(path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([2]string) + } } - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -1060,17 +1131,22 @@ func (_m *RequesterNS) Get(path string) (http.Response, error) { ret := _m.Called(path) var r0 http.Response - if rf, ok := ret.Get(0).(func(string) http.Response); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(http.Response) - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) + + if rf, ok := ret.Get(0).(func(string) (http.Response, error)); ok { + r0, r1 = rf(path) } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func(string) http.Response); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(http.Response) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -1105,6 +1181,7 @@ func (_m *RequesterArgSameAsImport) Get(_a0 string) *json.RawMessage { ret := _m.Called(_a0) var r0 *json.RawMessage + if rf, ok := ret.Get(0).(func(string) *json.RawMessage); ok { r0 = rf(_a0) } else { @@ -1145,6 +1222,7 @@ func (_m *RequesterArgSameAsNamedImport) Get(_a0 string) *json.RawMessage { ret := _m.Called(_a0) var r0 *json.RawMessage + if rf, ok := ret.Get(0).(func(string) *json.RawMessage); ok { r0 = rf(_a0) } else { @@ -1214,20 +1292,25 @@ func (_m *KeyManager) GetKey(_a0 string, _a1 uint16) ([]byte, *test.Err) { ret := _m.Called(_a0, _a1) var r0 []byte - if rf, ok := ret.Get(0).(func(string, uint16) []byte); ok { - r0 = rf(_a0, _a1) + var r1 *test.Err + + if rf, ok := ret.Get(0).(func(string, uint16) ([]byte, *test.Err)); ok { + r0, r1 = rf(_a0, _a1) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) + if rf, ok := ret.Get(0).(func(string, uint16) []byte); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } } - } - var r1 *test.Err - if rf, ok := ret.Get(1).(func(string, uint16) *test.Err); ok { - r1 = rf(_a0, _a1) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*test.Err) + if rf, ok := ret.Get(1).(func(string, uint16) *test.Err); ok { + r1 = rf(_a0, _a1) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*test.Err) + } } } @@ -1263,6 +1346,7 @@ func (_m *RequesterElided) Get(path string, url string) error { ret := _m.Called(path, url) var r0 error + if rf, ok := ret.Get(0).(func(string, string) error); ok { r0 = rf(path, url) } else { @@ -1309,31 +1393,36 @@ func (_m *RequesterReturnElided) Get(path string) (int, int, int, error) { ret := _m.Called(path) var r0 int - if rf, ok := ret.Get(0).(func(string) int); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(int) - } - var r1 int - if rf, ok := ret.Get(1).(func(string) int); ok { - r1 = rf(path) - } else { - r1 = ret.Get(1).(int) - } - var r2 int - if rf, ok := ret.Get(2).(func(string) int); ok { - r2 = rf(path) - } else { - r2 = ret.Get(2).(int) - } - var r3 error - if rf, ok := ret.Get(3).(func(string) error); ok { - r3 = rf(path) + + if rf, ok := ret.Get(0).(func(string) (int, int, int, error)); ok { + r0, r1, r2, r3 = rf(path) } else { - r3 = ret.Error(3) + if rf, ok := ret.Get(0).(func(string) int); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(string) int); ok { + r1 = rf(path) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(string) int); ok { + r2 = rf(path) + } else { + r2 = ret.Get(2).(int) + } + + if rf, ok := ret.Get(3).(func(string) error); ok { + r3 = rf(path) + } else { + r3 = ret.Error(3) + } } return r0, r1, r2, r3 @@ -1362,22 +1451,32 @@ func (_c *RequesterReturnElided_Get_Call) Return(a int, b int, c int, err error) return _c } +func (_c *RequesterReturnElided_Get_Call) RunAndReturn(run func(string) (int, int, int, error)) *RequesterReturnElided_Get_Call { + _c.Call.Return(run) + return _c +} + // Put provides a mock function with given fields: path func (_m *RequesterReturnElided) Put(path string) (int, error) { ret := _m.Called(path) var r0 int - if rf, ok := ret.Get(0).(func(string) int); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(int) - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) + + if rf, ok := ret.Get(0).(func(string) (int, error)); ok { + r0, r1 = rf(path) } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func(string) int); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -1406,6 +1505,11 @@ func (_c *RequesterReturnElided_Put_Call) Return(_a0 int, err error) *RequesterR return _c } +func (_c *RequesterReturnElided_Put_Call) RunAndReturn(run func(string) (int, error)) *RequesterReturnElided_Put_Call { + _c.Call.Return(run) + return _c +} + type mockConstructorTestingTNewRequesterReturnElided interface { mock.TestingT Cleanup(func()) @@ -1569,6 +1673,7 @@ func (_m *Fooer) Baz(path string) func(string) string { ret := _m.Called(path) var r0 func(string) string + if rf, ok := ret.Get(0).(func(string) func(string) string); ok { r0 = rf(path) } else { @@ -1585,6 +1690,7 @@ func (_m *Fooer) Foo(f func(string) string) error { ret := _m.Called(f) var r0 error + if rf, ok := ret.Get(0).(func(func(string) string) error); ok { r0 = rf(f) } else { @@ -1623,6 +1729,7 @@ func (_m *AsyncProducer) Input() chan<- bool { ret := _m.Called() var r0 chan<- bool + if rf, ok := ret.Get(0).(func() chan<- bool); ok { r0 = rf() } else { @@ -1639,6 +1746,7 @@ func (_m *AsyncProducer) Output() <-chan bool { ret := _m.Called() var r0 <-chan bool + if rf, ok := ret.Get(0).(func() <-chan bool); ok { r0 = rf() } else { @@ -1655,6 +1763,7 @@ func (_m *AsyncProducer) Whatever() chan bool { ret := _m.Called() var r0 chan bool + if rf, ok := ret.Get(0).(func() chan bool); ok { r0 = rf() } else { @@ -1695,17 +1804,22 @@ func (_m *MyReader) Read(p []byte) (int, error) { ret := _m.Called(p) var r0 int - if rf, ok := ret.Get(0).(func([]byte) int); ok { - r0 = rf(p) - } else { - r0 = ret.Get(0).(int) - } - var r1 error - if rf, ok := ret.Get(1).(func([]byte) error); ok { - r1 = rf(p) + + if rf, ok := ret.Get(0).(func([]byte) (int, error)); ok { + r0, r1 = rf(p) } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func([]byte) int); ok { + r0 = rf(p) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func([]byte) error); ok { + r1 = rf(p) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -1740,19 +1854,24 @@ func (_m *ConsulLock) Lock(_a0 <-chan struct{}) (<-chan struct{}, error) { ret := _m.Called(_a0) var r0 <-chan struct{} - if rf, ok := ret.Get(0).(func(<-chan struct{}) <-chan struct{}); ok { - r0 = rf(_a0) + var r1 error + + if rf, ok := ret.Get(0).(func(<-chan struct{}) (<-chan struct{}, error)); ok { + r0, r1 = rf(_a0) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(<-chan struct{}) + if rf, ok := ret.Get(0).(func(<-chan struct{}) <-chan struct{}); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(<-chan struct{}) + } } - } - var r1 error - if rf, ok := ret.Get(1).(func(<-chan struct{}) error); ok { - r1 = rf(_a0) - } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(1).(func(<-chan struct{}) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -1763,6 +1882,7 @@ func (_m *ConsulLock) Unlock() error { ret := _m.Called() var r0 error + if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() } else { @@ -1801,6 +1921,7 @@ func (_m *Blank) Create(x interface{}) error { ret := _m.Called(x) var r0 error + if rf, ok := ret.Get(0).(func(interface{}) error); ok { r0 = rf(x) } else { @@ -1839,6 +1960,7 @@ func (_m *MapFunc) Get(m map[string]func(string) string) error { ret := _m.Called(m) var r0 error + if rf, ok := ret.Get(0).(func(map[string]func(string) string) error); ok { r0 = rf(m) } else { @@ -1935,6 +2057,7 @@ func (_m *Example) A() http.Flusher { ret := _m.Called() var r0 http.Flusher + if rf, ok := ret.Get(0).(func() http.Flusher); ok { r0 = rf() } else { @@ -1951,6 +2074,7 @@ func (_m *Example) B(_a0 string) fixtureshttp.MyStruct { ret := _m.Called(_a0) var r0 fixtureshttp.MyStruct + if rf, ok := ret.Get(0).(func(string) fixtureshttp.MyStruct); ok { r0 = rf(_a0) } else { @@ -2035,6 +2159,7 @@ func (_m *FuncArgsCollision) Foo(ret interface{}) error { ret_1 := _m.Called(ret) var r0 error + if rf, ok := ret_1.Get(0).(func(interface{}) error); ok { r0 = rf(ret) } else { @@ -2073,6 +2198,7 @@ func (_m *ImportsSameAsPackage) A() test.B { ret := _m.Called() var r0 test.B + if rf, ok := ret.Get(0).(func() test.B); ok { r0 = rf() } else { @@ -2087,6 +2213,7 @@ func (_m *ImportsSameAsPackage) B() fixtures.KeyManager { ret := _m.Called() var r0 fixtures.KeyManager + if rf, ok := ret.Get(0).(func() fixtures.KeyManager); ok { r0 = rf() } else { @@ -2191,17 +2318,22 @@ func (_m *A) Call() (test.B, error) { ret := _m.Called() var r0 test.B - if rf, ok := ret.Get(0).(func() test.B); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(test.B) - } - var r1 error - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() + + if rf, ok := ret.Get(0).(func() (test.B, error)); ok { + r0, r1 = rf() } else { - r1 = ret.Error(1) + if rf, ok := ret.Get(0).(func() test.B); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(test.B) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } } return r0, r1 @@ -2236,6 +2368,7 @@ func (_m *Requester2OverrideName) Get(path string) error { ret := _m.Called(path) var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(path) } else { @@ -2347,6 +2480,7 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG var r0 struct { Type2 test.GenericType[string, test.EmbeddedGet[int]] } + if rf, ok := ret.Get(0).(func(struct{ Type1 TExternalIntf }) struct { Type2 test.GenericType[string, test.EmbeddedGet[int]] }); ok { @@ -2365,17 +2499,22 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG ret := _m.Called(_a0, _a1) var r0 TSigned - if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Get(0).(TSigned) - } - var r1 TIntf - if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { - r1 = rf(_a0, _a1) + + if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { + r0, r1 = rf(_a0, _a1) } else { - r1 = ret.Get(1).(TIntf) + if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Get(0).(TSigned) + } + + if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Get(1).(TIntf) + } } return r0, r1 @@ -2386,6 +2525,7 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG ret := _m.Called(_a0) var r0 test.GenericType[TSigned, TIntf] + if rf, ok := ret.Get(0).(func(test.GenericType[TAny, TIntf]) test.GenericType[TSigned, TIntf]); ok { r0 = rf(_a0) } else { @@ -2445,6 +2585,7 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG var r0 struct { Type2 test.GenericType[string, test.EmbeddedGet[int]] } + if rf, ok := ret.Get(0).(func(struct{ Type1 TExternalIntf }) struct { Type2 test.GenericType[string, test.EmbeddedGet[int]] }); ok { @@ -2486,22 +2627,34 @@ func (_c *RequesterGenerics_GenericAnonymousStructs_Call[TAny, TComparable, TSig return _c } +func (_c *RequesterGenerics_GenericAnonymousStructs_Call[TAny, TComparable, TSigned, TIntf, TExternalIntf, TGenIntf, TInlineType, TInlineTypeGeneric]) RunAndReturn(run func(struct{ Type1 TExternalIntf }) struct { + Type2 test.GenericType[string, test.EmbeddedGet[int]] +}) *RequesterGenerics_GenericAnonymousStructs_Call[TAny, TComparable, TSigned, TIntf, TExternalIntf, TGenIntf, TInlineType, TInlineTypeGeneric] { + _c.Call.Return(run) + return _c +} + // GenericArguments provides a mock function with given fields: _a0, _a1 func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TGenIntf, TInlineType, TInlineTypeGeneric]) GenericArguments(_a0 TAny, _a1 TComparable) (TSigned, TIntf) { ret := _m.Called(_a0, _a1) var r0 TSigned - if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Get(0).(TSigned) - } - var r1 TIntf - if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { - r1 = rf(_a0, _a1) + + if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { + r0, r1 = rf(_a0, _a1) } else { - r1 = ret.Get(1).(TIntf) + if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Get(0).(TSigned) + } + + if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Get(1).(TIntf) + } } return r0, r1 @@ -2534,11 +2687,17 @@ func (_c *RequesterGenerics_GenericArguments_Call[TAny, TComparable, TSigned, TI return _c } +func (_c *RequesterGenerics_GenericArguments_Call[TAny, TComparable, TSigned, TIntf, TExternalIntf, TGenIntf, TInlineType, TInlineTypeGeneric]) RunAndReturn(run func(TAny, TComparable) (TSigned, TIntf)) *RequesterGenerics_GenericArguments_Call[TAny, TComparable, TSigned, TIntf, TExternalIntf, TGenIntf, TInlineType, TInlineTypeGeneric] { + _c.Call.Return(run) + return _c +} + // GenericStructs provides a mock function with given fields: _a0 func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TGenIntf, TInlineType, TInlineTypeGeneric]) GenericStructs(_a0 test.GenericType[TAny, TIntf]) test.GenericType[TSigned, TIntf] { ret := _m.Called(_a0) var r0 test.GenericType[TSigned, TIntf] + if rf, ok := ret.Get(0).(func(test.GenericType[TAny, TIntf]) test.GenericType[TSigned, TIntf]); ok { r0 = rf(_a0) } else { @@ -2574,6 +2733,11 @@ func (_c *RequesterGenerics_GenericStructs_Call[TAny, TComparable, TSigned, TInt return _c } +func (_c *RequesterGenerics_GenericStructs_Call[TAny, TComparable, TSigned, TIntf, TExternalIntf, TGenIntf, TInlineType, TInlineTypeGeneric]) RunAndReturn(run func(test.GenericType[TAny, TIntf]) test.GenericType[TSigned, TIntf]) *RequesterGenerics_GenericStructs_Call[TAny, TComparable, TSigned, TIntf, TExternalIntf, TGenIntf, TInlineType, TInlineTypeGeneric] { + _c.Call.Return(run) + return _c +} + type mockConstructorTestingTNewRequesterGenerics interface { mock.TestingT Cleanup(func()) @@ -2618,6 +2782,7 @@ func (_m *MockRequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf var r0 struct { Type2 GenericType[string, EmbeddedGet[int]] } + if rf, ok := ret.Get(0).(func(struct{ Type1 TExternalIntf }) struct { Type2 GenericType[string, EmbeddedGet[int]] }); ok { @@ -2636,17 +2801,22 @@ func (_m *MockRequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf ret := _m.Called(_a0, _a1) var r0 TSigned - if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Get(0).(TSigned) - } - var r1 TIntf - if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { - r1 = rf(_a0, _a1) + + if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { + r0, r1 = rf(_a0, _a1) } else { - r1 = ret.Get(1).(TIntf) + if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Get(0).(TSigned) + } + + if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Get(1).(TIntf) + } } return r0, r1 @@ -2657,6 +2827,7 @@ func (_m *MockRequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf ret := _m.Called(_a0) var r0 GenericType[TSigned, TIntf] + if rf, ok := ret.Get(0).(func(GenericType[TAny, TIntf]) GenericType[TSigned, TIntf]); ok { r0 = rf(_a0) } else { From 22fb404c71aec081c3741b62da7a664ec5e75965 Mon Sep 17 00:00:00 2001 From: Dave Wyatt Date: Tue, 7 Feb 2023 17:58:02 -0500 Subject: [PATCH 2/5] Remove blank line after r-var declarations --- README.md | 2 - mocks/pkg/fixtures/A.go | 1 - mocks/pkg/fixtures/AsyncProducer.go | 3 -- mocks/pkg/fixtures/Blank.go | 1 - mocks/pkg/fixtures/ConsulLock.go | 2 - mocks/pkg/fixtures/EmbeddedGet.go | 1 - mocks/pkg/fixtures/Example.go | 2 - mocks/pkg/fixtures/Expecter.go | 4 -- mocks/pkg/fixtures/Fooer.go | 2 - mocks/pkg/fixtures/FuncArgsCollision.go | 1 - mocks/pkg/fixtures/GetGeneric.go | 1 - mocks/pkg/fixtures/GetInt.go | 1 - .../fixtures/HasConflictingNestedImports.go | 2 - mocks/pkg/fixtures/ImportsSameAsPackage.go | 2 - mocks/pkg/fixtures/KeyManager.go | 1 - mocks/pkg/fixtures/MapFunc.go | 1 - mocks/pkg/fixtures/MyReader.go | 1 - mocks/pkg/fixtures/Requester.go | 1 - mocks/pkg/fixtures/Requester2.go | 1 - mocks/pkg/fixtures/Requester3.go | 1 - .../pkg/fixtures/RequesterArgSameAsImport.go | 1 - .../fixtures/RequesterArgSameAsNamedImport.go | 1 - mocks/pkg/fixtures/RequesterArray.go | 1 - mocks/pkg/fixtures/RequesterElided.go | 1 - mocks/pkg/fixtures/RequesterGenerics.go | 3 -- mocks/pkg/fixtures/RequesterIface.go | 1 - mocks/pkg/fixtures/RequesterNS.go | 1 - mocks/pkg/fixtures/RequesterPtr.go | 1 - mocks/pkg/fixtures/RequesterReturnElided.go | 2 - mocks/pkg/fixtures/RequesterSlice.go | 1 - mocks/pkg/fixtures/RequesterVariadic.go | 4 -- .../fixtures/RequesterVariadicOneArgument.go | 4 -- mocks/pkg/fixtures/SendFunc.go | 1 - .../comment/IfaceWithBuildTagInComment.go | 1 - .../filename/IfaceWithBuildTagInFilename.go | 1 - mocks/pkg/fixtures/example_project/Root.go | 1 - .../example_project/bar/foo/Client.go | 1 - mocks/pkg/fixtures/example_project/foo/Foo.go | 2 - .../foo/PackageNameSameAsImport.go | 1 - pkg/generator.go | 2 - pkg/generator_test.go | 46 ------------------- 41 files changed, 108 deletions(-) diff --git a/README.md b/README.md index 2cb2d618..95b4e4f5 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,6 @@ func (m *Stringer) String() string { ret := m.Called() var r0 string - if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() } else { @@ -192,7 +191,6 @@ func (_m *SendFunc) Execute(data string) (int, error) { var r0 int var r1 error - if rf, ok := ret.Get(0).(func(string) (int, error); ok { r0, r1 = rf(data) } else { diff --git a/mocks/pkg/fixtures/A.go b/mocks/pkg/fixtures/A.go index ab30ee2f..71a237ca 100644 --- a/mocks/pkg/fixtures/A.go +++ b/mocks/pkg/fixtures/A.go @@ -18,7 +18,6 @@ func (_m *A) Call() (test.B, error) { var r0 test.B var r1 error - if rf, ok := ret.Get(0).(func() (test.B, error)); ok { r0, r1 = rf() } else { diff --git a/mocks/pkg/fixtures/AsyncProducer.go b/mocks/pkg/fixtures/AsyncProducer.go index 3c9d87d3..b8cc9453 100644 --- a/mocks/pkg/fixtures/AsyncProducer.go +++ b/mocks/pkg/fixtures/AsyncProducer.go @@ -14,7 +14,6 @@ func (_m *AsyncProducer) Input() chan<- bool { ret := _m.Called() var r0 chan<- bool - if rf, ok := ret.Get(0).(func() chan<- bool); ok { r0 = rf() } else { @@ -31,7 +30,6 @@ func (_m *AsyncProducer) Output() <-chan bool { ret := _m.Called() var r0 <-chan bool - if rf, ok := ret.Get(0).(func() <-chan bool); ok { r0 = rf() } else { @@ -48,7 +46,6 @@ func (_m *AsyncProducer) Whatever() chan bool { ret := _m.Called() var r0 chan bool - if rf, ok := ret.Get(0).(func() chan bool); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/Blank.go b/mocks/pkg/fixtures/Blank.go index 2d5f097b..ed681cc8 100644 --- a/mocks/pkg/fixtures/Blank.go +++ b/mocks/pkg/fixtures/Blank.go @@ -14,7 +14,6 @@ func (_m *Blank) Create(x interface{}) error { ret := _m.Called(x) var r0 error - if rf, ok := ret.Get(0).(func(interface{}) error); ok { r0 = rf(x) } else { diff --git a/mocks/pkg/fixtures/ConsulLock.go b/mocks/pkg/fixtures/ConsulLock.go index f19baba4..4c271746 100644 --- a/mocks/pkg/fixtures/ConsulLock.go +++ b/mocks/pkg/fixtures/ConsulLock.go @@ -15,7 +15,6 @@ func (_m *ConsulLock) Lock(_a0 <-chan struct{}) (<-chan struct{}, error) { var r0 <-chan struct{} var r1 error - if rf, ok := ret.Get(0).(func(<-chan struct{}) (<-chan struct{}, error)); ok { r0, r1 = rf(_a0) } else { @@ -42,7 +41,6 @@ func (_m *ConsulLock) Unlock() error { ret := _m.Called() var r0 error - if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/EmbeddedGet.go b/mocks/pkg/fixtures/EmbeddedGet.go index 0dce0689..dfef71f8 100644 --- a/mocks/pkg/fixtures/EmbeddedGet.go +++ b/mocks/pkg/fixtures/EmbeddedGet.go @@ -17,7 +17,6 @@ func (_m *EmbeddedGet[T]) Get() T { ret := _m.Called() var r0 T - if rf, ok := ret.Get(0).(func() T); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/Example.go b/mocks/pkg/fixtures/Example.go index 51d18afa..db089172 100644 --- a/mocks/pkg/fixtures/Example.go +++ b/mocks/pkg/fixtures/Example.go @@ -20,7 +20,6 @@ func (_m *Example) A() http.Flusher { ret := _m.Called() var r0 http.Flusher - if rf, ok := ret.Get(0).(func() http.Flusher); ok { r0 = rf() } else { @@ -37,7 +36,6 @@ func (_m *Example) B(_a0 string) fixtureshttp.MyStruct { ret := _m.Called(_a0) var r0 fixtureshttp.MyStruct - if rf, ok := ret.Get(0).(func(string) fixtureshttp.MyStruct); ok { r0 = rf(_a0) } else { diff --git a/mocks/pkg/fixtures/Expecter.go b/mocks/pkg/fixtures/Expecter.go index c65fcf6c..5b32d84e 100644 --- a/mocks/pkg/fixtures/Expecter.go +++ b/mocks/pkg/fixtures/Expecter.go @@ -23,7 +23,6 @@ func (_m *Expecter) ManyArgsReturns(str string, i int) ([]string, error) { var r0 []string var r1 error - if rf, ok := ret.Get(0).(func(string, int) ([]string, error)); ok { r0, r1 = rf(str, i) } else { @@ -79,7 +78,6 @@ func (_m *Expecter) NoArg() string { ret := _m.Called() var r0 string - if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() } else { @@ -160,7 +158,6 @@ func (_m *Expecter) Variadic(ints ...int) error { ret := _m.Called(_ca...) var r0 error - if rf, ok := ret.Get(0).(func(...int) error); ok { r0 = rf(ints...) } else { @@ -213,7 +210,6 @@ func (_m *Expecter) VariadicMany(i int, a string, intfs ...interface{}) error { ret := _m.Called(_ca...) var r0 error - if rf, ok := ret.Get(0).(func(int, string, ...interface{}) error); ok { r0 = rf(i, a, intfs...) } else { diff --git a/mocks/pkg/fixtures/Fooer.go b/mocks/pkg/fixtures/Fooer.go index ec06181a..1eb1eeff 100644 --- a/mocks/pkg/fixtures/Fooer.go +++ b/mocks/pkg/fixtures/Fooer.go @@ -19,7 +19,6 @@ func (_m *Fooer) Baz(path string) func(string) string { ret := _m.Called(path) var r0 func(string) string - if rf, ok := ret.Get(0).(func(string) func(string) string); ok { r0 = rf(path) } else { @@ -36,7 +35,6 @@ func (_m *Fooer) Foo(f func(string) string) error { ret := _m.Called(f) var r0 error - if rf, ok := ret.Get(0).(func(func(string) string) error); ok { r0 = rf(f) } else { diff --git a/mocks/pkg/fixtures/FuncArgsCollision.go b/mocks/pkg/fixtures/FuncArgsCollision.go index 905e23bf..6ecbf5c2 100644 --- a/mocks/pkg/fixtures/FuncArgsCollision.go +++ b/mocks/pkg/fixtures/FuncArgsCollision.go @@ -14,7 +14,6 @@ func (_m *FuncArgsCollision) Foo(ret interface{}) error { ret_1 := _m.Called(ret) var r0 error - if rf, ok := ret_1.Get(0).(func(interface{}) error); ok { r0 = rf(ret) } else { diff --git a/mocks/pkg/fixtures/GetGeneric.go b/mocks/pkg/fixtures/GetGeneric.go index 81789778..9b8079f4 100644 --- a/mocks/pkg/fixtures/GetGeneric.go +++ b/mocks/pkg/fixtures/GetGeneric.go @@ -17,7 +17,6 @@ func (_m *GetGeneric[T]) Get() T { ret := _m.Called() var r0 T - if rf, ok := ret.Get(0).(func() T); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/GetInt.go b/mocks/pkg/fixtures/GetInt.go index 41dbc475..545a5997 100644 --- a/mocks/pkg/fixtures/GetInt.go +++ b/mocks/pkg/fixtures/GetInt.go @@ -14,7 +14,6 @@ func (_m *GetInt) Get() int { ret := _m.Called() var r0 int - if rf, ok := ret.Get(0).(func() int); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/HasConflictingNestedImports.go b/mocks/pkg/fixtures/HasConflictingNestedImports.go index dd523ef4..af6ff12f 100644 --- a/mocks/pkg/fixtures/HasConflictingNestedImports.go +++ b/mocks/pkg/fixtures/HasConflictingNestedImports.go @@ -21,7 +21,6 @@ func (_m *HasConflictingNestedImports) Get(path string) (http.Response, error) { var r0 http.Response var r1 error - if rf, ok := ret.Get(0).(func(string) (http.Response, error)); ok { r0, r1 = rf(path) } else { @@ -46,7 +45,6 @@ func (_m *HasConflictingNestedImports) Z() fixtureshttp.MyStruct { ret := _m.Called() var r0 fixtureshttp.MyStruct - if rf, ok := ret.Get(0).(func() fixtureshttp.MyStruct); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/ImportsSameAsPackage.go b/mocks/pkg/fixtures/ImportsSameAsPackage.go index 836f2b53..ff177399 100644 --- a/mocks/pkg/fixtures/ImportsSameAsPackage.go +++ b/mocks/pkg/fixtures/ImportsSameAsPackage.go @@ -19,7 +19,6 @@ func (_m *ImportsSameAsPackage) A() test.B { ret := _m.Called() var r0 test.B - if rf, ok := ret.Get(0).(func() test.B); ok { r0 = rf() } else { @@ -34,7 +33,6 @@ func (_m *ImportsSameAsPackage) B() fixtures.KeyManager { ret := _m.Called() var r0 fixtures.KeyManager - if rf, ok := ret.Get(0).(func() fixtures.KeyManager); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/KeyManager.go b/mocks/pkg/fixtures/KeyManager.go index beb27af6..26763dc8 100644 --- a/mocks/pkg/fixtures/KeyManager.go +++ b/mocks/pkg/fixtures/KeyManager.go @@ -18,7 +18,6 @@ func (_m *KeyManager) GetKey(_a0 string, _a1 uint16) ([]byte, *test.Err) { var r0 []byte var r1 *test.Err - if rf, ok := ret.Get(0).(func(string, uint16) ([]byte, *test.Err)); ok { r0, r1 = rf(_a0, _a1) } else { diff --git a/mocks/pkg/fixtures/MapFunc.go b/mocks/pkg/fixtures/MapFunc.go index a3db6ee9..eff10a3c 100644 --- a/mocks/pkg/fixtures/MapFunc.go +++ b/mocks/pkg/fixtures/MapFunc.go @@ -14,7 +14,6 @@ func (_m *MapFunc) Get(m map[string]func(string) string) error { ret := _m.Called(m) var r0 error - if rf, ok := ret.Get(0).(func(map[string]func(string) string) error); ok { r0 = rf(m) } else { diff --git a/mocks/pkg/fixtures/MyReader.go b/mocks/pkg/fixtures/MyReader.go index 91c2b5a1..432e153d 100644 --- a/mocks/pkg/fixtures/MyReader.go +++ b/mocks/pkg/fixtures/MyReader.go @@ -15,7 +15,6 @@ func (_m *MyReader) Read(p []byte) (int, error) { var r0 int var r1 error - if rf, ok := ret.Get(0).(func([]byte) (int, error)); ok { r0, r1 = rf(p) } else { diff --git a/mocks/pkg/fixtures/Requester.go b/mocks/pkg/fixtures/Requester.go index 36a4b789..7b14175d 100644 --- a/mocks/pkg/fixtures/Requester.go +++ b/mocks/pkg/fixtures/Requester.go @@ -15,7 +15,6 @@ func (_m *Requester) Get(path string) (string, error) { var r0 string var r1 error - if rf, ok := ret.Get(0).(func(string) (string, error)); ok { r0, r1 = rf(path) } else { diff --git a/mocks/pkg/fixtures/Requester2.go b/mocks/pkg/fixtures/Requester2.go index 19237821..f0c20e18 100644 --- a/mocks/pkg/fixtures/Requester2.go +++ b/mocks/pkg/fixtures/Requester2.go @@ -14,7 +14,6 @@ func (_m *Requester2) Get(path string) error { ret := _m.Called(path) var r0 error - if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(path) } else { diff --git a/mocks/pkg/fixtures/Requester3.go b/mocks/pkg/fixtures/Requester3.go index 50b14f89..73b0b027 100644 --- a/mocks/pkg/fixtures/Requester3.go +++ b/mocks/pkg/fixtures/Requester3.go @@ -14,7 +14,6 @@ func (_m *Requester3) Get() error { ret := _m.Called() var r0 error - if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/RequesterArgSameAsImport.go b/mocks/pkg/fixtures/RequesterArgSameAsImport.go index ab297d79..4d783b91 100644 --- a/mocks/pkg/fixtures/RequesterArgSameAsImport.go +++ b/mocks/pkg/fixtures/RequesterArgSameAsImport.go @@ -18,7 +18,6 @@ func (_m *RequesterArgSameAsImport) Get(_a0 string) *json.RawMessage { ret := _m.Called(_a0) var r0 *json.RawMessage - if rf, ok := ret.Get(0).(func(string) *json.RawMessage); ok { r0 = rf(_a0) } else { diff --git a/mocks/pkg/fixtures/RequesterArgSameAsNamedImport.go b/mocks/pkg/fixtures/RequesterArgSameAsNamedImport.go index 4ea698c4..c0c5b782 100644 --- a/mocks/pkg/fixtures/RequesterArgSameAsNamedImport.go +++ b/mocks/pkg/fixtures/RequesterArgSameAsNamedImport.go @@ -18,7 +18,6 @@ func (_m *RequesterArgSameAsNamedImport) Get(_a0 string) *json.RawMessage { ret := _m.Called(_a0) var r0 *json.RawMessage - if rf, ok := ret.Get(0).(func(string) *json.RawMessage); ok { r0 = rf(_a0) } else { diff --git a/mocks/pkg/fixtures/RequesterArray.go b/mocks/pkg/fixtures/RequesterArray.go index 417e7383..c13c073b 100644 --- a/mocks/pkg/fixtures/RequesterArray.go +++ b/mocks/pkg/fixtures/RequesterArray.go @@ -15,7 +15,6 @@ func (_m *RequesterArray) Get(path string) ([2]string, error) { var r0 [2]string var r1 error - if rf, ok := ret.Get(0).(func(string) ([2]string, error)); ok { r0, r1 = rf(path) } else { diff --git a/mocks/pkg/fixtures/RequesterElided.go b/mocks/pkg/fixtures/RequesterElided.go index 0edab572..3af99cb0 100644 --- a/mocks/pkg/fixtures/RequesterElided.go +++ b/mocks/pkg/fixtures/RequesterElided.go @@ -14,7 +14,6 @@ func (_m *RequesterElided) Get(path string, url string) error { ret := _m.Called(path, url) var r0 error - if rf, ok := ret.Get(0).(func(string, string) error); ok { r0 = rf(path, url) } else { diff --git a/mocks/pkg/fixtures/RequesterGenerics.go b/mocks/pkg/fixtures/RequesterGenerics.go index 83f53007..4355e4ea 100644 --- a/mocks/pkg/fixtures/RequesterGenerics.go +++ b/mocks/pkg/fixtures/RequesterGenerics.go @@ -29,7 +29,6 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG var r0 struct { Type2 test.GenericType[string, test.EmbeddedGet[int]] } - if rf, ok := ret.Get(0).(func(struct{ Type1 TExternalIntf }) struct { Type2 test.GenericType[string, test.EmbeddedGet[int]] }); ok { @@ -49,7 +48,6 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG var r0 TSigned var r1 TIntf - if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { r0, r1 = rf(_a0, _a1) } else { @@ -74,7 +72,6 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG ret := _m.Called(_a0) var r0 test.GenericType[TSigned, TIntf] - if rf, ok := ret.Get(0).(func(test.GenericType[TAny, TIntf]) test.GenericType[TSigned, TIntf]); ok { r0 = rf(_a0) } else { diff --git a/mocks/pkg/fixtures/RequesterIface.go b/mocks/pkg/fixtures/RequesterIface.go index 54fe0e98..41d7d7d8 100644 --- a/mocks/pkg/fixtures/RequesterIface.go +++ b/mocks/pkg/fixtures/RequesterIface.go @@ -18,7 +18,6 @@ func (_m *RequesterIface) Get() io.Reader { ret := _m.Called() var r0 io.Reader - if rf, ok := ret.Get(0).(func() io.Reader); ok { r0 = rf() } else { diff --git a/mocks/pkg/fixtures/RequesterNS.go b/mocks/pkg/fixtures/RequesterNS.go index 851384a3..298829e4 100644 --- a/mocks/pkg/fixtures/RequesterNS.go +++ b/mocks/pkg/fixtures/RequesterNS.go @@ -19,7 +19,6 @@ func (_m *RequesterNS) Get(path string) (http.Response, error) { var r0 http.Response var r1 error - if rf, ok := ret.Get(0).(func(string) (http.Response, error)); ok { r0, r1 = rf(path) } else { diff --git a/mocks/pkg/fixtures/RequesterPtr.go b/mocks/pkg/fixtures/RequesterPtr.go index 71d41e4d..215c3ed1 100644 --- a/mocks/pkg/fixtures/RequesterPtr.go +++ b/mocks/pkg/fixtures/RequesterPtr.go @@ -15,7 +15,6 @@ func (_m *RequesterPtr) Get(path string) (*string, error) { var r0 *string var r1 error - if rf, ok := ret.Get(0).(func(string) (*string, error)); ok { r0, r1 = rf(path) } else { diff --git a/mocks/pkg/fixtures/RequesterReturnElided.go b/mocks/pkg/fixtures/RequesterReturnElided.go index 79486247..4bea02a9 100644 --- a/mocks/pkg/fixtures/RequesterReturnElided.go +++ b/mocks/pkg/fixtures/RequesterReturnElided.go @@ -25,7 +25,6 @@ func (_m *RequesterReturnElided) Get(path string) (int, int, int, error) { var r1 int var r2 int var r3 error - if rf, ok := ret.Get(0).(func(string) (int, int, int, error)); ok { r0, r1, r2, r3 = rf(path) } else { @@ -91,7 +90,6 @@ func (_m *RequesterReturnElided) Put(path string) (int, error) { var r0 int var r1 error - if rf, ok := ret.Get(0).(func(string) (int, error)); ok { r0, r1 = rf(path) } else { diff --git a/mocks/pkg/fixtures/RequesterSlice.go b/mocks/pkg/fixtures/RequesterSlice.go index 83bd9005..2ad02e70 100644 --- a/mocks/pkg/fixtures/RequesterSlice.go +++ b/mocks/pkg/fixtures/RequesterSlice.go @@ -15,7 +15,6 @@ func (_m *RequesterSlice) Get(path string) ([]string, error) { var r0 []string var r1 error - if rf, ok := ret.Get(0).(func(string) ([]string, error)); ok { r0, r1 = rf(path) } else { diff --git a/mocks/pkg/fixtures/RequesterVariadic.go b/mocks/pkg/fixtures/RequesterVariadic.go index 5196eb97..a5359e70 100644 --- a/mocks/pkg/fixtures/RequesterVariadic.go +++ b/mocks/pkg/fixtures/RequesterVariadic.go @@ -24,7 +24,6 @@ func (_m *RequesterVariadic) Get(values ...string) bool { ret := _m.Called(_ca...) var r0 bool - if rf, ok := ret.Get(0).(func(...string) bool); ok { r0 = rf(values...) } else { @@ -46,7 +45,6 @@ func (_m *RequesterVariadic) MultiWriteToFile(filename string, w ...io.Writer) s ret := _m.Called(_ca...) var r0 string - if rf, ok := ret.Get(0).(func(string, ...io.Writer) string); ok { r0 = rf(filename, w...) } else { @@ -63,7 +61,6 @@ func (_m *RequesterVariadic) OneInterface(a ...interface{}) bool { ret := _m.Called(_ca...) var r0 bool - if rf, ok := ret.Get(0).(func(...interface{}) bool); ok { r0 = rf(a...) } else { @@ -81,7 +78,6 @@ func (_m *RequesterVariadic) Sprintf(format string, a ...interface{}) string { ret := _m.Called(_ca...) var r0 string - if rf, ok := ret.Get(0).(func(string, ...interface{}) string); ok { r0 = rf(format, a...) } else { diff --git a/mocks/pkg/fixtures/RequesterVariadicOneArgument.go b/mocks/pkg/fixtures/RequesterVariadicOneArgument.go index dc98715c..f9cf19a7 100644 --- a/mocks/pkg/fixtures/RequesterVariadicOneArgument.go +++ b/mocks/pkg/fixtures/RequesterVariadicOneArgument.go @@ -18,7 +18,6 @@ func (_m *RequesterVariadicOneArgument) Get(values ...string) bool { ret := _m.Called(values) var r0 bool - if rf, ok := ret.Get(0).(func(...string) bool); ok { r0 = rf(values...) } else { @@ -33,7 +32,6 @@ func (_m *RequesterVariadicOneArgument) MultiWriteToFile(filename string, w ...i ret := _m.Called(filename, w) var r0 string - if rf, ok := ret.Get(0).(func(string, ...io.Writer) string); ok { r0 = rf(filename, w...) } else { @@ -48,7 +46,6 @@ func (_m *RequesterVariadicOneArgument) OneInterface(a ...interface{}) bool { ret := _m.Called(a) var r0 bool - if rf, ok := ret.Get(0).(func(...interface{}) bool); ok { r0 = rf(a...) } else { @@ -63,7 +60,6 @@ func (_m *RequesterVariadicOneArgument) Sprintf(format string, a ...interface{}) ret := _m.Called(format, a) var r0 string - if rf, ok := ret.Get(0).(func(string, ...interface{}) string); ok { r0 = rf(format, a...) } else { diff --git a/mocks/pkg/fixtures/SendFunc.go b/mocks/pkg/fixtures/SendFunc.go index 77fdb2cd..9206bf74 100644 --- a/mocks/pkg/fixtures/SendFunc.go +++ b/mocks/pkg/fixtures/SendFunc.go @@ -19,7 +19,6 @@ func (_m *SendFunc) Execute(ctx context.Context, data string) (int, error) { var r0 int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string) (int, error)); ok { r0, r1 = rf(ctx, data) } else { diff --git a/mocks/pkg/fixtures/buildtag/comment/IfaceWithBuildTagInComment.go b/mocks/pkg/fixtures/buildtag/comment/IfaceWithBuildTagInComment.go index 4b3727cb..8dc5d76a 100644 --- a/mocks/pkg/fixtures/buildtag/comment/IfaceWithBuildTagInComment.go +++ b/mocks/pkg/fixtures/buildtag/comment/IfaceWithBuildTagInComment.go @@ -17,7 +17,6 @@ func (_m *IfaceWithBuildTagInComment) Sprintf(format string, a ...interface{}) s ret := _m.Called(_ca...) var r0 string - if rf, ok := ret.Get(0).(func(string, ...interface{}) string); ok { r0 = rf(format, a...) } else { diff --git a/mocks/pkg/fixtures/buildtag/filename/IfaceWithBuildTagInFilename.go b/mocks/pkg/fixtures/buildtag/filename/IfaceWithBuildTagInFilename.go index f690e6ce..8060c7c3 100644 --- a/mocks/pkg/fixtures/buildtag/filename/IfaceWithBuildTagInFilename.go +++ b/mocks/pkg/fixtures/buildtag/filename/IfaceWithBuildTagInFilename.go @@ -17,7 +17,6 @@ func (_m *IfaceWithBuildTagInFilename) Sprintf(format string, a ...interface{}) ret := _m.Called(_ca...) var r0 string - if rf, ok := ret.Get(0).(func(string, ...interface{}) string); ok { r0 = rf(format, a...) } else { diff --git a/mocks/pkg/fixtures/example_project/Root.go b/mocks/pkg/fixtures/example_project/Root.go index 422f8f46..70bc600b 100644 --- a/mocks/pkg/fixtures/example_project/Root.go +++ b/mocks/pkg/fixtures/example_project/Root.go @@ -18,7 +18,6 @@ func (_m *Root) ReturnsFoo() (foo.Foo, error) { var r0 foo.Foo var r1 error - if rf, ok := ret.Get(0).(func() (foo.Foo, error)); ok { r0, r1 = rf() } else { diff --git a/mocks/pkg/fixtures/example_project/bar/foo/Client.go b/mocks/pkg/fixtures/example_project/bar/foo/Client.go index 98c8e2ab..00bef26b 100644 --- a/mocks/pkg/fixtures/example_project/bar/foo/Client.go +++ b/mocks/pkg/fixtures/example_project/bar/foo/Client.go @@ -15,7 +15,6 @@ func (_m *Client) Search(query string) ([]string, error) { var r0 []string var r1 error - if rf, ok := ret.Get(0).(func(string) ([]string, error)); ok { r0, r1 = rf(query) } else { diff --git a/mocks/pkg/fixtures/example_project/foo/Foo.go b/mocks/pkg/fixtures/example_project/foo/Foo.go index 7f056c48..317b8d54 100644 --- a/mocks/pkg/fixtures/example_project/foo/Foo.go +++ b/mocks/pkg/fixtures/example_project/foo/Foo.go @@ -17,7 +17,6 @@ func (_m *Foo) DoFoo() string { ret := _m.Called() var r0 string - if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() } else { @@ -33,7 +32,6 @@ func (_m *Foo) GetBaz() (*foo.Baz, error) { var r0 *foo.Baz var r1 error - if rf, ok := ret.Get(0).(func() (*foo.Baz, error)); ok { r0, r1 = rf() } else { diff --git a/mocks/pkg/fixtures/example_project/foo/PackageNameSameAsImport.go b/mocks/pkg/fixtures/example_project/foo/PackageNameSameAsImport.go index 9c7263c1..54278823 100644 --- a/mocks/pkg/fixtures/example_project/foo/PackageNameSameAsImport.go +++ b/mocks/pkg/fixtures/example_project/foo/PackageNameSameAsImport.go @@ -17,7 +17,6 @@ func (_m *PackageNameSameAsImport) NewClient() foo.Client { ret := _m.Called() var r0 foo.Client - if rf, ok := ret.Get(0).(func() foo.Client); ok { r0 = rf() } else { diff --git a/pkg/generator.go b/pkg/generator.go index f838ea79..62865cfe 100644 --- a/pkg/generator.go +++ b/pkg/generator.go @@ -615,8 +615,6 @@ func (g *Generator) Generate(ctx context.Context) error { g.printf("\tvar r%d %s\n", idx, typ) } - g.printf("\n") - var tab string if len(returns.Types) > 1 { tab = "\t" diff --git a/pkg/generator_test.go b/pkg/generator_test.go index d58b33c1..d324bb76 100644 --- a/pkg/generator_test.go +++ b/pkg/generator_test.go @@ -128,7 +128,6 @@ func (_m *Requester) Get(path string) (string, error) { var r0 string var r1 error - if rf, ok := ret.Get(0).(func(string) (string, error)); ok { r0, r1 = rf(path) } else { @@ -186,7 +185,6 @@ func (_m *Requester) Get(path string) (string, error) { var r0 string var r1 error - if rf, ok := ret.Get(0).(func(string) (string, error)); ok { r0, r1 = rf(path) } else { @@ -277,7 +275,6 @@ func (_m *Expecter) ManyArgsReturns(str string, i int) ([]string, error) { var r0 []string var r1 error - if rf, ok := ret.Get(0).(func(string, int) ([]string, error)); ok { r0, r1 = rf(str, i) } else { @@ -333,7 +330,6 @@ func (_m *Expecter) NoArg() string { ret := _m.Called() var r0 string - if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() } else { @@ -414,7 +410,6 @@ func (_m *Expecter) Variadic(ints ...int) error { ret := _m.Called(_ca...) var r0 error - if rf, ok := ret.Get(0).(func(...int) error); ok { r0 = rf(ints...) } else { @@ -467,7 +462,6 @@ func (_m *Expecter) VariadicMany(i int, a string, intfs ...interface{}) error { ret := _m.Called(_ca...) var r0 error - if rf, ok := ret.Get(0).(func(int, string, ...interface{}) error); ok { r0 = rf(i, a, intfs...) } else { @@ -561,7 +555,6 @@ func (_m *SendFunc) Execute(ctx context.Context, data string) (int, error) { var r0 int var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string) (int, error)); ok { r0, r1 = rf(ctx, data) } else { @@ -610,7 +603,6 @@ func (_m *Requester2) Get(path string) error { ret := _m.Called(path) var r0 error - if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(path) } else { @@ -649,7 +641,6 @@ func (_m *Requester3) Get() error { ret := _m.Called() var r0 error - if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() } else { @@ -934,7 +925,6 @@ func (_m *RequesterIface) Get() io.Reader { ret := _m.Called() var r0 io.Reader - if rf, ok := ret.Get(0).(func() io.Reader); ok { r0 = rf() } else { @@ -976,7 +966,6 @@ func (_m *RequesterPtr) Get(path string) (*string, error) { var r0 *string var r1 error - if rf, ok := ret.Get(0).(func(string) (*string, error)); ok { r0, r1 = rf(path) } else { @@ -1028,7 +1017,6 @@ func (_m *RequesterSlice) Get(path string) ([]string, error) { var r0 []string var r1 error - if rf, ok := ret.Get(0).(func(string) ([]string, error)); ok { r0, r1 = rf(path) } else { @@ -1080,7 +1068,6 @@ func (_m *RequesterArray) Get(path string) ([2]string, error) { var r0 [2]string var r1 error - if rf, ok := ret.Get(0).(func(string) ([2]string, error)); ok { r0, r1 = rf(path) } else { @@ -1132,7 +1119,6 @@ func (_m *RequesterNS) Get(path string) (http.Response, error) { var r0 http.Response var r1 error - if rf, ok := ret.Get(0).(func(string) (http.Response, error)); ok { r0, r1 = rf(path) } else { @@ -1181,7 +1167,6 @@ func (_m *RequesterArgSameAsImport) Get(_a0 string) *json.RawMessage { ret := _m.Called(_a0) var r0 *json.RawMessage - if rf, ok := ret.Get(0).(func(string) *json.RawMessage); ok { r0 = rf(_a0) } else { @@ -1222,7 +1207,6 @@ func (_m *RequesterArgSameAsNamedImport) Get(_a0 string) *json.RawMessage { ret := _m.Called(_a0) var r0 *json.RawMessage - if rf, ok := ret.Get(0).(func(string) *json.RawMessage); ok { r0 = rf(_a0) } else { @@ -1293,7 +1277,6 @@ func (_m *KeyManager) GetKey(_a0 string, _a1 uint16) ([]byte, *test.Err) { var r0 []byte var r1 *test.Err - if rf, ok := ret.Get(0).(func(string, uint16) ([]byte, *test.Err)); ok { r0, r1 = rf(_a0, _a1) } else { @@ -1346,7 +1329,6 @@ func (_m *RequesterElided) Get(path string, url string) error { ret := _m.Called(path, url) var r0 error - if rf, ok := ret.Get(0).(func(string, string) error); ok { r0 = rf(path, url) } else { @@ -1396,7 +1378,6 @@ func (_m *RequesterReturnElided) Get(path string) (int, int, int, error) { var r1 int var r2 int var r3 error - if rf, ok := ret.Get(0).(func(string) (int, int, int, error)); ok { r0, r1, r2, r3 = rf(path) } else { @@ -1462,7 +1443,6 @@ func (_m *RequesterReturnElided) Put(path string) (int, error) { var r0 int var r1 error - if rf, ok := ret.Get(0).(func(string) (int, error)); ok { r0, r1 = rf(path) } else { @@ -1673,7 +1653,6 @@ func (_m *Fooer) Baz(path string) func(string) string { ret := _m.Called(path) var r0 func(string) string - if rf, ok := ret.Get(0).(func(string) func(string) string); ok { r0 = rf(path) } else { @@ -1690,7 +1669,6 @@ func (_m *Fooer) Foo(f func(string) string) error { ret := _m.Called(f) var r0 error - if rf, ok := ret.Get(0).(func(func(string) string) error); ok { r0 = rf(f) } else { @@ -1729,7 +1707,6 @@ func (_m *AsyncProducer) Input() chan<- bool { ret := _m.Called() var r0 chan<- bool - if rf, ok := ret.Get(0).(func() chan<- bool); ok { r0 = rf() } else { @@ -1746,7 +1723,6 @@ func (_m *AsyncProducer) Output() <-chan bool { ret := _m.Called() var r0 <-chan bool - if rf, ok := ret.Get(0).(func() <-chan bool); ok { r0 = rf() } else { @@ -1763,7 +1739,6 @@ func (_m *AsyncProducer) Whatever() chan bool { ret := _m.Called() var r0 chan bool - if rf, ok := ret.Get(0).(func() chan bool); ok { r0 = rf() } else { @@ -1805,7 +1780,6 @@ func (_m *MyReader) Read(p []byte) (int, error) { var r0 int var r1 error - if rf, ok := ret.Get(0).(func([]byte) (int, error)); ok { r0, r1 = rf(p) } else { @@ -1855,7 +1829,6 @@ func (_m *ConsulLock) Lock(_a0 <-chan struct{}) (<-chan struct{}, error) { var r0 <-chan struct{} var r1 error - if rf, ok := ret.Get(0).(func(<-chan struct{}) (<-chan struct{}, error)); ok { r0, r1 = rf(_a0) } else { @@ -1882,7 +1855,6 @@ func (_m *ConsulLock) Unlock() error { ret := _m.Called() var r0 error - if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() } else { @@ -1921,7 +1893,6 @@ func (_m *Blank) Create(x interface{}) error { ret := _m.Called(x) var r0 error - if rf, ok := ret.Get(0).(func(interface{}) error); ok { r0 = rf(x) } else { @@ -1960,7 +1931,6 @@ func (_m *MapFunc) Get(m map[string]func(string) string) error { ret := _m.Called(m) var r0 error - if rf, ok := ret.Get(0).(func(map[string]func(string) string) error); ok { r0 = rf(m) } else { @@ -2057,7 +2027,6 @@ func (_m *Example) A() http.Flusher { ret := _m.Called() var r0 http.Flusher - if rf, ok := ret.Get(0).(func() http.Flusher); ok { r0 = rf() } else { @@ -2074,7 +2043,6 @@ func (_m *Example) B(_a0 string) fixtureshttp.MyStruct { ret := _m.Called(_a0) var r0 fixtureshttp.MyStruct - if rf, ok := ret.Get(0).(func(string) fixtureshttp.MyStruct); ok { r0 = rf(_a0) } else { @@ -2159,7 +2127,6 @@ func (_m *FuncArgsCollision) Foo(ret interface{}) error { ret_1 := _m.Called(ret) var r0 error - if rf, ok := ret_1.Get(0).(func(interface{}) error); ok { r0 = rf(ret) } else { @@ -2198,7 +2165,6 @@ func (_m *ImportsSameAsPackage) A() test.B { ret := _m.Called() var r0 test.B - if rf, ok := ret.Get(0).(func() test.B); ok { r0 = rf() } else { @@ -2213,7 +2179,6 @@ func (_m *ImportsSameAsPackage) B() fixtures.KeyManager { ret := _m.Called() var r0 fixtures.KeyManager - if rf, ok := ret.Get(0).(func() fixtures.KeyManager); ok { r0 = rf() } else { @@ -2319,7 +2284,6 @@ func (_m *A) Call() (test.B, error) { var r0 test.B var r1 error - if rf, ok := ret.Get(0).(func() (test.B, error)); ok { r0, r1 = rf() } else { @@ -2368,7 +2332,6 @@ func (_m *Requester2OverrideName) Get(path string) error { ret := _m.Called(path) var r0 error - if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(path) } else { @@ -2480,7 +2443,6 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG var r0 struct { Type2 test.GenericType[string, test.EmbeddedGet[int]] } - if rf, ok := ret.Get(0).(func(struct{ Type1 TExternalIntf }) struct { Type2 test.GenericType[string, test.EmbeddedGet[int]] }); ok { @@ -2500,7 +2462,6 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG var r0 TSigned var r1 TIntf - if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { r0, r1 = rf(_a0, _a1) } else { @@ -2525,7 +2486,6 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG ret := _m.Called(_a0) var r0 test.GenericType[TSigned, TIntf] - if rf, ok := ret.Get(0).(func(test.GenericType[TAny, TIntf]) test.GenericType[TSigned, TIntf]); ok { r0 = rf(_a0) } else { @@ -2585,7 +2545,6 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG var r0 struct { Type2 test.GenericType[string, test.EmbeddedGet[int]] } - if rf, ok := ret.Get(0).(func(struct{ Type1 TExternalIntf }) struct { Type2 test.GenericType[string, test.EmbeddedGet[int]] }); ok { @@ -2640,7 +2599,6 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG var r0 TSigned var r1 TIntf - if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { r0, r1 = rf(_a0, _a1) } else { @@ -2697,7 +2655,6 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG ret := _m.Called(_a0) var r0 test.GenericType[TSigned, TIntf] - if rf, ok := ret.Get(0).(func(test.GenericType[TAny, TIntf]) test.GenericType[TSigned, TIntf]); ok { r0 = rf(_a0) } else { @@ -2782,7 +2739,6 @@ func (_m *MockRequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf var r0 struct { Type2 GenericType[string, EmbeddedGet[int]] } - if rf, ok := ret.Get(0).(func(struct{ Type1 TExternalIntf }) struct { Type2 GenericType[string, EmbeddedGet[int]] }); ok { @@ -2802,7 +2758,6 @@ func (_m *MockRequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf var r0 TSigned var r1 TIntf - if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { r0, r1 = rf(_a0, _a1) } else { @@ -2827,7 +2782,6 @@ func (_m *MockRequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf ret := _m.Called(_a0) var r0 GenericType[TSigned, TIntf] - if rf, ok := ret.Get(0).(func(GenericType[TAny, TIntf]) GenericType[TSigned, TIntf]); ok { r0 = rf(_a0) } else { From 2e95447e72f0ae4b2fc8112ce29900998e637cfe Mon Sep 17 00:00:00 2001 From: Dave Wyatt Date: Thu, 9 Feb 2023 17:10:15 -0500 Subject: [PATCH 3/5] Use template to generate mock methods --- mocks/pkg/fixtures/A.go | 23 +- mocks/pkg/fixtures/ConsulLock.go | 23 +- mocks/pkg/fixtures/Expecter.go | 23 +- .../fixtures/HasConflictingNestedImports.go | 23 +- mocks/pkg/fixtures/KeyManager.go | 25 +- mocks/pkg/fixtures/MyReader.go | 23 +- mocks/pkg/fixtures/Requester.go | 23 +- mocks/pkg/fixtures/RequesterArray.go | 23 +- mocks/pkg/fixtures/RequesterGenerics.go | 23 +- mocks/pkg/fixtures/RequesterNS.go | 23 +- mocks/pkg/fixtures/RequesterPtr.go | 23 +- mocks/pkg/fixtures/RequesterReturnElided.go | 70 ++-- mocks/pkg/fixtures/RequesterSlice.go | 23 +- mocks/pkg/fixtures/SendFunc.go | 23 +- mocks/pkg/fixtures/example_project/Root.go | 23 +- .../example_project/bar/foo/Client.go | 23 +- mocks/pkg/fixtures/example_project/foo/Foo.go | 23 +- pkg/generator.go | 258 ++++++------ pkg/generator_test.go | 391 +++++++++--------- 19 files changed, 528 insertions(+), 561 deletions(-) diff --git a/mocks/pkg/fixtures/A.go b/mocks/pkg/fixtures/A.go index 71a237ca..e1cc4d55 100644 --- a/mocks/pkg/fixtures/A.go +++ b/mocks/pkg/fixtures/A.go @@ -19,19 +19,18 @@ func (_m *A) Call() (test.B, error) { var r0 test.B var r1 error if rf, ok := ret.Get(0).(func() (test.B, error)); ok { - r0, r1 = rf() + return rf() + } + if rf, ok := ret.Get(0).(func() test.B); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(test.B) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() } else { - if rf, ok := ret.Get(0).(func() test.B); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(test.B) - } - - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } + r1 = ret.Error(1) } return r0, r1 diff --git a/mocks/pkg/fixtures/ConsulLock.go b/mocks/pkg/fixtures/ConsulLock.go index 4c271746..d2b30cf7 100644 --- a/mocks/pkg/fixtures/ConsulLock.go +++ b/mocks/pkg/fixtures/ConsulLock.go @@ -16,21 +16,20 @@ func (_m *ConsulLock) Lock(_a0 <-chan struct{}) (<-chan struct{}, error) { var r0 <-chan struct{} var r1 error if rf, ok := ret.Get(0).(func(<-chan struct{}) (<-chan struct{}, error)); ok { - r0, r1 = rf(_a0) + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(<-chan struct{}) <-chan struct{}); ok { + r0 = rf(_a0) } else { - if rf, ok := ret.Get(0).(func(<-chan struct{}) <-chan struct{}); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(<-chan struct{}) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).(<-chan struct{}) } + } - if rf, ok := ret.Get(1).(func(<-chan struct{}) error); ok { - r1 = rf(_a0) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(<-chan struct{}) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) } return r0, r1 diff --git a/mocks/pkg/fixtures/Expecter.go b/mocks/pkg/fixtures/Expecter.go index 5b32d84e..de53ab26 100644 --- a/mocks/pkg/fixtures/Expecter.go +++ b/mocks/pkg/fixtures/Expecter.go @@ -24,21 +24,20 @@ func (_m *Expecter) ManyArgsReturns(str string, i int) ([]string, error) { var r0 []string var r1 error if rf, ok := ret.Get(0).(func(string, int) ([]string, error)); ok { - r0, r1 = rf(str, i) + return rf(str, i) + } + if rf, ok := ret.Get(0).(func(string, int) []string); ok { + r0 = rf(str, i) } else { - if rf, ok := ret.Get(0).(func(string, int) []string); ok { - r0 = rf(str, i) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) } + } - if rf, ok := ret.Get(1).(func(string, int) error); ok { - r1 = rf(str, i) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(string, int) error); ok { + r1 = rf(str, i) + } else { + r1 = ret.Error(1) } return r0, r1 diff --git a/mocks/pkg/fixtures/HasConflictingNestedImports.go b/mocks/pkg/fixtures/HasConflictingNestedImports.go index af6ff12f..1557690a 100644 --- a/mocks/pkg/fixtures/HasConflictingNestedImports.go +++ b/mocks/pkg/fixtures/HasConflictingNestedImports.go @@ -22,19 +22,18 @@ func (_m *HasConflictingNestedImports) Get(path string) (http.Response, error) { var r0 http.Response var r1 error if rf, ok := ret.Get(0).(func(string) (http.Response, error)); ok { - r0, r1 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) http.Response); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(http.Response) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) http.Response); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(http.Response) - } - - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } + r1 = ret.Error(1) } return r0, r1 diff --git a/mocks/pkg/fixtures/KeyManager.go b/mocks/pkg/fixtures/KeyManager.go index 26763dc8..5f8fda3d 100644 --- a/mocks/pkg/fixtures/KeyManager.go +++ b/mocks/pkg/fixtures/KeyManager.go @@ -19,22 +19,21 @@ func (_m *KeyManager) GetKey(_a0 string, _a1 uint16) ([]byte, *test.Err) { var r0 []byte var r1 *test.Err if rf, ok := ret.Get(0).(func(string, uint16) ([]byte, *test.Err)); ok { - r0, r1 = rf(_a0, _a1) + return rf(_a0, _a1) + } + if rf, ok := ret.Get(0).(func(string, uint16) []byte); ok { + r0 = rf(_a0, _a1) } else { - if rf, ok := ret.Get(0).(func(string, uint16) []byte); ok { - r0 = rf(_a0, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) } + } - if rf, ok := ret.Get(1).(func(string, uint16) *test.Err); ok { - r1 = rf(_a0, _a1) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*test.Err) - } + if rf, ok := ret.Get(1).(func(string, uint16) *test.Err); ok { + r1 = rf(_a0, _a1) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*test.Err) } } diff --git a/mocks/pkg/fixtures/MyReader.go b/mocks/pkg/fixtures/MyReader.go index 432e153d..ddcde557 100644 --- a/mocks/pkg/fixtures/MyReader.go +++ b/mocks/pkg/fixtures/MyReader.go @@ -16,19 +16,18 @@ func (_m *MyReader) Read(p []byte) (int, error) { var r0 int var r1 error if rf, ok := ret.Get(0).(func([]byte) (int, error)); ok { - r0, r1 = rf(p) + return rf(p) + } + if rf, ok := ret.Get(0).(func([]byte) int); ok { + r0 = rf(p) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func([]byte) error); ok { + r1 = rf(p) } else { - if rf, ok := ret.Get(0).(func([]byte) int); ok { - r0 = rf(p) - } else { - r0 = ret.Get(0).(int) - } - - if rf, ok := ret.Get(1).(func([]byte) error); ok { - r1 = rf(p) - } else { - r1 = ret.Error(1) - } + r1 = ret.Error(1) } return r0, r1 diff --git a/mocks/pkg/fixtures/Requester.go b/mocks/pkg/fixtures/Requester.go index 7b14175d..97b8eaba 100644 --- a/mocks/pkg/fixtures/Requester.go +++ b/mocks/pkg/fixtures/Requester.go @@ -16,19 +16,18 @@ func (_m *Requester) Get(path string) (string, error) { var r0 string var r1 error if rf, ok := ret.Get(0).(func(string) (string, error)); ok { - r0, r1 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) string); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(string) - } - - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } + r1 = ret.Error(1) } return r0, r1 diff --git a/mocks/pkg/fixtures/RequesterArray.go b/mocks/pkg/fixtures/RequesterArray.go index c13c073b..a3f27ec5 100644 --- a/mocks/pkg/fixtures/RequesterArray.go +++ b/mocks/pkg/fixtures/RequesterArray.go @@ -16,21 +16,20 @@ func (_m *RequesterArray) Get(path string) ([2]string, error) { var r0 [2]string var r1 error if rf, ok := ret.Get(0).(func(string) ([2]string, error)); ok { - r0, r1 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) [2]string); ok { + r0 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) [2]string); ok { - r0 = rf(path) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([2]string) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).([2]string) } + } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) } return r0, r1 diff --git a/mocks/pkg/fixtures/RequesterGenerics.go b/mocks/pkg/fixtures/RequesterGenerics.go index 4355e4ea..9f41a217 100644 --- a/mocks/pkg/fixtures/RequesterGenerics.go +++ b/mocks/pkg/fixtures/RequesterGenerics.go @@ -49,19 +49,18 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG var r0 TSigned var r1 TIntf if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { - r0, r1 = rf(_a0, _a1) + return rf(_a0, _a1) + } + if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Get(0).(TSigned) + } + + if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { + r1 = rf(_a0, _a1) } else { - if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Get(0).(TSigned) - } - - if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { - r1 = rf(_a0, _a1) - } else { - r1 = ret.Get(1).(TIntf) - } + r1 = ret.Get(1).(TIntf) } return r0, r1 diff --git a/mocks/pkg/fixtures/RequesterNS.go b/mocks/pkg/fixtures/RequesterNS.go index 298829e4..4f3d109a 100644 --- a/mocks/pkg/fixtures/RequesterNS.go +++ b/mocks/pkg/fixtures/RequesterNS.go @@ -20,19 +20,18 @@ func (_m *RequesterNS) Get(path string) (http.Response, error) { var r0 http.Response var r1 error if rf, ok := ret.Get(0).(func(string) (http.Response, error)); ok { - r0, r1 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) http.Response); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(http.Response) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) http.Response); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(http.Response) - } - - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } + r1 = ret.Error(1) } return r0, r1 diff --git a/mocks/pkg/fixtures/RequesterPtr.go b/mocks/pkg/fixtures/RequesterPtr.go index 215c3ed1..8dff00a9 100644 --- a/mocks/pkg/fixtures/RequesterPtr.go +++ b/mocks/pkg/fixtures/RequesterPtr.go @@ -16,21 +16,20 @@ func (_m *RequesterPtr) Get(path string) (*string, error) { var r0 *string var r1 error if rf, ok := ret.Get(0).(func(string) (*string, error)); ok { - r0, r1 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) *string); ok { + r0 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) *string); ok { - r0 = rf(path) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*string) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).(*string) } + } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) } return r0, r1 diff --git a/mocks/pkg/fixtures/RequesterReturnElided.go b/mocks/pkg/fixtures/RequesterReturnElided.go index 4bea02a9..5fa9e87f 100644 --- a/mocks/pkg/fixtures/RequesterReturnElided.go +++ b/mocks/pkg/fixtures/RequesterReturnElided.go @@ -26,31 +26,30 @@ func (_m *RequesterReturnElided) Get(path string) (int, int, int, error) { var r2 int var r3 error if rf, ok := ret.Get(0).(func(string) (int, int, int, error)); ok { - r0, r1, r2, r3 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) int); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(string) int); ok { + r1 = rf(path) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(string) int); ok { + r2 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) int); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(int) - } - - if rf, ok := ret.Get(1).(func(string) int); ok { - r1 = rf(path) - } else { - r1 = ret.Get(1).(int) - } - - if rf, ok := ret.Get(2).(func(string) int); ok { - r2 = rf(path) - } else { - r2 = ret.Get(2).(int) - } - - if rf, ok := ret.Get(3).(func(string) error); ok { - r3 = rf(path) - } else { - r3 = ret.Error(3) - } + r2 = ret.Get(2).(int) + } + + if rf, ok := ret.Get(3).(func(string) error); ok { + r3 = rf(path) + } else { + r3 = ret.Error(3) } return r0, r1, r2, r3 @@ -91,19 +90,18 @@ func (_m *RequesterReturnElided) Put(path string) (int, error) { var r0 int var r1 error if rf, ok := ret.Get(0).(func(string) (int, error)); ok { - r0, r1 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) int); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) int); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(int) - } - - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } + r1 = ret.Error(1) } return r0, r1 diff --git a/mocks/pkg/fixtures/RequesterSlice.go b/mocks/pkg/fixtures/RequesterSlice.go index 2ad02e70..4389f390 100644 --- a/mocks/pkg/fixtures/RequesterSlice.go +++ b/mocks/pkg/fixtures/RequesterSlice.go @@ -16,21 +16,20 @@ func (_m *RequesterSlice) Get(path string) ([]string, error) { var r0 []string var r1 error if rf, ok := ret.Get(0).(func(string) ([]string, error)); ok { - r0, r1 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) []string); ok { + r0 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) []string); ok { - r0 = rf(path) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) } + } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) } return r0, r1 diff --git a/mocks/pkg/fixtures/SendFunc.go b/mocks/pkg/fixtures/SendFunc.go index 9206bf74..3bcdfcd0 100644 --- a/mocks/pkg/fixtures/SendFunc.go +++ b/mocks/pkg/fixtures/SendFunc.go @@ -20,19 +20,18 @@ func (_m *SendFunc) Execute(ctx context.Context, data string) (int, error) { var r0 int var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (int, error)); ok { - r0, r1 = rf(ctx, data) + return rf(ctx, data) + } + if rf, ok := ret.Get(0).(func(context.Context, string) int); ok { + r0 = rf(ctx, data) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, data) } else { - if rf, ok := ret.Get(0).(func(context.Context, string) int); ok { - r0 = rf(ctx, data) - } else { - r0 = ret.Get(0).(int) - } - - if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = rf(ctx, data) - } else { - r1 = ret.Error(1) - } + r1 = ret.Error(1) } return r0, r1 diff --git a/mocks/pkg/fixtures/example_project/Root.go b/mocks/pkg/fixtures/example_project/Root.go index 70bc600b..0b8556e5 100644 --- a/mocks/pkg/fixtures/example_project/Root.go +++ b/mocks/pkg/fixtures/example_project/Root.go @@ -19,21 +19,20 @@ func (_m *Root) ReturnsFoo() (foo.Foo, error) { var r0 foo.Foo var r1 error if rf, ok := ret.Get(0).(func() (foo.Foo, error)); ok { - r0, r1 = rf() + return rf() + } + if rf, ok := ret.Get(0).(func() foo.Foo); ok { + r0 = rf() } else { - if rf, ok := ret.Get(0).(func() foo.Foo); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(foo.Foo) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).(foo.Foo) } + } - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) } return r0, r1 diff --git a/mocks/pkg/fixtures/example_project/bar/foo/Client.go b/mocks/pkg/fixtures/example_project/bar/foo/Client.go index 00bef26b..e629ab7e 100644 --- a/mocks/pkg/fixtures/example_project/bar/foo/Client.go +++ b/mocks/pkg/fixtures/example_project/bar/foo/Client.go @@ -16,21 +16,20 @@ func (_m *Client) Search(query string) ([]string, error) { var r0 []string var r1 error if rf, ok := ret.Get(0).(func(string) ([]string, error)); ok { - r0, r1 = rf(query) + return rf(query) + } + if rf, ok := ret.Get(0).(func(string) []string); ok { + r0 = rf(query) } else { - if rf, ok := ret.Get(0).(func(string) []string); ok { - r0 = rf(query) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) } + } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(query) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(query) + } else { + r1 = ret.Error(1) } return r0, r1 diff --git a/mocks/pkg/fixtures/example_project/foo/Foo.go b/mocks/pkg/fixtures/example_project/foo/Foo.go index 317b8d54..90da457d 100644 --- a/mocks/pkg/fixtures/example_project/foo/Foo.go +++ b/mocks/pkg/fixtures/example_project/foo/Foo.go @@ -33,21 +33,20 @@ func (_m *Foo) GetBaz() (*foo.Baz, error) { var r0 *foo.Baz var r1 error if rf, ok := ret.Get(0).(func() (*foo.Baz, error)); ok { - r0, r1 = rf() + return rf() + } + if rf, ok := ret.Get(0).(func() *foo.Baz); ok { + r0 = rf() } else { - if rf, ok := ret.Get(0).(func() *foo.Baz); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*foo.Baz) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).(*foo.Baz) } + } - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) } return r0, r1 diff --git a/pkg/generator.go b/pkg/generator.go index 62865cfe..38824dac 100644 --- a/pkg/generator.go +++ b/pkg/generator.go @@ -313,16 +313,20 @@ func (g *Generator) printf(s string, vals ...interface{}) { var templates = template.New("base template") func (g *Generator) printTemplate(data interface{}, templateString string) { - err := templates.ExecuteTemplate(&g.buf, templateString, data) + tmpl := templates.New(templateString).Funcs( + template.FuncMap{ + "join": strings.Join, + }, + ) + + tmpl, err := tmpl.Parse(templateString) if err != nil { - tmpl, err := templates.New(templateString).Parse(templateString) - if err != nil { - // couldn't compile template - panic(err) - } - if err := tmpl.Execute(&g.buf, data); err != nil { - panic(err) - } + // couldn't compile template + panic(err) + } + + if err := tmpl.Execute(&g.buf, data); err != nil { + panic(err) } } @@ -471,6 +475,32 @@ type paramList struct { Variadic bool } +func (p *paramList) FormattedParamNames() string { + formattedParamNames := "" + for i, name := range p.Names { + if i > 0 { + formattedParamNames += ", " + } + + paramType := p.Types[i] + // for variable args, move the ... to the end. + if strings.Index(paramType, "...") == 0 { + name += "..." + } + formattedParamNames += name + } + + return formattedParamNames +} + +func (p *paramList) ReturnNames() []string { + var names = make([]string, 0, len(p.Names)) + for i := 0; i < len(p.Names); i++ { + names = append(names, fmt.Sprintf("r%d", i)) + } + return names +} + func (g *Generator) genList(ctx context.Context, list *types.Tuple, variadic bool) *paramList { var params paramList @@ -551,120 +581,93 @@ func (g *Generator) Generate(ctx context.Context) error { } for _, method := range g.iface.Methods() { - // It's probably possible, but not worth the trouble for prototype if method.Signature.Variadic() && g.WithExpecter && !g.UnrollVariadic { return fmt.Errorf("cannot generate a valid expecter for variadic method with unroll-variadic=false") } - ftype := method.Signature - fname := method.Name - - params := g.genList(ctx, ftype.Params(), ftype.Variadic()) - returns := g.genList(ctx, ftype.Results(), false) - - if len(params.Names) == 0 { - g.printf("// %s provides a mock function with given fields:\n", fname) - } else { - g.printf( - "// %s provides a mock function with given fields: %s\n", fname, - strings.Join(params.Names, ", "), - ) - } - g.printf( - "func (_m *%s%s) %s(%s) ", g.mockName(), g.getInstantiatedTypeString(), fname, - strings.Join(params.Params, ", "), - ) - - switch len(returns.Types) { - case 0: - g.printf("{\n") - case 1: - g.printf("%s {\n", returns.Types[0]) - default: - g.printf("(%s) {\n", strings.Join(returns.Types, ", ")) - } - - formattedParamNames := "" - setOfParamNames := make(map[string]struct{}, len(params.Names)) - for i, name := range params.Names { - if i > 0 { - formattedParamNames += ", " - } - - paramType := params.Types[i] - // for variable args, move the ... to the end. - if strings.Index(paramType, "...") == 0 { - name += "..." - } - formattedParamNames += name - - setOfParamNames[name] = struct{}{} - } - - called := g.generateCalled(params, formattedParamNames) // _m.Called invocation string - - if len(returns.Types) > 0 { - retVariable := resolveCollision(setOfParamNames, "ret") - g.printf("\t%s := %s\n\n", retVariable, called) - - ret := make([]string, len(returns.Types)) - - for idx, typ := range returns.Types { - ret[idx] = fmt.Sprintf("r%d", idx) - g.printf("\tvar r%d %s\n", idx, typ) - } + g.generateMethod(ctx, method) + } - var tab string - if len(returns.Types) > 1 { - tab = "\t" - g.printf("\tif rf, ok := %s.Get(0).(func(%s) (%s)); ok {\n", - retVariable, strings.Join(params.Types, ", "), strings.Join(returns.Types, ", ")) - g.printf("\t\t%s = rf(%s)\n", strings.Join(ret, ", "), formattedParamNames) - g.printf("\t} else {\n") - } + g.generateConstructor(ctx) - for idx, typ := range returns.Types { - if idx > 0 { - g.printf("\n") - } - - g.printf("%s\tif rf, ok := %s.Get(%d).(func(%s) %s); ok {\n", - tab, retVariable, idx, strings.Join(params.Types, ", "), typ) - g.printf("%s\t\tr%d = rf(%s)\n", tab, idx, formattedParamNames) - g.printf("%s\t} else {\n", tab) - if typ == "error" { - g.printf("%s\t\tr%d = %s.Error(%d)\n", tab, idx, retVariable, idx) - } else if returns.Nilable[idx] { - g.printf("%s\t\tif %s.Get(%d) != nil {\n", tab, retVariable, idx) - g.printf("%s\t\t\tr%d = %s.Get(%d).(%s)\n", tab, idx, retVariable, idx, typ) - g.printf("%s\t\t}\n", tab) - } else { - g.printf("%s\t\tr%d = %s.Get(%d).(%s)\n", tab, idx, retVariable, idx, typ) - } - g.printf("%s\t}\n", tab) - } + return nil +} - if len(returns.Types) > 1 { - g.printf("\t}\n") - } +func (g *Generator) generateMethod(ctx context.Context, method *Method) { + ftype := method.Signature + fname := method.Name - g.printf("\n\treturn %s\n", strings.Join(ret, ", ")) - } else { - g.printf("\t%s\n", called) - } + params := g.genList(ctx, ftype.Params(), ftype.Variadic()) + returns := g.genList(ctx, ftype.Results(), false) + preamble, called := g.generateCalled(params) - g.printf("}\n") + data := struct { + FunctionName string + Params *paramList + Returns *paramList + MockName string + InstantiatedTypeString string + RetVariableName string + Preamble string + Called string + }{ + FunctionName: fname, + Params: params, + Returns: returns, + MockName: g.mockName(), + InstantiatedTypeString: g.getInstantiatedTypeString(), + RetVariableName: resolveCollision(params.Names, "ret"), + Preamble: preamble, + Called: called, + } - // Construct expecter helper functions - if g.WithExpecter { - g.generateExpecterMethodCall(ctx, method, params, returns) + g.printTemplate(data, ` +// {{.FunctionName}} provides a mock function with given fields: {{join .Params.Names ", "}} +func (_m *{{.MockName}}{{.InstantiatedTypeString}}) {{.FunctionName}}({{join .Params.Params ", "}}) {{if (gt (len .Returns.Types) 1)}}({{end}}{{join .Returns.Types ", "}}{{if (gt (len .Returns.Types) 1)}}){{end}} { +{{- .Preamble -}} +{{- if not .Returns.Types}} + {{- .Called}} +{{- else}} + {{- .RetVariableName}} := {{.Called}} + + {{range $idx, $name := .Returns.ReturnNames}} + var {{$name}} {{index $.Returns.Types $idx -}} + {{end}} + {{if gt (len .Returns.Types) 1 -}} + if rf, ok := {{.RetVariableName}}.Get(0).(func({{join .Params.Types ", "}}) ({{join .Returns.Types ", "}})); ok { + return rf({{.Params.FormattedParamNames}}) + } + {{end}} + {{- range $idx, $name := .Returns.ReturnNames}} + {{- if $idx}} + + {{end}} + {{- $typ := index $.Returns.Types $idx -}} + if rf, ok := {{$.RetVariableName}}.Get({{$idx}}).(func({{join $.Params.Types ", "}}) {{$typ}}); ok { + r{{$idx}} = rf({{$.Params.FormattedParamNames}}) + } else { + {{- if eq "error" $typ -}} + r{{$idx}} = {{$.RetVariableName}}.Error({{$idx}}) + {{- else if (index $.Returns.Nilable $idx) -}} + if {{$.RetVariableName}}.Get({{$idx}}) != nil { + r{{$idx}} = {{$.RetVariableName}}.Get({{$idx}}).({{$typ}}) } + {{- else -}} + r{{$idx}} = {{$.RetVariableName}}.Get({{$idx}}).({{$typ}}) + {{- end -}} } + {{- end}} - g.generateConstructor(ctx) + return {{join .Returns.ReturnNames ", "}} +{{- end}} +} +`) - return nil + // Construct expecter helper functions + if g.WithExpecter { + g.generateExpecterMethodCall(ctx, method, params, returns) + } } func (g *Generator) generateExpecterStruct(ctx context.Context) { @@ -817,18 +820,11 @@ func {{ .ConstructorName }}{{ .TypeConstraint }}(t {{ .ConstructorTestingInterfa // steps to prepare its argument list. // // It is separate from Generate to avoid cyclomatic complexity through early return statements. -func (g *Generator) generateCalled(list *paramList, formattedParamNames string) string { +func (g *Generator) generateCalled(list *paramList) (preamble string, called string) { namesLen := len(list.Names) - if namesLen == 0 { - return "_m.Called()" - } - - if !list.Variadic { - return "_m.Called(" + formattedParamNames + ")" - } - - if !g.UnrollVariadic { - return "_m.Called(" + strings.Join(list.Names, ", ") + ")" + if namesLen == 0 || !list.Variadic || !g.UnrollVariadic { + called = "_m.Called(" + strings.Join(list.Names, ", ") + ")" + return } var variadicArgsName string @@ -837,7 +833,7 @@ func (g *Generator) generateCalled(list *paramList, formattedParamNames string) // list.Types[] will contain a leading '...'. Strip this from the string to // do easier comparison. strippedIfaceType := strings.Trim(list.Types[namesLen-1], "...") - variadicIface := strippedIfaceType == "interface{}" + variadicIface := strippedIfaceType == "interface{}" || strippedIfaceType == "any" if variadicIface { // Variadic is already of the interface{} type, so we don't need special handling. @@ -845,8 +841,8 @@ func (g *Generator) generateCalled(list *paramList, formattedParamNames string) } else { // Define _va to avoid "cannot use t (type T) as type []interface {} in append" error // whenever the variadic type is non-interface{}. - g.printf("\t_va := make([]interface{}, len(%s))\n", variadicName) - g.printf("\tfor _i := range %s {\n\t\t_va[_i] = %s[_i]\n\t}\n", variadicName, variadicName) + preamble += fmt.Sprintf("\t_va := make([]interface{}, len(%s))\n", variadicName) + preamble += fmt.Sprintf("\tfor _i := range %s {\n\t\t_va[_i] = %s[_i]\n\t}\n", variadicName, variadicName) variadicArgsName = "_va" } @@ -866,15 +862,17 @@ func (g *Generator) generateCalled(list *paramList, formattedParamNames string) // // It's okay for us to use the interface{} type, regardless of the actual types, because // Called receives only interface{} anyway. - g.printf("\tvar _ca []interface{}\n") + preamble += ("\tvar _ca []interface{}\n") if namesLen > 1 { + formattedParamNames := list.FormattedParamNames() nonVariadicParamNames := formattedParamNames[0:strings.LastIndex(formattedParamNames, ",")] - g.printf("\t_ca = append(_ca, %s)\n", nonVariadicParamNames) + preamble += fmt.Sprintf("\t_ca = append(_ca, %s)\n", nonVariadicParamNames) } - g.printf("\t_ca = append(_ca, %s...)\n", variadicArgsName) + preamble += fmt.Sprintf("\t_ca = append(_ca, %s...)\n", variadicArgsName) - return "_m.Called(_ca...)" + called = "_m.Called(_ca...)" + return } func (g *Generator) Write(w io.Writer) error { @@ -892,11 +890,15 @@ func (g *Generator) Write(w io.Writer) error { return nil } -func resolveCollision(names map[string]struct{}, variable string) string { +func resolveCollision(names []string, variable string) string { ret := variable + set := make(map[string]struct{}) + for _, n := range names { + set[n] = struct{}{} + } for i := len(names); true; i++ { - _, ok := names[ret] + _, ok := set[ret] if !ok { break } diff --git a/pkg/generator_test.go b/pkg/generator_test.go index d324bb76..aa940faf 100644 --- a/pkg/generator_test.go +++ b/pkg/generator_test.go @@ -129,19 +129,18 @@ func (_m *Requester) Get(path string) (string, error) { var r0 string var r1 error if rf, ok := ret.Get(0).(func(string) (string, error)); ok { - r0, r1 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) string); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(string) - } + r0 = ret.Get(0).(string) + } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) } return r0, r1 @@ -186,19 +185,18 @@ func (_m *Requester) Get(path string) (string, error) { var r0 string var r1 error if rf, ok := ret.Get(0).(func(string) (string, error)); ok { - r0, r1 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) string); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(string) - } + r0 = ret.Get(0).(string) + } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) } return r0, r1 @@ -276,21 +274,20 @@ func (_m *Expecter) ManyArgsReturns(str string, i int) ([]string, error) { var r0 []string var r1 error if rf, ok := ret.Get(0).(func(string, int) ([]string, error)); ok { - r0, r1 = rf(str, i) + return rf(str, i) + } + if rf, ok := ret.Get(0).(func(string, int) []string); ok { + r0 = rf(str, i) } else { - if rf, ok := ret.Get(0).(func(string, int) []string); ok { - r0 = rf(str, i) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) } + } - if rf, ok := ret.Get(1).(func(string, int) error); ok { - r1 = rf(str, i) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(string, int) error); ok { + r1 = rf(str, i) + } else { + r1 = ret.Error(1) } return r0, r1 @@ -556,19 +553,18 @@ func (_m *SendFunc) Execute(ctx context.Context, data string) (int, error) { var r0 int var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (int, error)); ok { - r0, r1 = rf(ctx, data) + return rf(ctx, data) + } + if rf, ok := ret.Get(0).(func(context.Context, string) int); ok { + r0 = rf(ctx, data) } else { - if rf, ok := ret.Get(0).(func(context.Context, string) int); ok { - r0 = rf(ctx, data) - } else { - r0 = ret.Get(0).(int) - } + r0 = ret.Get(0).(int) + } - if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = rf(ctx, data) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, data) + } else { + r1 = ret.Error(1) } return r0, r1 @@ -967,21 +963,20 @@ func (_m *RequesterPtr) Get(path string) (*string, error) { var r0 *string var r1 error if rf, ok := ret.Get(0).(func(string) (*string, error)); ok { - r0, r1 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) *string); ok { + r0 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) *string); ok { - r0 = rf(path) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*string) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).(*string) } + } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) } return r0, r1 @@ -1018,21 +1013,20 @@ func (_m *RequesterSlice) Get(path string) ([]string, error) { var r0 []string var r1 error if rf, ok := ret.Get(0).(func(string) ([]string, error)); ok { - r0, r1 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) []string); ok { + r0 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) []string); ok { - r0 = rf(path) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]string) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) } + } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) } return r0, r1 @@ -1069,21 +1063,20 @@ func (_m *RequesterArray) Get(path string) ([2]string, error) { var r0 [2]string var r1 error if rf, ok := ret.Get(0).(func(string) ([2]string, error)); ok { - r0, r1 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) [2]string); ok { + r0 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) [2]string); ok { - r0 = rf(path) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([2]string) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).([2]string) } + } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) } return r0, r1 @@ -1120,19 +1113,18 @@ func (_m *RequesterNS) Get(path string) (http.Response, error) { var r0 http.Response var r1 error if rf, ok := ret.Get(0).(func(string) (http.Response, error)); ok { - r0, r1 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) http.Response); ok { + r0 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) http.Response); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(http.Response) - } + r0 = ret.Get(0).(http.Response) + } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) } return r0, r1 @@ -1278,22 +1270,21 @@ func (_m *KeyManager) GetKey(_a0 string, _a1 uint16) ([]byte, *test.Err) { var r0 []byte var r1 *test.Err if rf, ok := ret.Get(0).(func(string, uint16) ([]byte, *test.Err)); ok { - r0, r1 = rf(_a0, _a1) + return rf(_a0, _a1) + } + if rf, ok := ret.Get(0).(func(string, uint16) []byte); ok { + r0 = rf(_a0, _a1) } else { - if rf, ok := ret.Get(0).(func(string, uint16) []byte); ok { - r0 = rf(_a0, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) } + } - if rf, ok := ret.Get(1).(func(string, uint16) *test.Err); ok { - r1 = rf(_a0, _a1) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*test.Err) - } + if rf, ok := ret.Get(1).(func(string, uint16) *test.Err); ok { + r1 = rf(_a0, _a1) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*test.Err) } } @@ -1379,31 +1370,30 @@ func (_m *RequesterReturnElided) Get(path string) (int, int, int, error) { var r2 int var r3 error if rf, ok := ret.Get(0).(func(string) (int, int, int, error)); ok { - r0, r1, r2, r3 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) int); ok { + r0 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) int); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(int) - } + r0 = ret.Get(0).(int) + } - if rf, ok := ret.Get(1).(func(string) int); ok { - r1 = rf(path) - } else { - r1 = ret.Get(1).(int) - } + if rf, ok := ret.Get(1).(func(string) int); ok { + r1 = rf(path) + } else { + r1 = ret.Get(1).(int) + } - if rf, ok := ret.Get(2).(func(string) int); ok { - r2 = rf(path) - } else { - r2 = ret.Get(2).(int) - } + if rf, ok := ret.Get(2).(func(string) int); ok { + r2 = rf(path) + } else { + r2 = ret.Get(2).(int) + } - if rf, ok := ret.Get(3).(func(string) error); ok { - r3 = rf(path) - } else { - r3 = ret.Error(3) - } + if rf, ok := ret.Get(3).(func(string) error); ok { + r3 = rf(path) + } else { + r3 = ret.Error(3) } return r0, r1, r2, r3 @@ -1444,19 +1434,18 @@ func (_m *RequesterReturnElided) Put(path string) (int, error) { var r0 int var r1 error if rf, ok := ret.Get(0).(func(string) (int, error)); ok { - r0, r1 = rf(path) + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) int); ok { + r0 = rf(path) } else { - if rf, ok := ret.Get(0).(func(string) int); ok { - r0 = rf(path) - } else { - r0 = ret.Get(0).(int) - } + r0 = ret.Get(0).(int) + } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(path) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) } return r0, r1 @@ -1781,19 +1770,18 @@ func (_m *MyReader) Read(p []byte) (int, error) { var r0 int var r1 error if rf, ok := ret.Get(0).(func([]byte) (int, error)); ok { - r0, r1 = rf(p) + return rf(p) + } + if rf, ok := ret.Get(0).(func([]byte) int); ok { + r0 = rf(p) } else { - if rf, ok := ret.Get(0).(func([]byte) int); ok { - r0 = rf(p) - } else { - r0 = ret.Get(0).(int) - } + r0 = ret.Get(0).(int) + } - if rf, ok := ret.Get(1).(func([]byte) error); ok { - r1 = rf(p) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func([]byte) error); ok { + r1 = rf(p) + } else { + r1 = ret.Error(1) } return r0, r1 @@ -1830,21 +1818,20 @@ func (_m *ConsulLock) Lock(_a0 <-chan struct{}) (<-chan struct{}, error) { var r0 <-chan struct{} var r1 error if rf, ok := ret.Get(0).(func(<-chan struct{}) (<-chan struct{}, error)); ok { - r0, r1 = rf(_a0) + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(<-chan struct{}) <-chan struct{}); ok { + r0 = rf(_a0) } else { - if rf, ok := ret.Get(0).(func(<-chan struct{}) <-chan struct{}); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(<-chan struct{}) - } + if ret.Get(0) != nil { + r0 = ret.Get(0).(<-chan struct{}) } + } - if rf, ok := ret.Get(1).(func(<-chan struct{}) error); ok { - r1 = rf(_a0) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(<-chan struct{}) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) } return r0, r1 @@ -2285,19 +2272,18 @@ func (_m *A) Call() (test.B, error) { var r0 test.B var r1 error if rf, ok := ret.Get(0).(func() (test.B, error)); ok { - r0, r1 = rf() + return rf() + } + if rf, ok := ret.Get(0).(func() test.B); ok { + r0 = rf() } else { - if rf, ok := ret.Get(0).(func() test.B); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(test.B) - } + r0 = ret.Get(0).(test.B) + } - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) } return r0, r1 @@ -2463,19 +2449,18 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG var r0 TSigned var r1 TIntf if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { - r0, r1 = rf(_a0, _a1) + return rf(_a0, _a1) + } + if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { + r0 = rf(_a0, _a1) } else { - if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Get(0).(TSigned) - } + r0 = ret.Get(0).(TSigned) + } - if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { - r1 = rf(_a0, _a1) - } else { - r1 = ret.Get(1).(TIntf) - } + if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Get(1).(TIntf) } return r0, r1 @@ -2600,19 +2585,18 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG var r0 TSigned var r1 TIntf if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { - r0, r1 = rf(_a0, _a1) + return rf(_a0, _a1) + } + if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { + r0 = rf(_a0, _a1) } else { - if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Get(0).(TSigned) - } + r0 = ret.Get(0).(TSigned) + } - if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { - r1 = rf(_a0, _a1) - } else { - r1 = ret.Get(1).(TIntf) - } + if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Get(1).(TIntf) } return r0, r1 @@ -2759,19 +2743,18 @@ func (_m *MockRequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf var r0 TSigned var r1 TIntf if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { - r0, r1 = rf(_a0, _a1) + return rf(_a0, _a1) + } + if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { + r0 = rf(_a0, _a1) } else { - if rf, ok := ret.Get(0).(func(TAny, TComparable) TSigned); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Get(0).(TSigned) - } + r0 = ret.Get(0).(TSigned) + } - if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { - r1 = rf(_a0, _a1) - } else { - r1 = ret.Get(1).(TIntf) - } + if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Get(1).(TIntf) } return r0, r1 From cbaa47b08a2f1ca060b19f307f415d0302d5e579 Mon Sep 17 00:00:00 2001 From: Dave Wyatt Date: Thu, 9 Feb 2023 17:19:13 -0500 Subject: [PATCH 4/5] Update generated code in readme --- README.md | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 95b4e4f5..1b5659c1 100644 --- a/README.md +++ b/README.md @@ -192,19 +192,18 @@ func (_m *SendFunc) Execute(data string) (int, error) { var r0 int var r1 error if rf, ok := ret.Get(0).(func(string) (int, error); ok { - r0, r1 = rf(data) + return rf(data) + } + if rf, ok := ret.Get(0).(func(string) int); ok { + r0 = rf(data) } else { - if rf, ok := ret.Get(0).(func(string) int); ok { - r0 = rf(data) - } else { - r0 = ret.Get(0).(int) - } + r0 = ret.Get(0).(int) + } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(data) - } else { - r1 = ret.Error(1) - } + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(data) + } else { + r1 = ret.Error(1) } return r0, r1 From 15f76b960ae273ec9f061608ff0c1899c0632ec7 Mon Sep 17 00:00:00 2001 From: Dave Wyatt Date: Fri, 10 Feb 2023 12:35:09 -0500 Subject: [PATCH 5/5] Update comment --- pkg/generator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/generator.go b/pkg/generator.go index 38824dac..7159dced 100644 --- a/pkg/generator.go +++ b/pkg/generator.go @@ -816,7 +816,7 @@ func {{ .ConstructorName }}{{ .TypeConstraint }}(t {{ .ConstructorTestingInterfa g.printTemplate(data, constructorTemplate) } -// generateCalled returns the Mock.Called invocation string and, if necessary, prints the +// generateCalled returns the Mock.Called invocation string and, if necessary, a preamble with the // steps to prepare its argument list. // // It is separate from Generate to avoid cyclomatic complexity through early return statements.