]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/list: do not examine TestmainGo if the test fails to load
authorBryan C. Mills <bcmills@google.com>
Fri, 13 Jul 2018 21:24:05 +0000 (17:24 -0400)
committerBryan C. Mills <bcmills@google.com>
Thu, 19 Jul 2018 20:26:18 +0000 (20:26 +0000)
Fixes #25980.

Change-Id: I33c8e72871ffbb1cd1babbcd5dabc8cac0bbcaed
Reviewed-on: https://go-review.googlesource.com/123758
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/internal/list/list.go
src/cmd/go/testdata/script/list_test_e.txt [new file with mode: 0644]

index 9a5edd46795a215ef3f2471d4fd31ca1738ce06d..c1d008ce381213b3522d05678f8736d0cad9b76a 100644 (file)
@@ -425,16 +425,17 @@ func runList(cmd *base.Command, args []string) {
                        if len(p.TestGoFiles)+len(p.XTestGoFiles) > 0 {
                                pmain, _, _, err := load.TestPackagesFor(p, nil)
                                if err != nil {
-                                       if !*listE {
-                                               base.Errorf("can't load test package: %s", err)
+                                       if *listE {
+                                               pkgs = append(pkgs, &load.Package{
+                                                       PackagePublic: load.PackagePublic{
+                                                               ImportPath: p.ImportPath + ".test",
+                                                               Error:      &load.PackageError{Err: err.Error()},
+                                                       },
+                                               })
                                                continue
                                        }
-                                       pmain = &load.Package{
-                                               PackagePublic: load.PackagePublic{
-                                                       ImportPath: p.ImportPath + ".test",
-                                                       Error:      &load.PackageError{Err: err.Error()},
-                                               },
-                                       }
+                                       base.Errorf("can't load test package: %s", err)
+                                       continue
                                }
                                pkgs = append(pkgs, pmain)
 
diff --git a/src/cmd/go/testdata/script/list_test_e.txt b/src/cmd/go/testdata/script/list_test_e.txt
new file mode 100644 (file)
index 0000000..3e84de6
--- /dev/null
@@ -0,0 +1,9 @@
+# issue 25980: crash in go list -e -test
+go list -e -test -f '{{.Error}}' p
+stdout '^p/d_test.go:2:8: cannot find package "d" in any of:'
+
+-- p/d.go --
+package d
+-- p/d_test.go --
+package d_test
+import _ "d"