From: Bryan C. Mills Date: Fri, 13 Jul 2018 21:24:05 +0000 (-0400) Subject: cmd/go/internal/list: do not examine TestmainGo if the test fails to load X-Git-Tag: go1.11beta2~3 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b47927cc2657ca1e3a1b898632b577cacb3b440c;p=gostls13.git 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 --- diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go index 9a5edd4679..c1d008ce38 100644 --- a/src/cmd/go/internal/list/list.go +++ b/src/cmd/go/internal/list/list.go @@ -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 index 0000000000..3e84de6b07 --- /dev/null +++ b/src/cmd/go/testdata/script/list_test_e.txt @@ -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"