-
Notifications
You must be signed in to change notification settings - Fork 50
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
Port node
package tests to quicktest
#289
Conversation
455a5ca
to
e507a61
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work!
By the way, you might want to encode those "shorter qt expression" nits as sed lines, so you can automatically apply those cleanups throughout your PRs.
// If a datamodel.Node is the expected value, a full deep qt.Equals is used as normal. | ||
var closeEnough = &closeEnoughChecker{} | ||
|
||
var _ qt.Checker = (*closeEnoughChecker)(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clever :) I like how this turned out, even if implementing a custom checker with quicktest is slightly more verbose.
you could almost use qt.CmpEquals with https://pkg.go.dev/github.com/google/go-cmp/cmp#Comparer here, except that Comparer expects func(T, T) bool
, so it only kicks in when the two types being compared are exactly equal. The logic here is different, as it is more flexible.
node/tests/testcase.go
Outdated
Wish(t, err, ShouldEqual, nil) | ||
Wish(t, datamodel.DeepEqual(n, n3), ShouldEqual, true) | ||
qt.Check(t, err, qt.Equals, nil) | ||
qt.Check(t, datamodel.DeepEqual(n, n3), qt.Equals, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mental TODO: in the future, we might be able to expose datamodel.DeepEqual as a go-cmp Comparer. Definitely out of scope for this refactor, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One could also use the printer
package and then do string diff on the results.
That would simultaneously be very complete, and produce very readable debugable output, and also happily ignore the actual node implementation strategy (which is usually what we want).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quicktest
comes with CmpEquals
which looks pretty flexible; I wonder if we could use that here?
I'll add a TODO in code for this so that we don't forget :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is what I was alluding to. But you need a custom comparer, because by default, CmpEquals will just loop infinitely. This is because bindnode ipld.Node implementations contain schema types, which have cyclic pointers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally arrived there via the flat datamodel.DeepEqual, which works, but also doesn't give good errors. I think either a custom go-cmp comparer, or comparing encoded versions like "printer" or "dagjson" like Eric mentions, would work better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, not sure if you're aware, but qt.Check does a t.Error, whereas qt.Assert does a t.Fatal. I think in general we want the latter. For example:
If you use
|
Thank you for pointing that out @mvdan; I interpreted tests as Do you think the behaviour of tests should change? |
If you did that intentionally, then SGTM. Keeping existing behavior is better for the sake of a smooth refactor. I was bringing it up in case it flew under your radar. |
Thank you; I intentionally wanted to keep changes as net-zero as possible |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Wow, we have a lot of tests!)
Nice. It'll be great to have one fewer testing system in the dependency tree by the end of this (and the similar PRs).
e507a61
to
dd0d978
Compare
Port the tests in `node` package to quicktest; use: - `qt.Assert` for `wish.Require` - `qt.Check` for `wish.Wish` - `qt.IsTrue` for ShouldEqual` over `true` - `qt.IsFalse` for ShouldEqual` over `false` - `qt.IsNil` for ShouldEqual` over `nil` Port `closeEnough` Wish checker to its equivalent in quicktest. Relates to: - #219
dd0d978
to
b7e83a3
Compare
Port the tests in
node
package to quicktest; use:qt.Assert
forwish.Require
qt.Check
forwish.Wish
qt.IsTrue
for ShouldEqualover
true`qt.IsFalse
forShouldEqual
overfalse
qt.IsNil
forShouldEqual
overnil
Port
closeEnough
Wish checker to its equivalent in quicktest.Relates to: