Skip to content

Commit e074f19

Browse files
committed
chore: Don't consider test code “code under test”
changelog: ignore
1 parent 1540892 commit e074f19

21 files changed

Lines changed: 51 additions & 15 deletions

.github/workflows/coverage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jobs:
1616
- name: Checkout repository
1717
uses: actions/checkout@v4
1818

19-
- name: Install stable toolchain
20-
uses: dtolnay/rust-toolchain@stable
19+
- name: Install nightly toolchain
20+
uses: dtolnay/rust-toolchain@nightly
2121
with:
2222
components: llvm-tools-preview
2323

@@ -28,7 +28,7 @@ jobs:
2828
uses: taiki-e/install-action@nextest
2929

3030
- name: Collect coverage data
31-
run: cargo llvm-cov nextest --all-targets --lcov --output-path lcov.info
31+
run: cargo +nightly llvm-cov nextest --all-targets --lcov --output-path lcov.info
3232

3333
- name: Upload coverage to coveralls.io
3434
uses: coverallsapp/github-action@v2

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ readme = "README.md"
1515

1616
[workspace.lints]
1717

18+
[workspace.lints.rust]
19+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)'] }
20+
1821
[profile.release]
1922
lto = "thin"

bfieldcodec_derive/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,7 @@ impl BFieldCodecErrorEnumBuilder {
11731173
}
11741174

11751175
#[cfg(test)]
1176+
#[cfg_attr(coverage_nightly, coverage(off))]
11761177
mod tests {
11771178
use syn::parse_quote;
11781179

twenty-first/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
#![deny(clippy::shadow_unrelated)]
2+
//
3+
// If code coverage tool `cargo-llvm-cov` is running with the nightly toolchain,
4+
// enable the unstable “coverage” attribute. This allows using the annotation
5+
// `#[coverage(off)]` to explicitly exclude certain parts of the code from
6+
// being considered as “code under test.” Most prominently, the annotation
7+
// should be added to every `#[cfg(test)]` module. Since the “coverage”
8+
// feature is enable only conditionally, the annotation to use is:
9+
// #[cfg_attr(coverage_nightly, coverage(off))]
10+
//
11+
// See also:
12+
// - https://github.com/taiki-e/cargo-llvm-cov#exclude-code-from-coverage
13+
// - https://github.com/rust-lang/rust/issues/84605
14+
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
15+
216
pub mod config;
317
pub mod error;
418
pub mod math;
@@ -20,6 +34,7 @@ extern crate self as twenty_first;
2034
pub use bfieldcodec_derive;
2135

2236
#[cfg(test)]
37+
#[cfg_attr(coverage_nightly, coverage(off))]
2338
pub(crate) mod tests {
2439
use prelude::*;
2540

twenty-first/src/math/b_field_element.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,8 @@ impl PrimitiveRootOfUnity for BFieldElement {
793793
}
794794

795795
#[cfg(test)]
796-
mod b_prime_field_element_test {
796+
#[cfg_attr(coverage_nightly, coverage(off))]
797+
mod tests {
797798
use std::collections::hash_map::DefaultHasher;
798799
use std::hash::Hasher;
799800

twenty-first/src/math/bfield_codec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ impl<T> BFieldCodec for PhantomData<T> {
593593
}
594594

595595
#[cfg(test)]
596+
#[cfg_attr(coverage_nightly, coverage(off))]
596597
mod tests {
597598
use num_traits::ConstZero;
598599
use num_traits::Zero;
@@ -894,8 +895,7 @@ mod tests {
894895
/// See also: https://github.com/rust-lang/cargo/issues/8379#issuecomment-1261970561
895896
///
896897
/// [^1]: almost-cyclic because the dependency would be a dev-dependency
897-
#[cfg(test)]
898-
pub mod derive_tests {
898+
pub mod derive {
899899
use arbitrary::Arbitrary;
900900
use num_traits::Zero;
901901

twenty-first/src/math/lattice.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,8 @@ pub mod kem {
813813
}
814814

815815
#[cfg(test)]
816-
mod test {
816+
#[cfg_attr(coverage_nightly, coverage(off))]
817+
mod tests {
817818
use super::*;
818819

819820
#[test]
@@ -832,7 +833,8 @@ pub mod kem {
832833
}
833834

834835
#[cfg(test)]
835-
mod lattice_test {
836+
#[cfg_attr(coverage_nightly, coverage(off))]
837+
mod tests {
836838
use itertools::Itertools;
837839
use num_traits::ConstOne;
838840
use num_traits::Zero;

twenty-first/src/math/ntt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ pub fn twiddle_factors(slice_len: u32, root_of_unity: BFieldElement) -> Vec<Vec<
307307
}
308308

309309
#[cfg(test)]
310+
#[cfg_attr(coverage_nightly, coverage(off))]
310311
mod tests {
311312
use itertools::Itertools;
312313
use num_traits::ConstZero;

twenty-first/src/math/polynomial.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2701,7 +2701,8 @@ where
27012701
}
27022702

27032703
#[cfg(test)]
2704-
mod test_polynomials {
2704+
#[cfg_attr(coverage_nightly, coverage(off))]
2705+
mod tests {
27052706
use num_traits::ConstZero;
27062707
use proptest::collection::size_range;
27072708
use proptest::collection::vec;

twenty-first/src/math/x_field_element.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ impl ModPowU32 for XFieldElement {
658658
}
659659

660660
#[cfg(test)]
661+
#[cfg_attr(coverage_nightly, coverage(off))]
661662
mod tests {
662663
use itertools::Itertools;
663664
use itertools::izip;

0 commit comments

Comments
 (0)