-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
x/tools/analysis/passes/tests: report examples with misplaced Output comments #48362
Comments
Also reproduces on the playground: https://play.golang.org/p/0wPM6durES5. |
IMO this is working as intended, the
In your example the |
@ALTree In that case, the broken examples can probably just be addressed by moving the non- |
@ALTree: I agree, but it worries me that this allowed a broken example to be around for 4 years. Interestingly, it only fails this way when there is another comment after the |
@ameowlia I agree that this is behavior that is subtle and hard to catch. What if the testing tool's heuristic was changed to only process |
@smasher164 - I looked into this today (code here). I would like to try to contribute this if others think it is an acceptable solution. The main argument against this fix that I can see is "what happens if an example has multiple output commentblocks"? In that case I would suggest returning the first one and ignoring later ones. Multiple outputs seems like flagrant disregard for the spec. Adding a comment at the end (the issue I reported here) seems like an accident that would be nice to protect against. Alternatively we could add a go/vet warning to make sure that output commentblocks are always the last commentblock. This seems a little heavy handed though. |
Regarding the vet approach, this would at least need to satisfy the requirement of high frequency. It is not clear at the moment how frequent this issue is. Another approach is to perhaps make the documentation more clear. |
Yeah, the bug in x/text/language's example might be a rare exception. Running an Updating the documentation seems like a good option. Right now, testing says
|
I wrote a parser, ran it against this repo, and found one example: #48494. I plan on running it against ❓ @smasher164 - Any advice on how to run against a "corpus of open source code"? |
Change https://golang.org/cl/350995 mentions this issue: |
I typically run tools like that over my I guess nowadays with go modules, I'd run that over the $ find $(go env GOMODCACHE) -type f -name go.mod |
while read fname; do echo "${fname#$(go env GOMODCACHE)/}" |
cut -f1 -d"@"; done |
sort -u |
I think a vet check is the right place to fix this. See |
Move the "TODO" to outside of the function so that the "Output" comment block is the last comment block. Output is only checked when it is the last comment block. See #48362 for this issue. Fixes: #48494 Change-Id: I7a31d7c13710e58fa876c96240a927a9bb8273ad Reviewed-on: https://go-review.googlesource.com/c/go/+/350995 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: David Chase <drchase@google.com>
Good point. I guess we don't need to worry about the frequency of this pattern because we are just extending an existing checker with a simple logic? |
Right, exactly. Just reporting something that was already buggy. |
Output is only checked when it is the last comment block in the testable example. See this golang issue for more info: golang/go#48362
I ended up running the parser against the top 1000 open source golang repos based on stars and I found 5 additional instances of the bug(after removing duplicates from vendoring). @jayconrod - I'll start working on extending the checkExample vet check. Thank you for the point in the right direction. |
@ameowlia Nice finds. I bet there are a lot more out there, too. Thanks for working on this. |
The #1860 pointed out to a bug golang/go#48362 that leads to false positive testable example due to trailing comment. Moreover #918 changed test input without changing the output and that went unnoticed due to this bug. This change removes trailing comment to fix the example. It also removes the test input instead of adding correct output because the input does not match the final implemenation and thus is misleading. Fixes #1860 Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
The #1860 pointed out a bug golang/go#48362 that leads to the false positive testable example caused by a trailing comment. Moreover #918 changed the test input without changing the output and that went unnoticed due to this bug. This change removes trailing comment to fix the example. It also removes the test input instead of adding a correct output because the input syntax is incorrect therefore misleading. Fixes #1860 Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
Change https://golang.org/cl/351553 mentions this issue: |
The #1860 pointed out a bug golang/go#48362 that leads to the false positive testable example caused by a trailing comment. Moreover #918 changed the test input without changing the output and that went unnoticed due to this bug. This change removes trailing comment to fix the example. It also removes the test input instead of adding a correct output because the input syntax is incorrect therefore misleading. Fixes #1860 Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I ran this test in a test file:
What did you expect to see?
The test fail
What did you see instead?
The test passed.
I saw this in a real example with the ExampleMatcher here, which I reported in #48361.
The text was updated successfully, but these errors were encountered: