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

Closed
metakeule opened this issue Aug 2, 2014 · 4 comments
Closed

cmd/cover: doesn't respect examples #8466

metakeule opened this issue Aug 2, 2014 · 4 comments
Assignees
Milestone

Comments

@metakeule
Copy link

@metakeule metakeule commented Aug 2, 2014

What does 'go version' print?
1.3

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

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
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 3, 2014

Comment 1:

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

@adg
Copy link
Contributor

@adg 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
executed.
Here's my successful test run:
~/src/covertest $ cat foo.go
package foo
import "fmt"
func Foo() {
    fmt.Println("yay")
}
~/src/covertest $ cat foo_test.go 
package foo
func ExampleFoo() {
    Foo()
    // Output: yay
}
~/src/covertest $ go test -v -cover
=== RUN: ExampleFoo
--- PASS: ExampleFoo (0.00s)
PASS
coverage: 100.0% of statements
ok      covertest   0.010s

Owner changed to @adg.

Status changed to WaitingForReply.

@metakeule
Copy link
Author

@metakeule metakeule commented Aug 22, 2014

Comment 3:

You are right: "// Output:" was missing. Sorry for the noise.
@robpike
Copy link
Contributor

@robpike 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
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.