From abad8af018b232a089ea6397383a2b8fc4422cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Sroczy=C5=84ski?= Date: Tue, 14 Mar 2023 23:48:08 +0100 Subject: [PATCH 01/81] Add COMPONENT to install --- googletest/CMakeLists.txt | 2 ++ googletest/cmake/internal_utils.cmake | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index 95bfa4420..d06c14797 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -100,12 +100,14 @@ if (INSTALL_GTEST) set(version_file "${generated_dir}/${cmake_package_name}ConfigVersion.cmake") write_basic_package_version_file(${version_file} VERSION ${GOOGLETEST_VERSION} COMPATIBILITY AnyNewerVersion) install(EXPORT ${targets_export_name} + COMPONENT "${PROJECT_NAME}" NAMESPACE ${cmake_package_name}:: DESTINATION ${cmake_files_install_dir}) set(config_file "${generated_dir}/${cmake_package_name}Config.cmake") configure_package_config_file("${gtest_SOURCE_DIR}/cmake/Config.cmake.in" "${config_file}" INSTALL_DESTINATION ${cmake_files_install_dir}) install(FILES ${version_file} ${config_file} + COMPONENT "${PROJECT_NAME}" DESTINATION ${cmake_files_install_dir}) endif() diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index b09da33fa..edf637e22 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -327,10 +327,12 @@ endfunction() function(install_project) if(INSTALL_GTEST) install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/" + COMPONENT "${PROJECT_NAME}" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") # Install the project targets. install(TARGETS ${ARGN} EXPORT ${targets_export_name} + COMPONENT "${PROJECT_NAME}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") @@ -342,6 +344,7 @@ function(install_project) get_target_property(t_pdb_output_directory ${t} PDB_OUTPUT_DIRECTORY) install(FILES "${t_pdb_output_directory}/\${CMAKE_INSTALL_CONFIG_NAME}/$<$:${t_pdb_name_debug}>$<$>:${t_pdb_name}>.pdb" + COMPONENT "${PROJECT_NAME}" DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL) endforeach() @@ -352,6 +355,7 @@ function(install_project) configure_file("${PROJECT_SOURCE_DIR}/cmake/${t}.pc.in" "${configured_pc}" @ONLY) install(FILES "${configured_pc}" + COMPONENT "${PROJECT_NAME}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") endforeach() endif() From ded275d75e0756e9659226f94bd4b8399af721d7 Mon Sep 17 00:00:00 2001 From: Pro3757 Date: Tue, 30 May 2023 13:50:23 +0530 Subject: [PATCH 02/81] fix README table --- README.md | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 10d1f86f1..c53a5ecee 100644 --- a/README.md +++ b/README.md @@ -55,37 +55,37 @@ More information about building GoogleTest can be found at | Feature | Description | | ---------------------------- | --------------------------------------------- | | xUnit test framework | Googletest is based on the | -: : [xUnit](https\://en.wikipedia.org/wiki/XUnit) : -: : testing framework, a popular architecture for : -: : unit testing : +| | [xUnit](https\://en.wikipedia.org/wiki/XUnit) | +| | testing framework, a popular architecture for | +| | unit testing | | Test discovery | Googletest automatically discovers and runs | -: : your tests, eliminating the need to manually : -: : register your tests : +| | your tests, eliminating the need to manually | +| | register your tests | | Rich set of assertions | Googletest provides a variety of assertions, | -: : such as equality, inequality, exceptions, and : -: : more, making it easy to test your code : +| | such as equality, inequality, exceptions, and | +| | more, making it easy to test your code | | User-defined assertions | You can define your own assertions with | -: : Googletest, making it simple to write tests : -: : that are specific to your code : +| | Googletest, making it simple to write tests | +| | that are specific to your code | | Death tests | Googletest supports death tests, which verify | -: : that your code exits in a certain way, making : -: : it useful for testing error-handling code : +| | that your code exits in a certain way, making | +| | it useful for testing error-handling code | | Fatal and non-fatal failures | You can specify whether a test failure should | -: : be treated as fatal or non-fatal with : -: : Googletest, allowing tests to continue : -: : running even if a failure occurs : +| | be treated as fatal or non-fatal with | +| | Googletest, allowing tests to continue | +| | running even if a failure occurs | | Value-parameterized tests | Googletest supports value-parameterized | -: : tests, which run multiple times with : -: : different input values, making it useful for : -: : testing functions that take different inputs : +| | tests, which run multiple times with | +| | different input values, making it useful for | +| | testing functions that take different inputs | | Type-parameterized tests | Googletest also supports type-parameterized | -: : tests, which run with different data types, : -: : making it useful for testing functions that : -: : work with different data types : +| | tests, which run with different data types, | +| | making it useful for testing functions that | +| | work with different data types | | Various options for running | Googletest provides many options for running | -: tests : tests, including running individual tests, : -: : running tests in a specific order, and : -: : running tests in parallel : +| tests | tests, including running individual tests, | +| | running tests in a specific order, and | +| | running tests in parallel | ## Supported Platforms From 06f44bc951046150f1348598854b211afdcf37fc Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Thu, 1 Jun 2023 07:28:00 -0700 Subject: [PATCH 03/81] Copy supported platforms from README onto https://google.github.io/googletest/platforms.html PiperOrigin-RevId: 537016664 Change-Id: Ie62891a1061465a009b90feba0ccb91d85591160 --- docs/platforms.md | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/docs/platforms.md b/docs/platforms.md index eba6ef805..d35a7be05 100644 --- a/docs/platforms.md +++ b/docs/platforms.md @@ -1,35 +1,8 @@ # Supported Platforms -GoogleTest requires a codebase and compiler compliant with the C++11 standard or -newer. - -The GoogleTest code is officially supported on the following platforms. -Operating systems or tools not listed below are community-supported. For -community-supported platforms, patches that do not complicate the code may be -considered. - -If you notice any problems on your platform, please file an issue on the -[GoogleTest GitHub Issue Tracker](https://github.com/google/googletest/issues). -Pull requests containing fixes are welcome! - -### Operating systems - -* Linux -* macOS -* Windows - -### Compilers - -* gcc 5.0+ -* clang 5.0+ -* MSVC 2015+ - -**macOS users:** Xcode 9.3+ provides clang 5.0+. - -### Build systems - -* [Bazel](https://bazel.build/) -* [CMake](https://cmake.org/) - -Bazel is the build system used by the team internally and in tests. CMake is -supported on a best-effort basis and by the community. +GoogleTest follows Google's +[Foundational C++ Support Policy](https://opensource.google/documentation/policies/cplusplus-support). +See +[this table](https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md) +for a list of currently supported versions compilers, platforms, and build +tools. From a5b94f6819d2c296958ae1f6b9130df99a37ec6d Mon Sep 17 00:00:00 2001 From: Niranjan Nilakantan Date: Thu, 1 Jun 2023 09:48:54 -0700 Subject: [PATCH 04/81] Ignore the .cache directory create by VSCode. This is populated by the clangd language service provider. Also ignore the cmake-variants.yaml file. This can be created locally to select various build/test configurations. Fixes #4266 --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index f08cb72a3..fede02f65 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,10 @@ Win32-Release/ x64-Debug/ x64-Release/ +# VSCode files +.cache/ +cmake-variants.yaml + # Ignore autoconf / automake files Makefile.in aclocal.m4 From 5ca3ab833168674ff417845941fc46691769ed36 Mon Sep 17 00:00:00 2001 From: Pro3757 Date: Fri, 2 Jun 2023 00:58:00 +0530 Subject: [PATCH 05/81] change table to unordered list --- README.md | 66 +++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index c53a5ecee..927222713 100644 --- a/README.md +++ b/README.md @@ -52,40 +52,38 @@ documentation. We recommend starting with the More information about building GoogleTest can be found at [googletest/README.md](googletest/README.md). -| Feature | Description | -| ---------------------------- | --------------------------------------------- | -| xUnit test framework | Googletest is based on the | -| | [xUnit](https\://en.wikipedia.org/wiki/XUnit) | -| | testing framework, a popular architecture for | -| | unit testing | -| Test discovery | Googletest automatically discovers and runs | -| | your tests, eliminating the need to manually | -| | register your tests | -| Rich set of assertions | Googletest provides a variety of assertions, | -| | such as equality, inequality, exceptions, and | -| | more, making it easy to test your code | -| User-defined assertions | You can define your own assertions with | -| | Googletest, making it simple to write tests | -| | that are specific to your code | -| Death tests | Googletest supports death tests, which verify | -| | that your code exits in a certain way, making | -| | it useful for testing error-handling code | -| Fatal and non-fatal failures | You can specify whether a test failure should | -| | be treated as fatal or non-fatal with | -| | Googletest, allowing tests to continue | -| | running even if a failure occurs | -| Value-parameterized tests | Googletest supports value-parameterized | -| | tests, which run multiple times with | -| | different input values, making it useful for | -| | testing functions that take different inputs | -| Type-parameterized tests | Googletest also supports type-parameterized | -| | tests, which run with different data types, | -| | making it useful for testing functions that | -| | work with different data types | -| Various options for running | Googletest provides many options for running | -| tests | tests, including running individual tests, | -| | running tests in a specific order, and | -| | running tests in parallel | +## Features +* xUnit test framework: + Googletest is based on the [xUnit](https\://en.wikipedia.org/wiki/XUnit) + testing framework, a popular architecture for unit testing +* Test discovery: + Googletest automatically discovers and runs your tests, eliminating the need + to manually register your tests +* Rich set of assertions: + Googletest provides a variety of assertions, such as equality, inequality, + exceptions, and more, making it easy to test your code +* User-defined assertions: + You can define your own assertions with Googletest, making it simple to + write tests that are specific to your code +* Death tests: + Googletest supports death tests, which verify that your code exits in a + certain way, making it useful for testing error-handling code +* Fatal and non-fatal failures: + You can specify whether a test failure should be treated as fatal or + non-fatal with Googletest, allowing tests to continue running even if a + failure occurs +* Value-parameterized tests: + Googletest supports value-parameterized tests, which run multiple times with + different input values, making it useful for testing functions that take + different inputs +* Type-parameterized tests: + Googletest also supports type-parameterized tests, which run with different + data types, making it useful for testing functions that work with different + data types +* Various options for running tests: + Googletest provides many options for running tests including running + individual tests, running tests in a specific order, and running tests in + parallel ## Supported Platforms From 001f281926c74a819e9266bb4ec525515ff39418 Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Fri, 2 Jun 2023 12:17:43 +0200 Subject: [PATCH 06/81] Check for file system for current directory Check for current directory instead of death test to get original directory. A port may support filesystems but not death tests. --- googletest/src/gtest-internal-inl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index 5ba557fe1..be821662c 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -672,7 +672,7 @@ class GTEST_API_ UnitTestImpl { void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc, internal::TearDownTestSuiteFunc tear_down_tc, TestInfo* test_info) { -#ifdef GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_FILE_SYSTEM // In order to support thread-safe death tests, we need to // remember the original working directory when the test program // was first invoked. We cannot do this in RUN_ALL_TESTS(), as @@ -685,7 +685,7 @@ class GTEST_API_ UnitTestImpl { GTEST_CHECK_(!original_working_dir_.IsEmpty()) << "Failed to get the current working directory."; } -#endif // GTEST_HAS_DEATH_TEST +#endif // GTEST_HAS_FILE_SYSTEM GetTestSuite(test_info->test_suite_name(), test_info->type_param(), set_up_tc, tear_down_tc) From 65cfeca1a1eebca291b59395f79a60a4497d0f73 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 9 Jun 2023 11:28:44 -0700 Subject: [PATCH 07/81] internal g3doc documentation change. PiperOrigin-RevId: 539134110 Change-Id: I28041f77e18bc67aa0ffabdc7205e350deed22c8 --- docs/primer.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/primer.md b/docs/primer.md index 31d63160e..c3aee3cc6 100644 --- a/docs/primer.md +++ b/docs/primer.md @@ -42,7 +42,7 @@ Since GoogleTest is based on the popular xUnit architecture, you'll feel right at home if you've used JUnit or PyUnit before. If not, it will take you about 10 minutes to learn the basics and get started. So let's go! -## Beware of the nomenclature +## Beware of the Nomenclature {: .callout .note} *Note:* There might be some confusion arising from different definitions of the From 4c7aee827e16aa338189b88f6e3aa6d3d927dba4 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Wed, 14 Jun 2023 06:40:34 -0700 Subject: [PATCH 08/81] Skip entire test suite with `GTEST_SKIP()` in `SetUpTestSuite` Fixes #4273 PiperOrigin-RevId: 540254167 Change-Id: I2555740d10284223539035bf73f88554fcf73f8a --- googletest/src/gtest.cc | 3 ++- .../test/googletest-output-test-golden-lin.txt | 16 +++++++++++++--- googletest/test/googletest-output-test_.cc | 6 ++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index fb7512c1b..a88ac2557 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -3019,7 +3019,8 @@ void TestSuite::Run() { internal::HandleExceptionsInMethodIfSupported( this, &TestSuite::RunSetUpTestSuite, "SetUpTestSuite()"); - const bool skip_all = ad_hoc_test_result().Failed(); + const bool skip_all = + ad_hoc_test_result().Failed() || ad_hoc_test_result().Skipped(); start_timestamp_ = internal::GetTimeInMillis(); internal::Timer timer; diff --git a/googletest/test/googletest-output-test-golden-lin.txt b/googletest/test/googletest-output-test-golden-lin.txt index 1f24fb791..6ddf822ff 100644 --- a/googletest/test/googletest-output-test-golden-lin.txt +++ b/googletest/test/googletest-output-test-golden-lin.txt @@ -12,7 +12,7 @@ Expected equality of these values: 3 Stack trace: (omitted) -[==========] Running 89 tests from 42 test suites. +[==========] Running 90 tests from 43 test suites. [----------] Global test environment set-up. FooEnvironment::SetUp() called. BarEnvironment::SetUp() called. @@ -967,6 +967,15 @@ Stack trace: (omitted) googletest-output-test_.cc:#: Skipped [ SKIPPED ] TestSuiteThatFailsToSetUp.ShouldNotRun +[----------] 1 test from TestSuiteThatSkipsInSetUp +googletest-output-test_.cc:#: Skipped +Skip entire test suite +Stack trace: (omitted) + +[ RUN ] TestSuiteThatSkipsInSetUp.ShouldNotRun +googletest-output-test_.cc:#: Skipped + +[ SKIPPED ] TestSuiteThatSkipsInSetUp.ShouldNotRun [----------] 1 test from PrintingFailingParams/FailingParamTest [ RUN ] PrintingFailingParams/FailingParamTest.Fails/0 googletest-output-test_.cc:#: Failure @@ -1043,10 +1052,11 @@ Failed Expected fatal failure. Stack trace: (omitted) -[==========] 89 tests from 42 test suites ran. +[==========] 90 tests from 43 test suites ran. [ PASSED ] 31 tests. -[ SKIPPED ] 1 test, listed below: +[ SKIPPED ] 2 tests, listed below: [ SKIPPED ] TestSuiteThatFailsToSetUp.ShouldNotRun +[ SKIPPED ] TestSuiteThatSkipsInSetUp.ShouldNotRun [ FAILED ] 57 tests, listed below: [ FAILED ] NonfatalFailureTest.EscapesStringOperands [ FAILED ] NonfatalFailureTest.DiffForLongStrings diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc index f1facf570..e3560c018 100644 --- a/googletest/test/googletest-output-test_.cc +++ b/googletest/test/googletest-output-test_.cc @@ -1007,6 +1007,12 @@ class TestSuiteThatFailsToSetUp : public testing::Test { }; TEST_F(TestSuiteThatFailsToSetUp, ShouldNotRun) { std::abort(); } +class TestSuiteThatSkipsInSetUp : public testing::Test { + public: + static void SetUpTestSuite() { GTEST_SKIP() << "Skip entire test suite"; } +}; +TEST_F(TestSuiteThatSkipsInSetUp, ShouldNotRun) { std::abort(); } + // The main function. // // The idea is to use Google Test to run all the tests we have defined (some From 18fa6a4db32a30675c0b19bf72f8b5f693d21a23 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 15 Jun 2023 07:52:03 -0700 Subject: [PATCH 09/81] Allow clients to un-suppress output from gUnit EXPECT_EXIT tests. This is useful for running individual tests in a separate process, which is useful for testing e.g. flag changes which have a process-global effect. PiperOrigin-RevId: 540580573 Change-Id: I18a5d24d79425a9d595be3369efc44e2f655f6f8 --- googletest/include/gtest/gtest.h | 5 ++++- googletest/src/gtest-death-test.cc | 2 +- googletest/src/gtest.cc | 6 +++--- googletest/test/gtest_unittest.cc | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 841250349..86777c854 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -1055,6 +1055,10 @@ class GTEST_API_ TestEventListeners { return default_xml_generator_; } + // Controls whether events will be forwarded by the repeater to the + // listeners in the list. + void SuppressEventForwarding(bool); + private: friend class TestSuite; friend class TestInfo; @@ -1084,7 +1088,6 @@ class GTEST_API_ TestEventListeners { // Controls whether events will be forwarded by the repeater to the // listeners in the list. bool EventForwardingEnabled() const; - void SuppressEventForwarding(); // The actual list of listeners. internal::TestEventRepeater* repeater_; diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index 4cf78e71a..0eb6e38b2 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -1128,7 +1128,7 @@ DeathTest::TestRole NoExecDeathTest::AssumeRole() { LogToStderr(); // Event forwarding to the listeners of event listener API mush be shut // down in death test subprocesses. - GetUnitTestImpl()->listeners()->SuppressEventForwarding(); + GetUnitTestImpl()->listeners()->SuppressEventForwarding(true); g_in_fast_death_test_child = true; return EXECUTE_TEST; } else { diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index a88ac2557..d9fd27709 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -5156,8 +5156,8 @@ bool TestEventListeners::EventForwardingEnabled() const { return repeater_->forwarding_enabled(); } -void TestEventListeners::SuppressEventForwarding() { - repeater_->set_forwarding_enabled(false); +void TestEventListeners::SuppressEventForwarding(bool suppress) { + repeater_->set_forwarding_enabled(!suppress); } // class UnitTest @@ -5635,7 +5635,7 @@ void UnitTestImpl::RecordProperty(const TestProperty& test_property) { // subprocess. Must not be called before InitGoogleTest. void UnitTestImpl::SuppressTestEventsIfInSubprocess() { if (internal_run_death_test_flag_ != nullptr) - listeners()->SuppressEventForwarding(); + listeners()->SuppressEventForwarding(true); } #endif // GTEST_HAS_DEATH_TEST diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 77d968a72..dd049a00d 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -173,7 +173,7 @@ class TestEventListenersAccessor { } static void SuppressEventForwarding(TestEventListeners* listeners) { - listeners->SuppressEventForwarding(); + listeners->SuppressEventForwarding(true); } }; From 148b327ffa6f7f97cffd1606342a136cf497210b Mon Sep 17 00:00:00 2001 From: Kasra Hashemi <73937934+zencatalyst@users.noreply.github.com> Date: Fri, 16 Jun 2023 13:59:16 +0330 Subject: [PATCH 10/81] Update README.md Fixed punctuation issues --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ef0c288d5..443e02069 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ The 1.13.x branch requires at least C++14. #### Continuous Integration We use Google's internal systems for continuous integration. \ -GitHub Actions were added for the convenience of open source contributors. They -are exclusively maintained by the open source community and not used by the +GitHub Actions were added for the convenience of open-source contributors. They +are exclusively maintained by the open-source community and not used by the GoogleTest team. #### Coming Soon @@ -83,7 +83,7 @@ More information about building GoogleTest can be found at data types * Various options for running tests: \ Googletest provides many options for running tests including running - individual tests, running tests in a specific order, and running tests in + individual tests, running tests in a specific order and running tests in parallel ## Supported Platforms @@ -92,7 +92,7 @@ GoogleTest follows Google's [Foundational C++ Support Policy](https://opensource.google/documentation/policies/cplusplus-support). See [this table](https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md) -for a list of currently supported versions compilers, platforms, and build +for a list of currently supported versions of compilers, platforms, and build tools. ## Who Is Using GoogleTest? From 124bc587f0f6157f0bf49a05deb68956db307732 Mon Sep 17 00:00:00 2001 From: Ryan Schmidt Date: Mon, 19 Jun 2023 06:18:12 -0500 Subject: [PATCH 11/81] Change C++11 requirement to C++14 Version 1.13.x and later require C++14. Also fix missing closing backtick. --- googletest/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/googletest/README.md b/googletest/README.md index 4cad12f75..6bbd7f875 100644 --- a/googletest/README.md +++ b/googletest/README.md @@ -124,10 +124,10 @@ match the project in which it is included. #### C++ Standard Version -An environment that supports C++11 is required in order to successfully build +An environment that supports C++14 is required in order to successfully build GoogleTest. One way to ensure this is to specify the standard in the top-level -project, for example by using the `set(CMAKE_CXX_STANDARD 11)` command along -with `set(CMAKE_CXX_STANDARD_REQUIRED ON). If this is not feasible, for example +project, for example by using the `set(CMAKE_CXX_STANDARD 14)` command along +with `set(CMAKE_CXX_STANDARD_REQUIRED ON)`. If this is not feasible, for example in a C project using GoogleTest for validation, then it can be specified by adding it to the options for cmake via the`-DCMAKE_CXX_FLAGS` option. From 4fed5f285030085b096c930ff03e42c7814739b2 Mon Sep 17 00:00:00 2001 From: Juan Ramos Date: Mon, 19 Jun 2023 11:21:44 -0600 Subject: [PATCH 12/81] cmake: Raise min to 3.6 From the CMake 3.27 release notes: Compatibility with versions of CMake older than 3.5 is now deprecated and will be removed from a future version. Calls to cmake_minimum_required() or cmake_policy() that set the policy version to an older value now issue a deprecation diagnostic. This PR also removes manually setting policy CMP0048. This is redundant since the CMake min is already 3.X --- CMakeLists.txt | 6 +----- docs/pkgconfig.md | 14 +++++--------- googlemock/CMakeLists.txt | 3 +-- googletest/CMakeLists.txt | 3 +-- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6af414371..33a6c6ff4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,7 @@ # Note: CMake support is community-based. The maintainers do not use CMake # internally. -cmake_minimum_required(VERSION 3.5) - -if (POLICY CMP0048) - cmake_policy(SET CMP0048 NEW) -endif (POLICY CMP0048) +cmake_minimum_required(VERSION 3.6) if (POLICY CMP0069) cmake_policy(SET CMP0069 NEW) diff --git a/docs/pkgconfig.md b/docs/pkgconfig.md index 18a2546a3..bf05d5931 100644 --- a/docs/pkgconfig.md +++ b/docs/pkgconfig.md @@ -19,19 +19,15 @@ examples here we assume you want to compile the sample Using `pkg-config` in CMake is fairly easy: ```cmake -cmake_minimum_required(VERSION 3.0) - -cmake_policy(SET CMP0048 NEW) -project(my_gtest_pkgconfig VERSION 0.0.1 LANGUAGES CXX) - find_package(PkgConfig) pkg_search_module(GTEST REQUIRED gtest_main) -add_executable(testapp samples/sample3_unittest.cc) -target_link_libraries(testapp ${GTEST_LDFLAGS}) -target_compile_options(testapp PUBLIC ${GTEST_CFLAGS}) +add_executable(testapp) +target_sources(testapp PRIVATE samples/sample3_unittest.cc) +target_link_libraries(testapp PRIVATE ${GTEST_LDFLAGS}) +target_compile_options(testapp PRIVATE ${GTEST_CFLAGS}) -include(CTest) +enable_testing() add_test(first_and_only_test testapp) ``` diff --git a/googlemock/CMakeLists.txt b/googlemock/CMakeLists.txt index 5c1f0dafe..444c5ae80 100644 --- a/googlemock/CMakeLists.txt +++ b/googlemock/CMakeLists.txt @@ -36,8 +36,7 @@ endif() # as ${gmock_SOURCE_DIR} and to the root binary directory as # ${gmock_BINARY_DIR}. # Language "C" is required for find_package(Threads). -cmake_minimum_required(VERSION 3.5) -cmake_policy(SET CMP0048 NEW) +cmake_minimum_required(VERSION 3.6) project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) if (COMMAND set_up_hermetic_build) diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index d06c14797..efc2c3cbe 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -46,8 +46,7 @@ endif() # Project version: -cmake_minimum_required(VERSION 3.5) -cmake_policy(SET CMP0048 NEW) +cmake_minimum_required(VERSION 3.6) project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) if (POLICY CMP0063) # Visibility From efd8db1627631079dec02de2622071d8ec9ff5fa Mon Sep 17 00:00:00 2001 From: Juan Ramos Date: Tue, 20 Jun 2023 13:03:00 -0600 Subject: [PATCH 13/81] cmake: Clean up policy code Now that the min is 3.13 these policies don't need to be set manually anymore. CMP0054 - 3.1 CMP0063 - 3.3 CMP0069 - 3.9 CMP0077 - 3.13 --- CMakeLists.txt | 8 -------- googletest/CMakeLists.txt | 4 ---- googletest/cmake/internal_utils.cmake | 14 -------------- 3 files changed, 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 890e495ef..3b5cf3c48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,14 +3,6 @@ cmake_minimum_required(VERSION 3.13) -if (POLICY CMP0069) - cmake_policy(SET CMP0069 NEW) -endif (POLICY CMP0069) - -if (POLICY CMP0077) - cmake_policy(SET CMP0077 NEW) -endif (POLICY CMP0077) - project(googletest-distribution) set(GOOGLETEST_VERSION 1.13.0) diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index e76b8c8a5..a944dddbe 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -49,10 +49,6 @@ endif() cmake_minimum_required(VERSION 3.13) project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) -if (POLICY CMP0063) # Visibility - cmake_policy(SET CMP0063 NEW) -endif (POLICY CMP0063) - if (COMMAND set_up_hermetic_build) set_up_hermetic_build() endif() diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 6573d3003..481091135 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -12,14 +12,6 @@ # Test and Google Mock's option() definitions, and thus must be # called *after* the options have been defined. -if (POLICY CMP0054) - cmake_policy(SET CMP0054 NEW) -endif (POLICY CMP0054) - -if (POLICY CMP0069) - cmake_policy(SET CMP0069 NEW) -endif (POLICY CMP0069) - # Tweaks CMake's default compiler/linker settings to suit Google Test's needs. # # This must be a macro(), as inside a function string() can only @@ -264,12 +256,6 @@ function(cxx_executable name dir libs) ${name} "${cxx_default}" "${libs}" "${dir}/${name}.cc" ${ARGN}) endfunction() -# CMP0094 policy enables finding a Python executable in the LOCATION order, as -# specified by the PATH environment variable. -if (POLICY CMP0094) - cmake_policy(SET CMP0094 NEW) -endif() - # Sets PYTHONINTERP_FOUND and PYTHON_EXECUTABLE. if ("${CMAKE_VERSION}" VERSION_LESS "3.12.0") find_package(PythonInterp) From 812f35b26b88ab1607a806b87539175591bba8c2 Mon Sep 17 00:00:00 2001 From: Juan Ramos Date: Tue, 20 Jun 2023 19:02:23 -0600 Subject: [PATCH 14/81] cmake: Remove remaining checks for CMAKE_VERSION Remove conditional code that doesn't need to exist anymore. --- googlemock/CMakeLists.txt | 26 ++++------ googletest/CMakeLists.txt | 19 +++----- googletest/cmake/internal_utils.cmake | 68 ++++++++------------------- 3 files changed, 35 insertions(+), 78 deletions(-) diff --git a/googlemock/CMakeLists.txt b/googlemock/CMakeLists.txt index 5833d20c1..a9aa0723f 100644 --- a/googlemock/CMakeLists.txt +++ b/googlemock/CMakeLists.txt @@ -100,18 +100,14 @@ else() target_link_libraries(gmock_main PUBLIC gmock) set_target_properties(gmock_main PROPERTIES VERSION ${GOOGLETEST_VERSION}) endif() -# If the CMake version supports it, attach header directory information -# to the targets for when we are part of a parent build (ie being pulled -# in via add_subdirectory() rather than being a standalone build). -if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") - string(REPLACE ";" "$" dirs "${gmock_build_include_dirs}") - target_include_directories(gmock SYSTEM INTERFACE - "$" - "$/${CMAKE_INSTALL_INCLUDEDIR}>") - target_include_directories(gmock_main SYSTEM INTERFACE - "$" - "$/${CMAKE_INSTALL_INCLUDEDIR}>") -endif() + +string(REPLACE ";" "$" dirs "${gmock_build_include_dirs}") +target_include_directories(gmock SYSTEM INTERFACE + "$" + "$/${CMAKE_INSTALL_INCLUDEDIR}>") +target_include_directories(gmock_main SYSTEM INTERFACE + "$" + "$/${CMAKE_INSTALL_INCLUDEDIR}>") ######################################################################## # @@ -135,11 +131,7 @@ if (gmock_build_tests) enable_testing() if (MINGW OR CYGWIN) - if (CMAKE_VERSION VERSION_LESS "2.8.12") - add_compile_options("-Wa,-mbig-obj") - else() - add_definitions("-Wa,-mbig-obj") - endif() + add_compile_options("-Wa,-mbig-obj") endif() ############################################################ diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index a944dddbe..caafa8c76 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -140,18 +140,13 @@ if(GTEST_HAS_ABSL) endif() cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc) set_target_properties(gtest_main PROPERTIES VERSION ${GOOGLETEST_VERSION}) -# If the CMake version supports it, attach header directory information -# to the targets for when we are part of a parent build (ie being pulled -# in via add_subdirectory() rather than being a standalone build). -if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") - string(REPLACE ";" "$" dirs "${gtest_build_include_dirs}") - target_include_directories(gtest SYSTEM INTERFACE - "$" - "$/${CMAKE_INSTALL_INCLUDEDIR}>") - target_include_directories(gtest_main SYSTEM INTERFACE - "$" - "$/${CMAKE_INSTALL_INCLUDEDIR}>") -endif() +string(REPLACE ";" "$" dirs "${gtest_build_include_dirs}") +target_include_directories(gtest SYSTEM INTERFACE + "$" + "$/${CMAKE_INSTALL_INCLUDEDIR}>") +target_include_directories(gtest_main SYSTEM INTERFACE + "$" + "$/${CMAKE_INSTALL_INCLUDEDIR}>") if(CMAKE_SYSTEM_NAME MATCHES "QNX") target_link_libraries(gtest PUBLIC regex) endif() diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 481091135..e57207791 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -188,23 +188,14 @@ function(cxx_library_with_type name type cxx_flags) set_target_properties(${name} PROPERTIES COMPILE_DEFINITIONS "GTEST_CREATE_SHARED_LIBRARY=1") - if (NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") target_compile_definitions(${name} INTERFACE $) - endif() endif() if (DEFINED GTEST_HAS_PTHREAD) - if ("${CMAKE_VERSION}" VERSION_LESS "3.1.0") - set(threads_spec ${CMAKE_THREAD_LIBS_INIT}) - else() - set(threads_spec Threads::Threads) - endif() - target_link_libraries(${name} PUBLIC ${threads_spec}) + target_link_libraries(${name} PUBLIC Threads::Threads) endif() - if (NOT "${CMAKE_VERSION}" VERSION_LESS "3.8") - target_compile_features(${name} PUBLIC cxx_std_14) - endif() + target_compile_features(${name} PUBLIC cxx_std_14) endfunction() ######################################################################## @@ -256,16 +247,7 @@ function(cxx_executable name dir libs) ${name} "${cxx_default}" "${libs}" "${dir}/${name}.cc" ${ARGN}) endfunction() -# Sets PYTHONINTERP_FOUND and PYTHON_EXECUTABLE. -if ("${CMAKE_VERSION}" VERSION_LESS "3.12.0") - find_package(PythonInterp) - set(PYTHONINTERP_FOUND ${PYTHONINTERP_FOUND} CACHE INTERNAL "") - set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE INTERNAL "") -else() - find_package(Python COMPONENTS Interpreter) - set(PYTHONINTERP_FOUND ${Python_Interpreter_FOUND} CACHE INTERNAL "") - set(PYTHON_EXECUTABLE ${Python_EXECUTABLE} CACHE INTERNAL "") -endif() +find_package(Python3) # cxx_test_with_flags(name cxx_flags libs srcs...) # @@ -291,34 +273,22 @@ endfunction() # creates a Python test with the given name whose main module is in # test/name.py. It does nothing if Python is not installed. function(py_test name) - if (PYTHONINTERP_FOUND) - if ("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 3.1) - if (CMAKE_CONFIGURATION_TYPES) - # Multi-configuration build generators as for Visual Studio save - # output in a subdirectory of CMAKE_CURRENT_BINARY_DIR (Debug, - # Release etc.), so we have to provide it here. - add_test(NAME ${name} - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py - --build_dir=${CMAKE_CURRENT_BINARY_DIR}/$ ${ARGN}) - else (CMAKE_CONFIGURATION_TYPES) - # Single-configuration build generators like Makefile generators - # don't have subdirs below CMAKE_CURRENT_BINARY_DIR. - add_test(NAME ${name} - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py - --build_dir=${CMAKE_CURRENT_BINARY_DIR} ${ARGN}) - endif (CMAKE_CONFIGURATION_TYPES) - else() - # ${CMAKE_CURRENT_BINARY_DIR} is known at configuration time, so we can - # directly bind it from cmake. ${CTEST_CONFIGURATION_TYPE} is known - # only at ctest runtime (by calling ctest -c ), so - # we have to escape $ to delay variable substitution here. - add_test(NAME ${name} - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py - --build_dir=${CMAKE_CURRENT_BINARY_DIR}/\${CTEST_CONFIGURATION_TYPE} ${ARGN}) - endif() - # Make the Python import path consistent between Bazel and CMake. - set_tests_properties(${name} PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_SOURCE_DIR}) - endif(PYTHONINTERP_FOUND) + if (NOT Python3_Interpreter_FOUND) + return() + endif() + + get_cmake_property(is_multi "GENERATOR_IS_MULTI_CONFIG") + set(build_dir "${CMAKE_CURRENT_BINARY_DIR}") + if (is_multi) + set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/$") + endif() + + add_test(NAME ${name} + COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py + --build_dir=${build_dir} ${ARGN}) + + # Make the Python import path consistent between Bazel and CMake. + set_tests_properties(${name} PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_SOURCE_DIR}) endfunction() # install_project(targets...) From ec4fed93217bc2830959bb8e86798c1d86956949 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 22 Jun 2023 08:14:44 -0700 Subject: [PATCH 15/81] Update code examples in the gMock Cookbook following C++ best practices. PiperOrigin-RevId: 542564354 Change-Id: Ia3307f13f845c662c88fb7303112f41ef8c56b28 --- docs/gmock_cook_book.md | 46 +++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/docs/gmock_cook_book.md b/docs/gmock_cook_book.md index d57be58dd..f736b9fb8 100644 --- a/docs/gmock_cook_book.md +++ b/docs/gmock_cook_book.md @@ -697,9 +697,9 @@ TEST(AbcTest, Xyz) { EXPECT_CALL(foo, DoThat(_, _)); int n = 0; - EXPECT_EQ('+', foo.DoThis(5)); // FakeFoo::DoThis() is invoked. + EXPECT_EQ(foo.DoThis(5), '+'); // FakeFoo::DoThis() is invoked. foo.DoThat("Hi", &n); // FakeFoo::DoThat() is invoked. - EXPECT_EQ(2, n); + EXPECT_EQ(n, 2); } ``` @@ -1129,11 +1129,11 @@ using STL's `` header is just painful). For example, here's a predicate that's satisfied by any number that is >= 0, <= 100, and != 50: ```cpp -using testing::AllOf; -using testing::Ge; -using testing::Le; -using testing::Matches; -using testing::Ne; +using ::testing::AllOf; +using ::testing::Ge; +using ::testing::Le; +using ::testing::Matches; +using ::testing::Ne; ... Matches(AllOf(Ge(0), Le(100), Ne(50))) ``` @@ -1861,7 +1861,7 @@ error. So, what shall you do? Though you may be tempted, DO NOT use `std::ref()`: ```cpp -using testing::Return; +using ::testing::Return; class MockFoo : public Foo { public: @@ -1873,7 +1873,7 @@ class MockFoo : public Foo { EXPECT_CALL(foo, GetValue()) .WillRepeatedly(Return(std::ref(x))); // Wrong! x = 42; - EXPECT_EQ(42, foo.GetValue()); + EXPECT_EQ(foo.GetValue(), 42); ``` Unfortunately, it doesn't work here. The above code will fail with error: @@ -1895,14 +1895,14 @@ the expectation is set, and `Return(std::ref(x))` will always return 0. returns the value pointed to by `pointer` at the time the action is *executed*: ```cpp -using testing::ReturnPointee; +using ::testing::ReturnPointee; ... int x = 0; MockFoo foo; EXPECT_CALL(foo, GetValue()) .WillRepeatedly(ReturnPointee(&x)); // Note the & here. x = 42; - EXPECT_EQ(42, foo.GetValue()); // This will succeed now. + EXPECT_EQ(foo.GetValue(), 42); // This will succeed now. ``` ### Combining Actions @@ -2264,7 +2264,7 @@ TEST_F(FooTest, Test) { EXPECT_CALL(foo, DoThis(2)) .WillOnce(Invoke(NewPermanentCallback(SignOfSum, 5))); - EXPECT_EQ('+', foo.DoThis(2)); // Invokes SignOfSum(5, 2). + EXPECT_EQ(foo.DoThis(2), '+'); // Invokes SignOfSum(5, 2). } ``` @@ -2771,11 +2771,13 @@ returns a null `unique_ptr`, that’s what you’ll get if you don’t specify a action: ```cpp +using ::testing::IsNull; +... // Use the default action. EXPECT_CALL(mock_buzzer_, MakeBuzz("hello")); // Triggers the previous EXPECT_CALL. - EXPECT_EQ(nullptr, mock_buzzer_.MakeBuzz("hello")); + EXPECT_THAT(mock_buzzer_.MakeBuzz("hello"), IsNull()); ``` If you are not happy with the default action, you can tweak it as usual; see @@ -3194,9 +3196,9 @@ flag. For example, given the test program: ```cpp #include "gmock/gmock.h" -using testing::_; -using testing::HasSubstr; -using testing::Return; +using ::testing::_; +using ::testing::HasSubstr; +using ::testing::Return; class MockFoo { public: @@ -3817,15 +3819,15 @@ If the built-in actions don't work for you, you can easily define your own one. All you need is a call operator with a signature compatible with the mocked function. So you can use a lambda: -``` +```cpp MockFunction mock; EXPECT_CALL(mock, Call).WillOnce([](const int input) { return input * 7; }); -EXPECT_EQ(14, mock.AsStdFunction()(2)); +EXPECT_EQ(mock.AsStdFunction()(2), 14); ``` Or a struct with a call operator (even a templated one): -``` +```cpp struct MultiplyBy { template T operator()(T arg) { return arg * multiplier; } @@ -3840,16 +3842,16 @@ struct MultiplyBy { It's also fine for the callable to take no arguments, ignoring the arguments supplied to the mock function: -``` +```cpp MockFunction mock; EXPECT_CALL(mock, Call).WillOnce([] { return 17; }); -EXPECT_EQ(17, mock.AsStdFunction()(0)); +EXPECT_EQ(mock.AsStdFunction()(0), 17); ``` When used with `WillOnce`, the callable can assume it will be called at most once and is allowed to be a move-only type: -``` +```cpp // An action that contains move-only types and has an &&-qualified operator, // demanding in the type system that it be called at most once. This can be // used with WillOnce, but the compiler will reject it if handed to From 1361c77c4d0027f52a7a8e205b79d572909b5587 Mon Sep 17 00:00:00 2001 From: Ikko Eltociear Ashimine Date: Fri, 23 Jun 2023 01:20:10 +0900 Subject: [PATCH 16/81] Fix typo in googletest-catch-exceptions-test.py FITLER_OUT_SEH_TESTS_FLAG -> FILTER_OUT_SEH_TESTS_FLAG --- googletest/test/googletest-catch-exceptions-test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/test/googletest-catch-exceptions-test.py b/googletest/test/googletest-catch-exceptions-test.py index ee4dc9ae6..428b5b77f 100755 --- a/googletest/test/googletest-catch-exceptions-test.py +++ b/googletest/test/googletest-catch-exceptions-test.py @@ -297,10 +297,10 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase): def testUnhandledCxxExceptionsAbortTheProgram(self): # Filters out SEH exception tests on Windows. Unhandled SEH exceptions # cause tests to show pop-up windows there. - FITLER_OUT_SEH_TESTS_FLAG = FILTER_FLAG + '=-*Seh*' + FILTER_OUT_SEH_TESTS_FLAG = FILTER_FLAG + '=-*Seh*' # By default, Google Test doesn't catch the exceptions. uncaught_exceptions_ex_binary_output = gtest_test_utils.Subprocess( - [EX_EXE_PATH, NO_CATCH_EXCEPTIONS_FLAG, FITLER_OUT_SEH_TESTS_FLAG], + [EX_EXE_PATH, NO_CATCH_EXCEPTIONS_FLAG, FILTER_OUT_SEH_TESTS_FLAG], env=environ, ).output From e3d405f62b61a228e5359208b1fa933e03eadc65 Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Thu, 22 Jun 2023 11:52:54 -0500 Subject: [PATCH 17/81] add support for nxp qn9090 mcu Added additional defines to correctly detect the NXP QN9090 MCU platform and allow for native googletest compability. --- googletest/include/gtest/internal/gtest-port-arch.h | 2 ++ googletest/include/gtest/internal/gtest-port.h | 3 ++- googletest/src/gtest-filepath.cc | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port-arch.h b/googletest/include/gtest/internal/gtest-port-arch.h index 04064606f..34964932d 100644 --- a/googletest/include/gtest/internal/gtest-port-arch.h +++ b/googletest/include/gtest/internal/gtest-port-arch.h @@ -113,6 +113,8 @@ #define GTEST_OS_XTENSA 1 #elif defined(__hexagon__) #define GTEST_OS_QURT 1 +#elif defined(CPU_QN9090) || defined(CPU_QN9090HN) +#define GTEST_OS_NXP_QN9090 1 #endif // __CYGWIN__ #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index d71110c0c..8b6671459 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -505,7 +505,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #if (!(defined(GTEST_OS_LINUX_ANDROID) || defined(GTEST_OS_CYGWIN) || \ defined(GTEST_OS_SOLARIS) || defined(GTEST_OS_HAIKU) || \ defined(GTEST_OS_ESP32) || defined(GTEST_OS_ESP8266) || \ - defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT))) + defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT) || \ + defined(GTEST_OS_NXP_QN9090))) #define GTEST_HAS_STD_WSTRING 1 #else #define GTEST_HAS_STD_WSTRING 0 diff --git a/googletest/src/gtest-filepath.cc b/googletest/src/gtest-filepath.cc index 75f52bcfc..1d30c9564 100644 --- a/googletest/src/gtest-filepath.cc +++ b/googletest/src/gtest-filepath.cc @@ -102,7 +102,7 @@ FilePath FilePath::GetCurrentDir() { #if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \ defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \ defined(GTEST_OS_ESP32) || defined(GTEST_OS_XTENSA) || \ - defined(GTEST_OS_QURT) + defined(GTEST_OS_QURT) || defined(GTEST_OS_NXP_QN9090) // These platforms do not have a current directory, so we just return // something reasonable. return FilePath(kCurrentDirectoryString); @@ -356,7 +356,7 @@ bool FilePath::CreateFolder() const { #elif defined(GTEST_OS_WINDOWS) int result = _mkdir(pathname_.c_str()); #elif defined(GTEST_OS_ESP8266) || defined(GTEST_OS_XTENSA) || \ - defined(GTEST_OS_QURT) + defined(GTEST_OS_QURT) || defined(GTEST_OS_NXP_QN9090) // do nothing int result = 0; #else From 091d7eb897d5671449efb348834e5c78d36f6459 Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Thu, 11 May 2023 14:28:16 -0500 Subject: [PATCH 18/81] add support for nrf52 Added support for Nordic nRF52 series of MCUs --- googlemock/src/gmock_main.cc | 2 +- googletest/include/gtest/internal/gtest-port-arch.h | 2 ++ googletest/include/gtest/internal/gtest-port.h | 2 +- googletest/src/gtest-filepath.cc | 6 ++++-- googletest/src/gtest_main.cc | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/googlemock/src/gmock_main.cc b/googlemock/src/gmock_main.cc index fb37b53a3..327e6fa6a 100644 --- a/googlemock/src/gmock_main.cc +++ b/googlemock/src/gmock_main.cc @@ -32,7 +32,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -#if defined(GTEST_OS_ESP8266) || defined(GTEST_OS_ESP32) +#if defined(GTEST_OS_ESP8266) || defined(GTEST_OS_ESP32) || (defined(GTEST_OS_NRF52) && defined(ARDUINO)) #ifdef GTEST_OS_ESP8266 extern "C" { #endif diff --git a/googletest/include/gtest/internal/gtest-port-arch.h b/googletest/include/gtest/internal/gtest-port-arch.h index 34964932d..3162f2b1c 100644 --- a/googletest/include/gtest/internal/gtest-port-arch.h +++ b/googletest/include/gtest/internal/gtest-port-arch.h @@ -115,6 +115,8 @@ #define GTEST_OS_QURT 1 #elif defined(CPU_QN9090) || defined(CPU_QN9090HN) #define GTEST_OS_NXP_QN9090 1 +#elif defined(NRF52) +#define GTEST_OS_NRF52 1 #endif // __CYGWIN__ #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 8b6671459..24f1d81a9 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -506,7 +506,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; defined(GTEST_OS_SOLARIS) || defined(GTEST_OS_HAIKU) || \ defined(GTEST_OS_ESP32) || defined(GTEST_OS_ESP8266) || \ defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT) || \ - defined(GTEST_OS_NXP_QN9090))) + defined(GTEST_OS_NXP_QN9090) || defined(GTEST_OS_NRF52))) #define GTEST_HAS_STD_WSTRING 1 #else #define GTEST_HAS_STD_WSTRING 0 diff --git a/googletest/src/gtest-filepath.cc b/googletest/src/gtest-filepath.cc index 1d30c9564..d43f2e5d5 100644 --- a/googletest/src/gtest-filepath.cc +++ b/googletest/src/gtest-filepath.cc @@ -102,7 +102,8 @@ FilePath FilePath::GetCurrentDir() { #if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \ defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \ defined(GTEST_OS_ESP32) || defined(GTEST_OS_XTENSA) || \ - defined(GTEST_OS_QURT) || defined(GTEST_OS_NXP_QN9090) + defined(GTEST_OS_QURT) || defined(GTEST_OS_NXP_QN9090) || \ + defined(GTEST_OS_NRF52) // These platforms do not have a current directory, so we just return // something reasonable. return FilePath(kCurrentDirectoryString); @@ -356,7 +357,8 @@ bool FilePath::CreateFolder() const { #elif defined(GTEST_OS_WINDOWS) int result = _mkdir(pathname_.c_str()); #elif defined(GTEST_OS_ESP8266) || defined(GTEST_OS_XTENSA) || \ - defined(GTEST_OS_QURT) || defined(GTEST_OS_NXP_QN9090) + defined(GTEST_OS_QURT) || defined(GTEST_OS_NXP_QN9090) || \ + defined(GTEST_OS_NRF52) // do nothing int result = 0; #else diff --git a/googletest/src/gtest_main.cc b/googletest/src/gtest_main.cc index c2e3b3cc9..2a9271f75 100644 --- a/googletest/src/gtest_main.cc +++ b/googletest/src/gtest_main.cc @@ -31,7 +31,7 @@ #include "gtest/gtest.h" -#if defined(GTEST_OS_ESP8266) || defined(GTEST_OS_ESP32) +#if defined(GTEST_OS_ESP8266) || defined(GTEST_OS_ESP32) || (defined(GTEST_OS_NRF52) && defined(ARDUINO)) // Arduino-like platforms: program entry points are setup/loop instead of main. #ifdef GTEST_OS_ESP8266 From f269e15c5cafa4ba7f4b543e0c395646bbbbd32d Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 27 Jun 2023 11:14:33 -0700 Subject: [PATCH 19/81] Resolve an issue where the resolution of `operator<<` overloads would attempt to instantiate the incomplete `testing::internal::Secret` type. PiperOrigin-RevId: 543799815 Change-Id: Ic0a4f48d825bef26cb8cc74d8a0117b3a5ef3f14 --- googletest/include/gtest/internal/gtest-port.h | 6 ++++-- googletest/test/gtest_unittest.cc | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 8b6671459..52215409a 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -925,9 +925,11 @@ using std::tuple_size; namespace internal { // A secret type that Google Test users don't know about. It has no -// definition on purpose. Therefore it's impossible to create a +// accessible constructors on purpose. Therefore it's impossible to create a // Secret object, which is what we want. -class Secret; +class Secret { + Secret(const Secret&) = delete; +}; // A helper for suppressing warnings on constant condition. It just // returns 'condition'. diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index dd049a00d..6caa03fd3 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -67,11 +67,27 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) { #include #include #include +#include #include #include "gtest/gtest-spi.h" #include "src/gtest-internal-inl.h" +struct ConvertibleGlobalType { + // The inner enable_if is to ensure invoking is_constructible doesn't fail. + // The outer enable_if is to ensure the overload resolution doesn't encounter + // an ambiguity. + template < + class T, + std::enable_if_t< + false, std::enable_if_t::value, int>> = 0> + operator T() const; // NOLINT(google-explicit-constructor) +}; +void operator<<(ConvertibleGlobalType&, int); +static_assert(sizeof(decltype(std::declval() + << 1)(*)()) > 0, + "error in operator<< overload resolution"); + namespace testing { namespace internal { From 2acd53824402affcf473b2355d7323047e660e86 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Tue, 27 Jun 2023 20:46:32 -0700 Subject: [PATCH 20/81] On platforms without a file system, don't log an error when no alternative output format is requested. Fixes #4299 PiperOrigin-RevId: 543932266 Change-Id: Ide78c313ecf6829e4910f4a8407275c81edb3848 --- googletest/src/gtest.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index d9fd27709..d1eddf103 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -5655,8 +5655,10 @@ void UnitTestImpl::ConfigureXmlOutput() { << output_format << "\" ignored."; } #else - GTEST_LOG_(ERROR) << "ERROR: alternative output formats require " - << "GTEST_HAS_FILE_SYSTEM to be enabled"; + if (!output_format.empty()) { + GTEST_LOG_(ERROR) << "ERROR: alternative output formats require " + << "GTEST_HAS_FILE_SYSTEM to be enabled"; + } #endif // GTEST_HAS_FILE_SYSTEM } From 687c589949eaf8734484491a6882a7fc56aebc12 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 28 Jun 2023 11:44:27 -0700 Subject: [PATCH 21/81] Print stack traces on SEH exceptions on Windows Also tidies up a couple of things: - Prevent handling of stack overflows, which cannot be done safely - `exception_code` is a macro, so we rename it - The `std::string` heap allocation was unnecessary Fixes #4298 PiperOrigin-RevId: 544117790 Change-Id: I8ba61f87119d5fbdb1f653700d9867ca6f8c28ce --- googletest/src/gtest.cc | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index d1eddf103..704e1aca3 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -866,7 +866,7 @@ bool UnitTestOptions::FilterMatchesTest(const std::string& test_suite_name, // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise. // This function is useful as an __except condition. -int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) { +int UnitTestOptions::GTestShouldProcessSEH(DWORD seh_code) { // Google Test should handle a SEH exception if: // 1. the user wants it to, AND // 2. this is not a breakpoint exception, AND @@ -881,9 +881,11 @@ int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) { if (!GTEST_FLAG_GET(catch_exceptions)) should_handle = false; - else if (exception_code == EXCEPTION_BREAKPOINT) + else if (seh_code == EXCEPTION_BREAKPOINT) should_handle = false; - else if (exception_code == kCxxExceptionCode) + else if (seh_code == EXCEPTION_STACK_OVERFLOW) + should_handle = false; + else if (seh_code == kCxxExceptionCode) should_handle = false; return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH; @@ -2555,17 +2557,12 @@ bool Test::HasSameFixtureClass() { #if GTEST_HAS_SEH -// Adds an "exception thrown" fatal failure to the current test. This -// function returns its result via an output parameter pointer because VC++ -// prohibits creation of objects with destructors on stack in functions -// using __try (see error C2712). -static std::string* FormatSehExceptionMessage(DWORD exception_code, - const char* location) { +static std::string FormatSehExceptionMessage(DWORD exception_code, + const char* location) { Message message; message << "SEH exception with code 0x" << std::setbase(16) << exception_code << std::setbase(10) << " thrown in " << location << "."; - - return new std::string(message.GetString()); + return message.GetString(); } #endif // GTEST_HAS_SEH @@ -2613,14 +2610,20 @@ Result HandleSehExceptionsInMethodIfSupported(T* object, Result (T::*method)(), return (object->*method)(); } __except (internal::UnitTestOptions::GTestShouldProcessSEH( // NOLINT GetExceptionCode())) { - // We create the exception message on the heap because VC++ prohibits - // creation of objects with destructors on stack in functions using __try + // We wrap an inner function because VC++ prohibits direct creation of + // objects with destructors on stack in functions using __try // (see error C2712). - std::string* exception_message = - FormatSehExceptionMessage(GetExceptionCode(), location); - internal::ReportFailureInUnknownLocation(TestPartResult::kFatalFailure, - *exception_message); - delete exception_message; + struct Wrapper { + static void ReportFailure(DWORD code, const char* location) { + return internal::ReportFailureInUnknownLocation( + TestPartResult::kFatalFailure, + FormatSehExceptionMessage(code, location) + + "\n" + "Stack trace:\n" + + ::testing::internal::GetCurrentOsStackTraceExceptTop(1)); + } + }; + Wrapper::ReportFailure(GetExceptionCode(), location); return static_cast(0); } #else From 251e720391e92ab1aec845c7fd8ecdda35737f39 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 29 Jun 2023 14:39:44 -0700 Subject: [PATCH 22/81] Change `::testing` to `testing` in Testing Reference doc PiperOrigin-RevId: 544466397 Change-Id: Icb4d5fae38361cd75d47f908886831696eb2b1c9 --- docs/reference/testing.md | 70 +++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/docs/reference/testing.md b/docs/reference/testing.md index 877dfa322..17225a682 100644 --- a/docs/reference/testing.md +++ b/docs/reference/testing.md @@ -122,8 +122,8 @@ custom function can be used for more control: ```cpp INSTANTIATE_TEST_SUITE_P( MyInstantiation, MyTestSuite, - ::testing::Values(...), - [](const ::testing::TestParamInfo& info) { + testing::Values(...), + [](const testing::TestParamInfo& info) { // Can use info.param here to generate the test suffix std::string name = ... return name; @@ -148,7 +148,7 @@ type, for example: ```cpp template -class MyFixture : public ::testing::Test { +class MyFixture : public testing::Test { public: ... using List = std::list; @@ -324,7 +324,7 @@ Then the test code should look like: ```cpp namespace my_namespace { -class MyClassTest : public ::testing::Test { +class MyClassTest : public testing::Test { ... }; @@ -387,7 +387,7 @@ GoogleTest defines the following classes and types to help with writing tests. ### AssertionResult {#AssertionResult} -`::testing::AssertionResult` +`testing::AssertionResult` A class for indicating whether an assertion was successful. @@ -401,14 +401,14 @@ To create an instance of this class, use one of the factory functions ### AssertionException {#AssertionException} -`::testing::AssertionException` +`testing::AssertionException` Exception which can be thrown from [`TestEventListener::OnTestPartResult`](#TestEventListener::OnTestPartResult). ### EmptyTestEventListener {#EmptyTestEventListener} -`::testing::EmptyTestEventListener` +`testing::EmptyTestEventListener` Provides an empty implementation of all methods in the [`TestEventListener`](#TestEventListener) interface, such that a subclass only @@ -416,7 +416,7 @@ needs to override the methods it cares about. ### Environment {#Environment} -`::testing::Environment` +`testing::Environment` Represents a global test environment. See [Global Set-Up and Tear-Down](../advanced.md#global-set-up-and-tear-down). @@ -437,7 +437,7 @@ Override this to define how to tear down the environment. ### ScopedTrace {#ScopedTrace} -`::testing::ScopedTrace` +`testing::ScopedTrace` An instance of this class causes a trace to be included in every test failure message generated by code in the scope of the lifetime of the `ScopedTrace` @@ -453,7 +453,7 @@ ScopedTrace(const char* file, int line, const T& message) Example usage: ```cpp -::testing::ScopedTrace trace("file.cc", 123, "message"); +testing::ScopedTrace trace("file.cc", 123, "message"); ``` The resulting trace includes the given source file path and line number, and the @@ -464,7 +464,7 @@ See also [`SCOPED_TRACE`](#SCOPED_TRACE). ### Test {#Test} -`::testing::Test` +`testing::Test` The abstract class that all tests inherit from. `Test` is not copyable. @@ -552,7 +552,7 @@ after running each individual test. ### TestWithParam {#TestWithParam} -`::testing::TestWithParam` +`testing::TestWithParam` A convenience class which inherits from both [`Test`](#Test) and [`WithParamInterface`](#WithParamInterface). @@ -672,7 +672,7 @@ during execution of `SetUpTestSuite` and `TearDownTestSuite`. ### TestInfo {#TestInfo} -`::testing::TestInfo` +`testing::TestInfo` Stores information about a test. @@ -751,7 +751,7 @@ Returns the result of the test. See [`TestResult`](#TestResult). ### TestParamInfo {#TestParamInfo} -`::testing::TestParamInfo` +`testing::TestParamInfo` Describes a parameter to a value-parameterized test. The type `T` is the type of the parameter. @@ -761,7 +761,7 @@ and its integer index respectively. ### UnitTest {#UnitTest} -`::testing::UnitTest` +`testing::UnitTest` This class contains information about the test program. @@ -929,7 +929,7 @@ GoogleTest. See [`TestEventListeners`](#TestEventListeners). ### TestEventListener {#TestEventListener} -`::testing::TestEventListener` +`testing::TestEventListener` The interface for tracing execution of tests. The methods below are listed in the order the corresponding events are fired. @@ -1027,7 +1027,7 @@ Fired after all test activities have ended. ### TestEventListeners {#TestEventListeners} -`::testing::TestEventListeners` +`testing::TestEventListeners` Lets users add listeners to track events in GoogleTest. @@ -1072,7 +1072,7 @@ the caller and makes this function return `NULL` the next time. ### TestPartResult {#TestPartResult} -`::testing::TestPartResult` +`testing::TestPartResult` A copyable object representing the result of a test part (i.e. an assertion or an explicit `FAIL()`, `ADD_FAILURE()`, or `SUCCESS()`). @@ -1154,7 +1154,7 @@ Returns true if and only if the test part failed. ### TestProperty {#TestProperty} -`::testing::TestProperty` +`testing::TestProperty` A copyable object representing a user-specified test property which can be output as a key/value string pair. @@ -1181,7 +1181,7 @@ Sets a new value, overriding the previous one. ### TestResult {#TestResult} -`::testing::TestResult` +`testing::TestResult` Contains information about the result of a single test. @@ -1262,20 +1262,20 @@ range, aborts the program. ### TimeInMillis {#TimeInMillis} -`::testing::TimeInMillis` +`testing::TimeInMillis` An integer type representing time in milliseconds. ### Types {#Types} -`::testing::Types` +`testing::Types` Represents a list of types for use in typed tests and type-parameterized tests. The template argument `T...` can be any number of types, for example: ``` -::testing::Types +testing::Types ``` See [Typed Tests](../advanced.md#typed-tests) and @@ -1284,7 +1284,7 @@ information. ### WithParamInterface {#WithParamInterface} -`::testing::WithParamInterface` +`testing::WithParamInterface` The pure interface class that all value-parameterized tests inherit from. @@ -1310,9 +1310,9 @@ tests. ### InitGoogleTest {#InitGoogleTest} -`void ::testing::InitGoogleTest(int* argc, char** argv)` \ -`void ::testing::InitGoogleTest(int* argc, wchar_t** argv)` \ -`void ::testing::InitGoogleTest()` +`void testing::InitGoogleTest(int* argc, char** argv)` \ +`void testing::InitGoogleTest(int* argc, wchar_t** argv)` \ +`void testing::InitGoogleTest()` Initializes GoogleTest. This must be called before calling [`RUN_ALL_TESTS()`](#RUN_ALL_TESTS). In particular, it parses the command line @@ -1329,7 +1329,7 @@ platforms where there is no `argc`/`argv`. ### AddGlobalTestEnvironment {#AddGlobalTestEnvironment} -`Environment* ::testing::AddGlobalTestEnvironment(Environment* env)` +`Environment* testing::AddGlobalTestEnvironment(Environment* env)` Adds a test environment to the test program. Must be called before [`RUN_ALL_TESTS()`](#RUN_ALL_TESTS) is called. See @@ -1342,7 +1342,7 @@ See also [`Environment`](#Environment). ```cpp template -TestInfo* ::testing::RegisterTest(const char* test_suite_name, const char* test_name, +TestInfo* testing::RegisterTest(const char* test_suite_name, const char* test_name, const char* type_param, const char* value_param, const char* file, int line, Factory factory) ``` @@ -1381,27 +1381,27 @@ an all-caps name. ### AssertionSuccess {#AssertionSuccess} -`AssertionResult ::testing::AssertionSuccess()` +`AssertionResult testing::AssertionSuccess()` Creates a successful assertion result. See [`AssertionResult`](#AssertionResult). ### AssertionFailure {#AssertionFailure} -`AssertionResult ::testing::AssertionFailure()` +`AssertionResult testing::AssertionFailure()` Creates a failed assertion result. Use the `<<` operator to store a failure message: ```cpp -::testing::AssertionFailure() << "My failure message"; +testing::AssertionFailure() << "My failure message"; ``` See [`AssertionResult`](#AssertionResult). ### StaticAssertTypeEq {#StaticAssertTypeEq} -`::testing::StaticAssertTypeEq()` +`testing::StaticAssertTypeEq()` Compile-time assertion for type equality. Compiles if and only if `T1` and `T2` are the same type. The value it returns is irrelevant. @@ -1410,7 +1410,7 @@ See [Type Assertions](../advanced.md#type-assertions) for more information. ### PrintToString {#PrintToString} -`std::string ::testing::PrintToString(x)` +`std::string testing::PrintToString(x)` Prints any value `x` using GoogleTest's value printer. @@ -1420,7 +1420,7 @@ for more information. ### PrintToStringParamName {#PrintToStringParamName} -`std::string ::testing::PrintToStringParamName(TestParamInfo& info)` +`std::string testing::PrintToStringParamName(TestParamInfo& info)` A built-in parameterized test name generator which returns the result of [`PrintToString`](#PrintToString) called on `info.param`. Does not work when the From 1f531be3a19055d1402ec6476c5cab80492d3c68 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 30 Jun 2023 10:32:13 -0700 Subject: [PATCH 23/81] Make GoogleTest handle SEH exceptions before stack unwinding rather than afterward This ensure the erroring stack frame is visible and accessible when the handler is invoked. Fixes #4298 PiperOrigin-RevId: 544692549 Change-Id: Ia165a8c293e8edc820da5f5ad4416546fffe2493 --- googletest/src/gtest-internal-inl.h | 6 +-- googletest/src/gtest.cc | 67 +++++++++++------------------ 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index be821662c..1e9b5c266 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -387,10 +387,10 @@ class GTEST_API_ UnitTestOptions { #ifdef GTEST_OS_WINDOWS // Function for supporting the gtest_catch_exception flag. - // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the - // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise. + // Returns EXCEPTION_EXECUTE_HANDLER if given SEH exception was handled, or + // EXCEPTION_CONTINUE_SEARCH otherwise. // This function is useful as an __except condition. - static int GTestShouldProcessSEH(DWORD exception_code); + static int GTestProcessSEH(DWORD seh_code, const char* location); #endif // GTEST_OS_WINDOWS // Returns true if "name" matches the ':' separated list of glob-style diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 704e1aca3..30a5cc3f8 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -863,13 +863,18 @@ bool UnitTestOptions::FilterMatchesTest(const std::string& test_suite_name, } #if GTEST_HAS_SEH -// Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the -// given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise. -// This function is useful as an __except condition. -int UnitTestOptions::GTestShouldProcessSEH(DWORD seh_code) { +static std::string FormatSehExceptionMessage(DWORD exception_code, + const char* location) { + Message message; + message << "SEH exception with code 0x" << std::setbase(16) << exception_code + << std::setbase(10) << " thrown in " << location << "."; + return message.GetString(); +} + +int UnitTestOptions::GTestProcessSEH(DWORD seh_code, const char* location) { // Google Test should handle a SEH exception if: // 1. the user wants it to, AND - // 2. this is not a breakpoint exception, AND + // 2. this is not a breakpoint exception or stack overflow, AND // 3. this is not a C++ exception (VC++ implements them via SEH, // apparently). // @@ -877,18 +882,20 @@ int UnitTestOptions::GTestShouldProcessSEH(DWORD seh_code) { // (see http://support.microsoft.com/kb/185294 for more information). const DWORD kCxxExceptionCode = 0xe06d7363; - bool should_handle = true; + if (!GTEST_FLAG_GET(catch_exceptions) || seh_code == kCxxExceptionCode || + seh_code == EXCEPTION_BREAKPOINT || + seh_code == EXCEPTION_STACK_OVERFLOW) { + return EXCEPTION_CONTINUE_SEARCH; // Don't handle these exceptions + } - if (!GTEST_FLAG_GET(catch_exceptions)) - should_handle = false; - else if (seh_code == EXCEPTION_BREAKPOINT) - should_handle = false; - else if (seh_code == EXCEPTION_STACK_OVERFLOW) - should_handle = false; - else if (seh_code == kCxxExceptionCode) - should_handle = false; + internal::ReportFailureInUnknownLocation( + TestPartResult::kFatalFailure, + FormatSehExceptionMessage(seh_code, location) + + "\n" + "Stack trace:\n" + + ::testing::internal::GetCurrentOsStackTraceExceptTop(1)); - return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH; + return EXCEPTION_EXECUTE_HANDLER; } #endif // GTEST_HAS_SEH @@ -2555,18 +2562,6 @@ bool Test::HasSameFixtureClass() { return true; } -#if GTEST_HAS_SEH - -static std::string FormatSehExceptionMessage(DWORD exception_code, - const char* location) { - Message message; - message << "SEH exception with code 0x" << std::setbase(16) << exception_code - << std::setbase(10) << " thrown in " << location << "."; - return message.GetString(); -} - -#endif // GTEST_HAS_SEH - namespace internal { #if GTEST_HAS_EXCEPTIONS @@ -2608,22 +2603,8 @@ Result HandleSehExceptionsInMethodIfSupported(T* object, Result (T::*method)(), #if GTEST_HAS_SEH __try { return (object->*method)(); - } __except (internal::UnitTestOptions::GTestShouldProcessSEH( // NOLINT - GetExceptionCode())) { - // We wrap an inner function because VC++ prohibits direct creation of - // objects with destructors on stack in functions using __try - // (see error C2712). - struct Wrapper { - static void ReportFailure(DWORD code, const char* location) { - return internal::ReportFailureInUnknownLocation( - TestPartResult::kFatalFailure, - FormatSehExceptionMessage(code, location) + - "\n" - "Stack trace:\n" + - ::testing::internal::GetCurrentOsStackTraceExceptTop(1)); - } - }; - Wrapper::ReportFailure(GetExceptionCode(), location); + } __except (internal::UnitTestOptions::GTestProcessSEH( // NOLINT + GetExceptionCode(), location)) { return static_cast(0); } #else From be03d00f5f0cc3a997d1a368bee8a1fe93651f48 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Fri, 30 Jun 2023 18:49:33 -0700 Subject: [PATCH 24/81] Fix C++20 compatibility bug. This was shown to work for C++14, C++17, and C++20 after patched into googletest for the protobuf repo's CI. Closes #3659 PiperOrigin-RevId: 544795507 Change-Id: I3e0a94f675e78a6ee9aeccae86c23d940efed8eb --- googletest/include/gtest/gtest-printers.h | 6 +++--- googletest/include/gtest/internal/gtest-port.h | 2 +- googletest/src/gtest-printers.cc | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 539d99c40..9a765fd79 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -475,7 +475,7 @@ GTEST_API_ void PrintTo(char32_t c, ::std::ostream* os); inline void PrintTo(char16_t c, ::std::ostream* os) { PrintTo(ImplicitCast_(c), os); } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t inline void PrintTo(char8_t c, ::std::ostream* os) { PrintTo(ImplicitCast_(c), os); } @@ -588,7 +588,7 @@ inline void PrintTo(const unsigned char* s, ::std::ostream* os) { inline void PrintTo(unsigned char* s, ::std::ostream* os) { PrintTo(ImplicitCast_(s), os); } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t // Overloads for u8 strings. GTEST_API_ void PrintTo(const char8_t* s, ::std::ostream* os); inline void PrintTo(char8_t* s, ::std::ostream* os) { @@ -908,7 +908,7 @@ void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) { GTEST_API_ void UniversalPrintArray(const char* begin, size_t len, ::std::ostream* os); -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t // This overload prints a (const) char8_t array compactly. GTEST_API_ void UniversalPrintArray(const char8_t* begin, size_t len, ::std::ostream* os); diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 52215409a..26e4cc3d3 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -1998,7 +1998,7 @@ inline bool IsUpper(char ch) { inline bool IsXDigit(char ch) { return isxdigit(static_cast(ch)) != 0; } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t inline bool IsXDigit(char8_t ch) { return isxdigit(static_cast(ch)) != 0; } diff --git a/googletest/src/gtest-printers.cc b/googletest/src/gtest-printers.cc index 2b4706782..e3acecba8 100644 --- a/googletest/src/gtest-printers.cc +++ b/googletest/src/gtest-printers.cc @@ -216,7 +216,7 @@ static const char* GetCharWidthPrefix(signed char) { return ""; } static const char* GetCharWidthPrefix(unsigned char) { return ""; } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t static const char* GetCharWidthPrefix(char8_t) { return "u8"; } #endif @@ -232,7 +232,7 @@ static CharFormat PrintAsStringLiteralTo(char c, ostream* os) { return PrintAsStringLiteralTo(ToChar32(c), os); } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t static CharFormat PrintAsStringLiteralTo(char8_t c, ostream* os) { return PrintAsStringLiteralTo(ToChar32(c), os); } @@ -395,7 +395,7 @@ void UniversalPrintArray(const char* begin, size_t len, ostream* os) { UniversalPrintCharArray(begin, len, os); } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t // Prints a (const) char8_t array of 'len' elements, starting at address // 'begin'. void UniversalPrintArray(const char8_t* begin, size_t len, ostream* os) { @@ -438,7 +438,7 @@ void PrintCStringTo(const Char* s, ostream* os) { void PrintTo(const char* s, ostream* os) { PrintCStringTo(s, os); } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t void PrintTo(const char8_t* s, ostream* os) { PrintCStringTo(s, os); } #endif From 3044657e7afa759ce875a8161cd4bff0fd2e22bc Mon Sep 17 00:00:00 2001 From: Steve Robbins Date: Mon, 3 Jul 2023 21:23:18 -0500 Subject: [PATCH 25/81] Use template type FloatType in the cast. --- googletest/include/gtest/gtest-printers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 9a765fd79..e69a0a60a 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -531,7 +531,7 @@ int AppropriateResolution(FloatType val) { } else if (val >= 0.0001) { mulfor6 = 1e9; } - if (static_cast(static_cast(val * mulfor6 + 0.5)) / + if (static_cast(static_cast(val * mulfor6 + 0.5)) / mulfor6 == val) return 6; @@ -546,7 +546,7 @@ int AppropriateResolution(FloatType val) { } else if (val >= 1e6) { // 1,000,000 to 9,999,999 divfor6 = 10; } - if (static_cast(static_cast(val / divfor6 + 0.5)) * + if (static_cast(static_cast(val / divfor6 + 0.5)) * divfor6 == val) return 6; From 4a1a299b206ba250a4318f74938ea67c75c3c0c9 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 7 Jul 2023 13:42:49 -0700 Subject: [PATCH 26/81] Update docstring of PrintWithFallback(..) to reflect the recently changed ordering. PiperOrigin-RevId: 546373360 Change-Id: I2538b45d8c7710592071cc352da6771480c324e6 --- googletest/include/gtest/gtest-printers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 9a765fd79..bcdecd109 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -298,8 +298,8 @@ struct FindFirstPrinter< // - Print containers (they have begin/end/etc). // - Print function pointers. // - Print object pointers. -// - Use the stream operator, if available. // - Print protocol buffers. +// - Use the stream operator, if available. // - Print types convertible to BiggestInt. // - Print types convertible to StringView, if available. // - Fallback to printing the raw bytes of the object. From c88e0b4673f9b08818e0e74c4ed718db5f9b809c Mon Sep 17 00:00:00 2001 From: kimvaleen Date: Tue, 11 Jul 2023 12:05:05 +0300 Subject: [PATCH 27/81] Fixed variables that could be declared 'const' --- googletest/include/gtest/gtest.h | 2 +- googletest/include/gtest/internal/gtest-internal.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 86777c854..bee2aca5c 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -2102,7 +2102,7 @@ class GTEST_API_ ScopedTrace { // Therefore, a SCOPED_TRACE() would (correctly) only affect the // assertions in its own thread. #define SCOPED_TRACE(message) \ - ::testing::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)( \ + const ::testing::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)( \ __FILE__, __LINE__, (message)) // Compile-time assertion for type equality. diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 317894e73..a816ec2a4 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -1500,7 +1500,7 @@ class NeverThrown { #define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (::testing::internal::AlwaysTrue()) { \ - ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ + const ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \ From f014396910d397b4f408c0c867aa8ca6a000ef7f Mon Sep 17 00:00:00 2001 From: Anton Sosnin Date: Wed, 19 Jul 2023 18:08:41 +0300 Subject: [PATCH 28/81] Fix typo in gmock_cook_book.md --- docs/gmock_cook_book.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/gmock_cook_book.md b/docs/gmock_cook_book.md index f736b9fb8..e319bf636 100644 --- a/docs/gmock_cook_book.md +++ b/docs/gmock_cook_book.md @@ -2640,8 +2640,8 @@ action will exhibit different behaviors. Example: .WillRepeatedly(IncrementCounter(0)); foo.DoThis(); // Returns 1. foo.DoThis(); // Returns 2. - foo.DoThat(); // Returns 1 - Blah() uses a different - // counter than Bar()'s. + foo.DoThat(); // Returns 1 - DoThat() uses a different + // counter than DoThis()'s. ``` versus From 1ed6a8c67a0bd675149ece27bbec0ef1759854cf Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Wed, 19 Jul 2023 16:21:08 -0700 Subject: [PATCH 29/81] Remove unused cast implementation PiperOrigin-RevId: 549456180 Change-Id: I10862e6de981087a5c590cccf6152255e9a176a0 --- .../include/gtest/internal/gtest-port.h | 41 ------------------- 1 file changed, 41 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 514b1cc7d..656df2606 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -1146,47 +1146,6 @@ inline To ImplicitCast_(To x) { return x; } -// When you upcast (that is, cast a pointer from type Foo to type -// SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts -// always succeed. When you downcast (that is, cast a pointer from -// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because -// how do you know the pointer is really of type SubclassOfFoo? It -// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus, -// when you downcast, you should use this macro. In debug mode, we -// use dynamic_cast<> to double-check the downcast is legal (we die -// if it's not). In normal mode, we do the efficient static_cast<> -// instead. Thus, it's important to test in debug mode to make sure -// the cast is legal! -// This is the only place in the code we should use dynamic_cast<>. -// In particular, you SHOULDN'T be using dynamic_cast<> in order to -// do RTTI (eg code like this: -// if (dynamic_cast(foo)) HandleASubclass1Object(foo); -// if (dynamic_cast(foo)) HandleASubclass2Object(foo); -// You should design the code some other way not to need this. -// -// This relatively ugly name is intentional. It prevents clashes with -// similar functions users may have (e.g., down_cast). The internal -// namespace alone is not enough because the function can be found by ADL. -template // use like this: DownCast_(foo); -inline To DownCast_(From* f) { // so we only accept pointers - // Ensures that To is a sub-type of From *. This test is here only - // for compile-time type checking, and has no overhead in an - // optimized build at run-time, as it will be optimized away - // completely. - GTEST_INTENTIONAL_CONST_COND_PUSH_() - if (false) { - GTEST_INTENTIONAL_CONST_COND_POP_() - const To to = nullptr; - ::testing::internal::ImplicitCast_(to); - } - -#if GTEST_HAS_RTTI - // RTTI: debug mode only! - GTEST_CHECK_(f == nullptr || dynamic_cast(f) != nullptr); -#endif - return static_cast(f); -} - // Downcasts the pointer of type Base to Derived. // Derived must be a subclass of Base. The parameter MUST // point to a class of type Derived, not any subclass of it. From 01e18376efe643a82cff468734f87f8c60e314b6 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 21 Jul 2023 10:35:31 -0700 Subject: [PATCH 30/81] Make `AbslStringify` usage public in GoogleTest Fixes #4314 PiperOrigin-RevId: 549986457 Change-Id: Iff74f02ab1c106696f288540e9c623d56b76e3f7 --- googletest/include/gtest/gtest-printers.h | 22 ++++++++++++++++ googletest/test/googletest-printers-test.cc | 28 +++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 1ba5178e1..d1766e640 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -43,6 +43,9 @@ // 1. foo::PrintTo(const T&, ostream*) // 2. operator<<(ostream&, const T&) defined in either foo or the // global namespace. +// * Prefer AbslStringify(..) to operator<<(..), per https://abseil.io/tips/215. +// * Define foo::PrintTo(..) if the type already has AbslStringify(..), but an +// alternative presentation in test results is of interest. // // However if T is an STL-style container then it is printed element-wise // unless foo::PrintTo(const T&, ostream*) is defined. Note that @@ -112,6 +115,10 @@ #include #include +#ifdef GTEST_HAS_ABSL +#include "absl/strings/internal/has_absl_stringify.h" +#include "absl/strings/str_cat.h" +#endif // GTEST_HAS_ABSL #include "gtest/internal/gtest-internal.h" #include "gtest/internal/gtest-port.h" @@ -260,6 +267,18 @@ struct ConvertibleToStringViewPrinter { #endif }; +#ifdef GTEST_HAS_ABSL +struct ConvertibleToAbslStringifyPrinter { + template < + typename T, + typename = typename std::enable_if< + absl::strings_internal::HasAbslStringify::value>::type> // NOLINT + static void PrintValue(const T& value, ::std::ostream* os) { + *os << absl::StrCat(value); + } +}; +#endif // GTEST_HAS_ABSL + // Prints the given number of bytes in the given object to the given // ostream. GTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes, @@ -308,6 +327,9 @@ void PrintWithFallback(const T& value, ::std::ostream* os) { using Printer = typename FindFirstPrinter< T, void, ContainerPrinter, FunctionPointerPrinter, PointerPrinter, ProtobufPrinter, +#ifdef GTEST_HAS_ABSL + ConvertibleToAbslStringifyPrinter, +#endif // GTEST_HAS_ABSL internal_stream_operator_without_lexical_name_lookup::StreamPrinter, ConvertibleToIntegerPrinter, ConvertibleToStringViewPrinter, RawBytesPrinter, FallbackPrinter>::type; diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index f44f29a56..bee0ca4ab 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -55,6 +55,10 @@ #include "gtest/gtest-printers.h" #include "gtest/gtest.h" +#ifdef GTEST_HAS_ABSL +#include "absl/strings/str_format.h" +#endif + // Some user-defined types for testing the universal value printer. // An anonymous enum type. @@ -119,6 +123,19 @@ void operator<<(::std::ostream& os, const StreamableInGlobal* /* x */) { os << "StreamableInGlobal*"; } +#ifdef GTEST_HAS_ABSL +// A user-defined type with AbslStringify +struct Point { + template + friend void AbslStringify(Sink& sink, const Point& p) { + absl::Format(&sink, "(%d, %d)", p.x, p.y); + } + + int x = 10; + int y = 20; +}; +#endif + namespace foo { // A user-defined unprintable type in a user namespace. @@ -317,6 +334,11 @@ TEST(PrintEnumTest, EnumWithPrintTo) { EXPECT_EQ("invalid", Print(static_cast(0))); } +#ifdef GTEST_HAS_ABSL +// Tests printing a class that defines AbslStringify +TEST(PrintClassTest, AbslStringify) { EXPECT_EQ("(10, 20)", Print(Point())); } +#endif + // Tests printing a class implicitly convertible to BiggestInt. TEST(PrintClassTest, BiggestIntConvertible) { @@ -1636,6 +1658,12 @@ TEST(PrintToStringTest, PrintReferenceToStreamableInGlobal) { EXPECT_STREQ("StreamableInGlobal", PrintToString(r).c_str()); } +#ifdef GTEST_HAS_ABSL +TEST(PrintToStringTest, AbslStringify) { + EXPECT_PRINT_TO_STRING_(Point(), "(10, 20)"); +} +#endif + TEST(IsValidUTF8Test, IllFormedUTF8) { // The following test strings are ill-formed UTF-8 and are printed // as hex only (or ASCII, in case of ASCII bytes) because IsValidUTF8() is From 2f83a6e8f8aa56335f8b6a4d72c0a6841dcfa985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Gawro=C5=84ski?= Date: Thu, 27 Jul 2023 01:45:41 +0200 Subject: [PATCH 31/81] gtest: Supress warning about set unused variable Modified test ExpectThrowTest.DoesNotGenerateUnreachableCodeWarning --- googletest/test/gtest_unittest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 6caa03fd3..b1cbddfe2 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -4109,7 +4109,7 @@ TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) { // Tests that the compiler will not complain about unreachable code in the // EXPECT_THROW/EXPECT_ANY_THROW/EXPECT_NO_THROW macros. TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) { - int n = 0; + [[maybe_unused]] int n{0}; EXPECT_THROW(throw 1, int); EXPECT_NONFATAL_FAILURE(EXPECT_THROW(n++, int), ""); From c875c4e2249ec124c24f72141b3780c22256fd44 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 28 Jul 2023 09:50:50 -0700 Subject: [PATCH 32/81] Adjust includes to use <> instead of "", consistent with quickstart pages. Right now, gtest documentation uses different #include syntax. The quickstart pages (e.g., http://google.github.io/googletest/quickstart-bazel.html#create-and-run-a-binary) are checked in with `#include ` However, other documentation (such as the primer) uses `#include "gtest/gtest.h"` (e.g., https://google.github.io/googletest/primer.html#writing-the-main-function). PiperOrigin-RevId: 551878641 Change-Id: Iab93cc1da3ef4870a07b624071b75d6e9d3568c1 --- docs/gmock_cheat_sheet.md | 2 +- docs/gmock_cook_book.md | 2 +- docs/gmock_for_dummies.md | 6 +++--- docs/primer.md | 2 +- docs/reference/assertions.md | 2 +- googletest/README.md | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/gmock_cheat_sheet.md b/docs/gmock_cheat_sheet.md index 2fb0403e6..ddafaaa22 100644 --- a/docs/gmock_cheat_sheet.md +++ b/docs/gmock_cheat_sheet.md @@ -20,7 +20,7 @@ class Foo { (note that `~Foo()` **must** be virtual) we can define its mock as ```cpp -#include "gmock/gmock.h" +#include class MockFoo : public Foo { public: diff --git a/docs/gmock_cook_book.md b/docs/gmock_cook_book.md index e319bf636..da10918c9 100644 --- a/docs/gmock_cook_book.md +++ b/docs/gmock_cook_book.md @@ -3194,7 +3194,7 @@ You can unlock this power by running your test with the `--gmock_verbose=info` flag. For example, given the test program: ```cpp -#include "gmock/gmock.h" +#include using ::testing::_; using ::testing::HasSubstr; diff --git a/docs/gmock_for_dummies.md b/docs/gmock_for_dummies.md index b7264d358..43f907aaa 100644 --- a/docs/gmock_for_dummies.md +++ b/docs/gmock_for_dummies.md @@ -164,7 +164,7 @@ follow: After the process, you should have something like: ```cpp -#include "gmock/gmock.h" // Brings in gMock. +#include // Brings in gMock. class MockTurtle : public Turtle { public: @@ -224,8 +224,8 @@ Here's an example: ```cpp #include "path/to/mock-turtle.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" +#include +#include using ::testing::AtLeast; // #1 diff --git a/docs/primer.md b/docs/primer.md index c3aee3cc6..f2a97a726 100644 --- a/docs/primer.md +++ b/docs/primer.md @@ -395,7 +395,7 @@ You can start from this boilerplate: ```c++ #include "this/package/foo.h" -#include "gtest/gtest.h" +#include namespace my { namespace project { diff --git a/docs/reference/assertions.md b/docs/reference/assertions.md index 1cdff266e..aa1dbc04b 100644 --- a/docs/reference/assertions.md +++ b/docs/reference/assertions.md @@ -88,7 +88,7 @@ For example, the following code verifies that the string `value1` starts with 10: ```cpp -#include "gmock/gmock.h" +#include using ::testing::AllOf; using ::testing::Gt; diff --git a/googletest/README.md b/googletest/README.md index 6bbd7f875..815f3fc02 100644 --- a/googletest/README.md +++ b/googletest/README.md @@ -145,7 +145,7 @@ We list the most frequently used macros below. For a complete list, see file ### Multi-threaded Tests GoogleTest is thread-safe where the pthread library is available. After -`#include "gtest/gtest.h"`, you can check the +`#include `, you can check the `GTEST_IS_THREADSAFE` macro to see whether this is the case (yes if the macro is `#defined` to 1, no if it's undefined.). From efe6bb1db894556b5125b3b3147d6c37fbaffa51 Mon Sep 17 00:00:00 2001 From: Julien Combattelli Date: Thu, 27 Jul 2023 10:19:12 +0200 Subject: [PATCH 33/81] Use #if and not #ifdef to check filesystem support --- googletest/src/gtest-internal-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index 1e9b5c266..5b7fcbd06 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -672,7 +672,7 @@ class GTEST_API_ UnitTestImpl { void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc, internal::TearDownTestSuiteFunc tear_down_tc, TestInfo* test_info) { -#ifdef GTEST_HAS_FILE_SYSTEM +#if GTEST_HAS_FILE_SYSTEM // In order to support thread-safe death tests, we need to // remember the original working directory when the test program // was first invoked. We cannot do this in RUN_ALL_TESTS(), as From 717d8ab5e0f7d925ad3076dc53aebe7a7bcb8aaf Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Tue, 1 Aug 2023 13:56:21 -0700 Subject: [PATCH 34/81] Update GoogleTest dependencies PiperOrigin-RevId: 552912819 Change-Id: If1b6278f7fe5a8fc41fc3bc390356a94387d0091 --- WORKSPACE | 24 ++++++++++++------------ googletest_deps.bzl | 16 ++++++++-------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 1c8ea24d3..f819ffe61 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -6,22 +6,22 @@ googletest_deps() load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( - name = "rules_python", # 2023-01-10T22:00:51Z - sha256 = "5de54486a60ad8948dabe49605bb1c08053e04001a431ab3e96745b4d97a4419", - strip_prefix = "rules_python-70cce26432187a60b4e950118791385e6fb3c26f", - urls = ["https://github.com/bazelbuild/rules_python/archive/70cce26432187a60b4e950118791385e6fb3c26f.zip"], + name = "rules_python", # 2023-07-31T20:39:27Z + sha256 = "1250b59a33c591a1c4ba68c62e95fc88a84c334ec35a2e23f46cbc1b9a5a8b55", + strip_prefix = "rules_python-e355becc30275939d87116a4ec83dad4bb50d9e1", + urls = ["https://github.com/bazelbuild/rules_python/archive/e355becc30275939d87116a4ec83dad4bb50d9e1.zip"], ) http_archive( - name = "bazel_skylib", # 2022-11-16T18:29:32Z - sha256 = "a22290c26d29d3ecca286466f7f295ac6cbe32c0a9da3a91176a90e0725e3649", - strip_prefix = "bazel-skylib-5bfcb1a684550626ce138fe0fe8f5f702b3764c3", - urls = ["https://github.com/bazelbuild/bazel-skylib/archive/5bfcb1a684550626ce138fe0fe8f5f702b3764c3.zip"], + name = "bazel_skylib", # 2023-05-31T19:24:07Z + sha256 = "08c0386f45821ce246bbbf77503c973246ed6ee5c3463e41efc197fa9bc3a7f4", + strip_prefix = "bazel-skylib-288731ef9f7f688932bd50e704a91a45ec185f9b", + urls = ["https://github.com/bazelbuild/bazel-skylib/archive/288731ef9f7f688932bd50e704a91a45ec185f9b.zip"], ) http_archive( - name = "platforms", # 2022-11-09T19:18:22Z - sha256 = "b4a3b45dc4202e2b3e34e3bc49d2b5b37295fc23ea58d88fb9e01f3642ad9b55", - strip_prefix = "platforms-3fbc687756043fb58a407c2ea8c944bc2fe1d922", - urls = ["https://github.com/bazelbuild/platforms/archive/3fbc687756043fb58a407c2ea8c944bc2fe1d922.zip"], + name = "platforms", # 2023-07-28T19:44:27Z + sha256 = "40eb313613ff00a5c03eed20aba58890046f4d38dec7344f00bb9a8867853526", + strip_prefix = "platforms-4ad40ef271da8176d4fc0194d2089b8a76e19d7b", + urls = ["https://github.com/bazelbuild/platforms/archive/4ad40ef271da8176d4fc0194d2089b8a76e19d7b.zip"], ) diff --git a/googletest_deps.bzl b/googletest_deps.bzl index 5e807d72d..e25f5a1ad 100644 --- a/googletest_deps.bzl +++ b/googletest_deps.bzl @@ -7,16 +7,16 @@ def googletest_deps(): if not native.existing_rule("com_googlesource_code_re2"): http_archive( - name = "com_googlesource_code_re2", # 2023-06-01 - sha256 = "1726508efc93a50854c92e3f7ac66eb28f0e57652e413f11d7c1e28f97d997ba", - strip_prefix = "re2-03da4fc0857c285e3a26782f6bc8931c4c950df4", - urls = ["https://github.com/google/re2/archive/03da4fc0857c285e3a26782f6bc8931c4c950df4.zip"], + name = "com_googlesource_code_re2", # 2023-03-17T11:36:51Z + sha256 = "cb8b5312a65f2598954545a76e8bce913f35fbb3a21a5c88797a4448e9f9b9d9", + strip_prefix = "re2-578843a516fd1da7084ae46209a75f3613b6065e", + urls = ["https://github.com/google/re2/archive/578843a516fd1da7084ae46209a75f3613b6065e.zip"], ) if not native.existing_rule("com_google_absl"): http_archive( - name = "com_google_absl", # 2023-04-06T14:42:25Z - sha256 = "a50452f02402262f9a61a8eedda60f76dda6b9538d36b34b55bce9f74a4d5ef8", - strip_prefix = "abseil-cpp-e73b9139ee9b853a4bd7812531442c138da09084", - urls = ["https://github.com/abseil/abseil-cpp/archive/e73b9139ee9b853a4bd7812531442c138da09084.zip"], + name = "com_google_absl", # 2023-08-01T14:59:13Z + sha256 = "d2c09bf3b3aba57ad87a56082020bee2948445407756e92ddaf3595396086853", + strip_prefix = "abseil-cpp-22091f4c0d6626b3ef40446ce3d4ccab19425ca3", + urls = ["https://github.com/abseil/abseil-cpp/archive/22091f4c0d6626b3ef40446ce3d4ccab19425ca3.zip"], ) From e7fd109b536a8e22cc9e8aad84b35221c3d36042 Mon Sep 17 00:00:00 2001 From: Phoebe Liang Date: Tue, 1 Aug 2023 14:01:00 -0700 Subject: [PATCH 35/81] Make testing::Message support streamed AbslStringify values This allows types that provide an AbslStringify definition to be streamed into GoogleTest macros. PiperOrigin-RevId: 552914482 Change-Id: I5fb386980d4d24873f95f0a8ef83067a6a3c86ac --- googletest/include/gtest/gtest-message.h | 36 ++++++++++++++++++++-- googletest/test/googletest-message-test.cc | 23 ++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/googletest/include/gtest/gtest-message.h b/googletest/include/gtest/gtest-message.h index 4d4b152b1..59b805e4e 100644 --- a/googletest/include/gtest/gtest-message.h +++ b/googletest/include/gtest/gtest-message.h @@ -56,6 +56,13 @@ #include "gtest/internal/gtest-port.h" +#ifdef GTEST_HAS_ABSL +#include + +#include "absl/strings/internal/has_absl_stringify.h" +#include "absl/strings/str_cat.h" +#endif // GTEST_HAS_ABSL + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ /* class A needs to have dll-interface to be used by clients of class B */) @@ -111,8 +118,17 @@ class GTEST_API_ Message { *ss_ << str; } - // Streams a non-pointer value to this object. - template + // Streams a non-pointer value to this object. If building a version of + // GoogleTest with ABSL, this overload is only enabled if the value does not + // have an AbslStringify definition. + template ::value, // NOLINT + int>::type = 0 +#endif // GTEST_HAS_ABSL + > inline Message& operator<<(const T& val) { // Some libraries overload << for STL containers. These // overloads are defined in the global namespace instead of ::std. @@ -133,6 +149,22 @@ class GTEST_API_ Message { return *this; } +#ifdef GTEST_HAS_ABSL + // Streams a non-pointer value with an AbslStringify definition to this + // object. + template ::value, // NOLINT + int>::type = 0> + inline Message& operator<<(const T& val) { + // ::operator<< is needed here for a similar reason as with the non-Abseil + // version above + using ::operator<<; + *ss_ << absl::StrCat(val); + return *this; + } +#endif // GTEST_HAS_ABSL + // Streams a pointer value to this object. // // This function is an overload of the previous one. When you diff --git a/googletest/test/googletest-message-test.cc b/googletest/test/googletest-message-test.cc index 54e9d43c9..bf1f094c9 100644 --- a/googletest/test/googletest-message-test.cc +++ b/googletest/test/googletest-message-test.cc @@ -36,10 +36,26 @@ #include "gtest/gtest-message.h" #include "gtest/gtest.h" +#ifdef GTEST_HAS_ABSL +#include "absl/strings/str_format.h" +#endif // GTEST_HAS_ABSL + namespace { using ::testing::Message; +#ifdef GTEST_HAS_ABSL +struct AbslStringifiablePoint { + template + friend void AbslStringify(Sink& sink, const AbslStringifiablePoint& p) { + absl::Format(&sink, "(%d, %d)", p.x, p.y); + } + + int x; + int y; +}; +#endif // GTEST_HAS_ABSL + // Tests the testing::Message class // Tests the default constructor. @@ -128,6 +144,13 @@ TEST(MessageTest, StreamsInt) { EXPECT_EQ("123", (Message() << 123).GetString()); } +#ifdef GTEST_HAS_ABSL +// Tests streaming a type with an AbslStringify definition. +TEST(MessageTest, StreamsAbslStringify) { + EXPECT_EQ("(1, 2)", (Message() << AbslStringifiablePoint{1, 2}).GetString()); +} +#endif // GTEST_HAS_ABSL + // Tests that basic IO manipulators (endl, ends, and flush) can be // streamed to Message. TEST(MessageTest, StreamsBasicIoManip) { From 58e37f7e99152a28a092028294a6ca587e6657c5 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Wed, 2 Aug 2023 07:40:26 -0700 Subject: [PATCH 36/81] Add googletest-message-test to the Bazel tests It appears to have been unintentionally left out PiperOrigin-RevId: 553141410 Change-Id: I8adac55a3df0ec12d6fe03446f71858fc702e178 --- googletest/test/BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/googletest/test/BUILD.bazel b/googletest/test/BUILD.bazel index 7754c1303..1890b6ff9 100644 --- a/googletest/test/BUILD.bazel +++ b/googletest/test/BUILD.bazel @@ -64,6 +64,7 @@ cc_test( "googletest-global-environment-unittest_.cc", "googletest-break-on-failure-unittest_.cc", "googletest-listener-test.cc", + "googletest-message-test.cc", "googletest-output-test_.cc", "googletest-list-tests-unittest_.cc", "googletest-shuffle-test_.cc", From 96683ee6680e433a53e7deda976640ae3268012d Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Wed, 2 Aug 2023 08:18:56 -0700 Subject: [PATCH 37/81] Remove the GTEST_HAS_DOWNCAST_ customization point. PiperOrigin-RevId: 553150809 Change-Id: I10d19a45a85c5f63a5e65dc322413307116e1c25 --- googletest/include/gtest/internal/gtest-port.h | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 656df2606..b887e24ed 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -220,7 +220,6 @@ // GTEST_HAS_ALT_PATH_SEP_ - Always defined to 0 or 1. // GTEST_WIDE_STRING_USES_UTF16_ - Always defined to 0 or 1. // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ - Always defined to 0 or 1. -// GTEST_HAS_DOWNCAST_ - Always defined to 0 or 1. // GTEST_HAS_NOTIFICATION_- Always defined to 0 or 1. // // Synchronization: @@ -313,10 +312,6 @@ #include "gtest/internal/custom/gtest-port.h" #include "gtest/internal/gtest-port-arch.h" -#ifndef GTEST_HAS_DOWNCAST_ -#define GTEST_HAS_DOWNCAST_ 0 -#endif - #ifndef GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ #define GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ 0 #endif @@ -1153,17 +1148,12 @@ inline To ImplicitCast_(To x) { // check to enforce this. template Derived* CheckedDowncastToActualType(Base* base) { + static_assert(std::is_base_of::value, + "target type not derived from source type"); #if GTEST_HAS_RTTI - GTEST_CHECK_(typeid(*base) == typeid(Derived)); -#endif - -#if GTEST_HAS_DOWNCAST_ - return ::down_cast(base); -#elif GTEST_HAS_RTTI - return dynamic_cast(base); // NOLINT -#else - return static_cast(base); // Poor man's downcast. + GTEST_CHECK_(base == nullptr || dynamic_cast(base) != nullptr); #endif + return static_cast(base); } #if GTEST_HAS_STREAM_REDIRECTION From f8d7d77c06936315286eb55f8de22cd23c188571 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Wed, 2 Aug 2023 08:24:13 -0700 Subject: [PATCH 38/81] Bump version to v1.14 in preparation for release PiperOrigin-RevId: 553152072 Change-Id: I0bfbb2da6b3902fc3e41a8e1c4aacb291ffdd098 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b5cf3c48..089ac987f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.13) project(googletest-distribution) -set(GOOGLETEST_VERSION 1.13.0) +set(GOOGLETEST_VERSION 1.14.0) if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) set(CMAKE_CXX_EXTENSIONS OFF) From 843976e4f582ccb76cf87e0f128585324335779b Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Wed, 2 Aug 2023 09:44:39 -0700 Subject: [PATCH 39/81] Update documentation to refer to v1.14 PiperOrigin-RevId: 553172719 Change-Id: Ie09afa3788c8ed5c95913d8ca0b436f1df28241a --- README.md | 8 ++++---- googletest/README.md | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 443e02069..1bca4d1ff 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ GoogleTest now follows the We recommend [updating to the latest commit in the `main` branch as often as possible](https://github.com/abseil/abseil-cpp/blob/master/FAQ.md#what-is-live-at-head-and-how-do-i-do-it). We do publish occasional semantic versions, tagged with -`v${major}.${minor}.${patch}` (e.g. `v1.13.0`). +`v${major}.${minor}.${patch}` (e.g. `v1.14.0`). #### Documentation Updates @@ -17,12 +17,12 @@ Our documentation is now live on GitHub Pages at https://google.github.io/googletest/. We recommend browsing the documentation on GitHub Pages rather than directly in the repository. -#### Release 1.13.0 +#### Release 1.14.0 -[Release 1.13.0](https://github.com/google/googletest/releases/tag/v1.13.0) is +[Release 1.14.0](https://github.com/google/googletest/releases/tag/v1.14.0) is now available. -The 1.13.x branch requires at least C++14. +The 1.14.x branch requires at least C++14. #### Continuous Integration diff --git a/googletest/README.md b/googletest/README.md index 815f3fc02..9331fce3b 100644 --- a/googletest/README.md +++ b/googletest/README.md @@ -25,7 +25,7 @@ When building GoogleTest as a standalone project, the typical workflow starts with ``` -git clone https://github.com/google/googletest.git -b v1.13.0 +git clone https://github.com/google/googletest.git -b v1.14.0 cd googletest # Main directory of the cloned repository. mkdir build # Create a directory to hold the build output. cd build From 429432e341b3d68a8a9be079e739a587d41b48b8 Mon Sep 17 00:00:00 2001 From: Robert Shade Date: Wed, 2 Aug 2023 14:09:54 -0400 Subject: [PATCH 40/81] Avoid unreachable code warning --- googlemock/include/gmock/gmock-actions.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index bd9ba73ee..f20258bca 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -175,9 +175,15 @@ struct BuiltInDefaultValueGetter { static T Get() { Assert(false, __FILE__, __LINE__, "Default action undefined for the function return type."); - return internal::Invalid(); +#if defined(__GNUC__) || defined(__clang__) + __builtin_unreachable(); +#elif defined(_MSC_VER) + __assume(0); +#else + return Invalid(); // The above statement will never be reached, but is required in // order for this function to compile. +#endif } }; From 9ef5e8226919b56d6760b48258e706d819409994 Mon Sep 17 00:00:00 2001 From: Elliot Goodrich Date: Thu, 3 Aug 2023 21:22:23 +0100 Subject: [PATCH 41/81] Remove public includes of `` This commit removes `` from public GoogleTest header files. As `` is not a common included file, its content is unlikely to be included in translation units other than through GoogleTest includes. By reducing the number of include directives public headers in GoogleTest, this may reduce the time taken to compile tests as it would reduce the amount of work that the preprocessor and compiler front-end need to do. --- googletest/include/gtest/gtest.h | 9 ++++----- googletest/include/gtest/internal/gtest-internal.h | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 86777c854..894f1e0af 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -51,7 +51,6 @@ #include #include -#include #include #include #include @@ -1574,12 +1573,12 @@ AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression, } ::std::stringstream lhs_ss; - lhs_ss << std::setprecision(std::numeric_limits::digits10 + 2) - << lhs_value; + lhs_ss.precision(std::numeric_limits::digits10 + 2); + lhs_ss << lhs_value; ::std::stringstream rhs_ss; - rhs_ss << std::setprecision(std::numeric_limits::digits10 + 2) - << rhs_value; + rhs_ss.precision(std::numeric_limits::digits10 + 2); + rhs_ss << rhs_value; return EqFailure(lhs_expression, rhs_expression, StringStreamToString(&lhs_ss), StringStreamToString(&rhs_ss), diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 317894e73..e5cfa44c4 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -58,7 +58,6 @@ #include #include -#include #include #include #include From 6abc9e3d791ecac53361832bc4c14b6203daff4b Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Mon, 7 Aug 2023 12:44:13 -0700 Subject: [PATCH 42/81] Make references to `#include`s consistent across docs PiperOrigin-RevId: 554561504 Change-Id: Ia02ab6ac646bf6637d6f500a4aaedd14e0a04798 --- docs/reference/assertions.md | 2 +- docs/reference/mocking.md | 3 +-- docs/reference/testing.md | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/reference/assertions.md b/docs/reference/assertions.md index aa1dbc04b..492ff5ef6 100644 --- a/docs/reference/assertions.md +++ b/docs/reference/assertions.md @@ -1,7 +1,7 @@ # Assertions Reference This page lists the assertion macros provided by GoogleTest for verifying code -behavior. To use them, include the header `gtest/gtest.h`. +behavior. To use them, add `#include `. The majority of the macros listed below come as a pair with an `EXPECT_` variant and an `ASSERT_` variant. Upon failure, `EXPECT_` macros generate nonfatal diff --git a/docs/reference/mocking.md b/docs/reference/mocking.md index e414ffbd0..ab37ebf36 100644 --- a/docs/reference/mocking.md +++ b/docs/reference/mocking.md @@ -1,8 +1,7 @@ # Mocking Reference This page lists the facilities provided by GoogleTest for creating and working -with mock objects. To use them, include the header -`gmock/gmock.h`. +with mock objects. To use them, add `#include `. ## Macros {#macros} diff --git a/docs/reference/testing.md b/docs/reference/testing.md index 17225a682..ead66b362 100644 --- a/docs/reference/testing.md +++ b/docs/reference/testing.md @@ -3,7 +3,7 @@ This page lists the facilities provided by GoogleTest for writing test programs. -To use them, include the header `gtest/gtest.h`. +To use them, add `#include `. ## Macros From 22eb2de1efab758bebf8e0142fb0c4a999925b3b Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 7 Aug 2023 20:17:58 -0700 Subject: [PATCH 43/81] Fix GTestHelpTest.TestHelpFlag on FreeBSD The test supported a variety of BSDs, including kFreeBSD, but not FreeBSD. Move the BSD checks to a separate function and support checking for FreeBSD, in addition to kFreeBSD. Signed-off-by: Enji Cooper --- googletest/test/gtest_help_test.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/googletest/test/gtest_help_test.py b/googletest/test/gtest_help_test.py index 85a0c33c9..a4c7991d0 100755 --- a/googletest/test/gtest_help_test.py +++ b/googletest/test/gtest_help_test.py @@ -43,11 +43,21 @@ import sys from googletest.test import gtest_test_utils +FREEBSD = ('FreeBSD', 'GNU/kFreeBSD') +NETBSD = ('NetBSD', ) +OPENBSD = ('OpenBSD', ) + +def is_bsd_based_os() -> bool: + """Determine whether or not the OS is BSD-based.""" + if os.name != 'posix': + return False + + return os.uname()[0] in (FREEBSD + NETBSD + OPENBSD) + + IS_DARWIN = os.name == 'posix' and os.uname()[0] == 'Darwin' IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux' IS_GNUHURD = os.name == 'posix' and os.uname()[0] == 'GNU' -IS_GNUKFREEBSD = os.name == 'posix' and os.uname()[0] == 'GNU/kFreeBSD' -IS_OPENBSD = os.name == 'posix' and os.uname()[0] == 'OpenBSD' IS_WINDOWS = os.name == 'nt' PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_') @@ -136,7 +146,7 @@ class GTestHelpTest(gtest_test_utils.TestCase): self.assertTrue(HELP_REGEX.search(output), output) - if IS_DARWIN or IS_LINUX or IS_GNUHURD or IS_GNUKFREEBSD or IS_OPENBSD: + if IS_DARWIN or IS_LINUX or IS_GNUHURD or is_bsd_based_os(): self.assertIn(STREAM_RESULT_TO_FLAG, output) else: self.assertNotIn(STREAM_RESULT_TO_FLAG, output) From 77485ff0046136f89f14d5e7a51e98849dc00691 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Mon, 7 Aug 2023 21:36:44 -0700 Subject: [PATCH 44/81] Fix RETest/1.ImplicitConstructorWorks on non-ABSL platforms The last regular expression specified in the test is not technically POSIX compatible. Use `[[:alnum:]_]` instead of `\w+`; the latter is a Perl-compatible regular expression. Signed-off-by: Enji Cooper --- googletest/test/googletest-port-test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index 32a2a7b4d..e0793bad3 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -418,8 +418,8 @@ TYPED_TEST(RETest, ImplicitConstructorWorks) { const RE simple(TypeParam("hello")); EXPECT_STREQ("hello", simple.pattern()); - const RE normal(TypeParam(".*(\\w+)")); - EXPECT_STREQ(".*(\\w+)", normal.pattern()); + const RE normal(TypeParam(".*([[:alnum:]_]+)")); + EXPECT_STREQ(".*([[:alnum:]_]+)", normal.pattern()); } // Tests that RE's constructors reject invalid regular expressions. From 7e33b6a1c497ced1e98fc60175aeb4678419281c Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 10 Aug 2023 11:26:23 -0700 Subject: [PATCH 45/81] Specify SetUpTestSuite is required to be public. PiperOrigin-RevId: 555578256 Change-Id: I9366fc99ae953c29e468fcddb4be203c9c05661b --- docs/advanced.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/advanced.md b/docs/advanced.md index 3871db13b..344d5418b 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -899,10 +899,10 @@ also supports per-test-suite set-up/tear-down. To use it: variables to hold the shared resources. 2. Outside your test fixture class (typically just below it), define those member variables, optionally giving them initial values. -3. In the same test fixture class, define a `static void SetUpTestSuite()` - function (remember not to spell it as **`SetupTestSuite`** with a small - `u`!) to set up the shared resources and a `static void TearDownTestSuite()` - function to tear them down. +3. In the same test fixture class, define a public member function `static void + SetUpTestSuite()` (remember not to spell it as **`SetupTestSuite`** with a + small `u`!) to set up the shared resources and a `static void + TearDownTestSuite()` function to tear them down. That's it! GoogleTest automatically calls `SetUpTestSuite()` before running the *first test* in the `FooTest` test suite (i.e. before creating the first From 619601c5e26eb0cc763082e026b130a35e63deba Mon Sep 17 00:00:00 2001 From: sthd Date: Fri, 11 Aug 2023 11:01:14 +0300 Subject: [PATCH 46/81] Changed 3 public links from http to https --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1bca4d1ff..111801eab 100644 --- a/README.md +++ b/README.md @@ -100,12 +100,12 @@ tools. In addition to many internal projects at Google, GoogleTest is also used by the following notable projects: -* The [Chromium projects](http://www.chromium.org/) (behind the Chrome browser +* The [Chromium projects](https://www.chromium.org/) (behind the Chrome browser and Chrome OS). -* The [LLVM](http://llvm.org/) compiler. +* The [LLVM](https://llvm.org/) compiler. * [Protocol Buffers](https://github.com/google/protobuf), Google's data interchange format. -* The [OpenCV](http://opencv.org/) computer vision library. +* The [OpenCV](https://opencv.org/) computer vision library. ## Related Open Source Projects From 622ee5cf2998a6b2c2f24a95069e2748b26c4a2c Mon Sep 17 00:00:00 2001 From: sthd Date: Fri, 11 Aug 2023 11:06:25 +0300 Subject: [PATCH 47/81] Changed 2 public links from http to https --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8bed14b26..93d8b2fd1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,9 +47,9 @@ PR is acceptable as an alternative. ## The Google Test and Google Mock Communities The Google Test community exists primarily through the -[discussion group](http://groups.google.com/group/googletestframework) and the +[discussion group](https://groups.google.com/group/googletestframework) and the GitHub repository. Likewise, the Google Mock community exists primarily through -their own [discussion group](http://groups.google.com/group/googlemock). You are +their own [discussion group](https://groups.google.com/group/googlemock). You are definitely encouraged to contribute to the discussion and you can also help us to keep the effectiveness of the group high by following and promoting the guidelines listed here. From 5b5ef299500701c9d0df782c7432219f8d97f8cc Mon Sep 17 00:00:00 2001 From: sthd Date: Fri, 11 Aug 2023 11:21:47 +0300 Subject: [PATCH 48/81] Changed 3 public links from http to https --- docs/faq.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index 192809729..90c249781 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -607,7 +607,7 @@ defined such that we can print a value of `FooType`. In addition, if `FooType` is declared in a name space, the `<<` operator also needs to be defined in the *same* name space. See -[Tip of the Week #49](http://abseil.io/tips/49) for details. +[Tip of the Week #49](https://abseil.io/tips/49) for details. ## How do I suppress the memory leak messages on Windows? @@ -628,10 +628,10 @@ mistake in production. Such cleverness also leads to advise against the practice, and GoogleTest doesn't provide a way to do it. In general, the recommended way to cause the code to behave differently under -test is [Dependency Injection](http://en.wikipedia.org/wiki/Dependency_injection). You can inject +test is [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection). You can inject different functionality from the test and from the production code. Since your production code doesn't link in the for-test logic at all (the -[`testonly`](http://docs.bazel.build/versions/master/be/common-definitions.html#common.testonly) attribute for BUILD targets helps to ensure +[`testonly`](https://docs.bazel.build/versions/master/be/common-definitions.html#common.testonly) attribute for BUILD targets helps to ensure that), there is no danger in accidentally running it. However, if you *really*, *really*, *really* have no choice, and if you follow From 8ca57f194af05c0f5211e8d5d350c871b0551612 Mon Sep 17 00:00:00 2001 From: sthd Date: Fri, 11 Aug 2023 11:26:59 +0300 Subject: [PATCH 49/81] Changed 2 public links from http to https --- docs/advanced.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/advanced.md b/docs/advanced.md index 344d5418b..2a7c48275 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -508,9 +508,9 @@ TEST_F(FooDeathTest, DoesThat) { When built with Bazel and using Abseil, GoogleTest uses the [RE2](https://github.com/google/re2/wiki/Syntax) syntax. Otherwise, for POSIX systems (Linux, Cygwin, Mac), GoogleTest uses the -[POSIX extended regular expression](http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html#tag_09_04) +[POSIX extended regular expression](https://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html#tag_09_04) syntax. To learn about POSIX syntax, you may want to read this -[Wikipedia entry](http://en.wikipedia.org/wiki/Regular_expression#POSIX_extended). +[Wikipedia entry](https://en.wikipedia.org/wiki/Regular_expression#POSIX_extended). On Windows, GoogleTest uses its own simple regular expression implementation. It lacks many features. For example, we don't support union (`"x|y"`), grouping From d76e9e0dd93a9921e4054c71f23e7c8fa8da864d Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Tue, 15 Aug 2023 06:42:01 -0700 Subject: [PATCH 50/81] gtest_help_test: Delete obsolete helper `TestUnknownFlagWithAbseil` PiperOrigin-RevId: 557116814 Change-Id: I91e06b0d6001952366c50201b67491475a1f98af --- googletest/test/gtest_help_test.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/googletest/test/gtest_help_test.py b/googletest/test/gtest_help_test.py index 85a0c33c9..a76f220ca 100755 --- a/googletest/test/gtest_help_test.py +++ b/googletest/test/gtest_help_test.py @@ -146,19 +146,6 @@ class GTestHelpTest(gtest_test_utils.TestCase): else: self.assertNotIn(DEATH_TEST_STYLE_FLAG, output) - def TestUnknownFlagWithAbseil(self, flag): - """Verifies correct behavior when an unknown flag is specified. - - The right message must be printed and the tests must - skipped when the given flag is specified. - - Args: - flag: A flag to pass to the binary or None. - """ - exit_code, output = RunWithFlag(flag) - self.assertEqual(1, exit_code) - self.assertIn('ERROR: Unknown command line flag', output) - def TestNonHelpFlag(self, flag): """Verifies correct behavior when no help flag is specified. From 6513d0272d8bd2062cf4549fe2b0adb1fc862486 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Tue, 15 Aug 2023 07:11:18 -0700 Subject: [PATCH 51/81] gtest_help_test: Inline test helper functions `TestNonHelpFlag` is only a few asserts with no logic, which is easier to read in line, and helper `TestHelpFlag` is used in a single test case. PiperOrigin-RevId: 557122793 Change-Id: I7367424abfbb883c10c260fae066a2071e5dfa0e --- googletest/test/gtest_help_test.py | 32 ++++++++---------------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/googletest/test/gtest_help_test.py b/googletest/test/gtest_help_test.py index a76f220ca..3f7849605 100755 --- a/googletest/test/gtest_help_test.py +++ b/googletest/test/gtest_help_test.py @@ -116,17 +116,14 @@ def RunWithFlag(flag): class GTestHelpTest(gtest_test_utils.TestCase): """Tests the --help flag and its equivalent forms.""" - def TestHelpFlag(self, flag): + def testPrintsHelpWithFullFlag(self): """Verifies correct behavior when help flag is specified. The right message must be printed and the tests must skipped when the given flag is specified. - - Args: - flag: A flag to pass to the binary or None. """ - exit_code, output = RunWithFlag(flag) + exit_code, output = RunWithFlag('--help') if HAS_ABSL_FLAGS: # The Abseil flags library prints the ProgramUsageMessage() with # --help and returns 1. @@ -146,23 +143,6 @@ class GTestHelpTest(gtest_test_utils.TestCase): else: self.assertNotIn(DEATH_TEST_STYLE_FLAG, output) - def TestNonHelpFlag(self, flag): - """Verifies correct behavior when no help flag is specified. - - Verifies that when no help flag is specified, the tests are run - and the help message is not printed. - - Args: - flag: A flag to pass to the binary or None. - """ - - exit_code, output = RunWithFlag(flag) - self.assertNotEqual(exit_code, 0) - self.assertFalse(HELP_REGEX.search(output), output) - - def testPrintsHelpWithFullFlag(self): - self.TestHelpFlag('--help') - def testRunsTestsWithoutHelpFlag(self): """Verifies correct behavior when no help flag is specified. @@ -170,7 +150,9 @@ class GTestHelpTest(gtest_test_utils.TestCase): and the help message is not printed. """ - self.TestNonHelpFlag(None) + exit_code, output = RunWithFlag(None) + self.assertNotEqual(exit_code, 0) + self.assertFalse(HELP_REGEX.search(output), output) def testRunsTestsWithGtestInternalFlag(self): """Verifies correct behavior when internal testing flag is specified. @@ -179,7 +161,9 @@ class GTestHelpTest(gtest_test_utils.TestCase): a flag starting with Google Test prefix and 'internal_' is supplied. """ - self.TestNonHelpFlag(INTERNAL_FLAG_FOR_TESTING) + exit_code, output = RunWithFlag(INTERNAL_FLAG_FOR_TESTING) + self.assertNotEqual(exit_code, 0) + self.assertFalse(HELP_REGEX.search(output), output) if __name__ == '__main__': From dd9a9569041c1551613d116ff0d092b356c836b1 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Tue, 15 Aug 2023 07:59:51 -0700 Subject: [PATCH 52/81] gtest_help_test: Make method names `snake_case`, conforming with [the style guide](https://google.github.io/styleguide/pyguide#316-naming) PiperOrigin-RevId: 557133618 Change-Id: I27202ee91ee81b3d2e4c28102190d2bde8efba05 --- googletest/test/gtest_help_test.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/googletest/test/gtest_help_test.py b/googletest/test/gtest_help_test.py index 3f7849605..b3b740d96 100755 --- a/googletest/test/gtest_help_test.py +++ b/googletest/test/gtest_help_test.py @@ -96,7 +96,7 @@ HELP_REGEX = re.compile( ) -def RunWithFlag(flag): +def run_with_flag(flag): """Runs gtest_help_test_ with the given flag. Returns: @@ -116,14 +116,14 @@ def RunWithFlag(flag): class GTestHelpTest(gtest_test_utils.TestCase): """Tests the --help flag and its equivalent forms.""" - def testPrintsHelpWithFullFlag(self): + def test_prints_help_with_full_flag(self): """Verifies correct behavior when help flag is specified. The right message must be printed and the tests must skipped when the given flag is specified. """ - exit_code, output = RunWithFlag('--help') + exit_code, output = run_with_flag('--help') if HAS_ABSL_FLAGS: # The Abseil flags library prints the ProgramUsageMessage() with # --help and returns 1. @@ -143,25 +143,25 @@ class GTestHelpTest(gtest_test_utils.TestCase): else: self.assertNotIn(DEATH_TEST_STYLE_FLAG, output) - def testRunsTestsWithoutHelpFlag(self): + def test_runs_tests_without_help_flag(self): """Verifies correct behavior when no help flag is specified. Verifies that when no help flag is specified, the tests are run and the help message is not printed. """ - exit_code, output = RunWithFlag(None) + exit_code, output = run_with_flag(None) self.assertNotEqual(exit_code, 0) self.assertFalse(HELP_REGEX.search(output), output) - def testRunsTestsWithGtestInternalFlag(self): + def test_runs_tests_with_gtest_internal_flag(self): """Verifies correct behavior when internal testing flag is specified. Verifies that the tests are run and no help message is printed when a flag starting with Google Test prefix and 'internal_' is supplied. """ - exit_code, output = RunWithFlag(INTERNAL_FLAG_FOR_TESTING) + exit_code, output = run_with_flag(INTERNAL_FLAG_FOR_TESTING) self.assertNotEqual(exit_code, 0) self.assertFalse(HELP_REGEX.search(output), output) From e24cced08d658222c903b36c713d2265e3e83345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Gawro=C5=84ski?= Date: Wed, 26 Jul 2023 00:58:06 +0200 Subject: [PATCH 53/81] googletest: ansi color fix Adds prevents from returning nullptr by choosing default color. Issue: #4321 --- googletest/src/gtest.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 30a5cc3f8..e56ee1a17 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -3228,7 +3228,8 @@ static const char* GetAnsiColorCode(GTestColor color) { case GTestColor::kYellow: return "3"; default: - return nullptr; + assert(false); + return "9" ; } } From f42da0e4431a14260946323bff4d856f20973b2c Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 17 Aug 2023 12:55:43 -0700 Subject: [PATCH 54/81] Improve error message for invalid parameterized test names. PiperOrigin-RevId: 557910190 Change-Id: Ia965a6c96e4cc5997d8af2611abc62c42e81653e --- googletest/include/gtest/internal/gtest-param-util.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h index 6a81c37fa..dd39e98a1 100644 --- a/googletest/include/gtest/internal/gtest-param-util.h +++ b/googletest/include/gtest/internal/gtest-param-util.h @@ -584,7 +584,9 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { GTEST_CHECK_(IsValidParamName(param_name)) << "Parameterized test name '" << param_name - << "' is invalid, in " << file << " line " << line << std::endl; + << "' is invalid (contains spaces, dashes, underscores, or " + "non-alphanumeric characters), in " + << file << " line " << line << "" << std::endl; GTEST_CHECK_(test_param_names.count(param_name) == 0) << "Duplicate parameterized test name '" << param_name << "', in " From 14d05f4708c97d1efc0db917dd32ef2f2013686a Mon Sep 17 00:00:00 2001 From: Tanzinul Islam Date: Fri, 18 Aug 2023 19:44:48 +0100 Subject: [PATCH 55/81] Prefer $TMPDIR to /data/local/tmp on Android Newer devices can have the latter location read-only. (I observed this with Termux on a non-rooted Pixel 6.) --- googletest/src/gtest-port.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 2aaf2bcc2..589ace5e7 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -1064,7 +1064,13 @@ class CapturedStream { // The location /data/local/tmp is directly accessible from native code. // '/sdcard' and other variants cannot be relied on, as they are not // guaranteed to be mounted, or may have a delay in mounting. - name_template = "/data/local/tmp/"; + // + // However, prefer using the TMPDIR environment variable if set, as newer + // devices may have /data/local/tmp read-only. + if (auto tmpdir = ::getenv("TMPDIR")) + name_template.assign(tmpdir) += '/'; + else + name_template = "/data/local/tmp/"; #elif defined(GTEST_OS_IOS) char user_temp_dir[PATH_MAX + 1]; From 722daa3da6e2864afdb6fe5b2bf03a5989c01a5c Mon Sep 17 00:00:00 2001 From: Elior Schneider Date: Sun, 20 Aug 2023 09:38:57 +0300 Subject: [PATCH 56/81] Update advanced.md http to https --- docs/advanced.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced.md b/docs/advanced.md index 2a7c48275..0e1f812b9 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -2171,7 +2171,7 @@ The report format conforms to the following JSON Schema: ```json { - "$schema": "http://json-schema.org/schema#", + "$schema": "https://json-schema.org/schema#", "type": "object", "definitions": { "TestCase": { From 762d3a7f6681ec2f0882f79ce89da11589cac91b Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 21 Aug 2023 08:47:04 -0700 Subject: [PATCH 57/81] Clean up typos: Exhaused => Exhausted PiperOrigin-RevId: 558801066 Change-Id: Ia225d12014748db87639414f4c8c28a0d0e9e489 --- googlemock/test/gmock-spec-builders_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 221de2d20..aaf88d74e 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -906,7 +906,7 @@ TEST(ExpectCallTest, TakesDefaultActionWhenWillListIsExhausted) { " - returning default value.")); } -TEST(FunctionMockerMessageTest, ReportsExpectCallLocationForExhausedActions) { +TEST(FunctionMockerMessageTest, ReportsExpectCallLocationForExhaustedActions) { MockB b; std::string expect_call_location = FormatFileLocation(__FILE__, __LINE__ + 1); EXPECT_CALL(b, DoB()).Times(AnyNumber()).WillOnce(Return(1)); From 61332bd7e8810edd7ff9febfa71ece2e25b18df0 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Mon, 21 Aug 2023 09:49:59 -0700 Subject: [PATCH 58/81] CI: Update the Linux hybrid-latest docker container used for testing The following are the major updates * LLVM 17 branch (https://github.com/llvm/llvm-project b744f4c99cf91155c74a3c92db6f1335232ff3d) * GCC 13.2 * CMake 3.27.1 * Bazel 6.2.1 PiperOrigin-RevId: 558818264 Change-Id: Ib08d8331e2a8b2d68a702670451beaaac5d266f4 --- ci/linux-presubmit.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/linux-presubmit.sh b/ci/linux-presubmit.sh index 6bac88787..a1caa2720 100644 --- a/ci/linux-presubmit.sh +++ b/ci/linux-presubmit.sh @@ -31,7 +31,7 @@ set -euox pipefail -readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20230217" +readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20230816" readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20230120" if [[ -z ${GTEST_ROOT:-} ]]; then From c374da15c57ba6056fedd34c68442f3e2a20c1d7 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Tue, 22 Aug 2023 09:20:18 -0700 Subject: [PATCH 59/81] googletest: Replace http with https in links to docs This is a prerequisite for #4341 PiperOrigin-RevId: 559132807 Change-Id: Iadc961913e0ff107c5333dae17be5f8638663836 --- docs/faq.md | 6 +++--- docs/gmock_for_dummies.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index 192809729..90c249781 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -607,7 +607,7 @@ defined such that we can print a value of `FooType`. In addition, if `FooType` is declared in a name space, the `<<` operator also needs to be defined in the *same* name space. See -[Tip of the Week #49](http://abseil.io/tips/49) for details. +[Tip of the Week #49](https://abseil.io/tips/49) for details. ## How do I suppress the memory leak messages on Windows? @@ -628,10 +628,10 @@ mistake in production. Such cleverness also leads to advise against the practice, and GoogleTest doesn't provide a way to do it. In general, the recommended way to cause the code to behave differently under -test is [Dependency Injection](http://en.wikipedia.org/wiki/Dependency_injection). You can inject +test is [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection). You can inject different functionality from the test and from the production code. Since your production code doesn't link in the for-test logic at all (the -[`testonly`](http://docs.bazel.build/versions/master/be/common-definitions.html#common.testonly) attribute for BUILD targets helps to ensure +[`testonly`](https://docs.bazel.build/versions/master/be/common-definitions.html#common.testonly) attribute for BUILD targets helps to ensure that), there is no danger in accidentally running it. However, if you *really*, *really*, *really* have no choice, and if you follow diff --git a/docs/gmock_for_dummies.md b/docs/gmock_for_dummies.md index 43f907aaa..06c87256c 100644 --- a/docs/gmock_for_dummies.md +++ b/docs/gmock_for_dummies.md @@ -97,7 +97,7 @@ tests like this are expensive to run and fragile (What if you just upgraded to a shiny new graphics card that has better anti-aliasing? Suddenly you have to update all your golden images.). It would be too painful if all your tests are like this. Fortunately, you learned about -[Dependency Injection](http://en.wikipedia.org/wiki/Dependency_injection) and know the right thing +[Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) and know the right thing to do: instead of having your application talk to the system API directly, wrap the API in an interface (say, `Turtle`) and code to that interface: From f0eae4b3995b77cfbb49cc91f98da5d1f3c4fe05 Mon Sep 17 00:00:00 2001 From: sthd Date: Tue, 22 Aug 2023 20:58:34 +0300 Subject: [PATCH 60/81] changed http to https --- docs/gmock_for_dummies.md | 2 +- docs/primer.md | 8 ++++---- googlemock/README.md | 8 ++++---- googlemock/src/gmock-matchers.cc | 2 +- googletest/README.md | 2 +- googletest/cmake/internal_utils.cmake | 2 +- googletest/include/gtest/internal/gtest-internal.h | 10 +++++----- googletest/include/gtest/internal/gtest-port.h | 2 +- googletest/src/gtest-death-test.cc | 2 +- googletest/src/gtest-internal-inl.h | 2 +- googletest/src/gtest.cc | 2 +- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/gmock_for_dummies.md b/docs/gmock_for_dummies.md index 06c87256c..9f24dcae5 100644 --- a/docs/gmock_for_dummies.md +++ b/docs/gmock_for_dummies.md @@ -90,7 +90,7 @@ gMock is bundled with googletest. ## A Case for Mock Turtles Let's look at an example. Suppose you are developing a graphics program that -relies on a [LOGO](http://en.wikipedia.org/wiki/Logo_programming_language)-like +relies on a [LOGO](https://en.wikipedia.org/wiki/Logo_programming_language)-like API for drawing. How would you test that it does the right thing? Well, you can run it and compare the screen with a golden screen snapshot, but let's admit it: tests like this are expensive to run and fragile (What if you just upgraded to a diff --git a/docs/primer.md b/docs/primer.md index f2a97a726..4901e1ab0 100644 --- a/docs/primer.md +++ b/docs/primer.md @@ -50,7 +50,7 @@ terms *Test*, *Test Case* and *Test Suite*, so beware of misunderstanding these. Historically, GoogleTest started to use the term *Test Case* for grouping related tests, whereas current publications, including International Software -Testing Qualifications Board ([ISTQB](http://www.istqb.org/)) materials and +Testing Qualifications Board ([ISTQB](https://www.istqb.org/)) materials and various textbooks on software quality, use the term *[Test Suite][istqb test suite]* for this. @@ -68,13 +68,13 @@ deprecated and refactored away. So please be aware of the different definitions of the terms: -Meaning | GoogleTest Term | [ISTQB](http://www.istqb.org/) Term +Meaning | GoogleTest Term | [ISTQB](https://www.istqb.org/) Term :----------------------------------------------------------------------------------- | :---------------------- | :---------------------------------- Exercise a particular program path with specific input values and verify the results | [TEST()](#simple-tests) | [Test Case][istqb test case] -[istqb test case]: http://glossary.istqb.org/en/search/test%20case -[istqb test suite]: http://glossary.istqb.org/en/search/test%20suite +[istqb test case]: https://glossary.istqb.org/en/search/test%20case +[istqb test suite]: https://glossary.istqb.org/en/search/test%20suite ## Basic Concepts diff --git a/googlemock/README.md b/googlemock/README.md index 7da60655d..9a6dea300 100644 --- a/googlemock/README.md +++ b/googlemock/README.md @@ -7,9 +7,9 @@ derive better designs of your system and write better tests. It is inspired by: -* [jMock](http://www.jmock.org/) -* [EasyMock](http://www.easymock.org/) -* [Hamcrest](http://code.google.com/p/hamcrest/) +* [jMock](https://www.jmock.org/) +* [EasyMock](https://www.easymock.org/) +* [Hamcrest](https://code.google.com/p/hamcrest/) It is designed with C++'s specifics in mind. @@ -36,5 +36,5 @@ Details and examples can be found here: * [gMock Cheat Sheet](https://google.github.io/googletest/gmock_cheat_sheet.html) GoogleMock is a part of -[GoogleTest C++ testing framework](http://github.com/google/googletest/) and a +[GoogleTest C++ testing framework](https://github.com/google/googletest/) and a subject to the same requirements. diff --git a/googlemock/src/gmock-matchers.cc b/googlemock/src/gmock-matchers.cc index 07bba4f01..81a5b7ea5 100644 --- a/googlemock/src/gmock-matchers.cc +++ b/googlemock/src/gmock-matchers.cc @@ -120,7 +120,7 @@ GTEST_API_ std::string FormatMatcherDescription( // [1] Cormen, et al (2001). "Section 26.2: The Ford-Fulkerson method". // "Introduction to Algorithms (Second ed.)", pp. 651-664. // [2] "Ford-Fulkerson algorithm", Wikipedia, -// 'http://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm' +// 'https://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm' class MaxBipartiteMatchState { public: explicit MaxBipartiteMatchState(const MatchMatrix& graph) diff --git a/googletest/README.md b/googletest/README.md index 9331fce3b..140a057ae 100644 --- a/googletest/README.md +++ b/googletest/README.md @@ -12,7 +12,7 @@ GoogleTest comes with a CMake build script ([CMakeLists.txt](https://github.com/google/googletest/blob/main/CMakeLists.txt)) that can be used on a wide range of platforms ("C" stands for cross-platform.). If you don't have CMake installed already, you can download it for free from -. +. CMake works by generating native makefiles or build projects that can be used in the compiler environment of your choice. You can either build GoogleTest as a diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 64fa340fd..d4f67f43a 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -80,7 +80,7 @@ macro(config_compiler_and_linker) set(cxx_no_exception_flags "-EHs-c- -D_HAS_EXCEPTIONS=0") set(cxx_no_rtti_flags "-GR-") # Suppress "unreachable code" warning - # http://stackoverflow.com/questions/3232669 explains the issue. + # https://stackoverflow.com/questions/3232669 explains the issue. set(cxx_base_flags "${cxx_base_flags} -wd4702") # Ensure MSVC treats source files as UTF-8 encoded. if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 97a983393..4f077fcfb 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -78,7 +78,7 @@ // // will result in the token foo__LINE__, instead of foo followed by // the current line number. For more details, see -// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6 +// https://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6 #define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar) #define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo##bar @@ -169,7 +169,7 @@ namespace edit_distance { // All edits cost the same, with replace having lower priority than // add/remove. // Simple implementation of the Wagner-Fischer algorithm. -// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm +// See https://en.wikipedia.org/wiki/Wagner-Fischer_algorithm enum EditType { kMatch, kAdd, kRemove, kReplace }; GTEST_API_ std::vector CalculateOptimalEdits( const std::vector& left, const std::vector& right); @@ -236,7 +236,7 @@ GTEST_API_ std::string GetBoolAssertionFailureMessage( // For double, there are 11 exponent bits and 52 fraction bits. // // More details can be found at -// http://en.wikipedia.org/wiki/IEEE_floating-point_standard. +// https://en.wikipedia.org/wiki/IEEE_floating-point_standard. // // Template parameter: // @@ -281,7 +281,7 @@ class FloatingPoint { // bits. Therefore, 4 should be enough for ordinary use. // // See the following article for more details on ULP: - // http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ + // https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ static const uint32_t kMaxUlps = 4; // Constructs a FloatingPoint from a raw floating-point number. @@ -362,7 +362,7 @@ class FloatingPoint { // N - 1 (the biggest number representable using // sign-and-magnitude) is represented by 2N - 1. // - // Read http://en.wikipedia.org/wiki/Signed_number_representations + // Read https://en.wikipedia.org/wiki/Signed_number_representations // for more details on signed number representations. static Bits SignAndMagnitudeToBiased(const Bits& sam) { if (kSignBitMask & sam) { diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index b887e24ed..b5570b8bc 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -609,7 +609,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // Determines whether clone(2) is supported. // Usually it will only be available on Linux, excluding // Linux on the Itanium architecture. -// Also see http://linux.die.net/man/2/clone. +// Also see https://linux.die.net/man/2/clone. #ifndef GTEST_HAS_CLONE // The user didn't tell us, so we need to figure it out. diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index 0eb6e38b2..8417a300f 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -783,7 +783,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() { StreamableToString(static_cast(::GetCurrentProcessId())) + // size_t has the same width as pointers on both 32-bit and 64-bit // Windows platforms. - // See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx. + // See https://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx. "|" + StreamableToString(reinterpret_cast(write_handle)) + "|" + StreamableToString(reinterpret_cast(event_handle_.Get())); diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index 5b7fcbd06..4799a1e7b 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -312,7 +312,7 @@ void ShuffleRange(internal::Random* random, int begin, int end, << begin << ", " << size << "]."; // Fisher-Yates shuffle, from - // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle + // https://en.wikipedia.org/wiki/Fisher-Yates_shuffle for (int range_width = end - begin; range_width >= 2; range_width--) { const int last_in_range = begin + range_width - 1; const int selected = diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 66a315e51..62dfef664 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -879,7 +879,7 @@ int UnitTestOptions::GTestProcessSEH(DWORD seh_code, const char* location) { // apparently). // // SEH exception code for C++ exceptions. - // (see http://support.microsoft.com/kb/185294 for more information). + // (see https://support.microsoft.com/kb/185294 for more information). const DWORD kCxxExceptionCode = 0xe06d7363; if (!GTEST_FLAG_GET(catch_exceptions) || seh_code == kCxxExceptionCode || From 8a6feabf04bec8fb125e0df0ad1195c42350725f Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Fri, 25 Aug 2023 07:45:33 -0700 Subject: [PATCH 61/81] googletest: Add universal printer for `std::span` Fixes #4318 PiperOrigin-RevId: 560089120 Change-Id: I9d0d098140033520266747a1689e953ee8307c47 --- googletest/include/gtest/gtest-printers.h | 27 +++++++++++++++++-- .../include/gtest/internal/gtest-port.h | 12 +++++++++ googletest/test/googletest-printers-test.cc | 16 +++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index d1766e640..9ccbff7da 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -122,6 +122,10 @@ #include "gtest/internal/gtest-internal.h" #include "gtest/internal/gtest-port.h" +#if GTEST_INTERNAL_HAS_STD_SPAN +#include // NOLINT +#endif // GTEST_INTERNAL_HAS_STD_SPAN + namespace testing { // Definitions in the internal* namespaces are subject to change without notice. @@ -131,13 +135,32 @@ namespace internal { template void UniversalPrint(const T& value, ::std::ostream* os); +template +struct IsStdSpan { + static constexpr bool value = false; +}; + +#if GTEST_INTERNAL_HAS_STD_SPAN +template +struct IsStdSpan> { + static constexpr bool value = true; +}; +#endif // GTEST_INTERNAL_HAS_STD_SPAN + // Used to print an STL-style container when the user doesn't define // a PrintTo() for it. +// +// NOTE: Since std::span does not have const_iterator until C++23, it would +// fail IsContainerTest before C++23. However, IsContainerTest only uses +// the presence of const_iterator to avoid treating iterators as containers +// because of iterator::iterator. Which means std::span satisfies the *intended* +// condition of IsContainerTest. struct ContainerPrinter { template (0)) == sizeof(IsContainer)) && - !IsRecursiveContainer::value>::type> + ((sizeof(IsContainerTest(0)) == sizeof(IsContainer)) && + !IsRecursiveContainer::value) || + IsStdSpan::value>::type> static void PrintValue(const T& container, std::ostream* os) { const size_t kMaxCount = 32; // The maximum number of elements to print. *os << '{'; diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index b5570b8bc..35544a08a 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -208,6 +208,8 @@ // or // UniversalPrinter // specializations. Always defined to 0 or 1. +// GTEST_INTERNAL_HAS_STD_SPAN - for enabling UniversalPrinter +// specializations. Always defined to 0 or 1 // GTEST_INTERNAL_HAS_STRING_VIEW - for enabling Matcher or // Matcher // specializations. Always defined to 0 or 1. @@ -2407,6 +2409,16 @@ inline ::std::nullopt_t Nullopt() { return ::std::nullopt; } #define GTEST_INTERNAL_HAS_OPTIONAL 0 #endif +#ifdef __has_include +#if __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L +#define GTEST_INTERNAL_HAS_STD_SPAN 1 +#endif // __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L +#endif // __has_include + +#ifndef GTEST_INTERNAL_HAS_STD_SPAN +#define GTEST_INTERNAL_HAS_STD_SPAN 0 +#endif + #ifdef GTEST_HAS_ABSL // Always use absl::string_view for Matcher<> specializations if googletest // is built with absl support. diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index bee0ca4ab..d5061bef2 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -54,11 +54,16 @@ #include "gtest/gtest-printers.h" #include "gtest/gtest.h" +#include "gtest/internal/gtest-port.h" #ifdef GTEST_HAS_ABSL #include "absl/strings/str_format.h" #endif +#if GTEST_INTERNAL_HAS_STD_SPAN +#include // NOLINT +#endif // GTEST_INTERNAL_HAS_STD_SPAN + // Some user-defined types for testing the universal value printer. // An anonymous enum type. @@ -1179,6 +1184,17 @@ TEST(PrintStlContainerTest, Vector) { EXPECT_EQ("{ 1, 2 }", Print(v)); } +TEST(PrintStlContainerTest, StdSpan) { +#if GTEST_INTERNAL_HAS_STD_SPAN + int a[] = {3, 6, 5}; + std::span s = a; + + EXPECT_EQ("{ 3, 6, 5 }", Print(s)); +#else + GTEST_SKIP() << "Does not have std::span."; +#endif // GTEST_INTERNAL_HAS_STD_SPAN +} + TEST(PrintStlContainerTest, LongSequence) { const int a[100] = {1, 2, 3}; const vector v(a, a + 100); From edf9b4964d28f0f18552ff39c8f182b7903e19e3 Mon Sep 17 00:00:00 2001 From: Tanzinul Islam Date: Sat, 26 Aug 2023 08:53:45 +0100 Subject: [PATCH 62/81] Reuse TempDir() function --- googletest/src/gtest-port.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 589ace5e7..628ab3dbf 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -1067,10 +1067,7 @@ class CapturedStream { // // However, prefer using the TMPDIR environment variable if set, as newer // devices may have /data/local/tmp read-only. - if (auto tmpdir = ::getenv("TMPDIR")) - name_template.assign(tmpdir) += '/'; - else - name_template = "/data/local/tmp/"; + name_template = TempDir(); #elif defined(GTEST_OS_IOS) char user_temp_dir[PATH_MAX + 1]; From b86bf840d1d562d12efd4e0790ce14455f5fa271 Mon Sep 17 00:00:00 2001 From: Tanzinul Islam Date: Sun, 3 Sep 2023 15:39:19 +0100 Subject: [PATCH 63/81] Count threads after thread-creation while still holding mutex lock The `Mutex` is locked with the `MutexLock` before spawning the thread, so that the thread is prevented from completing (by being blocked on `Mutex`) before the new thread count is obtained. However, the existing bug (introduced in 22e6055) releases `Mutex` before obtaining the new thread count, which allows the thread to run to completion in the meantime. Also, since the `(thread_count_after_create != starting_count + 1)` condition (line 328) skips the remainder of the `for`-loop body on every iteration, `thread_count_after_join` stays uninitialized. I believe this is why [this test failed][1] on the macOS CI with this trace: ``` [----------] 1 test from GetThreadCountTest [ RUN ] GetThreadCountTest.ReturnsCorrectValue googletest/test/googletest-port-test.cc:350: Failure Expected equality of these values: thread_count_after_create Which is: 1 starting_count + 1 Which is: 2 googletest/test/googletest-port-test.cc:351: Failure Expected equality of these values: thread_count_after_join Which is: 140493185949400 starting_count Which is: 1 [ FAILED ] GetThreadCountTest.ReturnsCorrectValue (2 ms) [----------] 1 test from GetThreadCountTest (2 ms total) ``` [1]: https://github.com/google/googletest/actions/runs/6064919420/job/16453860690?pr=3049 --- googletest/test/googletest-port-test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index e0793bad3..8d210260f 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -296,7 +296,7 @@ void* ThreadFunc(void* data) { TEST(GetThreadCountTest, ReturnsCorrectValue) { size_t starting_count; size_t thread_count_after_create; - size_t thread_count_after_join; + size_t thread_count_after_join = 0; // We can't guarantee that no other thread was created or destroyed between // any two calls to GetThreadCount(). We make multiple attempts, hoping that @@ -316,9 +316,9 @@ TEST(GetThreadCountTest, ReturnsCorrectValue) { const int status = pthread_create(&thread_id, &attr, &ThreadFunc, &mutex); ASSERT_EQ(0, pthread_attr_destroy(&attr)); ASSERT_EQ(0, status); - } - thread_count_after_create = GetThreadCount(); + thread_count_after_create = GetThreadCount(); + } void* dummy; ASSERT_EQ(0, pthread_join(thread_id, &dummy)); From 728ec52d2167f61fad5672c3073d72d49a4482df Mon Sep 17 00:00:00 2001 From: Michael Hirshleifer Date: Thu, 14 Sep 2023 07:12:44 -0700 Subject: [PATCH 64/81] Remove Googletest FAQ entry for obsolete `ProtocolMessageEquals` and `ProtocolMessageEquiv` * These long-dead variants of the proto matchers don't exist in the current version of Googletest. * No evidence of external usage: [the only external references I see](https://www.google.com/search?q=%22protocolmessageequals%22+OR+%22protocolmessageequals%22) are copies of this guide. Possibly they were already removed by the time Googletest was publicly released. PiperOrigin-RevId: 565358401 Change-Id: I61379b7333fa8ee19cd5520caedf2c539f54c2d7 --- docs/faq.md | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index 90c249781..c942b5dcc 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -128,27 +128,6 @@ both approaches a try. Practice is a much better way to grasp the subtle differences between the two tools. Once you have some concrete experience, you can much more easily decide which one to use the next time. -## I got some run-time errors about invalid proto descriptors when using `ProtocolMessageEquals`. Help! - -{: .callout .note} -**Note:** `ProtocolMessageEquals` and `ProtocolMessageEquiv` are *deprecated* -now. Please use `EqualsProto`, etc instead. - -`ProtocolMessageEquals` and `ProtocolMessageEquiv` were redefined recently and -are now less tolerant of invalid protocol buffer definitions. In particular, if -you have a `foo.proto` that doesn't fully qualify the type of a protocol message -it references (e.g. `message` where it should be `message`), you -will now get run-time errors like: - -``` -... descriptor.cc:...] Invalid proto descriptor for file "path/to/foo.proto": -... descriptor.cc:...] blah.MyMessage.my_field: ".Bar" is not defined. -``` - -If you see this, your `.proto` file is broken and needs to be fixed by making -the types fully qualified. The new definition of `ProtocolMessageEquals` and -`ProtocolMessageEquiv` just happen to reveal your bug. - ## My death test modifies some state, but the change seems lost after the death test finishes. Why? Death tests (`EXPECT_DEATH`, etc) are executed in a sub-process s.t. the From d1467f5813f4d363cfd11aba99c4e9fe47a85e99 Mon Sep 17 00:00:00 2001 From: Michael Hirshleifer Date: Thu, 14 Sep 2023 10:36:23 -0700 Subject: [PATCH 65/81] GoogleTest FAQ: minor punctuation fixes PiperOrigin-RevId: 565411290 Change-Id: I57e94c679183e39eec2a2835f330b52fc9302767 --- docs/faq.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index c942b5dcc..c7d10b500 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -3,7 +3,7 @@ ## Why should test suite names and test names not contain underscore? {: .callout .note} -Note: GoogleTest reserves underscore (`_`) for special purpose keywords, such as +Note: GoogleTest reserves underscore (`_`) for special-purpose keywords, such as [the `DISABLED_` prefix](advanced.md#temporarily-disabling-tests), in addition to the following rationale. @@ -33,9 +33,9 @@ contains `_`? `TestSuiteName_Bar__Test`, which is invalid. So clearly `TestSuiteName` and `TestName` cannot start or end with `_` -(Actually, `TestSuiteName` can start with `_` -- as long as the `_` isn't -followed by an upper-case letter. But that's getting complicated. So for -simplicity we just say that it cannot start with `_`.). +(Actually, `TestSuiteName` can start with `_`—as long as the `_` isn't followed +by an upper-case letter. But that's getting complicated. So for simplicity we +just say that it cannot start with `_`.). It may seem fine for `TestSuiteName` and `TestName` to contain `_` in the middle. However, consider this: @@ -130,7 +130,7 @@ can much more easily decide which one to use the next time. ## My death test modifies some state, but the change seems lost after the death test finishes. Why? -Death tests (`EXPECT_DEATH`, etc) are executed in a sub-process s.t. the +Death tests (`EXPECT_DEATH`, etc.) are executed in a sub-process s.t. the expected crash won't kill the test program (i.e. the parent process). As a result, any in-memory side effects they incur are observable in their respective sub-processes, but not in the parent process. You can think of them as running @@ -171,16 +171,16 @@ class Foo { }; ``` -You also need to define it *outside* of the class body in `foo.cc`: +you also need to define it *outside* of the class body in `foo.cc`: ```c++ const int Foo::kBar; // No initializer here. ``` Otherwise your code is **invalid C++**, and may break in unexpected ways. In -particular, using it in GoogleTest comparison assertions (`EXPECT_EQ`, etc) will -generate an "undefined reference" linker error. The fact that "it used to work" -doesn't mean it's valid. It just means that you were lucky. :-) +particular, using it in GoogleTest comparison assertions (`EXPECT_EQ`, etc.) +will generate an "undefined reference" linker error. The fact that "it used to +work" doesn't mean it's valid. It just means that you were lucky. :-) If the declaration of the static data member is `constexpr` then it is implicitly an `inline` definition, and a separate definition in `foo.cc` is not @@ -290,7 +290,7 @@ a **fresh** test fixture object, immediately call `SetUp()`, run the test body, call `TearDown()`, and then delete the test fixture object. When you need to write per-test set-up and tear-down logic, you have the choice -between using the test fixture constructor/destructor or `SetUp()/TearDown()`. +between using the test fixture constructor/destructor or `SetUp()`/`TearDown()`. The former is usually preferred, as it has the following benefits: * By initializing a member variable in the constructor, we have the option to @@ -331,7 +331,7 @@ You may still want to use `SetUp()/TearDown()` in the following cases: GoogleTest assertions in a destructor if your code could run on such a platform. -## The compiler complains "no matching function to call" when I use ASSERT_PRED*. How do I fix it? +## The compiler complains "no matching function to call" when I use `ASSERT_PRED*`. How do I fix it? See details for [`EXPECT_PRED*`](reference/assertions.md#EXPECT_PRED) in the Assertions Reference. @@ -389,7 +389,7 @@ C++ is case-sensitive. Did you spell it as `Setup()`? Similarly, sometimes people spell `SetUpTestSuite()` as `SetupTestSuite()` and wonder why it's never called. -## I have several test suites which share the same test fixture logic, do I have to define a new test fixture class for each of them? This seems pretty tedious. +## I have several test suites which share the same test fixture logic; do I have to define a new test fixture class for each of them? This seems pretty tedious. You don't have to. Instead of @@ -524,7 +524,7 @@ The new NPTL thread library doesn't suffer from this problem, as it doesn't create a manager thread. However, if you don't control which machine your test runs on, you shouldn't depend on this. -## Why does GoogleTest require the entire test suite, instead of individual tests, to be named *DeathTest when it uses ASSERT_DEATH? +## Why does GoogleTest require the entire test suite, instead of individual tests, to be named `*DeathTest` when it uses `ASSERT_DEATH`? GoogleTest does not interleave tests from different test suites. That is, it runs all tests in one test suite first, and then runs all tests in the next test @@ -549,7 +549,7 @@ interleave tests from different test suites, we need to run all tests in the `FooTest` case before running any test in the `BarTest` case. This contradicts with the requirement to run `BarTest.DefDeathTest` before `FooTest.Uvw`. -## But I don't like calling my entire test suite \*DeathTest when it contains both death tests and non-death tests. What do I do? +## But I don't like calling my entire test suite `*DeathTest` when it contains both death tests and non-death tests. What do I do? You don't have to, but if you like, you may split up the test suite into `FooTest` and `FooDeathTest`, where the names make it clear that they are @@ -633,7 +633,7 @@ the `--gtest_also_run_disabled_tests` flag. Yes. The rule is **all test methods in the same test suite must use the same fixture -class.** This means that the following is **allowed** because both tests use the +class**. This means that the following is **allowed** because both tests use the same fixture class (`::testing::Test`). ```c++ From 8be20cce6931433c8bc3124beea91922cd621423 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 18 Sep 2023 03:17:14 -0700 Subject: [PATCH 66/81] Use the `empty()` method to check for emptiness instead of `length()` PiperOrigin-RevId: 566247438 Change-Id: I8199ef53310a057abbe23f8f4295507b60d6b707 --- googletest/src/gtest-filepath.cc | 2 +- googletest/src/gtest.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/src/gtest-filepath.cc b/googletest/src/gtest-filepath.cc index 513e947f5..902d8c7f6 100644 --- a/googletest/src/gtest-filepath.cc +++ b/googletest/src/gtest-filepath.cc @@ -336,7 +336,7 @@ bool FilePath::CreateDirectoriesRecursively() const { return false; } - if (pathname_.length() == 0 || this->DirectoryExists()) { + if (pathname_.empty() || this->DirectoryExists()) { return true; } diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 62dfef664..99b22ed32 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -5400,7 +5400,7 @@ void UnitTest::RecordProperty(const std::string& key, int UnitTest::Run() { #ifdef GTEST_HAS_DEATH_TEST const bool in_death_test_child_process = - GTEST_FLAG_GET(internal_run_death_test).length() > 0; + !GTEST_FLAG_GET(internal_run_death_test).empty(); // Google Test implements this protocol for catching that a test // program exits before returning control to Google Test: From adc514538678a61b13c240f7b41babbc03b2ac24 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 18 Sep 2023 15:03:24 -0700 Subject: [PATCH 67/81] Update code with IWYU annotations. PiperOrigin-RevId: 566424331 Change-Id: I0e16d979b9d79643c882c5082e154842983a5317 --- googlemock/include/gmock/gmock.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/googlemock/include/gmock/gmock.h b/googlemock/include/gmock/gmock.h index 568c8c71d..2ca4f7ac6 100644 --- a/googlemock/include/gmock/gmock.h +++ b/googlemock/include/gmock/gmock.h @@ -53,13 +53,13 @@ // // where all clauses are optional and WillOnce() can be repeated. -#include "gmock/gmock-actions.h" -#include "gmock/gmock-cardinalities.h" -#include "gmock/gmock-function-mocker.h" -#include "gmock/gmock-matchers.h" -#include "gmock/gmock-more-actions.h" -#include "gmock/gmock-more-matchers.h" -#include "gmock/gmock-nice-strict.h" +#include "gmock/gmock-actions.h" // IWYU pragma: export +#include "gmock/gmock-cardinalities.h" // IWYU pragma: export +#include "gmock/gmock-function-mocker.h" // IWYU pragma: export +#include "gmock/gmock-matchers.h" // IWYU pragma: export +#include "gmock/gmock-more-actions.h" // IWYU pragma: export +#include "gmock/gmock-more-matchers.h" // IWYU pragma: export +#include "gmock/gmock-nice-strict.h" // IWYU pragma: export #include "gmock/internal/gmock-internal-utils.h" #include "gmock/internal/gmock-port.h" From e27b194c2702f02cf033a32bb49978b8ff32aa15 Mon Sep 17 00:00:00 2001 From: Mitja Spes Date: Thu, 21 Sep 2023 10:06:21 +0200 Subject: [PATCH 68/81] Fix compile warnings in gmock-function-mocker.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Template type int changed to size_t. This fixes compile warning `conversion to ‘long unsigned int’ from ‘int’ may change the sign of the result` in gmock-function-mocker.h. --- googlemock/include/gmock/gmock-function-mocker.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/googlemock/include/gmock/gmock-function-mocker.h b/googlemock/include/gmock/gmock-function-mocker.h index 1a1f126e4..30355fedf 100644 --- a/googlemock/include/gmock/gmock-function-mocker.h +++ b/googlemock/include/gmock/gmock-function-mocker.h @@ -69,22 +69,22 @@ constexpr bool PrefixOf(const char* a, const char* b) { return *a == 0 || (*a == *b && internal::PrefixOf(a + 1, b + 1)); } -template +template constexpr bool StartsWith(const char (&prefix)[N], const char (&str)[M]) { return N <= M && internal::PrefixOf(prefix, str); } -template +template constexpr bool EndsWith(const char (&suffix)[N], const char (&str)[M]) { return N <= M && internal::PrefixOf(suffix, str + M - N); } -template +template constexpr bool Equals(const char (&a)[N], const char (&b)[M]) { return N == M && internal::PrefixOf(a, b); } -template +template constexpr bool ValidateSpec(const char (&spec)[N]) { return internal::Equals("const", spec) || internal::Equals("override", spec) || From 167a2255aef1420735dbe7eeabd4691709f8114a Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Thu, 21 Sep 2023 09:07:18 -0700 Subject: [PATCH 69/81] googletest: Update absl to version with HasAbslStringify https://github.com/abseil/abseil-cpp/commit/9e1789ffea47fdeb3133aa42aa9592f3673fb6ed PiperOrigin-RevId: 567324946 Change-Id: I8adc5803a81075a635dad79aa0312d4455e1ad63 --- googletest_deps.bzl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/googletest_deps.bzl b/googletest_deps.bzl index e25f5a1ad..8f19cbed7 100644 --- a/googletest_deps.bzl +++ b/googletest_deps.bzl @@ -15,8 +15,8 @@ def googletest_deps(): if not native.existing_rule("com_google_absl"): http_archive( - name = "com_google_absl", # 2023-08-01T14:59:13Z - sha256 = "d2c09bf3b3aba57ad87a56082020bee2948445407756e92ddaf3595396086853", - strip_prefix = "abseil-cpp-22091f4c0d6626b3ef40446ce3d4ccab19425ca3", - urls = ["https://github.com/abseil/abseil-cpp/archive/22091f4c0d6626b3ef40446ce3d4ccab19425ca3.zip"], + name = "com_google_absl", # 2023-09-13T14:58:42Z + sha256 = "7766815ef6293dc7bca58fef59a96d7d3230874412dcd36dafb0e313ed1356f2", + strip_prefix = "abseil-cpp-9e1789ffea47fdeb3133aa42aa9592f3673fb6ed", + urls = ["https://github.com/abseil/abseil-cpp/archive/9e1789ffea47fdeb3133aa42aa9592f3673fb6ed.zip"], ) From 80306a7b5ec8ddaabd26540f2827b903d69e7a02 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 21 Sep 2023 10:31:33 -0700 Subject: [PATCH 70/81] Use `absl::HasAbslStringify`, instead of the internal version. PiperOrigin-RevId: 567349341 Change-Id: I35f2679901aecbe9cb90d2e78ff28c5e383e7257 --- googletest/include/gtest/gtest-message.h | 19 +++++++++---------- googletest/include/gtest/gtest-printers.h | 9 ++++----- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/googletest/include/gtest/gtest-message.h b/googletest/include/gtest/gtest-message.h index 59b805e4e..448ac6b7e 100644 --- a/googletest/include/gtest/gtest-message.h +++ b/googletest/include/gtest/gtest-message.h @@ -59,7 +59,7 @@ #ifdef GTEST_HAS_ABSL #include -#include "absl/strings/internal/has_absl_stringify.h" +#include "absl/strings/has_absl_stringify.h" #include "absl/strings/str_cat.h" #endif // GTEST_HAS_ABSL @@ -121,14 +121,14 @@ class GTEST_API_ Message { // Streams a non-pointer value to this object. If building a version of // GoogleTest with ABSL, this overload is only enabled if the value does not // have an AbslStringify definition. - template ::value, // NOLINT - int>::type = 0 + , + typename std::enable_if::value, // NOLINT + int>::type = 0 #endif // GTEST_HAS_ABSL - > + > inline Message& operator<<(const T& val) { // Some libraries overload << for STL containers. These // overloads are defined in the global namespace instead of ::std. @@ -153,9 +153,8 @@ class GTEST_API_ Message { // Streams a non-pointer value with an AbslStringify definition to this // object. template ::value, // NOLINT - int>::type = 0> + typename std::enable_if::value, // NOLINT + int>::type = 0> inline Message& operator<<(const T& val) { // ::operator<< is needed here for a similar reason as with the non-Abseil // version above diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 9ccbff7da..1b12ef683 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -116,7 +116,7 @@ #include #ifdef GTEST_HAS_ABSL -#include "absl/strings/internal/has_absl_stringify.h" +#include "absl/strings/has_absl_stringify.h" #include "absl/strings/str_cat.h" #endif // GTEST_HAS_ABSL #include "gtest/internal/gtest-internal.h" @@ -292,10 +292,9 @@ struct ConvertibleToStringViewPrinter { #ifdef GTEST_HAS_ABSL struct ConvertibleToAbslStringifyPrinter { - template < - typename T, - typename = typename std::enable_if< - absl::strings_internal::HasAbslStringify::value>::type> // NOLINT + template ::value>::type> // NOLINT static void PrintValue(const T& value, ::std::ostream* os) { *os << absl::StrCat(value); } From e40661d89b051e9ef4eb8a2420b74bf78b39ef41 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 22 Sep 2023 10:45:22 -0700 Subject: [PATCH 71/81] Update C++ feature detection in `gtest-port.h` to rely on feature test macros where possible. This also avoids conflating C++ language versions with standard library versions, which don't always align. PiperOrigin-RevId: 567662118 Change-Id: I7c023bd043c81c540c9430eaeb7b450feaadb206 --- .../include/gtest/internal/gtest-port.h | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 35544a08a..5f741cad3 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -281,6 +281,22 @@ #error C++ versions less than C++14 are not supported. #endif +// MSVC >= 19.11 (VS 2017 Update 3) supports __has_include. +#ifdef __has_include +#define GTEST_INTERNAL_HAS_INCLUDE __has_include +#else +#define GTEST_INTERNAL_HAS_INCLUDE(...) 0 +#endif + +// Detect C++ feature test macros as gracefully as possible. +// MSVC >= 19.15, Clang >= 3.4.1, and GCC >= 4.1.2 support feature test macros. +#if GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L && \ + (!defined(__has_include) || GTEST_INTERNAL_HAS_INCLUDE()) +#include // C++20 and later +#elif (!defined(__has_include) || GTEST_INTERNAL_HAS_INCLUDE()) +#include // Pre-C++20 +#endif + #include // for isspace, etc #include // for ptrdiff_t #include @@ -2351,9 +2367,9 @@ using Any = ::absl::any; } // namespace internal } // namespace testing #else -#ifdef __has_include -#if __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L && \ - (!defined(_MSC_VER) || GTEST_HAS_RTTI) +#if defined(__cpp_lib_any) || (GTEST_INTERNAL_HAS_INCLUDE() && \ + GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L && \ + (!defined(_MSC_VER) || GTEST_HAS_RTTI)) // Otherwise for C++17 and higher use std::any for UniversalPrinter<> // specializations. #define GTEST_INTERNAL_HAS_ANY 1 @@ -2365,8 +2381,7 @@ using Any = ::std::any; } // namespace testing // The case where absl is configured NOT to alias std::any is not // supported. -#endif // __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L -#endif // __has_include +#endif // __cpp_lib_any #endif // GTEST_HAS_ABSL #ifndef GTEST_INTERNAL_HAS_ANY @@ -2386,8 +2401,8 @@ inline ::absl::nullopt_t Nullopt() { return ::absl::nullopt; } } // namespace internal } // namespace testing #else -#ifdef __has_include -#if __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L +#if defined(__cpp_lib_optional) || (GTEST_INTERNAL_HAS_INCLUDE() && \ + GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L) // Otherwise for C++17 and higher use std::optional for UniversalPrinter<> // specializations. #define GTEST_INTERNAL_HAS_OPTIONAL 1 @@ -2401,19 +2416,17 @@ inline ::std::nullopt_t Nullopt() { return ::std::nullopt; } } // namespace testing // The case where absl is configured NOT to alias std::optional is not // supported. -#endif // __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L -#endif // __has_include +#endif // __cpp_lib_optional #endif // GTEST_HAS_ABSL #ifndef GTEST_INTERNAL_HAS_OPTIONAL #define GTEST_INTERNAL_HAS_OPTIONAL 0 #endif -#ifdef __has_include -#if __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L +#if defined(__cpp_lib_span) || (GTEST_INTERNAL_HAS_INCLUDE() && \ + GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L) #define GTEST_INTERNAL_HAS_STD_SPAN 1 -#endif // __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L -#endif // __has_include +#endif // __cpp_lib_span #ifndef GTEST_INTERNAL_HAS_STD_SPAN #define GTEST_INTERNAL_HAS_STD_SPAN 0 @@ -2430,8 +2443,9 @@ using StringView = ::absl::string_view; } // namespace internal } // namespace testing #else -#ifdef __has_include -#if __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L +#if defined(__cpp_lib_string_view) || \ + (GTEST_INTERNAL_HAS_INCLUDE() && \ + GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L) // Otherwise for C++17 and higher use std::string_view for Matcher<> // specializations. #define GTEST_INTERNAL_HAS_STRING_VIEW 1 @@ -2443,9 +2457,7 @@ using StringView = ::std::string_view; } // namespace testing // The case where absl is configured NOT to alias std::string_view is not // supported. -#endif // __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= - // 201703L -#endif // __has_include +#endif // __cpp_lib_string_view #endif // GTEST_HAS_ABSL #ifndef GTEST_INTERNAL_HAS_STRING_VIEW @@ -2464,8 +2476,8 @@ using Variant = ::absl::variant; } // namespace internal } // namespace testing #else -#ifdef __has_include -#if __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L +#if defined(__cpp_lib_variant) || (GTEST_INTERNAL_HAS_INCLUDE() && \ + GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L) // Otherwise for C++17 and higher use std::variant for UniversalPrinter<> // specializations. #define GTEST_INTERNAL_HAS_VARIANT 1 @@ -2477,16 +2489,16 @@ using Variant = ::std::variant; } // namespace internal } // namespace testing // The case where absl is configured NOT to alias std::variant is not supported. -#endif // __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L -#endif // __has_include +#endif // __cpp_lib_variant #endif // GTEST_HAS_ABSL #ifndef GTEST_INTERNAL_HAS_VARIANT #define GTEST_INTERNAL_HAS_VARIANT 0 #endif -#if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \ - GTEST_INTERNAL_CPLUSPLUS_LANG < 201703L +#if (defined(__cpp_constexpr) && !defined(__cpp_inline_variables)) || \ + (defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \ + GTEST_INTERNAL_CPLUSPLUS_LANG < 201703L) #define GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL 1 #endif From e47544ad31cb3ceecd04cc13e8fe556f8df9fe0b Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 25 Sep 2023 14:37:34 -0700 Subject: [PATCH 72/81] Resolve `-Wundef` triggering on `GTEST_CREATE_SHARED_LIBRARY` and `GTEST_LINKED_AS_SHARED_LIBRARY` with shared libraries in GoogleTest Fixes: #4372 PiperOrigin-RevId: 568327612 Change-Id: Ifc47f1a2a2648c29858a22966331557cc928cc47 --- googletest/include/gtest/internal/gtest-port.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 5f741cad3..d061a49b9 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -845,9 +845,9 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #ifndef GTEST_API_ #ifdef _MSC_VER -#if GTEST_LINKED_AS_SHARED_LIBRARY +#if defined(GTEST_LINKED_AS_SHARED_LIBRARY) && GTEST_LINKED_AS_SHARED_LIBRARY #define GTEST_API_ __declspec(dllimport) -#elif GTEST_CREATE_SHARED_LIBRARY +#elif defined(GTEST_CREATE_SHARED_LIBRARY) && GTEST_CREATE_SHARED_LIBRARY #define GTEST_API_ __declspec(dllexport) #endif #elif GTEST_HAVE_ATTRIBUTE_(visibility) From 2d09ed35cfabc8032545a401e883aafd3efda048 Mon Sep 17 00:00:00 2001 From: Dzmitry Ivaniuk Date: Fri, 29 Sep 2023 17:26:23 +0300 Subject: [PATCH 73/81] cmake: Fix comments in cmake files Remove extra spaces. Fix so that the comment line starts with a capital letter and ends with a dot. --- CMakeLists.txt | 2 +- googlemock/CMakeLists.txt | 20 +++++++-------- googletest/CMakeLists.txt | 26 +++++++++---------- googletest/cmake/internal_utils.cmake | 37 +++++++++++++-------------- 4 files changed, 42 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 089ac987f..24d41c29c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ enable_testing() include(CMakeDependentOption) include(GNUInstallDirs) -#Note that googlemock target already builds googletest +# Note that googlemock target already builds googletest. option(BUILD_GMOCK "Builds the googlemock subproject" ON) option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON) option(GTEST_HAS_ABSL "Use Abseil and RE2. Requires Abseil and RE2 to be separately added to the build." OFF) diff --git a/googlemock/CMakeLists.txt b/googlemock/CMakeLists.txt index a9aa0723f..428bd9f8e 100644 --- a/googlemock/CMakeLists.txt +++ b/googlemock/CMakeLists.txt @@ -5,7 +5,7 @@ # CMake build script for Google Mock. # # To run the tests for Google Mock itself on Linux, use 'make test' or -# ctest. You can select which tests to run using 'ctest -R regex'. +# ctest. You can select which tests to run using 'ctest -R regex'. # For more options, run 'ctest --help'. option(gmock_build_tests "Build all of Google Mock's own tests." OFF) @@ -44,7 +44,7 @@ if (COMMAND set_up_hermetic_build) endif() # Instructs CMake to process Google Test's CMakeLists.txt and add its -# targets to the current scope. We are placing Google Test's binary +# targets to the current scope. We are placing Google Test's binary # directory in a subdirectory of our own as VC compilation may break # if they are the same (the default). add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/${gtest_dir}") @@ -60,9 +60,9 @@ else() endif() # Although Google Test's CMakeLists.txt calls this function, the -# changes there don't affect the current scope. Therefore we have to +# changes there don't affect the current scope. Therefore we have to # call it again here. -config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake +config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake # Adds Google Mock's and Google Test's header directories to the search path. set(gmock_build_include_dirs @@ -75,10 +75,10 @@ include_directories(${gmock_build_include_dirs}) ######################################################################## # -# Defines the gmock & gmock_main libraries. User tests should link +# Defines the gmock & gmock_main libraries. User tests should link # with one of them. -# Google Mock libraries. We build them using more strict warnings than what +# Google Mock libraries. We build them using more strict warnings than what # are used for other targets, to ensure that Google Mock can be compiled by # a user aggressive about warnings. if (MSVC) @@ -111,7 +111,7 @@ target_include_directories(gmock_main SYSTEM INTERFACE ######################################################################## # -# Install rules +# Install rules. install_project(gmock gmock_main) ######################################################################## @@ -121,8 +121,8 @@ install_project(gmock gmock_main) # You can skip this section if you aren't interested in testing # Google Mock itself. # -# The tests are not built by default. To build them, set the -# gmock_build_tests option to ON. You can do it by running ccmake +# The tests are not built by default. To build them, set the +# gmock_build_tests option to ON. You can do it by running ccmake # or specifying the -Dgmock_build_tests=ON flag when running cmake. if (gmock_build_tests) @@ -187,7 +187,7 @@ if (gmock_build_tests) cxx_shared_library(shared_gmock_main "${cxx_default}" "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) - # Tests that a binary can be built with Google Mock as a shared library. On + # Tests that a binary can be built with Google Mock as a shared library. On # some system configurations, it may not possible to run the binary without # knowing more details about the system configurations. We do not try to run # this binary. To get a more robust shared library coverage, configure with diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index caafa8c76..51a67c915 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -5,7 +5,7 @@ # CMake build script for Google Test. # # To run the tests for Google Test itself on Linux, use 'make test' or -# ctest. You can select which tests to run using 'ctest -R regex'. +# ctest. You can select which tests to run using 'ctest -R regex'. # For more options, run 'ctest --help'. # When other libraries are using a shared version of runtime libraries, @@ -35,7 +35,7 @@ endif() ######################################################################## # -# Project-wide settings +# Project-wide settings. # Name of the project. # @@ -44,7 +44,7 @@ endif() # ${gtest_BINARY_DIR}. # Language "C" is required for find_package(Threads). -# Project version: +# Project version. cmake_minimum_required(VERSION 3.13) project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) @@ -53,7 +53,7 @@ if (COMMAND set_up_hermetic_build) set_up_hermetic_build() endif() -# These commands only run if this is the main project +# These commands only run if this is the main project. if(CMAKE_PROJECT_NAME STREQUAL "gtest" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution") # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to @@ -83,7 +83,7 @@ include(cmake/internal_utils.cmake) config_compiler_and_linker() # Defined in internal_utils.cmake. # Needed to set the namespace for both the export targets and the -# alias libraries +# alias libraries. set(cmake_package_name GTest CACHE INTERNAL "") # Create the CMake package file descriptors. @@ -114,10 +114,10 @@ include_directories(${gtest_build_include_dirs}) ######################################################################## # -# Defines the gtest & gtest_main libraries. User tests should link +# Defines the gtest & gtest_main libraries. User tests should link # with one of them. -# Google Test libraries. We build them using more strict warnings than what +# Google Test libraries. We build them using more strict warnings than what # are used for other targets, to ensure that gtest can be compiled by a user # aggressive about warnings. cxx_library(gtest "${cxx_strict}" src/gtest-all.cc) @@ -154,15 +154,15 @@ target_link_libraries(gtest_main PUBLIC gtest) ######################################################################## # -# Install rules +# Install rules. install_project(gtest gtest_main) ######################################################################## # # Samples on how to link user tests with gtest or gtest_main. # -# They are not built by default. To build them, set the -# gtest_build_samples option to ON. You can do it by running ccmake +# They are not built by default. To build them, set the +# gtest_build_samples option to ON. You can do it by running ccmake # or specifying the -Dgtest_build_samples=ON flag when running cmake. if (gtest_build_samples) @@ -185,8 +185,8 @@ endif() # You can skip this section if you aren't interested in testing # Google Test itself. # -# The tests are not built by default. To build them, set the -# gtest_build_tests option to ON. You can do it by running ccmake +# The tests are not built by default. To build them, set the +# gtest_build_tests option to ON. You can do it by running ccmake # or specifying the -Dgtest_build_tests=ON flag when running cmake. if (gtest_build_tests) @@ -268,7 +268,7 @@ if (gtest_build_tests) py_test(gtest_skip_environment_check_output_test) # Visual Studio .NET 2003 does not support STL with exceptions disabled. - if (NOT MSVC OR MSVC_VERSION GREATER 1310) # 1310 is Visual Studio .NET 2003 + if (NOT MSVC OR MSVC_VERSION GREATER 1310) # 1310 is Visual Studio .NET 2003 cxx_executable_with_flags( googletest-catch-exceptions-no-ex-test_ "${cxx_no_exception}" diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index d4f67f43a..d5c82745f 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -29,7 +29,7 @@ macro(fix_default_compiler_settings_) CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) if (NOT BUILD_SHARED_LIBS AND NOT gtest_force_shared_crt) # When Google Test is built as a shared library, it should also use - # shared runtime libraries. Otherwise, it may end up with multiple + # shared runtime libraries. Otherwise, it may end up with multiple # copies of runtime library data in different modules, resulting in # hard-to-find crashes. When it is built as a static library, it is # preferable to use CRT as static libraries, as we don't have to rely @@ -55,11 +55,11 @@ macro(fix_default_compiler_settings_) endmacro() # Defines the compiler/linker flags used to build Google Test and -# Google Mock. You can tweak these definitions to suit your need. A +# Google Mock. You can tweak these definitions to suit your need. A # variable's value is empty before it's explicitly assigned to. macro(config_compiler_and_linker) # Note: pthreads on MinGW is not supported, even if available - # instead, we use windows threading primitives + # instead, we use windows threading primitives. unset(GTEST_HAS_PTHREAD) if (NOT gtest_disable_pthreads AND NOT MINGW) # Defines CMAKE_USE_PTHREADS_INIT and CMAKE_THREAD_LIBS_INIT. @@ -79,7 +79,7 @@ macro(config_compiler_and_linker) set(cxx_exception_flags "-EHsc -D_HAS_EXCEPTIONS=1") set(cxx_no_exception_flags "-EHs-c- -D_HAS_EXCEPTIONS=0") set(cxx_no_rtti_flags "-GR-") - # Suppress "unreachable code" warning + # Suppress "unreachable code" warning, # https://stackoverflow.com/questions/3232669 explains the issue. set(cxx_base_flags "${cxx_base_flags} -wd4702") # Ensure MSVC treats source files as UTF-8 encoded. @@ -110,7 +110,7 @@ macro(config_compiler_and_linker) set(cxx_exception_flags "-fexceptions") set(cxx_no_exception_flags "-fno-exceptions") # Until version 4.3.2, GCC doesn't define a macro to indicate - # whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI + # whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI # explicitly. set(cxx_no_rtti_flags "-fno-rtti -DGTEST_HAS_RTTI=0") set(cxx_strict_flags @@ -127,7 +127,7 @@ macro(config_compiler_and_linker) set(cxx_exception_flags "-qeh") set(cxx_no_exception_flags "-qnoeh") # Until version 9.0, Visual Age doesn't define a macro to indicate - # whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI + # whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI # explicitly. set(cxx_no_rtti_flags "-qnortti -DGTEST_HAS_RTTI=0") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "HP") @@ -157,7 +157,7 @@ macro(config_compiler_and_linker) set(cxx_strict "${cxx_default} ${cxx_strict_flags}") endmacro() -# Defines the gtest & gtest_main libraries. User tests should link +# Defines the gtest & gtest_main libraries. User tests should link # with one of them. function(cxx_library_with_type name type cxx_flags) # type can be either STATIC or SHARED to denote a static or shared library. @@ -167,15 +167,14 @@ function(cxx_library_with_type name type cxx_flags) set_target_properties(${name} PROPERTIES COMPILE_FLAGS "${cxx_flags}") - # Set the output directory for build artifacts + # Set the output directory for build artifacts. set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" - COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") - # make PDBs match library name + # Make PDBs match library name. get_target_property(pdb_debug_postfix ${name} DEBUG_POSTFIX) set_target_properties(${name} PROPERTIES @@ -212,7 +211,7 @@ endfunction() # cxx_executable_with_flags(name cxx_flags libs srcs...) # -# creates a named C++ executable that depends on the given libraries and +# Creates a named C++ executable that depends on the given libraries and # is built from the given source files with the given compiler flags. function(cxx_executable_with_flags name cxx_flags libs) add_executable(${name} ${ARGN}) @@ -239,8 +238,8 @@ endfunction() # cxx_executable(name dir lib srcs...) # -# creates a named target that depends on the given libs and is built -# from the given source files. dir/name.cc is implicitly included in +# Creates a named target that depends on the given libs and is built +# from the given source files. dir/name.cc is implicitly included in # the source file list. function(cxx_executable name dir libs) cxx_executable_with_flags( @@ -251,7 +250,7 @@ find_package(Python3) # cxx_test_with_flags(name cxx_flags libs srcs...) # -# creates a named C++ test that depends on the given libs and is built +# Creates a named C++ test that depends on the given libs and is built # from the given source files with the given compiler flags. function(cxx_test_with_flags name cxx_flags libs) cxx_executable_with_flags(${name} "${cxx_flags}" "${libs}" ${ARGN}) @@ -260,8 +259,8 @@ endfunction() # cxx_test(name libs srcs...) # -# creates a named test target that depends on the given libs and is -# built from the given source files. Unlike cxx_test_with_flags, +# Creates a named test target that depends on the given libs and is +# built from the given source files. Unlike cxx_test_with_flags, # test/name.cc is already implicitly included in the source file list. function(cxx_test name libs) cxx_test_with_flags("${name}" "${cxx_default}" "${libs}" @@ -270,8 +269,8 @@ endfunction() # py_test(name) # -# creates a Python test with the given name whose main module is in -# test/name.py. It does nothing if Python is not installed. +# Creates a Python test with the given name whose main module is in +# test/name.py. It does nothing if Python is not installed. function(py_test name) if (NOT Python3_Interpreter_FOUND) return() @@ -307,7 +306,7 @@ function(install_project) ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - # Install PDBs + # Install PDBs. foreach(t ${ARGN}) get_target_property(t_pdb_name ${t} COMPILE_PDB_NAME) get_target_property(t_pdb_name_debug ${t} COMPILE_PDB_NAME_DEBUG) From beb552fb47e9e8a6ddab20526663c2dddd601ec6 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Tue, 3 Oct 2023 11:41:17 -0700 Subject: [PATCH 74/81] gmock_cook_book: Document `DoAll`'s return type requirement The requirement is vaguely documented by "Only the return value of the last action in the sequence will be used.". However, this can be misleading, as users could potentially expect default-constructed values to be returned in absence of a matching return type. PiperOrigin-RevId: 570450839 Change-Id: Ibd98a6e6b2aaf2a8cfc15ed6aeab442526eab98e --- docs/gmock_cook_book.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/gmock_cook_book.md b/docs/gmock_cook_book.md index da10918c9..5e9b6647d 100644 --- a/docs/gmock_cook_book.md +++ b/docs/gmock_cook_book.md @@ -1927,6 +1927,12 @@ class MockFoo : public Foo { action_n)); ``` +The return value of the last action **must** match the return type of the mocked +method. In the example above, `action_n` could be `Return(true)`, or a lambda +that returns a `bool`, but not `SaveArg`, which returns `void`. Otherwise the +signature of `DoAll` would not match the signature expected by `WillOnce`, which +is the signature of the mocked method, and it wouldn't compile. + ### Verifying Complex Arguments {#SaveArgVerify} If you want to verify that a method is called with a particular argument but the From 2dd1c131950043a8ad5ab0d2dda0e0970596586a Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 5 Oct 2023 14:12:08 -0700 Subject: [PATCH 75/81] Fix RE::Init for Android and NetBSD. This is a somewhat recent change for Android (I'm not clear on whether it's a recent change for NetBSD, or if Android was just very behind on its implementation), so while this worked fine as recently as API 32 devices, REG_GNU is required for API 34 (API 33 untested). A test actually caught this, but https://github.com/google/googletest/pull/4334 "fixed" the test rather than the implementation. This CL also reverts the test change so it can catch the failure. PiperOrigin-RevId: 571126374 Change-Id: I420dfcedea58f2c8b605f699515d744006c0a9d9 --- googletest/src/gtest-port.cc | 15 +++++++++++++-- googletest/test/googletest-port-test.cc | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index e9d12d92e..3bb7dd450 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -697,13 +697,24 @@ bool RE::PartialMatch(const char* str, const RE& re) { void RE::Init(const char* regex) { pattern_ = regex; + // NetBSD (and Android, which takes its regex implemntation from NetBSD) does + // not include the GNU regex extensions (such as Perl style character classes + // like \w) in REG_EXTENDED. REG_EXTENDED is only specified to include the + // [[:alpha:]] style character classes. Enable REG_GNU wherever it is defined + // so users can use those extensions. +#if defined(REG_GNU) + constexpr int reg_flags = REG_EXTENDED | REG_GNU; +#else + constexpr int reg_flags = REG_EXTENDED; +#endif + // Reserves enough bytes to hold the regular expression used for a // full match. const size_t full_regex_len = strlen(regex) + 10; char* const full_pattern = new char[full_regex_len]; snprintf(full_pattern, full_regex_len, "^(%s)$", regex); - is_valid_ = regcomp(&full_regex_, full_pattern, REG_EXTENDED) == 0; + is_valid_ = regcomp(&full_regex_, full_pattern, reg_flags) == 0; // We want to call regcomp(&partial_regex_, ...) even if the // previous expression returns false. Otherwise partial_regex_ may // not be properly initialized can may cause trouble when it's @@ -714,7 +725,7 @@ void RE::Init(const char* regex) { // regex. We change it to an equivalent form "()" to be safe. if (is_valid_) { const char* const partial_regex = (*regex == '\0') ? "()" : regex; - is_valid_ = regcomp(&partial_regex_, partial_regex, REG_EXTENDED) == 0; + is_valid_ = regcomp(&partial_regex_, partial_regex, reg_flags) == 0; } EXPECT_TRUE(is_valid_) << "Regular expression \"" << regex diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index 8d210260f..9f05a0199 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -418,8 +418,8 @@ TYPED_TEST(RETest, ImplicitConstructorWorks) { const RE simple(TypeParam("hello")); EXPECT_STREQ("hello", simple.pattern()); - const RE normal(TypeParam(".*([[:alnum:]_]+)")); - EXPECT_STREQ(".*([[:alnum:]_]+)", normal.pattern()); + const RE normal(TypeParam(".*(\\w+)")); + EXPECT_STREQ(".*(\\w+)", normal.pattern()); } // Tests that RE's constructors reject invalid regular expressions. From 829c19901dac454ced475fec6a11e8e1b8a61549 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Tue, 17 Oct 2023 09:18:09 -0700 Subject: [PATCH 76/81] gtest-death-test-internal: Delete obsolete string constants These are not used anywhere in googletest and they are in namespace `testing::internal` PiperOrigin-RevId: 574171727 Change-Id: I5f668157a81ba3efaed77c1302b40cf07eeda52b --- googletest/include/gtest/internal/gtest-death-test-internal.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-death-test-internal.h b/googletest/include/gtest/internal/gtest-death-test-internal.h index 8e9c988b9..61536d657 100644 --- a/googletest/include/gtest/internal/gtest-death-test-internal.h +++ b/googletest/include/gtest/internal/gtest-death-test-internal.h @@ -52,9 +52,7 @@ GTEST_DECLARE_string_(internal_run_death_test); namespace testing { namespace internal { -// Names of the flags (needed for parsing Google Test flags). -const char kDeathTestStyleFlag[] = "death_test_style"; -const char kDeathTestUseFork[] = "death_test_use_fork"; +// Name of the flag (needed for parsing Google Test flag). const char kInternalRunDeathTestFlag[] = "internal_run_death_test"; #ifdef GTEST_HAS_DEATH_TEST From 9bb354fa8325fa31faa1e12627b25ab445e6eed3 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 17 Oct 2023 23:50:03 -0700 Subject: [PATCH 77/81] s/::testing::/testing::/ in test documentation outside of using statements to align with best practice PiperOrigin-RevId: 574377544 Change-Id: I0ca69a3bf14cc1aab75784eba220a48bf50cef04 --- docs/primer.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/primer.md b/docs/primer.md index 4901e1ab0..8b98da2a6 100644 --- a/docs/primer.md +++ b/docs/primer.md @@ -210,7 +210,7 @@ objects for several different tests. To create a fixture: -1. Derive a class from `::testing::Test` . Start its body with `protected:`, as +1. Derive a class from `testing::Test` . Start its body with `protected:`, as we'll want to access fixture members from sub-classes. 2. Inside the class, declare any objects you plan to use. 3. If necessary, write a default constructor or `SetUp()` function to prepare @@ -271,7 +271,7 @@ First, define a fixture class. By convention, you should give it the name `FooTest` where `Foo` is the class being tested. ```c++ -class QueueTest : public ::testing::Test { +class QueueTest : public testing::Test { protected: void SetUp() override { // q0_ remains empty @@ -402,7 +402,7 @@ namespace project { namespace { // The fixture for testing class Foo. -class FooTest : public ::testing::Test { +class FooTest : public testing::Test { protected: // You can remove any or all of the following functions if their bodies would // be empty. @@ -450,14 +450,14 @@ TEST_F(FooTest, DoesXyz) { } // namespace my int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } ``` -The `::testing::InitGoogleTest()` function parses the command line for -GoogleTest flags, and removes all recognized flags. This allows the user to -control a test program's behavior via various flags, which we'll cover in the +The `testing::InitGoogleTest()` function parses the command line for GoogleTest +flags, and removes all recognized flags. This allows the user to control a test +program's behavior via various flags, which we'll cover in the [AdvancedGuide](advanced.md). You **must** call this function before calling `RUN_ALL_TESTS()`, or the flags won't be properly initialized. From 116b7e55281c4200151524b093ecc03757a4ffda Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 19 Oct 2023 13:54:41 -0700 Subject: [PATCH 78/81] Improve error message for invalid parameterized test names. PiperOrigin-RevId: 574992011 Change-Id: Id6030a9e5f317966186cc48ef2c09ad97fa15d3e --- googletest/include/gtest/internal/gtest-param-util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h index dd39e98a1..b04f70206 100644 --- a/googletest/include/gtest/internal/gtest-param-util.h +++ b/googletest/include/gtest/internal/gtest-param-util.h @@ -584,8 +584,8 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { GTEST_CHECK_(IsValidParamName(param_name)) << "Parameterized test name '" << param_name - << "' is invalid (contains spaces, dashes, underscores, or " - "non-alphanumeric characters), in " + << "' is invalid (contains spaces, dashes, or any " + "non-alphanumeric characters other than underscores), in " << file << " line " << line << "" << std::endl; GTEST_CHECK_(test_param_names.count(param_name) == 0) From 518387203b573f35477fa6872dd54620e70d2bdb Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Mon, 23 Oct 2023 10:10:45 -0700 Subject: [PATCH 79/81] StartsWith: Explicitly construct matcher-typed strings from matchee parameter The current implementation breaks for absl::string_view on gcc, c++14: https://godbolt.org/z/Tzd3q1fqx Closes #4391 PiperOrigin-RevId: 575853981 Change-Id: I7b782598add480eb69d4ca27ea4a4bf5f758f6a3 --- googlemock/include/gmock/gmock-matchers.h | 4 ++-- googlemock/test/gmock-matchers-comparisons_test.cc | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 0f6771377..8052c74a1 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -1048,7 +1048,7 @@ class StartsWithMatcher { template bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { - const StringType& s2(s); + const StringType s2(s); return s2.length() >= prefix_.length() && s2.substr(0, prefix_.length()) == prefix_; } @@ -1102,7 +1102,7 @@ class EndsWithMatcher { template bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { - const StringType& s2(s); + const StringType s2(s); return s2.length() >= suffix_.length() && s2.substr(s2.length() - suffix_.length()) == suffix_; } diff --git a/googlemock/test/gmock-matchers-comparisons_test.cc b/googlemock/test/gmock-matchers-comparisons_test.cc index b2ce99e18..5b75b457b 100644 --- a/googlemock/test/gmock-matchers-comparisons_test.cc +++ b/googlemock/test/gmock-matchers-comparisons_test.cc @@ -1769,6 +1769,15 @@ TEST(StartsWithTest, CanDescribeSelf) { EXPECT_EQ("starts with \"Hi\"", Describe(m)); } +TEST(StartsWithTest, WorksWithStringMatcherOnStringViewMatchee) { +#if GTEST_INTERNAL_HAS_STRING_VIEW + EXPECT_THAT(internal::StringView("talk to me goose"), + StartsWith(std::string("talk"))); +#else + GTEST_SKIP() << "Not applicable without internal::StringView."; +#endif // GTEST_INTERNAL_HAS_STRING_VIEW +} + // Tests EndsWith(s). TEST(EndsWithTest, MatchesStringWithGivenSuffix) { From 7f036c5563af7d0329f20e8bb42effb04629f0c0 Mon Sep 17 00:00:00 2001 From: Theo Buehler Date: Wed, 25 Oct 2023 07:17:52 +0200 Subject: [PATCH 80/81] Add missing include for raise(3) If SIGTRAP is defined, this file may end up using raise(3), which is defined in csignal, leading to a compilation failure on at least OpenBSD/sparc64 with gcc 8. --- googletest/src/gtest.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 99b22ed32..dcf4e2694 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -43,6 +43,7 @@ #include #include // NOLINT #include +#include #include #include #include From 5b7fd63d6d69f1754d5f3be956949484ebac06d5 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 26 Oct 2023 13:14:13 -0700 Subject: [PATCH 81/81] Export gmock-spec-builders. gmock.h is the umbrella header to be used for rest of the library, and it also enables users to export certain details. This wasn't working for some interfaces like EXPECT_CALL because gmock-spec-builders wasn't explicitly exported. PiperOrigin-RevId: 576966583 Change-Id: Ie050430cf11384977cd95f4ed6e73235d6857057 --- googlemock/include/gmock/gmock.h | 1 + 1 file changed, 1 insertion(+) diff --git a/googlemock/include/gmock/gmock.h b/googlemock/include/gmock/gmock.h index 2ca4f7ac6..c78fb8ee5 100644 --- a/googlemock/include/gmock/gmock.h +++ b/googlemock/include/gmock/gmock.h @@ -60,6 +60,7 @@ #include "gmock/gmock-more-actions.h" // IWYU pragma: export #include "gmock/gmock-more-matchers.h" // IWYU pragma: export #include "gmock/gmock-nice-strict.h" // IWYU pragma: export +#include "gmock/gmock-spec-builders.h" // IWYU pragma: export #include "gmock/internal/gmock-internal-utils.h" #include "gmock/internal/gmock-port.h"