trycmd icon indicating copy to clipboard operation
trycmd copied to clipboard

Custom panic messages in snapbox

Open not-my-profile opened this issue 2 years ago • 3 comments

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.

not-my-profile avatar Aug 18 '23 04:08 not-my-profile

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?

epage avatar Aug 18 '23 20:08 epage

the new assert format that is coming out soon

Do you have a link for or more context about that?

not-my-profile avatar Aug 18 '23 23:08 not-my-profile

https://github.com/rust-lang/rust/pull/111071

epage avatar Aug 19 '23 00:08 epage