-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Replace all the various (-want, +got) styles with a single format #2580
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
Conversation
|
AMAZING |
test/diff/print.go
Outdated
|
|
||
| // Print takes a diff string generated by cmp.Diff and returns it | ||
| // in a consistent format for reuse across all of our tests. | ||
| func Print(diff string) string { |
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.
one detail that might be important to mention the docstring or maybe even in the function name is that this expects that cmp.Diff has been called with the arguments in a specific order (want vs. got)
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.
another option is to wrap cmp.diff entirely and also display the error - if you use https://golang.org/pkg/testing/#B.Helper you'll get very similar functionality to what we have now, e.g. something in the test like
diff.FailIfWantNotGot(tc.expectedTaskSpec, *ts, "Didn't get expected TaskSpec modifications")
And that function would actually call Errorf
This is straying dangerously into non-go-like territory tho, your way is clearer! I think it's clarify vs ease
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.
I did consider wrapping cmp.Diff and I do think that is a very good idea. Two considerations that lead me away from doing that here:
- Some tests use
t.Fatalfwhile others uset.Errorf. So I figured a diff wrapping func would probably need to account for that too. - With an 80 file diff I wanted to do the very minimum to make all the various call sites uniform and limit the amount of review required.
I figure we can write a wrapping func for cmp.Diff in a future PR and then progressively replace cmp.Diff usage, perhaps over the course of multiple PRs? Excellent point about B.Helper, I did not know about it!
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.
I really like the idea of a func with a name that points out the ordering ala ...WantGot(want, got); great idea!
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.
Created #2587 to follow up.
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.
OK, I've updated the PR to use diff.PrintWantGot as the name and I've updated the docstring to make explicit the expectation of ordering.
|
/approve |
|
wow, this is a huge cleanup, its always confusing to remind myself which one means want Build is failing on imports order 😢 : |
|
/lgtm |
Many, many of our tests use cmp.Diff to test whether two objects match. Every time that func gets used the test-writer has to remember to include "(-want, +got)" in the string they print. This is annoying to remember the order and format and can be easily implemented in a helper func instead. This commit introduces a helper func to print diff messages in a consistent way so that test writers dont have to manually type this formatting out every single time.
|
The following is the coverage report on the affected files.
|
In the previous commit a new func for printing consistent diff messages was added as a test helper. This commit updates all locations which use cmp.Diff to also use diff.PrintWantGot when displaying the diff.
|
Thanks for reviewing @pritidesai !
Thank goodness for the Makefile @vdemeester introduced, I ran |
|
The following is the coverage report on the affected files.
|
|
/test pull-tekton-pipeline-integration-tests |
|
Can we have a presubmit check to ensure I don't add a new |
Let's do that in a follow-up 😉 #2594 |
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.
/lgtm
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bobcatfish, vdemeester The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Changes
Many, many of our tests use cmp.Diff to test whether two objects
match. Every time that func gets used the test-writer has to remember
to include "(-want, +got)" in the string they print. This is annoying
to remember the order and format and can be easily implemented in a
helper func instead.
The first commit in this PR introduces a helper func to print diff messages in a
consistent way. This means test writers dont have to manually type
this formatting out every single time. The func is called
diff.PrintWantGot().The second commit in this PR replaces every single place where cmp.Diff output
is printed with a call to
diff.PrintWantGot()so that diff formatting becomes consistenteverywhere.
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide for more details.