Skip to content

Commit

Permalink
bug: go1.17 support
Browse files Browse the repository at this point in the history
Fuzzing tests are introduced in go1.18. When linter runs on older go runtime, it's ok, that testing.F is not found.

Disable f-checks if testing.F not found.
  • Loading branch information
kulti committed May 22, 2022
1 parent 3c02d20 commit 1ed2e86
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 54 deletions.
29 changes: 29 additions & 0 deletions pkg/analyzer/analyzer.go
Expand Up @@ -262,6 +262,35 @@ func (t thelper) buildTestCheckFuncOpts(pass *analysis.Pass, ctxType types.Type)
}, true
}

func (t thelper) buildFuzzCheckFuncOpts(pass *analysis.Pass, ctxType types.Type) (checkFuncOpts, bool) {
fObj := analysisutil.ObjectOf(pass, "testing", "F")
if fObj == nil {
return checkFuncOpts{}, true // fuzzing supports since go1.18, it's ok, that testig.F is missed.
}

fHelper, _, _ := types.LookupFieldOrMethod(fObj.Type(), true, fObj.Pkg(), "Helper")
if fHelper == nil {
return checkFuncOpts{}, false
}

tFuzz, _, _ := types.LookupFieldOrMethod(fObj.Type(), true, fObj.Pkg(), "Fuzz")
if tFuzz == nil {
return checkFuncOpts{}, false
}

return checkFuncOpts{
skipPrefix: "Fuzz",
varName: "f",
fnHelper: fHelper,
subRun: tFuzz,
hpType: types.NewPointer(fObj.Type()),
ctxType: ctxType,
checkBegin: t.enabledChecks.Enabled(checkFBegin),
checkFirst: t.enabledChecks.Enabled(checkFFirst),
checkName: t.enabledChecks.Enabled(checkFName),
}, true
}

func (t thelper) buildBenchmarkCheckFuncOpts(pass *analysis.Pass, ctxType types.Type) (checkFuncOpts, bool) {
bObj := analysisutil.ObjectOf(pass, "testing", "B")
if bObj == nil {
Expand Down
14 changes: 0 additions & 14 deletions pkg/analyzer/analyzer_go117.go

This file was deleted.

40 changes: 0 additions & 40 deletions pkg/analyzer/analyzer_go118.go

This file was deleted.

0 comments on commit 1ed2e86

Please sign in to comment.