@@ -223,14 +223,18 @@ type PkgInfo struct {
223223// GetPkgsInfo gets the absolute module and package root directories for the packages matched by the
224224// patterns `patterns`. It passes to `go list` the flags specified by `flags`. If `includingDeps`
225225// is true, all dependencies will also be included.
226- func GetPkgsInfo (patterns []string , includingDeps bool , flags ... string ) (map [string ]PkgInfo , error ) {
226+ func GetPkgsInfo (patterns []string , includingDeps bool , extractTests bool , flags ... string ) (map [string ]PkgInfo , error ) {
227227 // enable module mode so that we can find a module root if it exists, even if go module support is
228228 // disabled by a build
229229 if includingDeps {
230230 // the flag `-deps` causes all dependencies to be retrieved
231231 flags = append (flags , "-deps" )
232232 }
233233
234+ if extractTests {
235+ flags = append (flags , "-test" )
236+ }
237+
234238 // using -json overrides -f format
235239 output , err := RunList ("" , patterns , append (flags , "-json" )... )
236240 if err != nil {
@@ -272,6 +276,12 @@ func GetPkgsInfo(patterns []string, includingDeps bool, flags ...string) (map[st
272276 PkgDir : pkgAbsDir ,
273277 ModDir : modAbsDir ,
274278 }
279+
280+ if extractTests && strings .Contains (pkgInfo .ImportPath , " [" ) {
281+ // Assume " [" is the start of a qualifier, and index the package by its base name
282+ baseImportPath := strings .Split (pkgInfo .ImportPath , " [" )[0 ]
283+ pkgInfoMapping [baseImportPath ] = pkgInfoMapping [pkgInfo .ImportPath ]
284+ }
275285 }
276286 return pkgInfoMapping , nil
277287}
0 commit comments