From b5016df9db9117cffb24109ced3d3ea18e8dc448 Mon Sep 17 00:00:00 2001 From: Alysson Ribeiro <15274059+sonalys@users.noreply.github.com> Date: Thu, 14 Nov 2024 09:29:09 +0100 Subject: [PATCH] Fix(generator): Run functions with empty return --- .../vektra/mockery/v2/pkg/TypesPackage.go | 4 +- .../vektra/mockery/v2/pkg/fixtures/A.go | 2 +- .../mockery/v2/pkg/fixtures/AsyncProducer.go | 6 +- .../mockery/v2/pkg/fixtures/ConsulLock.go | 2 +- .../mockery/v2/pkg/fixtures/EmbeddedGet.go | 2 +- .../mockery/v2/pkg/fixtures/EmptyReturn.go | 98 +++++++++++++++++++ .../vektra/mockery/v2/pkg/fixtures/Example.go | 2 +- .../mockery/v2/pkg/fixtures/Expecter.go | 4 +- .../pkg/fixtures/ExpecterAndRolledVariadic.go | 4 +- .../vektra/mockery/v2/pkg/fixtures/Fooer.go | 2 +- .../mockery/v2/pkg/fixtures/GetGeneric.go | 2 +- .../vektra/mockery/v2/pkg/fixtures/GetInt.go | 2 +- .../fixtures/HasConflictingNestedImports.go | 2 +- .../v2/pkg/fixtures/ImportsSameAsPackage.go | 6 +- .../mockery/v2/pkg/fixtures/MapToInterface.go | 2 +- .../v2/pkg/fixtures/PanicOnNoReturnValue.go | 2 +- .../mockery/v2/pkg/fixtures/ReplaceGeneric.go | 4 +- .../v2/pkg/fixtures/ReplaceGenericSelf.go | 2 +- .../mockery/v2/pkg/fixtures/Requester3.go | 2 +- .../mockery/v2/pkg/fixtures/Requester4.go | 4 +- .../v2/pkg/fixtures/RequesterArgSameAsPkg.go | 2 +- .../mockery/v2/pkg/fixtures/RequesterIface.go | 2 +- .../vektra/mockery/v2/pkg/fixtures/Sibling.go | 4 +- .../v2/pkg/fixtures/UnsafeInterface.go | 2 +- .../vektra/mockery/v2/pkg/fixtures/UsesAny.go | 2 +- .../v2/pkg/fixtures/UsesOtherPkgIface.go | 2 +- .../pkg/fixtures/VariadicNoReturnInterface.go | 2 +- .../IfaceWithCustomBuildTagInComment.go | 4 +- .../v2/pkg/fixtures/requesterUnexported.go | 4 +- pkg/compat_test.go | 32 ++++++ pkg/fixtures/empty_return.go | 6 ++ .../mock_interfaceB_test.go | 2 +- pkg/fixtures/recursive_generation/Foo_mock.go | 2 +- .../recursive_generation/subpkg1/Foo_mock.go | 2 +- .../recursive_generation/subpkg2/Foo_mock.go | 2 +- .../Foo_mock.go | 2 +- pkg/generator.go | 8 ++ 37 files changed, 189 insertions(+), 45 deletions(-) create mode 100644 mocks/github.com/vektra/mockery/v2/pkg/fixtures/EmptyReturn.go create mode 100644 pkg/fixtures/empty_return.go diff --git a/mocks/github.com/vektra/mockery/v2/pkg/TypesPackage.go b/mocks/github.com/vektra/mockery/v2/pkg/TypesPackage.go index dc30f202..c55fc0b5 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/TypesPackage.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/TypesPackage.go @@ -17,7 +17,7 @@ func (_m *TypesPackage) EXPECT() *TypesPackage_Expecter { return &TypesPackage_Expecter{mock: &_m.Mock} } -// Name provides a mock function with given fields: +// Name provides a mock function with no fields func (_m *TypesPackage) Name() string { ret := _m.Called() @@ -62,7 +62,7 @@ func (_c *TypesPackage_Name_Call) RunAndReturn(run func() string) *TypesPackage_ return _c } -// Path provides a mock function with given fields: +// Path provides a mock function with no fields func (_m *TypesPackage) Path() string { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/A.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/A.go index afbdf941..554a332f 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/A.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/A.go @@ -20,7 +20,7 @@ func (_m *A) EXPECT() *A_Expecter { return &A_Expecter{mock: &_m.Mock} } -// Call provides a mock function with given fields: +// Call provides a mock function with no fields func (_m *A) Call() (test.B, error) { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/AsyncProducer.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/AsyncProducer.go index bef64eca..d0021f22 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/AsyncProducer.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/AsyncProducer.go @@ -17,7 +17,7 @@ func (_m *AsyncProducer) EXPECT() *AsyncProducer_Expecter { return &AsyncProducer_Expecter{mock: &_m.Mock} } -// Input provides a mock function with given fields: +// Input provides a mock function with no fields func (_m *AsyncProducer) Input() chan<- bool { ret := _m.Called() @@ -64,7 +64,7 @@ func (_c *AsyncProducer_Input_Call) RunAndReturn(run func() chan<- bool) *AsyncP return _c } -// Output provides a mock function with given fields: +// Output provides a mock function with no fields func (_m *AsyncProducer) Output() <-chan bool { ret := _m.Called() @@ -111,7 +111,7 @@ func (_c *AsyncProducer_Output_Call) RunAndReturn(run func() <-chan bool) *Async return _c } -// Whatever provides a mock function with given fields: +// Whatever provides a mock function with no fields func (_m *AsyncProducer) Whatever() chan bool { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ConsulLock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ConsulLock.go index 2dfe5dc6..757154be 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ConsulLock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ConsulLock.go @@ -75,7 +75,7 @@ func (_c *ConsulLock_Lock_Call) RunAndReturn(run func(<-chan struct{}) (<-chan s return _c } -// Unlock provides a mock function with given fields: +// Unlock provides a mock function with no fields func (_m *ConsulLock) Unlock() error { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/EmbeddedGet.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/EmbeddedGet.go index a87f878a..aa3ee419 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/EmbeddedGet.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/EmbeddedGet.go @@ -20,7 +20,7 @@ func (_m *EmbeddedGet[T]) EXPECT() *EmbeddedGet_Expecter[T] { return &EmbeddedGet_Expecter[T]{mock: &_m.Mock} } -// Get provides a mock function with given fields: +// Get provides a mock function with no fields func (_m *EmbeddedGet[T]) Get() T { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/EmptyReturn.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/EmptyReturn.go new file mode 100644 index 00000000..37fd97e9 --- /dev/null +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/EmptyReturn.go @@ -0,0 +1,98 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// EmptyReturn is an autogenerated mock type for the EmptyReturn type +type EmptyReturn struct { + mock.Mock +} + +type EmptyReturn_Expecter struct { + mock *mock.Mock +} + +func (_m *EmptyReturn) EXPECT() *EmptyReturn_Expecter { + return &EmptyReturn_Expecter{mock: &_m.Mock} +} + +// NoArgs provides a mock function with no fields +func (_m *EmptyReturn) NoArgs() { + _m.Called() +} + +// EmptyReturn_NoArgs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NoArgs' +type EmptyReturn_NoArgs_Call struct { + *mock.Call +} + +// NoArgs is a helper method to define mock.On call +func (_e *EmptyReturn_Expecter) NoArgs() *EmptyReturn_NoArgs_Call { + return &EmptyReturn_NoArgs_Call{Call: _e.mock.On("NoArgs")} +} + +func (_c *EmptyReturn_NoArgs_Call) Run(run func()) *EmptyReturn_NoArgs_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *EmptyReturn_NoArgs_Call) Return() *EmptyReturn_NoArgs_Call { + _c.Call.Return() + return _c +} + +func (_c *EmptyReturn_NoArgs_Call) RunAndReturn(run func()) *EmptyReturn_NoArgs_Call { + _c.Run(run) + return _c +} + +// WithArgs provides a mock function with given fields: a, b +func (_m *EmptyReturn) WithArgs(a int, b string) { + _m.Called(a, b) +} + +// EmptyReturn_WithArgs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithArgs' +type EmptyReturn_WithArgs_Call struct { + *mock.Call +} + +// WithArgs is a helper method to define mock.On call +// - a int +// - b string +func (_e *EmptyReturn_Expecter) WithArgs(a interface{}, b interface{}) *EmptyReturn_WithArgs_Call { + return &EmptyReturn_WithArgs_Call{Call: _e.mock.On("WithArgs", a, b)} +} + +func (_c *EmptyReturn_WithArgs_Call) Run(run func(a int, b string)) *EmptyReturn_WithArgs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int), args[1].(string)) + }) + return _c +} + +func (_c *EmptyReturn_WithArgs_Call) Return() *EmptyReturn_WithArgs_Call { + _c.Call.Return() + return _c +} + +func (_c *EmptyReturn_WithArgs_Call) RunAndReturn(run func(int, string)) *EmptyReturn_WithArgs_Call { + _c.Run(run) + return _c +} + +// NewEmptyReturn creates a new instance of EmptyReturn. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewEmptyReturn(t interface { + mock.TestingT + Cleanup(func()) +}) *EmptyReturn { + mock := &EmptyReturn{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Example.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Example.go index 7cfeaae4..72cbf9bc 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Example.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Example.go @@ -24,7 +24,7 @@ func (_m *Example) EXPECT() *Example_Expecter { return &Example_Expecter{mock: &_m.Mock} } -// A provides a mock function with given fields: +// A provides a mock function with no fields func (_m *Example) A() http.Flusher { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Expecter.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Expecter.go index 2807c78d..7d3c9a26 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Expecter.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Expecter.go @@ -76,7 +76,7 @@ func (_c *Expecter_ManyArgsReturns_Call) RunAndReturn(run func(string, int) ([]s return _c } -// NoArg provides a mock function with given fields: +// NoArg provides a mock function with no fields func (_m *Expecter) NoArg() string { ret := _m.Called() @@ -150,7 +150,7 @@ func (_c *Expecter_NoReturn_Call) Return() *Expecter_NoReturn_Call { } func (_c *Expecter_NoReturn_Call) RunAndReturn(run func(string)) *Expecter_NoReturn_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ExpecterAndRolledVariadic.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ExpecterAndRolledVariadic.go index 6fd6ffa0..469f09ad 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ExpecterAndRolledVariadic.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ExpecterAndRolledVariadic.go @@ -76,7 +76,7 @@ func (_c *ExpecterAndRolledVariadic_ManyArgsReturns_Call) RunAndReturn(run func( return _c } -// NoArg provides a mock function with given fields: +// NoArg provides a mock function with no fields func (_m *ExpecterAndRolledVariadic) NoArg() string { ret := _m.Called() @@ -150,7 +150,7 @@ func (_c *ExpecterAndRolledVariadic_NoReturn_Call) Return() *ExpecterAndRolledVa } func (_c *ExpecterAndRolledVariadic_NoReturn_Call) RunAndReturn(run func(string)) *ExpecterAndRolledVariadic_NoReturn_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Fooer.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Fooer.go index c172417b..4e35c74c 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Fooer.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Fooer.go @@ -46,7 +46,7 @@ func (_c *Fooer_Bar_Call) Return() *Fooer_Bar_Call { } func (_c *Fooer_Bar_Call) RunAndReturn(run func(func([]int))) *Fooer_Bar_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetGeneric.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetGeneric.go index fadb46f7..c8f72669 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetGeneric.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetGeneric.go @@ -20,7 +20,7 @@ func (_m *GetGeneric[T]) EXPECT() *GetGeneric_Expecter[T] { return &GetGeneric_Expecter[T]{mock: &_m.Mock} } -// Get provides a mock function with given fields: +// Get provides a mock function with no fields func (_m *GetGeneric[T]) Get() T { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetInt.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetInt.go index 0eeb3b4f..4bf8d3f4 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetInt.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetInt.go @@ -17,7 +17,7 @@ func (_m *GetInt) EXPECT() *GetInt_Expecter { return &GetInt_Expecter{mock: &_m.Mock} } -// Get provides a mock function with given fields: +// Get provides a mock function with no fields func (_m *GetInt) Get() int { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/HasConflictingNestedImports.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/HasConflictingNestedImports.go index 7249de4f..540e229a 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/HasConflictingNestedImports.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/HasConflictingNestedImports.go @@ -79,7 +79,7 @@ func (_c *HasConflictingNestedImports_Get_Call) RunAndReturn(run func(string) (h return _c } -// Z provides a mock function with given fields: +// Z provides a mock function with no fields func (_m *HasConflictingNestedImports) Z() fixtureshttp.MyStruct { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ImportsSameAsPackage.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ImportsSameAsPackage.go index e8045f24..4886e516 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ImportsSameAsPackage.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ImportsSameAsPackage.go @@ -22,7 +22,7 @@ func (_m *ImportsSameAsPackage) EXPECT() *ImportsSameAsPackage_Expecter { return &ImportsSameAsPackage_Expecter{mock: &_m.Mock} } -// A provides a mock function with given fields: +// A provides a mock function with no fields func (_m *ImportsSameAsPackage) A() test.B { ret := _m.Called() @@ -67,7 +67,7 @@ func (_c *ImportsSameAsPackage_A_Call) RunAndReturn(run func() test.B) *ImportsS return _c } -// B provides a mock function with given fields: +// B provides a mock function with no fields func (_m *ImportsSameAsPackage) B() fixtures.KeyManager { ret := _m.Called() @@ -143,7 +143,7 @@ func (_c *ImportsSameAsPackage_C_Call) Return() *ImportsSameAsPackage_C_Call { } func (_c *ImportsSameAsPackage_C_Call) RunAndReturn(run func(fixtures.C)) *ImportsSameAsPackage_C_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MapToInterface.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MapToInterface.go index 7bbb9be3..d68815d9 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MapToInterface.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MapToInterface.go @@ -59,7 +59,7 @@ func (_c *MapToInterface_Foo_Call) Return() *MapToInterface_Foo_Call { } func (_c *MapToInterface_Foo_Call) RunAndReturn(run func(...map[string]interface{})) *MapToInterface_Foo_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/PanicOnNoReturnValue.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/PanicOnNoReturnValue.go index eaa5ea6e..4db1babf 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/PanicOnNoReturnValue.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/PanicOnNoReturnValue.go @@ -17,7 +17,7 @@ func (_m *PanicOnNoReturnValue) EXPECT() *PanicOnNoReturnValue_Expecter { return &PanicOnNoReturnValue_Expecter{mock: &_m.Mock} } -// DoSomething provides a mock function with given fields: +// DoSomething provides a mock function with no fields func (_m *PanicOnNoReturnValue) DoSomething() string { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGeneric.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGeneric.go index 91a89c8f..fe17e136 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGeneric.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGeneric.go @@ -68,7 +68,7 @@ func (_c *ReplaceGeneric_A_Call[TConstraint, TKeep]) RunAndReturn(run func(test. return _c } -// B provides a mock function with given fields: +// B provides a mock function with no fields func (_m *ReplaceGeneric[TConstraint, TKeep]) B() test.B { ret := _m.Called() @@ -113,7 +113,7 @@ func (_c *ReplaceGeneric_B_Call[TConstraint, TKeep]) RunAndReturn(run func() tes return _c } -// C provides a mock function with given fields: +// C provides a mock function with no fields func (_m *ReplaceGeneric[TConstraint, TKeep]) C() TConstraint { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGenericSelf.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGenericSelf.go index 8d2ef76e..7b2ebe68 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGenericSelf.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGenericSelf.go @@ -17,7 +17,7 @@ func (_m *ReplaceGenericSelf) EXPECT() *ReplaceGenericSelf_Expecter { return &ReplaceGenericSelf_Expecter{mock: &_m.Mock} } -// A provides a mock function with given fields: +// A provides a mock function with no fields func (_m *ReplaceGenericSelf) A() *ReplaceGenericSelf { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester3.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester3.go index 2c18c927..22c23daf 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester3.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester3.go @@ -17,7 +17,7 @@ func (_m *Requester3) EXPECT() *Requester3_Expecter { return &Requester3_Expecter{mock: &_m.Mock} } -// Get provides a mock function with given fields: +// Get provides a mock function with no fields func (_m *Requester3) Get() error { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester4.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester4.go index da8d2ced..d77199a0 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester4.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester4.go @@ -17,7 +17,7 @@ func (_m *Requester4) EXPECT() *Requester4_Expecter { return &Requester4_Expecter{mock: &_m.Mock} } -// Get provides a mock function with given fields: +// Get provides a mock function with no fields func (_m *Requester4) Get() { _m.Called() } @@ -45,7 +45,7 @@ func (_c *Requester4_Get_Call) Return() *Requester4_Get_Call { } func (_c *Requester4_Get_Call) RunAndReturn(run func()) *Requester4_Get_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsPkg.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsPkg.go index 40218b9d..1da35b17 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsPkg.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsPkg.go @@ -46,7 +46,7 @@ func (_c *RequesterArgSameAsPkg_Get_Call) Return() *RequesterArgSameAsPkg_Get_Ca } func (_c *RequesterArgSameAsPkg_Get_Call) RunAndReturn(run func(string)) *RequesterArgSameAsPkg_Get_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterIface.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterIface.go index 78c73113..2186b6cf 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterIface.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterIface.go @@ -21,7 +21,7 @@ func (_m *RequesterIface) EXPECT() *RequesterIface_Expecter { return &RequesterIface_Expecter{mock: &_m.Mock} } -// Get provides a mock function with given fields: +// Get provides a mock function with no fields func (_m *RequesterIface) Get() io.Reader { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Sibling.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Sibling.go index b2baf893..36bebf84 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Sibling.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Sibling.go @@ -17,7 +17,7 @@ func (_m *Sibling) EXPECT() *Sibling_Expecter { return &Sibling_Expecter{mock: &_m.Mock} } -// DoSomething provides a mock function with given fields: +// DoSomething provides a mock function with no fields func (_m *Sibling) DoSomething() { _m.Called() } @@ -45,7 +45,7 @@ func (_c *Sibling_DoSomething_Call) Return() *Sibling_DoSomething_Call { } func (_c *Sibling_DoSomething_Call) RunAndReturn(run func()) *Sibling_DoSomething_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UnsafeInterface.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UnsafeInterface.go index 22116c17..1e46e90b 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UnsafeInterface.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UnsafeInterface.go @@ -50,7 +50,7 @@ func (_c *UnsafeInterface_Do_Call) Return() *UnsafeInterface_Do_Call { } func (_c *UnsafeInterface_Do_Call) RunAndReturn(run func(*unsafe.Pointer)) *UnsafeInterface_Do_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UsesAny.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UsesAny.go index 050afa35..b601eac8 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UsesAny.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UsesAny.go @@ -17,7 +17,7 @@ func (_m *UsesAny) EXPECT() *UsesAny_Expecter { return &UsesAny_Expecter{mock: &_m.Mock} } -// GetReader provides a mock function with given fields: +// GetReader provides a mock function with no fields func (_m *UsesAny) GetReader() any { ret := _m.Called() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UsesOtherPkgIface.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UsesOtherPkgIface.go index 44228599..aa823c8f 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UsesOtherPkgIface.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UsesOtherPkgIface.go @@ -49,7 +49,7 @@ func (_c *UsesOtherPkgIface_DoSomethingElse_Call) Return() *UsesOtherPkgIface_Do } func (_c *UsesOtherPkgIface_DoSomethingElse_Call) RunAndReturn(run func(test.Sibling)) *UsesOtherPkgIface_DoSomethingElse_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/VariadicNoReturnInterface.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/VariadicNoReturnInterface.go index 4a751e0f..ea80e045 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/VariadicNoReturnInterface.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/VariadicNoReturnInterface.go @@ -59,7 +59,7 @@ func (_c *VariadicNoReturnInterface_VariadicNoReturn_Call) Return() *VariadicNoR } func (_c *VariadicNoReturnInterface_VariadicNoReturn_Call) RunAndReturn(run func(int, ...interface{})) *VariadicNoReturnInterface_VariadicNoReturn_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/buildtag/comment/IfaceWithCustomBuildTagInComment.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/buildtag/comment/IfaceWithCustomBuildTagInComment.go index 73bc3023..148ce91d 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/buildtag/comment/IfaceWithCustomBuildTagInComment.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/buildtag/comment/IfaceWithCustomBuildTagInComment.go @@ -19,7 +19,7 @@ func (_m *IfaceWithCustomBuildTagInComment) EXPECT() *IfaceWithCustomBuildTagInC return &IfaceWithCustomBuildTagInComment_Expecter{mock: &_m.Mock} } -// Custom2 provides a mock function with given fields: +// Custom2 provides a mock function with no fields func (_m *IfaceWithCustomBuildTagInComment) Custom2() { _m.Called() } @@ -47,7 +47,7 @@ func (_c *IfaceWithCustomBuildTagInComment_Custom2_Call) Return() *IfaceWithCust } func (_c *IfaceWithCustomBuildTagInComment_Custom2_Call) RunAndReturn(run func()) *IfaceWithCustomBuildTagInComment_Custom2_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/requesterUnexported.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/requesterUnexported.go index 381e991d..a37c2a35 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/requesterUnexported.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/requesterUnexported.go @@ -17,7 +17,7 @@ func (_m *requesterUnexported) EXPECT() *requesterUnexported_Expecter { return &requesterUnexported_Expecter{mock: &_m.Mock} } -// Get provides a mock function with given fields: +// Get provides a mock function with no fields func (_m *requesterUnexported) Get() { _m.Called() } @@ -45,7 +45,7 @@ func (_c *requesterUnexported_Get_Call) Return() *requesterUnexported_Get_Call { } func (_c *requesterUnexported_Get_Call) RunAndReturn(run func()) *requesterUnexported_Get_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/pkg/compat_test.go b/pkg/compat_test.go index 385e7d59..c752402b 100644 --- a/pkg/compat_test.go +++ b/pkg/compat_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" mocks "github.com/vektra/mockery/v2/mocks/github.com/vektra/mockery/v2/pkg/fixtures" + test "github.com/vektra/mockery/v2/pkg/fixtures" ) // CompatSuite covers compatibility with github.com/stretchr/testify/mock. @@ -35,6 +36,37 @@ func (s *CompatSuite) TestOnAnythingOfTypeVariadicArgs() { m.AssertCalled(t, "Sprintf", "int: %d string: %s", 22, "twenty two") } +func (s *CompatSuite) TestOnEmptyReturn() { + m := mocks.NewEmptyReturn(s.T()) + var target test.EmptyReturn = m + + s.Run("NoArgs", func() { + run := false + + m.EXPECT().NoArgs().RunAndReturn(func() { + run = true + }) + + target.NoArgs() + + s.True(run) + }) + + s.Run("WithArgs", func() { + run := false + + m.EXPECT().WithArgs(42, "foo").RunAndReturn(func(arg0 int, arg1 string) { + run = true + s.Equal(42, arg0) + s.Equal("foo", arg1) + }) + + target.WithArgs(42, "foo") + + s.True(run) + }) +} + func TestCompatSuite(t *testing.T) { mockcompatSuite := new(CompatSuite) suite.Run(t, mockcompatSuite) diff --git a/pkg/fixtures/empty_return.go b/pkg/fixtures/empty_return.go new file mode 100644 index 00000000..8ece725a --- /dev/null +++ b/pkg/fixtures/empty_return.go @@ -0,0 +1,6 @@ +package test + +type EmptyReturn interface { + NoArgs() + WithArgs(a int, b string) +} diff --git a/pkg/fixtures/method_args/same_name_arg_and_type/mock_interfaceB_test.go b/pkg/fixtures/method_args/same_name_arg_and_type/mock_interfaceB_test.go index f0538bd7..cbeff2df 100644 --- a/pkg/fixtures/method_args/same_name_arg_and_type/mock_interfaceB_test.go +++ b/pkg/fixtures/method_args/same_name_arg_and_type/mock_interfaceB_test.go @@ -17,7 +17,7 @@ func (_m *interfaceBMock) EXPECT() *interfaceBMock_Expecter { return &interfaceBMock_Expecter{mock: &_m.Mock} } -// GetData provides a mock function with given fields: +// GetData provides a mock function with no fields func (_m *interfaceBMock) GetData() int { ret := _m.Called() diff --git a/pkg/fixtures/recursive_generation/Foo_mock.go b/pkg/fixtures/recursive_generation/Foo_mock.go index 1374b9fa..fbb8fd00 100644 --- a/pkg/fixtures/recursive_generation/Foo_mock.go +++ b/pkg/fixtures/recursive_generation/Foo_mock.go @@ -17,7 +17,7 @@ func (_m *MockFoo) EXPECT() *MockFoo_Expecter { return &MockFoo_Expecter{mock: &_m.Mock} } -// Get provides a mock function with given fields: +// Get provides a mock function with no fields func (_m *MockFoo) Get() string { ret := _m.Called() diff --git a/pkg/fixtures/recursive_generation/subpkg1/Foo_mock.go b/pkg/fixtures/recursive_generation/subpkg1/Foo_mock.go index 50697c1d..a4ae0651 100644 --- a/pkg/fixtures/recursive_generation/subpkg1/Foo_mock.go +++ b/pkg/fixtures/recursive_generation/subpkg1/Foo_mock.go @@ -17,7 +17,7 @@ func (_m *MockFoo) EXPECT() *MockFoo_Expecter { return &MockFoo_Expecter{mock: &_m.Mock} } -// Get provides a mock function with given fields: +// Get provides a mock function with no fields func (_m *MockFoo) Get() string { ret := _m.Called() diff --git a/pkg/fixtures/recursive_generation/subpkg2/Foo_mock.go b/pkg/fixtures/recursive_generation/subpkg2/Foo_mock.go index fe92d118..eef312d8 100644 --- a/pkg/fixtures/recursive_generation/subpkg2/Foo_mock.go +++ b/pkg/fixtures/recursive_generation/subpkg2/Foo_mock.go @@ -17,7 +17,7 @@ func (_m *MockFoo) EXPECT() *MockFoo_Expecter { return &MockFoo_Expecter{mock: &_m.Mock} } -// Get provides a mock function with given fields: +// Get provides a mock function with no fields func (_m *MockFoo) Get() string { ret := _m.Called() diff --git a/pkg/fixtures/recursive_generation/subpkg_with_only_autogenerated_files/Foo_mock.go b/pkg/fixtures/recursive_generation/subpkg_with_only_autogenerated_files/Foo_mock.go index 9648bcfd..b852f2c4 100644 --- a/pkg/fixtures/recursive_generation/subpkg_with_only_autogenerated_files/Foo_mock.go +++ b/pkg/fixtures/recursive_generation/subpkg_with_only_autogenerated_files/Foo_mock.go @@ -17,7 +17,7 @@ func (_m *MockFoo) EXPECT() *MockFoo_Expecter { return &MockFoo_Expecter{mock: &_m.Mock} } -// Get provides a mock function with given fields: +// Get provides a mock function with no fields func (_m *MockFoo) Get() string { ret := _m.Called() diff --git a/pkg/generator.go b/pkg/generator.go index f015a651..b338b061 100644 --- a/pkg/generator.go +++ b/pkg/generator.go @@ -826,7 +826,11 @@ func (g *Generator) generateMethod(ctx context.Context, method *Method) { } g.printTemplate(data, ` +{{- if gt (len .Params.Names) 0}} // {{.FunctionName}} provides a mock function with given fields: {{join .Params.Names ", "}} +{{- else}} +// {{.FunctionName}} provides a mock function with no fields +{{- end}} 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}} @@ -980,7 +984,11 @@ func (_c *{{.CallStruct}}{{ .InstantiatedTypeString }}) Return({{range .Returns. } func (_c *{{.CallStruct}}{{ .InstantiatedTypeString }}) RunAndReturn(run func({{range .Params.Types}}{{.}},{{end}})({{range .Returns.Types}}{{.}},{{end}})) *{{.CallStruct}}{{ .InstantiatedTypeString }} { +{{- if not .Returns.Types}} + _c.Run(run) +{{- else}} _c.Call.Return(run) +{{- end}} return _c } `)