Skip to content
Permalink
Browse files

stop on package load errors too

I had forgotten to check those. Otherwise, we might be ignoring parse or
typecheck errors.

We can't fix the TODO in load_test.go yet, because it looks like there's
another bug in go/packages. See golang/go#29280.
  • Loading branch information...
mvdan committed Dec 18, 2018
1 parent 5c4367b commit b332c55ef19d5e3d35cccecca3d5f2ac7b60ed79
Showing with 29 additions and 12 deletions.
  1. +1 −1 go.mod
  2. +2 −2 go.sum
  3. +10 −0 load.go
  4. +2 −2 load_test.go
  5. +2 −0 testdata/exprlist.go
  6. +3 −0 testdata/longstmt.go
  7. +9 −7 write_test.go
2 go.mod
@@ -1,3 +1,3 @@
module mvdan.cc/gogrep

require golang.org/x/tools v0.0.0-20181214171254-3c39ce7b6105
require golang.org/x/tools v0.0.0-20181218020041-13ba8ad772df
4 go.sum
@@ -1,2 +1,2 @@
golang.org/x/tools v0.0.0-20181214171254-3c39ce7b6105 h1:kFsnkWrmuEx8NF7fFPXVUvSHzRcmD/9TevF5wNmXizs=
golang.org/x/tools v0.0.0-20181214171254-3c39ce7b6105/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181218020041-13ba8ad772df h1:sXpV2FbQYylCBI9NPmrOEEFd/PTh5prLXXWYpQef3u0=
golang.org/x/tools v0.0.0-20181218020041-13ba8ad772df/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
10 load.go
@@ -4,6 +4,7 @@
package main

import (
"fmt"
"sort"
"strings"

@@ -25,6 +26,15 @@ func (m *matcher) load(wd string, args ...string) ([]*packages.Package, error) {
if err != nil {
return nil, err
}
jointErr := ""
packages.Visit(pkgs, nil, func(pkg *packages.Package) {
for _, err := range pkg.Errors {
jointErr += err.Error() + "\n"
}
})
if jointErr != "" {
return nil, fmt.Errorf("%s", jointErr)
}

// Make a sorted list of the packages, including transitive dependencies
// if recurse is true.
@@ -89,11 +89,11 @@ func TestLoad(t *testing.T) {
},
{
[]string{"-x", "if $_ { $*_ }", "longstmt.go"},
`longstmt.go:4:2: if true { foo(); bar(); }`,
`longstmt.go:7:2: if true { foo(); bar(); }`,
},
{
[]string{"-x", "1, 2, 3, 4, 5", "exprlist.go"},
`exprlist.go:3:13: 1, 2, 3, 4, 5`,
`exprlist.go:5:13: 1, 2, 3, 4, 5`,
},
}
for i, tc := range tests {
@@ -1,3 +1,5 @@
package util

func foo(a ...int) int

var _ = foo(1, 2, 3, 4, 5)
@@ -1,5 +1,8 @@
package util

func foo()
func bar()

func _() {
if true {
foo()
@@ -20,17 +20,18 @@ func TestWriteFiles(t *testing.T) {
}
files := []struct{ orig, want string }{
{
"package p\n\nfunc f() { foo() }\n",
"package p\n\nfunc f() { bar() }\n",
// TODO: "func foo()" should get changed too
"package p\n\nfunc foo()\nfunc bar()\nfunc f1() { foo() }\n",
"package p\n\nfunc foo()\nfunc bar()\nfunc f1() { bar() }\n",
},
{
"// package p doc\npackage p\n\nfunc f() { foo() }\n",
"// package p doc\npackage p\n\nfunc f() { bar() }\n",
"// package p doc\npackage p\n\nfunc f2() { foo() }\n",
"// package p doc\npackage p\n\nfunc f2() { bar() }\n",
},
{
`package p
func f() {
func fn(int)
func f3() {
go func() {
// comment
fn(0)
@@ -39,7 +40,8 @@ func f() {
`,
`package p
func f() {
func fn(int)
func f3() {
// comment
go fn(0)

0 comments on commit b332c55

Please sign in to comment.
You can’t perform that action at this time.