Skip to content

Commit

Permalink
Merge pull request #154 from lmb/cmp-equal-bad-checkf
Browse files Browse the repository at this point in the history
Turn a panicking cmp.Diff into a bad check
  • Loading branch information
frankban committed Apr 11, 2023
2 parents 6a0f8ad + 636ce19 commit 9a0c242
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (c *cmpEqualsChecker) Check(got interface{}, args []interface{}, note func(
// structs with unexported fields and neither AllowUnexported nor
// cmpopts.IgnoreUnexported are provided.
if r := recover(); r != nil {
err = fmt.Errorf("%s", r)
err = BadCheckf("%s", r)
}
}()
want := args[0]
Expand Down
12 changes: 7 additions & 5 deletions checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,15 @@ want:
},
expectedCheckFailure: `
error:
cannot handle unexported field at root.answer:
bad check: cannot handle unexported field at root.answer:
"github.com/frankban/quicktest_test".(struct { answer int })
consider using a custom Comparer; if you control the implementation of type, you can also consider using an Exporter, AllowUnexported, or cmpopts.IgnoreUnexported
`,
expectedNegateFailure: `
error:
bad check: cannot handle unexported field at root.answer:
"github.com/frankban/quicktest_test".(struct { answer int })
consider using a custom Comparer; if you control the implementation of type, you can also consider using an Exporter, AllowUnexported, or cmpopts.IgnoreUnexported
got:
struct { answer int }{answer:42}
want:
<same as "got">
`,
}, {
about: "CmpEquals: structs with unexported fields ignored",
Expand Down

0 comments on commit 9a0c242

Please sign in to comment.