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

Use stringified expressions instead of left and right #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TimoFreiberg
Copy link

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
Copy link
Author

Any interest in this?

@aquarhead
Copy link

I'm thinking about the same thing, but maybe just let caller provide different names for left and right is simpler (and more straightforward?)

@cormacrelf
Copy link

@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.

@rivy
Copy link

rivy commented Jan 1, 2020

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

@cormacrelf
Copy link

@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);

@rivy
Copy link

rivy commented Jan 15, 2020

@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"?

@cormacrelf
Copy link

@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.

@rivy
Copy link

rivy commented Jan 20, 2020

@cormacrelf , thanks for the clarification.

Base automatically changed from master to main February 9, 2021 15:52
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

Successfully merging this pull request may close these issues.

None yet

4 participants