]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/test: add 'tests' vet check to 'go test' suite
authorAlan Donovan <adonovan@google.com>
Wed, 20 Sep 2023 18:13:35 +0000 (14:13 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 14 Mar 2024 03:12:27 +0000 (03:12 +0000)
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 golang/go#44251

Change-Id: If5b9dee6d18fa0bc4de7f5f5f549eddeae953fc2
Reviewed-on: https://go-review.googlesource.com/c/go/+/529816
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>

doc/next/3-tools.md
src/cmd/go/alldocs.go
src/cmd/go/internal/test/test.go
src/cmd/go/testdata/script/test_bad_example.txt

index bdbe6c077173d05ac85cc18410702060400f51aa..56d82e4926ece02ea493215211fff55d6db09fe9 100644 (file)
@@ -10,3 +10,12 @@ or copying the `go` binary.
 
 ### Cgo {#cgo}
 
+### Vet
+
+The new `tests` analyzer reports common mistakes in declarations of
+tests, fuzzers, benchmarks, and examples in test packages, such as
+malformed names, wrong signatures, or examples that document
+non-existent identifiers. Some of these mistakes may cause tests not
+to run.
+
+This analyzer is among the subset of analyzers that are run by `go test`.
index dde47ac1b86bb3c66bbd1accd250577e44f4195f..cf3485faac27bd46231ec2bb669e751a3e68b925 100644 (file)
 // finds any problems, go test reports those and does not run the test
 // binary. Only a high-confidence subset of the default go vet checks are
 // used. That subset is: atomic, bool, buildtags, directive, errorsas,
-// ifaceassert, nilfunc, printf, and stringintconv. You can see
+// ifaceassert, nilfunc, printf, stringintconv, and tests. You can see
 // the documentation for these and other vet tests via "go doc cmd/vet".
 // To disable the running of go vet, use the -vet=off flag. To run all
 // checks, use the -vet=all flag.
index f1555fd5d42b7c2b3f270e911d67c614422c5f4e..17dc3a0fdbe059ea132479aa166ec9459eb2edfd 100644 (file)
@@ -79,7 +79,7 @@ and its test source files to identify significant problems. If go vet
 finds any problems, go test reports those and does not run the test
 binary. Only a high-confidence subset of the default go vet checks are
 used. That subset is: atomic, bool, buildtags, directive, errorsas,
-ifaceassert, nilfunc, printf, and stringintconv. You can see
+ifaceassert, nilfunc, printf, stringintconv, and tests. You can see
 the documentation for these and other vet tests via "go doc cmd/vet".
 To disable the running of go vet, use the -vet=off flag. To run all
 checks, use the -vet=all flag.
@@ -667,7 +667,7 @@ var defaultVetFlags = []string{
        "-slog",
        "-stringintconv",
        // "-structtags",
-       // "-tests",
+       "-tests",
        // "-unreachable",
        // "-unsafeptr",
        // "-unusedresult",
index 1d147b663fe62af62ab320b7baa9516a6a14f833..46bc264779e3f869684f84a187de651d39221716 100644 (file)
@@ -1,6 +1,7 @@
 # Tests that invalid examples are ignored.
 # Verifies golang.org/issue/35284
-go test x_test.go
+# Disable vet, as 'tests' analyzer objects to surplus parameter.
+go test -vet=off x_test.go
 
 -- x_test.go --
 package  x
@@ -10,4 +11,4 @@ import "fmt"
 func ExampleThisShouldNotHaveAParameter(thisShouldntExist int) {
        fmt.Println("X")
        // Output:
-}
\ No newline at end of file
+}