Skip to content

Commit

Permalink
Clarify documentation on Finish
Browse files Browse the repository at this point in the history
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 uber-go#50 but doing so would break
many users, so we reverted it in uber-go#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.
  • Loading branch information
sywhang committed Jul 10, 2024
1 parent 2c0a7fd commit 3b6f221
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gomock/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ type cleanuper interface {
// A Controller represents the top-level control of a mock ecosystem. It
// defines the scope and lifetime of mock objects, as well as their
// expectations. It is safe to call Controller's methods from multiple
// goroutines. Each test should create a new Controller and invoke Finish via
// defer.
// goroutines. Each test should create a new Controller.
//
// func TestFoo(t *testing.T) {
// ctrl := gomock.NewController(t)
Expand Down Expand Up @@ -240,6 +239,9 @@ func (ctrl *Controller) Call(receiver any, method string, args ...any) []any {

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

0 comments on commit 3b6f221

Please sign in to comment.