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

Coverage for a single package inside a workspace #361

Open
lasantosr opened this issue Apr 4, 2024 · 1 comment
Open

Coverage for a single package inside a workspace #361

lasantosr opened this issue Apr 4, 2024 · 1 comment
Labels
C-bug Category: related to a bug.

Comments

@lasantosr
Copy link

lasantosr commented Apr 4, 2024

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:

  • Cargo.toml:
    [workspace]
    members = ["crate-a", "crate-b"]
  • crate-a/Cargo.toml:
    [package]
    name = "crate-a"
    version = "0.1.0"
    edition = "2021"
    [dependencies]
  • crate-a/src/lib.rs:
    pub fn say_hello() {
        println!("Hello, world!");
    }
    
    #[cfg(test)]
    mod test {
        #[test]
        fn test_say_hello() {
            super::say_hello();
        }
    }
  • crate-b/Cargo.toml:
    [package]
    name = "crate-b"
    version = "0.1.0"
    edition = "2021"
    [dependencies]
    crate-a = { path = "../crate-a" }
  • crate-b/src/lib.rs:
    pub fn say_hello_goodby() {
        crate_a::say_hello();
        println!("Goodby!");
    }
    
    #[cfg(test)]
    mod test {
        #[test]
        fn test_say_hello_goodby() {
            super::say_hello_goodby();
        }
    }

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 taiki-e added the C-bug Category: related to a bug. label Apr 5, 2024
@taiki-e
Copy link
Owner

taiki-e commented Apr 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: related to a bug.
Projects
None yet
Development

No branches or pull requests

2 participants