-
Notifications
You must be signed in to change notification settings - Fork 195
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
add a test for default-gen output #55
add a test for default-gen output #55
Conversation
@mbohlool could you help review it? Thanks. |
examples/defaulter-gen/Makefile
Outdated
fi | ||
@go build -o /tmp/$(TOOL) | ||
@PKGS=$$(go list ./output_tests/... | paste -sd' '); \ | ||
/tmp/$(TOOL) --logtostderr --v=6 -i $$(echo $$PKGS | sed 's/ /,/g') -O zz_generated |
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.
so the paste command above is adding space between package names and sed here convert those spaces to comma, right? why not just use paste -sd','
?
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 copy-pasted it from https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/authorization/v1/types.go#L27. I can update both if you think it's necessary.
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.
The link is referring to the wrong file? Anyway I think you can just fix it here if you like. It is not necessary though.
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.
@@ -0,0 +1,22 @@ | |||
/* |
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.
Why do you want the generated file to be buildable? is the test only making sure that the output is what we expecting?
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.
The travis builds the entire repo.
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 can try to change .travis but that's more nasty IMHO :)
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.
In that case, I suggest you rename the expected file zz_generated.go to zz_generated.expected, add the name zz_generated.go to git_ignore of that folder, and do a diff zz_generated.expected zz_generated.go
instead of git diff ...
.
29bd77c
to
483cca9
Compare
@mbohlool updated, ptal. Thanks! |
LGTM |
But it look like travis is still compiling it :( maybe remove the file after you checked the diff? |
483cca9
to
b289754
Compare
fi | ||
@go build -o /tmp/$(TOOL) | ||
/tmp/$(TOOL) --logtostderr --v=6 -i ./output_tests/wholepkg -O zz_generated | ||
@if ! diff -q ./output_tests/wholepkg/zz_generated.expected ./output_tests/wholepkg/zz_generated.go; then \ |
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.
why is this different than https://github.com/kubernetes/gengo/blob/master/examples/deepcopy-gen/Makefile#L11 ?
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.
The generated code depends on apimachinery so it does not compile and fails travis. So i changed the suffix to .expected.
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.
Why does this exist? The library has a --verify-only option specifically so that we would not write things like this any more.
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.
We can change the default-gen Makefile to use --verify-only in a follow-up PR.
For this PR, because the generated code does not compile and breaks travis, i need to change the suffix of the output file to .expected, so the --verify-only approach doesn't work.
To use --verify-only, we have two options:
- vendor a mock apimachinery folder in the test package to make the code compile.
- hack the .travis to ignore this package.
@lavalamp please let me know how you want me to proceed. Thanks.
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.
blech wrt having external deps. OK. Can you comment that?
The point of checking it in is so that a human can look at a series of trivial output tests, and comprehend the output. --verify-only doesn't give me that?
} | ||
|
||
// No defaulter will be generated | ||
type Stuct_No_Field_Has_Manual_Defaulter struct { |
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.
s/Stuct/Struct/g
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.
Fixed.
b289754
to
e0660ff
Compare
--verify-only tells you that the checked-in thing is still indeed what the
generator would output.
…On Wed, May 17, 2017 at 10:19 PM, Tim Hockin ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In examples/defaulter-gen/Makefile
<#55 (comment)>:
> @@ -0,0 +1,15 @@
+TOOL=defaulter-gen
+
+test:
+ @if ! git diff --quiet HEAD; then \
+ echo "FAIL: git client is not clean"; \
+ false; \
+ fi
+ @go build -o /tmp/$(TOOL)
+ /tmp/$(TOOL) --logtostderr --v=6 -i ./output_tests/wholepkg -O zz_generated
+ @if ! diff -q ./output_tests/wholepkg/zz_generated.expected ./output_tests/wholepkg/zz_generated.go; then \
blech wrt having external deps. OK. Can you comment that?
The point of checking it in is so that a human can look at a series of
trivial output tests, and comprehend the output. --verify-only doesn't give
me that?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#55 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAngljpLfmvjHoq5Slw08iwYheiUnHkiks5r69TwgaJpZM4NZ3KJ>
.
|
In the deepcopy case, we regenerate and `git diff` which makes it easy for
people to produce the thing they need to check in.
In this case, it doesn't compile (we need to fix that, sigh...) so the same
trick doesn't work. We need a simple way for anyone hacking to regen that
code for submit.
On Wed, May 17, 2017 at 10:22 PM, Daniel Smith <notifications@github.com>
wrote:
… --verify-only tells you that the checked-in thing is still indeed what the
generator would output.
On Wed, May 17, 2017 at 10:19 PM, Tim Hockin ***@***.***>
wrote:
> ***@***.**** commented on this pull request.
> ------------------------------
>
> In examples/defaulter-gen/Makefile
> <#55 (comment)>:
>
> > @@ -0,0 +1,15 @@
> +TOOL=defaulter-gen
> +
> +test:
> + @if ! git diff --quiet HEAD; then \
> + echo "FAIL: git client is not clean"; \
> + false; \
> + fi
> + @go build -o /tmp/$(TOOL)
> + /tmp/$(TOOL) --logtostderr --v=6 -i ./output_tests/wholepkg -O
zz_generated
> + @if ! diff -q ./output_tests/wholepkg/zz_generated.expected
./output_tests/wholepkg/zz_generated.go; then \
>
> blech wrt having external deps. OK. Can you comment that?
>
> The point of checking it in is so that a human can look at a series of
> trivial output tests, and comprehend the output. --verify-only doesn't
give
> me that?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#55 (comment)>, or
mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/
AAngljpLfmvjHoq5Slw08iwYheiUnHkiks5r69TwgaJpZM4NZ3KJ>
> .
>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#55 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFVgVDo7a3KzsrlasRIq9wYdwZmcRFBSks5r69WogaJpZM4NZ3KJ>
.
|
How about split to 'make all' and 'make verify'? I still need to bypass the compile issue, how about the "vendor a mock apimachinery package" trick? |
I disagree with this strategy for tests. Being able to check in a different test output to pass the test make it easier for people to bypass tests and don't look at the change before checking in. When people forced to fix test cases manually it more likely for them to spot a problem vs just run the test and check in the diff. (I am arguing this only for test, for production generated code, easier to check in is better). |
@mbohlool i think it's fine as long as the difference of the generated code is shown in the PR and gets reviewed, so I agree with @thockin here. @thockin How about split to 'make' to 'make all' and 'make verify', and use the '--verify-only' flag when run 'make verify'? I still need to bypass the compile issue, how about the "vendor a mock apimachinery package" trick? |
I don't care much - I just want it to fail in an obvious way so humans can
examine the changes.
…On Thu, May 18, 2017 at 2:22 PM, Chao Xu ***@***.***> wrote:
@mbohlool <https://github.com/mbohlool> i think it's fine as long as the
difference of the generated code is shown in the PR and gets reviewed, so I
agree with @thockin <https://github.com/thockin> here.
@thockin <https://github.com/thockin> How about split to 'make' to 'make
all' and 'make verify', and use the '--verify-only' flag when run 'make
verify'?
I still need to bypass the compile issue, how about the "vendor a mock
apimachinery package" trick?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#55 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFVgVLlsTnOrKF3pddylYeuGPQSjaY9Qks5r7LaLgaJpZM4NZ3KJ>
.
|
cc @lavalamp @thockin