-
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/go/analysis/passes/testinggoroutine: do not ignore calls in goroutines (false negative) #63849
Comments
Thanks. We discussed this in triage: This could be done (via two passes over the package), but might not be worth the complexity. Seems like a low priority. |
Change https://go.dev/cl/541155 mentions this issue: |
This adds support for t.Run() statements. The new version performs two passes. The first pass collects all of the `go callee` and `t.Run(name, callee)` statements. The second pass inspects each callee FuncDecl or FuncLit for a call to a tb.Forbidden() function. When the enclosing callee function called from an t.Run() statement, it reports when tb is declared outside of the body of the enclosing function. Fixes golang/go#63799 Updates golang/go#63849 Updates golang/go#48124 Change-Id: I10d5f2a0af9b985126dbfcc98eaab97757a7f71d Reviewed-on: https://go-review.googlesource.com/c/tools/+/541155 TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Tim King <taking@google.com>
I found back this old issue, and found there was something made about this issue with 1733061 The code is still there The commit only refers to "Updates #63849" it's not about fixing it. So I'm curious, what did this commit was about in the context on this issue. I'm asking because apparently the issue is still there (status open) and I can replicate the issue in the code. Thanks |
Maybe here is the difference This is detected via changes made with 1733061 func TestSomething(t *testing.T) {
go fail(t)
}
func fail(tb *testing.T) {
tb.Helper()
tb.FailNow()
} This is not detected func TestSomething(t *testing.T) {
go func() {
fail(t)
}()
}
func fail(tb *testing.T) {
tb.Helper()
tb.FailNow()
} The second pattern (also the exact one reported in the example of this issue) is obviously the most frequent |
As you correctly point out, this example is not yet handled. So the issue has not yet been closed. FWIW the first pattern is simpler to detect. If someone wants to contribute an extension to the checker to detect the second that is sufficiently accurate, performant, etc, they can contribute PR. |
The text was updated successfully, but these errors were encountered: