approx
approx copied to clipboard
Adding messages to assert_* macros
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);
Yeah! This seems like a great idea!
@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.