From 9a49523b3dc554a547c5f19a2b0d20980bc692f2 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 30 Mar 2025 10:56:05 +0800 Subject: [PATCH] neorados/test: Simplify copy prevention by using GtestNonCopyable Updates the test framework to use GoogleTest's simplified copy prevention mechanism by inheriting from `::testing::internal::GtestNonCopyable` instead of custom macros. This change: - Replaces deprecated GTEST_DISALLOW_* macros that were removed in GoogleTest (https://github.com/google/googletest/commit/bf66935e07825318ae519675d73d0f3e313b3ec6) - Aligns with GoogleTest's current approach for preventing test suite copying, See https://github.com/google/googletest/commit/93f08be653c36ddc6943e9513fc14c7292b4d007 - Enables updating the GoogleTest submodule to silence CMake warnings - Improves compatibility with recent distro-packaged GoogleTest versions - add the minimal required GTest version when finding this package, this change should have no impact to our packaging. as both deb and rpm packagings are using bundled googletest submodule. and googletest 1.14 has been included by recent stable releases of popular distros, like fedora 41 and ubuntu 24.04. While `GtestNonCopyable` is technically an internal helper, we already use other helpers from the `::testing::internal` namespace, so this change maintains consistency with our existing approach. Signed-off-by: Kefu Chai --- src/CMakeLists.txt | 2 +- src/test/neorados/common_tests.h | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe161985aede2..ad965d17d0d0e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -764,7 +764,7 @@ add_subdirectory(erasure-code) if(WITH_TESTS) option(WITH_SYSTEM_GTEST "require and build with system gtest and gmock" OFF) if(WITH_SYSTEM_GTEST) - find_package(GTest REQUIRED) + find_package(GTest 1.13.0 REQUIRED) find_package(GMock REQUIRED) else() set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) diff --git a/src/test/neorados/common_tests.h b/src/test/neorados/common_tests.h index 5c2ebde4db6aa..0aec479ac6821 100644 --- a/src/test/neorados/common_tests.h +++ b/src/test/neorados/common_tests.h @@ -396,14 +396,11 @@ private: "test_suite_name must not be empty"); \ static_assert(sizeof(GTEST_STRINGIFY_(test_name)) > 1, \ "test_name must not be empty"); \ - class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) : public fixture { \ + class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ + : public fixture, private ::testing::internal::GTestNonCopyable { \ public: \ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() = default; \ ~GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() override = default; \ - GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \ - test_name)); \ - GTEST_DISALLOW_MOVE_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \ - test_name)); \ \ private: \ boost::asio::awaitable CoTestBody() override; \ -- 2.39.5