This repository was archived by the owner on Jun 27, 2023. It is now read-only.
add default calling of ctrl.Finish() in go1.14+#422
Merged
codyoss merged 2 commits intogolang:masterfrom Apr 6, 2020
codyoss:gm-407
Merged
add default calling of ctrl.Finish() in go1.14+#422codyoss merged 2 commits intogolang:masterfrom codyoss:gm-407
codyoss merged 2 commits intogolang:masterfrom
codyoss:gm-407
Conversation
In go1.14 the testing package added a new cleanup method that is called at the end of test runs. By taping into this gomock can remove the need for users to call ctrl.Finish() if they pass a *testing.T into gomock.NewController(...). Fixes #407
codyoss
commented
Mar 30, 2020
| ctrl.Call(subject, "FooMethod", "argument") | ||
| } | ||
|
|
||
| func TestOrderedCallsInCorrect(t *testing.T) { |
Member
Author
There was a problem hiding this comment.
With a couple of these tests I had to get a little fancy. Their implementation relied on Finish not being called to verify things. Cleanup acts in a LIFO matter. By registering a cleanup before the one in NewController, I can assert things after Finish() has been called.
codyoss
commented
Mar 30, 2020
| // provide a log message to guide users to remove `defer ctrl.Finish()` in Go 1.14+ | ||
| tr := unwrapTestReporter(ctrl.T) | ||
| if l, ok := tr.(interface{ Log(args ...interface{}) }); ok { | ||
| l.Log("In Go 1.14+ you no longer need to `ctrl.Finish()` if a *testing.T is passed to `NewController(...)`") |
Member
Author
There was a problem hiding this comment.
I can't decide if this is a good or bad idea. Do we let users know about this new behavior? I think this only shows up with -v. WDYT?
Collaborator
There was a problem hiding this comment.
I think it's a good idea. I think you're correct that it would only show up if -v is passed
codyoss
commented
Mar 30, 2020
|
|
||
| import "testing" | ||
|
|
||
| func TestDuplicateFinishCallFails(t *testing.T) { |
Member
Author
There was a problem hiding this comment.
This was the previous behavior, lets keep things the same for versions less than 1.14
cvgw
approved these changes
Apr 6, 2020
This was referenced Mar 11, 2021
Closed
This was referenced Mar 15, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In go1.14 the testing package added a new cleanup method that is
called at the end of test runs. By taping into this gomock can
remove the need for users to call ctrl.Finish() if they pass a
*testing.T into gomock.NewController(...).
Fixes #407