Skip to content

TestAssertionFailure should implement Error #543

@bjackman

Description

@bjackman

I'm trying to incrementally adopt Googletest. I have a test helper that returns anyhow::Result<()> and I want to start replacing its inner logic with verify_that!(...)?. verify_that! doesn't return an anyhow::Result of course, and usually in Anyhow I solve that by slapping a .context() call onto the end. But this doesn't work:

 2  error[E0599]: the method `context` exists for enum `Result<(), TestAssertionFailure>`, but its trait bounds were not satisfied
     --> src/test.rs:1297:57
      |
 1297 |             verify_that!(notif.status, eq(want_status)).context("assertion failed")?;
      |                                                         ^^^^^^^ method cannot be called on `Result<(), TestAssertionFailure>` due to unsatisfied trait bounds

So, basically you cannot mix TestAssertionFailure with other types of error (be it via Anyhow or just like Box<dyn Error> or whatever).

Maybe truly orthopraxic (just added that word to my vocabulary, thanks ChatGPT) test helpers wouldn't wanna do this and the fact that I have this problem is a sign that I haven't properly absorbed the googletest-rs doctrine? Like, when something that isn't exactly a test failure goes wrong, instead of returning errors in the failure case I should be failing an assert_*?

But, it seems unnecessary to enforce that doctrine? And maybe there are more important reasons that I haven't thought of why TestAssertionFailure should implement error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions