mediocre-go-lib/internal/massert/massert.go
Brian Picciano 9567a98606 Move massert into internal, and simplify it a lot
The previous massert isn't that useful compared to testify, but it's
nice to have some assertion helpers in the repo which don't require a
sub-dependency.
2023-12-26 16:27:41 +01:00

27 lines
567 B
Go

// massert helper assertion methods for tests.
package massert
import (
"reflect"
"testing"
)
// Equal fatals if reflect.DeepEqual fails.
func Equal[T any](t testing.TB, want, got T) {
t.Helper()
if !reflect.DeepEqual(want, got) {
t.Fatalf("%#v != %#v", want, got)
}
}
// Equalf is like Equal but extra formatting is appended.
func Equalf[T any](
t testing.TB, want, got T, fmtStr string, fmtArgs ...any,
) {
t.Helper()
if !reflect.DeepEqual(want, got) {
fmtArgs = append([]any{want, got}, fmtArgs...)
t.Fatalf("%#v != %#v "+fmtStr, fmtArgs...)
}
}