diff --git a/codecov.yml b/codecov.yml index f669938f1..8fb7fa500 100644 --- a/codecov.yml +++ b/codecov.yml @@ -10,5 +10,3 @@ coverage: base: auto ignore: - "crates/testing_aids/**/*" -# this is a temporary fix, for some reason codecov ignores cfg option in the file itself -- "crates/ohno/src/test_util.rs" diff --git a/crates/ohno/src/test_util.rs b/crates/ohno/src/test_util.rs index 4ee14e9b0..1bfb38387 100644 --- a/crates/ohno/src/test_util.rs +++ b/crates/ohno/src/test_util.rs @@ -30,24 +30,30 @@ /// ``` #[macro_export] macro_rules! assert_error_message { - ($error:expr, $expected:expr) => {{ - let error_string = $error.to_string(); - let expected: &str = $expected; + ($error:expr, $expected:expr) => { + $crate::test_util::assert_error_message_impl(&$error.to_string(), $expected) + }; +} - let test = move || { - if error_string == expected { - return (); - } - if let Some(remainder) = error_string.strip_prefix(expected) { - // backtrace, caused by, or error trace indicators - if remainder.starts_with("\n\nBacktrace:\n") || remainder.starts_with("\ncaused by: ") || remainder.starts_with("\n> ") { - return (); - } - } - panic!("left : {expected}\nright: {error_string}"); - }; - test(); - }}; +/// Implementation helper for [`assert_error_message!`]. +/// +/// # Note +/// +/// This is an implementation detail of the [`assert_error_message!`] macro. Do not call directly. +#[doc(hidden)] +#[cfg_attr(coverage_nightly, coverage(off))] +#[expect(clippy::panic, reason = "test assertion helper — panicking is the intended behavior")] +pub fn assert_error_message_impl(error_string: &str, expected: &str) { + if error_string == expected { + return; + } + if let Some(remainder) = error_string.strip_prefix(expected) { + // backtrace, caused by, or error trace indicators + if remainder.starts_with("\n\nBacktrace:\n") || remainder.starts_with("\ncaused by: ") || remainder.starts_with("\n> ") { + return; + } + } + panic!("left : {expected}\nright: {error_string}"); } #[cfg(test)]