@@ -1587,61 +1587,34 @@ func TestPanicsWithValue(t *testing.T) {
15871587func TestPanicsWithError (t * testing.T ) {
15881588 t .Parallel ()
15891589
1590- type NestedErr struct {
1591- Err error
1592- }
1593-
1594- mockT := new (CollectT )
1595- if ! PanicsWithError (mockT , "panic" , func () {
1590+ mockT := new (captureTestingT )
1591+ succeeded := PanicsWithError (mockT , "panic" , func () {
15961592 panic (errors .New ("panic" ))
1597- }) {
1598- t .Error ("PanicsWithError should return true" )
1599- }
1600- Len (t , mockT .errors , 0 )
1593+ })
1594+ mockT .checkResultAndErrMsg (t , true , succeeded , "" )
16011595
1602- mockT = new (CollectT )
1603- if PanicsWithError (mockT , "Panic!" , func () {
1604- }) {
1605- t .Error ("PanicsWithError should return false" )
1606- }
1607- if Len (t , mockT .errors , 1 ) {
1608- actual := mockT .errors [0 ].Error ()
1609- Contains (t , actual , "Panic value: <nil>" )
1610- }
1596+ succeeded = PanicsWithError (mockT , "Panic!" , func () {})
1597+ Equal (t , false , succeeded , "PanicsWithError should return false" )
1598+ Contains (t , mockT .msg , "Panic value:\t <nil>" )
16111599
1612- mockT = new (CollectT )
1613- if PanicsWithError (mockT , "at the disco" , func () {
1614- panic (errors .New ("actual err msg" ))
1615- }) {
1616- t .Error ("PanicsWithError should return false" )
1617- }
1618- if Len (t , mockT .errors , 1 ) {
1619- actual := mockT .errors [0 ].Error ()
1620- Contains (t , actual , `Error message: "actual err msg"` )
1621- }
1600+ succeeded = PanicsWithError (mockT , "expected panic err msg" , func () {
1601+ panic (errors .New ("actual panic err msg" ))
1602+ })
1603+ Equal (t , false , succeeded , "PanicsWithError should return false" )
1604+ Contains (t , mockT .msg , `Error message: "actual panic err msg"` )
16221605
1623- mockT = new (CollectT )
1624- if PanicsWithError (mockT , "at the disco" , func () {
1625- panic (& PanicsWithErrorWrapper {"wrapped" , errors .New ("other err msg" )})
1626- }) {
1627- t .Error ("PanicsWithError should return false" )
1628- }
1629- if Len (t , mockT .errors , 1 ) {
1630- actual := mockT .errors [0 ].Error ()
1631- Contains (t , actual , `Error message: "wrapped: other err msg"` )
1632- }
1606+ succeeded = PanicsWithError (mockT , "expected panic err msg" , func () {
1607+ panic (& PanicsWithErrorWrapper {"wrapped" , errors .New ("actual panic err msg" )})
1608+ })
1609+ Equal (t , false , succeeded , "PanicsWithError should return false" )
1610+ Contains (t , mockT .msg , `Error message: "wrapped: actual panic err msg"` )
16331611
1634- mockT = new (CollectT )
1635- if PanicsWithError (mockT , "Panic!" , func () {
1636- panic ("panic" )
1637- }) {
1638- t .Error ("PanicsWithError should return false" )
1639- }
1640- if Len (t , mockT .errors , 1 ) {
1641- actual := mockT .errors [0 ].Error ()
1642- Contains (t , actual , `Panic value: "panic"` )
1643- NotContains (t , actual , "Error message:" , "PanicsWithError should not report error message if not due an error" )
1644- }
1612+ succeeded = PanicsWithError (mockT , "expected panic msg" , func () {
1613+ panic ("actual panic msg" )
1614+ })
1615+ Equal (t , false , succeeded , "PanicsWithError should return false" )
1616+ Contains (t , mockT .msg , `Panic value: "actual panic msg"` )
1617+ NotContains (t , mockT .msg , "Error message:" , "PanicsWithError should not report error message if not due an error" )
16451618}
16461619
16471620type PanicsWithErrorWrapper struct {
0 commit comments