aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2020-07-01 10:33:56 -0400
committerBryan C. Mills <bcmills@google.com>2020-08-24 19:20:59 +0000
commitbb998747d6c5213e3a366936c482e149dce62720 (patch)
tree2df4af0928b8d0270d90554079cf1389a7e16291 /src
parentfb5c3eabd16bbeea28ee8a11d29a31cf5ed124dd (diff)
downloadgo-bb998747d6c5213e3a366936c482e149dce62720.tar.xz
cmd/go: populate the Module field for test packages
Fixes #39974 Change-Id: I52bb13e887fde52bf789198059c39fd6aacd96f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/240678 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/go/internal/load/test.go2
-rw-r--r--src/cmd/go/testdata/script/mod_list_test.txt14
2 files changed, 16 insertions, 0 deletions
diff --git a/src/cmd/go/internal/load/test.go b/src/cmd/go/internal/load/test.go
index a0e275095b..e0f13323df 100644
--- a/src/cmd/go/internal/load/test.go
+++ b/src/cmd/go/internal/load/test.go
@@ -191,6 +191,7 @@ func TestPackagesAndErrors(ctx context.Context, p *Package, cover *TestCover) (p
GoFiles: p.XTestGoFiles,
Imports: p.XTestImports,
ForTest: p.ImportPath,
+ Module: p.Module,
Error: pxtestErr,
},
Internal: PackageInternal{
@@ -222,6 +223,7 @@ func TestPackagesAndErrors(ctx context.Context, p *Package, cover *TestCover) (p
ImportPath: p.ImportPath + ".test",
Root: p.Root,
Imports: str.StringList(TestMainDeps),
+ Module: p.Module,
},
Internal: PackageInternal{
Build: &build.Package{Name: "main"},
diff --git a/src/cmd/go/testdata/script/mod_list_test.txt b/src/cmd/go/testdata/script/mod_list_test.txt
index a99e4f36cd..f697af6c92 100644
--- a/src/cmd/go/testdata/script/mod_list_test.txt
+++ b/src/cmd/go/testdata/script/mod_list_test.txt
@@ -3,9 +3,19 @@ env GO111MODULE=on
# go list -compiled -test must handle test-only packages
# golang.org/issue/27097.
go list -compiled -test
+stdout -count=4 '^.' # 4 lines
stdout '^m$'
stdout '^m\.test$'
stdout '^m \[m\.test\]$'
+stdout '^m_test \[m\.test\]$'
+
+# https://golang.org/issue/39974: test packages should have the Module field populated.
+go list -test -f '{{.ImportPath}}{{with .Module}}: {{.Path}}{{end}}'
+stdout -count=4 '^.' # 4 lines
+stdout '^m: m$'
+stdout '^m\.test: m$'
+stdout '^m \[m\.test\]: m$'
+stdout '^m_test \[m\.test\]: m$'
-- go.mod --
module m
@@ -14,3 +24,7 @@ module m
package x
import "testing"
func Test(t *testing.T) {}
+-- x_x_test.go --
+package x_test
+import "testing"
+func Test(t *testing.T) {}