From: Russ Cox Date: Tue, 21 Aug 2018 01:35:02 +0000 (-0400) Subject: [release-branch.go1.11] cmd/go: fix list -compiled of package with only tests X-Git-Tag: go1.11rc2~3 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4124fe1c2cd33a7ca572d54bfd47409172ba56b1;p=gostls13.git [release-branch.go1.11] cmd/go: fix list -compiled of package with only tests Fixes #27097. Change-Id: I6aa48a1c58a21fd320b0e9dcd1f86c90172f0182 Reviewed-on: https://go-review.googlesource.com/130139 Run-TryBot: Russ Cox Reviewed-by: Ian Lance Taylor (cherry picked from commit df6aedb630b3c79ff50147a85278a17702dcff1f) Reviewed-on: https://go-review.googlesource.com/130617 Run-TryBot: Ian Lance Taylor Run-TryBot: Andrew Bonventre Reviewed-by: Brad Fitzpatrick Reviewed-by: Andrew Bonventre TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go index 186b006c12..f3cb4e47ec 100644 --- a/src/cmd/go/internal/list/list.go +++ b/src/cmd/go/internal/list/list.go @@ -510,7 +510,9 @@ func runList(cmd *base.Command, args []string) { a := &work.Action{} // TODO: Use pkgsFilter? for _, p := range pkgs { - a.Deps = append(a.Deps, b.AutoAction(work.ModeInstall, work.ModeInstall, p)) + if len(p.GoFiles)+len(p.CgoFiles) > 0 { + a.Deps = append(a.Deps, b.AutoAction(work.ModeInstall, work.ModeInstall, p)) + } } b.Do(a) } diff --git a/src/cmd/go/testdata/script/mod_list_test.txt b/src/cmd/go/testdata/script/mod_list_test.txt new file mode 100644 index 0000000000..a99e4f36cd --- /dev/null +++ b/src/cmd/go/testdata/script/mod_list_test.txt @@ -0,0 +1,16 @@ +env GO111MODULE=on + +# go list -compiled -test must handle test-only packages +# golang.org/issue/27097. +go list -compiled -test +stdout '^m$' +stdout '^m\.test$' +stdout '^m \[m\.test\]$' + +-- go.mod -- +module m + +-- x_test.go -- +package x +import "testing" +func Test(t *testing.T) {}