-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/tools/go/analysis/analysistest: add module-aware analyzer test runners #53063
Comments
See also #37054. People have been complaining for a while, that was the first issue I found. |
I think it is fine to extend analysistest for modules mode. I want to understand what a "module-aware analyzer" is though. |
What I mean by module-aware analyzer is simply an analyzer that can operate on the package layout in Go Modules mode (not GOPATH mode). I think including But I think users can always build a package-to- |
@romaindoumenc This discussion is not only about making analysistest load packages with module mode (the code path was already mentioned in the original report), but also making the loaded packages and their modules accessible. |
Change https://go.dev/cl/577995 mentions this issue: |
Adds a new package testfiles to help write tests around go files and directories. These are especially helpful when dealing with go.mod files. Adds a new CopyTestFiles function that copies a directory and removes the ".test" file extension, e.g. "go.mod.test" becomes "go.mod". This allows for easily creating analysistests with go.mod files. This change also adds a new TestDir helper to extract to a temporary directory. Consolidates txtar usage around ExtractTxtar, which writes a txtar archive to a directory, and adds a convenience helper TestTxtar that extracts a txtar at a path to a temporary directory. Updates golang/go#61336 Updates golang/go#53063 Updates golang/go#46041 Updates golang/go#37054 Change-Id: I09210f751bbc6ac3f01c34fba22b7e8fa1ddf93f Reviewed-on: https://go-review.googlesource.com/c/tools/+/577995 Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
What I want to achieve
I want to write tests for analyzers that utilize
packages.Module
information.x/tools/go/analysis/analysistest
provides helper functions for testinggo/analysis
analyzers.Run
andRunWithSuggestedFixes
internally callgo/packages.Load
but explicitly in GOPATH mode.dir
is supposed to be GOPATH, which doesn't apply in module mode.packages.Config
is not accepted.These limit the utility of the package when authoring module-aware analyzers.
What I propose
I propose to add module-friendly test helpers. Something like:
or
Alternatives to consider
GOPATH style project layout is easy and convenient. For the last half decade, nobody
complained about this issue, which indicates supporting module mode in this package is not
important. My analyzer is not a typical one.
So I considered -
Refactor and move the core of
x/tools/go/analysis/analysistest
tox/tools/internal/analysisinternal/...
. Unfortunately, I see this will cause move ofx/tools/go/analysis/internal/checker
andanalysisflags
. I like containinganalysis
specific internal logic under x/tools/go/analysis/internal and am not sure about this big move.Make part of
analysistest.Run
available through a var inx/tools/internal/analysisinternal/...
that's set by analysistest init. See CL408375 This is a smaller change than 2, but documentation for the type aliasedanalysistest.Testing
andchecker.TestAnalyzerResult
isn't great.What about
WriteFiles
It also supports only GOPATH mode.
WriteFiles
can be potentially replaced withgo/packages/packagestest
.But for a simple analyzer test, this is more convenient than the helpers in
go/packages/packagestest
.cc @golang/tools-team
The text was updated successfully, but these errors were encountered: