11package goassert
22
33import (
4+ "reflect"
45 "testing"
56)
67
@@ -38,7 +39,7 @@ func NotPanic(t testing.TB, underTest func()) {
3839Asserts that the given function panics with the specified error.
3940The actual error must be of the same type and value as the given error
4041*/
41- func PanicWithError [K comparable ](t testing.TB , expectedError K , underTest func ()) {
42+ func PanicWithError [T any ](t testing.TB , expectedError T , underTest func ()) {
4243 t .Helper ()
4344
4445 defer func () {
@@ -48,15 +49,8 @@ func PanicWithError[K comparable](t testing.TB, expectedError K, underTest func(
4849 return
4950 }
5051
51- error , converted := r .(K )
52- if converted {
53- Equal (t , expectedError , error )
54- } else {
55- t .Errorf (
56- "Panic threw an unexpected error type. Expected Type: %T. Actual Type: %T" ,
57- expectedError ,
58- r ,
59- )
52+ if ! reflect .DeepEqual (expectedError , r ) {
53+ t .Errorf ("Expected panic with %v error but got %v error" , expectedError , r )
6054 }
6155 }()
6256
@@ -67,7 +61,7 @@ func PanicWithError[K comparable](t testing.TB, expectedError K, underTest func(
6761Asserts that the given function does not panic with the specified error.
6862The assertion succeeds if the given function does not panic or panics with a different error
6963*/
70- func NotPanicWithError [K comparable ](t testing.TB , expectedError K , underTest func ()) {
64+ func NotPanicWithError [T any ](t testing.TB , expectedError T , underTest func ()) {
7165 t .Helper ()
7266
7367 defer func () {
@@ -76,9 +70,8 @@ func NotPanicWithError[K comparable](t testing.TB, expectedError K, underTest fu
7670 return
7771 }
7872
79- error , converted := r .(K )
80- if converted {
81- NotEqual (t , expectedError , error )
73+ if reflect .DeepEqual (expectedError , r ) {
74+ t .Errorf ("Expected panic with different error than %v error" , expectedError )
8275 }
8376 }()
8477
0 commit comments