1
0
mirror of https://github.com/golang/go synced 2024-11-07 15:46:23 -07:00

cmd/go/internal/list: do not examine TestmainGo if the test fails to load

Fixes #25980.

Change-Id: I33c8e72871ffbb1cd1babbcd5dabc8cac0bbcaed
Reviewed-on: https://go-review.googlesource.com/123758
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Bryan C. Mills 2018-07-13 17:24:05 -04:00
parent 0b3d39c700
commit b47927cc26
2 changed files with 18 additions and 8 deletions

View 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)

View File

@ -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"