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

Code coverage with llvm-cov include tests in covered lines #7

Closed
joshuachp opened this issue Apr 3, 2023 · 3 comments
Closed

Code coverage with llvm-cov include tests in covered lines #7

joshuachp opened this issue Apr 3, 2023 · 3 comments

Comments

@joshuachp
Copy link

joshuachp commented Apr 3, 2023

As you can see here codecov - imap sort.rs, llvm-cov includes the test lines in the total coverage percentage.

This will increase the total percentage since the test lines are counted as covered. Other implementations like cargo-tarpaulin with llvm coverage excludes those test. Do you think those test lines should be skipped or kept?

An alternative could be the following:

diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index c675b38..03fff3f 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -75,13 +75,13 @@ jobs:
         uses: dtolnay/rust-toolchain@stable
         with:
           components: llvm-tools-preview
-      - name: cargo install cargo-llvm-cov
-        uses: taiki-e/install-action@cargo-llvm-cov
+      - name: cargo install cargo-tarpaulin
+        uses: taiki-e/install-action@cargo-tarpaulin
       - name: cargo generate-lockfile
         if: hashFiles('Cargo.lock') == ''
         run: cargo generate-lockfile
-      - name: cargo llvm-cov
-        run: cargo llvm-cov --locked --all-features --lcov --output-path lcov.info
+      - name: cargo tarpaulin
+        run: cargo tarpaulin --engine llvm --locked --all-features --out lcov
       - name: Upload to codecov.io
         uses: codecov/codecov-action@v3
         with:

This implementation could have other disadvantages than llvm-cov, but the coverage should be more representative of the real code. Here and example with the above codecov coverage

@jonhoo
Copy link
Owner

jonhoo commented Apr 8, 2023

I'd prefer for this to be fixed in cargo-llvm-cov rather than switching the coverage driver outright. I think the underlying issue here is taiki-e/cargo-llvm-cov#123, though I don't see an easy path to resolving it. I'm curious how tarpaulin avoids counting unit test code 🤔

cc @taiki-e @xd009642 in case the two of you might exchange ideas on this.

@xd009642
Copy link

xd009642 commented Apr 8, 2023

I use syn and walk through all the source in the project identifying which regions to ignore (in the source_analysis module)

@joshuachp joshuachp closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2023
@joshuachp
Copy link
Author

I'd prefer for this to be fixed in cargo-llvm-cov rather than switching the coverage driver outright. I think the underlying issue here is taiki-e/cargo-llvm-cov#123, though I don't see an easy path to resolving it.

Closing the issue here then. Thanks for the feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants