From be80b6d20489a7de10d5a81657e6bc89f2120680 Mon Sep 17 00:00:00 2001 From: robinknaapen Date: Fri, 12 Jun 2020 17:54:35 +0200 Subject: [PATCH] Add NCmp --- assert.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/assert.go b/assert.go index 6c762c3..b89a5f2 100644 --- a/assert.go +++ b/assert.go @@ -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) +}