assert.Same: add type names to fail message#1056
Closed
egawata wants to merge 1 commit intostretchr:masterfrom
Closed
assert.Same: add type names to fail message#1056egawata wants to merge 1 commit intostretchr:masterfrom
egawata wants to merge 1 commit intostretchr:masterfrom
Conversation
Collaborator
|
|
| return Fail(t, fmt.Sprintf("Not same: \n"+ | ||
| "expected: %p %#v\n"+ | ||
| "actual : %p %#v", expected, expected, actual, actual), msgAndArgs...) | ||
| "expected: %p %#v (%T)\n"+ |
Collaborator
There was a problem hiding this comment.
This format string is quite sensitive to the types used and sometimes duplicates details.
It's quite surprising that %#v formats MemberPtr(&Member{"Niko", 18}) as &Member{Name:"Niko", Age:18}
We need to include %T and %p, probably (%T)(%p) is the most conventional?
Contributor
Author
|
Thank you for comments. 😃 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a type names of testing values to a fail message of
assert.Same().Changes
Adds type names of testing values to a fail message of
assert.Same(), which might be necessary to identify the cause of failing.Motivation
Currently, when
assert.Same()fails, it outputs a message with pointer values and its go-syntax representation ofactual/expectedvalues.assert.Same()would fail when types of two values are different. The following test code would fail:However, it seems no difference between
actualandexpectedin its fail message, because they point to the same object. It would be hard to know why the test fails from this message.This PR adds type names of two values. The output would be like this:
Related issues