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

Commit 7f5f64d

Browse files
authored
fixup some docs and templates (#524)
1 parent 35998bb commit 7f5f64d

File tree

3 files changed

+60
-94
lines changed

3 files changed

+60
-94
lines changed

.github/pull_request_template.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
# Any file prefixed by an underscore.
88
*/_*
99

10-
# Vim temporary files.
10+
# System
1111
.*.swp
12+
.DS_Store
1213

1314
# The mockgen binary.
1415
mockgen/mockgen
1516

16-
# A binary produced by gotest.
17-
#gomock/[568]\.out
18-
1917
# Editors
2018
.vscode
2119
.idea

README.md

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
gomock [![Build Status][travis-ci-badge]][travis-ci] [![GoDoc][godoc-badge]][godoc]
2-
======
1+
# gomock
32

4-
GoMock is a mocking framework for the [Go programming language][golang]. It
3+
[![Build Status][ci-badge]][ci-runs] [![Go Reference][reference-badge]][reference]
4+
5+
gomock is a mocking framework for the [Go programming language][golang]. It
56
integrates well with Go's built-in `testing` package, but can be used in other
67
contexts too.
78

8-
Installation
9-
------------
9+
## Installation
1010

1111
Once you have [installed Go][golang-install], install the `mockgen` tool.
1212

@@ -19,9 +19,7 @@ GO111MODULE=on go get github.com/golang/mock/mockgen@v1.5.0
1919
If you use `mockgen` in your CI pipeline, it may be more appropriate to fixate
2020
on a specific mockgen version.
2121

22-
23-
Documentation
24-
-------------
22+
## Documentation
2523

2624
After installing, you can use `go doc` to get documentation:
2725

@@ -30,14 +28,14 @@ go doc github.com/golang/mock/gomock
3028
```
3129

3230
Alternatively, there is an online reference for the package hosted on GoPkgDoc
33-
[here][gomock-ref].
31+
[here][gomock-reference].
3432

35-
Running mockgen
36-
---------------
33+
## Running mockgen
3734

3835
`mockgen` has two modes of operation: source and reflect.
3936

40-
#### Source mode
37+
### Source mode
38+
4139
Source mode generates mock interfaces from a source file.
4240
It is enabled by using the -source flag. Other flags that
4341
may be useful in this mode are -imports and -aux_files.
@@ -48,7 +46,8 @@ Example:
4846
mockgen -source=foo.go [other options]
4947
```
5048

51-
#### Reflect mode
49+
### Reflect mode
50+
5251
Reflect mode generates mock interfaces by building a program
5352
that uses reflection to understand interfaces. It is enabled
5453
by passing two non-flag arguments: an import path, and a
@@ -65,54 +64,55 @@ mockgen database/sql/driver Conn,Driver
6564
mockgen . Conn,Driver
6665
```
6766

68-
#### Flags
67+
### Flags
68+
6969
The `mockgen` command is used to generate source code for a mock
7070
class given a Go source file containing interfaces to be mocked.
7171
It supports the following flags:
7272

73-
* `-source`: A file containing interfaces to be mocked.
73+
- `-source`: A file containing interfaces to be mocked.
74+
75+
- `-destination`: A file to which to write the resulting source code. If you
76+
don't set this, the code is printed to standard output.
7477

75-
* `-destination`: A file to which to write the resulting source code. If you
76-
don't set this, the code is printed to standard output.
78+
- `-package`: The package to use for the resulting mock class
79+
source code. If you don't set this, the package name is `mock_` concatenated
80+
with the package of the input file.
7781

78-
* `-package`: The package to use for the resulting mock class
79-
source code. If you don't set this, the package name is `mock_` concatenated
80-
with the package of the input file.
82+
- `-imports`: A list of explicit imports that should be used in the resulting
83+
source code, specified as a comma-separated list of elements of the form
84+
`foo=bar/baz`, where `bar/baz` is the package being imported and `foo` is
85+
the identifier to use for the package in the generated source code.
8186

82-
* `-imports`: A list of explicit imports that should be used in the resulting
83-
source code, specified as a comma-separated list of elements of the form
84-
`foo=bar/baz`, where `bar/baz` is the package being imported and `foo` is
85-
the identifier to use for the package in the generated source code.
87+
- `-aux_files`: A list of additional files that should be consulted to
88+
resolve e.g. embedded interfaces defined in a different file. This is
89+
specified as a comma-separated list of elements of the form
90+
`foo=bar/baz.go`, where `bar/baz.go` is the source file and `foo` is the
91+
package name of that file used by the -source file.
8692

87-
* `-aux_files`: A list of additional files that should be consulted to
88-
resolve e.g. embedded interfaces defined in a different file. This is
89-
specified as a comma-separated list of elements of the form
90-
`foo=bar/baz.go`, where `bar/baz.go` is the source file and `foo` is the
91-
package name of that file used by the -source file.
93+
- `-build_flags`: (reflect mode only) Flags passed verbatim to `go build`.
9294

93-
* `-build_flags`: (reflect mode only) Flags passed verbatim to `go build`.
95+
- `-mock_names`: A list of custom names for generated mocks. This is specified
96+
as a comma-separated list of elements of the form
97+
`Repository=MockSensorRepository,Endpoint=MockSensorEndpoint`, where
98+
`Repository` is the interface name and `MockSensorRepository` is the desired
99+
mock name (mock factory method and mock recorder will be named after the mock).
100+
If one of the interfaces has no custom name specified, then default naming
101+
convention will be used.
94102

95-
* `-mock_names`: A list of custom names for generated mocks. This is specified
96-
as a comma-separated list of elements of the form
97-
`Repository=MockSensorRepository,Endpoint=MockSensorEndpoint`, where
98-
`Repository` is the interface name and `MockSensorRepository` is the desired
99-
mock name (mock factory method and mock recorder will be named after the mock).
100-
If one of the interfaces has no custom name specified, then default naming
101-
convention will be used.
102-
103-
* `-self_package`: The full package import path for the generated code. The purpose
104-
of this flag is to prevent import cycles in the generated code by trying to include
105-
its own package. This can happen if the mock's package is set to one of its
106-
inputs (usually the main one) and the output is stdio so mockgen cannot detect the
107-
final output package. Setting this flag will then tell mockgen which import to exclude.
103+
- `-self_package`: The full package import path for the generated code. The
104+
purpose of this flag is to prevent import cycles in the generated code by
105+
trying to include its own package. This can happen if the mock's package is
106+
set to one of its inputs (usually the main one) and the output is stdio so
107+
mockgen cannot detect the final output package. Setting this flag will then
108+
tell mockgen which import to exclude.
108109

109-
* `-copyright_file`: Copyright file used to add copyright header to the resulting source code.
110+
- `-copyright_file`: Copyright file used to add copyright header to the resulting source code.
110111

111112
For an example of the use of `mockgen`, see the `sample/` directory. In simple
112113
cases, you will need only the `-source` flag.
113114

114-
Building Mocks
115-
--------------
115+
## Building Mocks
116116

117117
```go
118118
type Foo interface {
@@ -150,8 +150,7 @@ passing a *testing.T into `gomock.NewController(t)` you no longer need to call
150150
`ctrl.Finish()` explicitly. It will be called for you automatically from a self
151151
registered [Cleanup](https://pkg.go.dev/testing?tab=doc#T.Cleanup) function.
152152

153-
Building Stubs
154-
--------------
153+
## Building Stubs
155154

156155
```go
157156
type Foo interface {
@@ -193,20 +192,20 @@ func TestFoo(t *testing.T) {
193192
}
194193
```
195194

196-
### Modifying Failure Messages
195+
## Modifying Failure Messages
197196

198197
When a matcher reports a failure, it prints the received (`Got`) vs the
199198
expected (`Want`) value.
200199

201-
```
200+
```shell
202201
Got: [3]
203202
Want: is equal to 2
204203
Expected call at user_test.go:33 doesn't match the argument at index 1.
205204
Got: [0 1 1 2 3]
206205
Want: is equal to 1
207206
```
208207
209-
##### Modifying `Want`
208+
### Modifying `Want`
210209
211210
The `Want` value comes from the matcher's `String()` method. If the matcher's
212211
default output doesn't meet your needs, then it can be modified as follows:
@@ -221,7 +220,7 @@ gomock.WantFormatter(
221220
This modifies the `gomock.Eq(15)` matcher's output for `Want:` from `is equal
222221
to 15` to `is equal to fifteen`.
223222
224-
##### Modifying `Got`
223+
### Modifying `Got`
225224
226225
The `Got` value comes from the object's `String()` method if it is available.
227226
In some cases the output of an object is difficult to read (e.g., `[]byte`) and
@@ -240,10 +239,10 @@ gomock.GotFormatterAdapter(
240239
241240
If the received value is `3`, then it will be printed as `03`.
242241
243-
[golang]: http://golang.org/
244-
[golang-install]: http://golang.org/doc/install.html#releases
245-
[gomock-ref]: http://godoc.org/github.com/golang/mock/gomock
246-
[travis-ci-badge]: https://travis-ci.org/golang/mock.svg?branch=master
247-
[travis-ci]: https://travis-ci.org/golang/mock
248-
[godoc-badge]: https://godoc.org/github.com/golang/mock/gomock?status.svg
249-
[godoc]: https://godoc.org/github.com/golang/mock/gomock
242+
[golang]: http://golang.org/
243+
[golang-install]: http://golang.org/doc/install.html#releases
244+
[gomock-reference]: https://pkg.go.dev/github.com/golang/mock/gomock
245+
[ci-badge]: https://github.com/golang/mock/actions/workflows/test.yml/badge.svg
246+
[ci-runs]: https://github.com/golang/mock/actions
247+
[reference-badge]: https://pkg.go.dev/badge/github.com/golang/mock.svg
248+
[reference]: https://pkg.go.dev/github.com/golang/mock

0 commit comments

Comments
 (0)