Skip to content
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

Fix missing detached leading comments #539

Merged
merged 3 commits into from
Nov 17, 2022
Merged

Fix missing detached leading comments #539

merged 3 commits into from
Nov 17, 2022

Conversation

trunghai95
Copy link
Contributor

There's a bug causing the LeadingDetachedComments not copied properly to the source info.

Copy link
Owner

@jhump jhump left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh! Thanks for finding and fixing this. I clearly don't have good enough test coverage in here.

Is this an easy issue to reproduce? If so, it would be great to add a test that reproduces the bug, and then confirm that this change fixes it.

@trunghai95
Copy link
Contributor Author

Doh! Thanks for finding and fixing this. I clearly don't have good enough test coverage in here.

Is this an easy issue to reproduce? If so, it would be great to add a test that reproduces the bug, and then confirm that this change fixes it.

Yes, it is easy to reproduce. It happens every time I trigger Build() from a builder.

I think I can modify TestBuildersFromDescriptors_PreserveComments under builder_test.go to cover this case. Do you have a generator for internal/testprotos/desc_test1.proto? Or should I just manually modify one or some of the elements there?

@jhump
Copy link
Owner

jhump commented Nov 16, 2022

Or should I just manually modify one or some of the elements there?

You can manually modify it, but it might impact other test cases across the repo that use that file. I think it may be better to define a small, minimal file that reproduces the issue and then inline it into the test case. You can compile the source into descriptors using the protoparse package. See the test TestParseAndPrintWithUnrecognizedOptions in the protoprint package as an example.

@trunghai95
Copy link
Contributor Author

Added a test for it. This is the test result before and after the fix.

image

@@ -455,6 +456,109 @@ func TestBuildersFromDescriptors_PreserveComments(t *testing.T) {
testutil.Eq(t, count, descCount)
}

func TestBuilder_PreserveAllCommentsAfterBuild(t *testing.T) {
files := map[string]string{"test.proto": `
syntax = "proto3";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a much bigger example than necessary. Maybe just one enum and value and one message and field?

@jhump jhump merged commit 0facb74 into jhump:master Nov 17, 2022
@jhump
Copy link
Owner

jhump commented Nov 17, 2022

Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants