xd009642/tarpaulin

Wrong report for generics

Opened this issue · 3 comments

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".
Screenshot 2024-09-19 at 2 34 44 PM

Expected behavior

The report should be "100% coverage, 3/3 lines covered".

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);
    }
}
Screenshot 2024-09-19 at 2 45 36 PM

You can also try adding in --engine llvm to your tarpaulin call and seeing if that improves things 👀

@xd009642 I tried cargo tarpaulin --out Html --engine llvm. The issue is still there.