Skip to content

Commit

Permalink
go/analysis/internal/checker: add -test flag for single/multi-checkers
Browse files Browse the repository at this point in the history
Like `go list -test`, allow users to control inclusion/exclusion of test files.
Default is to include test files.

Change-Id: I1af3077f087089ad2201571b4a2f781d936d0102
Reviewed-on: https://go-review.googlesource.com/c/tools/+/410365
Reviewed-by: Alan Donovan <[email protected]>
  • Loading branch information
hyangah committed Jun 6, 2022
1 parent 43cce67 commit 2417911
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion go/analysis/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ var (
// Log files for optional performance tracing.
CPUProfile, MemProfile, Trace string

// IncludeTests indicates whether test files should be analyzed too.
IncludeTests = true

// Fix determines whether to apply all suggested fixes.
Fix bool
)
Expand All @@ -65,6 +68,7 @@ func RegisterFlags() {
flag.StringVar(&CPUProfile, "cpuprofile", "", "write CPU profile to this file")
flag.StringVar(&MemProfile, "memprofile", "", "write memory profile to this file")
flag.StringVar(&Trace, "trace", "", "write trace log to this file")
flag.BoolVar(&IncludeTests, "test", IncludeTests, "indicates whether test files should be analyzed, too")

flag.BoolVar(&Fix, "fix", false, "apply all suggested fixes")
}
Expand Down Expand Up @@ -163,7 +167,7 @@ func load(patterns []string, allSyntax bool) ([]*packages.Package, error) {
}
conf := packages.Config{
Mode: mode,
Tests: true,
Tests: IncludeTests,
}
initial, err := packages.Load(&conf, patterns...)
if err == nil {
Expand Down

0 comments on commit 2417911

Please sign in to comment.