-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/vet: enable fuzz checks in 'tests' analysis pass #46218
Comments
Maybe a dumb question, but can "the |
Could you perhaps elaborate on this one? Do you have a specific pattern in mind? |
@timothy-king Not a dumb question! I don't have an answer to this question though. Possibly? The use of generics might make things easier here as well, but I haven't looked too deeply into this yet.
@zpavlinovic Yes, I'm thinking of something like this:
In the case above,
or
|
All these four checks can be covered by a simple vet checker. My main question is whether this checker mets the frequency requirement. After all, running a malformed target will result in panic, so there may be few malformed targets in the tested code. I am more interested in the bugs that fail "silently", e.g. the expected mutations are not performed. Are there some patterns that are malformed but the related tests won't crash? |
For anyone looking at this later, golang.org/x/tools/go/analysis/passes/tests is a vet analysis that detects problems with tests, examples, and benchmarks, for example, a missing It's probably a good place to check fuzz tests here, rather than defining a new pass. |
@ansaba is going to look at this. Discussed with @timothy-king and we think it makes sense to start by adding this behavior to gopls alone, then migrate it to vet for 1.19, given that we're in the freeze. We're not yet sure the best way to stage this; we could use a separate analyzer, or include it in the tests analyzer hidden behind a flag. |
Submitted review for some of the validations : https://go-review.googlesource.com/c/tools/+/374495 |
Change https://go.dev/cl/374495 mentions this issue: |
The documentation here mentions that fuzz targets have no return values: https://go.dev/doc/fuzz/#glos-fuzz-target However, that (EDIT: it does appear in the docstring, I just missed it) |
Any objection to promoting this to a proposal, so that it can be decided upon for 1.19? We have already started implementing this for gopls, and it would just require a flag-flip to enable it for vet. |
@findleyr, can you say exactly what the implemented check does? Also, there is already a vet 'tests' analysis module. It seems like probably the fuzz target checker should go in there instead of being a separate analysis? Also @ianlancetaylor observes that the 'tests' analysis already does know about fuzz calls, although this appears to be undocumented in 'go tool vet help tests'. (#50198 seems to have been that support?) |
@rsc @ianlancetaylor vet does not yet know about Fuzz tests, because we guarded the new check behind an The additional checks currently implemented are (1) check for a well formed
We plan to additionally verify that the arguments to |
This proposal has been added to the active column of the proposals project |
Thanks, retitled. This sounds fine, especially if you have experience with these working well in gopls. |
Well we don't have much experience yet, as most of our users are not writing fuzz tests. However, I believe the new diagnostics will be helpful, and have ~0 false positives, so they seem worth including in cmd/vet. |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
Change https://go.dev/cl/471295 mentions this issue: |
… for cmd/vet This will remove the flag analysisinternal.DiagnoseFuzzTests created during golang/go#50198.Malformed fuzz target check will be enabled for cmd/vet. For golang/go#46218 Change-Id: I5cc8d685a57060f8dd84c1957f0d296a6205ddb6 Reviewed-on: https://go-review.googlesource.com/c/tools/+/471295 gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Nooras Saba <saba@golang.org>
There are several things that vet can do to support native fuzzing. This issue tracks all of the potential checks that could be added.
Vet should fail if...
f.Add
call don't match the ones inf.Fuzz
f.Fuzz
f.Fuzz
function is missing a*testing.T
as its first parameter*testing.F
method from within thef.Fuzz
functionThe text was updated successfully, but these errors were encountered: