catchorg / catchorg/Catch2

Runtime detection of catch2

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

Description

**Description**
I'm writing a custom assert macro because I want to test cases involving `assert()`.
My objective is this custom assert to behave like a regular assert but when it is running catch2 I want it to throw an exception. Some `assert` are expensive test, so I don't want to turn them into exception, as that would slow regular execution.

Is this currently possible to detect catch2 at runtime ?

**Additional context**
Something like that
```cpp
#ifndef NDEBUG
#define my_assert(e) ((void)(static_cast(e) ? 0 : pivot_assert_failed(#e, __FILE__, __LINE__)))
#define my_assert_failed(expr, file, line) { if (/* CATCH2 */) throw assertion_failed_exception(); else std::abort(); }
#else
#define my_assert(e) 0;
#endif

```

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.