From dc47fdbf22460ff1105e6c83032ccdab58831096 Mon Sep 17 00:00:00 2001 From: Alysson Ribeiro <15274059+sonalys@users.noreply.github.com> Date: Tue, 3 Dec 2024 17:36:43 +0100 Subject: [PATCH] Fix(generator): run functions with empty return (#842) * Chore(mocks): update generated mocks * Fix(generator): Run functions with empty return * Fix(empty-return): move tests to correct location * Merge: fix conflicts --------- Co-authored-by: Landon Clipp <11232769+LandonTClipp@users.noreply.github.com> --- .mockery.yaml | 14 ++- go.sum | 23 +++-- go.work.sum | 5 +- .../mockery/v2/pkg/TypesPackage_mock.go | 4 +- .../vektra/mockery/v2/pkg/fixtures/A_mock.go | 2 +- .../v2/pkg/fixtures/AsyncProducer_mock.go | 6 +- .../v2/pkg/fixtures/ConsulLock_mock.go | 2 +- .../v2/pkg/fixtures/EmbeddedGet_mock.go | 2 +- .../mockery/v2/pkg/fixtures/Example_mock.go | 2 +- .../ExpecterAndRolledVariadic_mock.go | 4 +- .../mockery/v2/pkg/fixtures/Expecter_mock.go | 4 +- .../mockery/v2/pkg/fixtures/Fooer_mock.go | 2 +- .../v2/pkg/fixtures/GetGeneric_mock.go | 2 +- .../mockery/v2/pkg/fixtures/GetInt_mock.go | 2 +- .../HasConflictingNestedImports_mock.go | 2 +- .../pkg/fixtures/ImportsSameAsPackage_mock.go | 6 +- .../v2/pkg/fixtures/MapToInterface_mock.go | 2 +- .../pkg/fixtures/PanicOnNoReturnValue_mock.go | 2 +- .../pkg/fixtures/ReplaceGenericSelf_mock.go | 2 +- .../v2/pkg/fixtures/ReplaceGeneric_mock.go | 4 +- .../v2/pkg/fixtures/Requester3_mock.go | 2 +- .../v2/pkg/fixtures/Requester4_mock.go | 4 +- .../fixtures/RequesterArgSameAsPkg_mock.go | 2 +- .../v2/pkg/fixtures/RequesterIface_mock.go | 2 +- .../mockery/v2/pkg/fixtures/Sibling_mock.go | 4 +- .../v2/pkg/fixtures/UnsafeInterface_mock.go | 2 +- .../mockery/v2/pkg/fixtures/UsesAny_mock.go | 2 +- .../v2/pkg/fixtures/UsesOtherPkgIface_mock.go | 2 +- .../VariadicNoReturnInterface_mock.go | 2 +- .../IfaceWithCustomBuildTagInComment_mock.go | 4 +- .../pkg/fixtures/requesterUnexported_mock.go | 4 +- pkg/fixtures/empty_return/interface.go | 6 ++ pkg/fixtures/empty_return/interface_test.go | 38 +++++++ .../empty_return/mock_EmptyReturn_test.go | 98 +++++++++++++++++++ .../example_project/mock_root_test.go | 4 +- .../example_project/mock_stringer_test.go | 2 +- .../mock_getter_iface_typed_param_test.go | 2 +- pkg/fixtures/issue845/mock_WithFix_test.go | 2 +- pkg/fixtures/issue845/mock_WithoutFix_test.go | 2 +- .../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 +- .../mock_InterfaceWithResolvedAlias_test.go | 2 +- .../mock_InterfaceWithUnresolvedAlias_test.go | 2 +- pkg/generator.go | 8 ++ 47 files changed, 228 insertions(+), 70 deletions(-) create mode 100644 pkg/fixtures/empty_return/interface.go create mode 100644 pkg/fixtures/empty_return/interface_test.go create mode 100644 pkg/fixtures/empty_return/mock_EmptyReturn_test.go diff --git a/.mockery.yaml b/.mockery.yaml index 56b729950..c94bb0f3f 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -70,6 +70,15 @@ packages: mockname: "Mock{{.InterfaceName}}" outpkg: "{{.PackageName}}" inpackage: True + github.com/vektra/mockery/v2/pkg/fixtures/empty_return: + config: + all: True + dir: "{{.InterfaceDir}}" + mockname: "{{.InterfaceName}}Mock" + outpkg: "{{.PackageName}}" + filename: "mock_{{.InterfaceName}}_test.go" + inpackage: True + keeptree: False github.com/vektra/mockery/v2/pkg/fixtures/method_args/same_name_arg_and_type: config: all: True @@ -81,10 +90,10 @@ packages: keeptree: False github.com/vektra/mockery/v2/pkg/fixtures/iface_typed_param: config: *inpackage_config - github.com/vektra/mockery/v2/pkg/fixtures/example_project: + github.com/vektra/mockery/v2/pkg/fixtures/example_project: config: *inpackage_config github.com/vektra/mockery/v2/pkg/fixtures/issue845: - config: + config: <<: *inpackage_config filename: "mock_{{.MockName}}_test.go" interfaces: @@ -114,4 +123,3 @@ packages: mockname: Interface2WithUnresolvedAlias - resolve-type-alias: True mockname: Interface2WithResolvedAlias - diff --git a/go.sum b/go.sum index 82fb22427..ffdbb4b5c 100644 --- a/go.sum +++ b/go.sum @@ -104,9 +104,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -258,8 +257,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= -golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= +golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -310,8 +309,8 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -350,8 +349,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -361,8 +360,8 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= -golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -413,8 +412,8 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= +golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= +golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/go.work.sum b/go.work.sum index 65d37e988..aeec43546 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1135,7 +1135,7 @@ golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDA golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 h1:4+4C/Iv2U4fMZBiMCc98MG1In4gJY5YRhtpDNeDeHWs= -golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= @@ -1226,6 +1226,7 @@ golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457 h1:zf5N6UOrA487eEFacMePxjXAJctxKmyjKUsjA11Uzuk= @@ -1255,7 +1256,7 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= -golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= diff --git a/mocks/github.com/vektra/mockery/v2/pkg/TypesPackage_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/TypesPackage_mock.go index dc30f202c..c55fc0b54 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/TypesPackage_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/TypesPackage_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/A_mock.go index afbdf9413..554a332fc 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/A_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/A_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/AsyncProducer_mock.go index bef64eca0..d0021f220 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/AsyncProducer_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/AsyncProducer_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ConsulLock_mock.go index 2dfe5dc62..757154be3 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ConsulLock_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ConsulLock_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/EmbeddedGet_mock.go index a913d1066..94df18a57 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/EmbeddedGet_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/EmbeddedGet_mock.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/Example_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Example_mock.go index 7cfeaae42..72cbf9bc1 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Example_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Example_mock.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/ExpecterAndRolledVariadic_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ExpecterAndRolledVariadic_mock.go index 6fd6ffa0a..469f09ad5 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ExpecterAndRolledVariadic_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ExpecterAndRolledVariadic_mock.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/Expecter_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Expecter_mock.go index 2807c78d3..7d3c9a263 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Expecter_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Expecter_mock.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/Fooer_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Fooer_mock.go index c172417be..4e35c74ca 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Fooer_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Fooer_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetGeneric_mock.go index 1e31cad1e..7c845611a 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetGeneric_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetGeneric_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetInt_mock.go index 0eeb3b4fd..4bf8d3f42 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetInt_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/GetInt_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/HasConflictingNestedImports_mock.go index 7249de4f3..540e229a6 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/HasConflictingNestedImports_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/HasConflictingNestedImports_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ImportsSameAsPackage_mock.go index e8045f246..4886e5166 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ImportsSameAsPackage_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ImportsSameAsPackage_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MapToInterface_mock.go index 7bbb9be32..d68815d93 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MapToInterface_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/MapToInterface_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/PanicOnNoReturnValue_mock.go index eaa5ea6e5..4db1babf2 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/PanicOnNoReturnValue_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/PanicOnNoReturnValue_mock.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/ReplaceGenericSelf_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGenericSelf_mock.go index dbd758a4c..d12758d2f 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGenericSelf_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGenericSelf_mock.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/ReplaceGeneric_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGeneric_mock.go index 7c37f5787..0ac565daf 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGeneric_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGeneric_mock.go @@ -70,7 +70,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() @@ -117,7 +117,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/Requester3_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester3_mock.go index 2c18c9277..22c23daf9 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester3_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester3_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester4_mock.go index da8d2ceda..d77199a08 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester4_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Requester4_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsPkg_mock.go index 40218b9d1..1da35b177 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsPkg_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterArgSameAsPkg_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterIface_mock.go index 78c731130..2186b6cf1 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterIface_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterIface_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Sibling_mock.go index b2baf893f..36bebf84d 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Sibling_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/Sibling_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UnsafeInterface_mock.go index 22116c177..1e46e90b5 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UnsafeInterface_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UnsafeInterface_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UsesAny_mock.go index 050afa35c..b601eac82 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UsesAny_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UsesAny_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UsesOtherPkgIface_mock.go index 44228599c..aa823c8f8 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UsesOtherPkgIface_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/UsesOtherPkgIface_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/VariadicNoReturnInterface_mock.go index 4a751e0ff..ea80e0459 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/VariadicNoReturnInterface_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/VariadicNoReturnInterface_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/buildtag/comment/IfaceWithCustomBuildTagInComment_mock.go index 73bc3023c..148ce91d1 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/buildtag/comment/IfaceWithCustomBuildTagInComment_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/buildtag/comment/IfaceWithCustomBuildTagInComment_mock.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_mock.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/requesterUnexported_mock.go index 381e991d3..a37c2a35c 100644 --- a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/requesterUnexported_mock.go +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/requesterUnexported_mock.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/fixtures/empty_return/interface.go b/pkg/fixtures/empty_return/interface.go new file mode 100644 index 000000000..8ece725a2 --- /dev/null +++ b/pkg/fixtures/empty_return/interface.go @@ -0,0 +1,6 @@ +package test + +type EmptyReturn interface { + NoArgs() + WithArgs(a int, b string) +} diff --git a/pkg/fixtures/empty_return/interface_test.go b/pkg/fixtures/empty_return/interface_test.go new file mode 100644 index 000000000..6039d146b --- /dev/null +++ b/pkg/fixtures/empty_return/interface_test.go @@ -0,0 +1,38 @@ +package test + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func Test(t *testing.T) { + m := NewEmptyReturnMock(t) + var target EmptyReturn = m + + t.Run("NoArgs", func(t *testing.T) { + run := false + + m.EXPECT().NoArgs().RunAndReturn(func() { + run = true + }) + + target.NoArgs() + + require.True(t, run) + }) + + t.Run("WithArgs", func(t *testing.T) { + run := false + + m.EXPECT().WithArgs(42, "foo").RunAndReturn(func(arg0 int, arg1 string) { + run = true + require.Equal(t, 42, arg0) + require.Equal(t, "foo", arg1) + }) + + target.WithArgs(42, "foo") + + require.True(t, run) + }) +} diff --git a/pkg/fixtures/empty_return/mock_EmptyReturn_test.go b/pkg/fixtures/empty_return/mock_EmptyReturn_test.go new file mode 100644 index 000000000..4f086b621 --- /dev/null +++ b/pkg/fixtures/empty_return/mock_EmptyReturn_test.go @@ -0,0 +1,98 @@ +// Code generated by mockery. DO NOT EDIT. + +package test + +import mock "github.com/stretchr/testify/mock" + +// EmptyReturnMock is an autogenerated mock type for the EmptyReturn type +type EmptyReturnMock struct { + mock.Mock +} + +type EmptyReturnMock_Expecter struct { + mock *mock.Mock +} + +func (_m *EmptyReturnMock) EXPECT() *EmptyReturnMock_Expecter { + return &EmptyReturnMock_Expecter{mock: &_m.Mock} +} + +// NoArgs provides a mock function with no fields +func (_m *EmptyReturnMock) NoArgs() { + _m.Called() +} + +// EmptyReturnMock_NoArgs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NoArgs' +type EmptyReturnMock_NoArgs_Call struct { + *mock.Call +} + +// NoArgs is a helper method to define mock.On call +func (_e *EmptyReturnMock_Expecter) NoArgs() *EmptyReturnMock_NoArgs_Call { + return &EmptyReturnMock_NoArgs_Call{Call: _e.mock.On("NoArgs")} +} + +func (_c *EmptyReturnMock_NoArgs_Call) Run(run func()) *EmptyReturnMock_NoArgs_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *EmptyReturnMock_NoArgs_Call) Return() *EmptyReturnMock_NoArgs_Call { + _c.Call.Return() + return _c +} + +func (_c *EmptyReturnMock_NoArgs_Call) RunAndReturn(run func()) *EmptyReturnMock_NoArgs_Call { + _c.Run(run) + return _c +} + +// WithArgs provides a mock function with given fields: a, b +func (_m *EmptyReturnMock) WithArgs(a int, b string) { + _m.Called(a, b) +} + +// EmptyReturnMock_WithArgs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithArgs' +type EmptyReturnMock_WithArgs_Call struct { + *mock.Call +} + +// WithArgs is a helper method to define mock.On call +// - a int +// - b string +func (_e *EmptyReturnMock_Expecter) WithArgs(a interface{}, b interface{}) *EmptyReturnMock_WithArgs_Call { + return &EmptyReturnMock_WithArgs_Call{Call: _e.mock.On("WithArgs", a, b)} +} + +func (_c *EmptyReturnMock_WithArgs_Call) Run(run func(a int, b string)) *EmptyReturnMock_WithArgs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int), args[1].(string)) + }) + return _c +} + +func (_c *EmptyReturnMock_WithArgs_Call) Return() *EmptyReturnMock_WithArgs_Call { + _c.Call.Return() + return _c +} + +func (_c *EmptyReturnMock_WithArgs_Call) RunAndReturn(run func(int, string)) *EmptyReturnMock_WithArgs_Call { + _c.Run(run) + return _c +} + +// NewEmptyReturnMock creates a new instance of EmptyReturnMock. 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 NewEmptyReturnMock(t interface { + mock.TestingT + Cleanup(func()) +}) *EmptyReturnMock { + mock := &EmptyReturnMock{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/fixtures/example_project/mock_root_test.go b/pkg/fixtures/example_project/mock_root_test.go index 7ab383281..86e93f91d 100644 --- a/pkg/fixtures/example_project/mock_root_test.go +++ b/pkg/fixtures/example_project/mock_root_test.go @@ -20,7 +20,7 @@ func (_m *MockRoot) EXPECT() *MockRoot_Expecter { return &MockRoot_Expecter{mock: &_m.Mock} } -// ReturnsFoo provides a mock function with given fields: +// ReturnsFoo provides a mock function with no fields func (_m *MockRoot) ReturnsFoo() (foo.Foo, error) { ret := _m.Called() @@ -106,7 +106,7 @@ func (_c *MockRoot_TakesBaz_Call) Return() *MockRoot_TakesBaz_Call { } func (_c *MockRoot_TakesBaz_Call) RunAndReturn(run func(*foo.Baz)) *MockRoot_TakesBaz_Call { - _c.Call.Return(run) + _c.Run(run) return _c } diff --git a/pkg/fixtures/example_project/mock_stringer_test.go b/pkg/fixtures/example_project/mock_stringer_test.go index ceeaa277e..17bdc5797 100644 --- a/pkg/fixtures/example_project/mock_stringer_test.go +++ b/pkg/fixtures/example_project/mock_stringer_test.go @@ -17,7 +17,7 @@ func (_m *MockStringer) EXPECT() *MockStringer_Expecter { return &MockStringer_Expecter{mock: &_m.Mock} } -// String provides a mock function with given fields: +// String provides a mock function with no fields func (_m *MockStringer) String() string { ret := _m.Called() diff --git a/pkg/fixtures/iface_typed_param/mock_getter_iface_typed_param_test.go b/pkg/fixtures/iface_typed_param/mock_getter_iface_typed_param_test.go index 7731d5fd8..41a73a02b 100644 --- a/pkg/fixtures/iface_typed_param/mock_getter_iface_typed_param_test.go +++ b/pkg/fixtures/iface_typed_param/mock_getter_iface_typed_param_test.go @@ -21,7 +21,7 @@ func (_m *MockGetterIfaceTypedParam[T]) EXPECT() *MockGetterIfaceTypedParam_Expe return &MockGetterIfaceTypedParam_Expecter[T]{mock: &_m.Mock} } -// Get provides a mock function with given fields: +// Get provides a mock function with no fields func (_m *MockGetterIfaceTypedParam[T]) Get() T { ret := _m.Called() diff --git a/pkg/fixtures/issue845/mock_WithFix_test.go b/pkg/fixtures/issue845/mock_WithFix_test.go index 94c06ac77..7fb7068e9 100644 --- a/pkg/fixtures/issue845/mock_WithFix_test.go +++ b/pkg/fixtures/issue845/mock_WithFix_test.go @@ -17,7 +17,7 @@ func (_m *WithFix) EXPECT() *WithFix_Expecter { return &WithFix_Expecter{mock: &_m.Mock} } -// Foo provides a mock function with given fields: +// Foo provides a mock function with no fields func (_m *WithFix) Foo() string { ret := _m.Called() diff --git a/pkg/fixtures/issue845/mock_WithoutFix_test.go b/pkg/fixtures/issue845/mock_WithoutFix_test.go index 0cbfaf5d1..29f10dc5d 100644 --- a/pkg/fixtures/issue845/mock_WithoutFix_test.go +++ b/pkg/fixtures/issue845/mock_WithoutFix_test.go @@ -17,7 +17,7 @@ func (_m *WithoutFix) EXPECT() *WithoutFix_Expecter { return &WithoutFix_Expecter{mock: &_m.Mock} } -// Foo provides a mock function with given fields: +// Foo provides a mock function with no fields func (_m *WithoutFix) Foo() string { ret := _m.Called() 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 f0538bd7a..cbeff2df8 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 1374b9faa..fbb8fd00e 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 50697c1da..a4ae0651c 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 fe92d1188..eef312d80 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 9648bcfdf..b852f2c42 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/fixtures/type_alias/mock_InterfaceWithResolvedAlias_test.go b/pkg/fixtures/type_alias/mock_InterfaceWithResolvedAlias_test.go index a0594b93f..b0e66f349 100644 --- a/pkg/fixtures/type_alias/mock_InterfaceWithResolvedAlias_test.go +++ b/pkg/fixtures/type_alias/mock_InterfaceWithResolvedAlias_test.go @@ -17,7 +17,7 @@ func (_m *InterfaceWithResolvedAlias) EXPECT() *InterfaceWithResolvedAlias_Expec return &InterfaceWithResolvedAlias_Expecter{mock: &_m.Mock} } -// Foo provides a mock function with given fields: +// Foo provides a mock function with no fields func (_m *InterfaceWithResolvedAlias) Foo() int { ret := _m.Called() diff --git a/pkg/fixtures/type_alias/mock_InterfaceWithUnresolvedAlias_test.go b/pkg/fixtures/type_alias/mock_InterfaceWithUnresolvedAlias_test.go index 677b2dbe3..4671d850e 100644 --- a/pkg/fixtures/type_alias/mock_InterfaceWithUnresolvedAlias_test.go +++ b/pkg/fixtures/type_alias/mock_InterfaceWithUnresolvedAlias_test.go @@ -20,7 +20,7 @@ func (_m *InterfaceWithUnresolvedAlias) EXPECT() *InterfaceWithUnresolvedAlias_E return &InterfaceWithUnresolvedAlias_Expecter{mock: &_m.Mock} } -// Foo provides a mock function with given fields: +// Foo provides a mock function with no fields func (_m *InterfaceWithUnresolvedAlias) Foo() type_alias.Type { ret := _m.Called() diff --git a/pkg/generator.go b/pkg/generator.go index 705879663..bcda68cb5 100644 --- a/pkg/generator.go +++ b/pkg/generator.go @@ -855,7 +855,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}} @@ -1009,7 +1013,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 } `)