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

Function PanicsWithValue

assert/assertions.go:1316–1330  ·  view source on GitHub ↗

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{})

Source from the content-addressed store, hash-verified

1314//
1315// assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() })
1316func 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

Callers 5

TestMock_WithTestFunction · 0.92
PanicsWithValueFunction · 0.92
PanicsWithValuefFunction · 0.70
TestPanicsWithValueFunction · 0.70
PanicsWithValueMethod · 0.70

Calls 3

didPanicFunction · 0.85
FailFunction · 0.70
HelperMethod · 0.65

Tested by 2

TestMock_WithTestFunction · 0.74
TestPanicsWithValueFunction · 0.56