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

Missing coverage when using Rust 1.75.0 #1438

Open
clechasseur opened this issue Dec 31, 2023 · 0 comments
Open

Missing coverage when using Rust 1.75.0 #1438

clechasseur opened this issue Dec 31, 2023 · 0 comments
Assignees

Comments

@clechasseur
Copy link

Describe the bug
OS: macOS Sonoma 14.2.1
Engine: llvm

It looks like when using tarpaulin with Rust 1.75.0, there are erroneous missing line coverage in the report.

To Reproduce
Minimal reproducible project (generated using cargo new foo --lib):

lib.rs

pub fn get_url<U: std::fmt::Display>(url: U, query: Option<&str>) -> String {
    let mut result = url.to_string();
    if let Some(query) = query {
        result += &format!("?{}", query);
    }
    result
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_get_url() {
        let result = get_url("http://zombo.com/", Some("zombo=com"));
        assert_eq!(result, "http://zombo.com/?zombo=com");
    }
}

tarpaulin.toml

[default]
engine = "Llvm"
exclude-files = [ "target*/*" ]
run-types = [ "Tests" ]
out = [ "Html" ]

When running cargo +1.75.0 tarpaulin:

|| Tested/Total Lines:
|| src/lib.rs: 4/5 +0.00%
|| 
80.00% coverage, 4/5 lines covered, +0.00% change in coverage

When running cargo +1.74.1 tarpaulin:

|| Tested/Total Lines:
|| src/lib.rs: 5/5 +20.00%
|| 
100.00% coverage, 5/5 lines covered, +20.00% change in coverage

The missing line in 1.75.0:

pub fn get_url<U: std::fmt::Display>(url: U, query: Option<&str>) -> String {
    let mut result = url.to_string();
    if let Some(query) = query {
        result += &format!("?{}", query); // <== THIS ONE
    }
    result
}

The fact that the get_url function is generic has something to do with this, but it's strange. If I change it to this:

pub fn get_url(url: &str, query: Option<&str>) -> String {
    let mut result = url.to_string();
    if let Some(query) = query {
        result += &format!("?{}", query);
    }
    result
}

And rerun cargo +1.75.0 tarpaulin:

|| Tested/Total Lines:
|| src/lib.rs: 4/4 +20.00%
|| 
100.00% coverage, 4/4 lines covered, +20.00% change in coverage

In this case, the line that was earlier considered uncovered is no longer considered at all.

An example of this in my project: https://app.codecov.io/gh/clechasseur/mini_exercism/commit/9f1d454fc3d0a22c841fbffaa80ddf6c61b8be49

Expected behavior
Lines should be considered covered, just like when using Rust 1.74.1.

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