Skip to content

Commit 70a5e8c

Browse files
authored
Clarify documentation on Finish (#194)
Finish no longer has to be explicitly called on Controller with defer if the Controller was created with testing.T. We tried to just mark this as deprecated in #50 but doing so would break many users, so we reverted it in #85. In doing so we dropped some wordings from the doc that marked Finished as unnecessary for most cases. This PR fixes the docstring to guide users without explicitly marking the API deprecated.
1 parent ec32d99 commit 70a5e8c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

gomock/controller.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ type cleanuper interface {
4848
// A Controller represents the top-level control of a mock ecosystem. It
4949
// defines the scope and lifetime of mock objects, as well as their
5050
// expectations. It is safe to call Controller's methods from multiple
51-
// goroutines. Each test should create a new Controller and invoke Finish via
52-
// defer.
51+
// goroutines. Each test should create a new Controller.
5352
//
5453
// func TestFoo(t *testing.T) {
5554
// ctrl := gomock.NewController(t)
@@ -240,6 +239,9 @@ func (ctrl *Controller) Call(receiver any, method string, args ...any) []any {
240239

241240
// Finish checks to see if all the methods that were expected to be called were called.
242241
// It is not idempotent and therefore can only be invoked once.
242+
//
243+
// Note: If you pass a *testing.T into [NewController], you no longer
244+
// need to call ctrl.Finish() in your test methods.
243245
func (ctrl *Controller) Finish() {
244246
// If we're currently panicking, probably because this is a deferred call.
245247
// This must be recovered in the deferred function.

0 commit comments

Comments
 (0)