Skip to content

Commit

Permalink
suite: fix recoverAndFailOnPanic to report at the right location
Browse files Browse the repository at this point in the history
Add calls to t.Helper() to fix the location where the panic is reported
as a test failure.
  • Loading branch information
dolmen committed Nov 1, 2023
1 parent 331c520 commit c685645
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions suite/suite.go
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

0 comments on commit c685645

Please sign in to comment.