Skip to content

Commit f4e613e

Browse files
ansabagopherbot
authored andcommitted
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Findley <[email protected]> Auto-Submit: Nooras Saba‎ <[email protected]>
1 parent 6546e8e commit f4e613e

File tree

7 files changed

+5
-26
lines changed

7 files changed

+5
-26
lines changed

go/analysis/passes/tests/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
// tests: check for common mistaken usages of tests and examples
1111
//
12-
// The tests checker walks Test, Benchmark and Example functions checking
12+
// The tests checker walks Test, Benchmark, Fuzzing and Example functions checking
1313
// malformed names, wrong signatures and examples documenting non-existent
1414
// identifiers.
1515
//

go/analysis/passes/tests/tests.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717

1818
"golang.org/x/tools/go/analysis"
1919
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
20-
"golang.org/x/tools/internal/analysisinternal"
2120
"golang.org/x/tools/internal/typeparams"
2221
)
2322

@@ -68,9 +67,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
6867
checkTest(pass, fn, "Test")
6968
case strings.HasPrefix(fn.Name.Name, "Benchmark"):
7069
checkTest(pass, fn, "Benchmark")
71-
}
72-
// run fuzz tests diagnostics only for 1.18 i.e. when analysisinternal.DiagnoseFuzzTests is turned on.
73-
if strings.HasPrefix(fn.Name.Name, "Fuzz") && analysisinternal.DiagnoseFuzzTests {
70+
case strings.HasPrefix(fn.Name.Name, "Fuzz"):
7471
checkTest(pass, fn, "Fuzz")
7572
checkFuzz(pass, fn)
7673
}

go/analysis/passes/tests/tests_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,12 @@ package tests_test
77
import (
88
"testing"
99

10-
"golang.org/x/tools/internal/analysisinternal"
11-
1210
"golang.org/x/tools/go/analysis/analysistest"
1311
"golang.org/x/tools/go/analysis/passes/tests"
1412
"golang.org/x/tools/internal/typeparams"
1513
)
1614

1715
func Test(t *testing.T) {
18-
// In 1.18, diagnostic for Fuzz Tests must not be used by cmd/vet.
19-
// So the code for Fuzz tests diagnostics is guarded behind flag analysisinternal.DiagnoseFuzzTests
20-
// Turn on the flag DiagnoseFuzzTests for analysis tests and then turn it off.
21-
analysisinternal.DiagnoseFuzzTests = true
22-
defer func() {
23-
analysisinternal.DiagnoseFuzzTests = false
24-
}()
2516
testdata := analysistest.TestData()
2617
pkgs := []string{
2718
"a", // loads "a", "a [a.test]", and "a.test"

gopls/doc/analyzers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ started by the test. For example:
554554

555555
check for common mistaken usages of tests and examples
556556

557-
The tests checker walks Test, Benchmark and Example functions checking
557+
The tests checker walks Test, Benchmark, Fuzzing and Example functions checking
558558
malformed names, wrong signatures and examples documenting non-existent
559559
identifiers.
560560

gopls/internal/lsp/source/api_json.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gopls/main.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@ import (
1919

2020
"golang.org/x/tools/gopls/internal/hooks"
2121
"golang.org/x/tools/gopls/internal/lsp/cmd"
22-
"golang.org/x/tools/internal/analysisinternal"
2322
"golang.org/x/tools/internal/tool"
2423
)
2524

2625
func main() {
27-
// In 1.18, diagnostics for Fuzz tests must not be used by cmd/vet.
28-
// So the code for Fuzz tests diagnostics is guarded behind flag analysisinternal.DiagnoseFuzzTests
29-
// Turn on analysisinternal.DiagnoseFuzzTests for gopls
30-
analysisinternal.DiagnoseFuzzTests = true
3126
ctx := context.Background()
3227
tool.Main(ctx, cmd.New("gopls", "", nil, hooks.Options), os.Args[1:])
3328
}

internal/analysisinternal/analysis.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ import (
1515
"strconv"
1616
)
1717

18-
// DiagnoseFuzzTests controls whether the 'tests' analyzer diagnoses fuzz tests
19-
// in Go 1.18+.
20-
var DiagnoseFuzzTests bool = false
21-
2218
func TypeErrorEndPos(fset *token.FileSet, src []byte, start token.Pos) token.Pos {
2319
// Get the end position for the type error.
2420
offset, end := fset.PositionFor(start, false).Offset, start

0 commit comments

Comments
 (0)