Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Add support for anonymous struct returns #701

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ 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:
@@ -30,7 +30,7 @@ jobs:

- name: Install mockgen
run: |
go install github.com/golang/mock/mockgen
go install go.uber.org/mock/mockgen

- name: Run test script
run: |
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This is the current list of maintainers to Uber's fork of gomock repository.

Sung Yoon Whang <sungyoon@uber.com>
Ryan Hang <rhang@uber.com>
Zhongpeng Lin <zplin@uber.com>
58 changes: 14 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -6,30 +6,21 @@ 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
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.

Once you have [installed Go][golang-install], install the `mockgen` tool.
Contributions are welcome in the form of GitHub issue or PR!

**Note**: If you have not done so already be sure to add `$GOPATH/bin` to your
`PATH`.
## Status

To get the latest released version use:
This project is still WIP. We will be tagging a release shortly, in early July.

### Go version < 1.16
## Supported Go Versions

```bash
GO111MODULE=on go get github.com/golang/mock/mockgen@v1.6.0
```

### Go 1.16+

```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.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.

## Running mockgen

@@ -250,28 +241,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/github.com/uber/mock.svg
[reference]: https://pkg.go.dev/github.com/uber/mock
10 changes: 8 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
module github.com/golang/mock
module go.uber.org/mock

go 1.18

require (
golang.org/x/mod v0.5.1
golang.org/x/tools v0.1.8
)

go 1.15
require (
github.com/yuin/goldmark v1.4.1 // indirect
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
)
19 changes: 0 additions & 19 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
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=
2 changes: 1 addition & 1 deletion gomock/controller_test.go
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ import (

"strings"

"github.com/golang/mock/gomock"
"go.uber.org/mock/gomock"
)

type ErrorReporter struct {
2 changes: 1 addition & 1 deletion gomock/example_test.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/golang/mock/gomock"
"go.uber.org/mock/gomock"
)

type Foo interface {
4 changes: 2 additions & 2 deletions gomock/internal/mock_gomock/mock_matcher.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gomock/matchers_test.go
Original file line number Diff line number Diff line change
@@ -14,16 +14,16 @@

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"
"errors"
"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
2 changes: 1 addition & 1 deletion gomock/mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mockgen/generic_go118.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import (
"go/ast"
"strings"

"github.com/golang/mock/mockgen/model"
"go.uber.org/mock/mockgen/model"
)

func getTypeSpecTypeParams(ts *ast.TypeSpec) []*ast.Field {
2 changes: 1 addition & 1 deletion mockgen/generic_notgo118.go
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ package main
import (
"go/ast"

"github.com/golang/mock/mockgen/model"
"go.uber.org/mock/mockgen/model"
)

func getTypeSpecTypeParams(ts *ast.TypeSpec) []*ast.Field {
Original file line number Diff line number Diff line change
@@ -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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion mockgen/internal/tests/const_array_length/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mockgen/internal/tests/copyright_file/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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 {

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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) {
2 changes: 1 addition & 1 deletion mockgen/internal/tests/dot_imports/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mockgen/internal/tests/empty_interface/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mockgen/internal/tests/extra_import/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package bugreport

import (
"github.com/golang/mock/gomock"
"go.uber.org/mock/gomock"
"testing"
)

2 changes: 1 addition & 1 deletion mockgen/internal/tests/generics/external.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package generics

import (
"github.com/golang/mock/mockgen/internal/tests/generics/other"
"go.uber.org/mock/mockgen/internal/tests/generics/other"
"golang.org/x/exp/constraints"
)

2 changes: 1 addition & 1 deletion mockgen/internal/tests/generics/generics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package generics

import "github.com/golang/mock/mockgen/internal/tests/generics/other"
import "go.uber.org/mock/mockgen/internal/tests/generics/other"

//go:generate mockgen --source=generics.go --destination=source/mock_generics_test.go --package source
////go:generate mockgen --destination=reflect/mock_test.go --package reflect . Bar,Bar2

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading