You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The go toolchain will create a cached test file that calls testing.MainStart for all tests, benches, fuzzes and examples if a package contains any tests. When running an analysis.Analyzer on a package that contains tests, this generated file will be passed in pass.Files. Since this is not created by the user, any reports that affect this file cannot be addressed. F.ex. diagnostics from whitespace which is violated in this file.
› go run . ./...
/home/simon/.cache/go-build/90/9008f547841e25259dff735e6c1b3cd00116f6368db052541f1e4fcdb443f56c-d
/home/simon/tmp/analyzer-mre/main.go
/home/simon/tmp/analyzer-mre/main.go
/home/simon/tmp/analyzer-mre/main_test.go
The generated file
This is the generated file (contents of /home/simon/.cache/go-build/90/900...) from the go-build directory which may include violations.
Click to expand
// Code generated by 'go test'. DO NOT EDIT.package main
import (
"os""testing""testing/internal/testdeps"
_ "a"
)
vartests= []testing.InternalTest{
}
varbenchmarks= []testing.InternalBenchmark{
}
varfuzzTargets= []testing.InternalFuzzTarget{
}
varexamples= []testing.InternalExample{
}
funcinit() {
testdeps.ImportPath="a"
}
funcmain() {
m:=testing.MainStart(testdeps.TestDeps{}, tests, benchmarks, fuzzTargets, examples)
os.Exit(m.Run())
}
Additional details
One naive way to address this could be for me to skip files without a .go suffix. However, this is not a reliable solution since if I use the //line directive (put a comment like //line hello.tmpl:1 at the first line of my file) the Filename for the Position will be hello.tmpl. This might be possible to work around by using PositionFor instead but I think a better solution is to not pass the file.
What did you expect to see?
Only code that's not generated by the go toolchain to be analyzed.
What did you see instead?
Code generated and cached in GOCACHE directory being passed to the analyzer.
The text was updated successfully, but these errors were encountered:
gopherbot
added
the
Tools
This label describes issues relating to any tools in the x/tools repository.
label
Nov 28, 2023
Go version
go1.20.1 linux/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
The go toolchain will create a cached test file that calls
testing.MainStart
for all tests, benches, fuzzes and examples if a package contains any tests. When running ananalysis.Analyzer
on a package that contains tests, this generated file will be passed inpass.Files
. Since this is not created by the user, any reports that affect this file cannot be addressed. F.ex. diagnostics from whitespace which is violated in this file.Reproducible example
main.go
main_test.go
package main
Running the code on itself:
› go run . ./... /home/simon/.cache/go-build/90/9008f547841e25259dff735e6c1b3cd00116f6368db052541f1e4fcdb443f56c-d /home/simon/tmp/analyzer-mre/main.go /home/simon/tmp/analyzer-mre/main.go /home/simon/tmp/analyzer-mre/main_test.go
The generated file
This is the generated file (contents of
/home/simon/.cache/go-build/90/900...
) from thego-build
directory which may include violations.Click to expand
Additional details
One naive way to address this could be for me to skip files without a
.go
suffix. However, this is not a reliable solution since if I use the//line
directive (put a comment like//line hello.tmpl:1
at the first line of my file) theFilename
for thePosition
will behello.tmpl
. This might be possible to work around by usingPositionFor
instead but I think a better solution is to not pass the file.What did you expect to see?
Only code that's not generated by the go toolchain to be analyzed.
What did you see instead?
Code generated and cached in
GOCACHE
directory being passed to the analyzer.The text was updated successfully, but these errors were encountered: