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

Adding messages to assert_* macros #44

Open
arekfu opened this issue Nov 8, 2018 · 2 comments · May be fixed by #45
Open

Adding messages to assert_* macros #44

arekfu opened this issue Nov 8, 2018 · 2 comments · May be fixed by #45

Comments

@arekfu
Copy link

arekfu commented Nov 8, 2018

It would be great to extend the assert_* macros to accept a custom panic message, the way assert_eq! does:

assert_eq!(a, b, "Failed to compare a and b; a={}, b={}", a, b);
@brendanzab
Copy link
Owner

Yeah! This seems like a great idea!

@adrianwong
Copy link
Contributor

@brendanzab I've attempted a fix for this.

Due to parsing ambiguities arising from adding a second repeating pattern, I took the approach of separating the panic message args from the rest of the macro args with a ;, like so:

($given:expr, $expected:expr $(, $opt:ident = $val:expr)*; $($arg:tt)*)
                                                        ^^^

which allows us to do this:

assert_abs_diff_eq!(x, y, epsilon = epsilon; "Should panic. x = {:?}, y = {:?},
    epsilon: {:?}", x, y, epsilon);

It feels rather hacky though, and deviates from how Rust asserts behave. If you've got a better idea on how to tackle this, I'm all ears.

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 a pull request may close this issue.

3 participants