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

suite: fix recoverAndFailOnPanic to report test failure at the right location #1502

Merged
merged 1 commit into from
Jan 31, 2024
Merged
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
4 changes: 4 additions & 0 deletions suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ func (suite *Suite) Assert() *assert.Assertions {
}

func recoverAndFailOnPanic(t *testing.T) {
t.Helper()
r := recover()
failOnPanic(t, r)
}

func failOnPanic(t *testing.T, r interface{}) {
t.Helper()
if r != nil {
t.Errorf("test panicked: %v\n%s", r, debug.Stack())
t.FailNow()
Expand Down Expand Up @@ -165,6 +167,8 @@ func Run(t *testing.T, suite TestingSuite) {
suite.SetT(t)
defer recoverAndFailOnPanic(t)
defer func() {
t.Helper()

r := recover()

if stats != nil {
Expand Down
Loading