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

Comments

Projects
None yet
1 participant
@13rac1
Copy link

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

This comment has been minimized.

Copy link
Author

commented Aug 27, 2018

Dupe of #24570

@13rac1 13rac1 closed this Aug 27, 2018

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