@@ -1587,30 +1587,43 @@ func TestPanicsWithValue(t *testing.T) {
1587
1587
func TestPanicsWithError (t * testing.T ) {
1588
1588
t .Parallel ()
1589
1589
1590
- mockT := new (testing.T )
1591
-
1592
- if ! PanicsWithError (mockT , "panic" , func () {
1590
+ mockT := new (captureTestingT )
1591
+ succeeded := PanicsWithError (mockT , "panic" , func () {
1593
1592
panic (errors .New ("panic" ))
1594
- }) {
1595
- t .Error ("PanicsWithError should return true" )
1596
- }
1593
+ })
1594
+ mockT .checkResultAndErrMsg (t , true , succeeded , "" )
1597
1595
1598
- if PanicsWithError (mockT , "Panic!" , func () {
1599
- }) {
1600
- t .Error ("PanicsWithError should return false" )
1601
- }
1596
+ succeeded = PanicsWithError (mockT , "Panic!" , func () {})
1597
+ Equal (t , false , succeeded , "PanicsWithError should return false" )
1598
+ Contains (t , mockT .msg , "Panic value:\t <nil>" )
1602
1599
1603
- if PanicsWithError (mockT , "at the disco " , func () {
1604
- panic (errors .New ("panic" ))
1605
- }) {
1606
- t . Error ( "PanicsWithError should return false" )
1607
- }
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"` )
1608
1605
1609
- if PanicsWithError (mockT , "Panic!" , func () {
1610
- panic ("panic" )
1611
- }) {
1612
- t .Error ("PanicsWithError should return false" )
1613
- }
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"` )
1611
+
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" )
1618
+ }
1619
+
1620
+ type PanicsWithErrorWrapper struct {
1621
+ Prefix string
1622
+ Err error
1623
+ }
1624
+
1625
+ func (e PanicsWithErrorWrapper ) Error () string {
1626
+ return e .Prefix + ": " + e .Err .Error ()
1614
1627
}
1615
1628
1616
1629
func TestNotPanics (t * testing.T ) {
0 commit comments