diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/test/helpers.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/test/helpers.go b/internal/test/helpers.go index a93aa9e..fc52074 100644 --- a/internal/test/helpers.go +++ b/internal/test/helpers.go @@ -19,6 +19,27 @@ func AssertEqual[V any](t *testing.T, actual, expected V) { t.Errorf("expected %#v, but got %#v", expected, actual) } +func AssertErrorEqual(t *testing.T, actual error, expected string) { + t.Helper() + if actual == nil { + t.Errorf("expected err = %q, but got nil", expected) + } else if actual.Error() != expected { + t.Errorf("expected err = %q, but got %q", expected, actual.Error()) + } +} + +func AssertPanics(t *testing.T, action func()) (recovered any) { + t.Helper() + defer func() { + recovered = recover() + if recovered == nil { + t.Error("action did not panic as expected") + } + }() + action() + return +} + func PointerTo[V any](value V) *V { return &value } |
