]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
neorados/test: Simplify copy prevention by using GtestNonCopyable
authorKefu Chai <tchaikov@gmail.com>
Sun, 30 Mar 2025 02:56:05 +0000 (10:56 +0800)
committerKefu Chai <tchaikov@gmail.com>
Sun, 30 Mar 2025 03:31:40 +0000 (11:31 +0800)
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 <tchaikov@gmail.com>
src/CMakeLists.txt
src/test/neorados/common_tests.h

index fe161985aede22fa876b61cea92b0af7943d5739..ad965d17d0d0ef688f50d750fdba88ad1eff7359 100644 (file)
@@ -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)
index 5c2ebde4db6aae8976eb93530477d6f066e3b229..0aec479ac6821b4a137e4174860ecd36c982228f 100644 (file)
@@ -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<void> CoTestBody() override;                        \