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{})
| 1335 | // |
| 1336 | // assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() }) |
| 1337 | func 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 | // |