mirror of
https://github.com/golang/go
synced 2024-11-18 06:14:46 -07:00
cmd/fiximports: fix 'go list' error formatting
Error positions should be printed, when specified. Also, made main_test less picky about whitespace before and after error output. After this change, the test for cmd/fiximports should pass before and after CL 210938. Updates golang/go#36087 Change-Id: I681d1ee07f7f19a0d9716b88678e2737f4c691de Reviewed-on: https://go-review.googlesource.com/c/tools/+/211337 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
38570b7665
commit
210e553fe1
@ -205,7 +205,7 @@ func fiximports(packages ...string) bool {
|
||||
strings.Contains(msg, "expects import") {
|
||||
// don't show the very errors we're trying to fix
|
||||
} else {
|
||||
fmt.Fprintln(stderr, msg)
|
||||
fmt.Fprintln(stderr, p.Error)
|
||||
}
|
||||
}
|
||||
|
||||
@ -467,6 +467,13 @@ type packageError struct {
|
||||
Err string // the error itself
|
||||
}
|
||||
|
||||
func (e packageError) Error() string {
|
||||
if e.Pos != "" {
|
||||
return e.Pos + ": " + e.Err
|
||||
}
|
||||
return e.Err
|
||||
}
|
||||
|
||||
// list runs 'go list' with the specified arguments and returns the
|
||||
// metadata for matching packages.
|
||||
func list(args ...string) ([]*listPackage, error) {
|
||||
|
@ -212,6 +212,7 @@ import (
|
||||
test.wantStderr = strings.Replace(test.wantStderr, `testdata/src/old.com/bad/bad.go`, `testdata\src\old.com\bad\bad.go`, -1)
|
||||
test.wantStderr = strings.Replace(test.wantStderr, `testdata/src/fruit.io/banana/banana.go`, `testdata\src\fruit.io\banana\banana.go`, -1)
|
||||
}
|
||||
test.wantStderr = strings.TrimSpace(test.wantStderr)
|
||||
|
||||
// Check status code.
|
||||
if fiximports(test.packages...) != test.wantOK {
|
||||
@ -219,12 +220,12 @@ import (
|
||||
}
|
||||
|
||||
// Compare stderr output.
|
||||
if got := stderr.(*bytes.Buffer).String(); got != test.wantStderr {
|
||||
if got := strings.TrimSpace(stderr.(*bytes.Buffer).String()); got != test.wantStderr {
|
||||
if strings.Contains(got, "vendor/golang_org/x/text/unicode/norm") {
|
||||
t.Skip("skipping known-broken test; see golang.org/issue/17417")
|
||||
}
|
||||
t.Errorf("#%d. stderr: got <<%s>>, want <<%s>>",
|
||||
i, stderr, test.wantStderr)
|
||||
t.Errorf("#%d. stderr: got <<\n%s\n>>, want <<\n%s\n>>",
|
||||
i, got, test.wantStderr)
|
||||
}
|
||||
|
||||
// Compare rewrites.
|
||||
|
Loading…
Reference in New Issue
Block a user