Wrong report for generics
Opened this issue · 3 comments
623637646 commented
Describe the bug
Wrong code coverage when using Generics.
Using commend: cargo tarpaulin --out html
Platform: Mac 14.5
To Reproduce
Demo code:
pub fn print_123_if_ok<T>(event: Result<T, String>) {
if let Result::Ok(value) = event {
println!("123");
}
}
#[cfg(test)]
mod tests {
use crate::print_123_if_ok;
#[test]
fn test_my_function_none() {
print_123_if_ok(Ok(1));
}
}
The report is "66.67% coverage, 2/3 lines covered".
Expected behavior
The report should be "100% coverage, 3/3 lines covered".
623637646 commented
Another case which should be 100% coverage:
pub struct Disposal<F>
where
F: FnOnce(),
{
action: Option<F>,
}
impl<F> Drop for Disposal<F>
where
F: FnOnce(),
{
fn drop(&mut self) {
if let Some(action) = self.action.take() {
action();
}
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_drop() {
let disposal = super::Disposal {
action: Some(|| {
println!("Dropping");
}),
};
drop(disposal);
}
}
xd009642 commented
You can also try adding in --engine llvm
to your tarpaulin call and seeing if that improves things 👀