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"