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: should include packages without tests in cover profile file #27261

Closed
13rac1 opened this issue Aug 27, 2018 · 1 comment
Closed

cmd/go: should include packages without tests in cover profile file #27261

13rac1 opened this issue Aug 27, 2018 · 1 comment

Comments

@13rac1
Copy link
Contributor

13rac1 commented Aug 27, 2018

What version of Go are you using (go version)?

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOOS="linux"

What did you do?

Created a new project with two sub-packages:

.
├── notests
│   └── notests.go
└── tests
    ├── tests.go
    └── tests_test.go

2 directories, 3 files

notests/notests.go

package notests

import "fmt"

func untested() {
	fmt.Print("untested")
}

tests/tests.go

package tests

import "fmt"

func tested() {
	fmt.Print("tested")
}

tests/tests_test.go

package tests

import "testing"

func TestTested(t *testing.T) {
	tested()
}

Ran go test ./... -v -cover -coverprofile cover.out

What did you expect to see?

$ cat cover.out
mode: set
empty-cover-profile/notests/notests.go:7.17,9.2 1 0
empty-cover-profile/tests/tests.go:7.15,9.2 1 1

Coverage details for both files.

#18909 requested this functionality, but it wasn't implemented in https://golang.org/cl/76875.

What did you see instead?

$ cat cover.out
mode: set
empty-cover-profile/tests/tests.go:7.15,9.2 1 1

Coverage details only for the file with a test in the same directory.

Workaround

echo "package notests" > notests/notests_test.go

Creating an empty test file creates coverage for both files.

@13rac1
Copy link
Contributor Author

13rac1 commented Aug 27, 2018

Dupe of #24570

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

2 participants