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{})
| 1249 | // |
| 1250 | // assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() }) |
| 1251 | func PanicsWithError(t TestingT, errString string, f PanicTestFunc, msgAndArgs ...interface{}) bool { |
| 1252 | if h, ok := t.(tHelper); ok { |
| 1253 | h.Helper() |
| 1254 | } |
| 1255 | |
| 1256 | funcDidPanic, panicValue, panickedStack := didPanic(f) |
| 1257 | if !funcDidPanic { |
| 1258 | return Fail(t, fmt.Sprintf("func %#v should panic\n\tPanic value:\t%#v", f, panicValue), msgAndArgs...) |
| 1259 | } |
| 1260 | panicErr, ok := panicValue.(error) |
| 1261 | if !ok || panicErr.Error() != errString { |
| 1262 | 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...) |
| 1263 | } |
| 1264 | |
| 1265 | return true |
| 1266 | } |
| 1267 | |
| 1268 | // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. |
| 1269 | // |
searching dependent graphs…