Skip to content

Commit

Permalink
Merge pull request #1502 from stretchr/suite-fix-reporting-of-panic-l…
Browse files Browse the repository at this point in the history
…ocation

suite: fix recoverAndFailOnPanic to report test failure at the right location
  • Loading branch information
MovieStoreGuy committed Jan 31, 2024
2 parents b139300 + 2be68b5 commit c3b0c9b
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 c3b0c9b

Please sign in to comment.