aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuzy Mueller <suzmue@golang.org>2018-08-09 13:05:54 -0400
committerRuss Cox <rsc@golang.org>2018-08-10 00:26:47 +0000
commitd611e95cabbd531418beb7c1fdc7191ba3151c2a (patch)
tree572314cb6ed29f5cffb148e5d04177666fb56508
parent9f4ea6c25d7cee2ddb7d478cf03582baad17cc59 (diff)
downloadgo-d611e95cabbd531418beb7c1fdc7191ba3151c2a.tar.gz
go-d611e95cabbd531418beb7c1fdc7191ba3151c2a.zip
cmd/go: make 'go list -test' report the correct import path
When a test variant of a package is created, the two versions cannot share memory for the fields that contain information about their imports, as these will be different between the two packagse. Both the Internal.Imports and the Imports fields must be able to be updated in the test variant without affecting the values of the original. Fixes golang/go#26880 Change-Id: Id61fad7d976e179c6c7711a394ce43ec8302fd7a Reviewed-on: https://go-review.googlesource.com/128836 Reviewed-by: Russ Cox <rsc@golang.org>
-rw-r--r--src/cmd/go/internal/load/test.go2
-rw-r--r--src/cmd/go/testdata/script/list_test_imports.txt19
2 files changed, 21 insertions, 0 deletions
diff --git a/src/cmd/go/internal/load/test.go b/src/cmd/go/internal/load/test.go
index 2cc7c6cb2a..bb9568d07e 100644
--- a/src/cmd/go/internal/load/test.go
+++ b/src/cmd/go/internal/load/test.go
@@ -342,6 +342,8 @@ func recompileForTest(pmain, preal, ptest, pxtest *Package) {
p1.ForTest = preal.ImportPath
p1.Internal.Imports = make([]*Package, len(p.Internal.Imports))
copy(p1.Internal.Imports, p.Internal.Imports)
+ p1.Imports = make([]string, len(p.Imports))
+ copy(p1.Imports, p.Imports)
p = p1
p.Target = ""
}
diff --git a/src/cmd/go/testdata/script/list_test_imports.txt b/src/cmd/go/testdata/script/list_test_imports.txt
new file mode 100644
index 0000000000..51d1ce9a69
--- /dev/null
+++ b/src/cmd/go/testdata/script/list_test_imports.txt
@@ -0,0 +1,19 @@
+# issue 26880: list with tests has wrong variant in imports
+go list -test -f '{{.ImportPath}}:{{with .Imports}} {{join . ", "}}{{end}}' a b
+cmp stdout imports.txt
+
+-- a/a.go --
+package a; import _ "b"
+-- b/b.go --
+package b
+-- b/b_test.go --
+package b
+-- b/b_x_test.go --
+package b_test; import _ "a"
+
+-- imports.txt --
+a: b
+b:
+b.test: b [b.test], b_test [b.test], os, testing, testing/internal/testdeps
+b [b.test]:
+b_test [b.test]: a [b.test]