Skip to content

Commit

Permalink
cmd/go/internal/vet: print line numbers appropriately on list errors
Browse files Browse the repository at this point in the history
Fixes golang#36173

For reasons that are unclear to me, this commit:
golang@f1d5ce0
introduces a TestPackagesFor function that strips line numbers from error
messages. This commit introduces a new version of that function for 'go vet'
that always keeps the line numbers.
  • Loading branch information
nicks committed Feb 4, 2020
1 parent 753d56d commit d005ca5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/cmd/go/internal/load/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ func TestPackagesFor(p *Package, cover *TestCover) (pmain, ptest, pxtest *Packag
break
}
if len(p1.DepsErrors) > 0 {
perr := p1.DepsErrors[0]
perr.Pos = "" // show full import stack
err = perr
err = p1.DepsErrors[0]
break
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/cmd/go/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,16 @@ func runTest(cmd *base.Command, args []string) {

buildTest, runTest, printTest, err := builderTest(&b, p)
if err != nil {
str := err.Error()
str = strings.TrimPrefix(str, "\n")
if p.ImportPath != "" {
base.Errorf("# %s\n%s", p.ImportPath, str)
// Strip off line number info so we can show the full import stack.
perr, ok := err.(*load.PackageError)
if ok {
perr.Pos = ""
}

base.Errorf("# %s\n%s", p.ImportPath, strings.TrimPrefix(err.Error(), "\n"))
} else {
base.Errorf("%s", str)
base.Errorf("%s", strings.TrimPrefix(err.Error(), "\n"))
}
fmt.Printf("FAIL\t%s [setup failed]\n", p.ImportPath)
continue
Expand Down
19 changes: 19 additions & 0 deletions src/cmd/go/testdata/script/vet_internal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
env GO111MODULE=off

# Issue 36173. Verify that "go vet" prints line numbers on load errors.

! go vet a/a_test.go
stderr 'a_test.go:4:3: use of internal package'

-- a/a.go --
package a

-- a/a_test.go --
package a

import (
_ "a/x/internal/y"
)

-- a/x/internal/y/y.go --
package y

0 comments on commit d005ca5

Please sign in to comment.