mirror of https://github.com/stretchr/testify.git
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.pull/1502/head
parent
b139300e7e
commit
2be68b5e9e
|
@ -78,11 +78,13 @@ func (suite *Suite) Assert() *assert.Assertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
func recoverAndFailOnPanic(t *testing.T) {
|
func recoverAndFailOnPanic(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
r := recover()
|
r := recover()
|
||||||
failOnPanic(t, r)
|
failOnPanic(t, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func failOnPanic(t *testing.T, r interface{}) {
|
func failOnPanic(t *testing.T, r interface{}) {
|
||||||
|
t.Helper()
|
||||||
if r != nil {
|
if r != nil {
|
||||||
t.Errorf("test panicked: %v\n%s", r, debug.Stack())
|
t.Errorf("test panicked: %v\n%s", r, debug.Stack())
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
|
@ -165,6 +167,8 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
suite.SetT(t)
|
suite.SetT(t)
|
||||||
defer recoverAndFailOnPanic(t)
|
defer recoverAndFailOnPanic(t)
|
||||||
defer func() {
|
defer func() {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
r := recover()
|
r := recover()
|
||||||
|
|
||||||
if stats != nil {
|
if stats != nil {
|
||||||
|
|
Loading…
Reference in New Issue