Skip to content

Commit 45a63d3

Browse files
committed
Add message argument to assert_eq macro
1 parent 4ba60ab commit 45a63d3

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/libcore/macros.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,18 @@ macro_rules! assert_eq {
9494
}
9595
}
9696
}
97-
})
97+
});
98+
($left:expr , $right:expr, $($arg:tt)*) => ({
99+
match (&($left), &($right)) {
100+
(left_val, right_val) => {
101+
if !(*left_val == *right_val) {
102+
panic!("assertion failed: `(left == right)` \
103+
(left: `{:?}`, right: `{:?}`): {}", left_val, right_val,
104+
format_args!($($arg)*))
105+
}
106+
}
107+
}
108+
});
98109
}
99110

100111
/// Ensure that a boolean expression is `true` at runtime.

src/test/run-pass/assert-eq-macro-success.rs

+3
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ pub fn main() {
1616
assert_eq!("abc".to_string(),"abc".to_string());
1717
assert_eq!(Box::new(Point{x:34}),Box::new(Point{x:34}));
1818
assert_eq!(&Point{x:34},&Point{x:34});
19+
assert_eq!(42, 42, "foo bar");
20+
assert_eq!(42, 42, "a {} c", "b");
21+
assert_eq!(42, 42, "{x}, {y}, {z}", x = 1, y = 2, z = 3);
1922
}

0 commit comments

Comments
 (0)