go/analysis/passes/tests: enable fuzz checks in 'tests' analysis pass for cmd/vet
This will remove the flag analysisinternal.DiagnoseFuzzTests created during golang/go#50198.Malformed fuzz target check will be enabled for cmd/vet.
For golang/go#46218
Change-Id: I5cc8d685a57060f8dd84c1957f0d296a6205ddb6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/471295
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Nooras Saba <saba@golang.org>
diff --git a/go/analysis/passes/tests/doc.go b/go/analysis/passes/tests/doc.go
index 9421de4..3ae27db 100644
--- a/go/analysis/passes/tests/doc.go
+++ b/go/analysis/passes/tests/doc.go
@@ -9,7 +9,7 @@
//
// tests: check for common mistaken usages of tests and examples
//
-// The tests checker walks Test, Benchmark and Example functions checking
+// The tests checker walks Test, Benchmark, Fuzzing and Example functions checking
// malformed names, wrong signatures and examples documenting non-existent
// identifiers.
//
diff --git a/go/analysis/passes/tests/tests.go b/go/analysis/passes/tests/tests.go
index fbacc6e..9589a46 100644
--- a/go/analysis/passes/tests/tests.go
+++ b/go/analysis/passes/tests/tests.go
@@ -17,7 +17,6 @@
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
- "golang.org/x/tools/internal/analysisinternal"
"golang.org/x/tools/internal/typeparams"
)
@@ -68,9 +67,7 @@
checkTest(pass, fn, "Test")
case strings.HasPrefix(fn.Name.Name, "Benchmark"):
checkTest(pass, fn, "Benchmark")
- }
- // run fuzz tests diagnostics only for 1.18 i.e. when analysisinternal.DiagnoseFuzzTests is turned on.
- if strings.HasPrefix(fn.Name.Name, "Fuzz") && analysisinternal.DiagnoseFuzzTests {
+ case strings.HasPrefix(fn.Name.Name, "Fuzz"):
checkTest(pass, fn, "Fuzz")
checkFuzz(pass, fn)
}
diff --git a/go/analysis/passes/tests/tests_test.go b/go/analysis/passes/tests/tests_test.go
index b0b09dd..740adc5 100644
--- a/go/analysis/passes/tests/tests_test.go
+++ b/go/analysis/passes/tests/tests_test.go
@@ -7,21 +7,12 @@
import (
"testing"
- "golang.org/x/tools/internal/analysisinternal"
-
"golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/go/analysis/passes/tests"
"golang.org/x/tools/internal/typeparams"
)
func Test(t *testing.T) {
- // In 1.18, diagnostic for Fuzz Tests must not be used by cmd/vet.
- // So the code for Fuzz tests diagnostics is guarded behind flag analysisinternal.DiagnoseFuzzTests
- // Turn on the flag DiagnoseFuzzTests for analysis tests and then turn it off.
- analysisinternal.DiagnoseFuzzTests = true
- defer func() {
- analysisinternal.DiagnoseFuzzTests = false
- }()
testdata := analysistest.TestData()
pkgs := []string{
"a", // loads "a", "a [a.test]", and "a.test"
diff --git a/gopls/doc/analyzers.md b/gopls/doc/analyzers.md
index b56f4dd..2717108 100644
--- a/gopls/doc/analyzers.md
+++ b/gopls/doc/analyzers.md
@@ -554,7 +554,7 @@
check for common mistaken usages of tests and examples
-The tests checker walks Test, Benchmark and Example functions checking
+The tests checker walks Test, Benchmark, Fuzzing and Example functions checking
malformed names, wrong signatures and examples documenting non-existent
identifiers.
diff --git a/gopls/internal/lsp/source/api_json.go b/gopls/internal/lsp/source/api_json.go
index 1399e87..7863915 100644
--- a/gopls/internal/lsp/source/api_json.go
+++ b/gopls/internal/lsp/source/api_json.go
@@ -363,7 +363,7 @@
},
{
Name: "\"tests\"",
- Doc: "check for common mistaken usages of tests and examples\n\nThe tests checker walks Test, Benchmark and Example functions checking\nmalformed names, wrong signatures and examples documenting non-existent\nidentifiers.\n\nPlease see the documentation for package testing in golang.org/pkg/testing\nfor the conventions that are enforced for Tests, Benchmarks, and Examples.",
+ Doc: "check for common mistaken usages of tests and examples\n\nThe tests checker walks Test, Benchmark, Fuzzing and Example functions checking\nmalformed names, wrong signatures and examples documenting non-existent\nidentifiers.\n\nPlease see the documentation for package testing in golang.org/pkg/testing\nfor the conventions that are enforced for Tests, Benchmarks, and Examples.",
Default: "true",
},
{
@@ -1037,7 +1037,7 @@
},
{
Name: "tests",
- Doc: "check for common mistaken usages of tests and examples\n\nThe tests checker walks Test, Benchmark and Example functions checking\nmalformed names, wrong signatures and examples documenting non-existent\nidentifiers.\n\nPlease see the documentation for package testing in golang.org/pkg/testing\nfor the conventions that are enforced for Tests, Benchmarks, and Examples.",
+ Doc: "check for common mistaken usages of tests and examples\n\nThe tests checker walks Test, Benchmark, Fuzzing and Example functions checking\nmalformed names, wrong signatures and examples documenting non-existent\nidentifiers.\n\nPlease see the documentation for package testing in golang.org/pkg/testing\nfor the conventions that are enforced for Tests, Benchmarks, and Examples.",
URL: "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/tests",
Default: true,
},
diff --git a/gopls/main.go b/gopls/main.go
index 02657e9..41c7cdb 100644
--- a/gopls/main.go
+++ b/gopls/main.go
@@ -19,15 +19,10 @@
"golang.org/x/tools/gopls/internal/hooks"
"golang.org/x/tools/gopls/internal/lsp/cmd"
- "golang.org/x/tools/internal/analysisinternal"
"golang.org/x/tools/internal/tool"
)
func main() {
- // In 1.18, diagnostics for Fuzz tests must not be used by cmd/vet.
- // So the code for Fuzz tests diagnostics is guarded behind flag analysisinternal.DiagnoseFuzzTests
- // Turn on analysisinternal.DiagnoseFuzzTests for gopls
- analysisinternal.DiagnoseFuzzTests = true
ctx := context.Background()
tool.Main(ctx, cmd.New("gopls", "", nil, hooks.Options), os.Args[1:])
}
diff --git a/internal/analysisinternal/analysis.go b/internal/analysisinternal/analysis.go
index d15f0eb..8948ecc 100644
--- a/internal/analysisinternal/analysis.go
+++ b/internal/analysisinternal/analysis.go
@@ -15,10 +15,6 @@
"strconv"
)
-// DiagnoseFuzzTests controls whether the 'tests' analyzer diagnoses fuzz tests
-// in Go 1.18+.
-var DiagnoseFuzzTests bool = false
-
func TypeErrorEndPos(fset *token.FileSet, src []byte, start token.Pos) token.Pos {
// Get the end position for the type error.
offset, end := fset.PositionFor(start, false).Offset, start