Skip to content

Commit

Permalink
Different diff: (+got -want)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankban committed Aug 4, 2023
1 parent 7c937a9 commit 6629340
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
8 changes: 4 additions & 4 deletions checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func (c *equalsChecker) Check(got interface{}, args []interface{}, note func(key
return i != -1 && i < len(s)-1
}
if isMultiLine(got) || isMultiLine(want) {
diff := cmp.Diff(strings.SplitAfter(got, "\n"), strings.SplitAfter(want, "\n"))
note("line diff (-got +want)", Unquoted(diff))
diff := cmp.Diff(strings.SplitAfter(want, "\n"), strings.SplitAfter(got, "\n"))
note("line diff (+got -want)", Unquoted(diff))
}
}
}
Expand Down Expand Up @@ -135,10 +135,10 @@ func (c *cmpEqualsChecker) Check(got interface{}, args []interface{}, note func(
}
}()
want := args[0]
if diff := cmp.Diff(got, want, c.opts...); diff != "" {
if diff := cmp.Diff(want, 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 (+got -want)", Unquoted(diff))
note("got", SuppressedIfLong{got})
note("want", SuppressedIfLong{want})
return ErrSilent
Expand Down
32 changes: 16 additions & 16 deletions checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not equal
line diff (-got +want):
line diff (+got -want):
%s
got:
"a\nlong\nmultiline\nstring"
Expand Down Expand Up @@ -159,7 +159,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not equal
line diff (-got +want):
line diff (+got -want):
%s
got:
"\nfoo"
Expand Down Expand Up @@ -415,7 +415,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (+got -want):
%s
got:
struct { Strings []interface {}; Ints []int }{
Expand All @@ -442,7 +442,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (+got -want):
%s
got:
<suppressed due to length (11 lines), use -v for full output>
Expand All @@ -467,7 +467,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (+got -want):
%s
got:
[]interface {}{
Expand Down Expand Up @@ -501,7 +501,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (+got -want):
%s
got:
<suppressed due to length (11 lines), use -v for full output>
Expand Down Expand Up @@ -533,7 +533,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (+got -want):
%s
got:
[]int{1, 2, 4}
Expand Down Expand Up @@ -608,7 +608,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (+got -want):
%s
got:
s"2012-03-29 00:00:00 +0000 UTC"
Expand Down Expand Up @@ -665,7 +665,7 @@ want args:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (+got -want):
%s
got:
struct { Strings []interface {}; Ints []int }{
Expand All @@ -692,7 +692,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (+got -want):
%s
got:
<suppressed due to length (15 lines), use -v for full output>
Expand All @@ -708,7 +708,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (+got -want):
%s
got:
[]interface {}{
Expand Down Expand Up @@ -878,7 +878,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (+got -want):
%s
got:
[]string{"bad", "wolf"}
Expand Down Expand Up @@ -2721,7 +2721,7 @@ error:
mismatch at index 1
error:
values are not deep equal
diff (-got +want):
diff (+got -want):
%s
got:
[]string{"a", "c"}
Expand Down Expand Up @@ -2947,7 +2947,7 @@ want:
expectedCheckFailure: fmt.Sprintf(`
error:
values are not deep equal
diff (-got +want):
diff (+got -want):
%s
got:
map[string]interface {}{
Expand Down Expand Up @@ -3085,8 +3085,8 @@ func TestCheckers(t *testing.T) {
}
}

func diff(x, y interface{}, opts ...cmp.Option) string {
d := cmp.Diff(x, y, opts...)
func diff(got, want interface{}, 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 @@ -95,25 +95,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,
}}
c.Assert(gotExamples, qt.DeepEquals, wantExamples)
want := `
error:
values are not deep equal
diff (-got +want):
diff (+got -want):
[]*quicktest_test.reportExample{
&{AnInt: 42},
&{AnInt: 47},
Expand All @@ -126,16 +126,16 @@ got:
[]*quicktest_test.reportExample{
&quicktest_test.reportExample{AnInt:42},
&quicktest_test.reportExample{AnInt:47},
&quicktest_test.reportExample{AnInt:1},
&quicktest_test.reportExample{AnInt:2},
&quicktest_test.reportExample{AnInt:1},
&quicktest_test.reportExample{},
}
want:
[]*quicktest_test.reportExample{
&quicktest_test.reportExample{AnInt:42},
&quicktest_test.reportExample{AnInt:47},
&quicktest_test.reportExample{AnInt:2},
&quicktest_test.reportExample{AnInt:1},
&quicktest_test.reportExample{},
&quicktest_test.reportExample{AnInt:2},
}
stack:
$file:112
Expand Down

0 comments on commit 6629340

Please sign in to comment.