aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2018-08-20 21:35:02 -0400
committerIan Lance Taylor <iant@golang.org>2018-08-22 15:51:42 +0000
commit4124fe1c2cd33a7ca572d54bfd47409172ba56b1 (patch)
tree977101dd3dee44b811ecebfdc5491a977161387f
parent4383edf1c622ec5c85dce698cdfdbca9fffcaf04 (diff)
downloadgo-4124fe1c2cd33a7ca572d54bfd47409172ba56b1.tar.gz
go-4124fe1c2cd33a7ca572d54bfd47409172ba56b1.zip
[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 <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> (cherry picked from commit df6aedb630b3c79ff50147a85278a17702dcff1f) Reviewed-on: https://go-review.googlesource.com/130617 Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Andrew Bonventre <andybons@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Andrew Bonventre <andybons@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/cmd/go/internal/list/list.go4
-rw-r--r--src/cmd/go/testdata/script/mod_list_test.txt16
2 files changed, 19 insertions, 1 deletions
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) {}