Brian Picciano
9567a98606
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.
27 lines
567 B
Go
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...)
|
|
}
|
|
}
|