Add NCmp
This commit is contained in:
parent
0ead6dfb99
commit
121a4e740a
@ -156,6 +156,7 @@ func (a Assert) SameElements(expected, actual interface{}, msg ...interface{}) {
|
||||
a.f(false, msg, ``)
|
||||
}
|
||||
|
||||
// Cmp assert wrapper for go-cmp
|
||||
func (a Assert) Cmp(expected, actual interface{}, opts ...cmp.Option) {
|
||||
a.t.Helper()
|
||||
diff := cmp.Diff(expected, actual, opts...)
|
||||
@ -165,3 +166,11 @@ func (a Assert) Cmp(expected, actual interface{}, opts ...cmp.Option) {
|
||||
|
||||
a.f(false, nil, "\n"+diff)
|
||||
}
|
||||
|
||||
// NCmp assert wrapper for go-cmp but fails when !Equal
|
||||
func (a Assert) NCmp(expected, actual interface{}, opts ...cmp.Option) {
|
||||
a.t.Helper()
|
||||
|
||||
ok := cmp.Equal(expected, actual, opts...)
|
||||
a.f(!ok, nil, `Should not be %#v, but it is`, expected)
|
||||
}
|
||||
|
@ -177,3 +177,18 @@ func TestCmpTimezones(t *testing.T) {
|
||||
fa.Cmp(&A{ti}, &A{ti2})
|
||||
assert.True(ft.GotError())
|
||||
}
|
||||
|
||||
func TestNCmp(t *testing.T) {
|
||||
assert := New(t)
|
||||
ft, fa := newFakeT()
|
||||
|
||||
type A struct {
|
||||
S string
|
||||
}
|
||||
|
||||
fa.NCmp(A{"not"}, A{"equal"})
|
||||
assert.False(ft.GotError())
|
||||
|
||||
fa.NCmp(A{"equal"}, A{"equal"})
|
||||
assert.True(ft.GotError())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user