From de8bbd2b164f1839186ce8a5117e86902701bdfe Mon Sep 17 00:00:00 2001 From: Squirrel Date: Thu, 8 Jun 2017 18:38:49 +0100 Subject: [PATCH 1/4] 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. --- src/libcore/macros.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 99000a031fea..5cb56433ac78 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -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)+)) } } From 87cfb5431edc2f190d3cde62cef803aaeda63c10 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Tue, 13 Jun 2017 14:17:59 +0100 Subject: [PATCH 2/4] Updated tests and fixed inconsistent message on assert_eq --- src/libcore/macros.rs | 18 ++++++++++-------- src/test/run-fail/assert-eq-macro-panic.rs | 4 +++- src/test/run-fail/assert-ne-macro-panic.rs | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 src/test/run-fail/assert-ne-macro-panic.rs diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 5cb56433ac78..f8316d685788 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -117,8 +117,8 @@ macro_rules! assert_eq { (left_val, right_val) => { if !(*left_val == *right_val) { panic!(r#"assertion failed: `(left == right)` -left: `{:?}` -right: `{:?}`"#, left_val, right_val) + left: `{:?}` + right: `{:?}`"#, left_val, right_val) } } } @@ -128,8 +128,8 @@ right: `{:?}`"#, left_val, right_val) (left_val, right_val) => { if !(*left_val == *right_val) { panic!(r#"assertion failed: `(left == right)` -left: `{:?}` -right: `{:?}`: {}"#, left_val, right_val, + left: `{:?}` + right: `{:?}`: {}"#, left_val, right_val, format_args!($($arg)+)) } } @@ -164,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) } } } @@ -174,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)+)) } } diff --git a/src/test/run-fail/assert-eq-macro-panic.rs b/src/test/run-fail/assert-eq-macro-panic.rs index a3e0a1f904fa..fed2ee0beab2 100644 --- a/src/test/run-fail/assert-eq-macro-panic.rs +++ b/src/test/run-fail/assert-eq-macro-panic.rs @@ -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); diff --git a/src/test/run-fail/assert-ne-macro-panic.rs b/src/test/run-fail/assert-ne-macro-panic.rs new file mode 100644 index 000000000000..d57bb0fb67fb --- /dev/null +++ b/src/test/run-fail/assert-ne-macro-panic.rs @@ -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 or the MIT license +// , 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); +} From 02969a7e0df02eaa32783a79925411f3a51b1444 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Tue, 13 Jun 2017 14:53:01 +0100 Subject: [PATCH 3/4] Removing tabs. Sorry - have updated my .vimrc --- src/libcore/macros.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index f8316d685788..326b5281d9e8 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -164,7 +164,7 @@ macro_rules! assert_ne { match (&$left, &$right) { (left_val, right_val) => { if *left_val == *right_val { - panic!(r#"assertion failed: `(left != right)` + panic!(r#"assertion failed: `(left != right)` left: `{:?}` right: `{:?}`"#, left_val, right_val) } @@ -175,7 +175,7 @@ macro_rules! assert_ne { match (&($left), &($right)) { (left_val, right_val) => { if *left_val == *right_val { - panic!(r#"assertion failed: `(left != right)` + panic!(r#"assertion failed: `(left != right)` left: `{:?}` right: `{:?}`: {}"#, left_val, right_val, format_args!($($arg)+)) From 0a07803532f0cc20427bb3f7e49a8b7f236a53d1 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Fri, 16 Jun 2017 07:34:37 +0100 Subject: [PATCH 4/4] Fixed cargo bench test for assert_eq multi-line message --- src/tools/cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/cargo b/src/tools/cargo index bbfe9b3a9d64..9ad6e5b8f68e 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit bbfe9b3a9d64aa8698b18cbb3803b3fa00ee3f44 +Subproject commit 9ad6e5b8f68ee4bcd85886e50b8b0a70cbb91a52