Skip to content

Invalid line coverage for multiple partially covered derive macros #404

Open
@treiher

Description

@treiher

If multiple derive macros are used, and one is covered and one is uncovered, the results shown in the llvm-cov output will not match the output produced by json.get_uncovered_lines(). While llvm-cov considers the line to be uncovered, json.get_uncovered_lines() considers the line to be covered. So even if there is a missing line, --show-missing-lines will not show the affected line and --fail-uncovered-lines 0 will have no effect.

Here is a reproducer:

use strum::{Display, EnumIter};

#[derive(Display, EnumIter, Clone, Debug, PartialEq)]
pub enum Foo {
    A = 0,
    B = 1,
}

#[cfg(test)]
mod tests {
    use strum::IntoEnumIterator;

    use super::*;

    #[test]
    fn test_foo_serde() {
        for foo in Foo::iter() {
            assert_eq!(foo, foo.clone());
        }
    }
}
Filename       Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
src/lib.rs           9                 2    77.78%           3                 1    66.67%           6                 1    83.33%           0                 0         -
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                9                 2    77.78%           3                 1    66.67%           6                 1    83.33%           0                 0         -

The function created by the strum::EnumIter macro is tested, while the function created by the strum::Display macro is not. llvm-cov considers line 3 to be uncovered, but this line is considered to be covered by json.get_uncovered_lines(). This issue is caused by the following code, which was added to fix #181:

cargo-llvm-cov/src/json.rs

Lines 268 to 270 in b7e5eb5

if let Some(covered_lines) = covered_files.get(file_name) {
uncovered_lines.retain(|&x| !covered_lines.contains(&x));
}

Unfortunately, I don't see a simple solution which wouldn't add a regression. Any ideas?

Using the JSON output for --fail-uncovered-lines would already be an improvement, so that at least the exit code would be correct, even if some lines in --show-missing-lines are missing. What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions