-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add sorting of map keys and test tweaks #6
Conversation
Removing unnecessary reference to “github.com/go-test/deep” helps testing github forks. It is safe to have the testing a part of the package because *_test.go files only get compiled when `go test` is invoked.
replaced sort.Slice() call with a full blown sort.Interface byStr to make it compatible with older versions of Go
Why sort map keys before comparing them? Also, why make the test part of the pkg? |
|
Please sort the diff result, not the map, please don't make deep mutate the test data. |
@omeid, the patch does exactly this: sorts the diff results before they are passed to the caller. And of course nobody mutates the outside data. |
Here, let me show an example, suppose we have the diffs logged like this:
And suppose also we have hundreds of them. So in order to have some control on what's going on we save the test output to a file and then use the diff program to check what has changed. Like this: But, there is a catch – due to the non-deterministic nature of hash-maps their keys come out in unpredictable order. I.e. next time it could be |
I agree that the output should be deterministic. That's always better. Anyway, I wouldn't make
isn't solid enough. See http://blog.campoy.cat/2014/03/github-and-go-forking-pull-requests-and.html for handling GitHub forks. Then, the 1st and the 3rd commit should be squashed. |
Any movement on this? +100 for sorted deterministic diffs, to allow machine parsing them to validate expectations/spot regressions. |
As of Go 1.12, fmt prints maps in key-sorted order. |
Agreed that deterministic results/output are ideal, especially for testing. Since the Go change @Anaminus mentioned, I think this feature needs to be reimplemented in a new PR. (Also, as @mibk said, deep_test.go does not need to be part of the pkg.) Will close this PR for now, but again: I support the idea. Just need a cleaner, go1.12-aware implementation of it. |
No description provided.