Skip to content

Commit de8bbd2

Browse files
authored
Assert failure message easier to read
By having the left and right strings above and below on the same line it helps spot the difference between the two. E.g. thread 'tests::test_safe_filename' panicked at 'assertion failed: `(left == right)` left: `"-aandb--S123.html"` right: `"-aandb-S123.html"`', When the strings are both on the same line it take a lot longer to spot the difference. It is a small change but the small time savings add up with repetition. This helps Rust be an excellent language to write tests in.
1 parent ae3d387 commit de8bbd2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/libcore/macros.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ macro_rules! assert_eq {
116116
match (&$left, &$right) {
117117
(left_val, right_val) => {
118118
if !(*left_val == *right_val) {
119-
panic!("assertion failed: `(left == right)` \
120-
(left: `{:?}`, right: `{:?}`)", left_val, right_val)
119+
panic!(r#"assertion failed: `(left == right)`
120+
left: `{:?}`
121+
right: `{:?}`"#, left_val, right_val)
121122
}
122123
}
123124
}
@@ -126,8 +127,9 @@ macro_rules! assert_eq {
126127
match (&($left), &($right)) {
127128
(left_val, right_val) => {
128129
if !(*left_val == *right_val) {
129-
panic!("assertion failed: `(left == right)` \
130-
(left: `{:?}`, right: `{:?}`): {}", left_val, right_val,
130+
panic!(r#"assertion failed: `(left == right)`
131+
left: `{:?}`
132+
right: `{:?}`: {}"#, left_val, right_val,
131133
format_args!($($arg)+))
132134
}
133135
}

0 commit comments

Comments
 (0)