From 1bf48ebdb986edbe7b293276a0b6b0fb2b1225a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Wed, 1 Nov 2023 21:39:20 +0100 Subject: [PATCH] suite: fix recoverAndFailOnPanic to report at the right location Add calls to t.Helper() to fix the location where the panic is reported as a test failure. --- suite/suite.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/suite/suite.go b/suite/suite.go index f3aa9a16b..eac6909b4 100644 --- a/suite/suite.go +++ b/suite/suite.go @@ -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() @@ -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 {