aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/kunwardeep
diff options
context:
space:
mode:
authordependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2024-03-04 17:40:11 +0000
committerTaras Madan <tarasmadan@google.com>2024-03-04 18:34:55 +0000
commit5fc5366972c874b919f93165bb4ed4e2bcb7c350 (patch)
tree287c3361a0dee0c72af80d9a1a66714a06e98a62 /vendor/github.com/kunwardeep
parent1be5ce38a9059c356eb193a8c34d60d61c9fc31f (diff)
mod: bump github.com/golangci/golangci-lint from 1.55.2 to 1.56.2
Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.55.2 to 1.56.2. - [Release notes](https://github.com/golangci/golangci-lint/releases) - [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md) - [Commits](https://github.com/golangci/golangci-lint/compare/v1.55.2...v1.56.2) --- updated-dependencies: - dependency-name: github.com/golangci/golangci-lint dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
Diffstat (limited to 'vendor/github.com/kunwardeep')
-rw-r--r--vendor/github.com/kunwardeep/paralleltest/pkg/paralleltest/paralleltest.go55
1 files changed, 42 insertions, 13 deletions
diff --git a/vendor/github.com/kunwardeep/paralleltest/pkg/paralleltest/paralleltest.go b/vendor/github.com/kunwardeep/paralleltest/pkg/paralleltest/paralleltest.go
index e21f278cf..1aecc1a51 100644
--- a/vendor/github.com/kunwardeep/paralleltest/pkg/paralleltest/paralleltest.go
+++ b/vendor/github.com/kunwardeep/paralleltest/pkg/paralleltest/paralleltest.go
@@ -54,8 +54,10 @@ func (a *parallelAnalyzer) run(pass *analysis.Pass) (interface{}, error) {
inspector.Preorder(nodeFilter, func(node ast.Node) {
funcDecl := node.(*ast.FuncDecl)
var funcHasParallelMethod,
+ funcCantParallelMethod,
rangeStatementOverTestCasesExists,
- rangeStatementHasParallelMethod bool
+ rangeStatementHasParallelMethod,
+ rangeStatementCantParallelMethod bool
var loopVariableUsedInRun *string
var numberOfTestRun int
var positionOfTestRunNode []ast.Node
@@ -77,20 +79,29 @@ func (a *parallelAnalyzer) run(pass *analysis.Pass) (interface{}, error) {
funcHasParallelMethod = methodParallelIsCalledInTestFunction(n, testVar)
}
+ // Check if the test calls t.Setenv, cannot be used in parallel tests or tests with parallel ancestors
+ if !funcCantParallelMethod {
+ funcCantParallelMethod = methodSetenvIsCalledInTestFunction(n, testVar)
+ }
+
// Check if the t.Run within the test function is calling t.Parallel
if methodRunIsCalledInTestFunction(n, testVar) {
// n is a call to t.Run; find out the name of the subtest's *testing.T parameter.
innerTestVar := getRunCallbackParameterName(n)
hasParallel := false
+ cantParallel := false
numberOfTestRun++
ast.Inspect(v, func(p ast.Node) bool {
if !hasParallel {
hasParallel = methodParallelIsCalledInTestFunction(p, innerTestVar)
}
+ if !cantParallel {
+ cantParallel = methodSetenvIsCalledInTestFunction(p, innerTestVar)
+ }
return true
})
- if !hasParallel {
+ if !hasParallel && !cantParallel {
positionOfTestRunNode = append(positionOfTestRunNode, n)
}
}
@@ -122,6 +133,10 @@ func (a *parallelAnalyzer) run(pass *analysis.Pass) (interface{}, error) {
rangeStatementHasParallelMethod = methodParallelIsCalledInMethodRun(r.X, innerTestVar)
}
+ if !rangeStatementCantParallelMethod {
+ rangeStatementCantParallelMethod = methodSetenvIsCalledInMethodRun(r.X, innerTestVar)
+ }
+
if loopVariableUsedInRun == nil {
if run, ok := r.X.(*ast.CallExpr); ok {
loopVariableUsedInRun = loopVarReferencedInRun(run, loopVars, pass.TypesInfo)
@@ -134,12 +149,17 @@ func (a *parallelAnalyzer) run(pass *analysis.Pass) (interface{}, error) {
}
}
- if !a.ignoreMissing && !funcHasParallelMethod {
+ // Descendents which call Setenv, also prevent tests from calling Parallel
+ if rangeStatementCantParallelMethod {
+ funcCantParallelMethod = true
+ }
+
+ if !a.ignoreMissing && !funcHasParallelMethod && !funcCantParallelMethod {
pass.Reportf(node.Pos(), "Function %s missing the call to method parallel\n", funcDecl.Name.Name)
}
if rangeStatementOverTestCasesExists && rangeNode != nil {
- if !rangeStatementHasParallelMethod {
+ if !rangeStatementHasParallelMethod && !rangeStatementCantParallelMethod {
if !a.ignoreMissing && !a.ignoreMissingSubtests {
pass.Reportf(rangeNode.Pos(), "Range statement for test %s missing the call to method parallel in test Run\n", funcDecl.Name.Name)
}
@@ -162,15 +182,23 @@ func (a *parallelAnalyzer) run(pass *analysis.Pass) (interface{}, error) {
}
func methodParallelIsCalledInMethodRun(node ast.Node, testVar string) bool {
- var methodParallelCalled bool
+ return targetMethodIsCalledInMethodRun(node, testVar, "Parallel")
+}
+
+func methodSetenvIsCalledInMethodRun(node ast.Node, testVar string) bool {
+ return targetMethodIsCalledInMethodRun(node, testVar, "Setenv")
+}
+
+func targetMethodIsCalledInMethodRun(node ast.Node, testVar, targetMethod string) bool {
+ var called bool
// nolint: gocritic
switch callExp := node.(type) {
case *ast.CallExpr:
for _, arg := range callExp.Args {
- if !methodParallelCalled {
+ if !called {
ast.Inspect(arg, func(n ast.Node) bool {
- if !methodParallelCalled {
- methodParallelCalled = methodParallelIsCalledInRunMethod(n, testVar)
+ if !called {
+ called = exprCallHasMethod(n, testVar, targetMethod)
return true
}
return false
@@ -178,11 +206,7 @@ func methodParallelIsCalledInMethodRun(node ast.Node, testVar string) bool {
}
}
}
- return methodParallelCalled
-}
-
-func methodParallelIsCalledInRunMethod(node ast.Node, testVar string) bool {
- return exprCallHasMethod(node, testVar, "Parallel")
+ return called
}
func methodParallelIsCalledInTestFunction(node ast.Node, testVar string) bool {
@@ -196,6 +220,11 @@ func methodRunIsCalledInRangeStatement(node ast.Node, testVar string) bool {
func methodRunIsCalledInTestFunction(node ast.Node, testVar string) bool {
return exprCallHasMethod(node, testVar, "Run")
}
+
+func methodSetenvIsCalledInTestFunction(node ast.Node, testVar string) bool {
+ return exprCallHasMethod(node, testVar, "Setenv")
+}
+
func exprCallHasMethod(node ast.Node, receiverName, methodName string) bool {
// nolint: gocritic
switch n := node.(type) {