MCPcopy Create free account
hub / github.com/stretchr/testify / PanicsWithError

Function PanicsWithError

assert/assertions.go:1285–1300  ·  view source on GitHub ↗

PanicsWithError asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value is an error that satisfies the EqualError comparison. assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() })

(t TestingT, errString string, f PanicTestFunc, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

1283//
1284// assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() })
1285func PanicsWithError(t TestingT, errString string, f PanicTestFunc, msgAndArgs ...interface{}) bool {
1286 if h, ok := t.(tHelper); ok {
1287 h.Helper()
1288 }
1289
1290 funcDidPanic, panicValue, panickedStack := didPanic(f)
1291 if !funcDidPanic {
1292 return Fail(t, fmt.Sprintf("func %#v should panic\n\tPanic value:\t%#v", f, panicValue), msgAndArgs...)
1293 }
1294 panicErr, ok := panicValue.(error)
1295 if !ok || panicErr.Error() != errString {
1296 return Fail(t, fmt.Sprintf("func %#v should panic with error message:\t%#v\n\tPanic value:\t%#v\n\tPanic stack:\t%s", f, errString, panicValue, panickedStack), msgAndArgs...)
1297 }
1298
1299 return true
1300}
1301
1302// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
1303//

Callers 4

PanicsWithErrorFunction · 0.92
PanicsWithErrorfFunction · 0.70
TestPanicsWithErrorFunction · 0.70
PanicsWithErrorMethod · 0.70

Calls 4

didPanicFunction · 0.85
FailFunction · 0.70
HelperMethod · 0.65
ErrorMethod · 0.45

Tested by 1

TestPanicsWithErrorFunction · 0.56