]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: fix name check for examples in _test package
authorKonstantin Shaposhnikov <k.shaposhnikov@gmail.com>
Mon, 27 Jun 2016 05:37:01 +0000 (13:37 +0800)
committerRob Pike <r@golang.org>
Mon, 27 Jun 2016 15:40:09 +0000 (15:40 +0000)
This fixes the obvious bug and makes go vet look for identifiers in foo
package when checking example names in foo_test package.

Note that for this check to work the foo package have to be
installed (using go install).

This commit however doesn't fix TestDivergentPackagesExamples test that
is not implemented correctly and passes only by chance.

Updates #16189

Change-Id: I5c2f675cd07e5b66cf0432b2b3e422ab45c3dedd
Reviewed-on: https://go-review.googlesource.com/24487
Reviewed-by: Dmitri Shuralyov <shurcool@gmail.com>
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/vet/tests.go

index 52ad3340983e81d44da9bb29fb0c2b62b64a7833..076835b9808d8be269c11bcb0d0ee9474f050548 100644 (file)
@@ -63,7 +63,7 @@ func extendedScope(pkg *Package) []*types.Scope {
        scopes := []*types.Scope{pkg.typesPkg.Scope()}
 
        pkgName := pkg.typesPkg.Name()
-       if strings.HasPrefix(pkgName, "_test") {
+       if strings.HasSuffix(pkgName, "_test") {
                basePkg := strings.TrimSuffix(pkgName, "_test")
                for _, p := range pkg.typesPkg.Imports() {
                        if p.Name() == basePkg {