From 1ff1274ee55d5766dadf3f4b55463b2bc1d83529 Mon Sep 17 00:00:00 2001 From: John Freeman Date: Thu, 14 Nov 2024 08:55:58 -0600 Subject: [PATCH] AND_THEN --- src/test/jtx/impl/subcases.cpp | 1 + src/test/jtx/subcases.h | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/jtx/impl/subcases.cpp b/src/test/jtx/impl/subcases.cpp index 8745f3d767..ab563a0a27 100644 --- a/src/test/jtx/impl/subcases.cpp +++ b/src/test/jtx/impl/subcases.cpp @@ -26,6 +26,7 @@ namespace subcases { Subcase::Subcase(Context& context, char const* name) : context_(context), name_(name) { + lastCreated = this; } Subcase::operator bool() const diff --git a/src/test/jtx/subcases.h b/src/test/jtx/subcases.h index 639a4029f7..7bf87907ee 100644 --- a/src/test/jtx/subcases.h +++ b/src/test/jtx/subcases.h @@ -113,6 +113,7 @@ struct Subcase ~Subcase(); /** Return true if we should enter this subcase. */ operator bool() const; + thread_local static Subcase* lastCreated; }; using Supercase = std::function; @@ -123,9 +124,14 @@ execute(beast::unit_test::suite* suite, char const* name, Supercase supercase); } // namespace subcases #define TEST_CASE(name) void name(subcases::Context& _09876) -#define SUBCASE(name) if (subcases::Subcase _54321{_09876, name}) +#define SUBCASE(name) if (subcases::Subcase sc##__COUNTER__{_09876, name}) #define SKIP(name) if (false) #define EXECUTE(name) \ subcases::execute(this, #name, [&](auto& ctx) { name(ctx); }) +// `AND_THEN` defines a subcase to contain all remaining subcases, +// without having to indent them in a nested block. +#define AND_THEN(name) \ + subcases::Subcase sc##__COUNTER__{_09876, name}; \ + if (!*subcases::Subcase.lastCreated) return; #endif