Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stringified expressions instead of left and right #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/lib.rs
Expand Up @@ -117,10 +117,12 @@ macro_rules! assert_eq {
match (&($left), &($right)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
panic!("assertion failed: `(left == right)`\
panic!("assertion failed: `({} == {})`\
\n\
\n{}\
\n",
stringify!($left),
stringify!($right),
$crate::Comparison::new(left_val, right_val))
}
}
Expand All @@ -130,10 +132,12 @@ macro_rules! assert_eq {
match (&($left), &($right)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
panic!("assertion failed: `(left == right)`: {}\
panic!("assertion failed: `({} == {})`: {}\
\n\
\n{}\
\n",
stringify!($left),
stringify!($right),
format_args!($($arg)*),
$crate::Comparison::new(left_val, right_val))
}
Expand Down Expand Up @@ -161,13 +165,15 @@ macro_rules! assert_ne {
let right_dbg = format!("{:?}", *right_val);
if left_dbg != right_dbg {

panic!("assertion failed: `(left != right)`{}{}\
panic!("assertion failed: `({} != {})`{}{}\
\n\
\n{}\
\n{}: According to the `PartialEq` implementation, both of the values \
are partially equivalent, even if the `Debug` outputs differ.\
\n\
\n",
stringify!($left),
stringify!($right),
$maybe_semicolon,
format_args!($($arg)+),
$crate::Comparison::new(left_val, right_val),
Expand All @@ -177,12 +183,14 @@ macro_rules! assert_ne {
.paint("Note"))
}

panic!("assertion failed: `(left != right)`{}{}\
panic!("assertion failed: `({} != {})`{}{}\
\n\
\n{}:\
\n{:#?}\
\n\
\n",
stringify!($left),
stringify!($right),
$maybe_semicolon,
format_args!($($arg)+),
$crate::Style::new().bold().paint("Both sides"),
Expand Down
8 changes: 4 additions & 4 deletions tests/assert_eq.rs
Expand Up @@ -3,7 +3,7 @@ use pretty_assertions::{assert_eq, assert_ne};
extern crate difference;

#[test]
#[should_panic(expected = r#"assertion failed: `(left == right)`
#[should_panic(expected = r#"assertion failed: `(x == y)`

Diff < left / right > :
Some(
Expand Down Expand Up @@ -43,7 +43,7 @@ fn assert_eq() {

#[test]
#[should_panic(
expected = r#"assertion failed: `(left == right)`: custom panic message
expected = r#"assertion failed: `(x == y)`: custom panic message

Diff < left / right > :
Some(
Expand Down Expand Up @@ -115,7 +115,7 @@ fn issue12() {
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left == right)`
#[should_panic(expected = r#"assertion failed: `(x == y)`

Diff < left / right > :
Some(
Expand Down Expand Up @@ -155,7 +155,7 @@ fn assert_eq_trailing_comma() {

#[test]
#[should_panic(
expected = r#"assertion failed: `(left == right)`: custom panic message
expected = r#"assertion failed: `(x == y)`: custom panic message

Diff < left / right > :
Some(
Expand Down
10 changes: 5 additions & 5 deletions tests/assert_ne.rs
@@ -1,7 +1,7 @@
#[allow(unused_imports)]
use pretty_assertions::{assert_eq, assert_ne};
#[test]
#[should_panic(expected = r#"assertion failed: `(left != right)`
#[should_panic(expected = r#"assertion failed: `(x != x)`

Both sides:
Some(
Expand Down Expand Up @@ -34,7 +34,7 @@ fn assert_ne() {

#[test]
#[should_panic(
expected = r#"assertion failed: `(left != right)`: custom panic message
expected = r#"assertion failed: `(x != x)`: custom panic message

Both sides:
Some(
Expand Down Expand Up @@ -77,7 +77,7 @@ fn assert_ne_non_empty_return() {
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left != right)`
#[should_panic(expected = r#"assertion failed: `(Foo(-0.0) != Foo(0.0))`

Diff < left / right > :
<-0.0
Expand Down Expand Up @@ -108,7 +108,7 @@ fn assert_ne_partial() {
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left != right)`
#[should_panic(expected = r#"assertion failed: `(x != x)`

Both sides:
Some(
Expand Down Expand Up @@ -141,7 +141,7 @@ fn assert_ne_trailing_comma() {

#[test]
#[should_panic(
expected = r#"assertion failed: `(left != right)`: custom panic message
expected = r#"assertion failed: `(x != x)`: custom panic message

Both sides:
Some(
Expand Down
2 changes: 1 addition & 1 deletion tests/pretty_string.rs
Expand Up @@ -16,7 +16,7 @@ impl<'a> fmt::Debug for PrettyString<'a> {
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left == right)`
#[should_panic(expected = r#"assertion failed: `(PrettyString("") == PrettyString("foo"))`

Diff < left / right > :
>foo
Expand Down