diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b5e2c25b..fd363ee2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,27 +1,32 @@ name: Run tests on: push: - branches: [main] + branches: ['*'] pull_request: - branches: [main] + branches: ['*'] + +permissions: + contents: read + env: GO111MODULE: on + jobs: test: strategy: matrix: - go-version: [1.15.x, 1.18.x] + go-version: [1.19.x, 1.20.x] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Vet and build run: | @@ -30,23 +35,17 @@ jobs: - name: Install mockgen run: | - go install github.com/golang/mock/mockgen + go install go.uber.org/mock/mockgen - name: Run test script run: | ./ci/test.sh ./ci/check_panic_handling.sh - - name: Run Go tests all - if: ${{ startsWith(matrix.go-version, '1.18') }} + - name: Run Tests run: | for i in $(find $PWD -name go.mod); do pushd $(dirname $i) go test ./... popd done - - - name: Run Go tests some - if: ${{ startsWith(matrix.go-version, '1.18') == false }} - run: | - go test ./... diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..0e3b6731 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,26 @@ +# Changelog +All notable changes to this project will be documented in this file. + +This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +## Unreleased +- No changes yet. + +## 0.2.0 (06 Jul 2023) +### Added +- `Controller.Satisfied` that lets you check whether all expected calls + bound to a Controller have been satisfied. +- `NewController` now takes optional `ControllerOption` parameter. +- `WithOverridableExpectations` is a `ControllerOption` that configures + Controller to override existing expectations upon a new EXPECT(). +- `-typed` flag for generating type-safe methods in the generated mock. + +## 0.1.0 (29 Jun 2023) + +This is a minor version that mirrors the original golang/mock +project that this project originates from. + +Any users on golang/mock project should be able to migrate to +this project as-is, and expect exact same set of features (apart +from supported Go versions. See [README](README.md#supported-go-versions) +for more details. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c12995e2..fe7357b0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,7 @@ First off, thank you for taking an interest to contribute to this project! ## Opening issues -When opening a [new issue](https://github.com/golang/mock/issues/new/choose) +When opening a [new issue](https://github.com/uber/mock/issues/new/choose) please: 1. Make sure there are not other open/closed issues asking/reporting/requesting diff --git a/MAINTAINERS b/MAINTAINERS new file mode 100644 index 00000000..a6d9819d --- /dev/null +++ b/MAINTAINERS @@ -0,0 +1,5 @@ +# This is the current list of maintainers to Uber's fork of gomock repository. + +Sung Yoon Whang +Ryan Hang +Zhongpeng Lin diff --git a/README.md b/README.md index a4213e50..6db882a0 100644 --- a/README.md +++ b/README.md @@ -6,30 +6,25 @@ gomock is a mocking framework for the [Go programming language][golang]. It integrates well with Go's built-in `testing` package, but can be used in other contexts too. -## Installation - -Once you have [installed Go][golang-install], install the `mockgen` tool. +This project originates from Google's `golang/mock` repo. Unfortunately Google +no longer maintains this project, and given the heavy usage of gomock project +within Uber, we've decided to fork and maintain this going forward at Uber. -**Note**: If you have not done so already be sure to add `$GOPATH/bin` to your -`PATH`. +Contributions are welcome in the form of GitHub issue or PR! -To get the latest released version use: +## Supported Go Versions -### Go version < 1.16 +go.uber.org/mock supports all Go versions supported by the official +[Go Release Policy](https://go.dev/doc/devel/release#policy). That is, +the two most recent releases of Go. -```bash -GO111MODULE=on go get github.com/golang/mock/mockgen@v1.6.0 -``` +## Installation -### Go 1.16+ +Install the `mockgen` tool. -```bash -go install github.com/golang/mock/mockgen@v1.6.0 ``` - -If you use `mockgen` in your CI pipeline, it may be more appropriate to fixate -on a specific mockgen version. You should try to keep the library in sync with -the version of mockgen used to generate your mocks. +go install go.uber.org/mock/mockgen@latest +``` ## Running mockgen @@ -118,6 +113,10 @@ It supports the following flags: - `-write_package_comment`: Writes package documentation comment (godoc) if true. (default true) +- `-write_source_comment`: Writes original file (source mode) or interface names (reflect mode) comment if true. (default true) + +- `-typed`: Generate Type-safe 'Return', 'Do', 'DoAndReturn' function. (default false) + For an example of the use of `mockgen`, see the `sample/` directory. In simple cases, you will need only the `-source` flag. @@ -250,28 +249,7 @@ If the received value is `3`, then it will be printed as `03`. [golang]: http://golang.org/ [golang-install]: http://golang.org/doc/install.html#releases -[gomock-reference]: https://pkg.go.dev/github.com/golang/mock/gomock -[ci-badge]: https://github.com/golang/mock/actions/workflows/test.yaml/badge.svg -[ci-runs]: https://github.com/golang/mock/actions -[reference-badge]: https://pkg.go.dev/badge/github.com/golang/mock.svg -[reference]: https://pkg.go.dev/github.com/golang/mock - -## Debugging Errors - -### reflect vendoring error - -```text -cannot find package "." -... github.com/golang/mock/mockgen/model -``` - -If you come across this error while using reflect mode and vendoring -dependencies there are three workarounds you can choose from: - -1. Use source mode. -2. Include an empty import `import _ "github.com/golang/mock/mockgen/model"`. -3. Add `--build_flags=--mod=mod` to your mockgen command. - -This error is due to changes in default behavior of the `go` command in more -recent versions. More details can be found in -[#494](https://github.com/golang/mock/issues/494). +[ci-badge]: https://github.com/uber/mock/actions/workflows/test.yaml/badge.svg +[ci-runs]: https://github.com/uber/mock/actions +[reference-badge]: https://pkg.go.dev/badge/go.uber.org/mock.svg +[reference]: https://pkg.go.dev/go.uber.org/mock diff --git a/go.mod b/go.mod index d920e36f..03fa5906 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,13 @@ -module github.com/golang/mock +module go.uber.org/mock + +go 1.19 require ( - golang.org/x/mod v0.5.1 - golang.org/x/tools v0.1.8 + golang.org/x/mod v0.11.0 + golang.org/x/tools v0.2.0 ) -go 1.15 +require ( + github.com/yuin/goldmark v1.4.13 // indirect + golang.org/x/sys v0.1.0 // indirect +) diff --git a/go.sum b/go.sum index 5ae13f0c..38c76462 100644 --- a/go.sum +++ b/go.sum @@ -1,29 +1,8 @@ -github.com/yuin/goldmark v1.4.1 h1:/vn0k+RBvwlxEmP5E7SZMqNxPhfMVFEJiykr15/0XKM= -github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38= -golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.8 h1:P1HhGGuLW4aAclzjtmJdf0mJOjVUZUzOTqkAkWL+l6w= -golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= -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-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= +golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE= +golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= diff --git a/gomock/callset.go b/gomock/callset.go index 49dba787..f2131a14 100644 --- a/gomock/callset.go +++ b/gomock/callset.go @@ -18,15 +18,19 @@ import ( "bytes" "errors" "fmt" + "sync" ) // callSet represents a set of expected calls, indexed by receiver and method // name. type callSet struct { // Calls that are still expected. - expected map[callSetKey][]*Call + expected map[callSetKey][]*Call + expectedMu *sync.Mutex // Calls that have been exhausted. exhausted map[callSetKey][]*Call + // when set to true, existing call expectations are overridden when new call expectations are made + allowOverride bool } // callSetKey is the key in the maps in callSet @@ -36,22 +40,47 @@ type callSetKey struct { } func newCallSet() *callSet { - return &callSet{make(map[callSetKey][]*Call), make(map[callSetKey][]*Call)} + return &callSet{ + expected: make(map[callSetKey][]*Call), + expectedMu: &sync.Mutex{}, + exhausted: make(map[callSetKey][]*Call), + } +} + +func newOverridableCallSet() *callSet { + return &callSet{ + expected: make(map[callSetKey][]*Call), + expectedMu: &sync.Mutex{}, + exhausted: make(map[callSetKey][]*Call), + allowOverride: true, + } } // Add adds a new expected call. func (cs callSet) Add(call *Call) { key := callSetKey{call.receiver, call.method} + + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + m := cs.expected if call.exhausted() { m = cs.exhausted } + if cs.allowOverride { + m[key] = make([]*Call, 0) + } + m[key] = append(m[key], call) } // Remove removes an expected call. func (cs callSet) Remove(call *Call) { key := callSetKey{call.receiver, call.method} + + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + calls := cs.expected[key] for i, c := range calls { if c == call { @@ -67,6 +96,9 @@ func (cs callSet) Remove(call *Call) { func (cs callSet) FindMatch(receiver interface{}, method string, args []interface{}) (*Call, error) { key := callSetKey{receiver, method} + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + // Search through the expected calls. expected := cs.expected[key] var callsErrors bytes.Buffer @@ -101,6 +133,9 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac // Failures returns the calls that are not satisfied. func (cs callSet) Failures() []*Call { + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + failures := make([]*Call, 0, len(cs.expected)) for _, calls := range cs.expected { for _, call := range calls { @@ -111,3 +146,19 @@ func (cs callSet) Failures() []*Call { } return failures } + +// Satisfied returns true in case all expected calls in this callSet are satisfied. +func (cs callSet) Satisfied() bool { + cs.expectedMu.Lock() + defer cs.expectedMu.Unlock() + + for _, calls := range cs.expected { + for _, call := range calls { + if !call.satisfied() { + return false + } + } + } + + return true +} diff --git a/gomock/callset_test.go b/gomock/callset_test.go index fe053af7..74e2ce4e 100644 --- a/gomock/callset_test.go +++ b/gomock/callset_test.go @@ -42,6 +42,24 @@ func TestCallSetAdd(t *testing.T) { } } +func TestCallSetAdd_WhenOverridable_ClearsPreviousExpectedAndExhausted(t *testing.T) { + method := "TestMethod" + var receiver interface{} = "TestReceiver" + cs := newOverridableCallSet() + + cs.Add(newCall(t, receiver, method, reflect.TypeOf(receiverType{}.Func))) + numExpectedCalls := len(cs.expected[callSetKey{receiver, method}]) + if numExpectedCalls != 1 { + t.Fatalf("Expected 1 expected call in callset, got %d", numExpectedCalls) + } + + cs.Add(newCall(t, receiver, method, reflect.TypeOf(receiverType{}.Func))) + newNumExpectedCalls := len(cs.expected[callSetKey{receiver, method}]) + if newNumExpectedCalls != 1 { + t.Fatalf("Expected 1 expected call in callset, got %d", newNumExpectedCalls) + } +} + func TestCallSetRemove(t *testing.T) { method := "TestMethod" var receiver interface{} = "TestReceiver" @@ -77,7 +95,7 @@ func TestCallSetRemove(t *testing.T) { func TestCallSetFindMatch(t *testing.T) { t.Run("call is exhausted", func(t *testing.T) { - cs := callSet{} + cs := newCallSet() var receiver interface{} = "TestReceiver" method := "TestMethod" args := []interface{}{} diff --git a/gomock/controller.go b/gomock/controller.go index 5e2def13..de904c8c 100644 --- a/gomock/controller.go +++ b/gomock/controller.go @@ -51,24 +51,24 @@ type cleanuper interface { // goroutines. Each test should create a new Controller and invoke Finish via // defer. // -// func TestFoo(t *testing.T) { -// ctrl := gomock.NewController(t) -// defer ctrl.Finish() -// // .. -// } +// func TestFoo(t *testing.T) { +// ctrl := gomock.NewController(t) +// defer ctrl.Finish() +// // .. +// } // -// func TestBar(t *testing.T) { -// t.Run("Sub-Test-1", st) { -// ctrl := gomock.NewController(st) -// defer ctrl.Finish() -// // .. -// }) -// t.Run("Sub-Test-2", st) { -// ctrl := gomock.NewController(st) -// defer ctrl.Finish() -// // .. -// }) -// }) +// func TestBar(t *testing.T) { +// t.Run("Sub-Test-1", st) { +// ctrl := gomock.NewController(st) +// defer ctrl.Finish() +// // .. +// }) +// t.Run("Sub-Test-2", st) { +// ctrl := gomock.NewController(st) +// defer ctrl.Finish() +// // .. +// }) +// }) type Controller struct { // T should only be called within a generated mock. It is not intended to // be used in user code and may be changed in future versions. T is the @@ -86,7 +86,7 @@ type Controller struct { // // New in go1.14+, if you are passing a *testing.T into this function you no // longer need to call ctrl.Finish() in your test methods. -func NewController(t TestReporter) *Controller { +func NewController(t TestReporter, opts ...ControllerOption) *Controller { h, ok := t.(TestHelper) if !ok { h = &nopTestHelper{t} @@ -95,6 +95,9 @@ func NewController(t TestReporter) *Controller { T: h, expectedCalls: newCallSet(), } + for _, opt := range opts { + opt.apply(ctrl) + } if c, ok := isCleanuper(ctrl.T); ok { c.Cleanup(func() { ctrl.T.Helper() @@ -105,6 +108,23 @@ func NewController(t TestReporter) *Controller { return ctrl } +// ControllerOption configures how a Controller should behave. +type ControllerOption interface { + apply(*Controller) +} + +type overridableExpectationsOption struct{} + +// WithOverridableExpectations allows for overridable call expectations +// i.e., subsequent call expectations override existing call expectations +func WithOverridableExpectations() overridableExpectationsOption { + return overridableExpectationsOption{} +} + +func (o overridableExpectationsOption) apply(ctrl *Controller) { + ctrl.expectedCalls = newOverridableCallSet() +} + type cancelReporter struct { t TestHelper cancel func() @@ -231,6 +251,12 @@ func (ctrl *Controller) Finish() { ctrl.finish(false, err) } +// Satisfied returns whether all expected calls bound to this Controller have been satisfied. +// Calling Finish is then guaranteed to not fail due to missing calls. +func (ctrl *Controller) Satisfied() bool { + return ctrl.expectedCalls.Satisfied() +} + func (ctrl *Controller) finish(cleanup bool, panicErr interface{}) { ctrl.T.Helper() diff --git a/gomock/controller_test.go b/gomock/controller_test.go index 921a51f8..69477238 100644 --- a/gomock/controller_test.go +++ b/gomock/controller_test.go @@ -21,7 +21,7 @@ import ( "strings" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) type ErrorReporter struct { diff --git a/gomock/doc.go b/gomock/doc.go index 1706b504..f1a304fb 100644 --- a/gomock/doc.go +++ b/gomock/doc.go @@ -15,18 +15,19 @@ // Package gomock is a mock framework for Go. // // Standard usage: -// (1) Define an interface that you wish to mock. -// type MyInterface interface { -// SomeMethod(x int64, y string) -// } -// (2) Use mockgen to generate a mock from the interface. -// (3) Use the mock in a test: -// func TestMyThing(t *testing.T) { -// mockCtrl := gomock.NewController(t)// -// mockObj := something.NewMockMyInterface(mockCtrl) -// mockObj.EXPECT().SomeMethod(4, "blah") -// // pass mockObj to a real object and play with it. -// } +// +// (1) Define an interface that you wish to mock. +// type MyInterface interface { +// SomeMethod(x int64, y string) +// } +// (2) Use mockgen to generate a mock from the interface. +// (3) Use the mock in a test: +// func TestMyThing(t *testing.T) { +// mockCtrl := gomock.NewController(t)// +// mockObj := something.NewMockMyInterface(mockCtrl) +// mockObj.EXPECT().SomeMethod(4, "blah") +// // pass mockObj to a real object and play with it. +// } // // By default, expected calls are not enforced to run in any particular order. // Call order dependency can be enforced by use of InOrder and/or Call.After. @@ -37,17 +38,17 @@ // // Example of using Call.After to chain expected call order: // -// firstCall := mockObj.EXPECT().SomeMethod(1, "first") -// secondCall := mockObj.EXPECT().SomeMethod(2, "second").After(firstCall) -// mockObj.EXPECT().SomeMethod(3, "third").After(secondCall) +// firstCall := mockObj.EXPECT().SomeMethod(1, "first") +// secondCall := mockObj.EXPECT().SomeMethod(2, "second").After(firstCall) +// mockObj.EXPECT().SomeMethod(3, "third").After(secondCall) // // Example of using InOrder to declare expected call order: // -// gomock.InOrder( -// mockObj.EXPECT().SomeMethod(1, "first"), -// mockObj.EXPECT().SomeMethod(2, "second"), -// mockObj.EXPECT().SomeMethod(3, "third"), -// ) +// gomock.InOrder( +// mockObj.EXPECT().SomeMethod(1, "first"), +// mockObj.EXPECT().SomeMethod(2, "second"), +// mockObj.EXPECT().SomeMethod(3, "third"), +// ) // // The standard TestReporter most users will pass to `NewController` is a // `*testing.T` from the context of the test. Note that this will use the diff --git a/gomock/example_test.go b/gomock/example_test.go index 0d938847..25b20a2e 100644 --- a/gomock/example_test.go +++ b/gomock/example_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) type Foo interface { @@ -48,3 +48,21 @@ func ExampleCall_DoAndReturn_captureArguments() { fmt.Printf("%s %s", r, s) // Output: I'm sleepy foo } + +func ExampleCall_DoAndReturn_withOverridableExpectations() { + t := &testing.T{} // provided by test + ctrl := gomock.NewController(t, gomock.WithOverridableExpectations()) + mockIndex := NewMockFoo(ctrl) + var s string + + mockIndex.EXPECT().Bar(gomock.AssignableToTypeOf(s)).DoAndReturn( + func(arg string) interface{} { + s = arg + return "I'm sleepy" + }, + ) + + r := mockIndex.Bar("foo") + fmt.Printf("%s %s", r, s) + // Output: I'm sleepy foo +} diff --git a/gomock/internal/mock_gomock/mock_matcher.go b/gomock/internal/mock_gomock/mock_matcher.go index f4a6d526..57e25a0f 100644 --- a/gomock/internal/mock_gomock/mock_matcher.go +++ b/gomock/internal/mock_gomock/mock_matcher.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/golang/mock/gomock (interfaces: Matcher) - +// Source: go.uber.org/mock/gomock (interfaces: Matcher) +// +// Generated by this command: +// +// mockgen -destination internal/mock_gomock/mock_matcher.go go.uber.org/mock/gomock Matcher +// // Package mock_gomock is a generated GoMock package. package mock_gomock import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockMatcher is a mock of Matcher interface. diff --git a/gomock/matchers.go b/gomock/matchers.go index 2822fb2c..6d5eff4f 100644 --- a/gomock/matchers.go +++ b/gomock/matchers.go @@ -283,8 +283,9 @@ func Any() Matcher { return anyMatcher{} } // Eq returns a matcher that matches on equality. // // Example usage: -// Eq(5).Matches(5) // returns true -// Eq(5).Matches(4) // returns false +// +// Eq(5).Matches(5) // returns true +// Eq(5).Matches(4) // returns false func Eq(x interface{}) Matcher { return eqMatcher{x} } // Len returns a matcher that matches on length. This matcher returns false if @@ -296,17 +297,19 @@ func Len(i int) Matcher { // Nil returns a matcher that matches if the received value is nil. // // Example usage: -// var x *bytes.Buffer -// Nil().Matches(x) // returns true -// x = &bytes.Buffer{} -// Nil().Matches(x) // returns false +// +// var x *bytes.Buffer +// Nil().Matches(x) // returns true +// x = &bytes.Buffer{} +// Nil().Matches(x) // returns false func Nil() Matcher { return nilMatcher{} } // Not reverses the results of its given child matcher. // // Example usage: -// Not(Eq(5)).Matches(4) // returns true -// Not(Eq(5)).Matches(5) // returns false +// +// Not(Eq(5)).Matches(4) // returns true +// Not(Eq(5)).Matches(5) // returns false func Not(x interface{}) Matcher { if m, ok := x.(Matcher); ok { return notMatcher{m} @@ -318,12 +321,13 @@ func Not(x interface{}) Matcher { // function is assignable to the type of the parameter to this function. // // Example usage: -// var s fmt.Stringer = &bytes.Buffer{} -// AssignableToTypeOf(s).Matches(time.Second) // returns true -// AssignableToTypeOf(s).Matches(99) // returns false // -// var ctx = reflect.TypeOf((*context.Context)(nil)).Elem() -// AssignableToTypeOf(ctx).Matches(context.Background()) // returns true +// var s fmt.Stringer = &bytes.Buffer{} +// AssignableToTypeOf(s).Matches(time.Second) // returns true +// AssignableToTypeOf(s).Matches(99) // returns false +// +// var ctx = reflect.TypeOf((*context.Context)(nil)).Elem() +// AssignableToTypeOf(ctx).Matches(context.Background()) // returns true func AssignableToTypeOf(x interface{}) Matcher { if xt, ok := x.(reflect.Type); ok { return assignableToTypeOfMatcher{xt} @@ -334,8 +338,9 @@ func AssignableToTypeOf(x interface{}) Matcher { // InAnyOrder is a Matcher that returns true for collections of the same elements ignoring the order. // // Example usage: -// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 3, 2}) // returns true -// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 2}) // returns false +// +// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 3, 2}) // returns true +// InAnyOrder([]int{1, 2, 3}).Matches([]int{1, 2}) // returns false func InAnyOrder(x interface{}) Matcher { return inAnyOrderMatcher{x} } diff --git a/gomock/matchers_test.go b/gomock/matchers_test.go index 61bc1993..5868c407 100644 --- a/gomock/matchers_test.go +++ b/gomock/matchers_test.go @@ -14,7 +14,7 @@ package gomock_test -//go:generate mockgen -destination internal/mock_gomock/mock_matcher.go github.com/golang/mock/gomock Matcher +//go:generate mockgen -destination internal/mock_gomock/mock_matcher.go go.uber.org/mock/gomock Matcher import ( "context" @@ -22,8 +22,8 @@ import ( "reflect" "testing" - "github.com/golang/mock/gomock" - "github.com/golang/mock/gomock/internal/mock_gomock" + "go.uber.org/mock/gomock" + "go.uber.org/mock/gomock/internal/mock_gomock" ) type A []string diff --git a/gomock/mock_test.go b/gomock/mock_test.go index 4f1cfa91..2206c607 100644 --- a/gomock/mock_test.go +++ b/gomock/mock_test.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. // Source: example_test.go - +// +// Generated by this command: +// +// mockgen -destination mock_test.go -package gomock_test -source example_test.go +// // Package gomock_test is a generated GoMock package. package gomock_test import ( reflect "reflect" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) // MockFoo is a mock of Foo interface. diff --git a/gomock/overridable_controller_test.go b/gomock/overridable_controller_test.go new file mode 100644 index 00000000..3d75e6af --- /dev/null +++ b/gomock/overridable_controller_test.go @@ -0,0 +1,34 @@ +package gomock_test + +import ( + "testing" + + "go.uber.org/mock/gomock" +) + +func TestEcho_NoOverride(t *testing.T) { + ctrl := gomock.NewController(t, gomock.WithOverridableExpectations()) + mockIndex := NewMockFoo(ctrl) + + mockIndex.EXPECT().Bar(gomock.Any()).Return("foo") + res := mockIndex.Bar("input") + + if res != "foo" { + t.Fatalf("expected response to equal 'foo', got %s", res) + } +} + +func TestEcho_WithOverride_BaseCase(t *testing.T) { + ctrl := gomock.NewController(t, gomock.WithOverridableExpectations()) + mockIndex := NewMockFoo(ctrl) + + // initial expectation set + mockIndex.EXPECT().Bar(gomock.Any()).Return("foo") + // override + mockIndex.EXPECT().Bar(gomock.Any()).Return("bar") + res := mockIndex.Bar("input") + + if res != "bar" { + t.Fatalf("expected response to equal 'bar', got %s", res) + } +} diff --git a/mockgen/generic_go118.go b/mockgen/generic_go118.go index b29db9a8..3b8ba6bb 100644 --- a/mockgen/generic_go118.go +++ b/mockgen/generic_go118.go @@ -11,10 +11,11 @@ package main import ( + "fmt" "go/ast" "strings" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" ) func getTypeSpecTypeParams(ts *ast.TypeSpec) []*ast.Field { @@ -24,7 +25,7 @@ func getTypeSpecTypeParams(ts *ast.TypeSpec) []*ast.Field { return ts.TypeParams.List } -func (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]bool) (model.Type, error) { +func (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]model.Type) (model.Type, error) { switch v := typ.(type) { case *ast.IndexExpr: m, err := p.parseType(pkg, v.X, tps) @@ -86,3 +87,30 @@ func getIdentTypeParams(decl interface{}) string { sb.WriteString("]") return sb.String() } + +func (p *fileParser) parseGenericMethod(field *ast.Field, it *namedInterface, iface *model.Interface, pkg string, tps map[string]model.Type) ([]*model.Method, error) { + var indices []ast.Expr + var typ ast.Expr + switch v := field.Type.(type) { + case *ast.IndexExpr: + indices = []ast.Expr{v.Index} + typ = v.X + case *ast.IndexListExpr: + indices = v.Indices + typ = v.X + default: + return nil, fmt.Errorf("don't know how to mock method of type %T", field.Type) + } + + nf := &ast.Field{ + Doc: field.Comment, + Names: field.Names, + Type: typ, + Tag: field.Tag, + Comment: field.Comment, + } + + it.embeddedInstTypeParams = indices + + return p.parseMethod(nf, it, iface, pkg, tps) +} diff --git a/mockgen/generic_notgo118.go b/mockgen/generic_notgo118.go index 8fe48c17..b991b641 100644 --- a/mockgen/generic_notgo118.go +++ b/mockgen/generic_notgo118.go @@ -18,19 +18,24 @@ package main import ( + "fmt" "go/ast" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" ) func getTypeSpecTypeParams(ts *ast.TypeSpec) []*ast.Field { return nil } -func (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]bool) (model.Type, error) { +func (p *fileParser) parseGenericType(pkg string, typ ast.Expr, tps map[string]model.Type) (model.Type, error) { return nil, nil } func getIdentTypeParams(decl interface{}) string { return "" } + +func (p *fileParser) parseGenericMethod(field *ast.Field, it *namedInterface, iface *model.Interface, pkg string, tps map[string]model.Type) ([]*model.Method, error) { + return nil, fmt.Errorf("don't know how to mock method of type %T", field.Type) +} diff --git a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport.go b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport.go index 288ab5d9..f49532df 100644 --- a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport.go +++ b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport.go @@ -5,7 +5,7 @@ package bugreport import ( "log" - "github.com/golang/mock/mockgen/internal/tests/aux_imports_embedded_interface/faux" + "go.uber.org/mock/mockgen/internal/tests/aux_imports_embedded_interface/faux" ) // Source is an interface w/ an embedded foreign interface diff --git a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go index 26a80d65..f53bc2bb 100644 --- a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go +++ b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go @@ -1,14 +1,18 @@ // Code generated by MockGen. DO NOT EDIT. // Source: bugreport.go - +// +// Generated by this command: +// +// mockgen -aux_files faux=faux/faux.go -destination bugreport_mock.go -package bugreport -source=bugreport.go Example +// // Package bugreport is a generated GoMock package. package bugreport import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - faux "github.com/golang/mock/mockgen/internal/tests/aux_imports_embedded_interface/faux" + gomock "go.uber.org/mock/gomock" + faux "go.uber.org/mock/mockgen/internal/tests/aux_imports_embedded_interface/faux" ) // MockSource is a mock of Source interface. diff --git a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_test.go b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_test.go index acfca322..cef03ed0 100644 --- a/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_test.go +++ b/mockgen/internal/tests/aux_imports_embedded_interface/bugreport_test.go @@ -3,7 +3,7 @@ package bugreport import ( "testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) // TestValidInterface assesses whether or not the generated mock is valid diff --git a/mockgen/internal/tests/const_array_length/mock.go b/mockgen/internal/tests/const_array_length/mock.go index 2591361c..782c1a54 100644 --- a/mockgen/internal/tests/const_array_length/mock.go +++ b/mockgen/internal/tests/const_array_length/mock.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. // Source: input.go - +// +// Generated by this command: +// +// mockgen -package const_length -destination mock.go -source input.go +// // Package const_length is a generated GoMock package. package const_length import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockI is a mock of I interface. diff --git a/mockgen/internal/tests/copyright_file/mock.go b/mockgen/internal/tests/copyright_file/mock.go index 3cfabcfa..ff041422 100644 --- a/mockgen/internal/tests/copyright_file/mock.go +++ b/mockgen/internal/tests/copyright_file/mock.go @@ -7,12 +7,16 @@ // Code generated by MockGen. DO NOT EDIT. // Source: input.go - +// +// Generated by this command: +// +// mockgen -package empty_interface -destination mock.go -source input.go -copyright_file=mock_copyright_header +// // Package empty_interface is a generated GoMock package. package empty_interface import ( - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockEmpty is a mock of Empty interface. diff --git a/mockgen/internal/tests/custom_package_name/greeter/greeter.go b/mockgen/internal/tests/custom_package_name/greeter/greeter.go index fd2eee0b..7bb4d99b 100644 --- a/mockgen/internal/tests/custom_package_name/greeter/greeter.go +++ b/mockgen/internal/tests/custom_package_name/greeter/greeter.go @@ -7,10 +7,10 @@ import ( "fmt" // non-matching import suffix and package name - "github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1" + "go.uber.org/mock/mockgen/internal/tests/custom_package_name/client/v1" // matching import suffix and package name - "github.com/golang/mock/mockgen/internal/tests/custom_package_name/validator" + "go.uber.org/mock/mockgen/internal/tests/custom_package_name/validator" ) type InputMaker interface { diff --git a/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go b/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go index c0fe30c2..50362c97 100644 --- a/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go +++ b/mockgen/internal/tests/custom_package_name/greeter/greeter_mock_test.go @@ -1,14 +1,18 @@ // Code generated by MockGen. DO NOT EDIT. // Source: greeter.go - +// +// Generated by this command: +// +// mockgen -source greeter.go -destination greeter_mock_test.go -package greeter +// // Package greeter is a generated GoMock package. package greeter import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - client "github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1" + gomock "go.uber.org/mock/gomock" + client "go.uber.org/mock/mockgen/internal/tests/custom_package_name/client/v1" ) // MockInputMaker is a mock of InputMaker interface. diff --git a/mockgen/internal/tests/custom_package_name/greeter/greeter_test.go b/mockgen/internal/tests/custom_package_name/greeter/greeter_test.go index a64d677c..b34d05fb 100644 --- a/mockgen/internal/tests/custom_package_name/greeter/greeter_test.go +++ b/mockgen/internal/tests/custom_package_name/greeter/greeter_test.go @@ -3,8 +3,8 @@ package greeter import ( "testing" - "github.com/golang/mock/gomock" - "github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1" + "go.uber.org/mock/gomock" + "go.uber.org/mock/mockgen/internal/tests/custom_package_name/client/v1" ) func TestGreeter_Greet(t *testing.T) { diff --git a/mockgen/internal/tests/dot_imports/mock.go b/mockgen/internal/tests/dot_imports/mock.go index 6e46eab9..bf02da83 100644 --- a/mockgen/internal/tests/dot_imports/mock.go +++ b/mockgen/internal/tests/dot_imports/mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: input.go - +// +// Generated by this command: +// +// mockgen -package dot_imports -destination mock.go -source input.go +// // Package dot_imports is a generated GoMock package. package dot_imports @@ -10,7 +14,7 @@ import ( . "net/http" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockWithDotImports is a mock of WithDotImports interface. diff --git a/mockgen/internal/tests/empty_interface/mock.go b/mockgen/internal/tests/empty_interface/mock.go index bffcf8ea..56a0d24b 100644 --- a/mockgen/internal/tests/empty_interface/mock.go +++ b/mockgen/internal/tests/empty_interface/mock.go @@ -1,11 +1,15 @@ // Code generated by MockGen. DO NOT EDIT. // Source: input.go - +// +// Generated by this command: +// +// mockgen -package empty_interface -destination mock.go -source input.go +// // Package empty_interface is a generated GoMock package. package empty_interface import ( - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockEmpty is a mock of Empty interface. diff --git a/mockgen/internal/tests/extra_import/mock.go b/mockgen/internal/tests/extra_import/mock.go index d8b0928e..3622083b 100644 --- a/mockgen/internal/tests/extra_import/mock.go +++ b/mockgen/internal/tests/extra_import/mock.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/golang/mock/mockgen/internal/tests/extra_import (interfaces: Foo) - +// Source: go.uber.org/mock/mockgen/internal/tests/extra_import (interfaces: Foo) +// +// Generated by this command: +// +// mockgen -destination mock.go -package extra_import . Foo +// // Package extra_import is a generated GoMock package. package extra_import import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockFoo is a mock of Foo interface. diff --git a/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go b/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go index 8eca8644..d8195906 100644 --- a/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go +++ b/mockgen/internal/tests/generated_identifier_conflict/bugreport_mock.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. // Source: bugreport.go - +// +// Generated by this command: +// +// mockgen -destination bugreport_mock.go -package bugreport -source=bugreport.go +// // Package bugreport is a generated GoMock package. package bugreport import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockExample is a mock of Example interface. diff --git a/mockgen/internal/tests/generated_identifier_conflict/bugreport_test.go b/mockgen/internal/tests/generated_identifier_conflict/bugreport_test.go index 3ca9807d..3b53248a 100644 --- a/mockgen/internal/tests/generated_identifier_conflict/bugreport_test.go +++ b/mockgen/internal/tests/generated_identifier_conflict/bugreport_test.go @@ -1,7 +1,7 @@ package bugreport import ( - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" "testing" ) diff --git a/mockgen/internal/tests/generics/external.go b/mockgen/internal/tests/generics/external.go index ec5032aa..a12c39f8 100644 --- a/mockgen/internal/tests/generics/external.go +++ b/mockgen/internal/tests/generics/external.go @@ -1,13 +1,16 @@ package generics import ( - "github.com/golang/mock/mockgen/internal/tests/generics/other" + "context" + "io" + + "go.uber.org/mock/mockgen/internal/tests/generics/other" "golang.org/x/exp/constraints" ) -//go:generate mockgen --source=external.go --destination=source/mock_external_test.go --package source +//go:generate mockgen --source=external.go --destination=source/mock_external_mock.go --package source -type ExternalConstraint[I constraints.Integer, F constraints.Float] interface { +type ExternalConstraint[I constraints.Integer, F any] interface { One(string) string Two(I) string Three(I) F @@ -18,4 +21,23 @@ type ExternalConstraint[I constraints.Integer, F constraints.Float] interface { Eight(F) other.Two[I, F] Nine(Iface[I]) Ten(*I) + Eleven() map[string]I + Twelve(ctx context.Context) <-chan []I + Thirteen(...I) *F +} + +type EmbeddingIface[T constraints.Integer, R constraints.Float] interface { + io.Reader + Generator[R] + Earth[Generator[T]] + other.Either[R, StructType, other.Five, Generator[T]] + ExternalConstraint[T, R] +} + +type Generator[T any] interface { + Generate() T +} + +type Group[T Generator[any]] interface { + Join(ctx context.Context) []T } diff --git a/mockgen/internal/tests/generics/generics.go b/mockgen/internal/tests/generics/generics.go index 0b389622..5ee56924 100644 --- a/mockgen/internal/tests/generics/generics.go +++ b/mockgen/internal/tests/generics/generics.go @@ -1,8 +1,11 @@ package generics -import "github.com/golang/mock/mockgen/internal/tests/generics/other" +import ( + "go.uber.org/mock/mockgen/internal/tests/generics/other" + "golang.org/x/exp/constraints" +) -//go:generate mockgen --source=generics.go --destination=source/mock_generics_test.go --package source +//go:generate mockgen --source=generics.go --destination=source/mock_generics_mock.go --package source ////go:generate mockgen --destination=reflect/mock_test.go --package reflect . Bar,Bar2 type Bar[T any, R any] interface { @@ -38,3 +41,19 @@ type StructType struct{} type StructType2 struct{} type AliasType Baz[other.Three] + +type Universe[T constraints.Signed] interface { + MilkyWay[T] +} + +type MilkyWay[R constraints.Integer] interface { + SolarSystem[R] +} + +type SolarSystem[T constraints.Ordered] interface { + Earth[T] +} + +type Earth[R any] interface { + Water(R) []R +} diff --git a/mockgen/internal/tests/generics/go.mod b/mockgen/internal/tests/generics/go.mod index 7eb82e14..01224450 100644 --- a/mockgen/internal/tests/generics/go.mod +++ b/mockgen/internal/tests/generics/go.mod @@ -1,10 +1,10 @@ -module github.com/golang/mock/mockgen/internal/tests/generics +module go.uber.org/mock/mockgen/internal/tests/generics -go 1.18 +go 1.19 require ( - github.com/golang/mock v1.6.0 + go.uber.org/mock v1.6.0 golang.org/x/exp v0.0.0-20220428152302-39d4317da171 ) -replace github.com/golang/mock => ../../../.. +replace go.uber.org/mock => ../../../.. diff --git a/mockgen/internal/tests/generics/go.sum b/mockgen/internal/tests/generics/go.sum index c6f44641..698ce9bc 100644 --- a/mockgen/internal/tests/generics/go.sum +++ b/mockgen/internal/tests/generics/go.sum @@ -1,26 +1,2 @@ -github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20220428152302-39d4317da171 h1:TfdoLivD44QwvssI9Sv1xwa5DcL5XQr4au4sZ2F2NV4= golang.org/x/exp v0.0.0-20220428152302-39d4317da171/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= -golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= -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-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/mockgen/internal/tests/generics/other/other.go b/mockgen/internal/tests/generics/other/other.go index 9265422b..6de7fe15 100644 --- a/mockgen/internal/tests/generics/other/other.go +++ b/mockgen/internal/tests/generics/other/other.go @@ -9,3 +9,10 @@ type Three struct{} type Four struct{} type Five interface{} + +type Either[T, R, K, V any] interface { + First() T + Second() R + Third() K + Fourth() V +} diff --git a/mockgen/internal/tests/generics/source/mock_external_mock.go b/mockgen/internal/tests/generics/source/mock_external_mock.go new file mode 100644 index 00000000..62f42d55 --- /dev/null +++ b/mockgen/internal/tests/generics/source/mock_external_mock.go @@ -0,0 +1,598 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: external.go + +// Package source is a generated GoMock package. +package source + +import ( + context "context" + reflect "reflect" + + gomock "go.uber.org/mock/gomock" + generics "go.uber.org/mock/mockgen/internal/tests/generics" + other "go.uber.org/mock/mockgen/internal/tests/generics/other" + constraints "golang.org/x/exp/constraints" +) + +// MockExternalConstraint is a mock of ExternalConstraint interface. +type MockExternalConstraint[I constraints.Integer, F any] struct { + ctrl *gomock.Controller + recorder *MockExternalConstraintMockRecorder[I, F] +} + +// MockExternalConstraintMockRecorder is the mock recorder for MockExternalConstraint. +type MockExternalConstraintMockRecorder[I constraints.Integer, F any] struct { + mock *MockExternalConstraint[I, F] +} + +// NewMockExternalConstraint creates a new mock instance. +func NewMockExternalConstraint[I constraints.Integer, F any](ctrl *gomock.Controller) *MockExternalConstraint[I, F] { + mock := &MockExternalConstraint[I, F]{ctrl: ctrl} + mock.recorder = &MockExternalConstraintMockRecorder[I, F]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExternalConstraint[I, F]) EXPECT() *MockExternalConstraintMockRecorder[I, F] { + return m.recorder +} + +// Eight mocks base method. +func (m *MockExternalConstraint[I, F]) Eight(arg0 F) other.Two[I, F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eight", arg0) + ret0, _ := ret[0].(other.Two[I, F]) + return ret0 +} + +// Eight indicates an expected call of Eight. +func (mr *MockExternalConstraintMockRecorder[I, F]) Eight(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eight), arg0) +} + +// Eleven mocks base method. +func (m *MockExternalConstraint[I, F]) Eleven() map[string]I { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eleven") + ret0, _ := ret[0].(map[string]I) + return ret0 +} + +// Eleven indicates an expected call of Eleven. +func (mr *MockExternalConstraintMockRecorder[I, F]) Eleven() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eleven)) +} + +// Five mocks base method. +func (m *MockExternalConstraint[I, F]) Five(arg0 I) generics.Baz[F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Five", arg0) + ret0, _ := ret[0].(generics.Baz[F]) + return ret0 +} + +// Five indicates an expected call of Five. +func (mr *MockExternalConstraintMockRecorder[I, F]) Five(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Five), arg0) +} + +// Four mocks base method. +func (m *MockExternalConstraint[I, F]) Four(arg0 I) generics.Foo[I, F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Four", arg0) + ret0, _ := ret[0].(generics.Foo[I, F]) + return ret0 +} + +// Four indicates an expected call of Four. +func (mr *MockExternalConstraintMockRecorder[I, F]) Four(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Four), arg0) +} + +// Nine mocks base method. +func (m *MockExternalConstraint[I, F]) Nine(arg0 generics.Iface[I]) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Nine", arg0) +} + +// Nine indicates an expected call of Nine. +func (mr *MockExternalConstraintMockRecorder[I, F]) Nine(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Nine), arg0) +} + +// One mocks base method. +func (m *MockExternalConstraint[I, F]) One(arg0 string) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "One", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// One indicates an expected call of One. +func (mr *MockExternalConstraintMockRecorder[I, F]) One(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).One), arg0) +} + +// Seven mocks base method. +func (m *MockExternalConstraint[I, F]) Seven(arg0 I) other.One[I] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seven", arg0) + ret0, _ := ret[0].(other.One[I]) + return ret0 +} + +// Seven indicates an expected call of Seven. +func (mr *MockExternalConstraintMockRecorder[I, F]) Seven(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Seven), arg0) +} + +// Six mocks base method. +func (m *MockExternalConstraint[I, F]) Six(arg0 I) *generics.Baz[F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Six", arg0) + ret0, _ := ret[0].(*generics.Baz[F]) + return ret0 +} + +// Six indicates an expected call of Six. +func (mr *MockExternalConstraintMockRecorder[I, F]) Six(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Six), arg0) +} + +// Ten mocks base method. +func (m *MockExternalConstraint[I, F]) Ten(arg0 *I) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Ten", arg0) +} + +// Ten indicates an expected call of Ten. +func (mr *MockExternalConstraintMockRecorder[I, F]) Ten(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Ten), arg0) +} + +// Thirteen mocks base method. +func (m *MockExternalConstraint[I, F]) Thirteen(arg0 ...I) *F { + m.ctrl.T.Helper() + varargs := []interface{}{} + for _, a := range arg0 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Thirteen", varargs...) + ret0, _ := ret[0].(*F) + return ret0 +} + +// Thirteen indicates an expected call of Thirteen. +func (mr *MockExternalConstraintMockRecorder[I, F]) Thirteen(arg0 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Thirteen), arg0...) +} + +// Three mocks base method. +func (m *MockExternalConstraint[I, F]) Three(arg0 I) F { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Three", arg0) + ret0, _ := ret[0].(F) + return ret0 +} + +// Three indicates an expected call of Three. +func (mr *MockExternalConstraintMockRecorder[I, F]) Three(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Three), arg0) +} + +// Twelve mocks base method. +func (m *MockExternalConstraint[I, F]) Twelve(ctx context.Context) <-chan []I { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Twelve", ctx) + ret0, _ := ret[0].(<-chan []I) + return ret0 +} + +// Twelve indicates an expected call of Twelve. +func (mr *MockExternalConstraintMockRecorder[I, F]) Twelve(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Twelve), ctx) +} + +// Two mocks base method. +func (m *MockExternalConstraint[I, F]) Two(arg0 I) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Two", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// Two indicates an expected call of Two. +func (mr *MockExternalConstraintMockRecorder[I, F]) Two(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Two), arg0) +} + +// MockEmbeddingIface is a mock of EmbeddingIface interface. +type MockEmbeddingIface[T constraints.Integer, R constraints.Float] struct { + ctrl *gomock.Controller + recorder *MockEmbeddingIfaceMockRecorder[T, R] +} + +// MockEmbeddingIfaceMockRecorder is the mock recorder for MockEmbeddingIface. +type MockEmbeddingIfaceMockRecorder[T constraints.Integer, R constraints.Float] struct { + mock *MockEmbeddingIface[T, R] +} + +// NewMockEmbeddingIface creates a new mock instance. +func NewMockEmbeddingIface[T constraints.Integer, R constraints.Float](ctrl *gomock.Controller) *MockEmbeddingIface[T, R] { + mock := &MockEmbeddingIface[T, R]{ctrl: ctrl} + mock.recorder = &MockEmbeddingIfaceMockRecorder[T, R]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEmbeddingIface[T, R]) EXPECT() *MockEmbeddingIfaceMockRecorder[T, R] { + return m.recorder +} + +// Eight mocks base method. +func (m *MockEmbeddingIface[T, R]) Eight(arg0 R) other.Two[T, R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eight", arg0) + ret0, _ := ret[0].(other.Two[T, R]) + return ret0 +} + +// Eight indicates an expected call of Eight. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eight(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eight), arg0) +} + +// Eleven mocks base method. +func (m *MockEmbeddingIface[T, R]) Eleven() map[string]T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eleven") + ret0, _ := ret[0].(map[string]T) + return ret0 +} + +// Eleven indicates an expected call of Eleven. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eleven() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eleven)) +} + +// First mocks base method. +func (m *MockEmbeddingIface[T, R]) First() R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "First") + ret0, _ := ret[0].(R) + return ret0 +} + +// First indicates an expected call of First. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) First() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "First", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).First)) +} + +// Five mocks base method. +func (m *MockEmbeddingIface[T, R]) Five(arg0 T) generics.Baz[R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Five", arg0) + ret0, _ := ret[0].(generics.Baz[R]) + return ret0 +} + +// Five indicates an expected call of Five. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Five(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Five), arg0) +} + +// Four mocks base method. +func (m *MockEmbeddingIface[T, R]) Four(arg0 T) generics.Foo[T, R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Four", arg0) + ret0, _ := ret[0].(generics.Foo[T, R]) + return ret0 +} + +// Four indicates an expected call of Four. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Four(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Four), arg0) +} + +// Fourth mocks base method. +func (m *MockEmbeddingIface[T, R]) Fourth() generics.Generator[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Fourth") + ret0, _ := ret[0].(generics.Generator[T]) + return ret0 +} + +// Fourth indicates an expected call of Fourth. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Fourth() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Fourth", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Fourth)) +} + +// Generate mocks base method. +func (m *MockEmbeddingIface[T, R]) Generate() R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Generate") + ret0, _ := ret[0].(R) + return ret0 +} + +// Generate indicates an expected call of Generate. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Generate() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Generate", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Generate)) +} + +// Nine mocks base method. +func (m *MockEmbeddingIface[T, R]) Nine(arg0 generics.Iface[T]) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Nine", arg0) +} + +// Nine indicates an expected call of Nine. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Nine(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Nine), arg0) +} + +// One mocks base method. +func (m *MockEmbeddingIface[T, R]) One(arg0 string) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "One", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// One indicates an expected call of One. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) One(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).One), arg0) +} + +// Read mocks base method. +func (m *MockEmbeddingIface[T, R]) Read(p []byte) (int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Read", p) + ret0, _ := ret[0].(int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Read indicates an expected call of Read. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Read(p interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Read), p) +} + +// Second mocks base method. +func (m *MockEmbeddingIface[T, R]) Second() generics.StructType { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Second") + ret0, _ := ret[0].(generics.StructType) + return ret0 +} + +// Second indicates an expected call of Second. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Second() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Second", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Second)) +} + +// Seven mocks base method. +func (m *MockEmbeddingIface[T, R]) Seven(arg0 T) other.One[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seven", arg0) + ret0, _ := ret[0].(other.One[T]) + return ret0 +} + +// Seven indicates an expected call of Seven. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Seven(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Seven), arg0) +} + +// Six mocks base method. +func (m *MockEmbeddingIface[T, R]) Six(arg0 T) *generics.Baz[R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Six", arg0) + ret0, _ := ret[0].(*generics.Baz[R]) + return ret0 +} + +// Six indicates an expected call of Six. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Six(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Six), arg0) +} + +// Ten mocks base method. +func (m *MockEmbeddingIface[T, R]) Ten(arg0 *T) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Ten", arg0) +} + +// Ten indicates an expected call of Ten. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Ten(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Ten), arg0) +} + +// Third mocks base method. +func (m *MockEmbeddingIface[T, R]) Third() other.Five { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Third") + ret0, _ := ret[0].(other.Five) + return ret0 +} + +// Third indicates an expected call of Third. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Third() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Third", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Third)) +} + +// Thirteen mocks base method. +func (m *MockEmbeddingIface[T, R]) Thirteen(arg0 ...T) *R { + m.ctrl.T.Helper() + varargs := []interface{}{} + for _, a := range arg0 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Thirteen", varargs...) + ret0, _ := ret[0].(*R) + return ret0 +} + +// Thirteen indicates an expected call of Thirteen. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Thirteen(arg0 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Thirteen), arg0...) +} + +// Three mocks base method. +func (m *MockEmbeddingIface[T, R]) Three(arg0 T) R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Three", arg0) + ret0, _ := ret[0].(R) + return ret0 +} + +// Three indicates an expected call of Three. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Three(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Three), arg0) +} + +// Twelve mocks base method. +func (m *MockEmbeddingIface[T, R]) Twelve(ctx context.Context) <-chan []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Twelve", ctx) + ret0, _ := ret[0].(<-chan []T) + return ret0 +} + +// Twelve indicates an expected call of Twelve. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Twelve(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Twelve), ctx) +} + +// Two mocks base method. +func (m *MockEmbeddingIface[T, R]) Two(arg0 T) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Two", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// Two indicates an expected call of Two. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Two(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Two), arg0) +} + +// Water mocks base method. +func (m *MockEmbeddingIface[T, R]) Water(arg0 generics.Generator[T]) []generics.Generator[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]generics.Generator[T]) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Water(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Water), arg0) +} + +// MockGenerator is a mock of Generator interface. +type MockGenerator[T any] struct { + ctrl *gomock.Controller + recorder *MockGeneratorMockRecorder[T] +} + +// MockGeneratorMockRecorder is the mock recorder for MockGenerator. +type MockGeneratorMockRecorder[T any] struct { + mock *MockGenerator[T] +} + +// NewMockGenerator creates a new mock instance. +func NewMockGenerator[T any](ctrl *gomock.Controller) *MockGenerator[T] { + mock := &MockGenerator[T]{ctrl: ctrl} + mock.recorder = &MockGeneratorMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockGenerator[T]) EXPECT() *MockGeneratorMockRecorder[T] { + return m.recorder +} + +// Generate mocks base method. +func (m *MockGenerator[T]) Generate() T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Generate") + ret0, _ := ret[0].(T) + return ret0 +} + +// Generate indicates an expected call of Generate. +func (mr *MockGeneratorMockRecorder[T]) Generate() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Generate", reflect.TypeOf((*MockGenerator[T])(nil).Generate)) +} + +// MockGroup is a mock of Group interface. +type MockGroup[T generics.Generator[any]] struct { + ctrl *gomock.Controller + recorder *MockGroupMockRecorder[T] +} + +// MockGroupMockRecorder is the mock recorder for MockGroup. +type MockGroupMockRecorder[T generics.Generator[any]] struct { + mock *MockGroup[T] +} + +// NewMockGroup creates a new mock instance. +func NewMockGroup[T generics.Generator[any]](ctrl *gomock.Controller) *MockGroup[T] { + mock := &MockGroup[T]{ctrl: ctrl} + mock.recorder = &MockGroupMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockGroup[T]) EXPECT() *MockGroupMockRecorder[T] { + return m.recorder +} + +// Join mocks base method. +func (m *MockGroup[T]) Join(ctx context.Context) []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Join", ctx) + ret0, _ := ret[0].([]T) + return ret0 +} + +// Join indicates an expected call of Join. +func (mr *MockGroupMockRecorder[T]) Join(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Join", reflect.TypeOf((*MockGroup[T])(nil).Join), ctx) +} diff --git a/mockgen/internal/tests/generics/source/mock_external_test.go b/mockgen/internal/tests/generics/source/mock_external_test.go index aab22749..c345164f 100644 --- a/mockgen/internal/tests/generics/source/mock_external_test.go +++ b/mockgen/internal/tests/generics/source/mock_external_test.go @@ -1,173 +1,41 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: external.go - -// Package source is a generated GoMock package. package source import ( - reflect "reflect" + "context" + "testing" - gomock "github.com/golang/mock/gomock" - generics "github.com/golang/mock/mockgen/internal/tests/generics" - other "github.com/golang/mock/mockgen/internal/tests/generics/other" - constraints "golang.org/x/exp/constraints" + "go.uber.org/mock/gomock" + "go.uber.org/mock/mockgen/internal/tests/generics" ) -// MockExternalConstraint is a mock of ExternalConstraint interface. -type MockExternalConstraint[I constraints.Integer, F constraints.Float] struct { - ctrl *gomock.Controller - recorder *MockExternalConstraintMockRecorder[I, F] -} - -// MockExternalConstraintMockRecorder is the mock recorder for MockExternalConstraint. -type MockExternalConstraintMockRecorder[I constraints.Integer, F constraints.Float] struct { - mock *MockExternalConstraint[I, F] -} - -// NewMockExternalConstraint creates a new mock instance. -func NewMockExternalConstraint[I constraints.Integer, F constraints.Float](ctrl *gomock.Controller) *MockExternalConstraint[I, F] { - mock := &MockExternalConstraint[I, F]{ctrl: ctrl} - mock.recorder = &MockExternalConstraintMockRecorder[I, F]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockExternalConstraint[I, F]) EXPECT() *MockExternalConstraintMockRecorder[I, F] { - return m.recorder -} - -// Eight mocks base method. -func (m *MockExternalConstraint[I, F]) Eight(arg0 F) other.Two[I, F] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Eight", arg0) - ret0, _ := ret[0].(other.Two[I, F]) - return ret0 -} - -// Eight indicates an expected call of Eight. -func (mr *MockExternalConstraintMockRecorder[I, F]) Eight(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eight), arg0) -} - -// Five mocks base method. -func (m *MockExternalConstraint[I, F]) Five(arg0 I) generics.Baz[F] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Five", arg0) - ret0, _ := ret[0].(generics.Baz[F]) - return ret0 -} - -// Five indicates an expected call of Five. -func (mr *MockExternalConstraintMockRecorder[I, F]) Five(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Five), arg0) -} - -// Four mocks base method. -func (m *MockExternalConstraint[I, F]) Four(arg0 I) generics.Foo[I, F] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Four", arg0) - ret0, _ := ret[0].(generics.Foo[I, F]) - return ret0 -} - -// Four indicates an expected call of Four. -func (mr *MockExternalConstraintMockRecorder[I, F]) Four(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Four), arg0) -} - -// Nine mocks base method. -func (m *MockExternalConstraint[I, F]) Nine(arg0 generics.Iface[I]) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Nine", arg0) -} - -// Nine indicates an expected call of Nine. -func (mr *MockExternalConstraintMockRecorder[I, F]) Nine(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Nine), arg0) -} - -// One mocks base method. -func (m *MockExternalConstraint[I, F]) One(arg0 string) string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "One", arg0) - ret0, _ := ret[0].(string) - return ret0 -} - -// One indicates an expected call of One. -func (mr *MockExternalConstraintMockRecorder[I, F]) One(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).One), arg0) -} - -// Seven mocks base method. -func (m *MockExternalConstraint[I, F]) Seven(arg0 I) other.One[I] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Seven", arg0) - ret0, _ := ret[0].(other.One[I]) - return ret0 -} - -// Seven indicates an expected call of Seven. -func (mr *MockExternalConstraintMockRecorder[I, F]) Seven(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Seven), arg0) -} - -// Six mocks base method. -func (m *MockExternalConstraint[I, F]) Six(arg0 I) *generics.Baz[F] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Six", arg0) - ret0, _ := ret[0].(*generics.Baz[F]) - return ret0 -} - -// Six indicates an expected call of Six. -func (mr *MockExternalConstraintMockRecorder[I, F]) Six(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Six), arg0) -} +func TestMockEmbeddingIface_One(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() -// Ten mocks base method. -func (m *MockExternalConstraint[I, F]) Ten(arg0 *I) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Ten", arg0) + m := NewMockEmbeddingIface[int, float64](ctrl) + m.EXPECT().One("foo").Return("bar") + if v := m.One("foo"); v != "bar" { + t.Errorf("One() = %v, want %v", v, "bar") + } } -// Ten indicates an expected call of Ten. -func (mr *MockExternalConstraintMockRecorder[I, F]) Ten(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Ten), arg0) -} +func TestMockUniverse_Water(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() -// Three mocks base method. -func (m *MockExternalConstraint[I, F]) Three(arg0 I) F { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Three", arg0) - ret0, _ := ret[0].(F) - return ret0 + m := NewMockUniverse[int](ctrl) + m.EXPECT().Water(1024) + m.Water(1024) } -// Three indicates an expected call of Three. -func (mr *MockExternalConstraintMockRecorder[I, F]) Three(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Three), arg0) -} - -// Two mocks base method. -func (m *MockExternalConstraint[I, F]) Two(arg0 I) string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Two", arg0) - ret0, _ := ret[0].(string) - return ret0 -} +func TestNewMockGroup_Join(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() -// Two indicates an expected call of Two. -func (mr *MockExternalConstraintMockRecorder[I, F]) Two(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Two), arg0) + m := NewMockGroup[generics.Generator[any]](ctrl) + ctx := context.TODO() + m.EXPECT().Join(ctx).Return(nil) + if v := m.Join(ctx); v != nil { + t.Errorf("Join() = %v, want %v", v, nil) + } } diff --git a/mockgen/internal/tests/generics/source/mock_generics_test.go b/mockgen/internal/tests/generics/source/mock_generics_mock.go similarity index 68% rename from mockgen/internal/tests/generics/source/mock_generics_test.go rename to mockgen/internal/tests/generics/source/mock_generics_mock.go index 0223e311..db279150 100644 --- a/mockgen/internal/tests/generics/source/mock_generics_test.go +++ b/mockgen/internal/tests/generics/source/mock_generics_mock.go @@ -7,9 +7,10 @@ package source import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - generics "github.com/golang/mock/mockgen/internal/tests/generics" - other "github.com/golang/mock/mockgen/internal/tests/generics/other" + gomock "go.uber.org/mock/gomock" + generics "go.uber.org/mock/mockgen/internal/tests/generics" + other "go.uber.org/mock/mockgen/internal/tests/generics/other" + constraints "golang.org/x/exp/constraints" ) // MockBar is a mock of Bar interface. @@ -327,3 +328,151 @@ func NewMockIface[T any](ctrl *gomock.Controller) *MockIface[T] { func (m *MockIface[T]) EXPECT() *MockIfaceMockRecorder[T] { return m.recorder } + +// MockUniverse is a mock of Universe interface. +type MockUniverse[T constraints.Signed] struct { + ctrl *gomock.Controller + recorder *MockUniverseMockRecorder[T] +} + +// MockUniverseMockRecorder is the mock recorder for MockUniverse. +type MockUniverseMockRecorder[T constraints.Signed] struct { + mock *MockUniverse[T] +} + +// NewMockUniverse creates a new mock instance. +func NewMockUniverse[T constraints.Signed](ctrl *gomock.Controller) *MockUniverse[T] { + mock := &MockUniverse[T]{ctrl: ctrl} + mock.recorder = &MockUniverseMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockUniverse[T]) EXPECT() *MockUniverseMockRecorder[T] { + return m.recorder +} + +// Water mocks base method. +func (m *MockUniverse[T]) Water(arg0 T) []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]T) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockUniverseMockRecorder[T]) Water(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockUniverse[T])(nil).Water), arg0) +} + +// MockMilkyWay is a mock of MilkyWay interface. +type MockMilkyWay[R constraints.Integer] struct { + ctrl *gomock.Controller + recorder *MockMilkyWayMockRecorder[R] +} + +// MockMilkyWayMockRecorder is the mock recorder for MockMilkyWay. +type MockMilkyWayMockRecorder[R constraints.Integer] struct { + mock *MockMilkyWay[R] +} + +// NewMockMilkyWay creates a new mock instance. +func NewMockMilkyWay[R constraints.Integer](ctrl *gomock.Controller) *MockMilkyWay[R] { + mock := &MockMilkyWay[R]{ctrl: ctrl} + mock.recorder = &MockMilkyWayMockRecorder[R]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockMilkyWay[R]) EXPECT() *MockMilkyWayMockRecorder[R] { + return m.recorder +} + +// Water mocks base method. +func (m *MockMilkyWay[R]) Water(arg0 R) []R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]R) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockMilkyWayMockRecorder[R]) Water(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockMilkyWay[R])(nil).Water), arg0) +} + +// MockSolarSystem is a mock of SolarSystem interface. +type MockSolarSystem[T constraints.Ordered] struct { + ctrl *gomock.Controller + recorder *MockSolarSystemMockRecorder[T] +} + +// MockSolarSystemMockRecorder is the mock recorder for MockSolarSystem. +type MockSolarSystemMockRecorder[T constraints.Ordered] struct { + mock *MockSolarSystem[T] +} + +// NewMockSolarSystem creates a new mock instance. +func NewMockSolarSystem[T constraints.Ordered](ctrl *gomock.Controller) *MockSolarSystem[T] { + mock := &MockSolarSystem[T]{ctrl: ctrl} + mock.recorder = &MockSolarSystemMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSolarSystem[T]) EXPECT() *MockSolarSystemMockRecorder[T] { + return m.recorder +} + +// Water mocks base method. +func (m *MockSolarSystem[T]) Water(arg0 T) []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]T) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockSolarSystemMockRecorder[T]) Water(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockSolarSystem[T])(nil).Water), arg0) +} + +// MockEarth is a mock of Earth interface. +type MockEarth[R any] struct { + ctrl *gomock.Controller + recorder *MockEarthMockRecorder[R] +} + +// MockEarthMockRecorder is the mock recorder for MockEarth. +type MockEarthMockRecorder[R any] struct { + mock *MockEarth[R] +} + +// NewMockEarth creates a new mock instance. +func NewMockEarth[R any](ctrl *gomock.Controller) *MockEarth[R] { + mock := &MockEarth[R]{ctrl: ctrl} + mock.recorder = &MockEarthMockRecorder[R]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEarth[R]) EXPECT() *MockEarthMockRecorder[R] { + return m.recorder +} + +// Water mocks base method. +func (m *MockEarth[R]) Water(arg0 R) []R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]R) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockEarthMockRecorder[R]) Water(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockEarth[R])(nil).Water), arg0) +} diff --git a/mockgen/internal/tests/import_embedded_interface/bugreport.go b/mockgen/internal/tests/import_embedded_interface/bugreport.go index 798d138e..0fedd7ef 100644 --- a/mockgen/internal/tests/import_embedded_interface/bugreport.go +++ b/mockgen/internal/tests/import_embedded_interface/bugreport.go @@ -19,8 +19,8 @@ package bugreport import ( "log" - "github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/ersatz" - "github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/faux" + "go.uber.org/mock/mockgen/internal/tests/import_embedded_interface/ersatz" + "go.uber.org/mock/mockgen/internal/tests/import_embedded_interface/faux" ) // Source is an interface w/ an embedded foreign interface diff --git a/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go b/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go index c060f8eb..54b559dc 100644 --- a/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go +++ b/mockgen/internal/tests/import_embedded_interface/bugreport_mock.go @@ -1,15 +1,19 @@ // Code generated by MockGen. DO NOT EDIT. // Source: bugreport.go - +// +// Generated by this command: +// +// mockgen -destination bugreport_mock.go -package bugreport -source=bugreport.go +// // Package bugreport is a generated GoMock package. package bugreport import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - ersatz "github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/ersatz" - ersatz0 "github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/other/ersatz" + gomock "go.uber.org/mock/gomock" + ersatz "go.uber.org/mock/mockgen/internal/tests/import_embedded_interface/ersatz" + ersatz0 "go.uber.org/mock/mockgen/internal/tests/import_embedded_interface/other/ersatz" ) // MockSource is a mock of Source interface. diff --git a/mockgen/internal/tests/import_embedded_interface/bugreport_test.go b/mockgen/internal/tests/import_embedded_interface/bugreport_test.go index 5915cbe1..27678408 100644 --- a/mockgen/internal/tests/import_embedded_interface/bugreport_test.go +++ b/mockgen/internal/tests/import_embedded_interface/bugreport_test.go @@ -11,12 +11,13 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + package bugreport import ( "testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) // TestValidInterface assesses whether or not the generated mock is valid diff --git a/mockgen/internal/tests/import_embedded_interface/ersatz/ersatz.go b/mockgen/internal/tests/import_embedded_interface/ersatz/ersatz.go index 0d2c7815..be01bb41 100644 --- a/mockgen/internal/tests/import_embedded_interface/ersatz/ersatz.go +++ b/mockgen/internal/tests/import_embedded_interface/ersatz/ersatz.go @@ -11,6 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + package ersatz type Embedded interface { diff --git a/mockgen/internal/tests/import_embedded_interface/faux/conflict.go b/mockgen/internal/tests/import_embedded_interface/faux/conflict.go index 27803dd6..5fcf9c1a 100644 --- a/mockgen/internal/tests/import_embedded_interface/faux/conflict.go +++ b/mockgen/internal/tests/import_embedded_interface/faux/conflict.go @@ -11,9 +11,10 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + package faux -import "github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/other/log" +import "go.uber.org/mock/mockgen/internal/tests/import_embedded_interface/other/log" func Conflict1() { log.Foo() diff --git a/mockgen/internal/tests/import_embedded_interface/faux/faux.go b/mockgen/internal/tests/import_embedded_interface/faux/faux.go index e1d66988..db3d1554 100644 --- a/mockgen/internal/tests/import_embedded_interface/faux/faux.go +++ b/mockgen/internal/tests/import_embedded_interface/faux/faux.go @@ -11,12 +11,13 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + package faux import ( "log" - "github.com/golang/mock/mockgen/internal/tests/import_embedded_interface/other/ersatz" + "go.uber.org/mock/mockgen/internal/tests/import_embedded_interface/other/ersatz" ) type Foreign interface { diff --git a/mockgen/internal/tests/import_embedded_interface/net_mock.go b/mockgen/internal/tests/import_embedded_interface/net_mock.go index 07792a6d..abe13c62 100644 --- a/mockgen/internal/tests/import_embedded_interface/net_mock.go +++ b/mockgen/internal/tests/import_embedded_interface/net_mock.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: net.go - +// +// Generated by this command: +// +// mockgen -destination net_mock.go -package bugreport -source=net.go +// // Package bugreport is a generated GoMock package. package bugreport @@ -8,7 +12,7 @@ import ( http "net/http" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockNet is a mock of Net interface. diff --git a/mockgen/internal/tests/import_embedded_interface/net_test.go b/mockgen/internal/tests/import_embedded_interface/net_test.go index 381f7de3..bf98dd80 100644 --- a/mockgen/internal/tests/import_embedded_interface/net_test.go +++ b/mockgen/internal/tests/import_embedded_interface/net_test.go @@ -11,12 +11,13 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + package bugreport import ( "testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) // TestValidInterface assesses whether or not the generated mock is valid diff --git a/mockgen/internal/tests/import_embedded_interface/other/ersatz/ersatz.go b/mockgen/internal/tests/import_embedded_interface/other/ersatz/ersatz.go index 9ca63914..25815d61 100644 --- a/mockgen/internal/tests/import_embedded_interface/other/ersatz/ersatz.go +++ b/mockgen/internal/tests/import_embedded_interface/other/ersatz/ersatz.go @@ -11,6 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + package ersatz type Embedded interface { diff --git a/mockgen/internal/tests/import_embedded_interface/other/log/log.go b/mockgen/internal/tests/import_embedded_interface/other/log/log.go index c0d032bf..469ba319 100644 --- a/mockgen/internal/tests/import_embedded_interface/other/log/log.go +++ b/mockgen/internal/tests/import_embedded_interface/other/log/log.go @@ -11,6 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + package log func Foo() {} diff --git a/mockgen/internal/tests/import_source/definition/source_mock.go b/mockgen/internal/tests/import_source/definition/source_mock.go index b3d58d76..cb9bf181 100644 --- a/mockgen/internal/tests/import_source/definition/source_mock.go +++ b/mockgen/internal/tests/import_source/definition/source_mock.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. // Source: source.go - +// +// Generated by this command: +// +// mockgen -package source -destination source_mock.go -source=source.go +// // Package source is a generated GoMock package. package source import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockS is a mock of S interface. diff --git a/mockgen/internal/tests/import_source/source_mock.go b/mockgen/internal/tests/import_source/source_mock.go index 46677a31..993813f7 100644 --- a/mockgen/internal/tests/import_source/source_mock.go +++ b/mockgen/internal/tests/import_source/source_mock.go @@ -1,14 +1,18 @@ // Code generated by MockGen. DO NOT EDIT. // Source: source.go - +// +// Generated by this command: +// +// mockgen -destination ../source_mock.go -source=source.go +// // Package mock_source is a generated GoMock package. package mock_source import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - source "github.com/golang/mock/mockgen/internal/tests/import_source/definition" + gomock "go.uber.org/mock/gomock" + source "go.uber.org/mock/mockgen/internal/tests/import_source/definition" ) // MockS is a mock of S interface. diff --git a/mockgen/internal/tests/internal_pkg/generate.go b/mockgen/internal/tests/internal_pkg/generate.go index 4e0a0cca..3e3e17fb 100644 --- a/mockgen/internal/tests/internal_pkg/generate.go +++ b/mockgen/internal/tests/internal_pkg/generate.go @@ -1,4 +1,4 @@ package test -//go:generate mockgen -destination subdir/internal/pkg/reflect_output/mock.go github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg Intf +//go:generate mockgen -destination subdir/internal/pkg/reflect_output/mock.go go.uber.org/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg Intf //go:generate mockgen -source subdir/internal/pkg/input.go -destination subdir/internal/pkg/source_output/mock.go diff --git a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go index 967c4b59..f1139ee7 100644 --- a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go +++ b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/reflect_output/mock.go @@ -1,14 +1,18 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg (interfaces: Intf) - +// Source: go.uber.org/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg (interfaces: Intf) +// +// Generated by this command: +// +// mockgen -destination subdir/internal/pkg/reflect_output/mock.go go.uber.org/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg Intf +// // Package mock_pkg is a generated GoMock package. package mock_pkg import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - pkg "github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg" + gomock "go.uber.org/mock/gomock" + pkg "go.uber.org/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg" ) // MockIntf is a mock of Intf interface. diff --git a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go index 2e61bae4..33ee528a 100644 --- a/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go +++ b/mockgen/internal/tests/internal_pkg/subdir/internal/pkg/source_output/mock.go @@ -1,14 +1,18 @@ // Code generated by MockGen. DO NOT EDIT. // Source: subdir/internal/pkg/input.go - +// +// Generated by this command: +// +// mockgen -source subdir/internal/pkg/input.go -destination subdir/internal/pkg/source_output/mock.go +// // Package mock_pkg is a generated GoMock package. package mock_pkg import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - pkg "github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg" + gomock "go.uber.org/mock/gomock" + pkg "go.uber.org/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg" ) // MockArg is a mock of Arg interface. diff --git a/mockgen/internal/tests/missing_import/output/source_mock.go b/mockgen/internal/tests/missing_import/output/source_mock.go index 082d10bc..4b31ab56 100644 --- a/mockgen/internal/tests/missing_import/output/source_mock.go +++ b/mockgen/internal/tests/missing_import/output/source_mock.go @@ -1,14 +1,18 @@ // Code generated by MockGen. DO NOT EDIT. // Source: source.go - +// +// Generated by this command: +// +// mockgen -package source -destination=../output/source_mock.go -source=source.go +// // Package source is a generated GoMock package. package source import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - source "github.com/golang/mock/mockgen/internal/tests/missing_import/source" + gomock "go.uber.org/mock/gomock" + source "go.uber.org/mock/mockgen/internal/tests/missing_import/source" ) // MockBar is a mock of Bar interface. diff --git a/mockgen/internal/tests/mock_in_test_package/mock_test.go b/mockgen/internal/tests/mock_in_test_package/mock_test.go index 08bc27b0..43af9989 100644 --- a/mockgen/internal/tests/mock_in_test_package/mock_test.go +++ b/mockgen/internal/tests/mock_in_test_package/mock_test.go @@ -1,14 +1,18 @@ // Code generated by MockGen. DO NOT EDIT. // Source: user.go - +// +// Generated by this command: +// +// mockgen --source=user.go --destination=mock_test.go --package=users_test +// // Package users_test is a generated GoMock package. package users_test import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" - users "github.com/golang/mock/mockgen/internal/tests/mock_in_test_package" + gomock "go.uber.org/mock/gomock" + users "go.uber.org/mock/mockgen/internal/tests/mock_in_test_package" ) // MockFinder is a mock of Finder interface. diff --git a/mockgen/internal/tests/overlapping_methods/mock.go b/mockgen/internal/tests/overlapping_methods/mock.go index 20cbc397..b56e2764 100644 --- a/mockgen/internal/tests/overlapping_methods/mock.go +++ b/mockgen/internal/tests/overlapping_methods/mock.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. // Source: overlap.go - +// +// Generated by this command: +// +// mockgen -package overlap -destination mock.go -source overlap.go -aux_files go.uber.org/mock/mockgen/internal/tests/overlapping_methods=interfaces.go +// // Package overlap is a generated GoMock package. package overlap import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockReadWriteCloser is a mock of ReadWriteCloser interface. diff --git a/mockgen/internal/tests/overlapping_methods/overlap.go b/mockgen/internal/tests/overlapping_methods/overlap.go index 82ff012e..b2625b14 100644 --- a/mockgen/internal/tests/overlapping_methods/overlap.go +++ b/mockgen/internal/tests/overlapping_methods/overlap.go @@ -1,6 +1,6 @@ package overlap -//go:generate mockgen -package overlap -destination mock.go -source overlap.go -aux_files github.com/golang/mock/mockgen/internal/tests/overlapping_methods=interfaces.go +//go:generate mockgen -package overlap -destination mock.go -source overlap.go -aux_files go.uber.org/mock/mockgen/internal/tests/overlapping_methods=interfaces.go type ReadWriteCloser interface { ReadCloser diff --git a/mockgen/internal/tests/overlapping_methods/overlap_test.go b/mockgen/internal/tests/overlapping_methods/overlap_test.go index fdd9ba73..0bb8a3dd 100644 --- a/mockgen/internal/tests/overlapping_methods/overlap_test.go +++ b/mockgen/internal/tests/overlapping_methods/overlap_test.go @@ -4,7 +4,7 @@ import ( "errors" "testing" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // TestValidInterface assesses whether or not the generated mock is valid diff --git a/mockgen/internal/tests/panicing_test/mock_test.go b/mockgen/internal/tests/panicing_test/mock_test.go index 5c7ef668..fb8c58e6 100644 --- a/mockgen/internal/tests/panicing_test/mock_test.go +++ b/mockgen/internal/tests/panicing_test/mock_test.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. // Source: panic.go - +// +// Generated by this command: +// +// mockgen --source=panic.go --destination=mock_test.go --package=paniccode +// // Package paniccode is a generated GoMock package. package paniccode import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockFoo is a mock of Foo interface. diff --git a/mockgen/internal/tests/panicing_test/panic_test.go b/mockgen/internal/tests/panicing_test/panic_test.go index 3e630f34..436ce8e3 100644 --- a/mockgen/internal/tests/panicing_test/panic_test.go +++ b/mockgen/internal/tests/panicing_test/panic_test.go @@ -20,7 +20,7 @@ package paniccode import ( "testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func TestDanger_Panics_Explicit(t *testing.T) { diff --git a/mockgen/internal/tests/parenthesized_parameter_type/mock.go b/mockgen/internal/tests/parenthesized_parameter_type/mock.go index 911df8d8..ff4fc309 100644 --- a/mockgen/internal/tests/parenthesized_parameter_type/mock.go +++ b/mockgen/internal/tests/parenthesized_parameter_type/mock.go @@ -5,7 +5,7 @@ package parenthesized_parameter_type import ( - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" reflect "reflect" ) diff --git a/mockgen/internal/tests/self_package/mock.go b/mockgen/internal/tests/self_package/mock.go index 72e2cfa8..7aa6ddf1 100644 --- a/mockgen/internal/tests/self_package/mock.go +++ b/mockgen/internal/tests/self_package/mock.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/golang/mock/mockgen/internal/tests/self_package (interfaces: Methods) - +// Source: go.uber.org/mock/mockgen/internal/tests/self_package (interfaces: Methods) +// +// Generated by this command: +// +// mockgen -package core -self_package go.uber.org/mock/mockgen/internal/tests/self_package -destination mock.go go.uber.org/mock/mockgen/internal/tests/self_package Methods +// // Package core is a generated GoMock package. package core import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockMethods is a mock of Methods interface. diff --git a/mockgen/internal/tests/self_package/types.go b/mockgen/internal/tests/self_package/types.go index bf1bc766..9cc8630f 100644 --- a/mockgen/internal/tests/self_package/types.go +++ b/mockgen/internal/tests/self_package/types.go @@ -1,6 +1,6 @@ package core -//go:generate mockgen -package core -self_package github.com/golang/mock/mockgen/internal/tests/self_package -destination mock.go github.com/golang/mock/mockgen/internal/tests/self_package Methods +//go:generate mockgen -package core -self_package go.uber.org/mock/mockgen/internal/tests/self_package -destination mock.go go.uber.org/mock/mockgen/internal/tests/self_package Methods type Info struct{} diff --git a/mockgen/internal/tests/test_package/mock_test.go b/mockgen/internal/tests/test_package/mock_test.go index b357165b..6a7f1005 100644 --- a/mockgen/internal/tests/test_package/mock_test.go +++ b/mockgen/internal/tests/test_package/mock_test.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. // Source: user_test.go - +// +// Generated by this command: +// +// mockgen --source=user_test.go --destination=mock_test.go --package=users_test +// // Package users_test is a generated GoMock package. package users_test import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockFinder is a mock of Finder interface. diff --git a/mockgen/internal/tests/typed/bugreport.go b/mockgen/internal/tests/typed/bugreport.go new file mode 100644 index 00000000..49fc286b --- /dev/null +++ b/mockgen/internal/tests/typed/bugreport.go @@ -0,0 +1,18 @@ +package typed + +//go:generate mockgen -typed -aux_files faux=faux/faux.go -destination bugreport_mock.go -package typed -source=bugreport.go Example + +import ( + "log" + + "go.uber.org/mock/mockgen/internal/tests/typed/faux" +) + +// Source is an interface w/ an embedded foreign interface +type Source interface { + faux.Foreign +} + +func CallForeignMethod(s Source) { + log.Println(s.Method()) +} diff --git a/mockgen/internal/tests/typed/bugreport_mock.go b/mockgen/internal/tests/typed/bugreport_mock.go new file mode 100644 index 00000000..3eba52af --- /dev/null +++ b/mockgen/internal/tests/typed/bugreport_mock.go @@ -0,0 +1,111 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: bugreport.go + +// Package typed is a generated GoMock package. +package typed + +import ( + reflect "reflect" + + gomock "go.uber.org/mock/gomock" + faux "go.uber.org/mock/mockgen/internal/tests/typed/faux" +) + +// MockSource is a mock of Source interface. +type MockSource struct { + ctrl *gomock.Controller + recorder *MockSourceMockRecorder +} + +// MockSourceMockRecorder is the mock recorder for MockSource. +type MockSourceMockRecorder struct { + mock *MockSource +} + +// NewMockSource creates a new mock instance. +func NewMockSource(ctrl *gomock.Controller) *MockSource { + mock := &MockSource{ctrl: ctrl} + mock.recorder = &MockSourceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSource) EXPECT() *MockSourceMockRecorder { + return m.recorder +} + +// Error mocks base method. +func (m *MockSource) Error() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Error") + ret0, _ := ret[0].(string) + return ret0 +} + +// Error indicates an expected call of Error. +func (mr *MockSourceMockRecorder) Error() *SourceErrorCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Error", reflect.TypeOf((*MockSource)(nil).Error)) + return &SourceErrorCall{Call: call} +} + +// SourceErrorCall wrap *gomock.Call +type SourceErrorCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *SourceErrorCall) Return(arg0 string) *SourceErrorCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *SourceErrorCall) Do(f func() string) *SourceErrorCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *SourceErrorCall) DoAndReturn(f func() string) *SourceErrorCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Method mocks base method. +func (m *MockSource) Method() faux.Return { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Method") + ret0, _ := ret[0].(faux.Return) + return ret0 +} + +// Method indicates an expected call of Method. +func (mr *MockSourceMockRecorder) Method() *SourceMethodCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Method", reflect.TypeOf((*MockSource)(nil).Method)) + return &SourceMethodCall{Call: call} +} + +// SourceMethodCall wrap *gomock.Call +type SourceMethodCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *SourceMethodCall) Return(arg0 faux.Return) *SourceMethodCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *SourceMethodCall) Do(f func() faux.Return) *SourceMethodCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *SourceMethodCall) DoAndReturn(f func() faux.Return) *SourceMethodCall { + c.Call = c.Call.DoAndReturn(f) + return c +} diff --git a/mockgen/internal/tests/typed/bugreport_test.go b/mockgen/internal/tests/typed/bugreport_test.go new file mode 100644 index 00000000..5b60484f --- /dev/null +++ b/mockgen/internal/tests/typed/bugreport_test.go @@ -0,0 +1,18 @@ +package typed + +import ( + "testing" + + "go.uber.org/mock/gomock" +) + +// TestValidInterface assesses whether or not the generated mock is valid +func TestValidInterface(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + s := NewMockSource(ctrl) + s.EXPECT().Method().Return("") + + CallForeignMethod(s) +} diff --git a/mockgen/internal/tests/typed/external.go b/mockgen/internal/tests/typed/external.go new file mode 100644 index 00000000..de02e027 --- /dev/null +++ b/mockgen/internal/tests/typed/external.go @@ -0,0 +1,21 @@ +package typed + +import ( + "go.uber.org/mock/mockgen/internal/tests/typed/other" + "golang.org/x/exp/constraints" +) + +//go:generate mockgen --source=external.go --destination=source/mock_external_test.go --package source -typed + +type ExternalConstraint[I constraints.Integer, F constraints.Float] interface { + One(string) string + Two(I) string + Three(I) F + Four(I) Foo[I, F] + Five(I) Baz[F] + Six(I) *Baz[F] + Seven(I) other.One[I] + Eight(F) other.Two[I, F] + Nine(Iface[I]) + Ten(*I) +} diff --git a/mockgen/internal/tests/typed/faux/faux.go b/mockgen/internal/tests/typed/faux/faux.go new file mode 100644 index 00000000..00f795e7 --- /dev/null +++ b/mockgen/internal/tests/typed/faux/faux.go @@ -0,0 +1,11 @@ +package faux + +type Foreign interface { + Method() Return + Embedded + error +} + +type Embedded interface{} + +type Return interface{} diff --git a/mockgen/internal/tests/typed/generics.go b/mockgen/internal/tests/typed/generics.go new file mode 100644 index 00000000..9e7746ee --- /dev/null +++ b/mockgen/internal/tests/typed/generics.go @@ -0,0 +1,40 @@ +package typed + +import "go.uber.org/mock/mockgen/internal/tests/typed/other" + +//go:generate mockgen --source=generics.go --destination=source/mock_generics_test.go --package source -typed +////go:generate mockgen --destination=reflect/mock_test.go --package reflect . Bar,Bar2 + +type Bar[T any, R any] interface { + One(string) string + Two(T) string + Three(T) R + Four(T) Foo[T, R] + Five(T) Baz[T] + Six(T) *Baz[T] + Seven(T) other.One[T] + Eight(T) other.Two[T, R] + Nine(Iface[T]) + Ten(*T) + Eleven() (*other.One[T], error) + Twelve() (*other.Two[T, R], error) + Thirteen() (Baz[StructType], error) + Fourteen() (*Foo[StructType, StructType2], error) + Fifteen() (Iface[StructType], error) + Sixteen() (Baz[other.Three], error) + Seventeen() (*Foo[other.Three, other.Four], error) + Eighteen() (Iface[*other.Five], error) + Nineteen() AliasType +} + +type Foo[T any, R any] struct{} + +type Baz[T any] struct{} + +type Iface[T any] interface{} + +type StructType struct{} + +type StructType2 struct{} + +type AliasType Baz[other.Three] diff --git a/mockgen/internal/tests/typed/go.mod b/mockgen/internal/tests/typed/go.mod new file mode 100644 index 00000000..831bf3bb --- /dev/null +++ b/mockgen/internal/tests/typed/go.mod @@ -0,0 +1,10 @@ +module go.uber.org/mock/mockgen/internal/tests/typed + +go 1.18 + +replace go.uber.org/mock => ../../../.. + +require ( + go.uber.org/mock v0.0.0-00010101000000-000000000000 + golang.org/x/exp v0.0.0-20220609121020-a51bd0440498 +) diff --git a/mockgen/internal/tests/typed/go.sum b/mockgen/internal/tests/typed/go.sum new file mode 100644 index 00000000..e45fa7f4 --- /dev/null +++ b/mockgen/internal/tests/typed/go.sum @@ -0,0 +1,26 @@ +github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20220609121020-a51bd0440498 h1:TF0FvLUGEq/8wOt/9AV1nj6D4ViZGUIGCMQfCv7VRXY= +golang.org/x/exp v0.0.0-20220609121020-a51bd0440498/go.mod h1:yh0Ynu2b5ZUe3MQfp2nM0ecK7wsgouWTDN0FNeJuIys= +golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= +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-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/mockgen/internal/tests/typed/other/other.go b/mockgen/internal/tests/typed/other/other.go new file mode 100644 index 00000000..9265422b --- /dev/null +++ b/mockgen/internal/tests/typed/other/other.go @@ -0,0 +1,11 @@ +package other + +type One[T any] struct{} + +type Two[T any, R any] struct{} + +type Three struct{} + +type Four struct{} + +type Five interface{} diff --git a/mockgen/internal/tests/typed/source/mock_external_test.go b/mockgen/internal/tests/typed/source/mock_external_test.go new file mode 100644 index 00000000..8e88a99e --- /dev/null +++ b/mockgen/internal/tests/typed/source/mock_external_test.go @@ -0,0 +1,413 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: external.go + +// Package source is a generated GoMock package. +package source + +import ( + reflect "reflect" + + gomock "go.uber.org/mock/gomock" + typed "go.uber.org/mock/mockgen/internal/tests/typed" + other "go.uber.org/mock/mockgen/internal/tests/typed/other" + constraints "golang.org/x/exp/constraints" +) + +// MockExternalConstraint is a mock of ExternalConstraint interface. +type MockExternalConstraint[I constraints.Integer, F constraints.Float] struct { + ctrl *gomock.Controller + recorder *MockExternalConstraintMockRecorder[I, F] +} + +// MockExternalConstraintMockRecorder is the mock recorder for MockExternalConstraint. +type MockExternalConstraintMockRecorder[I constraints.Integer, F constraints.Float] struct { + mock *MockExternalConstraint[I, F] +} + +// NewMockExternalConstraint creates a new mock instance. +func NewMockExternalConstraint[I constraints.Integer, F constraints.Float](ctrl *gomock.Controller) *MockExternalConstraint[I, F] { + mock := &MockExternalConstraint[I, F]{ctrl: ctrl} + mock.recorder = &MockExternalConstraintMockRecorder[I, F]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExternalConstraint[I, F]) EXPECT() *MockExternalConstraintMockRecorder[I, F] { + return m.recorder +} + +// Eight mocks base method. +func (m *MockExternalConstraint[I, F]) Eight(arg0 F) other.Two[I, F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eight", arg0) + ret0, _ := ret[0].(other.Two[I, F]) + return ret0 +} + +// Eight indicates an expected call of Eight. +func (mr *MockExternalConstraintMockRecorder[I, F]) Eight(arg0 interface{}) *ExternalConstraintEightCall[I, F] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eight), arg0) + return &ExternalConstraintEightCall[I, F]{Call: call} +} + +// ExternalConstraintEightCall wrap *gomock.Call +type ExternalConstraintEightCall[I constraints.Integer, F constraints.Float] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *ExternalConstraintEightCall[I, F]) Return(arg0 other.Two[I, F]) *ExternalConstraintEightCall[I, F] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *ExternalConstraintEightCall[I, F]) Do(f func(F) other.Two[I, F]) *ExternalConstraintEightCall[I, F] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *ExternalConstraintEightCall[I, F]) DoAndReturn(f func(F) other.Two[I, F]) *ExternalConstraintEightCall[I, F] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Five mocks base method. +func (m *MockExternalConstraint[I, F]) Five(arg0 I) typed.Baz[F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Five", arg0) + ret0, _ := ret[0].(typed.Baz[F]) + return ret0 +} + +// Five indicates an expected call of Five. +func (mr *MockExternalConstraintMockRecorder[I, F]) Five(arg0 interface{}) *ExternalConstraintFiveCall[I, F] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Five), arg0) + return &ExternalConstraintFiveCall[I, F]{Call: call} +} + +// ExternalConstraintFiveCall wrap *gomock.Call +type ExternalConstraintFiveCall[I constraints.Integer, F constraints.Float] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *ExternalConstraintFiveCall[I, F]) Return(arg0 typed.Baz[F]) *ExternalConstraintFiveCall[I, F] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *ExternalConstraintFiveCall[I, F]) Do(f func(I) typed.Baz[F]) *ExternalConstraintFiveCall[I, F] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *ExternalConstraintFiveCall[I, F]) DoAndReturn(f func(I) typed.Baz[F]) *ExternalConstraintFiveCall[I, F] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Four mocks base method. +func (m *MockExternalConstraint[I, F]) Four(arg0 I) typed.Foo[I, F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Four", arg0) + ret0, _ := ret[0].(typed.Foo[I, F]) + return ret0 +} + +// Four indicates an expected call of Four. +func (mr *MockExternalConstraintMockRecorder[I, F]) Four(arg0 interface{}) *ExternalConstraintFourCall[I, F] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Four), arg0) + return &ExternalConstraintFourCall[I, F]{Call: call} +} + +// ExternalConstraintFourCall wrap *gomock.Call +type ExternalConstraintFourCall[I constraints.Integer, F constraints.Float] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *ExternalConstraintFourCall[I, F]) Return(arg0 typed.Foo[I, F]) *ExternalConstraintFourCall[I, F] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *ExternalConstraintFourCall[I, F]) Do(f func(I) typed.Foo[I, F]) *ExternalConstraintFourCall[I, F] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *ExternalConstraintFourCall[I, F]) DoAndReturn(f func(I) typed.Foo[I, F]) *ExternalConstraintFourCall[I, F] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Nine mocks base method. +func (m *MockExternalConstraint[I, F]) Nine(arg0 typed.Iface[I]) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Nine", arg0) +} + +// Nine indicates an expected call of Nine. +func (mr *MockExternalConstraintMockRecorder[I, F]) Nine(arg0 interface{}) *ExternalConstraintNineCall[I, F] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Nine), arg0) + return &ExternalConstraintNineCall[I, F]{Call: call} +} + +// ExternalConstraintNineCall wrap *gomock.Call +type ExternalConstraintNineCall[I constraints.Integer, F constraints.Float] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *ExternalConstraintNineCall[I, F]) Return() *ExternalConstraintNineCall[I, F] { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *ExternalConstraintNineCall[I, F]) Do(f func(typed.Iface[I])) *ExternalConstraintNineCall[I, F] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *ExternalConstraintNineCall[I, F]) DoAndReturn(f func(typed.Iface[I])) *ExternalConstraintNineCall[I, F] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// One mocks base method. +func (m *MockExternalConstraint[I, F]) One(arg0 string) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "One", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// One indicates an expected call of One. +func (mr *MockExternalConstraintMockRecorder[I, F]) One(arg0 interface{}) *ExternalConstraintOneCall[I, F] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).One), arg0) + return &ExternalConstraintOneCall[I, F]{Call: call} +} + +// ExternalConstraintOneCall wrap *gomock.Call +type ExternalConstraintOneCall[I constraints.Integer, F constraints.Float] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *ExternalConstraintOneCall[I, F]) Return(arg0 string) *ExternalConstraintOneCall[I, F] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *ExternalConstraintOneCall[I, F]) Do(f func(string) string) *ExternalConstraintOneCall[I, F] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *ExternalConstraintOneCall[I, F]) DoAndReturn(f func(string) string) *ExternalConstraintOneCall[I, F] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Seven mocks base method. +func (m *MockExternalConstraint[I, F]) Seven(arg0 I) other.One[I] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seven", arg0) + ret0, _ := ret[0].(other.One[I]) + return ret0 +} + +// Seven indicates an expected call of Seven. +func (mr *MockExternalConstraintMockRecorder[I, F]) Seven(arg0 interface{}) *ExternalConstraintSevenCall[I, F] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Seven), arg0) + return &ExternalConstraintSevenCall[I, F]{Call: call} +} + +// ExternalConstraintSevenCall wrap *gomock.Call +type ExternalConstraintSevenCall[I constraints.Integer, F constraints.Float] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *ExternalConstraintSevenCall[I, F]) Return(arg0 other.One[I]) *ExternalConstraintSevenCall[I, F] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *ExternalConstraintSevenCall[I, F]) Do(f func(I) other.One[I]) *ExternalConstraintSevenCall[I, F] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *ExternalConstraintSevenCall[I, F]) DoAndReturn(f func(I) other.One[I]) *ExternalConstraintSevenCall[I, F] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Six mocks base method. +func (m *MockExternalConstraint[I, F]) Six(arg0 I) *typed.Baz[F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Six", arg0) + ret0, _ := ret[0].(*typed.Baz[F]) + return ret0 +} + +// Six indicates an expected call of Six. +func (mr *MockExternalConstraintMockRecorder[I, F]) Six(arg0 interface{}) *ExternalConstraintSixCall[I, F] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Six), arg0) + return &ExternalConstraintSixCall[I, F]{Call: call} +} + +// ExternalConstraintSixCall wrap *gomock.Call +type ExternalConstraintSixCall[I constraints.Integer, F constraints.Float] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *ExternalConstraintSixCall[I, F]) Return(arg0 *typed.Baz[F]) *ExternalConstraintSixCall[I, F] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *ExternalConstraintSixCall[I, F]) Do(f func(I) *typed.Baz[F]) *ExternalConstraintSixCall[I, F] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *ExternalConstraintSixCall[I, F]) DoAndReturn(f func(I) *typed.Baz[F]) *ExternalConstraintSixCall[I, F] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Ten mocks base method. +func (m *MockExternalConstraint[I, F]) Ten(arg0 *I) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Ten", arg0) +} + +// Ten indicates an expected call of Ten. +func (mr *MockExternalConstraintMockRecorder[I, F]) Ten(arg0 interface{}) *ExternalConstraintTenCall[I, F] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Ten), arg0) + return &ExternalConstraintTenCall[I, F]{Call: call} +} + +// ExternalConstraintTenCall wrap *gomock.Call +type ExternalConstraintTenCall[I constraints.Integer, F constraints.Float] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *ExternalConstraintTenCall[I, F]) Return() *ExternalConstraintTenCall[I, F] { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *ExternalConstraintTenCall[I, F]) Do(f func(*I)) *ExternalConstraintTenCall[I, F] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *ExternalConstraintTenCall[I, F]) DoAndReturn(f func(*I)) *ExternalConstraintTenCall[I, F] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Three mocks base method. +func (m *MockExternalConstraint[I, F]) Three(arg0 I) F { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Three", arg0) + ret0, _ := ret[0].(F) + return ret0 +} + +// Three indicates an expected call of Three. +func (mr *MockExternalConstraintMockRecorder[I, F]) Three(arg0 interface{}) *ExternalConstraintThreeCall[I, F] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Three), arg0) + return &ExternalConstraintThreeCall[I, F]{Call: call} +} + +// ExternalConstraintThreeCall wrap *gomock.Call +type ExternalConstraintThreeCall[I constraints.Integer, F constraints.Float] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *ExternalConstraintThreeCall[I, F]) Return(arg0 F) *ExternalConstraintThreeCall[I, F] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *ExternalConstraintThreeCall[I, F]) Do(f func(I) F) *ExternalConstraintThreeCall[I, F] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *ExternalConstraintThreeCall[I, F]) DoAndReturn(f func(I) F) *ExternalConstraintThreeCall[I, F] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Two mocks base method. +func (m *MockExternalConstraint[I, F]) Two(arg0 I) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Two", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// Two indicates an expected call of Two. +func (mr *MockExternalConstraintMockRecorder[I, F]) Two(arg0 interface{}) *ExternalConstraintTwoCall[I, F] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Two), arg0) + return &ExternalConstraintTwoCall[I, F]{Call: call} +} + +// ExternalConstraintTwoCall wrap *gomock.Call +type ExternalConstraintTwoCall[I constraints.Integer, F constraints.Float] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *ExternalConstraintTwoCall[I, F]) Return(arg0 string) *ExternalConstraintTwoCall[I, F] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *ExternalConstraintTwoCall[I, F]) Do(f func(I) string) *ExternalConstraintTwoCall[I, F] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *ExternalConstraintTwoCall[I, F]) DoAndReturn(f func(I) string) *ExternalConstraintTwoCall[I, F] { + c.Call = c.Call.DoAndReturn(f) + return c +} diff --git a/mockgen/internal/tests/typed/source/mock_generics_test.go b/mockgen/internal/tests/typed/source/mock_generics_test.go new file mode 100644 index 00000000..239bb5fe --- /dev/null +++ b/mockgen/internal/tests/typed/source/mock_generics_test.go @@ -0,0 +1,785 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: generics.go + +// Package source is a generated GoMock package. +package source + +import ( + reflect "reflect" + + gomock "go.uber.org/mock/gomock" + typed "go.uber.org/mock/mockgen/internal/tests/typed" + other "go.uber.org/mock/mockgen/internal/tests/typed/other" +) + +// MockBar is a mock of Bar interface. +type MockBar[T any, R any] struct { + ctrl *gomock.Controller + recorder *MockBarMockRecorder[T, R] +} + +// MockBarMockRecorder is the mock recorder for MockBar. +type MockBarMockRecorder[T any, R any] struct { + mock *MockBar[T, R] +} + +// NewMockBar creates a new mock instance. +func NewMockBar[T any, R any](ctrl *gomock.Controller) *MockBar[T, R] { + mock := &MockBar[T, R]{ctrl: ctrl} + mock.recorder = &MockBarMockRecorder[T, R]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBar[T, R]) EXPECT() *MockBarMockRecorder[T, R] { + return m.recorder +} + +// Eight mocks base method. +func (m *MockBar[T, R]) Eight(arg0 T) other.Two[T, R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eight", arg0) + ret0, _ := ret[0].(other.Two[T, R]) + return ret0 +} + +// Eight indicates an expected call of Eight. +func (mr *MockBarMockRecorder[T, R]) Eight(arg0 interface{}) *BarEightCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockBar[T, R])(nil).Eight), arg0) + return &BarEightCall[T, R]{Call: call} +} + +// BarEightCall wrap *gomock.Call +type BarEightCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarEightCall[T, R]) Return(arg0 other.Two[T, R]) *BarEightCall[T, R] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarEightCall[T, R]) Do(f func(T) other.Two[T, R]) *BarEightCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarEightCall[T, R]) DoAndReturn(f func(T) other.Two[T, R]) *BarEightCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Eighteen mocks base method. +func (m *MockBar[T, R]) Eighteen() (typed.Iface[*other.Five], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eighteen") + ret0, _ := ret[0].(typed.Iface[*other.Five]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Eighteen indicates an expected call of Eighteen. +func (mr *MockBarMockRecorder[T, R]) Eighteen() *BarEighteenCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eighteen", reflect.TypeOf((*MockBar[T, R])(nil).Eighteen)) + return &BarEighteenCall[T, R]{Call: call} +} + +// BarEighteenCall wrap *gomock.Call +type BarEighteenCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarEighteenCall[T, R]) Return(arg0 typed.Iface[*other.Five], arg1 error) *BarEighteenCall[T, R] { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarEighteenCall[T, R]) Do(f func() (typed.Iface[*other.Five], error)) *BarEighteenCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarEighteenCall[T, R]) DoAndReturn(f func() (typed.Iface[*other.Five], error)) *BarEighteenCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Eleven mocks base method. +func (m *MockBar[T, R]) Eleven() (*other.One[T], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eleven") + ret0, _ := ret[0].(*other.One[T]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Eleven indicates an expected call of Eleven. +func (mr *MockBarMockRecorder[T, R]) Eleven() *BarElevenCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockBar[T, R])(nil).Eleven)) + return &BarElevenCall[T, R]{Call: call} +} + +// BarElevenCall wrap *gomock.Call +type BarElevenCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarElevenCall[T, R]) Return(arg0 *other.One[T], arg1 error) *BarElevenCall[T, R] { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarElevenCall[T, R]) Do(f func() (*other.One[T], error)) *BarElevenCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarElevenCall[T, R]) DoAndReturn(f func() (*other.One[T], error)) *BarElevenCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Fifteen mocks base method. +func (m *MockBar[T, R]) Fifteen() (typed.Iface[typed.StructType], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Fifteen") + ret0, _ := ret[0].(typed.Iface[typed.StructType]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Fifteen indicates an expected call of Fifteen. +func (mr *MockBarMockRecorder[T, R]) Fifteen() *BarFifteenCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Fifteen", reflect.TypeOf((*MockBar[T, R])(nil).Fifteen)) + return &BarFifteenCall[T, R]{Call: call} +} + +// BarFifteenCall wrap *gomock.Call +type BarFifteenCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarFifteenCall[T, R]) Return(arg0 typed.Iface[typed.StructType], arg1 error) *BarFifteenCall[T, R] { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarFifteenCall[T, R]) Do(f func() (typed.Iface[typed.StructType], error)) *BarFifteenCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarFifteenCall[T, R]) DoAndReturn(f func() (typed.Iface[typed.StructType], error)) *BarFifteenCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Five mocks base method. +func (m *MockBar[T, R]) Five(arg0 T) typed.Baz[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Five", arg0) + ret0, _ := ret[0].(typed.Baz[T]) + return ret0 +} + +// Five indicates an expected call of Five. +func (mr *MockBarMockRecorder[T, R]) Five(arg0 interface{}) *BarFiveCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockBar[T, R])(nil).Five), arg0) + return &BarFiveCall[T, R]{Call: call} +} + +// BarFiveCall wrap *gomock.Call +type BarFiveCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarFiveCall[T, R]) Return(arg0 typed.Baz[T]) *BarFiveCall[T, R] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarFiveCall[T, R]) Do(f func(T) typed.Baz[T]) *BarFiveCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarFiveCall[T, R]) DoAndReturn(f func(T) typed.Baz[T]) *BarFiveCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Four mocks base method. +func (m *MockBar[T, R]) Four(arg0 T) typed.Foo[T, R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Four", arg0) + ret0, _ := ret[0].(typed.Foo[T, R]) + return ret0 +} + +// Four indicates an expected call of Four. +func (mr *MockBarMockRecorder[T, R]) Four(arg0 interface{}) *BarFourCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockBar[T, R])(nil).Four), arg0) + return &BarFourCall[T, R]{Call: call} +} + +// BarFourCall wrap *gomock.Call +type BarFourCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarFourCall[T, R]) Return(arg0 typed.Foo[T, R]) *BarFourCall[T, R] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarFourCall[T, R]) Do(f func(T) typed.Foo[T, R]) *BarFourCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarFourCall[T, R]) DoAndReturn(f func(T) typed.Foo[T, R]) *BarFourCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Fourteen mocks base method. +func (m *MockBar[T, R]) Fourteen() (*typed.Foo[typed.StructType, typed.StructType2], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Fourteen") + ret0, _ := ret[0].(*typed.Foo[typed.StructType, typed.StructType2]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Fourteen indicates an expected call of Fourteen. +func (mr *MockBarMockRecorder[T, R]) Fourteen() *BarFourteenCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Fourteen", reflect.TypeOf((*MockBar[T, R])(nil).Fourteen)) + return &BarFourteenCall[T, R]{Call: call} +} + +// BarFourteenCall wrap *gomock.Call +type BarFourteenCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarFourteenCall[T, R]) Return(arg0 *typed.Foo[typed.StructType, typed.StructType2], arg1 error) *BarFourteenCall[T, R] { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarFourteenCall[T, R]) Do(f func() (*typed.Foo[typed.StructType, typed.StructType2], error)) *BarFourteenCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarFourteenCall[T, R]) DoAndReturn(f func() (*typed.Foo[typed.StructType, typed.StructType2], error)) *BarFourteenCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Nine mocks base method. +func (m *MockBar[T, R]) Nine(arg0 typed.Iface[T]) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Nine", arg0) +} + +// Nine indicates an expected call of Nine. +func (mr *MockBarMockRecorder[T, R]) Nine(arg0 interface{}) *BarNineCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockBar[T, R])(nil).Nine), arg0) + return &BarNineCall[T, R]{Call: call} +} + +// BarNineCall wrap *gomock.Call +type BarNineCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarNineCall[T, R]) Return() *BarNineCall[T, R] { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarNineCall[T, R]) Do(f func(typed.Iface[T])) *BarNineCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarNineCall[T, R]) DoAndReturn(f func(typed.Iface[T])) *BarNineCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Nineteen mocks base method. +func (m *MockBar[T, R]) Nineteen() typed.AliasType { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Nineteen") + ret0, _ := ret[0].(typed.AliasType) + return ret0 +} + +// Nineteen indicates an expected call of Nineteen. +func (mr *MockBarMockRecorder[T, R]) Nineteen() *BarNineteenCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nineteen", reflect.TypeOf((*MockBar[T, R])(nil).Nineteen)) + return &BarNineteenCall[T, R]{Call: call} +} + +// BarNineteenCall wrap *gomock.Call +type BarNineteenCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarNineteenCall[T, R]) Return(arg0 typed.AliasType) *BarNineteenCall[T, R] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarNineteenCall[T, R]) Do(f func() typed.AliasType) *BarNineteenCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarNineteenCall[T, R]) DoAndReturn(f func() typed.AliasType) *BarNineteenCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// One mocks base method. +func (m *MockBar[T, R]) One(arg0 string) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "One", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// One indicates an expected call of One. +func (mr *MockBarMockRecorder[T, R]) One(arg0 interface{}) *BarOneCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockBar[T, R])(nil).One), arg0) + return &BarOneCall[T, R]{Call: call} +} + +// BarOneCall wrap *gomock.Call +type BarOneCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarOneCall[T, R]) Return(arg0 string) *BarOneCall[T, R] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarOneCall[T, R]) Do(f func(string) string) *BarOneCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarOneCall[T, R]) DoAndReturn(f func(string) string) *BarOneCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Seven mocks base method. +func (m *MockBar[T, R]) Seven(arg0 T) other.One[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seven", arg0) + ret0, _ := ret[0].(other.One[T]) + return ret0 +} + +// Seven indicates an expected call of Seven. +func (mr *MockBarMockRecorder[T, R]) Seven(arg0 interface{}) *BarSevenCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockBar[T, R])(nil).Seven), arg0) + return &BarSevenCall[T, R]{Call: call} +} + +// BarSevenCall wrap *gomock.Call +type BarSevenCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarSevenCall[T, R]) Return(arg0 other.One[T]) *BarSevenCall[T, R] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarSevenCall[T, R]) Do(f func(T) other.One[T]) *BarSevenCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarSevenCall[T, R]) DoAndReturn(f func(T) other.One[T]) *BarSevenCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Seventeen mocks base method. +func (m *MockBar[T, R]) Seventeen() (*typed.Foo[other.Three, other.Four], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seventeen") + ret0, _ := ret[0].(*typed.Foo[other.Three, other.Four]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Seventeen indicates an expected call of Seventeen. +func (mr *MockBarMockRecorder[T, R]) Seventeen() *BarSeventeenCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seventeen", reflect.TypeOf((*MockBar[T, R])(nil).Seventeen)) + return &BarSeventeenCall[T, R]{Call: call} +} + +// BarSeventeenCall wrap *gomock.Call +type BarSeventeenCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarSeventeenCall[T, R]) Return(arg0 *typed.Foo[other.Three, other.Four], arg1 error) *BarSeventeenCall[T, R] { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarSeventeenCall[T, R]) Do(f func() (*typed.Foo[other.Three, other.Four], error)) *BarSeventeenCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarSeventeenCall[T, R]) DoAndReturn(f func() (*typed.Foo[other.Three, other.Four], error)) *BarSeventeenCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Six mocks base method. +func (m *MockBar[T, R]) Six(arg0 T) *typed.Baz[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Six", arg0) + ret0, _ := ret[0].(*typed.Baz[T]) + return ret0 +} + +// Six indicates an expected call of Six. +func (mr *MockBarMockRecorder[T, R]) Six(arg0 interface{}) *BarSixCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockBar[T, R])(nil).Six), arg0) + return &BarSixCall[T, R]{Call: call} +} + +// BarSixCall wrap *gomock.Call +type BarSixCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarSixCall[T, R]) Return(arg0 *typed.Baz[T]) *BarSixCall[T, R] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarSixCall[T, R]) Do(f func(T) *typed.Baz[T]) *BarSixCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarSixCall[T, R]) DoAndReturn(f func(T) *typed.Baz[T]) *BarSixCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Sixteen mocks base method. +func (m *MockBar[T, R]) Sixteen() (typed.Baz[other.Three], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Sixteen") + ret0, _ := ret[0].(typed.Baz[other.Three]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Sixteen indicates an expected call of Sixteen. +func (mr *MockBarMockRecorder[T, R]) Sixteen() *BarSixteenCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sixteen", reflect.TypeOf((*MockBar[T, R])(nil).Sixteen)) + return &BarSixteenCall[T, R]{Call: call} +} + +// BarSixteenCall wrap *gomock.Call +type BarSixteenCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarSixteenCall[T, R]) Return(arg0 typed.Baz[other.Three], arg1 error) *BarSixteenCall[T, R] { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarSixteenCall[T, R]) Do(f func() (typed.Baz[other.Three], error)) *BarSixteenCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarSixteenCall[T, R]) DoAndReturn(f func() (typed.Baz[other.Three], error)) *BarSixteenCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Ten mocks base method. +func (m *MockBar[T, R]) Ten(arg0 *T) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Ten", arg0) +} + +// Ten indicates an expected call of Ten. +func (mr *MockBarMockRecorder[T, R]) Ten(arg0 interface{}) *BarTenCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockBar[T, R])(nil).Ten), arg0) + return &BarTenCall[T, R]{Call: call} +} + +// BarTenCall wrap *gomock.Call +type BarTenCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarTenCall[T, R]) Return() *BarTenCall[T, R] { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarTenCall[T, R]) Do(f func(*T)) *BarTenCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarTenCall[T, R]) DoAndReturn(f func(*T)) *BarTenCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Thirteen mocks base method. +func (m *MockBar[T, R]) Thirteen() (typed.Baz[typed.StructType], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Thirteen") + ret0, _ := ret[0].(typed.Baz[typed.StructType]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Thirteen indicates an expected call of Thirteen. +func (mr *MockBarMockRecorder[T, R]) Thirteen() *BarThirteenCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockBar[T, R])(nil).Thirteen)) + return &BarThirteenCall[T, R]{Call: call} +} + +// BarThirteenCall wrap *gomock.Call +type BarThirteenCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarThirteenCall[T, R]) Return(arg0 typed.Baz[typed.StructType], arg1 error) *BarThirteenCall[T, R] { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarThirteenCall[T, R]) Do(f func() (typed.Baz[typed.StructType], error)) *BarThirteenCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarThirteenCall[T, R]) DoAndReturn(f func() (typed.Baz[typed.StructType], error)) *BarThirteenCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Three mocks base method. +func (m *MockBar[T, R]) Three(arg0 T) R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Three", arg0) + ret0, _ := ret[0].(R) + return ret0 +} + +// Three indicates an expected call of Three. +func (mr *MockBarMockRecorder[T, R]) Three(arg0 interface{}) *BarThreeCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockBar[T, R])(nil).Three), arg0) + return &BarThreeCall[T, R]{Call: call} +} + +// BarThreeCall wrap *gomock.Call +type BarThreeCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarThreeCall[T, R]) Return(arg0 R) *BarThreeCall[T, R] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarThreeCall[T, R]) Do(f func(T) R) *BarThreeCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarThreeCall[T, R]) DoAndReturn(f func(T) R) *BarThreeCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Twelve mocks base method. +func (m *MockBar[T, R]) Twelve() (*other.Two[T, R], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Twelve") + ret0, _ := ret[0].(*other.Two[T, R]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Twelve indicates an expected call of Twelve. +func (mr *MockBarMockRecorder[T, R]) Twelve() *BarTwelveCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockBar[T, R])(nil).Twelve)) + return &BarTwelveCall[T, R]{Call: call} +} + +// BarTwelveCall wrap *gomock.Call +type BarTwelveCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarTwelveCall[T, R]) Return(arg0 *other.Two[T, R], arg1 error) *BarTwelveCall[T, R] { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarTwelveCall[T, R]) Do(f func() (*other.Two[T, R], error)) *BarTwelveCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarTwelveCall[T, R]) DoAndReturn(f func() (*other.Two[T, R], error)) *BarTwelveCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Two mocks base method. +func (m *MockBar[T, R]) Two(arg0 T) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Two", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// Two indicates an expected call of Two. +func (mr *MockBarMockRecorder[T, R]) Two(arg0 interface{}) *BarTwoCall[T, R] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockBar[T, R])(nil).Two), arg0) + return &BarTwoCall[T, R]{Call: call} +} + +// BarTwoCall wrap *gomock.Call +type BarTwoCall[T any, R any] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *BarTwoCall[T, R]) Return(arg0 string) *BarTwoCall[T, R] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *BarTwoCall[T, R]) Do(f func(T) string) *BarTwoCall[T, R] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *BarTwoCall[T, R]) DoAndReturn(f func(T) string) *BarTwoCall[T, R] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// MockIface is a mock of Iface interface. +type MockIface[T any] struct { + ctrl *gomock.Controller + recorder *MockIfaceMockRecorder[T] +} + +// MockIfaceMockRecorder is the mock recorder for MockIface. +type MockIfaceMockRecorder[T any] struct { + mock *MockIface[T] +} + +// NewMockIface creates a new mock instance. +func NewMockIface[T any](ctrl *gomock.Controller) *MockIface[T] { + mock := &MockIface[T]{ctrl: ctrl} + mock.recorder = &MockIfaceMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockIface[T]) EXPECT() *MockIfaceMockRecorder[T] { + return m.recorder +} diff --git a/mockgen/internal/tests/unexported_method/bugreport_mock.go b/mockgen/internal/tests/unexported_method/bugreport_mock.go index d52d06ec..99955ec9 100644 --- a/mockgen/internal/tests/unexported_method/bugreport_mock.go +++ b/mockgen/internal/tests/unexported_method/bugreport_mock.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. // Source: bugreport.go - +// +// Generated by this command: +// +// mockgen -destination bugreport_mock.go -package bugreport -source=bugreport.go Example +// // Package bugreport is a generated GoMock package. package bugreport import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockExample is a mock of Example interface. diff --git a/mockgen/internal/tests/unexported_method/bugreport_test.go b/mockgen/internal/tests/unexported_method/bugreport_test.go index d428fb4c..b3286852 100644 --- a/mockgen/internal/tests/unexported_method/bugreport_test.go +++ b/mockgen/internal/tests/unexported_method/bugreport_test.go @@ -3,7 +3,7 @@ package bugreport import ( "testing" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" ) func TestCallExample(t *testing.T) { diff --git a/mockgen/internal/tests/vendor_dep/doc.go b/mockgen/internal/tests/vendor_dep/doc.go index 29e424c8..de3e785e 100644 --- a/mockgen/internal/tests/vendor_dep/doc.go +++ b/mockgen/internal/tests/vendor_dep/doc.go @@ -1,4 +1,4 @@ package vendor_dep -//go:generate mockgen -package vendor_dep -destination mock.go github.com/golang/mock/mockgen/internal/tests/vendor_dep VendorsDep +//go:generate mockgen -package vendor_dep -destination mock.go go.uber.org/mock/mockgen/internal/tests/vendor_dep VendorsDep //go:generate mockgen -destination source_mock_package/mock.go -source=vendor_dep.go diff --git a/mockgen/internal/tests/vendor_dep/mock.go b/mockgen/internal/tests/vendor_dep/mock.go index 4900ac08..5d8a0618 100644 --- a/mockgen/internal/tests/vendor_dep/mock.go +++ b/mockgen/internal/tests/vendor_dep/mock.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/golang/mock/mockgen/internal/tests/vendor_dep (interfaces: VendorsDep) - +// Source: go.uber.org/mock/mockgen/internal/tests/vendor_dep (interfaces: VendorsDep) +// +// Generated by this command: +// +// mockgen -package vendor_dep -destination mock.go go.uber.org/mock/mockgen/internal/tests/vendor_dep VendorsDep +// // Package vendor_dep is a generated GoMock package. package vendor_dep import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" present "golang.org/x/tools/present" ) diff --git a/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go b/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go index b02a0489..33121418 100644 --- a/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go +++ b/mockgen/internal/tests/vendor_dep/source_mock_package/mock.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. // Source: vendor_dep.go - +// +// Generated by this command: +// +// mockgen -destination source_mock_package/mock.go -source=vendor_dep.go +// // Package mock_vendor_dep is a generated GoMock package. package mock_vendor_dep import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" present "golang.org/x/tools/present" ) diff --git a/mockgen/internal/tests/vendor_pkg/mock.go b/mockgen/internal/tests/vendor_pkg/mock.go index f0a41968..9b6264cc 100644 --- a/mockgen/internal/tests/vendor_pkg/mock.go +++ b/mockgen/internal/tests/vendor_pkg/mock.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. // Source: golang.org/x/tools/present (interfaces: Elem) - +// +// Generated by this command: +// +// mockgen -destination mock.go -package vendor_pkg golang.org/x/tools/present Elem +// // Package vendor_pkg is a generated GoMock package. package vendor_pkg import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockElem is a mock of Elem interface. diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index 79cb921c..44090356 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -37,14 +37,14 @@ import ( "strings" "unicode" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" "golang.org/x/mod/modfile" toolsimports "golang.org/x/tools/imports" ) const ( - gomockImportPath = "github.com/golang/mock/gomock" + gomockImportPath = "go.uber.org/mock/gomock" ) var ( @@ -54,13 +54,15 @@ var ( ) var ( - source = flag.String("source", "", "(source mode) Input Go source file; enables source mode.") - destination = flag.String("destination", "", "Output file; defaults to stdout.") - mockNames = flag.String("mock_names", "", "Comma-separated interfaceName=mockName pairs of explicit mock names to use. Mock names default to 'Mock'+ interfaceName suffix.") - packageOut = flag.String("package", "", "Package of the generated code; defaults to the package of the input with a 'mock_' prefix.") - selfPackage = flag.String("self_package", "", "The full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. This can happen if the mock's package is set to one of its inputs (usually the main one) and the output is stdio so mockgen cannot detect the final output package. Setting this flag will then tell mockgen which import to exclude.") - writePkgComment = flag.Bool("write_package_comment", true, "Writes package documentation comment (godoc) if true.") - copyrightFile = flag.String("copyright_file", "", "Copyright file used to add copyright header") + source = flag.String("source", "", "(source mode) Input Go source file; enables source mode.") + destination = flag.String("destination", "", "Output file; defaults to stdout.") + mockNames = flag.String("mock_names", "", "Comma-separated interfaceName=mockName pairs of explicit mock names to use. Mock names default to 'Mock'+ interfaceName suffix.") + packageOut = flag.String("package", "", "Package of the generated code; defaults to the package of the input with a 'mock_' prefix.") + selfPackage = flag.String("self_package", "", "The full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. This can happen if the mock's package is set to one of its inputs (usually the main one) and the output is stdio so mockgen cannot detect the final output package. Setting this flag will then tell mockgen which import to exclude.") + writePkgComment = flag.Bool("write_package_comment", true, "Writes package documentation comment (godoc) if true.") + writeSourceComment = flag.Bool("write_source_comment", true, "Writes original file (source mode) or interface names (reflect mode) comment if true.") + copyrightFile = flag.String("copyright_file", "", "Copyright file used to add copyright header") + typed = flag.Bool("typed", false, "Generate Type-safe 'Return', 'Do', 'DoAndReturn' function") debugParser = flag.Bool("debug_parser", false, "Print out parser results only.") showVersion = flag.Bool("version", false, "Print version.") @@ -282,12 +284,16 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac } g.p("// Code generated by MockGen. DO NOT EDIT.") - if g.filename != "" { - g.p("// Source: %v", g.filename) - } else { - g.p("// Source: %v (interfaces: %v)", g.srcPackage, g.srcInterfaces) + if *writeSourceComment { + if g.filename != "" { + g.p("// Source: %v", g.filename) + } else { + g.p("// Source: %v (interfaces: %v)", g.srcPackage, g.srcInterfaces) + } } - g.p("") + g.p("//") + g.p("// Generated by this command:") + g.p("// %v", strings.Join(os.Args, " ")) // Get all required imports, and generate unique names for them all. im := pkg.Imports() @@ -444,7 +450,7 @@ func (g *generator) GenerateMockInterface(intf *model.Interface, outputPackagePa g.out() g.p("}") - g.GenerateMockMethods(mockType, intf, outputPackagePath, shortTp) + g.GenerateMockMethods(mockType, intf, outputPackagePath, longTp, shortTp, *typed) return nil } @@ -455,13 +461,17 @@ func (b byMethodName) Len() int { return len(b) } func (b byMethodName) Swap(i, j int) { b[i], b[j] = b[j], b[i] } func (b byMethodName) Less(i, j int) bool { return b[i].Name < b[j].Name } -func (g *generator) GenerateMockMethods(mockType string, intf *model.Interface, pkgOverride, shortTp string) { +func (g *generator) GenerateMockMethods(mockType string, intf *model.Interface, pkgOverride, longTp, shortTp string, typed bool) { sort.Sort(byMethodName(intf.Methods)) for _, m := range intf.Methods { g.p("") _ = g.GenerateMockMethod(mockType, m, pkgOverride, shortTp) g.p("") - _ = g.GenerateMockRecorderMethod(mockType, m, shortTp) + _ = g.GenerateMockRecorderMethod(intf, mockType, m, shortTp, typed) + if typed { + g.p("") + _ = g.GenerateMockReturnCallMethod(intf, m, pkgOverride, longTp, shortTp) + } } } @@ -481,8 +491,8 @@ func makeArgString(argNames, argTypes []string) string { // GenerateMockMethod generates a mock method implementation. // If non-empty, pkgOverride is the package in which unqualified types reside. func (g *generator) GenerateMockMethod(mockType string, m *model.Method, pkgOverride, shortTp string) error { - argNames := g.getArgNames(m) - argTypes := g.getArgTypes(m, pkgOverride) + argNames := g.getArgNames(m, true /* in */) + argTypes := g.getArgTypes(m, pkgOverride, true /* in */) argString := makeArgString(argNames, argTypes) rets := make([]string, len(m.Out)) @@ -545,8 +555,8 @@ func (g *generator) GenerateMockMethod(mockType string, m *model.Method, pkgOver return nil } -func (g *generator) GenerateMockRecorderMethod(mockType string, m *model.Method, shortTp string) error { - argNames := g.getArgNames(m) +func (g *generator) GenerateMockRecorderMethod(intf *model.Interface, mockType string, m *model.Method, shortTp string, typed bool) error { + argNames := g.getArgNames(m, true) var argString string if m.Variadic == nil { @@ -569,7 +579,12 @@ func (g *generator) GenerateMockRecorderMethod(mockType string, m *model.Method, idRecv := ia.allocateIdentifier("mr") g.p("// %v indicates an expected call of %v.", m.Name, m.Name) - g.p("func (%s *%vMockRecorder%v) %v(%v) *gomock.Call {", idRecv, mockType, shortTp, m.Name, argString) + if typed { + g.p("func (%s *%vMockRecorder%v) %v(%v) *%s%sCall%s {", idRecv, mockType, shortTp, m.Name, argString, intf.Name, m.Name, shortTp) + } else { + g.p("func (%s *%vMockRecorder%v) %v(%v) *gomock.Call {", idRecv, mockType, shortTp, m.Name, argString) + } + g.in() g.p("%s.mock.ctrl.T.Helper()", idRecv) @@ -592,35 +607,114 @@ func (g *generator) GenerateMockRecorderMethod(mockType string, m *model.Method, callArgs = ", " + idVarArgs + "..." } } - g.p(`return %s.mock.ctrl.RecordCallWithMethodType(%s.mock, "%s", reflect.TypeOf((*%s%s)(nil).%s)%s)`, idRecv, idRecv, m.Name, mockType, shortTp, m.Name, callArgs) + if typed { + g.p(`call := %s.mock.ctrl.RecordCallWithMethodType(%s.mock, "%s", reflect.TypeOf((*%s%s)(nil).%s)%s)`, idRecv, idRecv, m.Name, mockType, shortTp, m.Name, callArgs) + g.p(`return &%s%sCall%s{Call: call}`, intf.Name, m.Name, shortTp) + } else { + g.p(`return %s.mock.ctrl.RecordCallWithMethodType(%s.mock, "%s", reflect.TypeOf((*%s%s)(nil).%s)%s)`, idRecv, idRecv, m.Name, mockType, shortTp, m.Name, callArgs) + } g.out() g.p("}") return nil } -func (g *generator) getArgNames(m *model.Method) []string { - argNames := make([]string, len(m.In)) - for i, p := range m.In { +func (g *generator) GenerateMockReturnCallMethod(intf *model.Interface, m *model.Method, pkgOverride, longTp, shortTp string) error { + argNames := g.getArgNames(m, true /* in */) + retNames := g.getArgNames(m, false /* out */) + argTypes := g.getArgTypes(m, pkgOverride, true /* in */) + retTypes := g.getArgTypes(m, pkgOverride, false /* out */) + argString := strings.Join(argTypes, ", ") + + rets := make([]string, len(m.Out)) + for i, p := range m.Out { + rets[i] = p.Type.String(g.packageMap, pkgOverride) + } + + var retString string + switch { + case len(rets) == 1: + retString = " " + rets[0] + case len(rets) > 1: + retString = " (" + strings.Join(rets, ", ") + ")" + } + + ia := newIdentifierAllocator(argNames) + idRecv := ia.allocateIdentifier("c") + + recvStructName := intf.Name + m.Name + + g.p("// %s%sCall wrap *gomock.Call", intf.Name, m.Name) + g.p("type %s%sCall%s struct{", intf.Name, m.Name, longTp) + g.in() + g.p("*gomock.Call") + g.out() + g.p("}") + + g.p("// Return rewrite *gomock.Call.Return") + g.p("func (%s *%sCall%s) Return(%v) *%sCall%s {", idRecv, recvStructName, shortTp, makeArgString(retNames, retTypes), recvStructName, shortTp) + g.in() + var retArgs string + if len(retNames) > 0 { + retArgs = strings.Join(retNames, ", ") + } + g.p(`%s.Call = %v.Call.Return(%v)`, idRecv, idRecv, retArgs) + g.p("return %s", idRecv) + g.out() + g.p("}") + + g.p("// Do rewrite *gomock.Call.Do") + g.p("func (%s *%sCall%s) Do(f func(%v)%v) *%sCall%s {", idRecv, recvStructName, shortTp, argString, retString, recvStructName, shortTp) + g.in() + g.p(`%s.Call = %v.Call.Do(f)`, idRecv, idRecv) + g.p("return %s", idRecv) + g.out() + g.p("}") + + g.p("// DoAndReturn rewrite *gomock.Call.DoAndReturn") + g.p("func (%s *%sCall%s) DoAndReturn(f func(%v)%v) *%sCall%s {", idRecv, recvStructName, shortTp, argString, retString, recvStructName, shortTp) + g.in() + g.p(`%s.Call = %v.Call.DoAndReturn(f)`, idRecv, idRecv) + g.p("return %s", idRecv) + g.out() + g.p("}") + return nil +} + +func (g *generator) getArgNames(m *model.Method, in bool) []string { + var params []*model.Parameter + if in { + params = m.In + } else { + params = m.Out + } + argNames := make([]string, len(params)) + for i, p := range params { name := p.Name if name == "" || name == "_" { name = fmt.Sprintf("arg%d", i) } argNames[i] = name } - if m.Variadic != nil { + if m.Variadic != nil && in { name := m.Variadic.Name if name == "" { - name = fmt.Sprintf("arg%d", len(m.In)) + name = fmt.Sprintf("arg%d", len(params)) } argNames = append(argNames, name) } return argNames } -func (g *generator) getArgTypes(m *model.Method, pkgOverride string) []string { - argTypes := make([]string, len(m.In)) - for i, p := range m.In { +func (g *generator) getArgTypes(m *model.Method, pkgOverride string, in bool) []string { + var params []*model.Parameter + if in { + params = m.In + } else { + params = m.Out + } + argTypes := make([]string, len(params)) + for i, p := range params { argTypes[i] = p.Type.String(g.packageMap, pkgOverride) } if m.Variadic != nil { diff --git a/mockgen/mockgen_test.go b/mockgen/mockgen_test.go index 55566001..01b34a89 100644 --- a/mockgen/mockgen_test.go +++ b/mockgen/mockgen_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" ) func TestMakeArgString(t *testing.T) { @@ -332,7 +332,7 @@ func TestGetArgNames(t *testing.T) { t.Run(testCase.name, func(t *testing.T) { g := generator{} - result := g.getArgNames(testCase.method) + result := g.getArgNames(testCase.method, true) if !reflect.DeepEqual(result, testCase.expected) { t.Fatalf("expected %s, got %s", result, testCase.expected) } diff --git a/mockgen/model/model.go b/mockgen/model/model.go index 94d7f4ba..70c52feb 100644 --- a/mockgen/model/model.go +++ b/mockgen/model/model.go @@ -24,7 +24,7 @@ import ( ) // pkgPath is the importable path for package model -const pkgPath = "github.com/golang/mock/mockgen/model" +const pkgPath = "go.uber.org/mock/mockgen/model" // Package is a Go package. It may be a subset. type Package struct { @@ -160,7 +160,7 @@ func init() { // For a non-pointer type, gob.Register will try to get package full path by // calling rt.PkgPath() for a name to register. If your project has vendor // directory, it is possible that PkgPath will get a path like this: - // ../../../vendor/github.com/golang/mock/mockgen/model + // ../../../vendor/go.uber.org/mock/mockgen/model gob.RegisterName(pkgPath+".PredeclaredType", PredeclaredType("")) } diff --git a/mockgen/parse.go b/mockgen/parse.go index 21c0d70a..a397922f 100644 --- a/mockgen/parse.go +++ b/mockgen/parse.go @@ -33,7 +33,7 @@ import ( "strconv" "strings" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" ) var ( @@ -274,20 +274,77 @@ func (p *fileParser) parsePackage(path string) (*fileParser, error) { return newP, nil } +func (p *fileParser) constructInstParams(pkg string, params []*ast.Field, instParams []model.Type, embeddedInstParams []ast.Expr, tps map[string]model.Type) ([]model.Type, error) { + pm := make(map[string]int) + var i int + for _, v := range params { + for _, n := range v.Names { + pm[n.Name] = i + instParams = append(instParams, model.PredeclaredType(n.Name)) + i++ + } + } + + var runtimeInstParams []model.Type + for _, instParam := range embeddedInstParams { + switch t := instParam.(type) { + case *ast.Ident: + if idx, ok := pm[t.Name]; ok { + runtimeInstParams = append(runtimeInstParams, instParams[idx]) + continue + } + } + modelType, err := p.parseType(pkg, instParam, tps) + if err != nil { + return nil, err + } + runtimeInstParams = append(runtimeInstParams, modelType) + } + + return runtimeInstParams, nil +} + +func (p *fileParser) constructTps(it *namedInterface) (tps map[string]model.Type) { + tps = make(map[string]model.Type) + n := 0 + for _, tp := range it.typeParams { + for _, tm := range tp.Names { + tps[tm.Name] = nil + if len(it.instTypes) != 0 { + tps[tm.Name] = it.instTypes[n] + n++ + } + } + } + return tps +} + +// parseInterface loads interface specified by pkg and name, parses it and returns +// a new model with the parsed. func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*model.Interface, error) { iface := &model.Interface{Name: name} - tps := make(map[string]bool) - + tps := p.constructTps(it) tp, err := p.parseFieldList(pkg, it.typeParams, tps) if err != nil { return nil, fmt.Errorf("unable to parse interface type parameters: %v", name) } + iface.TypeParams = tp - for _, v := range tp { - tps[v.Name] = true + for _, field := range it.it.Methods.List { + var methods []*model.Method + if methods, err = p.parseMethod(field, it, iface, pkg, tps); err != nil { + return nil, err + } + for _, m := range methods { + iface.AddMethod(m) + } } + return iface, nil +} - for _, field := range it.it.Methods.List { +func (p *fileParser) parseMethod(field *ast.Field, it *namedInterface, iface *model.Interface, pkg string, tps map[string]model.Type) ([]*model.Method, error) { + // {} for git diff + { switch v := field.Type.(type) { case *ast.FuncType: if nn := len(field.Names); nn != 1 { @@ -301,7 +358,7 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode if err != nil { return nil, err } - iface.AddMethod(m) + return []*model.Method{m}, nil case *ast.Ident: // Embedded interface in this package. embeddedIfaceType := p.auxInterfaces.Get(pkg, v.String()) @@ -312,10 +369,15 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode var embeddedIface *model.Interface if embeddedIfaceType != nil { var err error + embeddedIfaceType.instTypes, err = p.constructInstParams(pkg, it.typeParams, it.instTypes, it.embeddedInstTypeParams, tps) + if err != nil { + return nil, err + } embeddedIface, err = p.parseInterface(v.String(), pkg, embeddedIfaceType) if err != nil { return nil, err } + } else { // This is built-in error interface. if v.String() == model.ErrorInterface.Name { @@ -330,16 +392,17 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode return nil, p.errorf(v.Pos(), "unknown embedded interface %s.%s", pkg, v.String()) } + embeddedIfaceType.instTypes, err = p.constructInstParams(pkg, it.typeParams, it.instTypes, it.embeddedInstTypeParams, tps) + if err != nil { + return nil, err + } embeddedIface, err = ip.parseInterface(v.String(), pkg, embeddedIfaceType) if err != nil { return nil, err } } } - // Copy the methods. - for _, m := range embeddedIface.Methods { - iface.AddMethod(m) - } + return embeddedIface.Methods, nil case *ast.SelectorExpr: // Embedded interface in another package. filePkg, sel := v.X.(*ast.Ident).String(), v.Sel.String() @@ -352,6 +415,10 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode var err error embeddedIfaceType := p.auxInterfaces.Get(filePkg, sel) if embeddedIfaceType != nil { + embeddedIfaceType.instTypes, err = p.constructInstParams(pkg, it.typeParams, it.instTypes, it.embeddedInstTypeParams, tps) + if err != nil { + return nil, err + } embeddedIface, err = p.parseInterface(sel, filePkg, embeddedIfaceType) if err != nil { return nil, err @@ -373,24 +440,25 @@ func (p *fileParser) parseInterface(name, pkg string, it *namedInterface) (*mode if embeddedIfaceType = parser.importedInterfaces.Get(path, sel); embeddedIfaceType == nil { return nil, p.errorf(v.Pos(), "unknown embedded interface %s.%s", path, sel) } + + embeddedIfaceType.instTypes, err = p.constructInstParams(pkg, it.typeParams, it.instTypes, it.embeddedInstTypeParams, tps) + if err != nil { + return nil, err + } embeddedIface, err = parser.parseInterface(sel, path, embeddedIfaceType) if err != nil { return nil, err } } - // Copy the methods. // TODO: apply shadowing rules. - for _, m := range embeddedIface.Methods { - iface.AddMethod(m) - } + return embeddedIface.Methods, nil default: - return nil, fmt.Errorf("don't know how to mock method of type %T", field.Type) + return p.parseGenericMethod(field, it, iface, pkg, tps) } } - return iface, nil } -func (p *fileParser) parseFunc(pkg string, f *ast.FuncType, tps map[string]bool) (inParam []*model.Parameter, variadic *model.Parameter, outParam []*model.Parameter, err error) { +func (p *fileParser) parseFunc(pkg string, f *ast.FuncType, tps map[string]model.Type) (inParam []*model.Parameter, variadic *model.Parameter, outParam []*model.Parameter, err error) { if f.Params != nil { regParams := f.Params.List if isVariadic(f) { @@ -417,7 +485,7 @@ func (p *fileParser) parseFunc(pkg string, f *ast.FuncType, tps map[string]bool) return } -func (p *fileParser) parseFieldList(pkg string, fields []*ast.Field, tps map[string]bool) ([]*model.Parameter, error) { +func (p *fileParser) parseFieldList(pkg string, fields []*ast.Field, tps map[string]model.Type) ([]*model.Parameter, error) { nf := 0 for _, f := range fields { nn := len(f.Names) @@ -451,7 +519,7 @@ func (p *fileParser) parseFieldList(pkg string, fields []*ast.Field, tps map[str return ps, nil } -func (p *fileParser) parseType(pkg string, typ ast.Expr, tps map[string]bool) (model.Type, error) { +func (p *fileParser) parseType(pkg string, typ ast.Expr, tps map[string]model.Type) (model.Type, error) { switch v := typ.(type) { case *ast.ArrayType: ln := -1 @@ -493,7 +561,8 @@ func (p *fileParser) parseType(pkg string, typ ast.Expr, tps map[string]bool) (m } return &model.FuncType{In: in, Out: out, Variadic: variadic}, nil case *ast.Ident: - if v.IsExported() && !tps[v.Name] { + it, ok := tps[v.Name] + if v.IsExported() && !ok { // `pkg` may be an aliased imported pkg // if so, patch the import w/ the fully qualified import maybeImportedPkg, ok := p.imports[pkg] @@ -503,7 +572,9 @@ func (p *fileParser) parseType(pkg string, typ ast.Expr, tps map[string]bool) (m // assume type in this package return &model.NamedType{Package: pkg, Type: v.Name}, nil } - + if ok && it != nil { + return it, nil + } // assume predeclared type return model.PredeclaredType(v.Name), nil case *ast.InterfaceType: @@ -657,9 +728,11 @@ func importsOfFile(file *ast.File) (normalImports map[string]importedPackage, do } type namedInterface struct { - name *ast.Ident - it *ast.InterfaceType - typeParams []*ast.Field + name *ast.Ident + it *ast.InterfaceType + typeParams []*ast.Field + embeddedInstTypeParams []ast.Expr + instTypes []model.Type } // Create an iterator over all interfaces in file. @@ -681,7 +754,7 @@ func iterInterfaces(file *ast.File) <-chan *namedInterface { continue } - ch <- &namedInterface{ts.Name, it, getTypeSpecTypeParams(ts)} + ch <- &namedInterface{name: ts.Name, it: it, typeParams: getTypeSpecTypeParams(ts)} } } close(ch) diff --git a/mockgen/parse_test.go b/mockgen/parse_test.go index 82c831f3..3c4ba4cf 100644 --- a/mockgen/parse_test.go +++ b/mockgen/parse_test.go @@ -50,7 +50,7 @@ func TestFileParser_ParsePackage(t *testing.T) { importedInterfaces: newInterfaceCache(), } - newP, err := p.parsePackage("github.com/golang/mock/mockgen/internal/tests/custom_package_name/greeter") + newP, err := p.parsePackage("go.uber.org/mock/mockgen/internal/tests/custom_package_name/greeter") if err != nil { t.Fatalf("Unexpected error: %v", err) } @@ -84,7 +84,7 @@ func checkGreeterImports(t *testing.T, imports map[string]importedPackage) { if validatorPackage, ok := imports["validator"]; !ok { t.Errorf("Expected imports to have key \"fmt\"") } else { - expectedValidatorPackage := "github.com/golang/mock/mockgen/internal/tests/custom_package_name/validator" + expectedValidatorPackage := "go.uber.org/mock/mockgen/internal/tests/custom_package_name/validator" if validatorPackage.Path() != expectedValidatorPackage { t.Errorf("Expected validator key to have value %s but got %s", expectedValidatorPackage, validatorPackage.Path()) } @@ -94,7 +94,7 @@ func checkGreeterImports(t *testing.T, imports map[string]importedPackage) { if clientPackage, ok := imports["client"]; !ok { t.Errorf("Expected imports to have key \"client\"") } else { - expectedClientPackage := "github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1" + expectedClientPackage := "go.uber.org/mock/mockgen/internal/tests/custom_package_name/client/v1" if clientPackage.Path() != expectedClientPackage { t.Errorf("Expected client key to have value %s but got %s", expectedClientPackage, clientPackage.Path()) } diff --git a/mockgen/reflect.go b/mockgen/reflect.go index 4f86a151..bcb1319d 100644 --- a/mockgen/reflect.go +++ b/mockgen/reflect.go @@ -32,7 +32,7 @@ import ( "strings" "text/template" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" ) var ( @@ -169,8 +169,8 @@ func runInDir(program []byte, dir string) (*model.Package, error) { if err := cmd.Run(); err != nil { sErr := buf.String() if strings.Contains(sErr, `cannot find package "."`) && - strings.Contains(sErr, "github.com/golang/mock/mockgen/model") { - fmt.Fprint(os.Stderr, "Please reference the steps in the README to fix this error:\n\thttps://github.com/golang/mock#reflect-vendoring-error.\n") + strings.Contains(sErr, "go.uber.org/mock/mockgen/model") { + fmt.Fprint(os.Stderr, "Please reference the steps in the README to fix this error:\n\thttps://go.uber.org/mock#reflect-vendoring-error.\n") return nil, err } return nil, err @@ -198,7 +198,7 @@ import ( "path" "reflect" - "github.com/golang/mock/mockgen/model" + "go.uber.org/mock/mockgen/model" pkg_ {{printf "%q" .ImportPath}} ) diff --git a/sample/concurrent/concurrent.go b/sample/concurrent/concurrent.go index 1fb943a4..d1ebda90 100644 --- a/sample/concurrent/concurrent.go +++ b/sample/concurrent/concurrent.go @@ -1,7 +1,7 @@ // Package concurrent demonstrates how to use gomock with goroutines. package concurrent -//go:generate mockgen -destination mock/concurrent_mock.go github.com/golang/mock/sample/concurrent Math +//go:generate mockgen -destination mock/concurrent_mock.go go.uber.org/mock/sample/concurrent Math type Math interface { Sum(a, b int) int diff --git a/sample/concurrent/concurrent_test.go b/sample/concurrent/concurrent_test.go index 878ac427..4c4ae279 100644 --- a/sample/concurrent/concurrent_test.go +++ b/sample/concurrent/concurrent_test.go @@ -5,9 +5,9 @@ import ( "context" - "github.com/golang/mock/gomock" + "go.uber.org/mock/gomock" - mock "github.com/golang/mock/sample/concurrent/mock" + mock "go.uber.org/mock/sample/concurrent/mock" ) func call(ctx context.Context, m Math) (int, error) { diff --git a/sample/concurrent/mock/concurrent_mock.go b/sample/concurrent/mock/concurrent_mock.go index 301a5bf3..31beb2e8 100644 --- a/sample/concurrent/mock/concurrent_mock.go +++ b/sample/concurrent/mock/concurrent_mock.go @@ -1,13 +1,17 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/golang/mock/sample/concurrent (interfaces: Math) - +// Source: go.uber.org/mock/sample/concurrent (interfaces: Math) +// +// Generated by this command: +// +// mockgen -destination mock/concurrent_mock.go go.uber.org/mock/sample/concurrent Math +// // Package mock_concurrent is a generated GoMock package. package mock_concurrent import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockMath is a mock of Math interface. diff --git a/sample/mock_user_test.go b/sample/mock_user_test.go index 1e630d2e..0967eea2 100644 --- a/sample/mock_user_test.go +++ b/sample/mock_user_test.go @@ -1,6 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/golang/mock/sample (interfaces: Index,Embed,Embedded) - +// Source: go.uber.org/mock/sample (interfaces: Index,Embed,Embedded) +// +// Generated by this command: +// +// mockgen -destination mock_user_test.go -package user_test go.uber.org/mock/sample Index,Embed,Embedded +// // Package user_test is a generated GoMock package. package user_test @@ -14,11 +18,11 @@ import ( reflect "reflect" template0 "text/template" - gomock "github.com/golang/mock/gomock" - imp1 "github.com/golang/mock/sample/imp1" - imp2 "github.com/golang/mock/sample/imp2" - imp3 "github.com/golang/mock/sample/imp3" - imp_four "github.com/golang/mock/sample/imp4" + gomock "go.uber.org/mock/gomock" + imp1 "go.uber.org/mock/sample/imp1" + imp2 "go.uber.org/mock/sample/imp2" + imp3 "go.uber.org/mock/sample/imp3" + imp_four "go.uber.org/mock/sample/imp4" ) // MockIndex is a mock of Index interface. diff --git a/sample/user.go b/sample/user.go index adb041e1..173a01f7 100644 --- a/sample/user.go +++ b/sample/user.go @@ -1,7 +1,7 @@ // Package user is an example package with an interface. package user -//go:generate mockgen -destination mock_user_test.go -package user_test github.com/golang/mock/sample Index,Embed,Embedded +//go:generate mockgen -destination mock_user_test.go -package user_test go.uber.org/mock/sample Index,Embed,Embedded // Random bunch of imports to test mockgen. import ( @@ -18,15 +18,15 @@ import ( t2 "text/template" - "github.com/golang/mock/sample/imp1" + "go.uber.org/mock/sample/imp1" // Dependencies outside the standard library. - renamed2 "github.com/golang/mock/sample/imp2" + renamed2 "go.uber.org/mock/sample/imp2" - . "github.com/golang/mock/sample/imp3" + . "go.uber.org/mock/sample/imp3" - imp_four "github.com/golang/mock/sample/imp4" + imp_four "go.uber.org/mock/sample/imp4" ) // calls itself "imp_four" diff --git a/sample/user_test.go b/sample/user_test.go index 35cfa0f1..4c7d93c8 100644 --- a/sample/user_test.go +++ b/sample/user_test.go @@ -4,9 +4,9 @@ package user_test import ( "testing" - "github.com/golang/mock/gomock" - user "github.com/golang/mock/sample" - "github.com/golang/mock/sample/imp1" + "go.uber.org/mock/gomock" + user "go.uber.org/mock/sample" + "go.uber.org/mock/sample/imp1" ) func TestRemember(t *testing.T) {