Commit 52cc9e37 authored by Michael Matloob's avatar Michael Matloob

cmd/go: add test code packages in list -test

Previously go list -test <pkg> would return pkg and, if it exists,
pkg.test, the test main package. This change will also list the
two test code packages (if they exist) that contain testing functions,
<pkg> [<pkg>.test] and <pkg>_test [<pkg>.test].

These packages which contain testing code are usually the packages
go list users desire to know about, so they should be surfaced
in go list -test.

See the discussion at
golang.org/cl/123635#message-5befbc66663063fb7247645a02ab1327a681e362
for more context.

Change-Id: I7170b539d02b548c050ac54048735ed785f47389
Reviewed-on: https://go-review.googlesource.com/126475
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent e351a160
...@@ -1757,7 +1757,7 @@ func TestGoListTest(t *testing.T) { ...@@ -1757,7 +1757,7 @@ func TestGoListTest(t *testing.T) {
tg.run("list", "-test", "sort") tg.run("list", "-test", "sort")
tg.grepStdout(`^sort.test$`, "missing test main") tg.grepStdout(`^sort.test$`, "missing test main")
tg.grepStdout(`^sort$`, "missing real sort") tg.grepStdout(`^sort$`, "missing real sort")
tg.grepStdoutNot(`^sort \[sort.test\]$`, "unexpected test copy of sort") tg.grepStdout(`^sort \[sort.test\]$`, "unexpected test copy of sort")
tg.grepStdoutNot(`^testing \[sort.test\]$`, "unexpected test copy of testing") tg.grepStdoutNot(`^testing \[sort.test\]$`, "unexpected test copy of testing")
tg.grepStdoutNot(`^testing$`, "unexpected real copy of testing") tg.grepStdoutNot(`^testing$`, "unexpected real copy of testing")
......
...@@ -424,7 +424,7 @@ func runList(cmd *base.Command, args []string) { ...@@ -424,7 +424,7 @@ func runList(cmd *base.Command, args []string) {
continue continue
} }
if len(p.TestGoFiles)+len(p.XTestGoFiles) > 0 { if len(p.TestGoFiles)+len(p.XTestGoFiles) > 0 {
pmain, _, _, err := load.TestPackagesFor(p, nil) pmain, ptest, pxtest, err := load.TestPackagesFor(p, nil)
if err != nil { if err != nil {
if *listE { if *listE {
pkgs = append(pkgs, &load.Package{ pkgs = append(pkgs, &load.Package{
...@@ -439,6 +439,12 @@ func runList(cmd *base.Command, args []string) { ...@@ -439,6 +439,12 @@ func runList(cmd *base.Command, args []string) {
continue continue
} }
pkgs = append(pkgs, pmain) pkgs = append(pkgs, pmain)
if ptest != nil {
pkgs = append(pkgs, ptest)
}
if pxtest != nil {
pkgs = append(pkgs, pxtest)
}
data := *pmain.Internal.TestmainGo data := *pmain.Internal.TestmainGo
h := cache.NewHash("testmain") h := cache.NewHash("testmain")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment