akshayjshah / attest

Type-safe assertion helpers for Go
https://pkg.go.dev/go.akshayshah.org/attest
MIT License
15 stars 2 forks source link

display diff in reverse #4

Closed komuw closed 2 years ago

komuw commented 2 years ago

If you have a program like (https://go.dev/play/p/6gWHICoz0xd):

got := "hello"
want := "hell"
attest.Equal(t, got, want)

and you run it, you get a diff like:

    prog.go:12: got != want
        diff (+got, -want):
          string(
        -   "hell",
        +   "hello",
          )

In attest all the functions like Equal take got as the first argument and then want. So I would expect that when it comes to displaying the diff, it would follow the same order. ie, got is displayed first and then want.
However the diff displays the want first(in the example above; - "hell",)

akshayjshah commented 2 years ago

Hi @komuw! Sorry for the delay, I was on vacation for a bit.

cmp.Diff takes its arguments in the opposite order. The printed diff in your example is correct: compared to the expected result, you're missing "hell" and have "hello" instead.

komuw commented 2 years ago

I was talking about the order(or sequence). The signature of attest.Equal is;

attest.Equal(t, got, want)
                ^      ^
       got is first    want is second

and in the failure message;

diff (+got, -want):
        ^      ^
 got is first  want is second

and in the diff;

string(- "hell", + "hello", )
           ^         ^
want is first got is second

so in the diff, the sequence is flipped: want comes first

But it is a minor thing and I'm happy to close this.

Thanks for the awesome library!