From 19b7be8db9288e49603e47727ba6da1d422d457b Mon Sep 17 00:00:00 2001 From: Daniil Cherednik Date: Thu, 17 Jul 2025 15:16:17 +0200 Subject: [PATCH] Move Y_UNIT_TEST_TWIN, Y_UNIT_TEST_QUAD helpers in to ydb testlib --- ydb/core/kqp/ut/common/kqp_ut_common.h | 35 +----------------- ydb/core/tx/datashard/datashard_ut_order.cpp | 2 +- ydb/library/testlib/helpers.h | 39 ++++++++++++++++++++ 3 files changed, 41 insertions(+), 35 deletions(-) create mode 100644 ydb/library/testlib/helpers.h diff --git a/ydb/core/kqp/ut/common/kqp_ut_common.h b/ydb/core/kqp/ut/common/kqp_ut_common.h index 4d01007643cb..ca1f702c6e48 100644 --- a/ydb/core/kqp/ut/common/kqp_ut_common.h +++ b/ydb/core/kqp/ut/common/kqp_ut_common.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -19,40 +20,6 @@ #include -#define Y_UNIT_TEST_TWIN(N, OPT) \ - template \ - struct TTestCase##N : public TCurrentTestCase { \ - TTestCase##N() : TCurrentTestCase() { \ - if constexpr (OPT) { Name_ = #N "+" #OPT; } else { Name_ = #N "-" #OPT; } \ - } \ - static THolder CreateOn() { return ::MakeHolder>(); } \ - static THolder CreateOff() { return ::MakeHolder>(); } \ - void Execute_(NUnitTest::TTestContext&) override; \ - }; \ - struct TTestRegistration##N { \ - TTestRegistration##N() { \ - TCurrentTest::AddTest(TTestCase##N::CreateOn); \ - TCurrentTest::AddTest(TTestCase##N::CreateOff); \ - } \ - }; \ - static TTestRegistration##N testRegistration##N; \ - template \ - void TTestCase##N::Execute_(NUnitTest::TTestContext& ut_context Y_DECLARE_UNUSED) - -#define Y_UNIT_TEST_QUAD(N, OPT1, OPT2) \ - template void N(NUnitTest::TTestContext&); \ - struct TTestRegistration##N { \ - TTestRegistration##N() { \ - TCurrentTest::AddTest(#N "-" #OPT1 "-" #OPT2, static_cast(&N), false); \ - TCurrentTest::AddTest(#N "+" #OPT1 "-" #OPT2, static_cast(&N), false); \ - TCurrentTest::AddTest(#N "-" #OPT1 "+" #OPT2, static_cast(&N), false); \ - TCurrentTest::AddTest(#N "+" #OPT1 "+" #OPT2, static_cast(&N), false); \ - } \ - }; \ - static TTestRegistration##N testRegistration##N; \ - template \ - void N(NUnitTest::TTestContext&) - template TString MakeQuery(const TString& tmpl) { return TStringBuilder() diff --git a/ydb/core/tx/datashard/datashard_ut_order.cpp b/ydb/core/tx/datashard/datashard_ut_order.cpp index 25f943ebf894..460ef3768e04 100644 --- a/ydb/core/tx/datashard/datashard_ut_order.cpp +++ b/ydb/core/tx/datashard/datashard_ut_order.cpp @@ -7,7 +7,7 @@ #include #include #include -#include // Y_UNIT_TEST_(TWIN|QUAD) +#include #include #include #include diff --git a/ydb/library/testlib/helpers.h b/ydb/library/testlib/helpers.h new file mode 100644 index 000000000000..f9fc628e6bb2 --- /dev/null +++ b/ydb/library/testlib/helpers.h @@ -0,0 +1,39 @@ +#pragma once + +#include + +#define Y_UNIT_TEST_TWIN(N, OPT) \ + template \ + struct TTestCase##N : public TCurrentTestCase { \ + TTestCase##N() : TCurrentTestCase() { \ + if constexpr (OPT) { Name_ = #N "+" #OPT; } else { Name_ = #N "-" #OPT; } \ + } \ + static THolder CreateOn() { return ::MakeHolder>(); } \ + static THolder CreateOff() { return ::MakeHolder>(); } \ + void Execute_(NUnitTest::TTestContext&) override; \ + }; \ + struct TTestRegistration##N { \ + TTestRegistration##N() { \ + TCurrentTest::AddTest(TTestCase##N::CreateOn); \ + TCurrentTest::AddTest(TTestCase##N::CreateOff); \ + } \ + }; \ + static TTestRegistration##N testRegistration##N; \ + template \ + void TTestCase##N::Execute_(NUnitTest::TTestContext& ut_context Y_DECLARE_UNUSED) + +#define Y_UNIT_TEST_QUAD(N, OPT1, OPT2) \ + template void N(NUnitTest::TTestContext&); \ + struct TTestRegistration##N { \ + TTestRegistration##N() { \ + TCurrentTest::AddTest(#N "-" #OPT1 "-" #OPT2, static_cast(&N), false); \ + TCurrentTest::AddTest(#N "+" #OPT1 "-" #OPT2, static_cast(&N), false); \ + TCurrentTest::AddTest(#N "-" #OPT1 "+" #OPT2, static_cast(&N), false); \ + TCurrentTest::AddTest(#N "+" #OPT1 "+" #OPT2, static_cast(&N), false); \ + } \ + }; \ + static TTestRegistration##N testRegistration##N; \ + template \ + void N(NUnitTest::TTestContext&) + +