rust-pretty-assertions
rust-pretty-assertions copied to clipboard
Show only different part instead of the whole thing
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.
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?
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.
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;