Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Run helper method #510

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ func (suite *Suite) Assert() *assert.Assertions {
return suite.Assertions
}

// Run is a helper method to do a simple subtest. It sets `T()` to the
// `*testing.T` of the subtest.
func (suite *Suite) Run(name string, f func()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JelteF could the name be confusing considering we already have suite.Run?

oldT := suite.T()
suite.T().Run(name, func(t *testing.T) {
suite.SetT(t)

defer func() {
suite.SetT(oldT)
}()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this result in race conditions if somebody called suite.T().Parallel() within the subtest?


f()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than receiving an empty func(), maybe we should receive func(*Suite) and send a test suite with the new *testingT?

Would that prevent race conditions?

})
}

// Run takes a testing suite and runs all of the tests attached
// to it.
func Run(t *testing.T, suite TestingSuite) {
Expand Down