-
-
Notifications
You must be signed in to change notification settings - Fork 7
Add EqualsWithNaN
to testutil
#3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= | ||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import ( | |
"github.com/davecgh/go-spew/spew" | ||
"github.com/efficientgo/core/errors" | ||
"github.com/efficientgo/core/testutil/internal" | ||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
// Assert fails the test if the condition is false. | ||
|
@@ -76,6 +77,33 @@ func Equals(tb testing.TB, exp, act interface{}, v ...interface{}) { | |
tb.Fatal(sprintfWithLimit("\033[31m%s:%d:"+msg+"\n\n\texp: %#v\n\n\tgot: %#v%s\033[39m\n\n", filepath.Base(file), line, exp, act, diff(exp, act))) | ||
} | ||
|
||
type goCmp struct { | ||
opts cmp.Options | ||
} | ||
|
||
// WithGoCmp allows specifying options and using https://github.com/google/go-cmp | ||
// for equality comparisons. The compatibility guarantee of this function's arguments | ||
// are the same as go-cmp i.e none due to v0.x. | ||
func WithGoCmp(opts ...cmp.Option) goCmp { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's also mention in the comment that compatibility guarantee for this function arguments is same as go-cmp, so... zero as it is at version 0.x. It's fine, but let's just mention it in comment |
||
return goCmp{opts: opts} | ||
} | ||
|
||
// Equals uses go-cmp for comparing equality between two structs, and can be used with | ||
// various options defined in go-cmp/cmp and go-cmp/cmp/cmpopts. | ||
func (o goCmp) Equals(tb testing.TB, exp, act interface{}, v ...interface{}) { | ||
tb.Helper() | ||
if cmp.Equal(exp, act, o.opts) { | ||
return | ||
} | ||
_, file, line, _ := runtime.Caller(1) | ||
|
||
var msg string | ||
if len(v) > 0 { | ||
msg = fmt.Sprintf(v[0].(string), v[1:]...) | ||
} | ||
tb.Fatal(sprintfWithLimit("\033[31m%s:%d:"+msg+"\n\n\texp: %#v\n\n\tgot: %#v%s\033[39m\n\n", filepath.Base(file), line, exp, act, diff(exp, act))) | ||
} | ||
|
||
// FaultOrPanicToErr returns error if panic of fault was triggered during execution of function. | ||
func FaultOrPanicToErr(f func()) (err error) { | ||
// Set this go routine to panic on segfault to allow asserting on those. | ||
|
Uh oh!
There was an error while loading. Please reload this page.