aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/load.go
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2019-05-16 18:35:48 -0400
committerJay Conrod <jayconrod@google.com>2019-05-20 20:58:14 +0000
commitab724d43efe7e1a7516c1d13e40b55dca26a61b4 (patch)
tree9b20a0d14edc45e4861aee3aa8c83932c69d9d71 /src/cmd/go/internal/modload/load.go
parent776e1709e59c2c50d93467e666d4bb8955b32ed3 (diff)
downloadgo-ab724d43efe7e1a7516c1d13e40b55dca26a61b4.tar.gz
go-ab724d43efe7e1a7516c1d13e40b55dca26a61b4.zip
cmd/go: make 'go get -t' consider test dependencies in module mode
Fixes #32037 Change-Id: I696fe2029e383746252f37fe8d30df71b5ac8a6c Reviewed-on: https://go-review.googlesource.com/c/go/+/177677 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/load.go')
-rw-r--r--src/cmd/go/internal/modload/load.go19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go
index 579ef50382..b64b5b68cd 100644
--- a/src/cmd/go/internal/modload/load.go
+++ b/src/cmd/go/internal/modload/load.go
@@ -496,17 +496,26 @@ func PackageModule(path string) module.Version {
}
// PackageImports returns the imports for the package named by the import path.
-// It does not include test imports. It returns nil for unknown packages.
-func PackageImports(path string) []string {
+// Test imports will be returned as well if tests were loaded for the package
+// (i.e., if "all" was loaded or if LoadTests was set and the path was matched
+// by a command line argument). PackageImports will return nil for
+// unknown package paths.
+func PackageImports(path string) (imports, testImports []string) {
pkg, ok := loaded.pkgCache.Get(path).(*loadPkg)
if !ok {
- return nil
+ return nil, nil
}
- imports := make([]string, len(pkg.imports))
+ imports = make([]string, len(pkg.imports))
for i, p := range pkg.imports {
imports[i] = p.path
}
- return imports
+ if pkg.test != nil {
+ testImports = make([]string, len(pkg.test.imports))
+ for i, p := range pkg.test.imports {
+ testImports[i] = p.path
+ }
+ }
+ return imports, testImports
}
// ModuleUsedDirectly reports whether the main module directly imports