MCPcopy
hub / github.com/stretchr/testify / PanicsWithError

Function PanicsWithError

assert/assertions.go:1337–1352  ·  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

1335//
1336// assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() })
1337func PanicsWithError(t TestingT, errString string, f PanicTestFunc, msgAndArgs ...interface{}) bool {
1338 if h, ok := t.(tHelper); ok {
1339 h.Helper()
1340 }
1341
1342 funcDidPanic, panicValue, panickedStack := didPanic(f)
1343 if !funcDidPanic {
1344 return Fail(t, fmt.Sprintf("func %#v should panic\n\tPanic value:\t%#v", f, panicValue), msgAndArgs...)
1345 }
1346 panicErr, ok := panicValue.(error)
1347 if !ok || panicErr.Error() != errString {
1348 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...)
1349 }
1350
1351 return true
1352}
1353
1354// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
1355//

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