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

Show only different part instead of the whole thing #99

Open
Logarithmus opened this issue Apr 4, 2022 · 3 comments
Open

Show only different part instead of the whole thing #99

Logarithmus opened this issue Apr 4, 2022 · 3 comments

Comments

@Logarithmus
Copy link

Logarithmus commented Apr 4, 2022

When diffing 2 big objects which have a small difference in the middle, it's very hard to know what exactly gone wrong. I have to either scroll the terminal, or to redirectcargo test to a file and then use less.

So it would be nice to only display the difference, like diff tool does.

@tommilligan
Copy link
Collaborator

I can see the potential use for this in some circumstances. However, I can also think of examples made much harder with this. For instance, consider the following data:

[
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  3,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
]

And then the following diff (from diff -u):

--- actual.list 2022-04-04 15:30:43.378492792 +0100
+++ expected.list       2022-04-04 15:30:35.886500826 +0100
@@ -13,7 +13,7 @@
   0,
   0,
   0,
-  3,
+  0,
   0,
   0,
   0,

Is this easier to debug by being shorter? Without a file to open and jump to line 13 in, I would say this is much harder.

I think reasonably, displaying the shortened diff would have to be in addition to the complete diff. Which would necessarily make the whole output longer; which I'm not sure is what you want?

@Logarithmus
Copy link
Author

Logarithmus commented Apr 4, 2022

I think reasonably, displaying the shortened diff would have to be in addition to the complete diff

That's exactly how https://github.com/mitsuhiko/similar-asserts#similar-asserts handles it.
Currently I'm using it, but ideally I'd like to have a dedicated macro assert_eq_diff to display only diff. I think it's easier to add it into similar-asserts than to pretty-assertions. But your project seems more active and more widespread.

@julianbuettner
Copy link

An option to opt-in would be great.
It is really useful for big, complex, heterogeneous data strucutures.

use pretty_assertions::diff_only::assert_eq;

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

No branches or pull requests

3 participants