@@ -240,12 +240,11 @@ func RunWithSuggestedFixes(t Testing, dir string, a *analysis.Analyzer, patterns
240
240
return r
241
241
}
242
242
243
- // Run applies an analysis to the packages denoted by the "go list" patterns.
243
+ // RunModule applies an analysis to the packages denoted by the "go list" patterns.
244
244
//
245
- // It loads the packages from the specified GOPATH-style project
246
- // directory using golang.org/x/tools/go/packages, runs the analysis on
247
- // them, and checks that each analysis emits the expected diagnostics
248
- // and facts specified by the contents of '// want ...' comments in the
245
+ // It loads the packages from the module using golang.org/x/tools/go/packages,
246
+ // runs the analysis on them, and checks that each analysis emits the expected
247
+ // diagnostics and facts specified by the contents of '// want ...' comments in the
249
248
// package's source files. It treats a comment of the form
250
249
// "//...// want..." or "/*...// want... */" as if it starts at 'want'
251
250
//
@@ -278,7 +277,7 @@ func RunWithSuggestedFixes(t Testing, dir string, a *analysis.Analyzer, patterns
278
277
// Run also returns a Result for each package for which analysis was
279
278
// attempted, even if unsuccessful. It is safe for a test to ignore all
280
279
// the results, but a test may use it to perform additional checks.
281
- func Run (t Testing , dir string , a * analysis.Analyzer , patterns ... string ) []* Result {
280
+ func RunModule (t Testing , dir string , a * analysis.Analyzer , patterns ... string ) []* Result {
282
281
if t , ok := t .(testing.TB ); ok {
283
282
testenv .NeedsGoPackages (t )
284
283
}
@@ -300,12 +299,20 @@ func Run(t Testing, dir string, a *analysis.Analyzer, patterns ...string) []*Res
300
299
return results
301
300
}
302
301
302
+ // Run applies an analysis to the packages denoted by the "go list" patterns.
303
+ // It performs the same analysis as [RunModule], but uses GOPATH instead.
304
+ func Run (t Testing , dir string , a * analysis.Analyzer , patterns ... string ) []* Result {
305
+ os .Setenv ("GOPATH" , dir )
306
+ os .Setenv ("GO111MODULE" , "off" )
307
+ os .Setenv ("GOPROXY" , "off" )
308
+ return RunModule (t , dir , a , patterns ... )
309
+ }
310
+
303
311
// A Result holds the result of applying an analyzer to a package.
304
312
type Result = checker.TestAnalyzerResult
305
313
306
314
// loadPackages uses go/packages to load a specified packages (from source, with
307
- // dependencies) from dir, which is the root of a GOPATH-style project
308
- // tree. It returns an error if any package had an error, or the pattern
315
+ // dependencies) from dir. It returns an error if any package had an error, or the pattern
309
316
// matched no packages.
310
317
func loadPackages (a * analysis.Analyzer , dir string , patterns ... string ) ([]* packages.Package , error ) {
311
318
// packages.Load loads the real standard library, not a minimal
0 commit comments