Skip to content

Commit 531f6d4

Browse files
exclude cachet's untestable no-logs telemetry blocks from coverage
`record_{debug,info,error}_with_duration` each contain a `#[cfg(not(any(feature = "logs", test)))]` no-op block that only exists to silence unused-variable warnings when logging is compiled out. Under `--no-default-features` these blocks compile only into non-test builds (notably cachet's examples) and are never executed, so they surfaced as 9 uncovered lines under anvil's nextest-based coverage (which instruments example binaries; oxidizer's libtest `cargo llvm-cov` does not, which is why Codecov shows the file 100%). Add `#[cfg_attr(coverage_nightly, coverage(off))]` to the three functions (and enable `feature(coverage_attribute)` at the crate root) so these untestable discards are not instrumented. cachet goes 99.7% -> 100%. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 604c7d2 commit 531f6d4

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

crates/cachet/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
45
#![cfg_attr(docsrs, feature(doc_cfg))]
56

67
//! A composable, multi-tier caching library with stampede protection, background

crates/cachet/src/telemetry/cache.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ impl CacheTelemetry {
142142
not(feature = "logs"),
143143
expect(clippy::unused_self, reason = "self.logging_enabled is used when logs is enabled")
144144
)]
145+
// The body is a no-op when `logs` is off; under `--no-default-features`
146+
// it only compiles into non-test builds (e.g. examples) and is never
147+
// exercised, so exclude it from coverage rather than chase an untestable
148+
// discard. See telemetry tests for the logs-on path.
149+
#[cfg_attr(coverage_nightly, coverage(off))]
145150
fn record_debug_with_duration(&self, cache_name: CacheName, event: &'static str, duration: Duration) {
146151
#[cfg(any(feature = "logs", test))]
147152
if self.logging_enabled {
@@ -161,6 +166,7 @@ impl CacheTelemetry {
161166
not(feature = "logs"),
162167
expect(clippy::unused_self, reason = "self.logging_enabled is used when logs is enabled")
163168
)]
169+
#[cfg_attr(coverage_nightly, coverage(off))]
164170
fn record_info_with_duration(&self, cache_name: CacheName, event: &'static str, duration: Duration) {
165171
#[cfg(any(feature = "logs", test))]
166172
if self.logging_enabled {
@@ -180,6 +186,7 @@ impl CacheTelemetry {
180186
not(feature = "logs"),
181187
expect(clippy::unused_self, reason = "self.logging_enabled is used when logs is enabled")
182188
)]
189+
#[cfg_attr(coverage_nightly, coverage(off))]
183190
fn record_error_with_duration(&self, cache_name: CacheName, event: &'static str, duration: Duration) {
184191
#[cfg(any(feature = "logs", test))]
185192
if self.logging_enabled {

0 commit comments

Comments
 (0)