-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable using Stringer/error interfaces for diffing #895
Conversation
I think this change makes sense but am I correct in thinking that we're now delegating our own test output format to Given that the result of our test assertions are definitely a key feature/purpose of this framework, would it make more sense to rather update our formatting output to match `spew's or, at the least, version-lock our spew dependency? |
@boyan-soubachov we were always delegating it to I think maintaining a formatter as part of I do agree with you that the failure messages that |
`spew`'s default formatter will call `String()` or `Error()` in structs that implement the `fmt.Stringer` or `error` interfaces. Depending on the implementation of those, the diff can become quite useless to read (see the example struct I used for the test case in this commit). This changes `spew`'s configuration to `DisableMethods` so that it will always use it's own pretty printer. This makes testing structs less surprising and generally more useful, without tying the tests to the implementation of `String()` (the user here can always chose to `require.Equal(a.String(), b.String())` if testing those is important to them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! 👍 Thank you for your contribution.
@glesica , would you like to give this PR a once-over?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems very reasonable to me. Thanks for the contribution!
Summary: - github.com/stretchr/testify: @commit afd4130c14595c7d37c067f8c883f2b5ec2227e2 (from master) - github.com/stretchr/objx: @commit 477a77ecc69700c7cdeb1fa9e129548e1c1c393c (from v0.1.1) - gopkg.in/yaml.v2: not updated - github.com/pmezard/go-difflib: not updated This bump includes a lot of changes that were between the previous commit of `testify` we vendored (be8372ae8ec5c6daaed3cc28ebf73c54b737c240). It also includes a new change from this [pull-request](stretchr/testify#895) to make failure messages more consistent (especially useful for`proto.Message`s). Test Plan: Changes -> we should make sure we're running all go tests that use testify. GitOrigin-RevId: e88b2e1e997f7ec25df772c27524f17e10b185bc
See #989 |
Fix: #1072 |
This should have exported the spew config to make this configurable, even if it changed the default. Proposing |
NOTE: this changes something that is the default behavior. I intentionally am doing this as a proposal to change that behavior because I think the new one is better. If this is a problem, we could also achieve the goal of this PR by making
spewConfig
somewhat accessible so that the user of the library can choose toDisableMethods
themselves.spew
's default formatter will callString()
orError()
in structsthat implement the
fmt.Stringer
orerror
interfaces. Depending onthe implementation of those, the diff can become quite useless to read
(see the example struct I used for the test case in this commit).
This changes
spew
's configuration toDisableMethods
so that it willalways use it's own pretty printer. This makes testing structs less
surprising and generally more useful, without tying the tests to the
implementation of
String()
(the user here can always choose torequire.Equal(a.String(), b.String())
if testing those is important tothem.