From ab8e46b0660e076e629e6775ed8da9890c5fbf1f Mon Sep 17 00:00:00 2001 From: John Clements Date: Wed, 13 Mar 2013 12:10:32 -0700 Subject: add assert_eq! macro the assert_eq! macro compares its arguments and fails if they're not equal. It's more informative than fail_unless!, because it explicitly writes the given and expected arguments on failure. --- src/libsyntax/ext/expand.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index ad05e2f21e6..030cdab7951 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -464,6 +464,15 @@ pub fn core_macros() -> ~str { } ) + macro_rules! assert_eq ( + ($given:expr , $expected:expr) => + ({let given_val = $given; + let expected_val = $expected; + // check both directions of equality.... + if !((given_val == expected_val) && (expected_val == given_val)) { + fail!(fmt!(\"expected: %?, given: %?\",expected_val,given_val)); + }})) + macro_rules! condition ( { $c:ident: $in:ty -> $out:ty; } => { @@ -481,6 +490,7 @@ pub fn core_macros() -> ~str { } ) + }"; } -- cgit 1.4.1-3-g733a5