cargo-llvm-cov icon indicating copy to clipboard operation
cargo-llvm-cov copied to clipboard

Add an option to merge coverage of generics in the summary

Open larsluthman opened this issue 4 years ago • 2 comments

First, thanks for a very useful tool!

It would be nice if there was an command line option to merge the coverage of different instantiations of generic functions in the summary of the coverge of a file, so that it would show 100% coverage if the tests covered all of a generic function, even if different regions of the function were covered by different instantiations. Consider the following source file:

fn smaller_than_default<T: Default + PartialOrd>(t: T) -> bool {
    if t < T::default() { true }
    else { false }
}

#[test]
fn test_instantiations() {
    assert!(!smaller_than_default(56.4_f32));
    assert!(smaller_than_default(-56_i32));
}

With cargo-llvm-cov 0.1.0-alpha.4, the report will show a region coverage of 88.89% (8/9), even though all regions of the generic function are marked as covered. The current rule seems to be that there needs to be at least one instantiation with 100% coverage for the generic function to be counted as 100% covered. This is probably a good choice for some situations, but sometimes you have a generic function that is difficult to cover completely with a single instantiation and for those cases it would be nice to have an option to merge the coverage of all instantiations when computing the summary.

larsluthman avatar Aug 07 '21 10:08 larsluthman

This seems reasonable to me.

~~Probably, we can implement this by adding a CLI option to disable -show-instantiations in the following code.~~

taiki-e avatar Aug 07 '21 10:08 taiki-e

Probably, we can implement this by adding a CLI option to disable -show-instantiations in the following code.

Hmm, I'm not sure how this can be implemented on our side because the llvm-cov report command used to output the summary does not have a similar flag.

taiki-e avatar Aug 07 '21 17:08 taiki-e