From 445f73c80b61ff771450c7ec0f0836b6062f3aa3 Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Mon, 20 Nov 2023 08:46:28 -0300 Subject: [PATCH] added new check for no return values --- .../vektra/mockery/v2/pkg/TypesPackage.go | 8 ++ .../vektra/mockery/v2/pkg/fixtures/A.go | 4 + .../mockery/v2/pkg/fixtures/AsyncProducer.go | 12 +++ .../vektra/mockery/v2/pkg/fixtures/Blank.go | 4 + .../mockery/v2/pkg/fixtures/ConsulLock.go | 8 ++ .../mockery/v2/pkg/fixtures/EmbeddedGet.go | 4 + .../vektra/mockery/v2/pkg/fixtures/Example.go | 8 ++ .../mockery/v2/pkg/fixtures/Expecter.go | 16 ++++ .../pkg/fixtures/ExpecterAndRolledVariadic.go | 16 ++++ .../vektra/mockery/v2/pkg/fixtures/Fooer.go | 8 ++ .../v2/pkg/fixtures/FuncArgsCollision.go | 4 + .../mockery/v2/pkg/fixtures/GetGeneric.go | 4 + .../vektra/mockery/v2/pkg/fixtures/GetInt.go | 4 + .../fixtures/HasConflictingNestedImports.go | 8 ++ .../v2/pkg/fixtures/ImportsSameAsPackage.go | 8 ++ .../mockery/v2/pkg/fixtures/KeyManager.go | 4 + .../vektra/mockery/v2/pkg/fixtures/MapFunc.go | 4 + .../mockery/v2/pkg/fixtures/MyReader.go | 4 + .../v2/pkg/fixtures/PanicOnNoReturnValue.go | 77 +++++++++++++++++++ .../mockery/v2/pkg/fixtures/Requester.go | 4 + .../mockery/v2/pkg/fixtures/Requester2.go | 4 + .../mockery/v2/pkg/fixtures/Requester3.go | 4 + .../pkg/fixtures/RequesterArgSameAsImport.go | 4 + .../fixtures/RequesterArgSameAsNamedImport.go | 4 + .../mockery/v2/pkg/fixtures/RequesterArray.go | 4 + .../v2/pkg/fixtures/RequesterElided.go | 4 + .../v2/pkg/fixtures/RequesterGenerics.go | 12 +++ .../mockery/v2/pkg/fixtures/RequesterIface.go | 4 + .../mockery/v2/pkg/fixtures/RequesterNS.go | 4 + .../mockery/v2/pkg/fixtures/RequesterPtr.go | 4 + .../v2/pkg/fixtures/RequesterReturnElided.go | 8 ++ .../mockery/v2/pkg/fixtures/RequesterSlice.go | 4 + .../v2/pkg/fixtures/RequesterVariadic.go | 16 ++++ .../fixtures/RequesterVariadicOneArgument.go | 16 ++++ .../mockery/v2/pkg/fixtures/SendFunc.go | 4 + .../mockery/v2/pkg/fixtures/StructWithTag.go | 4 + .../mock_interfaceA_test.go | 12 +++ .../mock_interfaceB0_test.go | 4 + .../mock_interfaceB_test.go | 4 + pkg/fixtures/panic_err.go | 5 ++ pkg/fixtures/recursive_generation/Foo_mock.go | 4 + .../recursive_generation/subpkg1/Foo_mock.go | 4 + .../recursive_generation/subpkg2/Foo_mock.go | 4 + .../Foo_mock.go | 4 + pkg/generator.go | 4 + pkg/generator_test.go | 4 + 46 files changed, 358 insertions(+) create mode 100644 mocks/github.com/vektra/mockery/v2/pkg/fixtures/PanicOnNoReturnValue.go create mode 100644 pkg/fixtures/panic_err.go diff --git a/mocks/github.com/vektra/mockery/v2/pkg/TypesPackage.go b/mocks/github.com/vektra/mockery/v2/pkg/TypesPackage.go index a1b85506..44f96296 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/TypesPackage.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/TypesPackage.go @@ -21,6 +21,10 @@ func (_m *TypesPackage) EXPECT() *TypesPackage_Expecter { func (_m *TypesPackage) Name() string { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Name") + } + var r0 string if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() @@ -62,6 +66,10 @@ func (_c *TypesPackage_Name_Call) RunAndReturn(run func() string) *TypesPackage_ func (_m *TypesPackage) Path() string { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Path") + } + var r0 string if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() 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 4d5a41f0..c7682dea 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/A.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/A.go @@ -24,6 +24,10 @@ func (_m *A) EXPECT() *A_Expecter { func (_m *A) Call() (test.B, error) { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Call") + } + var r0 test.B var r1 error if rf, ok := ret.Get(0).(func() (test.B, error)); ok { 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 9badf642..e2f21751 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/AsyncProducer.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/AsyncProducer.go @@ -21,6 +21,10 @@ func (_m *AsyncProducer) EXPECT() *AsyncProducer_Expecter { func (_m *AsyncProducer) Input() chan<- bool { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Input") + } + var r0 chan<- bool if rf, ok := ret.Get(0).(func() chan<- bool); ok { r0 = rf() @@ -64,6 +68,10 @@ func (_c *AsyncProducer_Input_Call) RunAndReturn(run func() chan<- bool) *AsyncP func (_m *AsyncProducer) Output() <-chan bool { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Output") + } + var r0 <-chan bool if rf, ok := ret.Get(0).(func() <-chan bool); ok { r0 = rf() @@ -107,6 +115,10 @@ func (_c *AsyncProducer_Output_Call) RunAndReturn(run func() <-chan bool) *Async func (_m *AsyncProducer) Whatever() chan bool { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Whatever") + } + var r0 chan bool if rf, ok := ret.Get(0).(func() chan bool); ok { r0 = rf() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Blank.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Blank.go index e25ed682..50a08902 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Blank.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Blank.go @@ -21,6 +21,10 @@ func (_m *Blank) EXPECT() *Blank_Expecter { func (_m *Blank) Create(x interface{}) error { ret := _m.Called(x) + if len(ret) == 0 { + panic("Missing Return() function for Create") + } + var r0 error if rf, ok := ret.Get(0).(func(interface{}) error); ok { r0 = rf(x) 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 dc953f25..9bdeb62a 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ConsulLock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ConsulLock.go @@ -21,6 +21,10 @@ func (_m *ConsulLock) EXPECT() *ConsulLock_Expecter { func (_m *ConsulLock) Lock(_a0 <-chan struct{}) (<-chan struct{}, error) { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("Missing Return() function for Lock") + } + var r0 <-chan struct{} var r1 error if rf, ok := ret.Get(0).(func(<-chan struct{}) (<-chan struct{}, error)); ok { @@ -75,6 +79,10 @@ func (_c *ConsulLock_Lock_Call) RunAndReturn(run func(<-chan struct{}) (<-chan s func (_m *ConsulLock) Unlock() error { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Unlock") + } + var r0 error if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() 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 19fa5584..1954d434 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/EmbeddedGet.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/EmbeddedGet.go @@ -24,6 +24,10 @@ func (_m *EmbeddedGet[T]) EXPECT() *EmbeddedGet_Expecter[T] { func (_m *EmbeddedGet[T]) Get() T { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 T if rf, ok := ret.Get(0).(func() T); ok { r0 = rf() 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 0a9ab4c2..a67b163d 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Example.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Example.go @@ -27,6 +27,10 @@ func (_m *Example) EXPECT() *Example_Expecter { func (_m *Example) A() http.Flusher { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for A") + } + var r0 http.Flusher if rf, ok := ret.Get(0).(func() http.Flusher); ok { r0 = rf() @@ -70,6 +74,10 @@ func (_c *Example_A_Call) RunAndReturn(run func() http.Flusher) *Example_A_Call func (_m *Example) B(_a0 string) fixtureshttp.MyStruct { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("Missing Return() function for B") + } + var r0 fixtureshttp.MyStruct if rf, ok := ret.Get(0).(func(string) fixtureshttp.MyStruct); ok { r0 = rf(_a0) 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 bd3c0f3a..69aec464 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Expecter.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Expecter.go @@ -21,6 +21,10 @@ func (_m *Expecter) EXPECT() *Expecter_Expecter { func (_m *Expecter) ManyArgsReturns(str string, i int) ([]string, error) { ret := _m.Called(str, i) + if len(ret) == 0 { + panic("Missing Return() function for ManyArgsReturns") + } + var r0 []string var r1 error if rf, ok := ret.Get(0).(func(string, int) ([]string, error)); ok { @@ -76,6 +80,10 @@ func (_c *Expecter_ManyArgsReturns_Call) RunAndReturn(run func(string, int) ([]s func (_m *Expecter) NoArg() string { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for NoArg") + } + var r0 string if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() @@ -156,6 +164,10 @@ func (_m *Expecter) Variadic(ints ...int) error { _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("Missing Return() function for Variadic") + } + var r0 error if rf, ok := ret.Get(0).(func(...int) error); ok { r0 = rf(ints...) @@ -208,6 +220,10 @@ func (_m *Expecter) VariadicMany(i int, a string, intfs ...interface{}) error { _ca = append(_ca, intfs...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("Missing Return() function for VariadicMany") + } + var r0 error if rf, ok := ret.Get(0).(func(int, string, ...interface{}) error); ok { r0 = rf(i, a, intfs...) 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 c0b83854..9060e407 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ExpecterAndRolledVariadic.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ExpecterAndRolledVariadic.go @@ -21,6 +21,10 @@ func (_m *ExpecterAndRolledVariadic) EXPECT() *ExpecterAndRolledVariadic_Expecte func (_m *ExpecterAndRolledVariadic) ManyArgsReturns(str string, i int) ([]string, error) { ret := _m.Called(str, i) + if len(ret) == 0 { + panic("Missing Return() function for ManyArgsReturns") + } + var r0 []string var r1 error if rf, ok := ret.Get(0).(func(string, int) ([]string, error)); ok { @@ -76,6 +80,10 @@ func (_c *ExpecterAndRolledVariadic_ManyArgsReturns_Call) RunAndReturn(run func( func (_m *ExpecterAndRolledVariadic) NoArg() string { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for NoArg") + } + var r0 string if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() @@ -156,6 +164,10 @@ func (_m *ExpecterAndRolledVariadic) Variadic(ints ...int) error { } ret := tmpRet + if len(ret) == 0 { + panic("Missing Return() function for Variadic") + } + var r0 error if rf, ok := ret.Get(0).(func(...int) error); ok { r0 = rf(ints...) @@ -211,6 +223,10 @@ func (_m *ExpecterAndRolledVariadic) VariadicMany(i int, a string, intfs ...inte } ret := tmpRet + if len(ret) == 0 { + panic("Missing Return() function for VariadicMany") + } + var r0 error if rf, ok := ret.Get(0).(func(int, string, ...interface{}) error); ok { r0 = rf(i, a, intfs...) 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 6d3f1338..38fb0681 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Fooer.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Fooer.go @@ -54,6 +54,10 @@ func (_c *Fooer_Bar_Call) RunAndReturn(run func(func([]int))) *Fooer_Bar_Call { func (_m *Fooer) Baz(path string) func(string) string { ret := _m.Called(path) + if len(ret) == 0 { + panic("Missing Return() function for Baz") + } + var r0 func(string) string if rf, ok := ret.Get(0).(func(string) func(string) string); ok { r0 = rf(path) @@ -98,6 +102,10 @@ func (_c *Fooer_Baz_Call) RunAndReturn(run func(string) func(string) string) *Fo func (_m *Fooer) Foo(f func(string) string) error { ret := _m.Called(f) + if len(ret) == 0 { + panic("Missing Return() function for Foo") + } + var r0 error if rf, ok := ret.Get(0).(func(func(string) string) error); ok { r0 = rf(f) diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/FuncArgsCollision.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/FuncArgsCollision.go index 376dde63..c0872d14 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/FuncArgsCollision.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/FuncArgsCollision.go @@ -21,6 +21,10 @@ func (_m *FuncArgsCollision) EXPECT() *FuncArgsCollision_Expecter { func (_m *FuncArgsCollision) Foo(ret interface{}) error { ret_1 := _m.Called(ret) + if len(ret_1) == 0 { + panic("Missing Return() function for Foo") + } + var r0 error if rf, ok := ret_1.Get(0).(func(interface{}) error); ok { r0 = rf(ret) 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 fb4498c8..f943eaa1 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetGeneric.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetGeneric.go @@ -24,6 +24,10 @@ func (_m *GetGeneric[T]) EXPECT() *GetGeneric_Expecter[T] { func (_m *GetGeneric[T]) Get() T { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 T if rf, ok := ret.Get(0).(func() T); ok { r0 = rf() 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 5dc1d005..e8a73206 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetInt.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetInt.go @@ -21,6 +21,10 @@ func (_m *GetInt) EXPECT() *GetInt_Expecter { func (_m *GetInt) Get() int { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 int if rf, ok := ret.Get(0).(func() int); ok { r0 = rf() 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 6930277c..7785d1fd 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/HasConflictingNestedImports.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/HasConflictingNestedImports.go @@ -27,6 +27,10 @@ func (_m *HasConflictingNestedImports) EXPECT() *HasConflictingNestedImports_Exp func (_m *HasConflictingNestedImports) Get(path string) (http.Response, error) { ret := _m.Called(path) + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 http.Response var r1 error if rf, ok := ret.Get(0).(func(string) (http.Response, error)); ok { @@ -79,6 +83,10 @@ func (_c *HasConflictingNestedImports_Get_Call) RunAndReturn(run func(string) (h func (_m *HasConflictingNestedImports) Z() fixtureshttp.MyStruct { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Z") + } + var r0 fixtureshttp.MyStruct if rf, ok := ret.Get(0).(func() fixtureshttp.MyStruct); ok { r0 = rf() 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 cb77c712..a9e4899d 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ImportsSameAsPackage.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ImportsSameAsPackage.go @@ -26,6 +26,10 @@ func (_m *ImportsSameAsPackage) EXPECT() *ImportsSameAsPackage_Expecter { func (_m *ImportsSameAsPackage) A() test.B { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for A") + } + var r0 test.B if rf, ok := ret.Get(0).(func() test.B); ok { r0 = rf() @@ -67,6 +71,10 @@ func (_c *ImportsSameAsPackage_A_Call) RunAndReturn(run func() test.B) *ImportsS func (_m *ImportsSameAsPackage) B() fixtures.KeyManager { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for B") + } + var r0 fixtures.KeyManager if rf, ok := ret.Get(0).(func() fixtures.KeyManager); ok { r0 = rf() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/KeyManager.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/KeyManager.go index d8ac6934..cd2a4261 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/KeyManager.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/KeyManager.go @@ -24,6 +24,10 @@ func (_m *KeyManager) EXPECT() *KeyManager_Expecter { func (_m *KeyManager) GetKey(_a0 string, _a1 uint16) ([]byte, *test.Err) { ret := _m.Called(_a0, _a1) + if len(ret) == 0 { + panic("Missing Return() function for GetKey") + } + var r0 []byte var r1 *test.Err if rf, ok := ret.Get(0).(func(string, uint16) ([]byte, *test.Err)); ok { diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MapFunc.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MapFunc.go index 89c0e2f1..9635f5e3 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MapFunc.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MapFunc.go @@ -21,6 +21,10 @@ func (_m *MapFunc) EXPECT() *MapFunc_Expecter { func (_m *MapFunc) Get(m map[string]func(string) string) error { ret := _m.Called(m) + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 error if rf, ok := ret.Get(0).(func(map[string]func(string) string) error); ok { r0 = rf(m) diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MyReader.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MyReader.go index e2caf1d4..eae82a0b 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MyReader.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MyReader.go @@ -21,6 +21,10 @@ func (_m *MyReader) EXPECT() *MyReader_Expecter { func (_m *MyReader) Read(p []byte) (int, error) { ret := _m.Called(p) + if len(ret) == 0 { + panic("Missing Return() function for Read") + } + var r0 int var r1 error if rf, ok := ret.Get(0).(func([]byte) (int, error)); ok { diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/PanicOnNoReturnValue.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/PanicOnNoReturnValue.go new file mode 100644 index 00000000..165aaa03 --- /dev/null +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/PanicOnNoReturnValue.go @@ -0,0 +1,77 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// PanicOnNoReturnValue is an autogenerated mock type for the PanicOnNoReturnValue type +type PanicOnNoReturnValue struct { + mock.Mock +} + +type PanicOnNoReturnValue_Expecter struct { + mock *mock.Mock +} + +func (_m *PanicOnNoReturnValue) EXPECT() *PanicOnNoReturnValue_Expecter { + return &PanicOnNoReturnValue_Expecter{mock: &_m.Mock} +} + +// DoSomething provides a mock function with given fields: +func (_m *PanicOnNoReturnValue) DoSomething() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("Missing Return() function for DoSomething") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// PanicOnNoReturnValue_DoSomething_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DoSomething' +type PanicOnNoReturnValue_DoSomething_Call struct { + *mock.Call +} + +// DoSomething is a helper method to define mock.On call +func (_e *PanicOnNoReturnValue_Expecter) DoSomething() *PanicOnNoReturnValue_DoSomething_Call { + return &PanicOnNoReturnValue_DoSomething_Call{Call: _e.mock.On("DoSomething")} +} + +func (_c *PanicOnNoReturnValue_DoSomething_Call) Run(run func()) *PanicOnNoReturnValue_DoSomething_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *PanicOnNoReturnValue_DoSomething_Call) Return(_a0 string) *PanicOnNoReturnValue_DoSomething_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PanicOnNoReturnValue_DoSomething_Call) RunAndReturn(run func() string) *PanicOnNoReturnValue_DoSomething_Call { + _c.Call.Return(run) + return _c +} + +// NewPanicOnNoReturnValue creates a new instance of PanicOnNoReturnValue. 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 NewPanicOnNoReturnValue(t interface { + mock.TestingT + Cleanup(func()) +}) *PanicOnNoReturnValue { + mock := &PanicOnNoReturnValue{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester.go index 9e38a0d1..7b253fc3 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester.go @@ -21,6 +21,10 @@ func (_m *Requester) EXPECT() *Requester_Expecter { func (_m *Requester) Get(path string) (string, error) { ret := _m.Called(path) + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 string var r1 error if rf, ok := ret.Get(0).(func(string) (string, error)); ok { diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester2.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester2.go index 24b0d7a4..a0dcea9b 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester2.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester2.go @@ -21,6 +21,10 @@ func (_m *Requester2) EXPECT() *Requester2_Expecter { func (_m *Requester2) Get(path string) error { ret := _m.Called(path) + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 error if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(path) 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 81f1cf34..1eb09b54 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester3.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester3.go @@ -21,6 +21,10 @@ func (_m *Requester3) EXPECT() *Requester3_Expecter { func (_m *Requester3) Get() error { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 error if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsImport.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsImport.go index 4eab525d..0717bc27 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsImport.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsImport.go @@ -25,6 +25,10 @@ func (_m *RequesterArgSameAsImport) EXPECT() *RequesterArgSameAsImport_Expecter func (_m *RequesterArgSameAsImport) Get(_a0 string) *json.RawMessage { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 *json.RawMessage if rf, ok := ret.Get(0).(func(string) *json.RawMessage); ok { r0 = rf(_a0) diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsNamedImport.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsNamedImport.go index 28baf9bf..2cee7fee 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsNamedImport.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsNamedImport.go @@ -25,6 +25,10 @@ func (_m *RequesterArgSameAsNamedImport) EXPECT() *RequesterArgSameAsNamedImport func (_m *RequesterArgSameAsNamedImport) Get(_a0 string) *json.RawMessage { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 *json.RawMessage if rf, ok := ret.Get(0).(func(string) *json.RawMessage); ok { r0 = rf(_a0) diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArray.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArray.go index dbd40479..f10aa651 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArray.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArray.go @@ -21,6 +21,10 @@ func (_m *RequesterArray) EXPECT() *RequesterArray_Expecter { func (_m *RequesterArray) Get(path string) ([2]string, error) { ret := _m.Called(path) + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 [2]string var r1 error if rf, ok := ret.Get(0).(func(string) ([2]string, error)); ok { diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterElided.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterElided.go index 9d9b9623..b9a78588 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterElided.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterElided.go @@ -21,6 +21,10 @@ func (_m *RequesterElided) EXPECT() *RequesterElided_Expecter { func (_m *RequesterElided) Get(path string, url string) error { ret := _m.Called(path, url) + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 error if rf, ok := ret.Get(0).(func(string, string) error); ok { r0 = rf(path, url) diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterGenerics.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterGenerics.go index bb31f67c..46351dd0 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterGenerics.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterGenerics.go @@ -37,6 +37,10 @@ func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TG } { ret := _m.Called(_a0) + if len(ret) == 0 { + panic("Missing Return() function for GenericAnonymousStructs") + } + var r0 struct { Type2 test.GenericType[string, test.EmbeddedGet[int]] } @@ -92,6 +96,10 @@ func (_c *RequesterGenerics_GenericAnonymousStructs_Call[TAny, TComparable, TSig func (_m *RequesterGenerics[TAny, TComparable, TSigned, TIntf, TExternalIntf, TGenIntf, TInlineType, TInlineTypeGeneric]) GenericArguments(_a0 TAny, _a1 TComparable) (TSigned, TIntf) { ret := _m.Called(_a0, _a1) + if len(ret) == 0 { + panic("Missing Return() function for GenericArguments") + } + var r0 TSigned var r1 TIntf if rf, ok := ret.Get(0).(func(TAny, TComparable) (TSigned, TIntf)); ok { @@ -148,6 +156,10 @@ func (_c *RequesterGenerics_GenericArguments_Call[TAny, TComparable, TSigned, TI 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) + if len(ret) == 0 { + panic("Missing Return() function for GenericStructs") + } + 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) 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 66e87c14..64135c69 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterIface.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterIface.go @@ -25,6 +25,10 @@ func (_m *RequesterIface) EXPECT() *RequesterIface_Expecter { func (_m *RequesterIface) Get() io.Reader { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 io.Reader if rf, ok := ret.Get(0).(func() io.Reader); ok { r0 = rf() diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterNS.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterNS.go index bf7c66c7..403535b5 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterNS.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterNS.go @@ -25,6 +25,10 @@ func (_m *RequesterNS) EXPECT() *RequesterNS_Expecter { func (_m *RequesterNS) Get(path string) (http.Response, error) { ret := _m.Called(path) + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 http.Response var r1 error if rf, ok := ret.Get(0).(func(string) (http.Response, error)); ok { diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterPtr.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterPtr.go index 3d210460..4cef8d4a 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterPtr.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterPtr.go @@ -21,6 +21,10 @@ func (_m *RequesterPtr) EXPECT() *RequesterPtr_Expecter { func (_m *RequesterPtr) Get(path string) (*string, error) { ret := _m.Called(path) + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 *string var r1 error if rf, ok := ret.Get(0).(func(string) (*string, error)); ok { diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterReturnElided.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterReturnElided.go index ada3692c..af1e48cd 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterReturnElided.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterReturnElided.go @@ -21,6 +21,10 @@ func (_m *RequesterReturnElided) EXPECT() *RequesterReturnElided_Expecter { func (_m *RequesterReturnElided) Get(path string) (int, int, int, error) { ret := _m.Called(path) + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 int var r1 int var r2 int @@ -87,6 +91,10 @@ func (_c *RequesterReturnElided_Get_Call) RunAndReturn(run func(string) (int, in func (_m *RequesterReturnElided) Put(path string) (int, error) { ret := _m.Called(path) + if len(ret) == 0 { + panic("Missing Return() function for Put") + } + var r0 int var r1 error if rf, ok := ret.Get(0).(func(string) (int, error)); ok { diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterSlice.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterSlice.go index 74ac52f3..a753bdce 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterSlice.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterSlice.go @@ -21,6 +21,10 @@ func (_m *RequesterSlice) EXPECT() *RequesterSlice_Expecter { func (_m *RequesterSlice) Get(path string) ([]string, error) { ret := _m.Called(path) + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 []string var r1 error if rf, ok := ret.Get(0).(func(string) ([]string, error)); ok { diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterVariadic.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterVariadic.go index 94c3b1e0..fa80c6f7 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterVariadic.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterVariadic.go @@ -23,6 +23,10 @@ func (_m *RequesterVariadic) Get(values ...string) bool { _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 bool if rf, ok := ret.Get(0).(func(...string) bool); ok { r0 = rf(values...) @@ -44,6 +48,10 @@ func (_m *RequesterVariadic) MultiWriteToFile(filename string, w ...io.Writer) s _ca = append(_ca, _va...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("Missing Return() function for MultiWriteToFile") + } + var r0 string if rf, ok := ret.Get(0).(func(string, ...io.Writer) string); ok { r0 = rf(filename, w...) @@ -60,6 +68,10 @@ func (_m *RequesterVariadic) OneInterface(a ...interface{}) bool { _ca = append(_ca, a...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("Missing Return() function for OneInterface") + } + var r0 bool if rf, ok := ret.Get(0).(func(...interface{}) bool); ok { r0 = rf(a...) @@ -77,6 +89,10 @@ func (_m *RequesterVariadic) Sprintf(format string, a ...interface{}) string { _ca = append(_ca, a...) ret := _m.Called(_ca...) + if len(ret) == 0 { + panic("Missing Return() function for Sprintf") + } + var r0 string if rf, ok := ret.Get(0).(func(string, ...interface{}) string); ok { r0 = rf(format, a...) diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterVariadicOneArgument.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterVariadicOneArgument.go index 84f4d352..c5473cc8 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterVariadicOneArgument.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterVariadicOneArgument.go @@ -17,6 +17,10 @@ type RequesterVariadicOneArgument struct { func (_m *RequesterVariadicOneArgument) Get(values ...string) bool { ret := _m.Called(values) + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 bool if rf, ok := ret.Get(0).(func(...string) bool); ok { r0 = rf(values...) @@ -31,6 +35,10 @@ func (_m *RequesterVariadicOneArgument) Get(values ...string) bool { func (_m *RequesterVariadicOneArgument) MultiWriteToFile(filename string, w ...io.Writer) string { ret := _m.Called(filename, w) + if len(ret) == 0 { + panic("Missing Return() function for MultiWriteToFile") + } + var r0 string if rf, ok := ret.Get(0).(func(string, ...io.Writer) string); ok { r0 = rf(filename, w...) @@ -45,6 +53,10 @@ func (_m *RequesterVariadicOneArgument) MultiWriteToFile(filename string, w ...i func (_m *RequesterVariadicOneArgument) OneInterface(a ...interface{}) bool { ret := _m.Called(a) + if len(ret) == 0 { + panic("Missing Return() function for OneInterface") + } + var r0 bool if rf, ok := ret.Get(0).(func(...interface{}) bool); ok { r0 = rf(a...) @@ -59,6 +71,10 @@ func (_m *RequesterVariadicOneArgument) OneInterface(a ...interface{}) bool { func (_m *RequesterVariadicOneArgument) Sprintf(format string, a ...interface{}) string { ret := _m.Called(format, a) + if len(ret) == 0 { + panic("Missing Return() function for Sprintf") + } + var r0 string if rf, ok := ret.Get(0).(func(string, ...interface{}) string); ok { r0 = rf(format, a...) diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/SendFunc.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/SendFunc.go index 4db2e677..7ca04e5c 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/SendFunc.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/SendFunc.go @@ -25,6 +25,10 @@ func (_m *SendFunc) EXPECT() *SendFunc_Expecter { func (_m *SendFunc) Execute(ctx context.Context, data string) (int, error) { ret := _m.Called(ctx, data) + if len(ret) == 0 { + panic("Missing Return() function for Execute") + } + var r0 int var r1 error if rf, ok := ret.Get(0).(func(context.Context, string) (int, error)); ok { diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/StructWithTag.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/StructWithTag.go index 498115de..96e4c89d 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/StructWithTag.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/StructWithTag.go @@ -27,6 +27,10 @@ func (_m *StructWithTag) MethodA(v *struct { } { ret := _m.Called(v) + if len(ret) == 0 { + panic("Missing Return() function for MethodA") + } + var r0 *struct { FieldC int `json:"field_c"` FieldD int `json:"field_d" xml:"field_d"` diff --git a/pkg/fixtures/method_args/same_name_arg_and_type/mock_interfaceA_test.go b/pkg/fixtures/method_args/same_name_arg_and_type/mock_interfaceA_test.go index db1e5a0b..6b331a50 100644 --- a/pkg/fixtures/method_args/same_name_arg_and_type/mock_interfaceA_test.go +++ b/pkg/fixtures/method_args/same_name_arg_and_type/mock_interfaceA_test.go @@ -21,6 +21,10 @@ func (_m *interfaceAMock) EXPECT() *interfaceAMock_Expecter { func (_m *interfaceAMock) DoB(interfaceB0 interfaceB) interfaceB { ret := _m.Called(interfaceB0) + if len(ret) == 0 { + panic("Missing Return() function for DoB") + } + var r0 interfaceB if rf, ok := ret.Get(0).(func(interfaceB) interfaceB); ok { r0 = rf(interfaceB0) @@ -65,6 +69,10 @@ func (_c *interfaceAMock_DoB_Call) RunAndReturn(run func(interfaceB) interfaceB) func (_m *interfaceAMock) DoB0(interfaceB interfaceB0) interfaceB0 { ret := _m.Called(interfaceB) + if len(ret) == 0 { + panic("Missing Return() function for DoB0") + } + var r0 interfaceB0 if rf, ok := ret.Get(0).(func(interfaceB0) interfaceB0); ok { r0 = rf(interfaceB) @@ -109,6 +117,10 @@ func (_c *interfaceAMock_DoB0_Call) RunAndReturn(run func(interfaceB0) interface func (_m *interfaceAMock) DoB0v2(interfaceB00 interfaceB0) interfaceB0 { ret := _m.Called(interfaceB00) + if len(ret) == 0 { + panic("Missing Return() function for DoB0v2") + } + var r0 interfaceB0 if rf, ok := ret.Get(0).(func(interfaceB0) interfaceB0); ok { r0 = rf(interfaceB00) diff --git a/pkg/fixtures/method_args/same_name_arg_and_type/mock_interfaceB0_test.go b/pkg/fixtures/method_args/same_name_arg_and_type/mock_interfaceB0_test.go index 65bdfd1d..f5e86573 100644 --- a/pkg/fixtures/method_args/same_name_arg_and_type/mock_interfaceB0_test.go +++ b/pkg/fixtures/method_args/same_name_arg_and_type/mock_interfaceB0_test.go @@ -21,6 +21,10 @@ func (_m *interfaceB0Mock) EXPECT() *interfaceB0Mock_Expecter { func (_m *interfaceB0Mock) DoB0(interfaceB00 interfaceB0) interfaceB0 { ret := _m.Called(interfaceB00) + if len(ret) == 0 { + panic("Missing Return() function for DoB0") + } + var r0 interfaceB0 if rf, ok := ret.Get(0).(func(interfaceB0) interfaceB0); ok { r0 = rf(interfaceB00) 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 f01014df..9fbb63c8 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 @@ -21,6 +21,10 @@ func (_m *interfaceBMock) EXPECT() *interfaceBMock_Expecter { func (_m *interfaceBMock) GetData() int { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for GetData") + } + var r0 int if rf, ok := ret.Get(0).(func() int); ok { r0 = rf() diff --git a/pkg/fixtures/panic_err.go b/pkg/fixtures/panic_err.go new file mode 100644 index 00000000..ac646619 --- /dev/null +++ b/pkg/fixtures/panic_err.go @@ -0,0 +1,5 @@ +package test + +type PanicOnNoReturnValue interface { + DoSomething() string +} diff --git a/pkg/fixtures/recursive_generation/Foo_mock.go b/pkg/fixtures/recursive_generation/Foo_mock.go index b467ac42..8227b876 100644 --- a/pkg/fixtures/recursive_generation/Foo_mock.go +++ b/pkg/fixtures/recursive_generation/Foo_mock.go @@ -21,6 +21,10 @@ func (_m *MockFoo) EXPECT() *MockFoo_Expecter { func (_m *MockFoo) Get() string { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 string if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() diff --git a/pkg/fixtures/recursive_generation/subpkg1/Foo_mock.go b/pkg/fixtures/recursive_generation/subpkg1/Foo_mock.go index ab666e61..0cc31d1a 100644 --- a/pkg/fixtures/recursive_generation/subpkg1/Foo_mock.go +++ b/pkg/fixtures/recursive_generation/subpkg1/Foo_mock.go @@ -21,6 +21,10 @@ func (_m *MockFoo) EXPECT() *MockFoo_Expecter { func (_m *MockFoo) Get() string { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 string if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() diff --git a/pkg/fixtures/recursive_generation/subpkg2/Foo_mock.go b/pkg/fixtures/recursive_generation/subpkg2/Foo_mock.go index b74c986d..b9b1b4b2 100644 --- a/pkg/fixtures/recursive_generation/subpkg2/Foo_mock.go +++ b/pkg/fixtures/recursive_generation/subpkg2/Foo_mock.go @@ -21,6 +21,10 @@ func (_m *MockFoo) EXPECT() *MockFoo_Expecter { func (_m *MockFoo) Get() string { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 string if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() 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 c7027e16..3b040618 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 @@ -21,6 +21,10 @@ func (_m *MockFoo) EXPECT() *MockFoo_Expecter { func (_m *MockFoo) Get() string { ret := _m.Called() + if len(ret) == 0 { + panic("Missing Return() function for Get") + } + var r0 string if rf, ok := ret.Get(0).(func() string); ok { r0 = rf() diff --git a/pkg/generator.go b/pkg/generator.go index 8f5985a6..8a7702f0 100644 --- a/pkg/generator.go +++ b/pkg/generator.go @@ -752,6 +752,10 @@ func (_m *{{.MockName}}{{.InstantiatedTypeString}}) {{.FunctionName}}({{join .Pa {{- else}} {{- .RetVariableName}} := {{.Called}} + if len({{.RetVariableName}}) == 0 { + panic("Missing Return() function for {{.FunctionName}}") + } + {{range $idx, $name := .Returns.ReturnNames}} var {{$name}} {{index $.Returns.Types $idx -}} {{end}} diff --git a/pkg/generator_test.go b/pkg/generator_test.go index 5ea54b5b..50a0f5ef 100644 --- a/pkg/generator_test.go +++ b/pkg/generator_test.go @@ -517,6 +517,10 @@ func (s *GeneratorSuite) TestGeneratorForEmptyInterface() { s.checkGeneration("empty_interface.go", "Blank", false, "", "") } +func (s *GeneratorSuite) TestGeneratorForPanicOnNoReturnValueInterface() { + s.checkGeneration("panic_err.go", "PanicOnNoReturnValue", false, "", "") +} + func (s *GeneratorSuite) TestGeneratorArgumentIsMapFunc() { s.checkGeneration("map_func.go", "MapFunc", false, "", "") }