Skip to content

Custom panic messages in snapbox #223

Open

Description

@not-my-profile

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.

Activity

  1. added 2 commits that reference this issue on Aug 18, 2023
    f4e924c
    94fb977
  2. epage commented on Aug 18, 2023

    @epage
    Contributor

    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?

  3. not-my-profile commented on Aug 18, 2023

    @not-my-profile
    Author

    the new assert format that is coming out soon

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

  4. epage commented on Aug 19, 2023

    @epage
    Contributor
  5. added a commit that references this issue on May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-snapboxArea: snapbox package

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions