]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add test code packages in list -test
authorMichael Matloob <matloob@golang.org>
Fri, 27 Jul 2018 20:23:16 +0000 (16:23 -0400)
committerMichael Matloob <matloob@golang.org>
Mon, 30 Jul 2018 16:40:04 +0000 (16:40 +0000)
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: Russ Cox <rsc@golang.org>
src/cmd/go/go_test.go
src/cmd/go/internal/list/list.go

index adf17b8bc59baeb5760e1ce84165054084ff45cb..7249c0fb6e1e1057205afa44ab2024fc928492ef 100644 (file)
@@ -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")
 
index d21e89683474319f9af1a89887d00d595042b9df..5cb61b0d6736063208c3357ee28f29805dbea736 100644 (file)
@@ -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")