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

Use stringified expressions instead of `left` and `right`

Open TimoFreiberg opened this issue 5 years ago • 8 comments

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

TimoFreiberg avatar Jun 14 '19 09:06 TimoFreiberg

Any interest in this?

TimoFreiberg avatar Jun 26 '19 07:06 TimoFreiberg

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 avatar Oct 06 '19 09:10 aquarhead

@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 avatar Nov 06 '19 04:11 cormacrelf

@cormacrelf , can you give an example of what you mean by configuring with a let binding?

rivy avatar Jan 01 '20 19:01 rivy

@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 avatar Jan 02 '20 02:01 cormacrelf

@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 avatar Jan 15 '20 17:01 rivy

@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 avatar Jan 16 '20 03:01 cormacrelf

@cormacrelf , thanks for the clarification.

rivy avatar Jan 20 '20 02:01 rivy