-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/vet: check for improper use of t.Run and t.Parallel #18106
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
Comments
What is the frequency with which this occurs? |
this is just one possible manifest of
https://golang.org/doc/faq#closures_and_goroutines. If we can do a generic
vet check for all occurrences, then it's fine. But I don't think checking
only this single case is appropriate.
|
For the record it just happened to us at Social Point. Maybe a rule in https://github.com/dominikh/go-staticcheck would make it too if in vet is not possible. cc/ @dominikh |
#16520 is the generalization of this. This is marked as NeedsDecision but really it needs a concrete proposal of what gets checked and how, and an argument for why that will have approximately no false positives. |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
Just found this via search. For the record, this landed as #55972. |
Consider the following test:
Without the
name := name
line to capture the name variable, the subtest will execute with the wrong values as the testdata. Worst yet, the tests will run with the correct names, but the wrong data, completely misleading the user that the test is executing as expected.The blog on subtests explicitly warns that this must be done:
I propose that vet check for this mis-use. One possible algorithm:
t.Parallel
is called within at.Run
t.Run
following thet.Parallel
references a variable scoped to therange
of some outer loop (i.e., not captured)\cc @dominikh
The text was updated successfully, but these errors were encountered: