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

Wrong report for generics #1624

Open
623637646 opened this issue Sep 19, 2024 · 3 comments
Open

Wrong report for generics #1624

623637646 opened this issue Sep 19, 2024 · 3 comments
Assignees

Comments

@623637646
Copy link

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".

@623637646 623637646 changed the title Wrong report for generic generics Wrong report for generics Sep 19, 2024
@623637646
Copy link
Author

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

@xd009642
Copy link
Owner

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

@623637646
Copy link
Author

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

623637646 pushed a commit to 623637646/rx-rust that referenced this issue Sep 28, 2024
Ryan1729 added a commit to Ryan1729/mtg-pet-simulator that referenced this issue Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants