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

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

Open
visu-suganya opened this issue Jan 25, 2024 · 2 comments

Comments

@visu-suganya
Copy link

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
Copy link
Owner

rillig commented Jan 25, 2024

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 #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:

  • instrument each given directory
  • run all the tests at once, for all the directories
  • merge the coverage results from all directories

Here are a few entry points:

  • gobco.parseArgs panics right now but is already prepared for accepting multiple directories.
  • gobco.runGoTest currently runs go test on each directory separately. I don't remember why.
  • Gobco can already merge several coverage result files, see gobco_fixed.go, look for GOBCO_STATS.

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants