Forgive me, if this is a stupid request, but I have almost no experience in test driven developement and I'm just getting started with Rust.
But I have a simple program, with some functions I don't want to test. For example the main (), which changes a lot and is basically a few lines of "glue" code for functions from other modules.
I think a way to exclude such code from coverage with a rust attribute or a command line argument could help focusing on other parts of the code which are really lacking test coverage.
It's not a stupid request, I know kcov provides this by putting comment tags to show blocks to ignore. The next release of tarpaulin will let users exclude files from coverage (with wildcards!) But not parts of a single file.
So next release or if you want to use the current development one you could exclude main.rs. I have considered this but am loathe to make people tag comments into code, I don't think a coverage tool should change how the code base looks, so I'll look into other solutions!
I'd suggest using scoped attributes in Rust so it'd look like:
#[tarpaulin::exclude]
fn foo() {}
I believe that's nightly only still however.
As to your general feeling of how coverage tools shouldn't affect the source code.. consider how rustfmt affects the source code indirectly if I mark a function with rustfmt::skip; and, consider that if I had functions which simply aren't called during tests then the current approach (exclude a file) would require me to restructure my code to keep such functions in their own file.
@mehcode I'll look into adding attributes as I prefer that as a solution instead of comment tags like kcov uses.
So scoped attributes are also referred to as tool attributes and are only available for tools packaged with rustup (so clippy and rustfmt are the only ones using them current afaik). However, there is a solution cfg_attr.
Now users can put #[cfg_attr(tarpaulin, skip)] over modules, functions, traits, impls, and methods to remove those blocks from coverage results. This has been implemented along with a full suite of tests and merged into develop if you want to use it early. If not I'll probably release 0.6.1 near the end of the week.
Cheers @mehcode for pointing me in the right direction :+1:
Most helpful comment
It's not a stupid request, I know kcov provides this by putting comment tags to show blocks to ignore. The next release of tarpaulin will let users exclude files from coverage (with wildcards!) But not parts of a single file.
So next release or if you want to use the current development one you could exclude
main.rs. I have considered this but am loathe to make people tag comments into code, I don't think a coverage tool should change how the code base looks, so I'll look into other solutions!