From 3d1dcac4c4662498c3f50fdb35071cce96231850 Mon Sep 17 00:00:00 2001 From: assafpr <93249401+assafpr@users.noreply.github.com> Date: Wed, 22 Jun 2022 14:15:53 +0300 Subject: [PATCH 01/57] change link from master to main in documentation since master branch was changed to main, the links should be changed accordingly. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 30edaecf..788b857a 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ that generates stub code for GoogleTest. ## Contributing Changes Please read -[`CONTRIBUTING.md`](https://github.com/google/googletest/blob/master/CONTRIBUTING.md) +[`CONTRIBUTING.md`](https://github.com/google/googletest/blob/main/CONTRIBUTING.md) for details on how to contribute to this project. Happy testing! From b3f3819a62d2aad678791d64cee0fefb2e921620 Mon Sep 17 00:00:00 2001 From: assafpr <93249401+assafpr@users.noreply.github.com> Date: Wed, 22 Jun 2022 14:21:07 +0300 Subject: [PATCH 02/57] Update gmock_output_test_golden.txt --- googlemock/test/gmock_output_test_golden.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/googlemock/test/gmock_output_test_golden.txt b/googlemock/test/gmock_output_test_golden.txt index fdf224fd..467fa20e 100644 --- a/googlemock/test/gmock_output_test_golden.txt +++ b/googlemock/test/gmock_output_test_golden.txt @@ -75,14 +75,14 @@ GMOCK WARNING: Uninteresting mock function call - returning default value. Function call: Bar2(0, 1) Returns: false -NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md#knowing-when-to-expect for details. +NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details. [ OK ] GMockOutputTest.UninterestingCall [ RUN ] GMockOutputTest.UninterestingCallToVoidFunction GMOCK WARNING: Uninteresting mock function call - returning directly. Function call: Bar3(0, 1) -NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md#knowing-when-to-expect for details. +NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details. [ OK ] GMockOutputTest.UninterestingCallToVoidFunction [ RUN ] GMockOutputTest.RetiredExpectation unknown file: Failure @@ -266,14 +266,14 @@ Uninteresting mock function call - taking default action specified at: FILE:#: Function call: Bar2(2, 2) Returns: true -NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md#knowing-when-to-expect for details. +NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details. GMOCK WARNING: Uninteresting mock function call - taking default action specified at: FILE:#: Function call: Bar2(1, 1) Returns: false -NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md#knowing-when-to-expect for details. +NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details. [ OK ] GMockOutputTest.UninterestingCallWithDefaultAction [ RUN ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction From 358a3f6e3ebba782b0e04011ffb4f4202355fae9 Mon Sep 17 00:00:00 2001 From: assafpr <93249401+assafpr@users.noreply.github.com> Date: Wed, 22 Jun 2022 14:31:03 +0300 Subject: [PATCH 03/57] documentation, change mater branch to main --- docs/samples.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples.md b/docs/samples.md index 2d97ca55..c11177bb 100644 --- a/docs/samples.md +++ b/docs/samples.md @@ -1,7 +1,7 @@ # Googletest Samples If you're like us, you'd like to look at -[googletest samples.](https://github.com/google/googletest/tree/master/googletest/samples) +[googletest samples.](https://github.com/google/googletest/tree/main/googletest/samples) The sample directory has a number of well-commented samples showing how to use a variety of googletest features. From 1b772a9bc4aad97764840000c52309de42d7ae48 Mon Sep 17 00:00:00 2001 From: assafpr <93249401+assafpr@users.noreply.github.com> Date: Wed, 22 Jun 2022 14:36:10 +0300 Subject: [PATCH 04/57] documentation, change mater branch to main --- docs/_layouts/default.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_layouts/default.html b/docs/_layouts/default.html index dcb42d91..c7f331b8 100644 --- a/docs/_layouts/default.html +++ b/docs/_layouts/default.html @@ -48,7 +48,7 @@ From f2f099fb7034370927ff8b62ce7892c485a8565a Mon Sep 17 00:00:00 2001 From: assafpr <93249401+assafpr@users.noreply.github.com> Date: Wed, 22 Jun 2022 16:09:54 +0300 Subject: [PATCH 05/57] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b3f50436..3aba7f6c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -80,7 +80,7 @@ fairly rigid coding style, as defined by the [google-styleguide](https://github.com/google/styleguide) project. All patches will be expected to conform to the style outlined [here](https://google.github.io/styleguide/cppguide.html). Use -[.clang-format](https://github.com/google/googletest/blob/master/.clang-format) +[.clang-format](https://github.com/google/googletest/blob/main/.clang-format) to check your formatting. ## Requirements for Contributors From b59ae848d16b3f3f5f20e38f91c70d748fe733f2 Mon Sep 17 00:00:00 2001 From: assafpr <93249401+assafpr@users.noreply.github.com> Date: Wed, 22 Jun 2022 16:12:54 +0300 Subject: [PATCH 06/57] Update faq.md --- docs/faq.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/faq.md b/docs/faq.md index c849aff9..19280972 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -267,7 +267,7 @@ If necessary, you can continue to derive test fixtures from a derived fixture. GoogleTest has no limit on how deep the hierarchy can be. For a complete example using derived test fixtures, see -[sample5_unittest.cc](https://github.com/google/googletest/blob/master/googletest/samples/sample5_unittest.cc). +[sample5_unittest.cc](https://github.com/google/googletest/blob/main/googletest/samples/sample5_unittest.cc). ## My compiler complains "void value not ignored as it ought to be." What does this mean? From fde6af67908ce431d7c08fa81781978b988fdb73 Mon Sep 17 00:00:00 2001 From: assafpr <93249401+assafpr@users.noreply.github.com> Date: Wed, 22 Jun 2022 16:21:35 +0300 Subject: [PATCH 07/57] documentation, change mater branch to main --- googletest/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/README.md b/googletest/README.md index d26b309e..60aaede4 100644 --- a/googletest/README.md +++ b/googletest/README.md @@ -9,7 +9,7 @@ depends on which build system you use, and is usually straightforward. ### Build with CMake GoogleTest comes with a CMake build script -([CMakeLists.txt](https://github.com/google/googletest/blob/master/CMakeLists.txt)) +([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 . @@ -140,7 +140,7 @@ command line. Generally, these macros are named like `GTEST_XYZ` and you define them to either 1 or 0 to enable or disable a certain feature. We list the most frequently used macros below. For a complete list, see file -[include/gtest/internal/gtest-port.h](https://github.com/google/googletest/blob/master/googletest/include/gtest/internal/gtest-port.h). +[include/gtest/internal/gtest-port.h](https://github.com/google/googletest/blob/main/googletest/include/gtest/internal/gtest-port.h). ### Multi-threaded Tests From 72901486ba39f8f4df9d0386b0521b711ef374a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Travert?= Date: Sun, 26 Jun 2022 18:59:46 +0200 Subject: [PATCH 08/57] Avoid implicit conversion from int to char --- googlemock/src/gmock-internal-utils.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc index 0a74841f..2d7c5c4e 100644 --- a/googlemock/src/gmock-internal-utils.cc +++ b/googlemock/src/gmock-internal-utils.cc @@ -201,7 +201,7 @@ GTEST_API_ void IllegalDoDefault(const char* file, int line) { constexpr char UnBase64Impl(char c, const char* const base64, char carry) { return *base64 == 0 ? static_cast(65) : *base64 == c ? carry - : UnBase64Impl(c, base64 + 1, carry + 1); + : UnBase64Impl(c, base64 + 1, static_cast(carry + 1)); } template From 5eaa1139038076ed9bc029ab6518844a1b03ea7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Travert?= Date: Sun, 26 Jun 2022 19:01:00 +0200 Subject: [PATCH 09/57] Avoid implicit conversion from int to char --- googletest/src/gtest-printers.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/src/gtest-printers.cc b/googletest/src/gtest-printers.cc index f3976d23..d475ad36 100644 --- a/googletest/src/gtest-printers.cc +++ b/googletest/src/gtest-printers.cc @@ -315,7 +315,7 @@ void PrintTo(__uint128_t v, ::std::ostream* os) { low = low / 10 + high_mod * 1844674407370955161 + carry / 10; char digit = static_cast(carry % 10); - *--p = '0' + digit; + *--p = static_cast('0' + digit); } *os << p; } From df4b8edee0928a080852237c9a3443aaa68af7b9 Mon Sep 17 00:00:00 2001 From: assafpr <93249401+assafpr@users.noreply.github.com> Date: Mon, 27 Jun 2022 09:48:05 +0300 Subject: [PATCH 10/57] Update advanced.md master branch changed to main branch in links --- docs/advanced.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/advanced.md b/docs/advanced.md index 9a752b92..bce983c6 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -1142,8 +1142,8 @@ GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FooTest); You can see [sample7_unittest.cc] and [sample8_unittest.cc] for more examples. -[sample7_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample7_unittest.cc "Parameterized Test example" -[sample8_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample8_unittest.cc "Parameterized Test example with multiple parameters" +[sample7_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample7_unittest.cc "Parameterized Test example" +[sample8_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample8_unittest.cc "Parameterized Test example with multiple parameters" ### Creating Value-Parameterized Abstract Tests @@ -1294,7 +1294,7 @@ TYPED_TEST(FooTest, HasPropertyA) { ... } You can see [sample6_unittest.cc] for a complete example. -[sample6_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample6_unittest.cc "Typed Test example" +[sample6_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample6_unittest.cc "Typed Test example" ## Type-Parameterized Tests @@ -1733,7 +1733,7 @@ You can do so by adding one line: Now, sit back and enjoy a completely different output from your tests. For more details, see [sample9_unittest.cc]. -[sample9_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample9_unittest.cc "Event listener example" +[sample9_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample9_unittest.cc "Event listener example" You may append more than one listener to the list. When an `On*Start()` or `OnTestPartResult()` event is fired, the listeners will receive it in the order @@ -1760,7 +1760,7 @@ by the former. See [sample10_unittest.cc] for an example of a failure-raising listener. -[sample10_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample10_unittest.cc "Failure-raising listener example" +[sample10_unittest.cc]: https://github.com/google/googletest/blob/main/googletest/samples/sample10_unittest.cc "Failure-raising listener example" ## Running Test Programs: Advanced Options From dfa990f9426797abfc10e2ec02ff9ccdbe8b4619 Mon Sep 17 00:00:00 2001 From: assafpr <93249401+assafpr@users.noreply.github.com> Date: Mon, 27 Jun 2022 09:50:36 +0300 Subject: [PATCH 11/57] Update gmock-spec-builders.cc --- googlemock/src/gmock-spec-builders.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 658ad3fa..78fbdfaa 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -295,7 +295,7 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) { "call should not happen. Do not suppress it by blindly adding " "an EXPECT_CALL() if you don't mean to enforce the call. " "See " - "https://github.com/google/googletest/blob/master/docs/" + "https://github.com/google/googletest/blob/main/docs/" "gmock_cook_book.md#" "knowing-when-to-expect for details.\n", stack_frames_to_skip); From 64df55449acb3b0c2e9de2ded58def728f8e3114 Mon Sep 17 00:00:00 2001 From: assafpr <93249401+assafpr@users.noreply.github.com> Date: Mon, 27 Jun 2022 09:51:44 +0300 Subject: [PATCH 12/57] Update gtest-death-test.cc --- googletest/src/gtest-death-test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index e6abc627..5c9d3f23 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -249,7 +249,7 @@ static std::string DeathTestThreadWarning(size_t thread_count) { msg << "detected " << thread_count << " threads."; } msg << " See " - "https://github.com/google/googletest/blob/master/docs/" + "https://github.com/google/googletest/blob/main/docs/" "advanced.md#death-tests-and-threads" << " for more explanation and suggested solutions, especially if" << " this is the last message you see before your test times out."; From 66d2463610e5db956e742e4267312169b0a84958 Mon Sep 17 00:00:00 2001 From: assafpr <93249401+assafpr@users.noreply.github.com> Date: Mon, 27 Jun 2022 09:53:40 +0300 Subject: [PATCH 13/57] Update gmock-spec-builders_test.cc master branch changed to main in link --- 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 122d5b94..bb1e83ef 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -2059,7 +2059,7 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture { "call should not happen. Do not suppress it by blindly adding " "an EXPECT_CALL() if you don't mean to enforce the call. " "See " - "https://github.com/google/googletest/blob/master/docs/" + "https://github.com/google/googletest/blob/main/docs/" "gmock_cook_book.md#" "knowing-when-to-expect for details."; From 1547c2acc833f53263b23fdea7fe1eeddd792933 Mon Sep 17 00:00:00 2001 From: assafpr <93249401+assafpr@users.noreply.github.com> Date: Mon, 27 Jun 2022 09:55:28 +0300 Subject: [PATCH 14/57] Update gmock-actions.h master branch changed to main in links --- googlemock/include/gmock/gmock-actions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index c785ad8a..7e78c09a 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -122,7 +122,7 @@ // MORE INFORMATION: // // To learn more about using these macros, please search for 'ACTION' on -// https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md +// https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md // IWYU pragma: private, include "gmock/gmock.h" // IWYU pragma: friend gmock/.* From d0af91ead3983b0eacae3efa5bf3a2b368141bb0 Mon Sep 17 00:00:00 2001 From: assafpr <93249401+assafpr@users.noreply.github.com> Date: Mon, 27 Jun 2022 09:56:59 +0300 Subject: [PATCH 15/57] Update gmock-matchers.h branch master changed to main on link --- googlemock/include/gmock/gmock-matchers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 62829011..186a95ca 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -240,7 +240,7 @@ // // To learn more about using these macros, please search for 'MATCHER' // on -// https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md +// https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md // // This file also implements some commonly used argument matchers. More // matchers can be defined by the user implementing the From dd72ed19fe52f2dbca3b354d9a49eb4124693b99 Mon Sep 17 00:00:00 2001 From: assafpr <93249401+assafpr@users.noreply.github.com> Date: Mon, 27 Jun 2022 09:59:06 +0300 Subject: [PATCH 16/57] Update gtest.cc fix a broken link --- googletest/src/gtest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 6f31dd22..1b9c51be 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -6037,7 +6037,7 @@ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) { // each TestSuite and TestInfo object. // If shard_tests == true, further filters tests based on sharding // variables in the environment - see -// https://github.com/google/googletest/blob/master/googletest/docs/advanced.md +// https://github.com/google/googletest/blob/main/docs/advanced.md // . Returns the number of tests that should run. int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) { const int32_t total_shards = shard_tests == HONOR_SHARDING_PROTOCOL From 61720589cbef9707b3c5247d02141a7c31e2876f Mon Sep 17 00:00:00 2001 From: Matei Dibu Date: Wed, 20 Jul 2022 19:16:51 +0300 Subject: [PATCH 17/57] gtest-death-test: add 'noreturn' --- googletest/src/gtest-death-test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index e6abc627..d549e83d 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -284,7 +284,7 @@ enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW }; // message is propagated back to the parent process. Otherwise, the // message is simply printed to stderr. In either case, the program // then exits with status 1. -static void DeathTestAbort(const std::string& message) { +[[noreturn]] static void DeathTestAbort(const std::string& message) { // On a POSIX system, this function may be called from a threadsafe-style // death test child process, which operates on a very small stack. Use // the heap for any additional non-minuscule memory requirements. From aa2e91fd6918519dafa3bee4aa706d04857e7d06 Mon Sep 17 00:00:00 2001 From: Yuriy Chernyshov Date: Thu, 21 Jul 2022 14:25:43 +0300 Subject: [PATCH 18/57] Continuation for #3183 Some of the #ifdefs were missed in original PR. Should be fixed now. --- 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 a91e8b8b..8e4d2953 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -384,7 +384,7 @@ GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char32_t); GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string); GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string); -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char8_t, ::std::u8string); GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char8_t, ::std::u8string); #endif @@ -556,7 +556,7 @@ inline void PrintTo(const ::std::string& s, ::std::ostream* os) { } // Overloads for ::std::u8string -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t GTEST_API_ void PrintU8StringTo(const ::std::u8string& s, ::std::ostream* os); inline void PrintTo(const ::std::u8string& s, ::std::ostream* os) { PrintU8StringTo(s, os); From b1e9b6323a17002b8359fef338c57bc0437caf57 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Mon, 25 Jul 2022 14:37:44 -0700 Subject: [PATCH 19/57] Add IsEmpty overload for C-style strings Fixes #3937 PiperOrigin-RevId: 463180144 Change-Id: I21b528acc4c3f3aba4234642be01fcead7fe7f00 --- .../include/gmock/gmock-more-matchers.h | 45 ++++++++++++++++--- .../test/gmock-matchers-comparisons_test.cc | 26 +++++++++++ 2 files changed, 64 insertions(+), 7 deletions(-) diff --git a/googlemock/include/gmock/gmock-more-matchers.h b/googlemock/include/gmock/gmock-more-matchers.h index 47aaf984..d9a92107 100644 --- a/googlemock/include/gmock/gmock-more-matchers.h +++ b/googlemock/include/gmock/gmock-more-matchers.h @@ -40,6 +40,9 @@ #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_ #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_ +#include +#include + #include "gmock/gmock-matchers.h" namespace testing { @@ -56,14 +59,42 @@ namespace testing { #endif #endif -// Defines a matcher that matches an empty container. The container must -// support both size() and empty(), which all STL-like containers provide. -MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { - if (arg.empty()) { - return true; +namespace internal { + +// Implements the polymorphic IsEmpty matcher, which +// can be used as a Matcher as long as T is either a container that defines +// empty() and size() (e.g. std::vector or std::string), or a C-style string. +class IsEmptyMatcher { + public: + // Matches anything that defines empty() and size(). + template + bool MatchAndExplain(const MatcheeContainerType& c, + MatchResultListener* listener) const { + if (c.empty()) { + return true; + } + *listener << "whose size is " << c.size(); + return false; } - *result_listener << "whose size is " << arg.size(); - return false; + + // Matches C-style strings. + bool MatchAndExplain(const char* s, MatchResultListener* listener) const { + return MatchAndExplain(std::string(s), listener); + } + + // Describes what this matcher matches. + void DescribeTo(std::ostream* os) const { *os << "is empty"; } + + void DescribeNegationTo(std::ostream* os) const { *os << "isn't empty"; } +}; + +} // namespace internal + +// Creates a polymorphic matcher that matches an empty container or C-style +// string. The container must support both size() and empty(), which all +// STL-like containers provide. +inline PolymorphicMatcher IsEmpty() { + return MakePolymorphicMatcher(internal::IsEmptyMatcher()); } // Define a matcher that matches a value that evaluates in boolean diff --git a/googlemock/test/gmock-matchers-comparisons_test.cc b/googlemock/test/gmock-matchers-comparisons_test.cc index eb8f3f63..c90b0b4e 100644 --- a/googlemock/test/gmock-matchers-comparisons_test.cc +++ b/googlemock/test/gmock-matchers-comparisons_test.cc @@ -39,6 +39,8 @@ #pragma warning(disable : 4100) #endif +#include + #include "test/gmock-matchers_test.h" namespace testing { @@ -983,6 +985,30 @@ TEST(ComparisonBaseTest, WorksWithMoveOnly) { helper.Call(MoveOnly(1)); } +TEST(IsEmptyTest, MatchesContainer) { + const Matcher> m = IsEmpty(); + std::vector a = {}; + std::vector b = {1}; + EXPECT_TRUE(m.Matches(a)); + EXPECT_FALSE(m.Matches(b)); +} + +TEST(IsEmptyTest, MatchesStdString) { + const Matcher m = IsEmpty(); + std::string a = "z"; + std::string b = ""; + EXPECT_FALSE(m.Matches(a)); + EXPECT_TRUE(m.Matches(b)); +} + +TEST(IsEmptyTest, MatchesCString) { + const Matcher m = IsEmpty(); + const char a[] = ""; + const char b[] = "x"; + EXPECT_TRUE(m.Matches(a)); + EXPECT_FALSE(m.Matches(b)); +} + // Tests that IsNull() matches any NULL pointer of any type. TEST(IsNullTest, MatchesNullPointer) { Matcher m1 = IsNull(); From dd7a9d29a33de34836c345c3b753d4eba15c5f44 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 28 Jul 2022 17:14:35 -0700 Subject: [PATCH 20/57] Add support of 18-member structs to gmock UnpackStructImpl. PiperOrigin-RevId: 463961734 Change-Id: Ib62e320a745c190955f181c1f4f12e4cd407ef22 --- googlemock/include/gmock/gmock-matchers.h | 9 +++++++-- googlemock/test/gmock-matchers-comparisons_test.cc | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 3c8cc32e..f45ace18 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -3240,6 +3240,11 @@ auto UnpackStructImpl(const T& t, MakeIndexSequence<17>, char) { const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q] = t; return std::tie(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q); } +template +auto UnpackStructImpl(const T& t, MakeIndexSequence<18>, char) { + const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r] = t; + return std::tie(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r); +} #endif // defined(__cpp_structured_bindings) template @@ -3306,8 +3311,8 @@ class FieldsAreMatcherImpl> std::vector inner_listener(sizeof...(I)); VariadicExpand( - {failed_pos == ~size_t{} && !std::get(matchers_).MatchAndExplain( - std::get(tuple), &inner_listener[I]) + {failed_pos == ~size_t{}&& !std::get(matchers_).MatchAndExplain( + std::get(tuple), &inner_listener[I]) ? failed_pos = I : 0 ...}); if (failed_pos != ~size_t{}) { diff --git a/googlemock/test/gmock-matchers-comparisons_test.cc b/googlemock/test/gmock-matchers-comparisons_test.cc index c90b0b4e..1c6cac62 100644 --- a/googlemock/test/gmock-matchers-comparisons_test.cc +++ b/googlemock/test/gmock-matchers-comparisons_test.cc @@ -1710,6 +1710,16 @@ TEST(FieldsAreTest, StructuredBindings) { }; EXPECT_THAT(MyVarType16{}, FieldsAre(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + struct MyVarType17 { + int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q; + }; + EXPECT_THAT(MyVarType17{}, + FieldsAre(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + struct MyVarType18 { + int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r; + }; + EXPECT_THAT(MyVarType18{}, + FieldsAre(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); } #endif From 3280a930bf3f2fdb77da9a6cdf5866ef22708ff1 Mon Sep 17 00:00:00 2001 From: Baruch Burstein Date: Sun, 31 Jul 2022 22:50:04 +0300 Subject: [PATCH 21/57] Custom type with Combine(). Fix for #3781 --- docs/reference/testing.md | 1 + googletest/include/gtest/gtest-param-test.h | 40 ++++++++++ googletest/include/gtest/gtest.h | 2 +- .../include/gtest/internal/gtest-param-util.h | 71 +++++++++++++++++ googletest/test/googletest-param-test-test.cc | 76 ++++++++++++++++--- 5 files changed, 180 insertions(+), 10 deletions(-) diff --git a/docs/reference/testing.md b/docs/reference/testing.md index dc479423..877dfa32 100644 --- a/docs/reference/testing.md +++ b/docs/reference/testing.md @@ -109,6 +109,7 @@ namespace: | `ValuesIn(container)` or `ValuesIn(begin,end)` | Yields values from a C-style array, an STL-style container, or an iterator range `[begin, end)`. | | `Bool()` | Yields sequence `{false, true}`. | | `Combine(g1, g2, ..., gN)` | Yields as `std::tuple` *n*-tuples all combinations (Cartesian product) of the values generated by the given *n* generators `g1`, `g2`, ..., `gN`. | +| `ConvertGenerator(g)` | Yields values generated by generator `g`, `static_cast` to `T`. | The optional last argument *`name_generator`* is a function or functor that generates custom test name suffixes based on the test parameters. The function diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index b55119ac..d59e552e 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -407,6 +407,46 @@ internal::CartesianProductHolder Combine(const Generator&... g) { return internal::CartesianProductHolder(g...); } +// ConvertGenerator() wraps a parameter generator in order to cast each prduced +// value through a known type before supplying it to the test suite +// +// Synopsis: +// ConvertGenerator(gen) +// - returns a generator producing the same elements as generated by gen, but +// each element is static_cast to type T before being returned +// +// It is useful when using the Combine() function to get the generated +// parameters in a custom type instead of std::tuple +// +// Example: +// +// This will instantiate tests in test suite AnimalTest each one with +// the parameter values tuple("cat", BLACK), tuple("cat", WHITE), +// tuple("dog", BLACK), and tuple("dog", WHITE): +// +// enum Color { BLACK, GRAY, WHITE }; +// struct ParamType { +// using TupleT = std::tuple; +// std::string animal; +// Color color; +// ParamType(TupleT t) : animal(std::get<0>(t)), color(std::get<1>(t)) {} +// }; +// class AnimalTest +// : public testing::TestWithParam {...}; +// +// TEST_P(AnimalTest, AnimalLooksNice) {...} +// +// INSTANTIATE_TEST_SUITE_P(AnimalVariations, AnimalTest, +// ConvertGenerator( +// Combine(Values("cat", "dog"), +// Values(BLACK, WHITE)))); +// +template +internal::ParamConverterGenerator ConvertGenerator( + internal::ParamGenerator gen) { + return internal::ParamConverterGenerator(gen); +} + #define TEST_P(test_suite_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ : public test_suite_name { \ diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index d19a587a..0c97f6c9 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -1625,7 +1625,7 @@ class GTEST_API_ AssertHelper { // the GetParam() method. // // Use it with one of the parameter generator defining functions, like Range(), -// Values(), ValuesIn(), Bool(), and Combine(). +// Values(), ValuesIn(), Bool(), Combine(), and ConvertGenerator(). // // class FooTest : public ::testing::TestWithParam { // protected: diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h index e7af2f90..c643a3bd 100644 --- a/googletest/include/gtest/internal/gtest-param-util.h +++ b/googletest/include/gtest/internal/gtest-param-util.h @@ -950,6 +950,77 @@ class CartesianProductHolder { std::tuple generators_; }; +template +class ParamGeneratorConverter : public ParamGeneratorInterface { + public: + ParamGeneratorConverter(ParamGenerator gen) + : generator_(std::move(gen)) {} + + ParamIteratorInterface* Begin() const override { + return new Iterator(this, generator_.begin(), generator_.end()); + } + ParamIteratorInterface* End() const override { + return new Iterator(this, generator_.end(), generator_.end()); + } + + private: + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, ParamIterator it, + ParamIterator end) + : base_(base), it_(it), end_(end) { + if (it_ != end_) value_ = std::make_shared(static_cast(*it_)); + } + ~Iterator() override {} + + const ParamGeneratorInterface* BaseGenerator() const override { + return base_; + } + void Advance() override { + ++it_; + if (it_ != end_) value_ = std::make_shared(static_cast(*it_)); + } + ParamIteratorInterface* Clone() const override { + return new Iterator(*this); + } + const To* Current() const override { return value_.get(); } + bool Equals(const ParamIteratorInterface& other) const override { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const ParamIterator other_it = + CheckedDowncastToActualType(&other)->it_; + return it_ == other_it; + } + + private: + Iterator(const Iterator& other) = default; + + const ParamGeneratorInterface* const base_; + ParamIterator it_; + ParamIterator end_; + std::shared_ptr value_; + }; // class ParamGeneratorConverter::Iterator + + ParamGenerator generator_; +}; // class ParamGeneratorConverter + +template +class ParamConverterGenerator { + public: + ParamConverterGenerator(ParamGenerator g) : generator(g) {} + + template + operator ParamGenerator() const { + return ParamGenerator(new ParamGeneratorConverter(generator)); + } + + private: + ParamGenerator generator; +}; + } // namespace internal } // namespace testing diff --git a/googletest/test/googletest-param-test-test.cc b/googletest/test/googletest-param-test-test.cc index e3090ae4..a1d27864 100644 --- a/googletest/test/googletest-param-test-test.cc +++ b/googletest/test/googletest-param-test-test.cc @@ -51,6 +51,7 @@ using ::std::vector; using ::testing::AddGlobalTestEnvironment; using ::testing::Bool; using ::testing::Combine; +using ::testing::ConvertGenerator; using ::testing::Message; using ::testing::Range; using ::testing::TestWithParam; @@ -402,7 +403,7 @@ TEST(BoolTest, BoolWorks) { TEST(CombineTest, CombineWithTwoParameters) { const char* foo = "foo"; const char* bar = "bar"; - const ParamGenerator > gen = + const ParamGenerator> gen = Combine(Values(foo, bar), Values(3, 4)); std::tuple expected_values[] = { @@ -413,7 +414,7 @@ TEST(CombineTest, CombineWithTwoParameters) { // Tests that Combine() with three parameters generates the expected sequence. TEST(CombineTest, CombineWithThreeParameters) { - const ParamGenerator > gen = + const ParamGenerator> gen = Combine(Values(0, 1), Values(3, 4), Values(5, 6)); std::tuple expected_values[] = { std::make_tuple(0, 3, 5), std::make_tuple(0, 3, 6), @@ -427,7 +428,7 @@ TEST(CombineTest, CombineWithThreeParameters) { // sequence generates a sequence with the number of elements equal to the // number of elements in the sequence generated by the second parameter. TEST(CombineTest, CombineWithFirstParameterSingleValue) { - const ParamGenerator > gen = + const ParamGenerator> gen = Combine(Values(42), Values(0, 1)); std::tuple expected_values[] = {std::make_tuple(42, 0), @@ -439,7 +440,7 @@ TEST(CombineTest, CombineWithFirstParameterSingleValue) { // sequence generates a sequence with the number of elements equal to the // number of elements in the sequence generated by the first parameter. TEST(CombineTest, CombineWithSecondParameterSingleValue) { - const ParamGenerator > gen = + const ParamGenerator> gen = Combine(Values(0, 1), Values(42)); std::tuple expected_values[] = {std::make_tuple(0, 42), @@ -450,7 +451,7 @@ TEST(CombineTest, CombineWithSecondParameterSingleValue) { // Tests that when the first parameter produces an empty sequence, // Combine() produces an empty sequence, too. TEST(CombineTest, CombineWithFirstParameterEmptyRange) { - const ParamGenerator > gen = + const ParamGenerator> gen = Combine(Range(0, 0), Values(0, 1)); VerifyGeneratorIsEmpty(gen); } @@ -458,7 +459,7 @@ TEST(CombineTest, CombineWithFirstParameterEmptyRange) { // Tests that when the second parameter produces an empty sequence, // Combine() produces an empty sequence, too. TEST(CombineTest, CombineWithSecondParameterEmptyRange) { - const ParamGenerator > gen = + const ParamGenerator> gen = Combine(Values(0, 1), Range(1, 1)); VerifyGeneratorIsEmpty(gen); } @@ -469,7 +470,7 @@ TEST(CombineTest, CombineWithMaxNumberOfParameters) { const char* foo = "foo"; const char* bar = "bar"; const ParamGenerator< - std::tuple > + std::tuple> gen = Combine(Values(foo, bar), Values(1), Values(2), Values(3), Values(4), Values(5), Values(6), Values(7), Values(8), Values(9)); @@ -497,11 +498,11 @@ class NonDefaultConstructAssignString { }; TEST(CombineTest, NonDefaultConstructAssign) { - const ParamGenerator > gen = + const ParamGenerator> gen = Combine(Values(0, 1), Values(NonDefaultConstructAssignString("A"), NonDefaultConstructAssignString("B"))); - ParamGenerator >::iterator + ParamGenerator>::iterator it = gen.begin(); EXPECT_EQ(0, std::get<0>(*it)); @@ -523,6 +524,63 @@ TEST(CombineTest, NonDefaultConstructAssign) { EXPECT_TRUE(it == gen.end()); } +template +class ConstructFromT { + public: + ConstructFromT(const T& t) : t_(t) {} + template + ConstructFromT(Args&&... args) : t_(std::forward(args)...) {} + + bool operator==(const ConstructFromT& other) const { return other.t_ == t_; } + + const T& get() const { return t_; } + + private: + T t_; +}; + +TEST(ConvertTest, CombineWithTwoParameters) { + const char* foo = "foo"; + const char* bar = "bar"; + const ParamGenerator>> gen = + ConvertGenerator>( + Combine(Values(foo, bar), Values(3, 4))); + + ConstructFromT> expected_values[] = { + {foo, 3}, {foo, 4}, {bar, 3}, {bar, 4}}; + VerifyGenerator(gen, expected_values); +} + +TEST(ConvertTest, NonDefaultConstructAssign) { + const ParamGenerator< + ConstructFromT>> + gen = ConvertGenerator>( + Combine(Values(0, 1), Values(NonDefaultConstructAssignString("A"), + NonDefaultConstructAssignString("B")))); + + ParamGenerator>>::iterator it = + gen.begin(); + + EXPECT_EQ(0, std::get<0>(it->get())); + EXPECT_EQ("A", std::get<1>(it->get()).str()); + ++it; + + EXPECT_EQ(0, std::get<0>(it->get())); + EXPECT_EQ("B", std::get<1>(it->get()).str()); + ++it; + + EXPECT_EQ(1, std::get<0>(it->get())); + EXPECT_EQ("A", std::get<1>(it->get()).str()); + ++it; + + EXPECT_EQ(1, std::get<0>(it->get())); + EXPECT_EQ("B", std::get<1>(it->get()).str()); + ++it; + + EXPECT_TRUE(it == gen.end()); +} + // Tests that an generator produces correct sequence after being // assigned from another generator. TEST(ParamGeneratorTest, AssignmentWorks) { From 5b909beeec178f338be997830b6c31a80cda7a93 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Thu, 4 Aug 2022 10:53:26 -0700 Subject: [PATCH 22/57] Explicitly instantiate matchee std::string in MatchesRegex If this ever turns out to be a performance issue, we could use std::conditional and std::is_same to avoid copying std::strings. Fixes #3949 PiperOrigin-RevId: 465353572 Change-Id: If2d691bccb626c692c87e006df5afe88a4ed1542 --- googletest/include/gtest/gtest-matchers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/include/gtest/gtest-matchers.h b/googletest/include/gtest/gtest-matchers.h index bffa00c5..4a60b0d0 100644 --- a/googletest/include/gtest/gtest-matchers.h +++ b/googletest/include/gtest/gtest-matchers.h @@ -842,7 +842,7 @@ class MatchesRegexMatcher { template bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { - const std::string& s2(s); + const std::string s2(s); return full_match_ ? RE::FullMatch(s2, *regex_) : RE::PartialMatch(s2, *regex_); } From 4c9a3bb62bf3ba1f1010bf96f9c8ed767b363774 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Mon, 8 Aug 2022 11:47:36 -0700 Subject: [PATCH 23/57] gtest_unittest: Call FAIL() in lambda, fix incorrect fatality expectation FAIL() evaluates into a return statement: https://github.com/google/googletest/blob/5b909beeec178f338be997830b6c31a80cda7a93/googletest/include/gtest/internal/gtest-internal.h#L1347 Calling it from the body of the test case turns all subsequent expectations into no-ops. Fixes #3941 PiperOrigin-RevId: 466104977 Change-Id: Ic15f43acb734295a5c9690a2b5eec6f65e8c0814 --- googletest/test/gtest_unittest.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index b579e81e..329ca546 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -3454,10 +3454,10 @@ TEST_F(NoFatalFailureTest, MessageIsStreamable) { TestPartResultArray gtest_failures; { ScopedFakeTestPartResultReporter gtest_reporter(>est_failures); - EXPECT_NO_FATAL_FAILURE(FAIL() << "foo") << "my message"; + EXPECT_NO_FATAL_FAILURE([] { FAIL() << "foo"; }()) << "my message"; } ASSERT_EQ(2, gtest_failures.size()); - EXPECT_EQ(TestPartResult::kNonFatalFailure, + EXPECT_EQ(TestPartResult::kFatalFailure, gtest_failures.GetTestPartResult(0).type()); EXPECT_EQ(TestPartResult::kNonFatalFailure, gtest_failures.GetTestPartResult(1).type()); From 7274ec186442c96e4c7dcc99c684a03e5db2ff48 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Fri, 12 Aug 2022 10:46:04 -0700 Subject: [PATCH 24/57] Add --features=external_include_paths to Bazel CI to ignore warnings from dependencies PiperOrigin-RevId: 467244441 Change-Id: Iefa65474d8c62e7c4c942957dc8e275715076e5f --- .github/workflows/gtest-ci.yml | 6 +++--- ci/linux-presubmit.sh | 3 +++ ci/macos-presubmit.sh | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gtest-ci.yml b/.github/workflows/gtest-ci.yml index 036c392f..b2dcab49 100644 --- a/.github/workflows/gtest-ci.yml +++ b/.github/workflows/gtest-ci.yml @@ -17,7 +17,7 @@ jobs: fetch-depth: 0 - name: Tests - run: bazel test --test_output=errors //... + run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ... MacOs: runs-on: macos-latest @@ -28,7 +28,7 @@ jobs: fetch-depth: 0 - name: Tests - run: bazel test --test_output=errors //... + run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ... Windows: @@ -40,4 +40,4 @@ jobs: fetch-depth: 0 - name: Tests - run: bazel test --test_output=errors //... + run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ... diff --git a/ci/linux-presubmit.sh b/ci/linux-presubmit.sh index f7e0f465..4eb5bbe4 100644 --- a/ci/linux-presubmit.sh +++ b/ci/linux-presubmit.sh @@ -80,6 +80,7 @@ time docker run \ --copt="-Wuninitialized" \ --copt="-Wno-error=pragmas" \ --distdir="/bazel-distdir" \ + --features=external_include_paths \ --keep_going \ --show_timestamps \ --test_output=errors @@ -100,6 +101,7 @@ for std in ${STD}; do --copt="-Wuninitialized" \ --define="absl=${absl}" \ --distdir="/bazel-distdir" \ + --features=external_include_paths \ --keep_going \ --show_timestamps \ --test_output=errors @@ -123,6 +125,7 @@ for std in ${STD}; do --copt="-Wuninitialized" \ --define="absl=${absl}" \ --distdir="/bazel-distdir" \ + --features=external_include_paths \ --keep_going \ --linkopt="--gcc-toolchain=/usr/local" \ --show_timestamps \ diff --git a/ci/macos-presubmit.sh b/ci/macos-presubmit.sh index 3b711da5..8f35df58 100644 --- a/ci/macos-presubmit.sh +++ b/ci/macos-presubmit.sh @@ -68,6 +68,7 @@ for absl in 0 1; do --copt="-Werror" \ --cxxopt="-std=c++14" \ --define="absl=${absl}" \ + --features=external_include_paths \ --keep_going \ --show_timestamps \ --test_output=errors From c0e032efe587efa99413dd9ac54c3953a7915588 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Tue, 16 Aug 2022 10:23:11 -0700 Subject: [PATCH 25/57] Update README.md to point to the Foundational C++ Support Policy PiperOrigin-RevId: 467959285 Change-Id: Ibd92b3a278f293736b31bd7e07fe502241bb1f05 --- README.md | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 5061357e..cd89abb2 100644 --- a/README.md +++ b/README.md @@ -59,39 +59,12 @@ More information about building GoogleTest can be found at ## Supported Platforms -GoogleTest requires a codebase and compiler compliant with the C++14 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/) - -**Note:** 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. ## Who Is Using GoogleTest? From 91c3669f21cf569f13bd15569b5411e6ca9a8961 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 19 Aug 2022 11:10:56 -0700 Subject: [PATCH 26/57] bazel: move -std=c++14 to .bazelrc Bazel defaults to -std=c++11 on macOS which gtest doesn't support. --- .bazelrc | 1 + .github/workflows/gtest-ci.yml | 9 +++------ ci/linux-presubmit.sh | 1 - ci/macos-presubmit.sh | 1 - 4 files changed, 4 insertions(+), 8 deletions(-) create mode 100644 .bazelrc diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000..f93facf0 --- /dev/null +++ b/.bazelrc @@ -0,0 +1 @@ +build --cxxopt=-std=c++14 diff --git a/.github/workflows/gtest-ci.yml b/.github/workflows/gtest-ci.yml index b2dcab49..e61880f9 100644 --- a/.github/workflows/gtest-ci.yml +++ b/.github/workflows/gtest-ci.yml @@ -4,9 +4,6 @@ on: push: pull_request: -env: - BAZEL_CXXOPTS: -std=c++14 - jobs: Linux: runs-on: ubuntu-latest @@ -17,7 +14,7 @@ jobs: fetch-depth: 0 - name: Tests - run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ... + run: bazel test --features=external_include_paths --test_output=errors ... MacOs: runs-on: macos-latest @@ -28,7 +25,7 @@ jobs: fetch-depth: 0 - name: Tests - run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ... + run: bazel test --features=external_include_paths --test_output=errors ... Windows: @@ -40,4 +37,4 @@ jobs: fetch-depth: 0 - name: Tests - run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ... + run: bazel test --features=external_include_paths --test_output=errors ... diff --git a/ci/linux-presubmit.sh b/ci/linux-presubmit.sh index 4eb5bbe4..f6eb9b7d 100644 --- a/ci/linux-presubmit.sh +++ b/ci/linux-presubmit.sh @@ -72,7 +72,6 @@ time docker run \ --workdir="/src" \ --rm \ --env="CC=/usr/local/bin/gcc" \ - --env="BAZEL_CXXOPTS=-std=c++14" \ ${LINUX_GCC_FLOOR_CONTAINER} \ /usr/local/bin/bazel test ... \ --copt="-Wall" \ diff --git a/ci/macos-presubmit.sh b/ci/macos-presubmit.sh index 8f35df58..a5d6635a 100644 --- a/ci/macos-presubmit.sh +++ b/ci/macos-presubmit.sh @@ -66,7 +66,6 @@ for absl in 0 1; do ${BAZEL_BIN} test ... \ --copt="-Wall" \ --copt="-Werror" \ - --cxxopt="-std=c++14" \ --define="absl=${absl}" \ --features=external_include_paths \ --keep_going \ From 25cc5777a17820a6339204a3552aa1dd5e428669 Mon Sep 17 00:00:00 2001 From: Hardik Vala Date: Mon, 22 Aug 2022 06:42:26 -0700 Subject: [PATCH 27/57] Add support of 19-member structs to gmock UnpackStructImpl. PiperOrigin-RevId: 469171380 Change-Id: Ic75fc0523924e40e620552d4c04b79dad22a68e0 --- googlemock/include/gmock/gmock-matchers.h | 5 +++++ googlemock/test/gmock-matchers-comparisons_test.cc | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 46157360..5faf8dc9 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -3245,6 +3245,11 @@ auto UnpackStructImpl(const T& t, MakeIndexSequence<18>, char) { const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r] = t; return std::tie(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r); } +template +auto UnpackStructImpl(const T& t, MakeIndexSequence<19>, char) { + const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s] = t; + return std::tie(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s); +} #endif // defined(__cpp_structured_bindings) template diff --git a/googlemock/test/gmock-matchers-comparisons_test.cc b/googlemock/test/gmock-matchers-comparisons_test.cc index 1c6cac62..0cf731ff 100644 --- a/googlemock/test/gmock-matchers-comparisons_test.cc +++ b/googlemock/test/gmock-matchers-comparisons_test.cc @@ -1720,6 +1720,11 @@ TEST(FieldsAreTest, StructuredBindings) { }; EXPECT_THAT(MyVarType18{}, FieldsAre(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + struct MyVarType19 { + int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s; + }; + EXPECT_THAT(MyVarType19{}, FieldsAre(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0)); } #endif From afd902e992b720d1b3e106bc5e425a5768872265 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 26 Aug 2022 06:34:54 -0700 Subject: [PATCH 28/57] Consider all TERM values ending in "-256color" to be color supporting. In particular this handles TERM=hterm-256color correctly. PiperOrigin-RevId: 470232889 Change-Id: Iea594a3fde2b8b0a10e527956d70ba0bb3452e08 --- googletest/src/gtest.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 513a8878..81409a33 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -3245,18 +3245,15 @@ bool ShouldUseColor(bool stdout_is_tty) { #else // On non-Windows platforms, we rely on the TERM variable. const char* const term = posix::GetEnv("TERM"); - const bool term_supports_color = + const bool term_supports_color = term != nullptr && ( String::CStringEquals(term, "xterm") || String::CStringEquals(term, "xterm-color") || - String::CStringEquals(term, "xterm-256color") || String::CStringEquals(term, "screen") || - String::CStringEquals(term, "screen-256color") || String::CStringEquals(term, "tmux") || - String::CStringEquals(term, "tmux-256color") || String::CStringEquals(term, "rxvt-unicode") || - String::CStringEquals(term, "rxvt-unicode-256color") || String::CStringEquals(term, "linux") || - String::CStringEquals(term, "cygwin"); + String::CStringEquals(term, "cygwin") || + String::EndsWithCaseInsensitive(term, "-256color")); return stdout_is_tty && term_supports_color; #endif // GTEST_OS_WINDOWS } From 0e0d9feefab1b51aaab9dfd70132e93c0b6964e5 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 1 Sep 2022 07:24:20 -0700 Subject: [PATCH 29/57] Fixed header guards to match style guide conventions. PiperOrigin-RevId: 471524660 Change-Id: Ie11e6a7a5a5497f64d5b9c382f1017094e043093 --- googlemock/include/gmock/gmock-function-mocker.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/googlemock/include/gmock/gmock-function-mocker.h b/googlemock/include/gmock/gmock-function-mocker.h index f565d980..b568aefe 100644 --- a/googlemock/include/gmock/gmock-function-mocker.h +++ b/googlemock/include/gmock/gmock-function-mocker.h @@ -34,8 +34,8 @@ // IWYU pragma: private, include "gmock/gmock.h" // IWYU pragma: friend gmock/.* -#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT -#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT +#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_ +#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_ #include // IWYU pragma: keep #include // IWYU pragma: keep @@ -511,4 +511,4 @@ using internal::FunctionMocker; #define GMOCK_MOCKER_(arity, constness, Method) \ GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) -#endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ +#endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_ From 0f6885405c980d5479d6177f7223d4bc7bacca6b Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 8 Sep 2022 09:41:57 -0700 Subject: [PATCH 30/57] Remove obsolete MSVC warning pragmas for Invalid() Remove the MSVC pragmas for disabling warning C4717 (infinite recursion) for Invalid() because that warning has been fixed in cl/441474979. PiperOrigin-RevId: 473012585 Change-Id: I5f1bf88379bd4f2bf005e029c04766ac4caadd84 --- .../include/gmock/internal/gmock-internal-utils.h | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index b1343fdc..92d8eb9d 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -290,13 +290,6 @@ class WithoutMatchers { // Internal use only: access the singleton instance of WithoutMatchers. GTEST_API_ WithoutMatchers GetWithoutMatchers(); -// Disable MSVC warnings for infinite recursion, since in this case the -// recursion is unreachable. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4717) -#endif - // Invalid() is usable as an expression of type T, but will terminate // the program with an assertion failure if actually run. This is useful // when a value of type T is needed for compilation, but the statement @@ -314,10 +307,6 @@ inline T Invalid() { #endif } -#ifdef _MSC_VER -#pragma warning(pop) -#endif - // Given a raw type (i.e. having no top-level reference or const // modifier) RawContainer that's either an STL-style container or a // native array, class StlContainerView has the From c29315dda476f195298ab8da180e564478649b9e Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 9 Sep 2022 15:14:20 -0700 Subject: [PATCH 31/57] Use UnorderedElementsAre in example about using matchers with maps PiperOrigin-RevId: 473353707 Change-Id: Ief5bdbd2b8e28bac8f47be9aaeac4bb93875a793 --- docs/gmock_cook_book.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/gmock_cook_book.md b/docs/gmock_cook_book.md index 8a11d864..5be298d3 100644 --- a/docs/gmock_cook_book.md +++ b/docs/gmock_cook_book.md @@ -1424,11 +1424,12 @@ Use `Pair` when comparing maps or other associative containers. {% raw %} ```cpp -using testing::ElementsAre; -using testing::Pair; +using ::testing::UnorderedElementsAre; +using ::testing::Pair; ... - std::map m = {{"a", 1}, {"b", 2}, {"c", 3}}; - EXPECT_THAT(m, ElementsAre(Pair("a", 1), Pair("b", 2), Pair("c", 3))); + absl::flat_hash_map m = {{"a", 1}, {"b", 2}, {"c", 3}}; + EXPECT_THAT(m, UnorderedElementsAre( + Pair("a", 1), Pair("b", 2), Pair("c", 3))); ``` {% endraw %} @@ -1445,8 +1446,8 @@ using testing::Pair; * If the container is passed by pointer instead of by reference, just write `Pointee(ElementsAre*(...))`. * The order of elements *matters* for `ElementsAre*()`. If you are using it - with containers whose element order are undefined (e.g. `hash_map`) you - should use `WhenSorted` around `ElementsAre`. + with containers whose element order are undefined (such as a + `std::unordered_map`) you should use `UnorderedElementsAre`. ### Sharing Matchers From 7cafeff7bddf0430ae1e68ebb6213bb7c5d4a8ec Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Tue, 13 Sep 2022 08:14:45 -0700 Subject: [PATCH 32/57] Rollback 4fa8cfe3f4dee8975ee02d98633a5245ab67c6d7 Breaks the intended C++ version on some CI builds PiperOrigin-RevId: 474022587 Change-Id: I41a58893802c90864e0f2cc3d15e6c169c59146d --- .bazelrc | 1 - .github/workflows/gtest-ci.yml | 9 ++++++--- ci/linux-presubmit.sh | 1 + ci/macos-presubmit.sh | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) delete mode 100644 .bazelrc diff --git a/.bazelrc b/.bazelrc deleted file mode 100644 index f93facf0..00000000 --- a/.bazelrc +++ /dev/null @@ -1 +0,0 @@ -build --cxxopt=-std=c++14 diff --git a/.github/workflows/gtest-ci.yml b/.github/workflows/gtest-ci.yml index e61880f9..b2dcab49 100644 --- a/.github/workflows/gtest-ci.yml +++ b/.github/workflows/gtest-ci.yml @@ -4,6 +4,9 @@ on: push: pull_request: +env: + BAZEL_CXXOPTS: -std=c++14 + jobs: Linux: runs-on: ubuntu-latest @@ -14,7 +17,7 @@ jobs: fetch-depth: 0 - name: Tests - run: bazel test --features=external_include_paths --test_output=errors ... + run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ... MacOs: runs-on: macos-latest @@ -25,7 +28,7 @@ jobs: fetch-depth: 0 - name: Tests - run: bazel test --features=external_include_paths --test_output=errors ... + run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ... Windows: @@ -37,4 +40,4 @@ jobs: fetch-depth: 0 - name: Tests - run: bazel test --features=external_include_paths --test_output=errors ... + run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ... diff --git a/ci/linux-presubmit.sh b/ci/linux-presubmit.sh index f6eb9b7d..4eb5bbe4 100644 --- a/ci/linux-presubmit.sh +++ b/ci/linux-presubmit.sh @@ -72,6 +72,7 @@ time docker run \ --workdir="/src" \ --rm \ --env="CC=/usr/local/bin/gcc" \ + --env="BAZEL_CXXOPTS=-std=c++14" \ ${LINUX_GCC_FLOOR_CONTAINER} \ /usr/local/bin/bazel test ... \ --copt="-Wall" \ diff --git a/ci/macos-presubmit.sh b/ci/macos-presubmit.sh index a5d6635a..8f35df58 100644 --- a/ci/macos-presubmit.sh +++ b/ci/macos-presubmit.sh @@ -66,6 +66,7 @@ for absl in 0 1; do ${BAZEL_BIN} test ... \ --copt="-Wall" \ --copt="-Werror" \ + --cxxopt="-std=c++14" \ --define="absl=${absl}" \ --features=external_include_paths \ --keep_going \ From 1336c4b6d1a6f4bc6beebccb920e5ff858889292 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Tue, 13 Sep 2022 10:12:42 -0700 Subject: [PATCH 33/57] Fix MSVC C++14 flag for GitHub workflow PiperOrigin-RevId: 474053482 Change-Id: If5cdf7458139ba3ad04b8c078734d6890199a348 --- .github/workflows/gtest-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gtest-ci.yml b/.github/workflows/gtest-ci.yml index b2dcab49..bcef926b 100644 --- a/.github/workflows/gtest-ci.yml +++ b/.github/workflows/gtest-ci.yml @@ -40,4 +40,4 @@ jobs: fetch-depth: 0 - name: Tests - run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ... + run: bazel test --cxxopt=/std:c++14 --features=external_include_paths --test_output=errors ... From 05cc575c65924b83535b6d35fc39a1981b458bef Mon Sep 17 00:00:00 2001 From: John Hinnegan <426690+softwaregravy@users.noreply.github.com> Date: Sun, 18 Sep 2022 10:54:36 -0400 Subject: [PATCH 34/57] Update link to Bazel installation guide The Bazel docs have moved! --- docs/quickstart-bazel.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/quickstart-bazel.md b/docs/quickstart-bazel.md index c187e729..853139a9 100644 --- a/docs/quickstart-bazel.md +++ b/docs/quickstart-bazel.md @@ -17,7 +17,7 @@ See [Supported Platforms](platforms.md) for more information about platforms compatible with GoogleTest. If you don't already have Bazel installed, see the -[Bazel installation guide](https://docs.bazel.build/versions/main/install.html). +[Bazel installation guide](https://bazel.build/install). {: .callout .note} Note: The terminal commands in this tutorial show a Unix shell prompt, but the From 7a3abfec0aa5255f0ecf246987422493e9ca6a75 Mon Sep 17 00:00:00 2001 From: Marat Dukhan Date: Tue, 20 Sep 2022 23:07:33 -0700 Subject: [PATCH 35/57] Port GoogleTest to QuRT (Hexagon RTOS) --- googlemock/src/gmock-spec-builders.cc | 7 ++++++ .../include/gtest/internal/gtest-port-arch.h | 2 ++ .../include/gtest/internal/gtest-port.h | 25 +++++++++++++------ googletest/src/gtest-filepath.cc | 4 +-- googletest/src/gtest_main.cc | 12 +++++++++ 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 1771e403..b333e53d 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -51,6 +51,9 @@ #if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC #include // NOLINT #endif +#if GTEST_OS_QURT +#include +#endif // Silence C4800 (C4800: 'int *const ': forcing value // to bool 'true' or 'false') for MSVC 15 @@ -519,8 +522,12 @@ class MockObjectRegistry { // RUN_ALL_TESTS() has already returned when this destructor is // called. Therefore we cannot use the normal Google Test // failure reporting mechanism. +#if GTEST_OS_QURT + qurt_exception_raise_fatal(); +#else _exit(1); // We cannot call exit() as it is not reentrant and // may already have been called. +#endif } } diff --git a/googletest/include/gtest/internal/gtest-port-arch.h b/googletest/include/gtest/internal/gtest-port-arch.h index f025db76..04064606 100644 --- a/googletest/include/gtest/internal/gtest-port-arch.h +++ b/googletest/include/gtest/internal/gtest-port-arch.h @@ -111,6 +111,8 @@ #define GTEST_OS_ESP32 1 #elif defined(__XTENSA__) #define GTEST_OS_XTENSA 1 +#elif defined(__hexagon__) +#define GTEST_OS_QURT 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 c9e1f324..025d3d47 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -385,7 +385,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // On Android, is only available starting with Gingerbread. #define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9) #else -#define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS && !GTEST_OS_XTENSA) +#define GTEST_HAS_POSIX_RE \ + !(GTEST_OS_WINDOWS || GTEST_OS_XTENSA || GTEST_OS_QURT) #endif #endif @@ -457,7 +458,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // no support for it at least as recent as Froyo (2.2). #define GTEST_HAS_STD_WSTRING \ (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ - GTEST_OS_HAIKU || GTEST_OS_ESP32 || GTEST_OS_ESP8266 || GTEST_OS_XTENSA)) + GTEST_OS_HAIKU || GTEST_OS_ESP32 || GTEST_OS_ESP8266 || \ + GTEST_OS_XTENSA || GTEST_OS_QURT)) #endif // GTEST_HAS_STD_WSTRING @@ -578,9 +580,9 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // output correctness and to implement death tests. #ifndef GTEST_HAS_STREAM_REDIRECTION // By default, we assume that stream redirection is supported on all -// platforms except known mobile ones. +// platforms except known mobile / embedded ones. #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ - GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA + GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA || GTEST_OS_QURT #define GTEST_HAS_STREAM_REDIRECTION 0 #else #define GTEST_HAS_STREAM_REDIRECTION 1 @@ -2019,7 +2021,12 @@ inline int StrCaseCmp(const char* s1, const char* s2) { return strcasecmp(s1, s2); } inline char* StrDup(const char* src) { return strdup(src); } +#if GTEST_OS_QURT +// QuRT doesn't support any directory functions, including rmdir +inline int RmDir(const char* dir GTEST_ATTRIBUTE_UNUSED_) { return 0; } +#else inline int RmDir(const char* dir) { return rmdir(dir); } +#endif inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } #endif // GTEST_OS_WINDOWS @@ -2044,7 +2051,8 @@ GTEST_DISABLE_MSC_DEPRECATED_PUSH_() // defined there. #if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \ - !GTEST_OS_WINDOWS_RT && !GTEST_OS_ESP8266 && !GTEST_OS_XTENSA + !GTEST_OS_WINDOWS_RT && !GTEST_OS_ESP8266 && !GTEST_OS_XTENSA && \ + !GTEST_OS_QURT inline int ChDir(const char* dir) { return chdir(dir); } #endif inline FILE* FOpen(const char* path, const char* mode) { @@ -2058,14 +2066,14 @@ inline FILE* FOpen(const char* path, const char* mode) { return fopen(path, mode); #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW } -#if !GTEST_OS_WINDOWS_MOBILE +#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT inline FILE* FReopen(const char* path, const char* mode, FILE* stream) { return freopen(path, mode, stream); } inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); } #endif inline int FClose(FILE* fp) { return fclose(fp); } -#if !GTEST_OS_WINDOWS_MOBILE +#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT inline int Read(int fd, void* buf, unsigned int count) { return static_cast(read(fd, buf, count)); } @@ -2077,7 +2085,8 @@ inline const char* StrError(int errnum) { return strerror(errnum); } #endif inline const char* GetEnv(const char* name) { #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ - GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA + GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA || \ + GTEST_OS_QURT // We are on an embedded platform, which has no environment variables. static_cast(name); // To prevent 'unused argument' warning. return nullptr; diff --git a/googletest/src/gtest-filepath.cc b/googletest/src/gtest-filepath.cc index f6ee90cd..6767db0d 100644 --- a/googletest/src/gtest-filepath.cc +++ b/googletest/src/gtest-filepath.cc @@ -96,7 +96,7 @@ static bool IsPathSeparator(char c) { FilePath FilePath::GetCurrentDir() { #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_ESP32 || \ - GTEST_OS_XTENSA + GTEST_OS_XTENSA || GTEST_OS_QURT // These platforms do not have a current directory, so we just return // something reasonable. return FilePath(kCurrentDirectoryString); @@ -323,7 +323,7 @@ bool FilePath::CreateFolder() const { delete[] unicode; #elif GTEST_OS_WINDOWS int result = _mkdir(pathname_.c_str()); -#elif GTEST_OS_ESP8266 || GTEST_OS_XTENSA +#elif GTEST_OS_ESP8266 || GTEST_OS_XTENSA || GTEST_OS_QURT // do nothing int result = 0; #else diff --git a/googletest/src/gtest_main.cc b/googletest/src/gtest_main.cc index 44976375..d2260488 100644 --- a/googletest/src/gtest_main.cc +++ b/googletest/src/gtest_main.cc @@ -32,9 +32,12 @@ #include "gtest/gtest.h" #if GTEST_OS_ESP8266 || GTEST_OS_ESP32 +// Aduino-like platforms: program entry points are setup/loop instead of main. + #if GTEST_OS_ESP8266 extern "C" { #endif + void setup() { testing::InitGoogleTest(); } void loop() { RUN_ALL_TESTS(); } @@ -43,7 +46,16 @@ void loop() { RUN_ALL_TESTS(); } } #endif +#elif GTEST_OS_QURT +// QuRT: program entry point is main, but argc/argv are unusable. + +GTEST_API_ int main() { + printf("Running main() from %s\n", __FILE__); + testing::InitGoogleTest(); + return RUN_ALL_TESTS(); +} #else +// Normal platforms: program entry point is main, argc/argv are initialized. GTEST_API_ int main(int argc, char **argv) { printf("Running main() from %s\n", __FILE__); From 83bd792e36db826f869f30ded6c6acc82c4fe672 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 27 Sep 2022 12:44:59 +0200 Subject: [PATCH 36/57] Upgrade GitHub Actions Checkout https://github.com/actions/checkout/releases --- .github/workflows/gtest-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gtest-ci.yml b/.github/workflows/gtest-ci.yml index bcef926b..7ace9509 100644 --- a/.github/workflows/gtest-ci.yml +++ b/.github/workflows/gtest-ci.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 @@ -23,7 +23,7 @@ jobs: runs-on: macos-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 @@ -35,7 +35,7 @@ jobs: runs-on: windows-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 From 9836817d8256faf4829e2046c4a391df4b7cc54c Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 27 Sep 2022 12:47:32 +0200 Subject: [PATCH 37/57] Branding: macOS --- .github/workflows/gtest-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gtest-ci.yml b/.github/workflows/gtest-ci.yml index 7ace9509..03a8cc5e 100644 --- a/.github/workflows/gtest-ci.yml +++ b/.github/workflows/gtest-ci.yml @@ -19,7 +19,7 @@ jobs: - name: Tests run: bazel test --cxxopt=-std=c++14 --features=external_include_paths --test_output=errors ... - MacOs: + macOS: runs-on: macos-latest steps: From dfa67352364e00452360e1fa5d59677459712ee7 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 27 Sep 2022 12:08:58 -0700 Subject: [PATCH 38/57] Add GoogleTest workaround for MSVC crash with Address Sanitizer (ASAN) on version 17.3.3 PiperOrigin-RevId: 477240422 Change-Id: I894037850617252e462783c0885e30fc8e7ad122 --- 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 81409a33..43e8723b 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -2713,7 +2713,8 @@ TestInfo::TestInfo(const std::string& a_test_suite_name, internal::TypeId fixture_class_id, internal::TestFactoryBase* factory) : test_suite_name_(a_test_suite_name), - name_(a_name), + // begin()/end() is MSVC 17.3.3 ASAN crash workaround (GitHub issue #3997) + name_(a_name.begin(), a_name.end()), type_param_(a_type_param ? new std::string(a_type_param) : nullptr), value_param_(a_value_param ? new std::string(a_value_param) : nullptr), location_(a_code_location), From 4924e0610a89dcd58077a691a2e3702b0d6e58ed Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 28 Sep 2022 11:55:06 -0700 Subject: [PATCH 39/57] Moves boilerplate disabling copy constructor/assignment from GoogleTest's TEST_P macro into a header file to avoid triggering warnings in user code. Fixes #4015 PiperOrigin-RevId: 477513399 Change-Id: Ia21928ee12e85946b4c8db86835d225cb257eecc --- googletest/include/gtest/gtest-param-test.h | 7 +------ googletest/include/gtest/gtest.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index b55119ac..19238ae4 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -409,7 +409,7 @@ internal::CartesianProductHolder Combine(const Generator&... g) { #define TEST_P(test_suite_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - : public test_suite_name { \ + : public ::testing::internal::UserTestSuite { \ public: \ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \ void TestBody() override; \ @@ -429,11 +429,6 @@ internal::CartesianProductHolder Combine(const Generator&... g) { return 0; \ } \ static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \ - GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - (const GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) &) = delete; \ - GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) & operator=( \ - const GTEST_TEST_CLASS_NAME_(test_suite_name, \ - test_name) &) = delete; /* NOLINT */ \ }; \ int GTEST_TEST_CLASS_NAME_(test_suite_name, \ test_name)::gtest_registering_dummy_ = \ diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index d19a587a..6ff2774f 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -190,6 +190,21 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string& message); std::set* GetIgnoredParameterizedTestSuites(); +// Mix-in class for user tests. +// This allows us to add/delete members to/from test suites without having to +// modify the test macros themselves. +// This makes the code easier to read and maintain, as well making it easier +// for users to suppress any warnings originating from these members, as the +// members are now declared in an external header instead of in user code. +template +class UserTestSuite : public TestClass { + public: + UserTestSuite() = default; + UserTestSuite(const UserTestSuite &) = delete; + UserTestSuite &operator=(const UserTestSuite &) = delete; + virtual ~UserTestSuite() = default; +}; + } // namespace internal // The friend relationship of some of these classes is cyclic. From c43b916a9623e052860f59e52f71de1974ed8823 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 28 Sep 2022 14:14:25 -0700 Subject: [PATCH 40/57] Uses a simpler mechanism to disable the copying of GoogleTest test suites. PiperOrigin-RevId: 477549427 Change-Id: I6421ca09f0f1296cebdc3e54565049f1542dfa8a --- googletest/include/gtest/gtest-param-test.h | 2 +- googletest/include/gtest/gtest.h | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index 19238ae4..2dbac48e 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -409,7 +409,7 @@ internal::CartesianProductHolder Combine(const Generator&... g) { #define TEST_P(test_suite_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - : public ::testing::internal::UserTestSuite { \ + : public test_suite_name, private ::testing::internal::NonCopyable { \ public: \ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \ void TestBody() override; \ diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 6ff2774f..4f037ad7 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -190,19 +190,12 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string& message); std::set* GetIgnoredParameterizedTestSuites(); -// Mix-in class for user tests. -// This allows us to add/delete members to/from test suites without having to -// modify the test macros themselves. -// This makes the code easier to read and maintain, as well making it easier -// for users to suppress any warnings originating from these members, as the -// members are now declared in an external header instead of in user code. -template -class UserTestSuite : public TestClass { +class NonCopyable { public: - UserTestSuite() = default; - UserTestSuite(const UserTestSuite &) = delete; - UserTestSuite &operator=(const UserTestSuite &) = delete; - virtual ~UserTestSuite() = default; + NonCopyable() = default; + NonCopyable(const NonCopyable &) = delete; + NonCopyable &operator=(const NonCopyable &) = delete; + ~NonCopyable() = default; }; } // namespace internal From 19387c9dd5b153a6bdef6f1fc4fb2391fdb122d0 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 28 Sep 2022 14:58:29 -0700 Subject: [PATCH 41/57] Rollback: Uses a simpler mechanism to disable the copying of GoogleTest test suites. PiperOrigin-RevId: 477560280 Change-Id: I1c1f5a1d6645859ec38cb1a75cd267816d2aff35 --- googletest/include/gtest/gtest-param-test.h | 2 +- googletest/include/gtest/gtest.h | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index 2dbac48e..19238ae4 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -409,7 +409,7 @@ internal::CartesianProductHolder Combine(const Generator&... g) { #define TEST_P(test_suite_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - : public test_suite_name, private ::testing::internal::NonCopyable { \ + : public ::testing::internal::UserTestSuite { \ public: \ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \ void TestBody() override; \ diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 4f037ad7..6ff2774f 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -190,12 +190,19 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string& message); std::set* GetIgnoredParameterizedTestSuites(); -class NonCopyable { +// Mix-in class for user tests. +// This allows us to add/delete members to/from test suites without having to +// modify the test macros themselves. +// This makes the code easier to read and maintain, as well making it easier +// for users to suppress any warnings originating from these members, as the +// members are now declared in an external header instead of in user code. +template +class UserTestSuite : public TestClass { public: - NonCopyable() = default; - NonCopyable(const NonCopyable &) = delete; - NonCopyable &operator=(const NonCopyable &) = delete; - ~NonCopyable() = default; + UserTestSuite() = default; + UserTestSuite(const UserTestSuite &) = delete; + UserTestSuite &operator=(const UserTestSuite &) = delete; + virtual ~UserTestSuite() = default; }; } // namespace internal From d1a0039b97291dd1dc14f123b906bb7622ffe07c Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 28 Sep 2022 15:24:12 -0700 Subject: [PATCH 42/57] Rollback: Moves boilerplate disabling copy constructor/assignment from GoogleTest's TEST_P macro into a header file to avoid triggering warnings in user code. PiperOrigin-RevId: 477566426 Change-Id: Ia417e295d839f43be6e61a5699457866108f2a01 --- googletest/include/gtest/gtest-param-test.h | 7 ++++++- googletest/include/gtest/gtest.h | 15 --------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index 19238ae4..b55119ac 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -409,7 +409,7 @@ internal::CartesianProductHolder Combine(const Generator&... g) { #define TEST_P(test_suite_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - : public ::testing::internal::UserTestSuite { \ + : public test_suite_name { \ public: \ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \ void TestBody() override; \ @@ -429,6 +429,11 @@ internal::CartesianProductHolder Combine(const Generator&... g) { return 0; \ } \ static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \ + GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ + (const GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) &) = delete; \ + GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) & operator=( \ + const GTEST_TEST_CLASS_NAME_(test_suite_name, \ + test_name) &) = delete; /* NOLINT */ \ }; \ int GTEST_TEST_CLASS_NAME_(test_suite_name, \ test_name)::gtest_registering_dummy_ = \ diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 6ff2774f..d19a587a 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -190,21 +190,6 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string& message); std::set* GetIgnoredParameterizedTestSuites(); -// Mix-in class for user tests. -// This allows us to add/delete members to/from test suites without having to -// modify the test macros themselves. -// This makes the code easier to read and maintain, as well making it easier -// for users to suppress any warnings originating from these members, as the -// members are now declared in an external header instead of in user code. -template -class UserTestSuite : public TestClass { - public: - UserTestSuite() = default; - UserTestSuite(const UserTestSuite &) = delete; - UserTestSuite &operator=(const UserTestSuite &) = delete; - virtual ~UserTestSuite() = default; -}; - } // namespace internal // The friend relationship of some of these classes is cyclic. From 93f08be653c36ddc6943e9513fc14c7292b4d007 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 30 Sep 2022 10:54:41 -0700 Subject: [PATCH 43/57] Uses a simpler mechanism to disable the copying of GoogleTest test suites, to move code out of the TEST_P macro. PiperOrigin-RevId: 478031678 Change-Id: I45f0ce17a4add526c86b8212d836d98d63b3a193 --- googletest/include/gtest/gtest-param-test.h | 7 +------ googletest/include/gtest/gtest.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index b55119ac..2d38b96c 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -409,7 +409,7 @@ internal::CartesianProductHolder Combine(const Generator&... g) { #define TEST_P(test_suite_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - : public test_suite_name { \ + : public test_suite_name, private ::testing::internal::GTestNonCopyable {\ public: \ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \ void TestBody() override; \ @@ -429,11 +429,6 @@ internal::CartesianProductHolder Combine(const Generator&... g) { return 0; \ } \ static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \ - GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - (const GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) &) = delete; \ - GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) & operator=( \ - const GTEST_TEST_CLASS_NAME_(test_suite_name, \ - test_name) &) = delete; /* NOLINT */ \ }; \ int GTEST_TEST_CLASS_NAME_(test_suite_name, \ test_name)::gtest_registering_dummy_ = \ diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index d19a587a..81e124fa 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -190,6 +190,17 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string& message); std::set* GetIgnoredParameterizedTestSuites(); +// A base class that prevents subclasses from being copyable. +// We do this instead of using '= delete' so as to avoid triggering warnings +// inside user code regarding any of our declarations. +class GTestNonCopyable { + public: + GTestNonCopyable() = default; + GTestNonCopyable(const GTestNonCopyable &) = delete; + GTestNonCopyable &operator=(const GTestNonCopyable &) = delete; + ~GTestNonCopyable() = default; +}; + } // namespace internal // The friend relationship of some of these classes is cyclic. From 08935483cb22749b3c3774e9bcd5ef35b5a1a7b7 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 5 Oct 2022 12:26:54 -0700 Subject: [PATCH 44/57] Makes Clang compilations via Ninja on Windows define _DLL only for shared CRT builds, as one would already expect from MSVC builds. (Previously, static Clang/Ninja builds on Windows also implicitly defined _DLL, which was problematic.) PiperOrigin-RevId: 479113168 Change-Id: I252d9be90fd33df75dab922e62b197208830d124 --- googletest/cmake/internal_utils.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 6f7fdc2c..41405587 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -21,8 +21,9 @@ endif (POLICY CMP0054) # This must be a macro(), as inside a function string() can only # update variables in the function scope. macro(fix_default_compiler_settings_) - if (MSVC) - # For MSVC, CMake sets certain flags to defaults we want to override. + if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC|Clang") + # For MSVC and Clang, CMake sets certain flags to defaults we want to + # override. # This replacement code is taken from sample in the CMake Wiki at # https://gitlab.kitware.com/cmake/community/wikis/FAQ#dynamic-replace. foreach (flag_var @@ -39,6 +40,10 @@ macro(fix_default_compiler_settings_) # on CRT DLLs being available. CMake always defaults to using shared # CRT libraries, so we override that default here. string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}") + + # When using Ninja with Clang, static builds pass -D_DLL on Windows. + # This is incorrect and should not happen, so we fix that here. + string(REPLACE "-D_DLL" "" ${flag_var} "${${flag_var}}") endif() # We prefer more strict warning checking for building Google Test. From 67e264834a45c3d543aa2fa11bcc41c4ba90316b Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 6 Oct 2022 11:21:49 -0700 Subject: [PATCH 45/57] [fuchsia] Use __builtin_trap to trigger gunit_break_on_failure on non-x86 arch In developing tests for the fuchsia debugger, it was found that in addition to catching gtest failures (which are implemented as software breakpoints) we also see PageFault exceptions, caused by this nullptr dereference. PiperOrigin-RevId: 479365782 Change-Id: I84d805d94c2e46b6f3c982ca1ae49c6ac3ed3430 --- googletest/src/gtest.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 43e8723b..638d53bb 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -143,6 +143,14 @@ #include "absl/strings/str_replace.h" #endif // GTEST_HAS_ABSL +// Checks builtin compiler feature |x| while avoiding an extra layer of #ifdefs +// at the callsite. +#if defined(__has_builtin) +#define GTEST_HAS_BUILTIN(x) __has_builtin(x) +#else +#define GTEST_HAS_BUILTIN(x) 0 +#endif // defined(__has_builtin) + namespace testing { using internal::CountIf; @@ -5331,6 +5339,10 @@ void UnitTest::AddTestPartResult(TestPartResult::Type result_type, (defined(__x86_64__) || defined(__i386__))) // with clang/gcc we can achieve the same effect on x86 by invoking int3 asm("int3"); +#elif GTEST_HAS_BUILTIN(__builtin_trap) + __builtin_trap(); +#elif defined(SIGTRAP) + raise(SIGTRAP); #else // Dereference nullptr through a volatile pointer to prevent the compiler // from removing. We use this rather than abort() or __builtin_trap() for From 9fbb6575035e3ac97ad9547d042c026a1296c705 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 7 Oct 2022 14:20:15 -0700 Subject: [PATCH 46/57] Update the POSIX Extended section of the Regular Expression Wikipedia page PiperOrigin-RevId: 479667644 Change-Id: I4ab03bd5f0520f8586667de8bd1b9443f241337a --- docs/advanced.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced.md b/docs/advanced.md index bce983c6..c3c54614 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -487,7 +487,7 @@ When built with Bazel and using Abseil, googletest uses the systems (Linux, Cygwin, Mac), googletest uses the [POSIX extended regular expression](http://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_Regular_Expressions). +[Wikipedia entry](http://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 0231584a608bda1101c5f50ae03805c518ece93b Mon Sep 17 00:00:00 2001 From: Vertexwahn Date: Sat, 8 Oct 2022 13:33:18 +0200 Subject: [PATCH 47/57] Update rules_python, bazel_skylib and platfroms --- WORKSPACE | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 4d7b3988..7e371b90 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -20,20 +20,25 @@ http_archive( http_archive( name = "rules_python", - sha256 = "0b460f17771258341528753b1679335b629d1d25e3af28eda47d009c103a6e15", - strip_prefix = "rules_python-aef17ad72919d184e5edb7abf61509eb78e57eda", - urls = ["https://github.com/bazelbuild/rules_python/archive/aef17ad72919d184e5edb7abf61509eb78e57eda.zip"], # 2022-06-21T23:44:47Z + sha256 = "8c8fe44ef0a9afc256d1e75ad5f448bb59b81aba149b8958f02f7b3a98f5d9b4", + strip_prefix = "rules_python-0.13.0", + url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.13.0.tar.gz", ) http_archive( name = "bazel_skylib", - urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz"], - sha256 = "f7be3474d42aae265405a592bb7da8e171919d74c16f082a5457840f06054728", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz", + ], + sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506", ) http_archive( name = "platforms", - sha256 = "a879ea428c6d56ab0ec18224f976515948822451473a80d06c2e50af0bbe5121", - strip_prefix = "platforms-da5541f26b7de1dc8e04c075c99df5351742a4a2", - urls = ["https://github.com/bazelbuild/platforms/archive/da5541f26b7de1dc8e04c075c99df5351742a4a2.zip"], # 2022-05-27 + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.6/platforms-0.0.6.tar.gz", + "https://github.com/bazelbuild/platforms/releases/download/0.0.6/platforms-0.0.6.tar.gz", + ], + sha256 = "5308fc1d8865406a49427ba24a9ab53087f17f5266a7aabbfc28823f3916e1ca", ) From 671cfb7dbf26363ea0fc11b7e813cda7c2a2912e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20G=C3=A9czi?= Date: Fri, 7 Oct 2022 00:00:00 +0000 Subject: [PATCH 48/57] Suggests a release with fixed CMakeLists.txt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Géczi --- googletest/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/README.md b/googletest/README.md index 75b3d526..3a82b1df 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 release-1.12.0 +git clone https://github.com/google/googletest.git -b release-1.12.1 cd googletest # Main directory of the cloned repository. mkdir build # Create a directory to hold the build output. cd build From 1d505b8e40db0204fd0515673fa97137680cb8ac Mon Sep 17 00:00:00 2001 From: Denis Hananein Date: Tue, 11 Oct 2022 12:11:46 +0200 Subject: [PATCH 49/57] Fix JSON output format #3884 --- googletest/src/gtest.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 638d53bb..38594528 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -4829,6 +4829,9 @@ void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream, // If there was a test failure outside of one of the test suites (like in a // test environment) include that in the output. if (unit_test.ad_hoc_test_result().Failed()) { + if (comma) { + *stream << ",\n"; + } OutputJsonTestSuiteForTestResult(stream, unit_test.ad_hoc_test_result()); } From d29b143bda80baad6fd3f5b523ed54f10eb0eea3 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 12 Oct 2022 10:30:15 -0700 Subject: [PATCH 50/57] Workaround for Visual C++ error C2039 with std::tuple_element_t. Fixes #3931 PiperOrigin-RevId: 480659507 Change-Id: I6fabef63b1285189a06375227273d9de2456e37a --- googlemock/include/gmock/gmock-actions.h | 12 ++++++++---- .../include/gmock/internal/gmock-internal-utils.h | 7 +++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 7e78c09a..aad07d51 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -1428,8 +1428,10 @@ struct WithArgsAction { // MSVC complains about the I parameter pack not being // expanded (error C3520) despite it being expanded in the // type alias. - OnceAction>::type...)>>::value, + // TupleElement is also an MSVC workaround. + // See its definition for details. + OnceAction>...)>>::value, int>::type = 0> operator OnceAction() && { // NOLINT struct OA { @@ -1453,8 +1455,10 @@ struct WithArgsAction { // MSVC complains about the I parameter pack not being // expanded (error C3520) despite it being expanded in the // type alias. - Action>::type...)>>::value, + // TupleElement is also an MSVC workaround. + // See its definition for details. + Action>...)>>::value, int>::type = 0> operator Action() const { // NOLINT Action> converted(inner_action); diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 92d8eb9d..2678920b 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -453,6 +453,13 @@ struct Function { template constexpr size_t Function::ArgumentCount; +// Workaround for MSVC error C2039: 'type': is not a member of 'std' +// when std::tuple_element is used. +// See: https://github.com/google/googletest/issues/3931 +// Can be replaced with std::tuple_element_t in C++14. +template +using TupleElement = typename std::tuple_element::type; + bool Base64Unescape(const std::string& encoded, std::string* decoded); #ifdef _MSC_VER From a41c3d0fb80c4558aa3799f262a7cfd67f32c468 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 14 Oct 2022 09:12:51 +0200 Subject: [PATCH 51/57] Fix table markup in testing.md --- docs/reference/testing.md | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/docs/reference/testing.md b/docs/reference/testing.md index dd0b982c..d983301e 100644 --- a/docs/reference/testing.md +++ b/docs/reference/testing.md @@ -101,23 +101,14 @@ functions that generate the test parameters, all defined in the `::testing` namespace: - -| Parameter Generator | Behavior | -| ---------------------------- | -------------------------------------------- | -| `Range(begin, end [, step])` | Yields values `{begin, begin+step, | -: : begin+step+step, ...}`. The values do not : -: : include `end`. `step` defaults to 1. : -| `Values(v1, v2, ..., vN)` | Yields values `{v1, v2, ..., vN}`. | -| `ValuesIn(container)` or | Yields values from a C-style array, an | -: `ValuesIn(begin,end)` : STL-style container, or an iterator range : -: : `[begin, end)`. : -| `Bool()` | Yields sequence `{false, true}`. | -| `Combine(g1, g2, ..., gN)` | Yields as `std::tuple` *n*-tuples all | -: : combinations (Cartesian product) of the : -: : values generated by the given *n* generators : -: : `g1`, `g2`, ..., `gN`. : -| `ConvertGenerator(g)` | Yields values generated by generator `g`, | -: : `static_cast` to `T`. : +| Parameter Generator | Behavior | +| ------------------- | ---------------------------------------------------- | +| `Range(begin, end [, step])` | Yields values `{begin, begin+step, begin+step+step, ...}`. The values do not include `end`. `step` defaults to 1. | +| `Values(v1, v2, ..., vN)` | Yields values `{v1, v2, ..., vN}`. | +| `ValuesIn(container)` or `ValuesIn(begin,end)` | Yields values from a C-style array, an STL-style container, or an iterator range `[begin, end)`. | +| `Bool()` | Yields sequence `{false, true}`. | +| `Combine(g1, g2, ..., gN)` | Yields as `std::tuple` *n*-tuples all combinations (Cartesian product) of the values generated by the given *n* generators `g1`, `g2`, ..., `gN`. | +| `ConvertGenerator(g)` | Yields values generated by generator `g`, `static_cast` to `T`. | The optional last argument *`name_generator`* is a function or functor that generates custom test name suffixes based on the test parameters. The function From 137b6e2770deb44aacd229c20507413120655b22 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 14 Oct 2022 10:32:14 -0700 Subject: [PATCH 52/57] Terse printing of std::reference_wrapper hides pointer This matches the intention and documentation of terse printing which generally avoids printing the pointer. PiperOrigin-RevId: 481178950 Change-Id: I27039dac1870934d2d5b212e2cc7e97ab82c5b34 --- googletest/include/gtest/gtest-printers.h | 7 +++++++ googletest/test/googletest-printers-test.cc | 23 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 8e4d2953..89215e62 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -891,6 +891,13 @@ class UniversalTersePrinter { UniversalPrint(value, os); } }; +template +class UniversalTersePrinter> { + public: + static void Print(std::reference_wrapper value, ::std::ostream* os) { + UniversalTersePrinter::Print(value.get(), os); + } +}; template class UniversalTersePrinter { public: diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index acfecf97..d2d88a52 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -193,6 +194,11 @@ OutputStream& operator<<(OutputStream& os, return os; } +struct StreamableInLocal {}; +void operator<<(::std::ostream& os, const StreamableInLocal& /* x */) { + os << "StreamableInLocal"; +} + // A user-defined streamable but recursively-defined container type in // a user namespace, it mimics therefore std::filesystem::path or // boost::filesystem::path. @@ -1604,6 +1610,23 @@ TEST(PrintToStringTest, ContainsNonLatin) { "\n As Text: \"From ä — ẑ\""); } +TEST(PrintToStringTest, PrintStreamableInLocal) { + EXPECT_STREQ("StreamableInLocal", + PrintToString(foo::StreamableInLocal()).c_str()); +} + +TEST(PrintToStringTest, PrintReferenceToStreamableInLocal) { + foo::StreamableInLocal s; + std::reference_wrapper r(s); + EXPECT_STREQ("StreamableInLocal", PrintToString(r).c_str()); +} + +TEST(PrintToStringTest, PrintReferenceToStreamableInGlobal) { + StreamableInGlobal s; + std::reference_wrapper r(s); + EXPECT_STREQ("StreamableInGlobal", PrintToString(r).c_str()); +} + 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 a9b2f0495cabb1ff01b51bcd0625cb1fd82da4ce Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Fri, 14 Oct 2022 11:00:07 -0700 Subject: [PATCH 53/57] Use attribute testing to simplify portable attribute macros Fixes #4025 PiperOrigin-RevId: 481186097 Change-Id: Id7d09e4626e5ccf564e8cfaa65581c1cd827918d --- .../include/gtest/internal/gtest-port.h | 85 ++++++++----------- 1 file changed, 37 insertions(+), 48 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 3556fdb9..50d4c41f 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -642,6 +642,22 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; default: // NOLINT #endif +// GTEST_HAVE_ATTRIBUTE_ +// +// A function-like feature checking macro that is a wrapper around +// `__has_attribute`, which is defined by GCC 5+ and Clang and evaluates to a +// nonzero constant integer if the attribute is supported or 0 if not. +// +// It evaluates to zero if `__has_attribute` is not defined by the compiler. +// +// GCC: https://gcc.gnu.org/gcc-5/changes.html +// Clang: https://clang.llvm.org/docs/LanguageExtensions.html +#ifdef __has_attribute +#define GTEST_HAVE_ATTRIBUTE_(x) __has_attribute(x) +#else +#define GTEST_HAVE_ATTRIBUTE_(x) 0 +#endif + // Use this annotation at the end of a struct/class definition to // prevent the compiler from optimizing away instances that are never // used. This is useful when all interesting logic happens inside the @@ -653,30 +669,22 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // // Also use it after a variable or parameter declaration to tell the // compiler the variable/parameter does not have to be used. -#if defined(__GNUC__) && !defined(COMPILER_ICC) +#if GTEST_HAVE_ATTRIBUTE_(unused) #define GTEST_ATTRIBUTE_UNUSED_ __attribute__((unused)) -#elif defined(__clang__) -#if __has_attribute(unused) -#define GTEST_ATTRIBUTE_UNUSED_ __attribute__((unused)) -#endif -#endif -#ifndef GTEST_ATTRIBUTE_UNUSED_ +#else #define GTEST_ATTRIBUTE_UNUSED_ #endif // Use this annotation before a function that takes a printf format string. -#if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC) -#if defined(__MINGW_PRINTF_FORMAT) +#if GTEST_HAVE_ATTRIBUTE_(format) && defined(__MINGW_PRINTF_FORMAT) // MinGW has two different printf implementations. Ensure the format macro // matches the selected implementation. See // https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/. #define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ - __attribute__(( \ - __format__(__MINGW_PRINTF_FORMAT, string_index, first_to_check))) -#else -#define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ - __attribute__((__format__(__printf__, string_index, first_to_check))) -#endif + __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, first_to_check))) +#elif GTEST_HAVE_ATTRIBUTE_(format) +#define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ + __attribute__((format(printf, string_index, first_to_check))) #else #define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) #endif @@ -686,11 +694,11 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // following the argument list: // // Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_; -#if defined(__GNUC__) && !defined(COMPILER_ICC) +#if GTEST_HAVE_ATTRIBUTE_(warn_unused_result) #define GTEST_MUST_USE_RESULT_ __attribute__((warn_unused_result)) #else #define GTEST_MUST_USE_RESULT_ -#endif // __GNUC__ && !COMPILER_ICC +#endif // MS C++ compiler emits warning when a conditional expression is compile time // constant. In some contexts this warning is false positive and needs to be @@ -746,7 +754,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #elif GTEST_CREATE_SHARED_LIBRARY #define GTEST_API_ __declspec(dllexport) #endif -#elif __GNUC__ >= 4 || defined(__clang__) +#elif GTEST_HAVE_ATTRIBUTE_(visibility) #define GTEST_API_ __attribute__((visibility("default"))) #endif // _MSC_VER @@ -760,20 +768,17 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #define GTEST_DEFAULT_DEATH_TEST_STYLE "fast" #endif // GTEST_DEFAULT_DEATH_TEST_STYLE -#ifdef __GNUC__ +#if GTEST_HAVE_ATTRIBUTE_(noinline) // Ask the compiler to never inline a given function. #define GTEST_NO_INLINE_ __attribute__((noinline)) #else #define GTEST_NO_INLINE_ #endif -#if defined(__clang__) -// Nested ifs to avoid triggering MSVC warning. -#if __has_attribute(disable_tail_calls) +#if GTEST_HAVE_ATTRIBUTE_(disable_tail_calls) // Ask the compiler not to perform tail call optimization inside // the marked function. #define GTEST_NO_TAIL_CALL_ __attribute__((disable_tail_calls)) -#endif #elif __GNUC__ #define GTEST_NO_TAIL_CALL_ \ __attribute__((optimize("no-optimize-sibling-calls"))) @@ -792,50 +797,34 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // A function level attribute to disable checking for use of uninitialized // memory when built with MemorySanitizer. -#if defined(__clang__) -#if __has_feature(memory_sanitizer) +#if GTEST_HAVE_ATTRIBUTE_(no_sanitize_memory) #define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ __attribute__((no_sanitize_memory)) #else #define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ -#endif // __has_feature(memory_sanitizer) -#else -#define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ -#endif // __clang__ +#endif // A function level attribute to disable AddressSanitizer instrumentation. -#if defined(__clang__) -#if __has_feature(address_sanitizer) +#if GTEST_HAVE_ATTRIBUTE_(no_sanitize_address) #define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \ __attribute__((no_sanitize_address)) #else #define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ -#endif // __has_feature(address_sanitizer) -#else -#define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ -#endif // __clang__ +#endif // A function level attribute to disable HWAddressSanitizer instrumentation. -#if defined(__clang__) -#if __has_feature(hwaddress_sanitizer) +#if GTEST_HAVE_ATTRIBUTE_(no_sanitize) #define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ \ __attribute__((no_sanitize("hwaddress"))) #else #define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ -#endif // __has_feature(hwaddress_sanitizer) -#else -#define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ -#endif // __clang__ +#endif // A function level attribute to disable ThreadSanitizer instrumentation. -#if defined(__clang__) -#if __has_feature(thread_sanitizer) -#define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ __attribute__((no_sanitize_thread)) +#if GTEST_HAVE_ATTRIBUTE_(no_sanitize_thread) +#define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ __attribute((no_sanitize_thread)) #else #define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ -#endif // __has_feature(thread_sanitizer) -#else -#define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ -#endif // __clang__ +#endif namespace testing { From 88c59752c05d74475c3d487b28c5e82ad0b129b8 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Mon, 17 Oct 2022 10:39:12 -0700 Subject: [PATCH 54/57] Add Windows CI script PiperOrigin-RevId: 481680362 Change-Id: I87b2b71427a8ad2603f5445d6ef794c3fa84746e --- ci/windows-presubmit.bat | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 ci/windows-presubmit.bat diff --git a/ci/windows-presubmit.bat b/ci/windows-presubmit.bat new file mode 100644 index 00000000..8668ff35 --- /dev/null +++ b/ci/windows-presubmit.bat @@ -0,0 +1,56 @@ +SETLOCAL ENABLEDELAYEDEXPANSION + +SET BAZEL_EXE=%KOKORO_GFILE_DIR%\bazel-5.1.1-windows-x86_64.exe + +SET PATH=C:\Python37;%PATH% +SET BAZEL_PYTHON=C:\python37\python.exe +SET BAZEL_SH=C:\tools\msys64\usr\bin\bash.exe +SET CMAKE_BIN="C:\Program Files\CMake\bin\cmake.exe" +SET CTEST_BIN="C:\Program Files\CMake\bin\ctest.exe" +SET CTEST_OUTPUT_ON_FAILURE=1 + +IF EXIST git\googletest ( + CD git\googletest +) ELSE IF EXIST github\googletest ( + CD github\googletest +) + +IF %errorlevel% neq 0 EXIT /B 1 + +:: ---------------------------------------------------------------------------- +:: CMake Visual Studio 15 2017 Win64 +MKDIR cmake_msvc2017 +CD cmake_msvc2017 + +%CMAKE_BIN% .. ^ + -G "Visual Studio 15 2017 Win64" ^ + -DPYTHON_EXECUTABLE:FILEPATH=c:\python37\python.exe ^ + -DPYTHON_INCLUDE_DIR:PATH=c:\python37\include ^ + -DPYTHON_LIBRARY:FILEPATH=c:\python37\lib\site-packages\pip ^ + -Dgtest_build_samples=ON ^ + -Dgtest_build_tests=ON ^ + -Dgmock_build_tests=ON +IF %errorlevel% neq 0 EXIT /B 1 + +%CMAKE_BIN% --build . --target ALL_BUILD --config Debug -- -maxcpucount +IF %errorlevel% neq 0 EXIT /B 1 + +%CTEST_BIN% -C Debug --timeout 600 +IF %errorlevel% neq 0 EXIT /B 1 + +CD .. +RMDIR /S /Q cmake_msvc2017 + +:: ---------------------------------------------------------------------------- +:: Bazel Visual Studio 15 2017 Win64 + +SET BAZEL_VC=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC +%BAZEL_EXE% test ... ^ + --compilation_mode=dbg ^ + --copt=/std:c++14 ^ + --copt=/WX ^ + --features=external_include_paths ^ + --keep_going ^ + --test_output=errors ^ + --test_tag_filters=-no_test_msvc2017 +IF %errorlevel% neq 0 EXIT /B 1 From 26d3ab54422257b65452d5feeb080c015eabf5e8 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Mon, 17 Oct 2022 16:15:24 -0700 Subject: [PATCH 55/57] Fix detection of the no_sanitize("hwaddress") attribute PiperOrigin-RevId: 481765573 Change-Id: I1ba829c3cbf364a51d3ba383ee3b474c0e109578 --- googletest/include/gtest/internal/gtest-port.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 50d4c41f..005a0c0d 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -658,6 +658,16 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #define GTEST_HAVE_ATTRIBUTE_(x) 0 #endif +// GTEST_HAVE_FEATURE_ +// +// A function-like feature checking macro that is a wrapper around +// `__has_feature`. +#ifdef __has_feature +#define GTEST_HAVE_FEATURE_(x) __has_feature(x) +#else +#define GTEST_HAVE_FEATURE_(x) 0 +#endif + // Use this annotation at the end of a struct/class definition to // prevent the compiler from optimizing away instances that are never // used. This is useful when all interesting logic happens inside the @@ -812,7 +822,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #endif // A function level attribute to disable HWAddressSanitizer instrumentation. -#if GTEST_HAVE_ATTRIBUTE_(no_sanitize) +#if GTEST_HAVE_FEATURE_(hwaddress_sanitizer) && \ + GTEST_HAVE_ATTRIBUTE_(no_sanitize) #define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ \ __attribute__((no_sanitize("hwaddress"))) #else From f372c760264ad5fe672a96994d4a44190201e5c1 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 18 Oct 2022 08:51:57 -0700 Subject: [PATCH 56/57] Adds Win32 UNC path support to FilePath::IsAbsolutePath() and FilePath::IsRootDirectory() in GoogleTest Fixes: #3025 PiperOrigin-RevId: 481932601 Change-Id: I90fcb5b3d189aea79a0fd18735bad038b3511270 --- .../include/gtest/internal/gtest-filepath.h | 10 +++ googletest/src/gtest-filepath.cc | 75 ++++++++++++++----- googletest/test/googletest-filepath-test.cc | 18 +++++ 3 files changed, 85 insertions(+), 18 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-filepath.h b/googletest/include/gtest/internal/gtest-filepath.h index a2a60a96..dd7a3a49 100644 --- a/googletest/include/gtest/internal/gtest-filepath.h +++ b/googletest/include/gtest/internal/gtest-filepath.h @@ -199,6 +199,16 @@ class GTEST_API_ FilePath { // separators. Returns NULL if no path separator was found. const char* FindLastPathSeparator() const; + // Returns the length of the path root, including the directory separator at + // the end of the prefix. Returns zero by definition if the path is relative. + // Examples: + // - [Windows] "..\Sibling" => 0 + // - [Windows] "\Windows" => 1 + // - [Windows] "C:/Windows\Notepad.exe" => 3 + // - [Windows] "\\Host\Share\C$/Windows" => 13 + // - [UNIX] "/bin" => 1 + size_t CalculateRootLength() const; + std::string pathname_; }; // class FilePath diff --git a/googletest/src/gtest-filepath.cc b/googletest/src/gtest-filepath.cc index 6767db0d..bec58700 100644 --- a/googletest/src/gtest-filepath.cc +++ b/googletest/src/gtest-filepath.cc @@ -145,6 +145,45 @@ const char* FilePath::FindLastPathSeparator() const { return last_sep; } +size_t FilePath::CalculateRootLength() const { + const auto &path = pathname_; + auto s = path.begin(); + auto end = path.end(); +#if GTEST_OS_WINDOWS + if (end - s >= 2 && s[1] == ':' && + (end - s == 2 || IsPathSeparator(s[2])) && + (('A' <= s[0] && s[0] <= 'Z') || ('a' <= s[0] && s[0] <= 'z'))) { + // A typical absolute path like "C:\Windows" or "D:" + s += 2; + if (s != end) { + ++s; + } + } else if (end - s >= 3 && IsPathSeparator(*s) && IsPathSeparator(*(s + 1)) + && !IsPathSeparator(*(s + 2))) { + // Move past the "\\" prefix in a UNC path like "\\Server\Share\Folder" + s += 2; + // Skip 2 components and their following separators ("Server\" and "Share\") + for (int i = 0; i < 2; ++i) { + while (s != end) { + bool stop = IsPathSeparator(*s); + ++s; + if (stop) { + break; + } + } + } + } else if (s != end && IsPathSeparator(*s)) { + // A drive-rooted path like "\Windows" + ++s; + } +#else + if (s != end && IsPathSeparator(*s)) { + ++s; + } +#endif + return static_cast(s - path.begin()); +} + // Returns a copy of the FilePath with the directory part removed. // Example: FilePath("path/to/file").RemoveDirectoryName() returns // FilePath("file"). If there is no directory part ("just_a_file"), it returns @@ -246,26 +285,16 @@ bool FilePath::DirectoryExists() const { } // Returns true if pathname describes a root directory. (Windows has one -// root directory per disk drive.) +// root directory per disk drive. UNC share roots are also included.) bool FilePath::IsRootDirectory() const { -#if GTEST_OS_WINDOWS - return pathname_.length() == 3 && IsAbsolutePath(); -#else - return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]); -#endif + size_t root_length = CalculateRootLength(); + return root_length > 0 && root_length == pathname_.size() && + IsPathSeparator(pathname_[root_length - 1]); } // Returns true if pathname describes an absolute path. bool FilePath::IsAbsolutePath() const { - const char* const name = pathname_.c_str(); -#if GTEST_OS_WINDOWS - return pathname_.length() >= 3 && - ((name[0] >= 'a' && name[0] <= 'z') || - (name[0] >= 'A' && name[0] <= 'Z')) && - name[1] == ':' && IsPathSeparator(name[2]); -#else - return IsPathSeparator(name[0]); -#endif + return CalculateRootLength() > 0; } // Returns a pathname for a file that does not currently exist. The pathname @@ -347,17 +376,27 @@ FilePath FilePath::RemoveTrailingPathSeparator() const { // Removes any redundant separators that might be in the pathname. // For example, "bar///foo" becomes "bar/foo". Does not eliminate other // redundancies that might be in a pathname involving "." or "..". +// Note that "\\Host\Share" does not contain a redundancy on Windows! void FilePath::Normalize() { auto out = pathname_.begin(); - for (const char character : pathname_) { + auto i = pathname_.cbegin(); +#if GTEST_OS_WINDOWS + // UNC paths are treated specially + if (pathname_.end() - i >= 3 && IsPathSeparator(*i) && + IsPathSeparator(*(i + 1)) && !IsPathSeparator(*(i + 2))) { + *(out++) = kPathSeparator; + *(out++) = kPathSeparator; + } +#endif + while (i != pathname_.end()) { + const char character = *i; if (!IsPathSeparator(character)) { *(out++) = character; } else if (out == pathname_.begin() || *std::prev(out) != kPathSeparator) { *(out++) = kPathSeparator; - } else { - continue; } + ++i; } pathname_.erase(out, pathname_.end()); diff --git a/googletest/test/googletest-filepath-test.cc b/googletest/test/googletest-filepath-test.cc index fe53f848..1e2cc4aa 100644 --- a/googletest/test/googletest-filepath-test.cc +++ b/googletest/test/googletest-filepath-test.cc @@ -421,8 +421,13 @@ TEST(NormalizeTest, MultipleConsecutiveSeparatorsInMidstring) { // "/bar" == //bar" == "///bar" TEST(NormalizeTest, MultipleConsecutiveSeparatorsAtStringStart) { EXPECT_EQ(GTEST_PATH_SEP_ "bar", FilePath(GTEST_PATH_SEP_ "bar").string()); +#if GTEST_OS_WINDOWS + EXPECT_EQ(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar", + FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string()); +#else EXPECT_EQ(GTEST_PATH_SEP_ "bar", FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string()); +#endif EXPECT_EQ( GTEST_PATH_SEP_ "bar", FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string()); @@ -621,6 +626,9 @@ TEST(FilePathTest, IsAbsolutePath) { EXPECT_TRUE( FilePath("c:/" GTEST_PATH_SEP_ "is_not" GTEST_PATH_SEP_ "relative") .IsAbsolutePath()); + EXPECT_TRUE(FilePath("d:/Windows").IsAbsolutePath()); + EXPECT_TRUE(FilePath("\\\\Host\\Share").IsAbsolutePath()); + EXPECT_TRUE(FilePath("\\\\Host\\Share\\Folder").IsAbsolutePath()); #else EXPECT_TRUE(FilePath(GTEST_PATH_SEP_ "is_not" GTEST_PATH_SEP_ "relative") .IsAbsolutePath()); @@ -637,6 +645,16 @@ TEST(FilePathTest, IsRootDirectory) { EXPECT_FALSE(FilePath("b:a").IsRootDirectory()); EXPECT_FALSE(FilePath("8:/").IsRootDirectory()); EXPECT_FALSE(FilePath("c|/").IsRootDirectory()); + EXPECT_TRUE(FilePath("c:/").IsRootDirectory()); + EXPECT_FALSE(FilePath("d:/Windows").IsRootDirectory()); + + // This is for backward compatibility, since callers (even in this library) + // have assumed IsRootDirectory() implies a trailing directory separator. + EXPECT_FALSE(FilePath("\\\\Host\\Share").IsRootDirectory()); + + EXPECT_TRUE(FilePath("\\\\Host\\Share\\").IsRootDirectory()); + EXPECT_FALSE(FilePath("\\\\Host\\Share\\.").IsRootDirectory()); + EXPECT_FALSE(FilePath("\\\\Host\\Share\\C$\\").IsRootDirectory()); #else EXPECT_TRUE(FilePath("/").IsRootDirectory()); EXPECT_TRUE(FilePath("//").IsRootDirectory()); From 6bad847991e663f2e2cc0fac1e72765763ab616b Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 18 Oct 2022 21:39:44 -0700 Subject: [PATCH 57/57] CMake: Add GTEST_HAS_ABSL build option for using Absl PiperOrigin-RevId: 482101793 Change-Id: I1bd140fd6a325f573c8a0c464e4dccd4acd0d0a3 --- CMakeLists.txt | 1 + googletest/CMakeLists.txt | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 725d6707..4210622b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ include(GNUInstallDirs) #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) if(BUILD_GMOCK) add_subdirectory( googlemock ) diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index aa00a5f3..95bfa442 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -125,6 +125,22 @@ include_directories(${gtest_build_include_dirs}) # aggressive about warnings. cxx_library(gtest "${cxx_strict}" src/gtest-all.cc) set_target_properties(gtest PROPERTIES VERSION ${GOOGLETEST_VERSION}) +if(GTEST_HAS_ABSL) + target_compile_definitions(gtest PUBLIC GTEST_HAS_ABSL=1) + target_link_libraries(gtest PUBLIC + absl::failure_signal_handler + absl::stacktrace + absl::symbolize + absl::flags_parse + absl::flags_reflection + absl::flags_usage + absl::strings + absl::any + absl::optional + absl::variant + re2::re2 + ) +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