From 4bf17543d8fafd06000ed5097707718be88276ac Mon Sep 17 00:00:00 2001 From: xyligansereja Date: Thu, 9 Apr 2026 16:45:01 +0300 Subject: added patch commit_hash:343a4d8f871af0716a506a7b4a806821b6960075 --- library/cpp/testing/unittest/registar.h | 106 +++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 3 deletions(-) (limited to 'library/cpp/testing') diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h index b7909a0245b..a526f5aa184 100644 --- a/library/cpp/testing/unittest/registar.h +++ b/library/cpp/testing/unittest/registar.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,8 @@ #include #include #include +#include +#include extern bool CheckExceptionMessage(const char*, TString&); @@ -941,6 +944,42 @@ public: \ bool Failed_ = false; }; + template + TString BuildParamTestName(const char* base, const Es&... es) { + TString s = base; + ((s += "-", s += ToString(es)), ...); + return s; + } + + template + void ForEachProductRanges(F&& f) { + std::invoke(std::forward(f)); + } + + template + void ForEachProductRanges(F&& f, const FirstRange& first, const RestRanges&... rest) { + for (auto&& x : first) { + auto bound = std::bind_front(std::forward(f), x); + ForEachProductRanges(std::move(bound), rest...); + } + } + + template + void ForEachEnums(F&& f) { + ForEachProductRanges(std::forward(f), GetEnumAllValues()...); + } + + template + TString BuildParamTestNameFromTupleImpl(const char* base, const Tuple& t, std::index_sequence) { + return BuildParamTestName(base, std::get(t)...); + } + + template + TString BuildParamTestNameFromTuple(const char* base, const Tuple& t) { + return BuildParamTestNameFromTupleImpl( + base, t, std::make_index_sequence>{}); + } + #define UNIT_TEST_SUITE_REGISTRATION(T) \ static const ::NUnitTest::TTestBaseFactory Y_GENERATE_UNIQUE_ID(UTREG_); @@ -1056,9 +1095,70 @@ public: \ Y_UNIT_TEST_IMPL_REGISTER(N, FF, F) \ void TTestCase##N::Execute_(NUnitTest::TTestContext& ut_context Y_DECLARE_UNUSED) -#define Y_UNIT_TEST(N) Y_UNIT_TEST_IMPL(N, false, TCurrentTestCase) -#define Y_UNIT_TEST_F(N, F) Y_UNIT_TEST_IMPL(N, false, F) -#define SIMPLE_UNIT_FORKED_TEST(N) Y_UNIT_TEST_IMPL(N, true, TCurrentTestCase) +#define Y_UNIT_TEST_ENUM_IMPL(N, FF, F, ...) \ + struct TTestCase##N : public F { \ + using Types = std::tuple<__VA_ARGS__>; \ + Types Args; \ + TString ParametrizedTestName; \ + explicit TTestCase##N(Types args) \ + : Args(std::move(args)) \ + , ParametrizedTestName(::NUnitTest::BuildParamTestNameFromTuple(#N, Args)) \ + { \ + Name_ = ParametrizedTestName.c_str(); \ + ForceFork_ = FF; \ + File_ = nullptr; \ + Line_ = 0; \ + } \ + static THolder Create(Types args) { \ + return ::MakeHolder(std::move(args)); \ + } \ + void Execute_(NUnitTest::TTestContext&) override; \ + template \ + decltype(auto) Arg() const { \ + return std::get(Args); \ + } \ + }; \ + struct TTestRegistration##N { \ + TTestRegistration##N() { \ + ::NUnitTest::ForEachEnums<__VA_ARGS__>([&](auto... items) { \ + TCurrentTest::AddTest([=] { \ + return TTestCase##N::Create(typename TTestCase##N::Types(items...)); \ + }); \ + }); \ + } \ + }; \ + static const TTestRegistration##N testRegistration##N; \ + void TTestCase##N::Execute_(NUnitTest::TTestContext& ut_context Y_DECLARE_UNUSED) + +#define Y_UNIT_TEST_ENUM_IMPL_LINE(N, FF, F, ...) \ + Y_UNIT_TEST_ENUM_IMPL(N, FF, F, __VA_ARGS__) + +#define Y_UNIT_TEST(N, ...) \ + Y_UNIT_TEST_DISPATCH_##__VA_OPT__(ENUMS)(N __VA_OPT__(,) __VA_ARGS__) + +#define Y_UNIT_TEST_DISPATCH_(N) \ + Y_UNIT_TEST_IMPL(N, false, TCurrentTestCase) + +#define Y_UNIT_TEST_DISPATCH_ENUMS(N, ...) \ + Y_UNIT_TEST_ENUM_IMPL_LINE(N, false, TCurrentTestCase, __VA_ARGS__) + +#define Y_UNIT_TEST_F(N, F, ...) \ + Y_UNIT_TEST_F_DISPATCH_##__VA_OPT__(ENUMS)(N, F __VA_OPT__(,) __VA_ARGS__) + +#define Y_UNIT_TEST_F_DISPATCH_(N, F) \ + Y_UNIT_TEST_IMPL(N, false, F) + +#define Y_UNIT_TEST_F_DISPATCH_ENUMS(N, F, ...) \ + Y_UNIT_TEST_ENUM_IMPL_LINE(N, false, F, __VA_ARGS__) + +#define SIMPLE_UNIT_FORKED_TEST(N, ...) \ + SIMPLE_UNIT_FORKED_TEST_DISPATCH_##__VA_OPT__(ENUMS)(N __VA_OPT__(,) __VA_ARGS__) + +#define SIMPLE_UNIT_FORKED_TEST_DISPATCH_(N) \ + Y_UNIT_TEST_IMPL(N, true, TCurrentTestCase) + +#define SIMPLE_UNIT_FORKED_TEST_DISPATCH_ENUMS(N, ...) \ + Y_UNIT_TEST_ENUM_IMPL_LINE(N, true, TCurrentTestCase, __VA_ARGS__) #define Y_UNIT_TEST_SUITE_IMPLEMENTATION(N) \ namespace NTestSuite##N -- cgit v1.3