-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Use go-cmp instead of reflect.DeepEqual #535
Comments
From what I've seen, having used go-cmp to create an assertion, there's no way to make it backwards compatible.
|
advantages of using go-cmp instead of reflect.DeepEqual. result of go-cmp is OK, but result of reflect.DeepEqual is
|
@dsnet might be a good person to loop into this conversation (if they're interested). |
Tried to implement this. |
@posener Do you have that branch around still? |
can push it, nothing to fancy |
If this is merged, we can have |
@posener being able to use |
@ernesto-jimenez another issue here: I guess we are intending also to use the |
I've used my branch in go-cmp and my branch in testify.
Here are the result of the tetify unit-tests: results.txt |
How are you planning on accepting https://godoc.org/github.com/google/go-cmp/cmp#Option to |
Another blocking issue for using go-cmp: google/go-cmp#80. |
@dnephin , I think the main advantage is that it gives more control over comparing: For example, if you want extra control on comparing time objects: ignore timezone or wall time, it could be done in the |
To expand:
The concept of I should note that |
@posener Yes I understand the value of My question was:
If you only apply a static set of So either there needs to be a different function added, or you break compatiblity and add an Options arg. Or is there some other option I'm missing? |
I agree - and we are also breaking API by changing the diff format. |
Rethinking: I see two more options:
|
Another option is to allow overriding default behaviour.
Do the same thing for the Diff function. |
Yet another option: leave the current function as is, to maintain compatibility, and add a new function which uses go-cmp (and takes options, etc). EqualEx or Equivalent or Comparable or something. |
This would also allow fixing issues such as: I have NaNs in structures, and want a comparison that I can use to assert equality, which I can do with go-cmp. |
I have similar problem with floats, in my structures there are floats that cannot be compared just for
What about this option? I can contribute to make it happen. |
Any news on this? |
Any updates? |
found a bad case type Item struct { func main() {
}` want : true , got: fase |
I guess that is ok. |
@allenhaozi I think you are trying or want to assert with |
Of all the options, I think it would make sense to gauge community interest in making a I don't think we can (feasibly) get around the diff output changes without breaking the API and the point about @glesica , thoughts? |
The new go-cmp Reporter option can be used to create custom diff. |
There is already an assertion framework based on So a project like |
When I need advance comparison, I use |
The package
github.com/google/go-cmp
is better suited for comparison in tests thanreflect.DeepEqual
.We should replace our
DeepEqual
usage withgo-cmp
.Replacement should be backwards-compatible.
The text was updated successfully, but these errors were encountered: