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