Skip to content

Commit f1d6050

Browse files
adonovangopherbot
authored andcommitted
cmd/go/internal/test: add 'tests' vet check to 'go test' suite
The tests analyser reports structural problems in test declarations. Presumably most of these would be caught by go test itself, which compiles and runs (some subset of) the tests, but Benchmark and Fuzz functions are executed less frequently and may benefit more from static checks. Also, reflect the change in go test help message. + release note Fixes #44251 Change-Id: If5b9dee6d18fa0bc4de7f5f5f549eddeae953fc2 Reviewed-on: https://go-review.googlesource.com/c/go/+/529816 Reviewed-by: Ian Lance Taylor <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Alan Donovan <[email protected]>
1 parent 6133c1e commit f1d6050

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

doc/next/3-tools.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ or copying the `go` binary.
1010

1111
### Cgo {#cgo}
1212

13+
### Vet
14+
15+
The new `tests` analyzer reports common mistakes in declarations of
16+
tests, fuzzers, benchmarks, and examples in test packages, such as
17+
malformed names, wrong signatures, or examples that document
18+
non-existent identifiers. Some of these mistakes may cause tests not
19+
to run.
20+
21+
This analyzer is among the subset of analyzers that are run by `go test`.

src/cmd/go/alldocs.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/test/test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ and its test source files to identify significant problems. If go vet
7979
finds any problems, go test reports those and does not run the test
8080
binary. Only a high-confidence subset of the default go vet checks are
8181
used. That subset is: atomic, bool, buildtags, directive, errorsas,
82-
ifaceassert, nilfunc, printf, and stringintconv. You can see
82+
ifaceassert, nilfunc, printf, stringintconv, and tests. You can see
8383
the documentation for these and other vet tests via "go doc cmd/vet".
8484
To disable the running of go vet, use the -vet=off flag. To run all
8585
checks, use the -vet=all flag.
@@ -667,7 +667,7 @@ var defaultVetFlags = []string{
667667
"-slog",
668668
"-stringintconv",
669669
// "-structtags",
670-
// "-tests",
670+
"-tests",
671671
// "-unreachable",
672672
// "-unsafeptr",
673673
// "-unusedresult",
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Tests that invalid examples are ignored.
22
# Verifies golang.org/issue/35284
3-
go test x_test.go
3+
# Disable vet, as 'tests' analyzer objects to surplus parameter.
4+
go test -vet=off x_test.go
45

56
-- x_test.go --
67
package x
@@ -10,4 +11,4 @@ import "fmt"
1011
func ExampleThisShouldNotHaveAParameter(thisShouldntExist int) {
1112
fmt.Println("X")
1213
// Output:
13-
}
14+
}

0 commit comments

Comments
 (0)