From 52cc9e3762171bd45368b3280554bf12a63f23b2 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Fri, 27 Jul 2018 16:23:16 -0400 Subject: [PATCH] cmd/go: add test code packages in list -test Previously go list -test 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, [.test] and _test [.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 TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox --- src/cmd/go/go_test.go | 2 +- src/cmd/go/internal/list/list.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index adf17b8bc5..7249c0fb6e 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -1757,7 +1757,7 @@ func TestGoListTest(t *testing.T) { tg.run("list", "-test", "sort") tg.grepStdout(`^sort.test$`, "missing test main") 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$`, "unexpected real copy of testing") diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go index d21e896834..5cb61b0d67 100644 --- a/src/cmd/go/internal/list/list.go +++ b/src/cmd/go/internal/list/list.go @@ -424,7 +424,7 @@ func runList(cmd *base.Command, args []string) { continue } 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 *listE { pkgs = append(pkgs, &load.Package{ @@ -439,6 +439,12 @@ func runList(cmd *base.Command, args []string) { continue } pkgs = append(pkgs, pmain) + if ptest != nil { + pkgs = append(pkgs, ptest) + } + if pxtest != nil { + pkgs = append(pkgs, pxtest) + } data := *pmain.Internal.TestmainGo h := cache.NewHash("testmain") -- 2.48.1