google / google/googletest-rust

TestAssertionFailure should implement Error

Open
#543 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
432
Forks
36
Avg merge
7d 17h
Merged PRs (30d)
2

Description

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` or whatever).

Maybe truly orthopraxic ([just added that word to my vocabulary](https://en.wikipedia.org/wiki/Orthopraxy), 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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.