diff --git a/googlemock/CMakeLists.txt b/googlemock/CMakeLists.txt index 33ec96363..f9a2e64a2 100644 --- a/googlemock/CMakeLists.txt +++ b/googlemock/CMakeLists.txt @@ -10,6 +10,9 @@ option(gmock_build_tests "Build all of Google Mock's own tests." OFF) +set(gmock_default_mock_behavior "1" CACHE STRING + "Controls default mock behavior (0=Nice, 1=Naggy, 2=Strict).") + # A directory to find Google Test sources. if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt") set(gtest_dir gtest) @@ -102,6 +105,9 @@ else() set_target_properties(gmock_main PROPERTIES VERSION ${GOOGLETEST_VERSION}) endif() +target_compile_definitions(gmock PRIVATE + GMOCK_DEFAULT_MOCK_BEHAVIOR=${gmock_default_mock_behavior}) + string(REPLACE ";" "$" dirs "${gmock_build_include_dirs}") target_include_directories(gmock SYSTEM INTERFACE "$" diff --git a/googlemock/include/gmock/gmock-nice-strict.h b/googlemock/include/gmock/gmock-nice-strict.h index 5a3537e2b..433b5615d 100644 --- a/googlemock/include/gmock/gmock-nice-strict.h +++ b/googlemock/include/gmock/gmock-nice-strict.h @@ -38,10 +38,11 @@ // uninteresting calls as errors. // // Currently a mock is naggy by default, so MockFoo and -// NaggyMock behave like the same. However, we will soon -// switch the default behavior of mocks to be nice, as that in general -// leads to more maintainable tests. When that happens, MockFoo will -// stop behaving like NaggyMock and start behaving like +// NaggyMock behave like the same. The default can be +// overridden at build time via the GMOCK_DEFAULT_MOCK_BEHAVIOR +// CMake option, or at runtime via the --gmock_default_mock_behavior +// flag. If the default is set to NiceMock, MockFoo will stop +// behaving like NaggyMock and start behaving like // NiceMock. // // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of diff --git a/googlemock/src/gmock.cc b/googlemock/src/gmock.cc index b5e714da7..b740c61ed 100644 --- a/googlemock/src/gmock.cc +++ b/googlemock/src/gmock.cc @@ -44,7 +44,7 @@ GMOCK_DEFINE_string_(verbose, testing::internal::kWarningVerbosity, " warning - prints warnings and errors.\n" " error - prints errors only."); -GMOCK_DEFINE_int32_(default_mock_behavior, 1, +GMOCK_DEFINE_int32_(default_mock_behavior, GMOCK_DEFAULT_MOCK_BEHAVIOR, "Controls the default behavior of mocks." " Valid values:\n" " 0 - by default, mocks act as NiceMocks.\n"