This change now makes use of go list to check for package names. This
tool is module aware and allows for better named imports.
To test this change I needed to also add a small package to our mod
file. To keep this import from disappearing from go.mod I made use
of the tools file strategy.
Note this change will change the import names in generated code. This
should not be a breaking change in user code.
Fixes#326
testing.T.FailNow (and Fatal, ...) work only when called from the same
goroutine as the test. This makes using gomock with e.g. RPC server
mocks quite a challenge as the tests are likely to deadlock instead of
failing properly.
This adds a new constructor returning an additional context, which is
cancelled on any fatal failure in mock.
This commit enhances the cosmetic output of the mockgen code generator
such that its output includes package-level comment documentation. It
can be disabled by setting the `--write_package_comment` flag to
`false`. Disabling it is only useful to prevent clobbering of existing
package documentation, which would occur if the user instructed mockgen
to emit its output to a pre-existing Go package that contains end-user
public API.
This change is motivated by several things:
(1.) enhancing the readability of http://godoc documentation for large
package trees.
(2.) providing a differentiable characteristic from other
human-written packages. This helps both humans and programs
differentiate between packages themselves for purposes of
classification, which is useful when automatically refactorings
across an entire codebase like a monorepo.
(3.) keeping the output stylistically consistent with that emitted from
the protoc-gen-go code generator, which Protocol Buffers uses.
Without this fix, using the `Do` method on a variadic function will
cause a panic, because not all of the arguments will be propagated to
the action function:
```
$ go test ./sample
--- FAIL: TestVariadicFunction (0.00s)
panic: reflect: Call using zero Value argument [recovered]
panic: reflect: Call using zero Value argument [recovered]
panic: reflect: Call using zero Value argument
...
github.com/golang/mock/gomock.(*Controller).Finish(0xc4200d57a0)
/gopath/src/github.com/golang/mock/gomock/controller.go:149 +0x320
...
github.com/golang/mock/gomock.(*Call).call.func1()
/gopath/src/github.com/golang/mock/gomock/call.go:234 +0x6a
...
FAIL github.com/golang/mock/sample 0.013s
```
A nil passed to such a method would be wrapped as Eq(nil),
which would only match other nil interface values. That's
not helpful if the method takes a nilable concrete type
(e.g. a pointer). The fix here is to handle nil specially
and store it as Nil() instead.
There is a new subpackage, mockgen/model, which is an abstract
representation of a Go package. The source-based parser constructs a
model.Package, and the code generator works solely from that.
This will make future approaches (e.g. reflection-based parser) easier.
In the process I have cleaned up a bunch of the crufty package-handling
code. This should be easier to work with in the future.