Skip to content

Commit e5f10ee

Browse files
joshwlewisedmorley
andauthored
Add coverage reporting via cargo-llvm-cov (#349)
* Add coverage reporting via cargo-llvm-cov * Update .github/workflows/ci.yml Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com> Signed-off-by: Josh W Lewis <josh.w.lewis@gmail.com> * Update .github/workflows/ci.yml Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com> Signed-off-by: Josh W Lewis <josh.w.lewis@gmail.com> --------- Signed-off-by: Josh W Lewis <josh.w.lewis@gmail.com> Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
1 parent 328272b commit e5f10ee

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

.github/workflows/ci.yml

+25
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,31 @@ jobs:
4040
- name: Run unit tests
4141
run: cargo test --locked
4242

43+
unit-test-coverage:
44+
name: Generate test coverage report
45+
runs-on: ubuntu-24.04
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v4
49+
with:
50+
submodules: true
51+
- name: Install nightly Rust toolchain
52+
run: rustup install nightly
53+
- name: Rust Cache
54+
uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7
55+
- name: Install cargo-llvm-cov
56+
uses: taiki-e/install-action@62730e3d4f6bd81d824694e963e06d7153968c93 # v2.49.29
57+
with:
58+
tool: cargo-llvm-cov
59+
- name: Run unit tests and generate coverage report
60+
run: cargo +nightly llvm-cov --locked --html
61+
- name: Upload HTML coverage report
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: "llvm-cov-html-${{github.event.repository.name}}-${{github.sha}}"
65+
path: "target/llvm-cov/html"
66+
if-no-files-found: "error"
67+
4368
integration-test:
4469
name: integration-tests ${{ matrix.builder }} / ${{ matrix.arch }}
4570
runs-on: ${{ matrix.arch == 'arm64' && 'pub-hk-ubuntu-24.04-arm-medium' || 'ubuntu-24.04' }}

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ edition = "2021"
1010
unreachable_pub = "warn"
1111
unsafe_code = "warn"
1212
unused_crate_dependencies = "warn"
13+
# Allows the usage of cfg(coverage_nightly).
14+
# cargo-llvm-cov enables that config when instrumenting our code, so we can enable
15+
# the experimental coverage_attribute feature.
16+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)'] }
1317

1418
[workspace.lints.clippy]
1519
panic_in_result_fn = "warn"

buildpacks/go/src/main.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// cargo-llvm-cov sets the coverage_nightly attribute when instrumenting our code. In that case,
2+
// we enable https://doc.rust-lang.org/beta/unstable-book/language-features/coverage-attribute.html
3+
// to be able selectively opt out of coverage for functions/lines/modules.
4+
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
5+
16
mod cfg;
27
mod cmd;
38
mod layers;

0 commit comments

Comments
 (0)