rust-pretty-assertions
rust-pretty-assertions copied to clipboard
Use stringified expressions instead of `left` and `right`
Hi and thanks for the helpful library!
I was annoyed a few times now by the panic message only showing (left == right)
instead of my actual arguments to the assert_eq
call and had to add a custom message describing the arguments.
This change also helps in remembering which side was the expected or the actual value (which happens to me...)
Slightly ugly things in this MR:
The following message is duplicated 4 times:
assertion failed: `({} == {})`
Some existing tests now also verify this new feature, I think it would be slightly prettier to make these tests also pass x
and y
as arguments (so they don't check two things at once) and make a new test verify this new feature
Any interest in this?
I'm thinking about the same thing, but maybe just let caller provide different names for left
and right
is simpler (and more straightforward?)
@aquarhead It would actually be more complicated. You would need to add macro arguments to what are purportedly drop-in replacements for assert_eq. This breaks switching back with a one-liner. I like the stringified expressions; you can just configure it by introducing a let
binding.
@cormacrelf , can you give an example of what you mean by configuring with a let
binding?
@cormacrelf , can you give an example of what you mean by configuring with a
let
binding?
let one = ...;
let very_fancy_two = ...;
assert_eq!(one, very_fancy_two);
@cormacrelf , can you give an example of what you mean by configuring with a
let
binding?let one = ...; let very_fancy_two = ...; assert_eq!(one, very_fancy_two);
I don't understand. Does that show anything different from "left" and "right"?
@rivy you’re confused because I said “can” instead of “could”. It doesn’t now, but it would if the two expressions passed to assert_eq were stringified and those strings were used instead of left and right. It would say < one / very_fancy_two >
instead.
@cormacrelf , thanks for the clarification.