Skip to content

Commit

Permalink
Change diff to (-want +got)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankban committed Mar 1, 2024
1 parent 0b55498 commit b420efb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
8 changes: 4 additions & 4 deletions checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ func (c *equalsChecker[T]) Check(note func(key string, value any)) (err error) {
return i != -1 && i < len(s)-1
}
if isMultiLine(c.got) || isMultiLine(c.want) {
diff := cmp.Diff(strings.SplitAfter(c.got, "\n"), strings.SplitAfter(c.want, "\n"))
note("line diff (-got +want)", Unquoted(diff))
diff := cmp.Diff(strings.SplitAfter(c.want, "\n"), strings.SplitAfter(c.got, "\n"))
note("line diff (-want +got)", Unquoted(diff))
}
}

Expand Down Expand Up @@ -135,10 +135,10 @@ func (c *cmpEqualsChecker[T]) Check(note func(key string, value any)) (err error
err = BadCheckf("%s", r)
}
}()
if diff := cmp.Diff(c.got, c.want, c.opts...); diff != "" {
if diff := cmp.Diff(c.want, c.got, c.opts...); diff != "" {
// Only output values when the verbose flag is set.
note("error", Unquoted("values are not deep equal"))
note("diff (-got +want)", Unquoted(diff))
note("diff (-want +got)", Unquoted(diff))
note("got", SuppressedIfLong{c.got})
note("want", SuppressedIfLong{c.want})
return ErrSilent
Expand Down
30 changes: 15 additions & 15 deletions checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not equal
line diff (-got +want):
line diff (-want +got):
%s
got:
"a\nlong\nmultiline\nstring"
Expand All @@ -161,7 +161,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not equal
line diff (-got +want):
line diff (-want +got):
%s
got:
"\nfoo"
Expand Down Expand Up @@ -341,7 +341,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (-want +got):
%s
got:
qt_test.cmpType{
Expand All @@ -366,7 +366,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (-want +got):
%s
got:
<suppressed due to length (15 lines), use -v for full output>
Expand All @@ -380,7 +380,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (-want +got):
%s
got:
[]interface {}{
Expand Down Expand Up @@ -424,7 +424,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (-want +got):
%s
got:
<suppressed due to length (11 lines), use -v for full output>
Expand All @@ -447,7 +447,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (-want +got):
%s
got:
[]interface {}{
Expand Down Expand Up @@ -479,7 +479,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (-want +got):
%s
got:
<suppressed due to length (11 lines), use -v for full output>
Expand All @@ -503,7 +503,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (-want +got):
%s
got:
[]int{1, 2, 4}
Expand Down Expand Up @@ -567,7 +567,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (-want +got):
%s
got:
s"2012-03-29 00:00:00 +0000 UTC"
Expand Down Expand Up @@ -691,7 +691,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (-want +got):
%s
got:
[]string{"bad", "wolf"}
Expand Down Expand Up @@ -1601,7 +1601,7 @@ error:
mismatch at index 1
error:
values are not deep equal
diff (-got +want):
diff (-want +got):
%s
got:
[]string{"a", "c"}
Expand Down Expand Up @@ -1724,7 +1724,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (-want +got):
%s
got:
map[string]interface {}{
Expand Down Expand Up @@ -1988,8 +1988,8 @@ func TestCheckers(t *testing.T) {
}
}

func diff(x, y any, opts ...cmp.Option) string {
d := cmp.Diff(x, y, opts...)
func diff(got, want any, opts ...cmp.Option) string {
d := cmp.Diff(want, got, opts...)
return strings.TrimSuffix(qt.Prefixf(" ", "%s", d), "\n")
}

Expand Down
20 changes: 10 additions & 10 deletions report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,25 @@ func TestCmpReportOutput(t *testing.T) {
AnInt: 42,
}, {
AnInt: 47,
}, {
AnInt: 1,
}, {
AnInt: 2,
}}
}, {
AnInt: 1,
}, {}}
wantExamples := []*reportExample{{
AnInt: 42,
}, {
AnInt: 47,
}, {
AnInt: 2,
}, {
AnInt: 1,
}, {}}
}, {
AnInt: 2,
}}
qt.Assert(tt, qt.DeepEquals(gotExamples, wantExamples))
want := `
error:
values are not deep equal
diff (-got +want):
diff (-want +got):
[]*qt_test.reportExample{
&{AnInt: 42},
&{AnInt: 47},
Expand All @@ -124,16 +124,16 @@ got:
[]*qt_test.reportExample{
&qt_test.reportExample{AnInt:42},
&qt_test.reportExample{AnInt:47},
&qt_test.reportExample{AnInt:1},
&qt_test.reportExample{AnInt:2},
&qt_test.reportExample{AnInt:1},
&qt_test.reportExample{},
}
want:
[]*qt_test.reportExample{
&qt_test.reportExample{AnInt:42},
&qt_test.reportExample{AnInt:47},
&qt_test.reportExample{AnInt:2},
&qt_test.reportExample{AnInt:1},
&qt_test.reportExample{},
&qt_test.reportExample{AnInt:2},
}
stack:
$file:110
Expand Down

0 comments on commit b420efb

Please sign in to comment.