catchorg / catchorg/Catch2

Support for logging NSErrors and similar 'out' parameters

Open
#704 1 comment 0 reactions 0 assignees View on GitHub
Feature Request
Dominant language
C++
Stars
21.5k
Forks
3.5k
Avg merge
3d 16h
Merged PRs (30d)
2

Description

The Cocoa error handling conventions involve passing an `NSError` error object by reference, and if the called function/method fails, the `error` parameter will have been populated with a value containing detailed information. There may be other APIs using a similar pattern; I'm implementing a C API right now that works similarly, with an `Error` struct.

It would be very useful for Catch to be able to log the error when a test assertion fails. That is, if I have the following test:

``` objc
NSError *error;
REQUIRE([[NSFileManager defaultManager] deleteItemAtPath: path error: &error]);
```

and the test fails, I'd like Catch to log the value of `error`.

Clearly this will require some syntactic changes, since the REQUIRE macro has no knowledge of this `error` variable. It might need a different macro, or something wrapped around the `&error` expression, or whatever. I spent about an hour this morning experimenting and trying to figure something out, but couldn't get it to work. I was using `INFO("Error is "...)` to log the error data, but no matter what I do either the INFO gets called before the method is called, or it goes out of scope before the failure-handling code runs, or it gets called after the failure-handling code...

Any idea how to do this? I've started digging into the Catch source, but it's pretty thorny and honestly somewhat beyond my level of C++ competence.

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.