From e40bcca3c2cbe1161921459020ad57218519e362 Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Thu, 17 Nov 2022 13:59:44 -0500 Subject: [PATCH] Extract assert_contains macro --- tests/report.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/report.rs b/tests/report.rs index 476fc624..521fd519 100644 --- a/tests/report.rs +++ b/tests/report.rs @@ -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)] @@ -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] @@ -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]