Auto merge of #42541 - gilescope:patch-1, r=alexcrichton

assert_eq failure message easier to read

By having the left and right strings aligned with one another it helps spot the difference between the two far quicker than if they are on the same line.

E.g.
Before:

```
thread 'tests::test_safe_filename' panicked at 'assertion failed: `(left == right)` left:  `"-aandb--S123.html"` right: `"-aandb-S123.html"`',
```

After:

```
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 would help Rust be an excellent language to write tests in out of the box.

Closes https://github.com/rust-lang/rust/issues/41615
This commit is contained in:
bors 2017-06-24 12:18:40 +00:00
commit 3cf9f5d787
4 changed files with 33 additions and 10 deletions

View File

@ -116,8 +116,9 @@ macro_rules! assert_eq {
match (&$left, &$right) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
panic!("assertion failed: `(left == right)` \
(left: `{:?}`, right: `{:?}`)", left_val, right_val)
panic!(r#"assertion failed: `(left == right)`
left: `{:?}`,
right: `{:?}`"#, left_val, right_val)
}
}
}
@ -126,8 +127,9 @@ macro_rules! assert_eq {
match (&($left), &($right)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
panic!("assertion failed: `(left == right)` \
(left: `{:?}`, right: `{:?}`): {}", left_val, right_val,
panic!(r#"assertion failed: `(left == right)`
left: `{:?}`,
right: `{:?}`: {}"#, left_val, right_val,
format_args!($($arg)+))
}
}
@ -162,8 +164,9 @@ macro_rules! assert_ne {
match (&$left, &$right) {
(left_val, right_val) => {
if *left_val == *right_val {
panic!("assertion failed: `(left != right)` \
(left: `{:?}`, right: `{:?}`)", left_val, right_val)
panic!(r#"assertion failed: `(left != right)`
left: `{:?}`,
right: `{:?}`"#, left_val, right_val)
}
}
}
@ -172,8 +175,9 @@ macro_rules! assert_ne {
match (&($left), &($right)) {
(left_val, right_val) => {
if *left_val == *right_val {
panic!("assertion failed: `(left != right)` \
(left: `{:?}`, right: `{:?}`): {}", left_val, right_val,
panic!(r#"assertion failed: `(left != right)`
left: `{:?}`,
right: `{:?}`: {}"#, left_val, right_val,
format_args!($($arg)+))
}
}

View File

@ -8,7 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:assertion failed: `(left == right)` (left: `14`, right: `15`)
// error-pattern:assertion failed: `(left == right)`
// error-pattern: left: `14`
// error-pattern:right: `15`
fn main() {
assert_eq!(14, 15);

View File

@ -0,0 +1,17 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:assertion failed: `(left != right)`
// error-pattern: left: `14`
// error-pattern:right: `14`
fn main() {
assert_ne!(14, 14);
}

@ -1 +1 @@
Subproject commit 50b1c24d146fa072db71f12005deed319ac5ba9a
Subproject commit 534ce68621ce4feec0b7e8627cfd3b077d4f3900