diff --git a/contrib/googletest-cmake/CMakeLists.txt b/contrib/googletest-cmake/CMakeLists.txt index 5b00096615a..c917a2f31a7 100644 --- a/contrib/googletest-cmake/CMakeLists.txt +++ b/contrib/googletest-cmake/CMakeLists.txt @@ -6,13 +6,7 @@ target_compile_definitions (_gtest PUBLIC GTEST_HAS_POSIX_RE=0) target_include_directories(_gtest SYSTEM PUBLIC "${SRC_DIR}/googletest/include") target_include_directories(_gtest PRIVATE "${SRC_DIR}/googletest") -add_library(_gtest_main "${SRC_DIR}/googletest/src/gtest_main.cc") -set_target_properties(_gtest_main PROPERTIES VERSION "1.0.0") -target_link_libraries(_gtest_main PUBLIC _gtest) - -add_library(_gtest_all INTERFACE) -target_link_libraries(_gtest_all INTERFACE _gtest _gtest_main) -add_library(ch_contrib::gtest_all ALIAS _gtest_all) +add_library(ch_contrib::gtest ALIAS _gtest) add_library(_gmock "${SRC_DIR}/googlemock/src/gmock-all.cc") set_target_properties(_gmock PROPERTIES VERSION "1.0.0") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1c93bc5d35e..d13c9cbe9bc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -592,7 +592,7 @@ if (ENABLE_TESTS) target_link_libraries(unit_tests_dbms PRIVATE ch_contrib::gmock_all - ch_contrib::gtest_all + ch_contrib::gtest clickhouse_functions clickhouse_aggregate_functions clickhouse_parsers diff --git a/src/Common/tests/gtest_main.cpp b/src/Common/tests/gtest_main.cpp new file mode 100644 index 00000000000..81c46950798 --- /dev/null +++ b/src/Common/tests/gtest_main.cpp @@ -0,0 +1,18 @@ +#include + +#include + +class ContextEnvironment : public testing::Environment +{ +public: + void SetUp() override { getContext(); } +}; + +int main(int argc, char ** argv) +{ + testing::InitGoogleTest(&argc, argv); + + testing::AddGlobalTestEnvironment(new ContextEnvironment); + + return RUN_ALL_TESTS(); +} diff --git a/src/Coordination/tests/gtest_coordination.cpp b/src/Coordination/tests/gtest_coordination.cpp index d207fab332e..42bf9d89103 100644 --- a/src/Coordination/tests/gtest_coordination.cpp +++ b/src/Coordination/tests/gtest_coordination.cpp @@ -71,6 +71,13 @@ protected: DB::KeeperContextPtr keeper_context = std::make_shared(true); Poco::Logger * log{&Poco::Logger::get("CoordinationTest")}; + void SetUp() override + { + Poco::AutoPtr channel(new Poco::ConsoleChannel(std::cerr)); + Poco::Logger::root().setChannel(channel); + Poco::Logger::root().setLevel("trace"); + } + void setLogDirectory(const std::string & path) { keeper_context->setLogDisk(std::make_shared("LogDisk", path)); } void setSnapshotDirectory(const std::string & path) @@ -2911,13 +2918,4 @@ INSTANTIATE_TEST_SUITE_P(CoordinationTestSuite, CoordinationTest, ::testing::ValuesIn(std::initializer_list{CompressionParam{true, ".zstd"}, CompressionParam{false, ""}})); -int main(int argc, char ** argv) -{ - Poco::AutoPtr channel(new Poco::ConsoleChannel(std::cerr)); - Poco::Logger::root().setChannel(channel); - Poco::Logger::root().setLevel("trace"); - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - #endif