diff options
author | Jay Conrod <jayconrod@google.com> | 2019-02-13 18:35:19 -0500 |
---|---|---|
committer | Jay Conrod <jayconrod@google.com> | 2019-03-08 20:22:16 +0000 |
commit | f1d5ce0185fe184c016016d55f1718778b799f6d (patch) | |
tree | d2a8b9cdcdbc83b183301e4ad377c7ce3df1d4b5 /src/cmd/go/internal/list/list.go | |
parent | 1ab9f6837d6da80dad41657a913e47fa13a4fee8 (diff) | |
download | go-f1d5ce0185fe184c016016d55f1718778b799f6d.tar.gz go-f1d5ce0185fe184c016016d55f1718778b799f6d.zip |
cmd/go: make go list error behavior consistent in tests
"go list -test" constructs a package graph, then creates test packages
for the target. If it encounters an error (for example, a syntax error
in a test file or a test function with the wrong signature), it
reports the error and exits without printing the test packages or
their dependencies, even if the -e flag is given. This is a problem
for tools that operate on test files while users are editing them. For
example, autocomplete may not work while the user is typing.
With this change, a new function, load.TestPackagesAndErrors replaces
TestPackagesFor. The new function attaches errors to the returned test
packages instead of returning immediately. "go list -test" calls this
when the -e flag is set. TestPackagesFor now returns the same error as
before, but it returns non-nil packages so that "go list -test"
without -e can print partial results.
Fixes #28491
Change-Id: I141765c4574eae424d872eb9bf7dd63fdfb85efb
Reviewed-on: https://go-review.googlesource.com/c/go/+/164357
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/list/list.go')
-rw-r--r-- | src/cmd/go/internal/list/list.go | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go index e482c393b6..4a6633d9a1 100644 --- a/src/cmd/go/internal/list/list.go +++ b/src/cmd/go/internal/list/list.go @@ -447,37 +447,34 @@ func runList(cmd *base.Command, args []string) { continue } if len(p.TestGoFiles)+len(p.XTestGoFiles) > 0 { - pmain, ptest, pxtest, err := load.TestPackagesFor(p, nil) - if err != nil { - if *listE { - pkgs = append(pkgs, &load.Package{ - PackagePublic: load.PackagePublic{ - ImportPath: p.ImportPath + ".test", - Error: &load.PackageError{Err: err.Error()}, - }, - }) - continue + var pmain, ptest, pxtest *load.Package + var err error + if *listE { + pmain, ptest, pxtest = load.TestPackagesAndErrors(p, nil) + } else { + pmain, ptest, pxtest, err = load.TestPackagesFor(p, nil) + if err != nil { + base.Errorf("can't load test package: %s", err) } - base.Errorf("can't load test package: %s", err) - continue } - pkgs = append(pkgs, pmain) - if ptest != nil { + if pmain != nil { + pkgs = append(pkgs, pmain) + data := *pmain.Internal.TestmainGo + h := cache.NewHash("testmain") + h.Write([]byte("testmain\n")) + h.Write(data) + out, _, err := c.Put(h.Sum(), bytes.NewReader(data)) + if err != nil { + base.Fatalf("%s", err) + } + pmain.GoFiles[0] = c.OutputFile(out) + } + if ptest != nil && ptest != p { pkgs = append(pkgs, ptest) } if pxtest != nil { pkgs = append(pkgs, pxtest) } - - data := *pmain.Internal.TestmainGo - h := cache.NewHash("testmain") - h.Write([]byte("testmain\n")) - h.Write(data) - out, _, err := c.Put(h.Sum(), bytes.NewReader(data)) - if err != nil { - base.Fatalf("%s", err) - } - pmain.GoFiles[0] = c.OutputFile(out) } } } |