Skip to content

Commit 527037c

Browse files
CopilotValuedMammal
authored andcommitted
ci(coverage): Switch to cargo-llvm-cov for code coverage
- Updated .github/workflows/code_coverage.yml to use cargo-llvm-cov instead of grcov - Removed environment variables (RUSTFLAGS, RUSTDOCFLAGS, LLVM_PROFILE_FILE) - Switched to nightly toolchain for coverage generation - Enabled coverage_nightly config attribute in lib.rs - Added coverage(off) attribute to all test modules to exclude them from coverage reports - Added lint config for coverage_nightly cfg to Cargo.toml - Also add lcov.info to .gitignore to prevent accidental commits
1 parent bb9b07f commit 527037c

17 files changed

Lines changed: 33 additions & 19 deletions

File tree

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Code Coverage
22

3-
# Generates code coverage reports using grcov and uploads results to Codecov.
3+
# Generates code coverage reports using cargo-llvm-cov and uploads results to Codecov.
44
# Runs on every push and pull request to track test coverage metrics.
55
# Uploads coverage data to Codecov for tracking and produces an HTML report artifact for download.
66

@@ -14,38 +14,32 @@ jobs:
1414
Coverage:
1515
name: Code Coverage
1616
runs-on: ubuntu-latest
17-
env:
18-
RUSTFLAGS: "-Cinstrument-coverage"
19-
RUSTDOCFLAGS: "-Cinstrument-coverage"
20-
LLVM_PROFILE_FILE: "./target/coverage/%p-%m.profraw"
2117

2218
steps:
2319
- name: Checkout
2420
uses: actions/checkout@v6
2521
with:
2622
persist-credentials: false
27-
- name: Install lcov tools
28-
run: sudo apt-get install lcov -y
29-
# This action automatically reads and applies rust-toolchain.toml
3023
- name: Install Rust toolchain
3124
uses: actions-rust-lang/setup-rust-toolchain@v1
3225
with:
26+
toolchain: nightly
3327
components: llvm-tools-preview
3428
cache: true
35-
- name: Install grcov
36-
run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install grcov; fi
37-
- name: Test
38-
run: cargo test --all-features
39-
- name: Make coverage directory
40-
run: mkdir coverage
41-
- name: Run grcov
42-
run: grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --keep-only 'src/**' --ignore 'tests/**' --ignore 'examples/**' -o ./coverage/lcov.info
29+
- name: Install cargo-llvm-cov
30+
run: cargo install cargo-llvm-cov
31+
- name: Generate coverage data
32+
run: cargo llvm-cov --all-features --branch --quiet --ignore-filename-regex "test_utils" --lcov --output-path lcov.info
33+
env:
34+
RUSTFLAGS: "--cfg coverage_nightly"
4335
- name: Generate HTML coverage report
44-
run: genhtml -o coverage-report.html --ignore-errors unmapped ./coverage/lcov.info
36+
run: cargo llvm-cov --all-features --branch --quiet --ignore-filename-regex "test_utils" --html
37+
env:
38+
RUSTFLAGS: "--cfg coverage_nightly"
4539
- name: Codecov upload
4640
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7
4741
with:
48-
files: ./coverage/lcov.info
42+
files: ./lcov.info
4943
flags: rust
5044
name: codecov-bdk-wallet
5145
token: ${{ secrets.CODECOV_TOKEN }}
@@ -54,4 +48,4 @@ jobs:
5448
uses: actions/upload-artifact@v6
5549
with:
5650
name: coverage-report
57-
path: coverage-report.html
51+
path: target/llvm-cov/html

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ Cargo.lock
99
*.db
1010
*.sqlite*
1111
examples/test_data
12+
13+
# Coverage reports
14+
lcov.info

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ rust-version = "1.85.0"
1616
all-features = true
1717
rustdoc-args = ["--cfg", "docsrs"]
1818

19+
[lints.rust]
20+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)'] }
21+
1922
[dependencies]
2023
bdk_chain = { version = "0.23.1", features = ["miniscript", "serde"], default-features = false }
2124
bitcoin = { version = "0.32.7", features = ["serde", "base64"], default-features = false }

src/descriptor/checksum.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub fn calc_checksum(desc: &str) -> Result<String, DescriptorError> {
3434
}
3535
}
3636

37+
#[cfg_attr(coverage_nightly, coverage(off))]
3738
#[cfg(test)]
3839
mod test {
3940
use super::*;

src/descriptor/dsl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ macro_rules! fragment {
823823
});
824824
}
825825

826+
#[cfg_attr(coverage_nightly, coverage(off))]
826827
#[cfg(test)]
827828
mod test {
828829
use alloc::string::ToString;

src/descriptor/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ impl DescriptorMeta for ExtendedDescriptor {
609609
}
610610
}
611611

612+
#[cfg_attr(coverage_nightly, coverage(off))]
612613
#[cfg(test)]
613614
mod test {
614615
use alloc::string::ToString;

src/descriptor/policy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,7 @@ impl ExtractPolicy for Descriptor<DescriptorPublicKey> {
11731173
}
11741174
}
11751175

1176+
#[cfg_attr(coverage_nightly, coverage(off))]
11761177
#[cfg(test)]
11771178
mod test {
11781179
use super::*;

src/descriptor/template.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ expand_make_bipxx!(legacy, Legacy);
632632
expand_make_bipxx!(segwit_v0, Segwitv0);
633633
expand_make_bipxx!(segwit_v1, Tap);
634634

635+
#[cfg_attr(coverage_nightly, coverage(off))]
635636
#[cfg(test)]
636637
mod test {
637638
// Test existing descriptor templates to make sure they are expanded to the right descriptors.

src/keys/bip39.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ impl<Ctx: ScriptContext> GeneratableKey<Ctx> for Mnemonic {
149149
}
150150
}
151151

152+
#[cfg_attr(coverage_nightly, coverage(off))]
152153
#[cfg(test)]
153154
mod test {
154155
use super::WordCount;

src/keys/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@ impl fmt::Display for KeyError {
10411041
#[cfg(feature = "std")]
10421042
impl std::error::Error for KeyError {}
10431043

1044+
#[cfg_attr(coverage_nightly, coverage(off))]
10441045
#[cfg(test)]
10451046
mod test {
10461047
use super::*;

0 commit comments

Comments
 (0)