mediocre-go-lib/internal/massert/massert.go

27 lines
567 B
Go
Raw Normal View History

// 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...)
}
}