trycmd
trycmd copied to clipboard
Custom panic messages in snapbox
std::assert_eq supports providing a custom panic message in a third argument (optionally followed by further parameters for the message arguments). pretty_assertions and similar-asserts both provide assert_eq! macros that are compatible.
snapbox however currently appears to hard-code it's panic message:
https://github.com/assert-rs/trycmd/blob/d73c84cda48aebda8a4b3fd404745c8bff0ab649/crates/snapbox/src/assert.rs#L55-L61
I think custom panic messages are a nice way to provide more context to a test failure, so I think it would be great if snapbox supported them.
Yeah, I've recently gotten requests for this from others. When creating snapbox, I overlooked this because
- I tend to use filesystem snapshots which provides enough extra context that I wasn't needing it
- A lot of times, I'm needing to use
Assert, meaning the macros don't get as much attention
The main care about I had was then handled with track_caller.
If we move forward with this, I would expect we'd try to match the new assert format that is coming out soon, where relevant.
My main concern is what the API should look like for something like this. Assert is a first class citizen in the API and should be able to be reused across calls (something which the current solution in #224 does not handle). I also don't like creating a bunch of variations of functions for different use cases. Maybe smaller builders off of Assert?
the new assert format that is coming out soon
Do you have a link for or more context about that?
https://github.com/rust-lang/rust/pull/111071