catchorg / catchorg/Catch2

Attaching extra contextual information to REQUIRE() macro.

Open
#601 4 comments 1 reaction 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

Is there any (easy) way to attach contextual information to a REQUIRE macro?

I'd like to be able to do something like:

```
REQUIRE(expected_prog.size() > 0, "Program loaded from disk is empty! Either it's missing, or the file is damaged.");
```

Where the string `"Program loaded from disk is empty! Either it's missing, or the file is damaged."` is additionally printed to the output if the macro fails.

`INFO()` _kind_ of does this, but the "INFO" stack is not cleared by a `REQUIRE` macro, so if I have a number of tests in the setup of a complex object, and the last one fails, it dumps _all_ the `INFO()` messages to the console.

I can force scoping by putting each `INFO()/REQUIRE()` pair in a separate set of blocks, but when my setup procedure can involve 10+ calls that must be executed in sequence, it quickly gets hideous.

---

Before someone derails with comments about overly complex setup stuff, this is the setup procedure for a specialized piece of embedded hardware. Yes, it is that complicated, and I'm testing and exercising the low-level API. It's unavoidable.

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.