You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C++20 coroutines are increasingly used for asynchronous APIs, but writing tests for coroutine-based code typically requires blocking adapters (e.g. sync_wait) or custom wrappers. This adds friction and does not work in event-loop-driven environments where blocking inside a test body is not possible.
It would therefore be useful if Catch2 supported test cases defined as coroutines, for example:
TEST_CASE_ASYNC("my async test")
{
auto result = co_awaitasync_operation();
CHECK(result == 42);
}
Because Catch2 supports C++14, this feature would only be available when compiling with C++20/coroutine support. It would have to be guarded behind a build config flag.
Additional context
We have implemented a proof of concept in a private fork where we added a very basic coroutine task type. All scheduling and event-loop integration happen in user code, which keeps the approach flexible while adding minimal complexity inside Catch2. This was enough to solve related issues such as #1755 (we also target Emscripten).
I've looked at other C++ testing frameworks, but none currently seem to support coroutines natively. However, popular frameworks in other languages (e.g. C#, Python, JavaScript) support async tests, so the concept itself isn't novel.
Activity