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

cmd/vet: go1.7 not finding ExampleT_M identifiers #16189

Closed
gmlewis opened this issue Jun 27, 2016 · 5 comments

Comments

Projects
None yet
6 participants
@gmlewis
Copy link
Contributor

commented Jun 27, 2016

Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?

go version go1.7beta2 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/local/google/gmlewis/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build185106612=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

In https://github.com/google/go-github we have Travis builds on Go versions 1.4.3, 1.5.4, 1.6.2, and tip. tip recently started failing with the go tool vet . command. See: https://travis-ci.org/google/go-github/builds/140438111 and https://travis-ci.org/google/go-github/jobs/140438114 for more details.

I ran go tool vet -v . locally, and get:

Checking file examples/basicauth/main.go
Checking file github/activity.go
...
Checking file github/users_test.go
Checking file github/examples_test.go
github/examples_test.go:15: ExampleClient_Markdown refers to unknown identifier: Client
github/examples_test.go:29: ExampleRepositoriesService_GetReadme refers to unknown identifier: RepositoriesService
github/examples_test.go:47: ExampleRepositoriesService_List refers to unknown identifier: RepositoriesService
github/examples_test.go:61: ExampleUsersService_ListAll refers to unknown identifier: UsersService
Checking file tests/fields/fields.go
Checking file tests/integration/doc.go

You can reproduce the error by typing:

$ go get github.com/google/go-github
$ cd $GOPATH/src/github.com/google/go-github
$ go tool vet -v .

What did you expect to see?

No errors.

What did you see instead?

See above. Note that type Client is defined in github.go and method Markdown is defined in misc.go.

We are tracking this issue here if you would like to comment:
google/go-github#386

Thank you!

@gmlewis gmlewis changed the title x/tools/cmd/vet: go1.7 not finding ExamplesT_M identifiers x/tools/cmd/vet: go1.7 not finding ExampleT_M identifiers Jun 27, 2016

@dmitshur

This comment has been minimized.

Copy link
Member

commented Jun 27, 2016

The naming convention to declare examples for a package has not changed in 1.7, as can be confirmed here:

https://github.com/golang/go/blob/go1.7beta2/src/testing/testing.go#L100-L115

So this indeed appears to be a bug/regression, rather than a valid change in behavior.

(Either that, or the documentation/specification was not updated to match new vet behavior.)

@kostya-sh

This comment has been minimized.

Copy link
Contributor

commented Jun 27, 2016

I have submitted CL 24487 that fixes the bug. Note however that you have to run go install prior to running go vet in order for it to work correctly.

While looking into this bug I also discovered that the test for this use case (examples in _test package) seems to be wrong however it is not easy to fix because:

  1. to properly test vet behavior with _test packages it should be invoked with a directory argument and errchck tool doesn't support directories
  2. package from testdata have to be installed for the functionality to work correctly
@gopherbot

This comment has been minimized.

Copy link

commented Jun 27, 2016

CL https://golang.org/cl/24487 mentions this issue.

@kostya-sh

This comment has been minimized.

Copy link
Contributor

commented Jun 27, 2016

A more complete fix in CL 24488. It might be too big for 1.7 though.

@gopherbot

This comment has been minimized.

Copy link

commented Jun 27, 2016

CL https://golang.org/cl/24488 mentions this issue.

gopherbot pushed a commit that referenced this issue Jun 27, 2016

cmd/vet: fix name check for examples in _test package
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>

@ianlancetaylor ianlancetaylor changed the title x/tools/cmd/vet: go1.7 not finding ExampleT_M identifiers cmd/vet: go1.7 not finding ExampleT_M identifiers Jun 27, 2016

@ianlancetaylor ianlancetaylor added this to the Go1.7Maybe milestone Jun 27, 2016

@adg adg self-assigned this Jun 27, 2016

@gopherbot gopherbot closed this in 85a4f44 Jun 28, 2016

@golang golang locked and limited conversation to collaborators Jun 28, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.