From 4d000608176bf0971a7f10c2fc1f91f8c492a608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 15 Oct 2022 19:05:12 +0200 Subject: [PATCH] TestComponent: Display assert errors as Display not Debug for easier xml coloring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/component/test.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/component/test.rs b/src/component/test.rs index 93b9ac5..baa6e0c 100644 --- a/src/component/test.rs +++ b/src/component/test.rs @@ -43,7 +43,7 @@ impl fmt::Debug for Expect { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Expect::")?; match self { - Expect::Element(el) => write!(f, "Element({:?})", String::from(el)), + Expect::Element(el) => write!(f, "Element({})", String::from(el)), Expect::Iq(_, desc) => write!(f, "Iq(, {})", desc), Expect::Message(_, desc) => write!(f, "Message(, {})", desc), Expect::Presence(_, desc) => write!(f, "Presence(, {})", desc), @@ -167,7 +167,17 @@ impl Component { match expected { Some(expected) => match expected { - Expect::Element(el) => assert_eq!(String::from(&el), String::from(&out)), + Expect::Element(el) => { + let (expected, actual) = (String::from(&el), String::from(&out)); + if expected != actual { + panic!( + r#"assertion failed: `(actual == expected)` + actual: `{}`, + expected: `{}`"#, + actual, expected + ) + } + } Expect::Iq(cb, _) => match Iq::try_from(out.0.clone()) { Ok(iq) => cb(iq), _ => panic!(