Skip to content

Commit 604c7d2

Browse files
replace codecov ignores with coverage(off) for the per-package gate
cargo-coverage-gate (the per-package line-coverage gate anvil runs) evaluates raw lcov and does not read codecov.yml, so files the repo excludes from Codecov via `ignore` globs were still gated and failed. Translate the two ignores into mechanisms the gate honors: - testing_aids: add crate-level `#![cfg_attr(coverage_nightly, coverage(off))]` (+ feature gate). It is an internal (publish=false) test-helper crate whose utilities are exercised opportunistically by other crates' tests, so per-package coverage is not meaningful. Now reports NO DATA -> OK. - ohno/src/test_util.rs: the existing module-level coverage(off) was inert for `assert_error_message!` because a macro body is re-instrumented at each expansion site and attributed back to this file. Move the assertion logic into `assert_error_message_impl` (a real `#[doc(hidden)] pub fn`); the macro now expands to a single call to it. The function is compiled once in ohno where coverage(off) applies, so test_util.rs no longer contributes instrumented lines. ohno goes 99.3% -> 100%. The function is `#[track_caller]` so assertion failures still report at the caller's line (a plain function would point into test_util.rs). Macro behavior is unchanged (verified: ohno + http_extensions tests, incl. the should_panic, doctest, and panic location). - codecov.yml: drop both now-redundant `ignore` entries (the lines no longer appear in the lcov at all, so Codecov and the gate agree). NOTE: ohno is published (crates.io v0.3.6); this adds a doc-hidden public helper (additive, non-breaking) to back the macro. Remaining: cachet 99.7% (no-default-features-only telemetry fallback arms) is a genuine gap, not a codecov ignore -- handled separately. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 748230e commit 604c7d2

3 files changed

Lines changed: 35 additions & 22 deletions

File tree

codecov.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,3 @@ coverage:
1818
target: 100
1919
threshold: "0"
2020
base: auto
21-
ignore:
22-
- "crates/testing_aids/**/*"
23-
# Macro expansion causes coverage to be inaccurate in these files, so we ignore them for now. We can re-enable them once we have a better solution for macro coverage.
24-
- "crates/ohno/src/test_util.rs"

crates/ohno/src/test_util.rs

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

4-
#![cfg_attr(coverage_nightly, coverage(off))] // coverage doesn't handle panics well
4+
// The assertion logic lives in `assert_error_message_impl` (a real function),
5+
// not inline in the macro body, so this module-level `coverage(off)` actually
6+
// suppresses it. A macro body is re-instrumented at every expansion site and
7+
// attributed back to this file, so `coverage(off)` here never reached it.
8+
#![cfg_attr(coverage_nightly, coverage(off))]
59

610
//! Test utilities for the ohno crate.
711
//!
@@ -30,24 +34,30 @@
3034
/// ```
3135
#[macro_export]
3236
macro_rules! assert_error_message {
33-
($error:expr, $expected:expr) => {{
34-
let error_string = $error.to_string();
35-
let expected: &str = $expected;
37+
($error:expr, $expected:expr) => {{ $crate::test_util::assert_error_message_impl(&$error.to_string(), $expected) }};
38+
}
3639

37-
let test = move || {
38-
if error_string == expected {
39-
return ();
40-
}
41-
if let Some(remainder) = error_string.strip_prefix(expected) {
42-
// backtrace, caused by, or error trace indicators
43-
if remainder.starts_with("\n\nBacktrace:\n") || remainder.starts_with("\ncaused by: ") || remainder.starts_with("\n> ") {
44-
return ();
45-
}
46-
}
47-
panic!("left : {expected}\nright: {error_string}");
48-
};
49-
test();
50-
}};
40+
/// Implementation backing [`assert_error_message!`].
41+
///
42+
/// Kept as a function (rather than inline in the macro) so that the
43+
/// module-level `#[coverage(off)]` applies to the assertion's untested
44+
/// branches; inlined in the macro they would be instrumented at every
45+
/// expansion site and reported as coverage gaps in this file.
46+
///
47+
/// Not part of the public API; invoke [`assert_error_message!`] instead.
48+
#[doc(hidden)]
49+
#[track_caller]
50+
pub fn assert_error_message_impl(error_string: &str, expected: &str) {
51+
if error_string == expected {
52+
return;
53+
}
54+
if let Some(remainder) = error_string.strip_prefix(expected) {
55+
// backtrace, caused by, or error trace indicators
56+
if remainder.starts_with("\n\nBacktrace:\n") || remainder.starts_with("\ncaused by: ") || remainder.starts_with("\n> ") {
57+
return;
58+
}
59+
}
60+
panic!("left : {expected}\nright: {error_string}");
5161
}
5262

5363
#[cfg(test)]

crates/testing_aids/src/lib.rs

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

4+
// Test-only helper crate: its utilities are exercised opportunistically by
5+
// other crates' tests, so per-package line coverage is not a meaningful gate
6+
// here. Exclude the whole crate from instrumentation (mirrors the codecov.yml
7+
// `ignore` this replaces).
8+
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
9+
#![cfg_attr(coverage_nightly, coverage(off))]
10+
411
//! An unpublished crate containing testing utilities for use within this repo.
512
613
#![allow(clippy::panic, clippy::unwrap_used, missing_docs, reason = "Test code")]

0 commit comments

Comments
 (0)