Skip to content

fix: false positive with test builder pattern #51

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maratori
Copy link

Fixes #50

@kunwardeep kunwardeep requested a review from Copilot June 3, 2025 01:26
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses a false-positive detection in the parallel testing analyzer by recognizing builder-pattern test functions.

  • Introduces new test cases in t_test.go to cover various builder patterns.
  • Refactors analyzeTestRun to use a type switch and explicitly treat call expressions as valid test builders.
  • Adds a *ast.CallExpr case to avoid flagging builder invocations as missing t.Parallel().

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/paralleltest/testdata/src/t/t_test.go Adds TestBuilder with helper builder-pattern functions to test the analyzer’s behavior.
pkg/paralleltest/paralleltest.go Refactors analyzeTestRun to a type switch and adds a *ast.CallExpr branch setting hasParallel.
Comments suppressed due to low confidence (1)

pkg/paralleltest/testdata/src/t/t_test.go:342

  • [nitpick] Using t as the parameter name for a string callback is ambiguous with the outer *testing.T; consider renaming it to something like name or s for clarity.
t.Run("4", testBuilderWithAnotherCallback(func(t string) {

@@ -104,6 +105,8 @@ func (a *parallelAnalyzer) analyzeTestRun(pass *analysis.Pass, n ast.Node, testV
if !foundFunc {
analysis.hasParallel = false
}
case *ast.CallExpr:
analysis.hasParallel = true
Copy link
Preview

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

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

[nitpick] Assuming every call expression implies a parallel builder can mask real missing t.Parallel() calls; consider inspecting the returned function literal or validating the callee identity rather than blanket-marking parallel.

Suggested change
analysis.hasParallel = true
if methodParallelIsCalledInTestFunction(arg, innerTestVar) {
analysis.hasParallel = true
}

Copilot uses AI. Check for mistakes.

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.

False positive with test builder pattern
1 participant