diff options
author | alexv-smirnov <alex@ydb.tech> | 2023-03-06 14:00:15 +0300 |
---|---|---|
committer | alexv-smirnov <alex@ydb.tech> | 2023-03-06 14:00:15 +0300 |
commit | 2b52843982ad694cf840c1f8f4db4872080b1418 (patch) | |
tree | c93bc66177c8ab9d4868f9cc531b88595c55cf1a | |
parent | ca44d2f11d133072b5d154d206ff3840dc2383ce (diff) | |
download | ydb-2b52843982ad694cf840c1f8f4db4872080b1418.tar.gz |
Convert ydb/core/blobstorage/base tests to gtest
20 files changed, 262 insertions, 26 deletions
diff --git a/library/cpp/testing/CMakeLists.txt b/library/cpp/testing/CMakeLists.txt index 6953208ad6..23be63b053 100644 --- a/library/cpp/testing/CMakeLists.txt +++ b/library/cpp/testing/CMakeLists.txt @@ -9,7 +9,9 @@ add_subdirectory(benchmark) add_subdirectory(common) add_subdirectory(gmock_in_unittest) +add_subdirectory(gtest) add_subdirectory(gtest_extensions) +add_subdirectory(gtest_main) add_subdirectory(hook) add_subdirectory(unittest) add_subdirectory(unittest_main) diff --git a/library/cpp/testing/gtest/CMakeLists.darwin.txt b/library/cpp/testing/gtest/CMakeLists.darwin.txt new file mode 100644 index 0000000000..41bc7e20f9 --- /dev/null +++ b/library/cpp/testing/gtest/CMakeLists.darwin.txt @@ -0,0 +1,25 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(cpp-testing-gtest) +target_link_libraries(cpp-testing-gtest PUBLIC + contrib-libs-cxxsupp + yutil + restricted-googletest-googlemock + restricted-googletest-googletest + cpp-string_utils-relaxed_escaper + cpp-testing-common + cpp-testing-gtest_extensions + cpp-testing-hook +) +target_sources(cpp-testing-gtest PRIVATE + ${CMAKE_SOURCE_DIR}/library/cpp/testing/gtest/gtest.cpp + ${CMAKE_SOURCE_DIR}/library/cpp/testing/gtest/main.cpp + ${CMAKE_SOURCE_DIR}/library/cpp/testing/gtest/matchers.cpp +) diff --git a/library/cpp/testing/gtest/CMakeLists.linux-aarch64.txt b/library/cpp/testing/gtest/CMakeLists.linux-aarch64.txt new file mode 100644 index 0000000000..e172e2381a --- /dev/null +++ b/library/cpp/testing/gtest/CMakeLists.linux-aarch64.txt @@ -0,0 +1,26 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(cpp-testing-gtest) +target_link_libraries(cpp-testing-gtest PUBLIC + contrib-libs-linux-headers + contrib-libs-cxxsupp + yutil + restricted-googletest-googlemock + restricted-googletest-googletest + cpp-string_utils-relaxed_escaper + cpp-testing-common + cpp-testing-gtest_extensions + cpp-testing-hook +) +target_sources(cpp-testing-gtest PRIVATE + ${CMAKE_SOURCE_DIR}/library/cpp/testing/gtest/gtest.cpp + ${CMAKE_SOURCE_DIR}/library/cpp/testing/gtest/main.cpp + ${CMAKE_SOURCE_DIR}/library/cpp/testing/gtest/matchers.cpp +) diff --git a/library/cpp/testing/gtest/CMakeLists.linux.txt b/library/cpp/testing/gtest/CMakeLists.linux.txt new file mode 100644 index 0000000000..e172e2381a --- /dev/null +++ b/library/cpp/testing/gtest/CMakeLists.linux.txt @@ -0,0 +1,26 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(cpp-testing-gtest) +target_link_libraries(cpp-testing-gtest PUBLIC + contrib-libs-linux-headers + contrib-libs-cxxsupp + yutil + restricted-googletest-googlemock + restricted-googletest-googletest + cpp-string_utils-relaxed_escaper + cpp-testing-common + cpp-testing-gtest_extensions + cpp-testing-hook +) +target_sources(cpp-testing-gtest PRIVATE + ${CMAKE_SOURCE_DIR}/library/cpp/testing/gtest/gtest.cpp + ${CMAKE_SOURCE_DIR}/library/cpp/testing/gtest/main.cpp + ${CMAKE_SOURCE_DIR}/library/cpp/testing/gtest/matchers.cpp +) diff --git a/library/cpp/testing/gtest/CMakeLists.txt b/library/cpp/testing/gtest/CMakeLists.txt new file mode 100644 index 0000000000..5bb4faffb4 --- /dev/null +++ b/library/cpp/testing/gtest/CMakeLists.txt @@ -0,0 +1,15 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + +if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND UNIX AND NOT APPLE AND NOT ANDROID) + include(CMakeLists.linux-aarch64.txt) +elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + include(CMakeLists.darwin.txt) +elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND UNIX AND NOT APPLE AND NOT ANDROID) + include(CMakeLists.linux.txt) +endif() diff --git a/library/cpp/testing/gtest/ut/README.md b/library/cpp/testing/gtest/ut/README.md new file mode 100644 index 0000000000..ee8d212c18 --- /dev/null +++ b/library/cpp/testing/gtest/ut/README.md @@ -0,0 +1 @@ +Note: integration tests are located in */devtools/ya/test/tests/gtest_beta*. Launch them as well after changing this library. diff --git a/library/cpp/testing/gtest/ut/golden/data.txt b/library/cpp/testing/gtest/ut/golden/data.txt new file mode 100644 index 0000000000..190a18037c --- /dev/null +++ b/library/cpp/testing/gtest/ut/golden/data.txt @@ -0,0 +1 @@ +123 diff --git a/library/cpp/testing/gtest/ut/matchers_ut.cpp b/library/cpp/testing/gtest/ut/matchers_ut.cpp new file mode 100644 index 0000000000..3ba3cf3e92 --- /dev/null +++ b/library/cpp/testing/gtest/ut/matchers_ut.cpp @@ -0,0 +1,15 @@ +#include <library/cpp/testing/common/env.h> +#include <library/cpp/testing/gtest/gtest.h> + +#include <array> +#include <vector> + +constexpr std::string_view TEST_DATA_TEXT{"123\n"}; +constexpr std::array<char, 4> TEST_DATA_ARRAY{'1', '2', '3', '\n'}; +const std::vector<char> TEST_DATA_CHAR_VECTOR{'1', '2', '3', '\n'}; + +TEST(GoldenFileEq, Example) { + EXPECT_THAT(TEST_DATA_TEXT, NGTest::GoldenFileEq(std::string(SRC_("golden/data.txt")))); + EXPECT_THAT(TEST_DATA_ARRAY, NGTest::GoldenFileEq(TString(SRC_("golden/data.txt")))); + EXPECT_THAT(TEST_DATA_CHAR_VECTOR, NGTest::GoldenFileEq(SRC_("golden/data.txt"))); +} diff --git a/library/cpp/testing/gtest/ut/ut.cpp b/library/cpp/testing/gtest/ut/ut.cpp new file mode 100644 index 0000000000..0b6d69b2cf --- /dev/null +++ b/library/cpp/testing/gtest/ut/ut.cpp @@ -0,0 +1,48 @@ +#include <library/cpp/testing/gtest/gtest.h> +#include <library/cpp/testing/hook/hook.h> + +static int HookOrder = 0; +static int PreInitHook1 = 0; +static int PreInitHook2 = 0; +static int PreRunHook1 = 0; +static int PreRunHook2 = 0; +static int PostRunHook1 = 0; +static int PostRunHook2 = 0; + +Y_TEST_HOOK_BEFORE_INIT(PreInit1) { + PreInitHook1 = ++HookOrder; +} + +Y_TEST_HOOK_BEFORE_INIT(PreInit2) { + PreInitHook2 = ++HookOrder; +} + +Y_TEST_HOOK_BEFORE_RUN(PreRun1) { + PreRunHook1 = ++HookOrder; +} + +Y_TEST_HOOK_BEFORE_RUN(PreRun2) { + PreRunHook2 = ++HookOrder; +} + +Y_TEST_HOOK_AFTER_RUN(PostRun1) { + PostRunHook1 = ++HookOrder; + Cerr << "PostRunHook1" << Endl; +} + +Y_TEST_HOOK_AFTER_RUN(PostRun2) { + PostRunHook2 = ++HookOrder; + Cerr << "PostRunHook2" << Endl; +} + +TEST(Gtest, HookOrder) { + EXPECT_NEAR(PreInitHook1, PreInitHook2, 1); + EXPECT_NEAR(PreRunHook1, PreRunHook2, 1); + EXPECT_LE(std::max(PreInitHook1, PreInitHook2), std::min(PreRunHook1, PreRunHook2)); + EXPECT_EQ(PostRunHook1, 0); + EXPECT_EQ(PostRunHook2, 0); +} + +TEST(Gtest, Metrics) { + RecordProperty("Metric1", 10); +} diff --git a/library/cpp/testing/gtest_main/CMakeLists.darwin.txt b/library/cpp/testing/gtest_main/CMakeLists.darwin.txt new file mode 100644 index 0000000000..1075010e22 --- /dev/null +++ b/library/cpp/testing/gtest_main/CMakeLists.darwin.txt @@ -0,0 +1,18 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(cpp-testing-gtest_main) +target_link_libraries(cpp-testing-gtest_main PUBLIC + contrib-libs-cxxsupp + yutil + cpp-testing-gtest +) +target_sources(cpp-testing-gtest_main PRIVATE + ${CMAKE_SOURCE_DIR}/library/cpp/testing/gtest_main/main.cpp +) diff --git a/library/cpp/testing/gtest_main/CMakeLists.linux-aarch64.txt b/library/cpp/testing/gtest_main/CMakeLists.linux-aarch64.txt new file mode 100644 index 0000000000..f3ef692fb6 --- /dev/null +++ b/library/cpp/testing/gtest_main/CMakeLists.linux-aarch64.txt @@ -0,0 +1,19 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(cpp-testing-gtest_main) +target_link_libraries(cpp-testing-gtest_main PUBLIC + contrib-libs-linux-headers + contrib-libs-cxxsupp + yutil + cpp-testing-gtest +) +target_sources(cpp-testing-gtest_main PRIVATE + ${CMAKE_SOURCE_DIR}/library/cpp/testing/gtest_main/main.cpp +) diff --git a/library/cpp/testing/gtest_main/CMakeLists.linux.txt b/library/cpp/testing/gtest_main/CMakeLists.linux.txt new file mode 100644 index 0000000000..f3ef692fb6 --- /dev/null +++ b/library/cpp/testing/gtest_main/CMakeLists.linux.txt @@ -0,0 +1,19 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(cpp-testing-gtest_main) +target_link_libraries(cpp-testing-gtest_main PUBLIC + contrib-libs-linux-headers + contrib-libs-cxxsupp + yutil + cpp-testing-gtest +) +target_sources(cpp-testing-gtest_main PRIVATE + ${CMAKE_SOURCE_DIR}/library/cpp/testing/gtest_main/main.cpp +) diff --git a/library/cpp/testing/gtest_main/CMakeLists.txt b/library/cpp/testing/gtest_main/CMakeLists.txt new file mode 100644 index 0000000000..5bb4faffb4 --- /dev/null +++ b/library/cpp/testing/gtest_main/CMakeLists.txt @@ -0,0 +1,15 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + +if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND UNIX AND NOT APPLE AND NOT ANDROID) + include(CMakeLists.linux-aarch64.txt) +elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + include(CMakeLists.darwin.txt) +elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND UNIX AND NOT APPLE AND NOT ANDROID) + include(CMakeLists.linux.txt) +endif() diff --git a/ydb/core/blobstorage/base/batched_vec_ut.cpp b/ydb/core/blobstorage/base/batched_vec_ut.cpp index 2cbcd98a66..cf6d6691ee 100644 --- a/ydb/core/blobstorage/base/batched_vec_ut.cpp +++ b/ydb/core/blobstorage/base/batched_vec_ut.cpp @@ -1,12 +1,13 @@ #include "batched_vec.h" -#include <library/cpp/testing/unittest/registar.h> +#include <library/cpp/testing/gtest/gtest.h> +#include <ydb/library/testlib/unittest_gtest_macro_subst.h> namespace NKikimr { - Y_UNIT_TEST_SUITE(TBatchedVecTest) { - Y_UNIT_TEST(TestToStringInt) { + namespace { + TEST(TBatchedVecTest, TestToStringInt) { TBatchedVec<ui64> vec {0, 1, 2, 3}; UNIT_ASSERT_C(vec.ToString() == "[0 1 2 3]", "given string: " << vec.ToString()); } @@ -19,7 +20,7 @@ namespace NKikimr { } }; - Y_UNIT_TEST(TestOutputTOutputType) { + TEST(TBatchedVecTest, TestOutputTOutputType) { TBatchedVec<TOutputType> vec { {'a'}, {'b'}, {'c'}, {'d'} }; TStringStream str; vec.Output(str); diff --git a/ydb/core/blobstorage/base/bufferwithgaps_ut.cpp b/ydb/core/blobstorage/base/bufferwithgaps_ut.cpp index 71e1e1a5eb..70500c664a 100644 --- a/ydb/core/blobstorage/base/bufferwithgaps_ut.cpp +++ b/ydb/core/blobstorage/base/bufferwithgaps_ut.cpp @@ -1,18 +1,19 @@ #include "bufferwithgaps.h" -#include <library/cpp/testing/unittest/registar.h> +#include <library/cpp/testing/gtest/gtest.h> +#include <ydb/library/testlib/unittest_gtest_macro_subst.h> using NKikimr::TBufferWithGaps; -Y_UNIT_TEST_SUITE(BufferWithGaps) { +namespace { - Y_UNIT_TEST(Basic) { + TEST(BufferWithGaps, Basic) { TBufferWithGaps buffer(0); TString data = "Hello!"; buffer.SetData(TString(data)); UNIT_ASSERT_STRINGS_EQUAL(data, buffer.Substr(0, buffer.Size())); } - Y_UNIT_TEST(IsReadable) { + TEST(BufferWithGaps, IsReadable) { TBufferWithGaps buffer(0); TString data = "Hello! How are you? I'm fine, and you? Me too, thanks!"; TString gaps = "G GGGG GG GGG G G"; diff --git a/ydb/core/blobstorage/base/ptr_ut.cpp b/ydb/core/blobstorage/base/ptr_ut.cpp index b0854f28cc..9826d04380 100644 --- a/ydb/core/blobstorage/base/ptr_ut.cpp +++ b/ydb/core/blobstorage/base/ptr_ut.cpp @@ -1,10 +1,11 @@ #include "ptr.h" #include <library/cpp/deprecated/atomic/atomic.h> -#include <library/cpp/testing/unittest/registar.h> +#include <library/cpp/testing/gtest/gtest.h> +#include <ydb/library/testlib/unittest_gtest_macro_subst.h> using namespace NKikimr; -Y_UNIT_TEST_SUITE(PtrTest) { +namespace { ////////////////////////////////////////////////////////////////////////////////////////// // Basic test for TAtomicRefCountWithDeleter @@ -40,22 +41,22 @@ Y_UNIT_TEST_SUITE(PtrTest) { using TTest1Ptr = TIntrusivePtr<TTest1>; - Y_UNIT_TEST(Test1) { + TEST(PtrTest, Test1) { TSimpleTestDeleter deleter; - UNIT_ASSERT_EQUAL(deleter.GetNum(), 0); + UNIT_ASSERT_EQUAL(deleter.GetNum(), 0u ); { TTest1Ptr ptr1 = new TTest1(deleter); TTest1Ptr ptr2(ptr1); } - UNIT_ASSERT_EQUAL(deleter.GetNum(), 1); + UNIT_ASSERT_EQUAL(deleter.GetNum(), 1u ); { TTest1Ptr ptr1 = new TTest1(deleter); TTest1Ptr ptr2(ptr1); } - UNIT_ASSERT_EQUAL(deleter.GetNum(), 2); + UNIT_ASSERT_EQUAL(deleter.GetNum(), 2u ); } } diff --git a/ydb/core/blobstorage/base/ut/CMakeLists.darwin.txt b/ydb/core/blobstorage/base/ut/CMakeLists.darwin.txt index 35142e6abc..fda46210c0 100644 --- a/ydb/core/blobstorage/base/ut/CMakeLists.darwin.txt +++ b/ydb/core/blobstorage/base/ut/CMakeLists.darwin.txt @@ -8,15 +8,13 @@ add_executable(ydb-core-blobstorage-base-ut) -target_include_directories(ydb-core-blobstorage-base-ut PRIVATE - ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/base -) target_link_libraries(ydb-core-blobstorage-base-ut PUBLIC contrib-libs-cxxsupp yutil cpp-malloc-system library-cpp-cpuid_check - cpp-testing-unittest_main + cpp-testing-gtest + cpp-testing-gtest_main core-blobstorage-base library-cpp-getopt library-cpp-svnversion diff --git a/ydb/core/blobstorage/base/ut/CMakeLists.linux-aarch64.txt b/ydb/core/blobstorage/base/ut/CMakeLists.linux-aarch64.txt index 0fbe74917c..a6e984cda1 100644 --- a/ydb/core/blobstorage/base/ut/CMakeLists.linux-aarch64.txt +++ b/ydb/core/blobstorage/base/ut/CMakeLists.linux-aarch64.txt @@ -8,15 +8,13 @@ add_executable(ydb-core-blobstorage-base-ut) -target_include_directories(ydb-core-blobstorage-base-ut PRIVATE - ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/base -) target_link_libraries(ydb-core-blobstorage-base-ut PUBLIC contrib-libs-linux-headers contrib-libs-cxxsupp yutil library-cpp-lfalloc - cpp-testing-unittest_main + cpp-testing-gtest + cpp-testing-gtest_main core-blobstorage-base library-cpp-getopt library-cpp-svnversion diff --git a/ydb/core/blobstorage/base/ut/CMakeLists.linux.txt b/ydb/core/blobstorage/base/ut/CMakeLists.linux.txt index 3897ecbcfa..4ff87315a1 100644 --- a/ydb/core/blobstorage/base/ut/CMakeLists.linux.txt +++ b/ydb/core/blobstorage/base/ut/CMakeLists.linux.txt @@ -8,9 +8,6 @@ add_executable(ydb-core-blobstorage-base-ut) -target_include_directories(ydb-core-blobstorage-base-ut PRIVATE - ${CMAKE_SOURCE_DIR}/ydb/core/blobstorage/base -) target_link_libraries(ydb-core-blobstorage-base-ut PUBLIC contrib-libs-linux-headers contrib-libs-cxxsupp @@ -18,7 +15,8 @@ target_link_libraries(ydb-core-blobstorage-base-ut PUBLIC cpp-malloc-tcmalloc libs-tcmalloc-no_percpu_cache library-cpp-cpuid_check - cpp-testing-unittest_main + cpp-testing-gtest + cpp-testing-gtest_main core-blobstorage-base library-cpp-getopt library-cpp-svnversion diff --git a/ydb/library/testlib/unittest_gtest_macro_subst.h b/ydb/library/testlib/unittest_gtest_macro_subst.h new file mode 100644 index 0000000000..e3154b86a3 --- /dev/null +++ b/ydb/library/testlib/unittest_gtest_macro_subst.h @@ -0,0 +1,9 @@ +// Macro substitutions for tests converted from Unittest to GTest + +#define UNIT_ASSERT( condition ) ASSERT_TRUE( condition ) +#define UNIT_ASSERT_C( condition, comment ) ASSERT_TRUE( condition ) << comment +#define UNIT_ASSERT_STRINGS_EQUAL( p1, p2 ) ASSERT_EQ( p1, p2 ) +#define UNIT_ASSERT_EQUAL( p1, p2 ) ASSERT_EQ( p1, p2 ) +#define UNIT_ASSERT_EQUAL_C( p1, p2, comment ) ASSERT_EQ( p1, p2 ) << comment +#define UNIT_ASSERT_UNEQUAL( p1, p2 ) ASSERT_NE( p1, p2 ) +#define UNIT_ASSERT_UNEQUAL_C( p1, p2, comment ) ASSERT_NE( p1, p2 ) << comment
\ No newline at end of file |