-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/analysis/unitchecker: add test of go vet on std
This change adds a new test that runs go vet on std, using a unitchecker-based tool with (hopefully) the same set of analyzers as the real cmd/vet in GOROOT. This should serve as an early warning when a change to an analyzer causes it to become stricter on std packages. Change-Id: I87503f40ad2d54b928d876216a951ed88b216e58 Reviewed-on: https://go-review.googlesource.com/c/tools/+/493619 Run-TryBot: Alan Donovan <adonovan@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
- Loading branch information
Showing
5 changed files
with
123 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package unitchecker_test | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
|
||
"golang.org/x/tools/go/analysis/passes/asmdecl" | ||
"golang.org/x/tools/go/analysis/passes/assign" | ||
"golang.org/x/tools/go/analysis/passes/atomic" | ||
"golang.org/x/tools/go/analysis/passes/bools" | ||
"golang.org/x/tools/go/analysis/passes/buildtag" | ||
"golang.org/x/tools/go/analysis/passes/cgocall" | ||
"golang.org/x/tools/go/analysis/passes/composite" | ||
"golang.org/x/tools/go/analysis/passes/copylock" | ||
"golang.org/x/tools/go/analysis/passes/directive" | ||
"golang.org/x/tools/go/analysis/passes/errorsas" | ||
"golang.org/x/tools/go/analysis/passes/framepointer" | ||
"golang.org/x/tools/go/analysis/passes/httpresponse" | ||
"golang.org/x/tools/go/analysis/passes/ifaceassert" | ||
"golang.org/x/tools/go/analysis/passes/loopclosure" | ||
"golang.org/x/tools/go/analysis/passes/lostcancel" | ||
"golang.org/x/tools/go/analysis/passes/nilfunc" | ||
"golang.org/x/tools/go/analysis/passes/printf" | ||
"golang.org/x/tools/go/analysis/passes/shift" | ||
"golang.org/x/tools/go/analysis/passes/sigchanyzer" | ||
"golang.org/x/tools/go/analysis/passes/stdmethods" | ||
"golang.org/x/tools/go/analysis/passes/stringintconv" | ||
"golang.org/x/tools/go/analysis/passes/structtag" | ||
"golang.org/x/tools/go/analysis/passes/testinggoroutine" | ||
"golang.org/x/tools/go/analysis/passes/tests" | ||
"golang.org/x/tools/go/analysis/passes/timeformat" | ||
"golang.org/x/tools/go/analysis/passes/unmarshal" | ||
"golang.org/x/tools/go/analysis/passes/unreachable" | ||
"golang.org/x/tools/go/analysis/passes/unusedresult" | ||
"golang.org/x/tools/go/analysis/unitchecker" | ||
) | ||
|
||
// vet is the entrypoint of this executable when ENTRYPOINT=vet. | ||
// Keep consistent with the actual vet in GOROOT/src/cmd/vet/main.go. | ||
func vet() { | ||
unitchecker.Main( | ||
asmdecl.Analyzer, | ||
assign.Analyzer, | ||
atomic.Analyzer, | ||
bools.Analyzer, | ||
buildtag.Analyzer, | ||
cgocall.Analyzer, | ||
composite.Analyzer, | ||
copylock.Analyzer, | ||
directive.Analyzer, | ||
errorsas.Analyzer, | ||
framepointer.Analyzer, | ||
httpresponse.Analyzer, | ||
ifaceassert.Analyzer, | ||
loopclosure.Analyzer, | ||
lostcancel.Analyzer, | ||
nilfunc.Analyzer, | ||
printf.Analyzer, | ||
shift.Analyzer, | ||
sigchanyzer.Analyzer, | ||
stdmethods.Analyzer, | ||
stringintconv.Analyzer, | ||
structtag.Analyzer, | ||
tests.Analyzer, | ||
testinggoroutine.Analyzer, | ||
timeformat.Analyzer, | ||
unmarshal.Analyzer, | ||
unreachable.Analyzer, | ||
// unsafeptr.Analyzer, // currently reports findings in runtime | ||
unusedresult.Analyzer, | ||
) | ||
} | ||
|
||
// TestVetStdlib runs the same analyzers as the actual vet over the | ||
// standard library, using go vet and unitchecker, to ensure that | ||
// there are no findings. | ||
func TestVetStdlib(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping in -short mode") | ||
} | ||
if version := runtime.Version(); !strings.HasPrefix(version, "devel") { | ||
t.Skipf("This test is only wanted on development branches where code can be easily fixed. Skipping because runtime.Version=%q.", version) | ||
} | ||
|
||
cmd := exec.Command("go", "vet", "-vettool="+os.Args[0], "std") | ||
cmd.Env = append(os.Environ(), "ENTRYPOINT=vet") | ||
if out, err := cmd.CombinedOutput(); err != nil { | ||
t.Errorf("go vet std failed (%v):\n%s", err, out) | ||
} | ||
} |