Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: change vet -shadow to subtest calling -vettool=shadow #36486

Merged
merged 1 commit into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ required = [
"golang.org/x/perf/cmd/benchstat",
"golang.org/x/tools/cmd/goyacc",
"golang.org/x/tools/cmd/stringer",
"golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow",
]

ignored = [
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ bin/.bootstrap: $(GITHOOKS) Gopkg.lock | bin/.submodules-initialized
./vendor/github.com/wadey/gocovmerge \
./vendor/golang.org/x/perf/cmd/benchstat \
./vendor/golang.org/x/tools/cmd/goyacc \
./vendor/golang.org/x/tools/cmd/stringer
./vendor/golang.org/x/tools/cmd/stringer \
./vendor/golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
touch $@

.SECONDARY: bin/.submodules-initialized
Expand Down
151 changes: 76 additions & 75 deletions pkg/testutils/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1269,9 +1269,81 @@ func TestLint(t *testing.T) {

t.Run("TestVet", func(t *testing.T) {
t.Parallel()
// `go vet` is a special snowflake that emits all its output on
// `stderr.
//
runVet := func(t *testing.T, args ...string) {
args = append(append([]string{"vet"}, args...), pkgScope)
cmd := exec.Command("go", args...)
cmd.Dir = crdb.Dir
var b bytes.Buffer
cmd.Stdout = &b
cmd.Stderr = &b
switch err := cmd.Run(); err.(type) {
case nil:
case *exec.ExitError:
// Non-zero exit is expected.
default:
t.Fatal(err)
}

if err := stream.ForEach(stream.Sequence(
stream.FilterFunc(func(arg stream.Arg) error {
scanner := bufio.NewScanner(&b)
for scanner.Scan() {
if s := scanner.Text(); strings.TrimSpace(s) != "" {
arg.Out <- s
}
}
return scanner.Err()
}),
stream.GrepNot(`declaration of "?(pE|e)rr"? shadows`),
stream.GrepNot(`\.pb\.gw\.go:[0-9:]+: declaration of "?ctx"? shadows`),
stream.GrepNot(`\.[eo]g\.go:[0-9:]+: declaration of ".*" shadows`),
stream.GrepNot(`^#`), // comment line
), func(s string) {
t.Errorf("\n%s", s)
}); err != nil {
t.Error(err)
}
}
printfuncs := strings.Join([]string{
"ErrEvent",
"ErrEventf",
"Error",
"Errorf",
"ErrorfDepth",
"Event",
"Eventf",
"Fatal",
"Fatalf",
"FatalfDepth",
"Info",
"Infof",
"InfofDepth",
"NewAssertionErrorWithDepthf",
"NewAssertionErrorWithWrappedErrf",
"NewAssertionErrorf",
"NewDangerousStatementErrorf",
"NewError",
"NewErrorWithDepthf",
"NewErrorf",
"SetDetailf",
"SetHintf",
"Unimplemented",
"UnimplementedWithDepth",
"UnimplementedWithIssueDetailErrorf",
"UnimplementedWithIssueErrorf",
"VEvent",
"VEventf",
"Warning",
"Warningf",
"WarningfDepth",
"Wrapf",
"WrapWithDepthf",
}, ",")

// Unfortunately if an analyzer is passed via -vettool like shadow, it seems
// we cannot also run the core analyzers (or at least cannot pass them flags
// like -printfuncs).
t.Run("shadow", func(t *testing.T) { runVet(t, "-vettool=bin/shadow") })
// The -printfuncs functionality is interesting and
// under-documented. It checks two things:
//
Expand All @@ -1286,78 +1358,7 @@ func TestLint(t *testing.T) {
// A function may be a Printf or Print wrapper if its last argument is ...interface{}.
// If the next-to-last argument is a string, then this may be a Printf wrapper.
// Otherwise it may be a Print wrapper.
cmd := exec.Command("go", "vet", "-all", "-shadow", "-printfuncs",
strings.Join([]string{
"ErrEvent",
"ErrEventf",
"Error",
"Errorf",
"ErrorfDepth",
"Event",
"Eventf",
"Fatal",
"Fatalf",
"FatalfDepth",
"Info",
"Infof",
"InfofDepth",
"NewAssertionErrorWithDepthf",
"NewAssertionErrorWithWrappedErrf",
"NewAssertionErrorf",
"NewDangerousStatementErrorf",
"NewError",
"NewErrorWithDepthf",
"NewErrorf",
"SetDetailf",
"SetHintf",
"Unimplemented",
"UnimplementedWithDepth",
"UnimplementedWithIssueDetailErrorf",
"UnimplementedWithIssueErrorf",
"VEvent",
"VEventf",
"Warning",
"Warningf",
"WarningfDepth",
"Wrapf",
"WrapWithDepthf",
}, ","),
pkgScope,
)
cmd.Dir = crdb.Dir
var b bytes.Buffer
cmd.Stdout = &b
cmd.Stderr = &b
switch err := cmd.Run(); err.(type) {
case nil:
case *exec.ExitError:
// Non-zero exit is expected.
default:
t.Fatal(err)
}

if err := stream.ForEach(stream.Sequence(
stream.FilterFunc(func(arg stream.Arg) error {
scanner := bufio.NewScanner(&b)
for scanner.Scan() {
if s := scanner.Text(); strings.TrimSpace(s) != "" {
arg.Out <- s
}
}
return scanner.Err()
}),
stream.GrepNot(`declaration of "?(pE|e)rr"? shadows`),
stream.GrepNot(`\.pb\.gw\.go:[0-9]+: declaration of "?ctx"? shadows`),
stream.GrepNot(`\.[eo]g\.go:[0-9]+: declaration of ".*" shadows`),
stream.GrepNot(`^#`), // comment line
// Upstream compiler error. See: https://github.com/golang/go/issues/23701
stream.GrepNot(`pkg/sql/pgwire/pgwire_test\.go.*internal compiler error`),
stream.GrepNot(`^Please file a bug report|^https://golang.org/issue/new`),
), func(s string) {
t.Errorf("\n%s", s)
}); err != nil {
t.Error(err)
}
runVet(t, "-all", "-printfuncs", printfuncs)
})

// TODO(tamird): replace this with errcheck.NewChecker() when
Expand Down
2 changes: 1 addition & 1 deletion vendor
Submodule vendor updated 65 files
+0 −391 github.com/golang/leveldb/memfs/memfs.go
+192 −0 golang.org/x/tools/go/analysis/analysis.go
+336 −0 golang.org/x/tools/go/analysis/doc.go
+343 −0 golang.org/x/tools/go/analysis/internal/analysisflags/flags.go
+89 −0 golang.org/x/tools/go/analysis/internal/analysisflags/help.go
+701 −0 golang.org/x/tools/go/analysis/internal/checker/checker.go
+299 −0 golang.org/x/tools/go/analysis/internal/facts/facts.go
+88 −0 golang.org/x/tools/go/analysis/internal/facts/imports.go
+760 −0 golang.org/x/tools/go/analysis/passes/asmdecl/asmdecl.go
+68 −0 golang.org/x/tools/go/analysis/passes/assign/assign.go
+96 −0 golang.org/x/tools/go/analysis/passes/atomic/atomic.go
+214 −0 golang.org/x/tools/go/analysis/passes/bools/bools.go
+159 −0 golang.org/x/tools/go/analysis/passes/buildtag/buildtag.go
+390 −0 golang.org/x/tools/go/analysis/passes/cgocall/cgocall.go
+108 −0 golang.org/x/tools/go/analysis/passes/composite/composite.go
+33 −0 golang.org/x/tools/go/analysis/passes/composite/whitelist.go
+300 −0 golang.org/x/tools/go/analysis/passes/copylock/copylock.go
+225 −0 golang.org/x/tools/go/analysis/passes/ctrlflow/ctrlflow.go
+177 −0 golang.org/x/tools/go/analysis/passes/httpresponse/httpresponse.go
+49 −0 golang.org/x/tools/go/analysis/passes/inspect/inspect.go
+106 −0 golang.org/x/tools/go/analysis/passes/internal/analysisutil/util.go
+130 −0 golang.org/x/tools/go/analysis/passes/loopclosure/loopclosure.go
+315 −0 golang.org/x/tools/go/analysis/passes/lostcancel/lostcancel.go
+74 −0 golang.org/x/tools/go/analysis/passes/nilfunc/nilfunc.go
+1,017 −0 golang.org/x/tools/go/analysis/passes/printf/printf.go
+239 −0 golang.org/x/tools/go/analysis/passes/printf/types.go
+9 −0 golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow/main.go
+288 −0 golang.org/x/tools/go/analysis/passes/shadow/shadow.go
+101 −0 golang.org/x/tools/go/analysis/passes/shift/dead.go
+128 −0 golang.org/x/tools/go/analysis/passes/shift/shift.go
+186 −0 golang.org/x/tools/go/analysis/passes/stdmethods/stdmethods.go
+273 −0 golang.org/x/tools/go/analysis/passes/structtag/structtag.go
+175 −0 golang.org/x/tools/go/analysis/passes/tests/tests.go
+92 −0 golang.org/x/tools/go/analysis/passes/unmarshal/unmarshal.go
+314 −0 golang.org/x/tools/go/analysis/passes/unreachable/unreachable.go
+130 −0 golang.org/x/tools/go/analysis/passes/unsafeptr/unsafeptr.go
+131 −0 golang.org/x/tools/go/analysis/passes/unusedresult/unusedresult.go
+77 −0 golang.org/x/tools/go/analysis/singlechecker/singlechecker.go
+64 −0 golang.org/x/tools/go/analysis/unitchecker/main.go
+387 −0 golang.org/x/tools/go/analysis/unitchecker/unitchecker.go
+9 −0 golang.org/x/tools/go/analysis/unitchecker/unitchecker112.go
+104 −0 golang.org/x/tools/go/analysis/validate.go
+182 −0 golang.org/x/tools/go/ast/inspector/inspector.go
+216 −0 golang.org/x/tools/go/ast/inspector/typeof.go
+510 −0 golang.org/x/tools/go/cfg/builder.go
+150 −0 golang.org/x/tools/go/cfg/cfg.go
+160 −0 golang.org/x/tools/go/internal/packagesdriver/sizes.go
+226 −0 golang.org/x/tools/go/packages/doc.go
+79 −0 golang.org/x/tools/go/packages/external.go
+806 −0 golang.org/x/tools/go/packages/golist.go
+450 −0 golang.org/x/tools/go/packages/golist_fallback.go
+318 −0 golang.org/x/tools/go/packages/golist_fallback_testmain.go
+104 −0 golang.org/x/tools/go/packages/golist_overlay.go
+945 −0 golang.org/x/tools/go/packages/packages.go
+55 −0 golang.org/x/tools/go/packages/visit.go
+523 −0 golang.org/x/tools/go/types/objectpath/objectpath.go
+196 −0 golang.org/x/tools/internal/fastwalk/fastwalk.go
+13 −0 golang.org/x/tools/internal/fastwalk/fastwalk_dirent_fileno.go
+14 −0 golang.org/x/tools/internal/fastwalk/fastwalk_dirent_ino.go
+13 −0 golang.org/x/tools/internal/fastwalk/fastwalk_dirent_namlen_bsd.go
+29 −0 golang.org/x/tools/internal/fastwalk/fastwalk_dirent_namlen_linux.go
+37 −0 golang.org/x/tools/internal/fastwalk/fastwalk_portable.go
+127 −0 golang.org/x/tools/internal/fastwalk/fastwalk_unix.go
+249 −0 golang.org/x/tools/internal/gopathwalk/walk.go
+388 −0 golang.org/x/tools/internal/semver/semver.go