rust-pretty-assertions icon indicating copy to clipboard operation
rust-pretty-assertions copied to clipboard

Show only different part instead of the whole thing

Open Logarithmus opened this issue 2 years ago • 3 comments

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.

Logarithmus avatar Apr 04 '22 13:04 Logarithmus

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?

tommilligan avatar Apr 04 '22 14:04 tommilligan

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.

Logarithmus avatar Apr 04 '22 14:04 Logarithmus

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;

julianbuettner avatar Feb 26 '23 19:02 julianbuettner