@@ -223,14 +223,18 @@ type PkgInfo struct {
223
223
// GetPkgsInfo gets the absolute module and package root directories for the packages matched by the
224
224
// patterns `patterns`. It passes to `go list` the flags specified by `flags`. If `includingDeps`
225
225
// 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 ) {
227
227
// enable module mode so that we can find a module root if it exists, even if go module support is
228
228
// disabled by a build
229
229
if includingDeps {
230
230
// the flag `-deps` causes all dependencies to be retrieved
231
231
flags = append (flags , "-deps" )
232
232
}
233
233
234
+ if extractTests {
235
+ flags = append (flags , "-test" )
236
+ }
237
+
234
238
// using -json overrides -f format
235
239
output , err := RunList ("" , patterns , append (flags , "-json" )... )
236
240
if err != nil {
@@ -272,6 +276,12 @@ func GetPkgsInfo(patterns []string, includingDeps bool, flags ...string) (map[st
272
276
PkgDir : pkgAbsDir ,
273
277
ModDir : modAbsDir ,
274
278
}
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
+ }
275
285
}
276
286
return pkgInfoMapping , nil
277
287
}
0 commit comments