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/go: go test -coverprofile produces no profile if there are no test files. #6725

Closed
augustoroman opened this issue Nov 6, 2013 · 7 comments

Comments

@augustoroman
Copy link
Contributor

To reproduce, run in the GOPATH root:
    mkdir z/
    echo -e 'package z\nfunc x() { println("x") }' > z/z.go
    go test -coverprofile=c.out z

Expected behavior:
  c.out created indicating 0% test coverage (no statements of z.go are covered)

Actual behavior:
  No c.out created.

However, if a test file exists:
    echo "package z" > z/z_test.go
    go test -coverprofile=c.out z
    # c.out created showing no statements covered

Then c.out is created as expected.


The current behavior is problematic in my script that automatically generates coverage
for a directory tree -- there is no indication in the output for packages that have no
tests.


Go: go version go1.2rc3 darwin/amd64
OS: OS X 10.8.5
@adg
Copy link
Contributor

adg commented Nov 7, 2013

Comment 1:

Similarly, "go test -cover" doesn't report coverage for packages without tests.
$ go test -cover
?       unsafe  [no test files]
This is either WorkingAsIntended or a bug. I'll let Rob decide which.

Owner changed to @robpike.

@adg
Copy link
Contributor

adg commented Nov 7, 2013

Comment 2:

Status changed to WaitingForReply.

@augustoroman
Copy link
Contributor Author

Comment 3:

If this is accepted as a bug, I would prefer to get this fixed for the 1.2 release if
possible so that the functionality is not changed in later releases.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 4:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 5:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 6:

Labels changed: added repo-main.

@robpike
Copy link
Contributor

robpike commented Sep 24, 2014

Comment 7:

If there are no tests there is no cpuprofile either.

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc unassigned robpike Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants