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

assert_eq(a,b,) doesn't show pretty printing #41

Closed
Stargateur opened this issue Apr 10, 2020 · 4 comments · Fixed by #50
Closed

assert_eq(a,b,) doesn't show pretty printing #41

Stargateur opened this issue Apr 10, 2020 · 4 comments · Fixed by #50

Comments

@Stargateur
Copy link

Stargateur commented Apr 10, 2020

Giving the following MCVE:

fn main() {
    #[derive(Debug, PartialEq)]
    struct Foo<'a> {
        lorem: &'a str,
        ipsum: u32,
        dolor: Result<String, String>,
    }

    let x = Some(Foo { lorem: "Hello World!", ipsum: 42, dolor: Ok("hey".to_string())});
    let y = Some(Foo { lorem: "Hello Wrold!", ipsum: 42, dolor: Ok("hey ho!".to_string())});

    pretty_assertions::assert_eq!(x, y,);
}
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Some(Foo { lorem: "Hello World!", ipsum: 42, dolor: Ok("hey") })`,
 right: `Some(Foo { lorem: "Hello Wrold!", ipsum: 42, dolor: Ok("hey ho!") })`', src\main.rs:12:5

Add an extra comma, seem to disable everything.

@Stargateur Stargateur changed the title Unknown bug assert_eq(a,b,) doesn't show pretty printing Apr 10, 2020
@Stargateur Stargateur reopened this Apr 10, 2020
@Stargateur
Copy link
Author

Like I didn't use pretty_assertions::assert_eq; the line:

https://github.com/colin-kiegel/rust-pretty-assertions/blob/2f4058ac7fb5e24a923aef80851c6608b6683d0f/src/lib.rs#L113-L115

fail back to std implementation, I think we need to use a internal second macro to avoid repetition code and the bug. But I'm don't know much about rust declarative macro.

Same problem will happen for assert_ne!:

https://github.com/colin-kiegel/rust-pretty-assertions/blob/2f4058ac7fb5e24a923aef80851c6608b6683d0f/src/lib.rs#L147-L155

@spenserblack
Copy link

This should do it (it's probably what was intended).

 ($left:expr , $right:expr,) => ({ 
-    assert_eq!($left, $right)
+    $crate::assert_eq!($left, $right)
 }); 

But the optional , can also be captured with this macro pattern.

($left:expr, $right:expr $(,)?) => { /* do stuff */ }

@gmoshkin
Copy link

Spent a couple of hours today finding out this bug :(

@tommilligan
Copy link
Collaborator

Thanks for reporting this. A fix has been merged and will be in the next release.

bors bot added a commit to jonasbb/serde_with that referenced this issue Mar 13, 2021
279: Update pretty_assertions requirement from 0.6.1 to 0.7.1 r=jonasbb a=dependabot[bot]

Updates the requirements on [pretty_assertions](https://github.com/colin-kiegel/rust-pretty-assertions) to permit the latest version.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/colin-kiegel/rust-pretty-assertions/releases">pretty_assertions's releases</a>.</em></p>
<blockquote>
<h2>v0.7.1</h2>
<h2>Fixed</h2>
<ul>
<li>Fix a bug where multiline changes showed an unhelpful inline diff (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/66">#66</a>, <a href="https://github.com/tommilligan"><code>@​tommilligan</code></a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/colin-kiegel/rust-pretty-assertions/blob/main/CHANGELOG.md">pretty_assertions's changelog</a>.</em></p>
<blockquote>
<h1>v0.7.1</h1>
<ul>
<li>Fix a bug where multiline changes showed an unhelpful inline diff (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/66">#66</a>, <a href="https://github.com/tommilligan"><code>@​tommilligan</code></a>)</li>
</ul>
<h1>v0.7.0</h1>
<h2>Changed</h2>
<ul>
<li>Move from <code>difference</code> to <code>diff</code> for calculating diffs. The exact assertion messages generated may differ from previous versions. (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/52">#52</a>, <a href="https://github.com/tommilligan"><code>@​tommilligan</code></a>)</li>
</ul>
<p>For example, the following assertion message from <code>v0.7.0</code>:</p>
<p><img src="https://raw.githubusercontent.com/colin-kiegel/rust-pretty-assertions/2d2357ff56d22c51a86b2f1cfe6efcee9f5a8081/examples/pretty_assertion.png" alt="pretty assertion" /></p>
<p>Was previously rendered like this in <code>v0.6.1</code>:</p>
<p><img src="https://raw.githubusercontent.com/colin-kiegel/rust-pretty-assertions/2d2357ff56d22c51a86b2f1cfe6efcee9f5a8081/examples/pretty_assertion_v0_6_1.png" alt="pretty assertion" /></p>
<h2>Added</h2>
<ul>
<li>Support for unsized values (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/42">#42</a>, <a href="https://github.com/stanislav-tkach"><code>@​stanislav-tkach</code></a>)</li>
<li>Document the <code>Comparison</code> struct, which was previously hidden. This can be used to generate a pretty diff of two values without panicking. (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/52">#52</a>, <a href="https://github.com/tommilligan"><code>@​tommilligan</code></a>)</li>
</ul>
<h2>Fixed</h2>
<ul>
<li>Fix some unhygenic macro expansions (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/41">#41</a>, <a href="https://github.com/tommilligan"><code>@​tommilligan</code></a>)</li>
</ul>
<h2>Internal</h2>
<ul>
<li>Test Windows targets in CI (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/46">#46</a>, <a href="https://github.com/tommilligan"><code>@​tommilligan</code></a>)</li>
<li>Bump <code>ansi_term</code> version to 0.12 (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/34">#34</a>, <a href="https://github.com/waywardmonkeys"><code>@​waywardmonkeys</code></a>)</li>
<li>Code health improvements (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/34">#34</a>, <a href="https://github.com/waywardmonkeys"><code>@​waywardmonkeys</code></a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/2667441b0edb3322eab7d7779a3a96c280414ddf"><code>2667441</code></a> Merge pull request <a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/68">#68</a> from tommilligan/prep-v0.7.1</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/6dde470f579a2bf88251a6e4eb1a691be3d19920"><code>6dde470</code></a> Merge pull request <a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/67">#67</a> from tommilligan/ci-revert-cargo-target-dir</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/b517e396dbbce136a27756732080a1a592e74eca"><code>b517e39</code></a> chore: prepare for v0.7.1</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/fdff5f32f967a171cbb59dbb18e814532bf594a5"><code>fdff5f3</code></a> Merge pull request <a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/66">#66</a> from tommilligan/chunk-diffing</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/62e93575ffc081c36f779da188057a51df555734"><code>62e9357</code></a> Revert &quot;ci: remove concern with CARGO_TARGET_DIR&quot;</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/8f7d7a5ee00a2e36885fc016fb13e91c062dd7ae"><code>8f7d7a5</code></a> printer: do not print inline diff for multiline insert/delete chunks</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/083ce2ebe4892fb219f36beb764065920de0f96b"><code>083ce2e</code></a> Merge pull request <a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/65">#65</a> from tommilligan/ci-rm-cargo-target-dir</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/56a0aaa6185e2e5db46aef54fb61a4388f89943f"><code>56a0aaa</code></a> ci: remove concern with CARGO_TARGET_DIR</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/7f6ae17e0046d1ddb55291cf7ea7064c8630fbf5"><code>7f6ae17</code></a> Merge pull request <a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/63">#63</a> from tommilligan/update-gitignore</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/ccb2e45112471740a61ce82565ab5ffe916c6d3d"><code>ccb2e45</code></a> ci: update gitignore</li>
<li>Additional commits viewable in <a href="https://github.com/colin-kiegel/rust-pretty-assertions/compare/v0.6.1...v0.7.1">compare view</a></li>
</ul>
</details>
<br />


Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
bors bot added a commit to jonasbb/rust_misc_utils that referenced this issue Mar 13, 2021
62: Update pretty_assertions requirement from 0.6 to 0.7 r=jonasbb a=dependabot[bot]

Updates the requirements on [pretty_assertions](https://github.com/colin-kiegel/rust-pretty-assertions) to permit the latest version.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/colin-kiegel/rust-pretty-assertions/releases">pretty_assertions's releases</a>.</em></p>
<blockquote>
<h2>v0.7.1</h2>
<h2>Fixed</h2>
<ul>
<li>Fix a bug where multiline changes showed an unhelpful inline diff (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/66">#66</a>, <a href="https://github.com/tommilligan"><code>@​tommilligan</code></a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/colin-kiegel/rust-pretty-assertions/blob/main/CHANGELOG.md">pretty_assertions's changelog</a>.</em></p>
<blockquote>
<h1>v0.7.1</h1>
<ul>
<li>Fix a bug where multiline changes showed an unhelpful inline diff (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/66">#66</a>, <a href="https://github.com/tommilligan"><code>@​tommilligan</code></a>)</li>
</ul>
<h1>v0.7.0</h1>
<h2>Changed</h2>
<ul>
<li>Move from <code>difference</code> to <code>diff</code> for calculating diffs. The exact assertion messages generated may differ from previous versions. (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/52">#52</a>, <a href="https://github.com/tommilligan"><code>@​tommilligan</code></a>)</li>
</ul>
<p>For example, the following assertion message from <code>v0.7.0</code>:</p>
<p><img src="https://raw.githubusercontent.com/colin-kiegel/rust-pretty-assertions/2d2357ff56d22c51a86b2f1cfe6efcee9f5a8081/examples/pretty_assertion.png" alt="pretty assertion" /></p>
<p>Was previously rendered like this in <code>v0.6.1</code>:</p>
<p><img src="https://raw.githubusercontent.com/colin-kiegel/rust-pretty-assertions/2d2357ff56d22c51a86b2f1cfe6efcee9f5a8081/examples/pretty_assertion_v0_6_1.png" alt="pretty assertion" /></p>
<h2>Added</h2>
<ul>
<li>Support for unsized values (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/42">#42</a>, <a href="https://github.com/stanislav-tkach"><code>@​stanislav-tkach</code></a>)</li>
<li>Document the <code>Comparison</code> struct, which was previously hidden. This can be used to generate a pretty diff of two values without panicking. (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/52">#52</a>, <a href="https://github.com/tommilligan"><code>@​tommilligan</code></a>)</li>
</ul>
<h2>Fixed</h2>
<ul>
<li>Fix some unhygenic macro expansions (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/41">#41</a>, <a href="https://github.com/tommilligan"><code>@​tommilligan</code></a>)</li>
</ul>
<h2>Internal</h2>
<ul>
<li>Test Windows targets in CI (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/46">#46</a>, <a href="https://github.com/tommilligan"><code>@​tommilligan</code></a>)</li>
<li>Bump <code>ansi_term</code> version to 0.12 (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/34">#34</a>, <a href="https://github.com/waywardmonkeys"><code>@​waywardmonkeys</code></a>)</li>
<li>Code health improvements (<a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/34">#34</a>, <a href="https://github.com/waywardmonkeys"><code>@​waywardmonkeys</code></a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/2667441b0edb3322eab7d7779a3a96c280414ddf"><code>2667441</code></a> Merge pull request <a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/68">#68</a> from tommilligan/prep-v0.7.1</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/6dde470f579a2bf88251a6e4eb1a691be3d19920"><code>6dde470</code></a> Merge pull request <a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/67">#67</a> from tommilligan/ci-revert-cargo-target-dir</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/b517e396dbbce136a27756732080a1a592e74eca"><code>b517e39</code></a> chore: prepare for v0.7.1</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/fdff5f32f967a171cbb59dbb18e814532bf594a5"><code>fdff5f3</code></a> Merge pull request <a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/66">#66</a> from tommilligan/chunk-diffing</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/62e93575ffc081c36f779da188057a51df555734"><code>62e9357</code></a> Revert &quot;ci: remove concern with CARGO_TARGET_DIR&quot;</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/8f7d7a5ee00a2e36885fc016fb13e91c062dd7ae"><code>8f7d7a5</code></a> printer: do not print inline diff for multiline insert/delete chunks</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/083ce2ebe4892fb219f36beb764065920de0f96b"><code>083ce2e</code></a> Merge pull request <a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/65">#65</a> from tommilligan/ci-rm-cargo-target-dir</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/56a0aaa6185e2e5db46aef54fb61a4388f89943f"><code>56a0aaa</code></a> ci: remove concern with CARGO_TARGET_DIR</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/7f6ae17e0046d1ddb55291cf7ea7064c8630fbf5"><code>7f6ae17</code></a> Merge pull request <a href="https://github.com/colin-kiegel/rust-pretty-assertions/issues/63">#63</a> from tommilligan/update-gitignore</li>
<li><a href="https://github.com/colin-kiegel/rust-pretty-assertions/commit/ccb2e45112471740a61ce82565ab5ffe916c6d3d"><code>ccb2e45</code></a> ci: update gitignore</li>
<li>Additional commits viewable in <a href="https://github.com/colin-kiegel/rust-pretty-assertions/compare/v0.6.0...v0.7.1">compare view</a></li>
</ul>
</details>
<br />


Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants