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

Weird filter behavior if module is named tests #421

Open
ede1998 opened this issue Feb 18, 2025 · 3 comments
Open

Weird filter behavior if module is named tests #421

ede1998 opened this issue Feb 18, 2025 · 3 comments
Labels
C-documentation Category: related to documentation. C-question Category: A question

Comments

@ede1998
Copy link

ede1998 commented Feb 18, 2025

I read in another issue (#123) that integration tests are automatically excluded from coverage reports while unit tests are not (so far).

This lead to a situation that had me very confused at first:
I have a module named tests in my crate that contains tests and test helper code.

Actual behavior:
The submodules of the tests module are ignored in coverage reporting but tests.rs is not.
My assumption is that it's probably because of the filtering for integration tests.
I was very confused at first and thought the coverage collection is not working properly or sth.

Desired behavior:
Either ignore all of the unit test code or none of it.

Minimal example:

src/
├── lib.rs
├── tests
│   └── example.rs
└── tests.rs

src/tests.rs

mod example;

src/tests/example.rs

fn hello_world() {
    println!("Hello");
}

src/lib.rs

mod tests;
@taiki-e
Copy link
Owner

taiki-e commented Feb 19, 2025

Both readme and top-level comment of #123 says:

cargo-llvm-cov excludes code contained in the directory named tests from the report by default

Excluding tests.rs is proposed in #123 (comment) and I agreed with it in #123 (comment), but no one has implemented it yet. PR to implement it is welcome.

@ede1998
Copy link
Author

ede1998 commented Feb 22, 2025

Good to know. Don't have the bandwidth for the PR atm.

I didn't find a reference to the default exclusions in the README btw.

(And I assumed the top-level comment was referring to the tests directory for integration tests because it is named along side examples.)

One such that just popped in my mind: Is there a way to un-exclude the tests module? When I quickly tried it out, I didn't find a way.

@taiki-e
Copy link
Owner

taiki-e commented Feb 23, 2025

I didn't find a reference to the default exclusions in the README btw.

One such that just popped in my mind: Is there a way to un-exclude the tests module? When I quickly tried it out, I didn't find a way.

Now documented by 8e02736. See https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#exclude-file-from-coverage.

@taiki-e taiki-e added C-documentation Category: related to documentation. C-question Category: A question labels Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-documentation Category: related to documentation. C-question Category: A question
Projects
None yet
Development

No branches or pull requests

2 participants