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

Use t.Cleanup (added in go1.14) to call Finish automatically #407

@prashantv

Description

@prashantv

Requested feature

Currently, any test that uses gomock often has this snippet at the top:

ctrl := gomock.NewController(t)
defer ctrl.Finish()

The caller has to remember to defer ctrl.Finish(). This could be avoided if the gomock library supported go1.14's t.Cleanup functionality.

Why the feature is needed
It reduces likelihood of the caller forgetting to call Finish, and reduces noise in tests.

Proposed solution
(Likely in a go1.14+-only file)

  • Make Finish OK to call multiple times.
  • Add a new constructor that takes testing.TB and calls Finish in a cleanup function

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions