rillig / gobco

Measure branch coverage of golang tests
62 stars 12 forks source link

Does the coverage of a Package calculated only by the tests in same package #31

Open visu-suganya opened 6 months ago

visu-suganya commented 6 months ago

Hi @rillig

First of all Thanks so much for Branch(C1) and Condition(C2) coverage implementation. It helps us a lot.

I have to find C1 for whole project. So I planned to pass packages one by one to get whole coverage. In this case: Is the package coverage rate (C1) that can be measured by gobco limited to the portion of the test code in the same package that passes? For example, if there are packages A and B, and a function in package A is only tested within package B, will the test coverage of package A be 0%?

rillig commented 6 months ago

Hi @visu-suganya, gobco is currently limited to checking the coverage of a single directory, using only the tests from that same directory.

I didn't implement the multi-directory coverage because I didn't want to duplicate all the logic of scanning for nested go packages in a directory, see https://github.com/rillig/gobco/issues/12.

If you know how the magic argument ./... is interpreted exactly or would like to try it out, feel free to hack gobco. The basic idea is:

Here are a few entry points:

So it may be as simple as connecting all these parts. I didn't badly need this feature up to now, that's why I didn't implement it.

visu-suganya commented 6 months ago

Thanks for your detailed reply @rillig I Just want to know the background of coverage calculation when passing single package.

As a result, if the unit test is in other package, coverage will not be calculated with the current implementation of gobco....!!!

Gobco can already merge several coverage result files, see gobco_fixed.go, look for GOBCO_STATS

I will explore this. Thank you.

It would be helpful if you give us any example (syntax to be used) to merge the results if possible.