wadey/gocovmerge

merging cover profiles with the same files doesn't add to coverage

dougnukem opened this issue · 3 comments

When running coverage doing an integration tests (e.g. generating coverage for other packages in my project that get covered when a test runs).

Using go test -coverpkg=pkgA,pkgB,pkgC -coverprofile=profile.cover ./subpackage

I think it's because the same go files are represented in the merged cover profile and the last entry counts, it should be calculating the total aggregate coverage if it processes files of the same name.

wadey commented

This should work. Can you give a more exact example, perhaps the generated coverprofile files and the arguments you are passing to gocovmerge to merge them?

You should be outputting to multiple -coverprofile files and then passing them as arguments to gocovmerge like:

go test -coverpkg=pkgA,pkgB,pkgC -coverprofile=profile1.cover ./subpackage1
go test -coverpkg=pkgA,pkgB,pkgC -coverprofile=profile2.cover ./subpackage2
gocovmerge profile1.cover profile2.cover >merged.cover

Is this how you are using it?

Actually I think my issue was I was using go list -f to generate the -coverpkg=... and was forgetting to put in the package itself e.g.

# Generates package dependencies of pkga
go list -f '{{range $i, $f := .Deps}}{{if eq (printf "%.26s" $f) "github.com/legit/woodhouse" }}{{$f}},{{end}}{{end}}'` pkga

I needed to also include the package itself:

# Generates package dependencies of pkga including a to pass to -coverpkg
go list -f '{{range $i, $f := .Deps}}{{if eq (printf "%.26s" $f) "github.com/legit/woodhouse" }}{{$f}},{{end}}{{end}}{{.ImportPath}}'` pkga
wadey commented

Ah, that makes sense. I'll go ahead and close this issue then as it sounds like you resolved it.