Skip to content

Commit

Permalink
Add message argument to assert_eq macro
Browse files Browse the repository at this point in the history
  • Loading branch information
komamitsu committed Jun 21, 2016
1 parent 4ba60ab commit 45a63d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,18 @@ macro_rules! assert_eq {
}
}
}
})
});
($left:expr , $right:expr, $($arg:tt)*) => ({
match (&($left), &($right)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
panic!("assertion failed: `(left == right)` \
(left: `{:?}`, right: `{:?}`): {}", left_val, right_val,
format_args!($($arg)*))
}
}
}
});
}

/// Ensure that a boolean expression is `true` at runtime.
Expand Down
3 changes: 3 additions & 0 deletions src/test/run-pass/assert-eq-macro-success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ pub fn main() {
assert_eq!("abc".to_string(),"abc".to_string());
assert_eq!(Box::new(Point{x:34}),Box::new(Point{x:34}));
assert_eq!(&Point{x:34},&Point{x:34});
assert_eq!(42, 42, "foo bar");
assert_eq!(42, 42, "a {} c", "b");
assert_eq!(42, 42, "{x}, {y}, {z}", x = 1, y = 2, z = 3);
}

0 comments on commit 45a63d3

Please sign in to comment.