diff --git a/README.md b/README.md index 648f8822..d9ba7e15 100644 --- a/README.md +++ b/README.md @@ -189,13 +189,16 @@ func (_m *SendFunc) Execute(data string) (int, error) { ret := _m.Called(data) var r0 int + var r1 error + if rf, ok := ret.Get(0).(func(string) (int, error); ok { + return rf(data) + } 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) } else { @@ -236,21 +239,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"), @@ -301,7 +302,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 { @@ -309,6 +310,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")). @@ -322,16 +338,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..e1cc4d55 100644 --- a/mocks/pkg/fixtures/A.go +++ b/mocks/pkg/fixtures/A.go @@ -17,13 +17,16 @@ func (_m *A) Call() (test.B, error) { ret := _m.Called() var r0 test.B + var r1 error + if rf, ok := ret.Get(0).(func() (test.B, error)); ok { + return rf() + } 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() } else { diff --git a/mocks/pkg/fixtures/ConsulLock.go b/mocks/pkg/fixtures/ConsulLock.go index d5b8d27f..d2b30cf7 100644 --- a/mocks/pkg/fixtures/ConsulLock.go +++ b/mocks/pkg/fixtures/ConsulLock.go @@ -14,6 +14,10 @@ func (_m *ConsulLock) Lock(_a0 <-chan struct{}) (<-chan struct{}, error) { ret := _m.Called(_a0) var r0 <-chan struct{} + var r1 error + if rf, ok := ret.Get(0).(func(<-chan struct{}) (<-chan struct{}, error)); ok { + return rf(_a0) + } if rf, ok := ret.Get(0).(func(<-chan struct{}) <-chan struct{}); ok { r0 = rf(_a0) } else { @@ -22,7 +26,6 @@ func (_m *ConsulLock) Lock(_a0 <-chan struct{}) (<-chan struct{}, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(<-chan struct{}) error); ok { r1 = rf(_a0) } else { diff --git a/mocks/pkg/fixtures/Expecter.go b/mocks/pkg/fixtures/Expecter.go index 6d7ce5ee..de53ab26 100644 --- a/mocks/pkg/fixtures/Expecter.go +++ b/mocks/pkg/fixtures/Expecter.go @@ -22,6 +22,10 @@ func (_m *Expecter) ManyArgsReturns(str string, i int) ([]string, error) { ret := _m.Called(str, i) var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(string, int) ([]string, error)); ok { + return rf(str, i) + } if rf, ok := ret.Get(0).(func(string, int) []string); ok { r0 = rf(str, i) } else { @@ -30,7 +34,6 @@ func (_m *Expecter) ManyArgsReturns(str string, i int) ([]string, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(string, int) error); ok { r1 = rf(str, i) } else { @@ -64,6 +67,11 @@ 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() @@ -100,6 +108,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 +141,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)) @@ -178,6 +196,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{} @@ -227,6 +250,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/HasConflictingNestedImports.go b/mocks/pkg/fixtures/HasConflictingNestedImports.go index 985d6ff7..1557690a 100644 --- a/mocks/pkg/fixtures/HasConflictingNestedImports.go +++ b/mocks/pkg/fixtures/HasConflictingNestedImports.go @@ -20,13 +20,16 @@ func (_m *HasConflictingNestedImports) Get(path string) (http.Response, error) { ret := _m.Called(path) var r0 http.Response + var r1 error + if rf, ok := ret.Get(0).(func(string) (http.Response, error)); ok { + return rf(path) + } 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) } else { diff --git a/mocks/pkg/fixtures/KeyManager.go b/mocks/pkg/fixtures/KeyManager.go index da5b4bbe..5f8fda3d 100644 --- a/mocks/pkg/fixtures/KeyManager.go +++ b/mocks/pkg/fixtures/KeyManager.go @@ -17,6 +17,10 @@ func (_m *KeyManager) GetKey(_a0 string, _a1 uint16) ([]byte, *test.Err) { ret := _m.Called(_a0, _a1) var r0 []byte + var r1 *test.Err + if rf, ok := ret.Get(0).(func(string, uint16) ([]byte, *test.Err)); ok { + return rf(_a0, _a1) + } if rf, ok := ret.Get(0).(func(string, uint16) []byte); ok { r0 = rf(_a0, _a1) } else { @@ -25,7 +29,6 @@ func (_m *KeyManager) GetKey(_a0 string, _a1 uint16) ([]byte, *test.Err) { } } - var r1 *test.Err if rf, ok := ret.Get(1).(func(string, uint16) *test.Err); ok { r1 = rf(_a0, _a1) } else { diff --git a/mocks/pkg/fixtures/MyReader.go b/mocks/pkg/fixtures/MyReader.go index f677c95d..ddcde557 100644 --- a/mocks/pkg/fixtures/MyReader.go +++ b/mocks/pkg/fixtures/MyReader.go @@ -14,13 +14,16 @@ func (_m *MyReader) Read(p []byte) (int, error) { ret := _m.Called(p) var r0 int + var r1 error + if rf, ok := ret.Get(0).(func([]byte) (int, error)); ok { + return rf(p) + } 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) } else { diff --git a/mocks/pkg/fixtures/Requester.go b/mocks/pkg/fixtures/Requester.go index c22011f2..97b8eaba 100644 --- a/mocks/pkg/fixtures/Requester.go +++ b/mocks/pkg/fixtures/Requester.go @@ -14,13 +14,16 @@ func (_m *Requester) Get(path string) (string, error) { ret := _m.Called(path) var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(string) (string, error)); ok { + return rf(path) + } 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) } else { diff --git a/mocks/pkg/fixtures/RequesterArray.go b/mocks/pkg/fixtures/RequesterArray.go index b5cac438..a3f27ec5 100644 --- a/mocks/pkg/fixtures/RequesterArray.go +++ b/mocks/pkg/fixtures/RequesterArray.go @@ -14,6 +14,10 @@ func (_m *RequesterArray) Get(path string) ([2]string, error) { ret := _m.Called(path) var r0 [2]string + var r1 error + if rf, ok := ret.Get(0).(func(string) ([2]string, error)); ok { + return rf(path) + } if rf, ok := ret.Get(0).(func(string) [2]string); ok { r0 = rf(path) } else { @@ -22,7 +26,6 @@ func (_m *RequesterArray) Get(path string) ([2]string, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(path) } else { diff --git a/mocks/pkg/fixtures/RequesterGenerics.go b/mocks/pkg/fixtures/RequesterGenerics.go index 6fe44588..9f41a217 100644 --- a/mocks/pkg/fixtures/RequesterGenerics.go +++ b/mocks/pkg/fixtures/RequesterGenerics.go @@ -47,13 +47,16 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG ret := _m.Called(_a0, _a1) var r0 TSigned + var r1 TIntf + if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { + 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) } - var r1 TIntf if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { r1 = rf(_a0, _a1) } else { diff --git a/mocks/pkg/fixtures/RequesterNS.go b/mocks/pkg/fixtures/RequesterNS.go index e7a69f14..4f3d109a 100644 --- a/mocks/pkg/fixtures/RequesterNS.go +++ b/mocks/pkg/fixtures/RequesterNS.go @@ -18,13 +18,16 @@ func (_m *RequesterNS) Get(path string) (http.Response, error) { ret := _m.Called(path) var r0 http.Response + var r1 error + if rf, ok := ret.Get(0).(func(string) (http.Response, error)); ok { + return rf(path) + } 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) } else { diff --git a/mocks/pkg/fixtures/RequesterPtr.go b/mocks/pkg/fixtures/RequesterPtr.go index 2d19b39b..8dff00a9 100644 --- a/mocks/pkg/fixtures/RequesterPtr.go +++ b/mocks/pkg/fixtures/RequesterPtr.go @@ -14,6 +14,10 @@ func (_m *RequesterPtr) Get(path string) (*string, error) { ret := _m.Called(path) var r0 *string + var r1 error + if rf, ok := ret.Get(0).(func(string) (*string, error)); ok { + return rf(path) + } if rf, ok := ret.Get(0).(func(string) *string); ok { r0 = rf(path) } else { @@ -22,7 +26,6 @@ func (_m *RequesterPtr) Get(path string) (*string, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(path) } else { diff --git a/mocks/pkg/fixtures/RequesterReturnElided.go b/mocks/pkg/fixtures/RequesterReturnElided.go index 82d7c6a8..5fa9e87f 100644 --- a/mocks/pkg/fixtures/RequesterReturnElided.go +++ b/mocks/pkg/fixtures/RequesterReturnElided.go @@ -22,27 +22,30 @@ func (_m *RequesterReturnElided) Get(path string) (int, int, int, error) { ret := _m.Called(path) var r0 int + var r1 int + var r2 int + var r3 error + if rf, ok := ret.Get(0).(func(string) (int, int, int, error)); ok { + return rf(path) + } 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) } else { @@ -75,18 +78,26 @@ 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 + var r1 error + if rf, ok := ret.Get(0).(func(string) (int, error)); ok { + return rf(path) + } 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) } else { @@ -119,6 +130,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..4389f390 100644 --- a/mocks/pkg/fixtures/RequesterSlice.go +++ b/mocks/pkg/fixtures/RequesterSlice.go @@ -14,6 +14,10 @@ func (_m *RequesterSlice) Get(path string) ([]string, error) { ret := _m.Called(path) var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(string) ([]string, error)); ok { + return rf(path) + } if rf, ok := ret.Get(0).(func(string) []string); ok { r0 = rf(path) } else { @@ -22,7 +26,6 @@ func (_m *RequesterSlice) Get(path string) ([]string, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(path) } else { diff --git a/mocks/pkg/fixtures/SendFunc.go b/mocks/pkg/fixtures/SendFunc.go index ee4d3e0d..3bcdfcd0 100644 --- a/mocks/pkg/fixtures/SendFunc.go +++ b/mocks/pkg/fixtures/SendFunc.go @@ -18,13 +18,16 @@ func (_m *SendFunc) Execute(ctx context.Context, data string) (int, error) { ret := _m.Called(ctx, data) var r0 int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (int, error)); ok { + 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) } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { r1 = rf(ctx, data) } else { diff --git a/mocks/pkg/fixtures/example_project/Root.go b/mocks/pkg/fixtures/example_project/Root.go index 0f5a11ba..0b8556e5 100644 --- a/mocks/pkg/fixtures/example_project/Root.go +++ b/mocks/pkg/fixtures/example_project/Root.go @@ -17,6 +17,10 @@ func (_m *Root) ReturnsFoo() (foo.Foo, error) { ret := _m.Called() var r0 foo.Foo + var r1 error + if rf, ok := ret.Get(0).(func() (foo.Foo, error)); ok { + return rf() + } if rf, ok := ret.Get(0).(func() foo.Foo); ok { r0 = rf() } else { @@ -25,7 +29,6 @@ func (_m *Root) ReturnsFoo() (foo.Foo, error) { } } - var r1 error if rf, ok := ret.Get(1).(func() error); ok { 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 a8b6f07d..e629ab7e 100644 --- a/mocks/pkg/fixtures/example_project/bar/foo/Client.go +++ b/mocks/pkg/fixtures/example_project/bar/foo/Client.go @@ -14,6 +14,10 @@ func (_m *Client) Search(query string) ([]string, error) { ret := _m.Called(query) var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(string) ([]string, error)); ok { + return rf(query) + } if rf, ok := ret.Get(0).(func(string) []string); ok { r0 = rf(query) } else { @@ -22,7 +26,6 @@ func (_m *Client) Search(query string) ([]string, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { 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 1470e204..90da457d 100644 --- a/mocks/pkg/fixtures/example_project/foo/Foo.go +++ b/mocks/pkg/fixtures/example_project/foo/Foo.go @@ -31,6 +31,10 @@ func (_m *Foo) GetBaz() (*foo.Baz, error) { ret := _m.Called() var r0 *foo.Baz + var r1 error + if rf, ok := ret.Get(0).(func() (*foo.Baz, error)); ok { + return rf() + } if rf, ok := ret.Get(0).(func() *foo.Baz); ok { r0 = rf() } else { @@ -39,7 +43,6 @@ func (_m *Foo) GetBaz() (*foo.Baz, error) { } } - var r1 error if rf, ok := ret.Get(1).(func() error); ok { r1 = rf() } else { diff --git a/pkg/generator.go b/pkg/generator.go index 69fc94b2..7159dced 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,101 +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 += ", " - } + g.generateMethod(ctx, method) + } - paramType := params.Types[i] - // for variable args, move the ... to the end. - if strings.Index(paramType, "...") == 0 { - name += "..." - } - formattedParamNames += name + g.generateConstructor(ctx) - setOfParamNames[name] = struct{}{} - } + return nil +} - 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 { - 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("\t} else {\n") - if typ == "error" { - g.printf("\t\tr%d = %s.Error(%d)\n", 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") - } else { - g.printf("\t\tr%d = %s.Get(%d).(%s)\n", idx, retVariable, idx, typ) - } - g.printf("\t}\n\n") - - ret[idx] = fmt.Sprintf("r%d", idx) - } +func (g *Generator) generateMethod(ctx context.Context, method *Method) { + ftype := method.Signature + fname := method.Name - g.printf("\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) { @@ -750,6 +772,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 +} `) } @@ -789,22 +816,15 @@ 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. -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 @@ -813,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. @@ -821,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" } @@ -842,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 { @@ -868,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 efe92eac..aa940faf 100644 --- a/pkg/generator_test.go +++ b/pkg/generator_test.go @@ -127,13 +127,16 @@ func (_m *Requester) Get(path string) (string, error) { ret := _m.Called(path) var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(string) (string, error)); ok { + return rf(path) + } 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) } else { @@ -180,13 +183,16 @@ func (_m *Requester) Get(path string) (string, error) { ret := _m.Called(path) var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(string) (string, error)); ok { + return rf(path) + } 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) } else { @@ -219,6 +225,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,6 +272,10 @@ func (_m *Expecter) ManyArgsReturns(str string, i int) ([]string, error) { ret := _m.Called(str, i) var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(string, int) ([]string, error)); ok { + return rf(str, i) + } if rf, ok := ret.Get(0).(func(string, int) []string); ok { r0 = rf(str, i) } else { @@ -269,7 +284,6 @@ func (_m *Expecter) ManyArgsReturns(str string, i int) ([]string, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(string, int) error); ok { r1 = rf(str, i) } else { @@ -303,6 +317,11 @@ 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() @@ -339,6 +358,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 +391,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)) @@ -417,6 +446,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{} @@ -466,6 +500,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,13 +551,16 @@ func (_m *SendFunc) Execute(ctx context.Context, data string) (int, error) { ret := _m.Called(ctx, data) var r0 int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (int, error)); ok { + 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) } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { r1 = rf(ctx, data) } else { @@ -919,6 +961,10 @@ func (_m *RequesterPtr) Get(path string) (*string, error) { ret := _m.Called(path) var r0 *string + var r1 error + if rf, ok := ret.Get(0).(func(string) (*string, error)); ok { + return rf(path) + } if rf, ok := ret.Get(0).(func(string) *string); ok { r0 = rf(path) } else { @@ -927,7 +973,6 @@ func (_m *RequesterPtr) Get(path string) (*string, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(path) } else { @@ -966,6 +1011,10 @@ func (_m *RequesterSlice) Get(path string) ([]string, error) { ret := _m.Called(path) var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(string) ([]string, error)); ok { + return rf(path) + } if rf, ok := ret.Get(0).(func(string) []string); ok { r0 = rf(path) } else { @@ -974,7 +1023,6 @@ func (_m *RequesterSlice) Get(path string) ([]string, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(path) } else { @@ -1013,6 +1061,10 @@ func (_m *RequesterArray) Get(path string) ([2]string, error) { ret := _m.Called(path) var r0 [2]string + var r1 error + if rf, ok := ret.Get(0).(func(string) ([2]string, error)); ok { + return rf(path) + } if rf, ok := ret.Get(0).(func(string) [2]string); ok { r0 = rf(path) } else { @@ -1021,7 +1073,6 @@ func (_m *RequesterArray) Get(path string) ([2]string, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(path) } else { @@ -1060,13 +1111,16 @@ func (_m *RequesterNS) Get(path string) (http.Response, error) { ret := _m.Called(path) var r0 http.Response + var r1 error + if rf, ok := ret.Get(0).(func(string) (http.Response, error)); ok { + return rf(path) + } 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) } else { @@ -1214,6 +1268,10 @@ func (_m *KeyManager) GetKey(_a0 string, _a1 uint16) ([]byte, *test.Err) { ret := _m.Called(_a0, _a1) var r0 []byte + var r1 *test.Err + if rf, ok := ret.Get(0).(func(string, uint16) ([]byte, *test.Err)); ok { + return rf(_a0, _a1) + } if rf, ok := ret.Get(0).(func(string, uint16) []byte); ok { r0 = rf(_a0, _a1) } else { @@ -1222,7 +1280,6 @@ func (_m *KeyManager) GetKey(_a0 string, _a1 uint16) ([]byte, *test.Err) { } } - var r1 *test.Err if rf, ok := ret.Get(1).(func(string, uint16) *test.Err); ok { r1 = rf(_a0, _a1) } else { @@ -1309,27 +1366,30 @@ func (_m *RequesterReturnElided) Get(path string) (int, int, int, error) { ret := _m.Called(path) var r0 int + var r1 int + var r2 int + var r3 error + if rf, ok := ret.Get(0).(func(string) (int, int, int, error)); ok { + return rf(path) + } 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) } else { @@ -1362,18 +1422,26 @@ 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 + var r1 error + if rf, ok := ret.Get(0).(func(string) (int, error)); ok { + return rf(path) + } 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) } else { @@ -1406,6 +1474,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()) @@ -1695,13 +1768,16 @@ func (_m *MyReader) Read(p []byte) (int, error) { ret := _m.Called(p) var r0 int + var r1 error + if rf, ok := ret.Get(0).(func([]byte) (int, error)); ok { + return rf(p) + } 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) } else { @@ -1740,6 +1816,10 @@ func (_m *ConsulLock) Lock(_a0 <-chan struct{}) (<-chan struct{}, error) { ret := _m.Called(_a0) var r0 <-chan struct{} + var r1 error + if rf, ok := ret.Get(0).(func(<-chan struct{}) (<-chan struct{}, error)); ok { + return rf(_a0) + } if rf, ok := ret.Get(0).(func(<-chan struct{}) <-chan struct{}); ok { r0 = rf(_a0) } else { @@ -1748,7 +1828,6 @@ func (_m *ConsulLock) Lock(_a0 <-chan struct{}) (<-chan struct{}, error) { } } - var r1 error if rf, ok := ret.Get(1).(func(<-chan struct{}) error); ok { r1 = rf(_a0) } else { @@ -2191,13 +2270,16 @@ func (_m *A) Call() (test.B, error) { ret := _m.Called() var r0 test.B + var r1 error + if rf, ok := ret.Get(0).(func() (test.B, error)); ok { + return rf() + } 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() } else { @@ -2365,13 +2447,16 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG ret := _m.Called(_a0, _a1) var r0 TSigned + var r1 TIntf + if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { + 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) } - var r1 TIntf if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { r1 = rf(_a0, _a1) } else { @@ -2486,18 +2571,28 @@ 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 + var r1 TIntf + if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { + 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) } - var r1 TIntf if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { r1 = rf(_a0, _a1) } else { @@ -2534,6 +2629,11 @@ 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) @@ -2574,6 +2674,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()) @@ -2636,13 +2741,16 @@ func (_m *MockRequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf ret := _m.Called(_a0, _a1) var r0 TSigned + var r1 TIntf + if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { + 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) } - var r1 TIntf if rf, ok := ret.Get(1).(func(TAny, TComparable) TIntf); ok { r1 = rf(_a0, _a1) } else {