testify icon indicating copy to clipboard operation
testify copied to clipboard

Diffs are slightly off for assert.Equal on maps

Open abourget opened this issue 9 years ago • 6 comments

It seems the map is rendered with no trailing , for the last element, so the diff catches that as a modified line.. but really the line isn't modified..

Diff:
            --- Expected
            +++ Actual
            @@ -1,5 +1,7 @@
            -(map[string]interface {}) (len=3) {
            +(map[string]interface {}) (len=5) {
              (string) (len=15) "installed.first": (string) (len=20) "2006-01-02T15:04:05Z",
              (string) (len=14) "installed.last": (string) (len=20) "2006-01-02T15:04:05Z",
            - (string) (len=23) "installed.windows.first": (string) (len=20) "2006-01-02T15:04:05Z"
            + (string) (len=23) "installed.windows.first": (string) (len=20) "2006-01-02T15:04:05Z",
            + (string) (len=22) "installed.windows.last": (string) (len=20) "2006-01-02T15:04:05Z",
            + (string) (len=30) "installed.windows.last_version": (string) (len=3) "8.1"
             }

See how installed.windows.first is different only in the trailing , !

abourget avatar Mar 23 '16 13:03 abourget

thanks @abourget

I'll have to check there's an option in spew to print the trailing comma.

Would you be interested in doing a pull request with the enhancement?

ernesto-jimenez avatar Mar 23 '16 14:03 ernesto-jimenez

yes :) I'll take a look into it...

abourget avatar Mar 24 '16 13:03 abourget

Opened a PR for this in go-spew.

atombender avatar Nov 21 '16 19:11 atombender

I pinged the maintainer about the go-spew PR. If he agrees to merge it then we can close this, otherwise I'll probably go ahead and close it anyway unless someone has a clever idea that will resolve it without changing go-spew.

georgelesica-wf avatar Jan 12 '19 04:01 georgelesica-wf

@georgelesica-wf Have you considered using Litter instead of Spew? We wrote Litter to replace Spew in our tests, as we use a lot of snapshot tests where we store results in files and compare them. Its output is more consistent and more readable, since it's basically just Go.

atombender avatar Jan 12 '19 05:01 atombender

seems that when comparing maps, order matters? is that the issue here?

ghostsquad avatar Jul 22 '22 21:07 ghostsquad