Closed
Description
Currently there is no driver suitable for running analyzers from a go test (or from code, in general). The multichecker and singlechecker drivers are meant for cli tools and call os.Exit(), so they cannot be used.
We want to be able to run analysis from a go test rather than a separate binary. It is easier to integrate into our CI system if is a normal test.
My first thought was something that looks like this:
func Run(args []string, analyzers []*analysis.Analyzer) ([]analysis.Diagnostic, error)
Returning Diagnostic is not quite right though since the user doesn't have the FileSet to translate the diagnostics' token.Pos. I also assume something would have to be done for passing analyzer flags programatically.
/cc @ianthehat since you responded briefly in Slack regarding this feature request
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
matloob commentedon Jun 6, 2019
Hi, could you provide more information about your use case?
Are you trying to test analyses or are you trying to create a test that runs analyses on other packages in your project?
muirdm commentedon Jun 6, 2019
The latter: trying to run analyzers against packages in our project via a go test. I tweaked the title to deemphasize the test part since I know it is confusing.
[-]x/tools/go/analysis: provide driver for running analysis in test[/-][+]x/tools/go/analysis: provide driver for running analysis programmatically[/+]mikesep commentedon Jun 6, 2019
I'm interested in a similar use case. I'm working on a tool to run my Analyzer against packages to gather information, after which I'll want to do some final overall analysis on the collected data and output a report.
fatih commentedon Jun 7, 2019
I just recently stumbled into the same problem. I wanted to run a long running service and not use any of the drivers (i.e:
singlechecker
) as those abstract more than I want.matloob commentedon Jun 19, 2019
I think the best way to move forward on this is to add such a library in an external package (outside of tools) and let it bake a little. I don't think there's anything (other than the obvious visibility and accessibility to potential users) that requires this to be in tools.
Once it's used more and we're happy with it we can move it back to tools.
On a related note, it would be nice if we had some sort of playground with fewer stability requirements than tools to do experiments in. As it is now once we add anything it's pretty much there forever and we can't make any changes.....
gopherbot commentedon Jun 14, 2022
Change https://go.dev/cl/411907 mentions this issue:
go/analysis/checker: a go/packages-based driver library
go/analysis/checker: a go/packages-based driver library
go/analysis/checker: a go/packages-based driver library
10 remaining items