Repository navigation
cmd/go: vet ignores custom tools’ -test=false flag #81598
Description
A custom analysis tool built with golang.org/x/tools/go/analysis/singlechecker advertises and accepts -test=false, but go vet still loads and analyzes test files. The same tool honors the option when invoked directly.
Reproduced on linux/arm64 in Docker with Go built from 89066c7:
go version go1.28-devel_89066c7425 Fri Sep 18 10:09:44 2026 -0700 linux/arm64
Using golang.org/x/tools v0.45.0, create these files:
// vettool/main.go
package main
import (
"golang.org/x/tools/go/analysis/passes/printf"
"golang.org/x/tools/go/analysis/singlechecker"
)
func main() { singlechecker.Main(printf.Analyzer) }// p.go
package p// p_test.go
package p
import "fmt"
func bad() { fmt.Printf("%d", "wrong") }Then run:
go mod init example.com/repro
go get golang.org/x/tools/go/analysis/singlechecker@v0.45.0
go build -o printfcheck ./vettool
go vet -vettool=./printfcheck -test=false .Expected: no diagnostics from p_test.go. Actual:
p_test.go:5:26: fmt.Printf format %d has arg "wrong" of wrong type string
Invoking ./printfcheck -test=false . succeeds without diagnostics.
The flag is discovered and forwarded by cmd/go, but cmd/go unconditionally sets ModResolveTests and calls TestPackagesFor. Singlechecker dispatches the resulting .cfg file to unitchecker, bypassing the standalone package loader that applies -test. This also means unresolved test-only imports can fail the command despite -test=false.
This was reported downstream in google/gvisor#8596 in 2023. Adin identified the driver interaction and suggested standalone invocation as a workaround. I could not find an existing Go issue for it.
A local cmd/go change applies the advertised boolean flag before package loading; a script regression fails before the change and passes after it. The flag-discovery protocol does not distinguish driver flags from analyzer flags, so treating other tools' boolean flags named test as package-selection flags is a compatibility consideration for this approach.
Assisted-by: Codex
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTodo
Activity
gopherbot commentedon Sep 18, 2026
Change https://go.dev/cl/835045 mentions this issue:
cmd/go: honor custom vet tools' -test flagcherrymui commentedon Sep 18, 2026
cc @adonovan @matloob