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/cover: doesn't respect examples #8466

metakeule opened this issue Aug 2, 2014 · 4 comments

cmd/cover: doesn't respect examples #8466

metakeule opened this issue Aug 2, 2014 · 4 comments


Copy link

What does 'go version' print?

What steps reproduce the problem?
If possible, include a link to a program on

1. create a package
2. create a test case as example
3. run go test --cover

What happened?
the example does not contribute to the coverage

What should have happened instead?
the example should contribute to the coverage since it's
a test and run with go test
Copy link

Comment 1:

Labels changed: added repo-tools, release-go1.4.

Copy link

adg commented Aug 7, 2014

Comment 2:

I am unable to reproduce this. Coverage works fine with examples.
Are you including an "Output:" comment in your example function? If not, the example
won't be executed as a test. Use "go test -v" to make sure your examples are being
Here's my successful test run:
~/src/covertest $ cat foo.go
package foo
import "fmt"
func Foo() {
~/src/covertest $ cat foo_test.go 
package foo
func ExampleFoo() {
    // Output: yay
~/src/covertest $ go test -v -cover
=== RUN: ExampleFoo
--- PASS: ExampleFoo (0.00s)
coverage: 100.0% of statements
ok      covertest   0.010s

Owner changed to @adg.

Status changed to WaitingForReply.

Copy link

Comment 3:

You are right: "// Output:" was missing. Sorry for the noise.

Copy link

robpike commented Aug 22, 2014

Comment 4:

Status changed to Invalid.

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc unassigned adg Jun 23, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

6 participants