Skip to content

Commit

Permalink
Extract assert_contains macro
Browse files Browse the repository at this point in the history
  • Loading branch information
shepmaster committed Nov 17, 2022
1 parent e491da4 commit e40bcca
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions tests/report.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
use snafu::{prelude::*, IntoError, Report};

macro_rules! assert_contains {
(needle: $needle:expr, haystack: $haystack:expr) => {
assert!(
$haystack.contains($needle),
"Expected {:?} to include {:?}",
$haystack,
$needle,
)
};
}

#[test]
fn includes_the_error_display_text() {
#[derive(Debug, Snafu)]
Expand All @@ -10,12 +21,7 @@ fn includes_the_error_display_text() {
let msg = r.to_string();

let expected = "This is my Display text!";
assert!(
msg.contains(expected),
"Expected {:?} to include {:?}",
msg,
expected,
);
assert_contains!(needle: expected, haystack: msg);
}

#[test]
Expand All @@ -35,12 +41,7 @@ fn includes_the_source_display_text() {
let msg = r.to_string();

let expected = "This is my inner Display";
assert!(
msg.contains(expected),
"Expected {:?} to include {:?}",
msg,
expected,
);
assert_contains!(needle: expected, haystack: msg);
}

#[test]
Expand Down

0 comments on commit e40bcca

Please sign in to comment.