taiki-e / cargo-llvm-cov

Cargo subcommand to easily use LLVM source-based code coverage (-C instrument-coverage).
Apache License 2.0
920 stars 57 forks source link

Coverage for a single package inside a workspace #361

Open lasantosr opened 6 months ago

lasantosr commented 6 months ago

I've faced the same issue as #278, i'll try to provide a reproducible example:

Create a new workspace with the following structure:

├── Cargo.toml
├── crate-a
│   ├── Cargo.toml
│   └── src
│       └── lib.rs
└── crate-b
    ├── Cargo.toml
    └── src
        └── lib.rs

The content of the files:

Run the coverage report just for crate-b: cargo llvm-cov --package crate-b

This is the actual output:

Filename                      Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
crate-a/src/lib.rs                  1                 0   100.00%           1                 0   100.00%           3                 0   100.00%           0                 0         -
crate-b/src/lib.rs                  2                 0   100.00%           2                 0   100.00%           7                 0   100.00%           0                 0         -
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               3                 0   100.00%           3                 0   100.00%          10                 0   100.00%           0                 0         -

This is the expected output:

Filename                      Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
src/lib.rs                          2                 0   100.00%           2                 0   100.00%           7                 0   100.00%           0                 0         -
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                               2                 0   100.00%           2                 0   100.00%           7                 0   100.00%           0                 0         -

It can be achieved ignoring crate-a from the files, but it increases in complexity as the workspace has more members: cargo llvm-cov --package crate-b --ignore-filename-regex '(^|\/)crate-a'

taiki-e commented 6 months ago

Thanks. The problem here appears to be similar to #303, and perhaps something in the implementation of #31 is not working well.