Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
40 changes: 23 additions & 17 deletions crates/ohno/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Comment thread
psandana marked this conversation as resolved.
#[expect(clippy::panic, reason = "test assertion helper — panicking is the intended behavior")]
pub fn assert_error_message_impl(error_string: &str, expected: &str) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code was intentionally a part of a macro so when a test fails, it will point you to the caller

also, making hidden pub function is not the best choice if we can avoid it

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)]
Expand Down
Loading