PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value equals the expected panic value. assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() })
(t TestingT, expected interface{}, f PanicTestFunc, msgAndArgs ...interface{})
| 1314 | // |
| 1315 | // assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() }) |
| 1316 | func PanicsWithValue(t TestingT, expected interface{}, f PanicTestFunc, msgAndArgs ...interface{}) bool { |
| 1317 | if h, ok := t.(tHelper); ok { |
| 1318 | h.Helper() |
| 1319 | } |
| 1320 | |
| 1321 | funcDidPanic, panicValue, panickedStack := didPanic(f) |
| 1322 | if !funcDidPanic { |
| 1323 | return Fail(t, fmt.Sprintf("func %#v should panic\n\tPanic value:\t%#v", f, panicValue), msgAndArgs...) |
| 1324 | } |
| 1325 | if panicValue != expected { |
| 1326 | return Fail(t, fmt.Sprintf("func %#v should panic with value:\t%#v\n\tPanic value:\t%#v\n\tPanic stack:\t%s", f, expected, panicValue, panickedStack), msgAndArgs...) |
| 1327 | } |
| 1328 | |
| 1329 | return true |
| 1330 | } |
| 1331 | |
| 1332 | // PanicsWithError asserts that the code inside the specified PanicTestFunc |
| 1333 | // panics, and that the recovered panic value is an error that satisfies the |