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

Collect coverage for the tests themselves #229

Closed
orenbenkiki opened this issue May 19, 2019 · 4 comments
Closed

Collect coverage for the tests themselves #229

orenbenkiki opened this issue May 19, 2019 · 4 comments
Assignees
Milestone

Comments

@orenbenkiki
Copy link

Currently, running kcov only generates coverage for files under the src/ directory. In my case, I would like to be able to also collect coverage for the files under the tests/ directory.

Looking at Makefile.stable.toml, the command line is: kcov --include-pattern=${CARGO_MAKE_WORKING_DIRECTORY}/src/ ...; There doesn't seem to be any environment variable one could set to request that the tests/ directory would also be included in the coverage.

How about something like CARGO_MAKE_KCOV_INCLUDE_TESTS or perhaps a more general CARGO_MAKE_KCOV_INCLUDE_PATTERN?

@sagiegurari
Copy link
Owner

will probably move that pattern to the config to enable overriding as I feel its not correct to show coverage value to include non library code (having unit test in is bad enough but hard to split out).

@sagiegurari sagiegurari added this to the 0.19.2 milestone May 19, 2019
@orenbenkiki
Copy link
Author

orenbenkiki commented May 19, 2019

For me, the coverage is less about reaching a specific high percentage; it is about visibility of which lines are covered. Hence https://crates.io/crates/cargo-coverage-annotations which ensures that any lines that are not executed are explicitly marked with a // NOT TESTED comment (or variants).

I found this helps in figuring out what's happening in the code; on multiple occasions I was surprised that certain code paths were not taken, even though I expected them to. Yes, I know, pure TDD avoids this, but even then refactoring loses the tight connection between coverage and tests.

I would like the same certainty that all my code paths in the test code are actually reached. Admittedly, test code is typically trivial so this doesn't matter as much, but for the rare cases it does matter, it would be nice to have this ability. If nothing else, this would allow me to avoid having to place a // FILE NOT TESTED comment at the start of each test file. This comment is really jarring...

So absolutely no argument that the default should be only the src. I'm just asking for the ability explicitly to shoot myself in the foot ;-)

@sagiegurari
Copy link
Owner

@orenbenkiki I modified task coverage-kcov and setup the env var there, so it can be overridden on the task level (this is mainly because CARGO_MAKE_WORKING_DIRECTORY can dynamically change per task via cwd attribute).
this is now available in a development branch

@orenbenkiki
Copy link
Author

Thanks!

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

No branches or pull requests

2 participants