From 64f19a9fc39fb56bf643a82545cce922630091b4 Mon Sep 17 00:00:00 2001 From: Deniz Bahadir Date: Tue, 19 Oct 2021 15:14:44 +0200 Subject: [PATCH 1/8] CMake: Fix values of INTERFACE_INCLUDE_DIRECTORIES property Replace semicolon by `$` in generator-expressions of target property `INTERFACE_INCLUDE_DIRECTORIES` of CMake targets `gtest`, `gtest_main`, `gmock` and `gmock_main`. Fixes: #3616 Signed-off-by: Deniz Bahadir --- googlemock/CMakeLists.txt | 5 +++-- googletest/CMakeLists.txt | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/googlemock/CMakeLists.txt b/googlemock/CMakeLists.txt index 2b55ba15..3ab75a1b 100644 --- a/googlemock/CMakeLists.txt +++ b/googlemock/CMakeLists.txt @@ -105,11 +105,12 @@ endif() # to the targets for when we are part of a parent build (ie being pulled # in via add_subdirectory() rather than being a standalone build). if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") + string(REPLACE ";" "$" dirs "${gmock_build_include_dirs}") target_include_directories(gmock SYSTEM INTERFACE - "$" + "$" "$/${CMAKE_INSTALL_INCLUDEDIR}>") target_include_directories(gmock_main SYSTEM INTERFACE - "$" + "$" "$/${CMAKE_INSTALL_INCLUDEDIR}>") endif() diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index 15b8f0c3..b03e71c5 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -131,11 +131,12 @@ set_target_properties(gtest_main PROPERTIES VERSION ${GOOGLETEST_VERSION}) # to the targets for when we are part of a parent build (ie being pulled # in via add_subdirectory() rather than being a standalone build). if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") + string(REPLACE ";" "$" dirs "${gtest_build_include_dirs}") target_include_directories(gtest SYSTEM INTERFACE - "$" + "$" "$/${CMAKE_INSTALL_INCLUDEDIR}>") target_include_directories(gtest_main SYSTEM INTERFACE - "$" + "$" "$/${CMAKE_INSTALL_INCLUDEDIR}>") endif() target_link_libraries(gtest_main PUBLIC gtest) From 91461509de9b4bfacbad7fb927981aaf0b3327eb Mon Sep 17 00:00:00 2001 From: Joris van der Pol <73706994+jjfvanderpol@users.noreply.github.com> Date: Wed, 5 Jan 2022 11:07:50 +0100 Subject: [PATCH 2/8] Set CMake Policy CMP0077 to NEW --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d2eb810..4daf35b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,10 @@ if (POLICY CMP0048) cmake_policy(SET CMP0048 NEW) endif (POLICY CMP0048) +if (POLICY CMP0077) + cmake_policy(SET CMP0077 NEW) +endif (POLICY CMP0077) + project(googletest-distribution) set(GOOGLETEST_VERSION 1.11.0) From 2eadda6e0072d47ddea1dc24a1ed63abb995cdfe Mon Sep 17 00:00:00 2001 From: Hossein Ghahramanzadeh Date: Sat, 29 Jan 2022 08:05:03 +0100 Subject: [PATCH 3/8] Do constant time matching for exact match filters. --- googletest/src/gtest.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 04266dca..c04aac6f 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -50,6 +50,7 @@ #include #include // NOLINT #include +#include #include #include "gtest/gtest-assertion-result.h" @@ -725,6 +726,11 @@ static bool PatternMatchesString(const std::string& name_str, return true; } +static bool IsGlobPattern(const std::string& pattern) { + return std::any_of(pattern.begin(), pattern.end(), + [](const char c) { return c == '?' || c == '*'; }); +} + namespace { class UnitTestFilter { @@ -734,13 +740,19 @@ class UnitTestFilter { // Constructs a filter from a string of patterns separated by `:`. explicit UnitTestFilter(const std::string& filter) { // By design "" filter matches "" string. - SplitString(filter, ':', &patterns_); + SplitString(filter, ':', &glob_patterns_); + const auto exact_match_pattern_begin = std::partition( + glob_patterns_.begin(), glob_patterns_.end(), &IsGlobPattern); + exact_match_patterns_.insert(exact_match_pattern_begin, + glob_patterns_.end()); + glob_patterns_.erase(exact_match_pattern_begin, glob_patterns_.end()); } // Returns true if and only if name matches at least one of the patterns in // the filter. bool MatchesName(const std::string& name) const { - return std::any_of(patterns_.begin(), patterns_.end(), + return exact_match_patterns_.count(name) || + std::any_of(glob_patterns_.begin(), glob_patterns_.end(), [&name](const std::string& pattern) { return PatternMatchesString( name, pattern.c_str(), @@ -749,7 +761,8 @@ class UnitTestFilter { } private: - std::vector patterns_; + std::vector glob_patterns_; + std::unordered_set exact_match_patterns_; }; class PositiveAndNegativeUnitTestFilter { From 631f4f9947fd97bfa6dd10d253830a5c2988e752 Mon Sep 17 00:00:00 2001 From: Andrew Krasavin Date: Sat, 5 Feb 2022 03:44:54 +0300 Subject: [PATCH 4/8] Fix gtest-help-test failure on OpenBSD --- googletest/test/gtest_help_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/googletest/test/gtest_help_test.py b/googletest/test/gtest_help_test.py index 3e628ae5..6d2dde00 100755 --- a/googletest/test/gtest_help_test.py +++ b/googletest/test/gtest_help_test.py @@ -45,6 +45,7 @@ from googletest.test import gtest_test_utils IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux' IS_GNUHURD = os.name == 'posix' and os.uname()[0] == 'GNU' IS_GNUKFREEBSD = os.name == 'posix' and os.uname()[0] == 'GNU/kFreeBSD' +IS_OPENBSD = os.name == 'posix' and os.uname()[0] == 'OpenBSD' IS_WINDOWS = os.name == 'nt' PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_') @@ -113,7 +114,7 @@ class GTestHelpTest(gtest_test_utils.TestCase): self.assertEquals(0, exit_code) self.assert_(HELP_REGEX.search(output), output) - if IS_LINUX or IS_GNUHURD or IS_GNUKFREEBSD: + if IS_LINUX or IS_GNUHURD or IS_GNUKFREEBSD or IS_OPENBSD: self.assert_(STREAM_RESULT_TO_FLAG in output, output) else: self.assert_(STREAM_RESULT_TO_FLAG not in output, output) From d6841c040d63b6e2bc716e365d1c60d26f23b1f5 Mon Sep 17 00:00:00 2001 From: Hossein Ghahramanzadeh Date: Sat, 5 Feb 2022 17:43:21 +0100 Subject: [PATCH 5/8] Apply requested changes by using std::inserter with move. --- googletest/src/gtest.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index c04aac6f..80fa0ea7 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -726,13 +726,13 @@ static bool PatternMatchesString(const std::string& name_str, return true; } -static bool IsGlobPattern(const std::string& pattern) { +namespace { + +bool IsGlobPattern(const std::string& pattern) { return std::any_of(pattern.begin(), pattern.end(), [](const char c) { return c == '?' || c == '*'; }); } -namespace { - class UnitTestFilter { public: UnitTestFilter() = default; @@ -740,12 +740,14 @@ class UnitTestFilter { // Constructs a filter from a string of patterns separated by `:`. explicit UnitTestFilter(const std::string& filter) { // By design "" filter matches "" string. - SplitString(filter, ':', &glob_patterns_); - const auto exact_match_pattern_begin = std::partition( - glob_patterns_.begin(), glob_patterns_.end(), &IsGlobPattern); - exact_match_patterns_.insert(exact_match_pattern_begin, - glob_patterns_.end()); - glob_patterns_.erase(exact_match_pattern_begin, glob_patterns_.end()); + std::vector all_patterns; + SplitString(filter, ':', &all_patterns); + const auto exact_match_patterns_begin = std::partition( + all_patterns.begin(), all_patterns.end(), &IsGlobPattern); + + glob_patterns_.reserve(exact_match_patterns_begin - all_patterns.begin()); + std::move(all_patterns.begin(), exact_match_patterns_begin, std::inserter(glob_patterns_, glob_patterns_.begin())); + std::move(exact_match_patterns_begin, all_patterns.end(), std::inserter(exact_match_patterns_, exact_match_patterns_.begin())); } // Returns true if and only if name matches at least one of the patterns in From 0e402173c97aea7a00749e825b194bfede4f2e45 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 9 Feb 2022 16:19:22 -0800 Subject: [PATCH 6/8] Add a 3-arg overload for ResultOf() matcher that takes a description string for better error messages. PiperOrigin-RevId: 427598749 Change-Id: I8c7a5d7b2dde017641534f1c7eed8dd56c33e845 --- docs/reference/matchers.md | 1 + googlemock/include/gmock/gmock-matchers.h | 43 +++++++++++++++++++---- googlemock/test/gmock-matchers_test.cc | 10 ++++++ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/docs/reference/matchers.md b/docs/reference/matchers.md index 47d2808c..0f57db47 100644 --- a/docs/reference/matchers.md +++ b/docs/reference/matchers.md @@ -194,6 +194,7 @@ messages, you can use: | Matcher | Description | | :--------------- | :------------------------------------------------ | | `ResultOf(f, m)` | `f(argument)` matches matcher `m`, where `f` is a function or functor. | +| `ResultOf(result_description, f, m)` | The same as the two-parameter version, but provides a better error message. ## Pointer Matchers diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 5cf5019d..95845864 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -2206,13 +2206,21 @@ template class ResultOfMatcher { public: ResultOfMatcher(Callable callable, InnerMatcher matcher) - : callable_(std::move(callable)), matcher_(std::move(matcher)) { + : ResultOfMatcher(/*result_description=*/"", std::move(callable), + std::move(matcher)) {} + + ResultOfMatcher(const std::string& result_description, Callable callable, + InnerMatcher matcher) + : result_description_(result_description), + callable_(std::move(callable)), + matcher_(std::move(matcher)) { CallableTraits::CheckIsValid(callable_); } template operator Matcher() const { - return Matcher(new Impl(callable_, matcher_)); + return Matcher( + new Impl(result_description_, callable_, matcher_)); } private: @@ -2225,16 +2233,27 @@ class ResultOfMatcher { public: template - Impl(const CallableStorageType& callable, const M& matcher) - : callable_(callable), matcher_(MatcherCast(matcher)) {} + Impl(const std::string& result_description, + const CallableStorageType& callable, const M& matcher) + : result_description_(result_description), + callable_(callable), + matcher_(MatcherCast(matcher)) {} void DescribeTo(::std::ostream* os) const override { - *os << "is mapped by the given callable to a value that "; + if (result_description_.empty()) { + *os << "is mapped by the given callable to a value that "; + } else { + *os << "whose " << result_description_ << " "; + } matcher_.DescribeTo(os); } void DescribeNegationTo(::std::ostream* os) const override { - *os << "is mapped by the given callable to a value that "; + if (result_description_.empty()) { + *os << "is mapped by the given callable to a value that "; + } else { + *os << "whose " << result_description_ << " "; + } matcher_.DescribeNegationTo(os); } @@ -2250,6 +2269,7 @@ class ResultOfMatcher { } private: + const std::string result_description_; // Functors often define operator() as non-const method even though // they are actually stateless. But we need to use them even when // 'this' is a const pointer. It's the user's responsibility not to @@ -2259,6 +2279,7 @@ class ResultOfMatcher { const Matcher matcher_; }; // class Impl + const std::string result_description_; const CallableStorageType callable_; const InnerMatcher matcher_; }; @@ -4422,6 +4443,16 @@ internal::ResultOfMatcher ResultOf( std::move(matcher)); } +// Same as ResultOf() above, but also takes a description of the `callable` +// result to provide better error messages. +template +internal::ResultOfMatcher ResultOf( + const std::string& result_description, Callable callable, + InnerMatcher matcher) { + return internal::ResultOfMatcher( + result_description, std::move(callable), std::move(matcher)); +} + // String matchers. // Matches a string equal to str. diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 34282e6f..6d480e0e 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -4643,6 +4643,16 @@ TEST(ResultOfTest, CanDescribeItself) { "isn't equal to \"foo\"", DescribeNegation(matcher)); } +// Tests that ResultOf() can describe itself when provided a result description. +TEST(ResultOfTest, CanDescribeItselfWithResultDescription) { + Matcher matcher = + ResultOf("string conversion", &IntToStringFunction, StrEq("foo")); + + EXPECT_EQ("whose string conversion is equal to \"foo\"", Describe(matcher)); + EXPECT_EQ("whose string conversion isn't equal to \"foo\"", + DescribeNegation(matcher)); +} + // Tests that ResultOf() can explain the match result. int IntFunction(int input) { return input == 42 ? 80 : 90; } From ea55f1f52c489535f0d3b583c81529762c9cb5ea Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 14 Feb 2022 13:27:54 -0800 Subject: [PATCH 7/8] Address conversion warning by explicitly casting to size_t Closes #3762 PiperOrigin-RevId: 428593750 Change-Id: Ifac216568fbc7d999adb71996ec6a1bbe3b97412 --- googletest/src/gtest.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 4775fbc3..396fdfe2 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -745,7 +746,8 @@ class UnitTestFilter { const auto exact_match_patterns_begin = std::partition( all_patterns.begin(), all_patterns.end(), &IsGlobPattern); - glob_patterns_.reserve(exact_match_patterns_begin - all_patterns.begin()); + glob_patterns_.reserve(static_cast( + std::distance(all_patterns.begin(), exact_match_patterns_begin))); std::move(all_patterns.begin(), exact_match_patterns_begin, std::inserter(glob_patterns_, glob_patterns_.begin())); std::move( From c9461a9b55ba954df0489bab6420eb297bed846b Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Thu, 17 Feb 2022 14:18:22 -0800 Subject: [PATCH 8/8] Update GCC/Clang Linux tests to use Bazel 5.0.0 PiperOrigin-RevId: 429400664 Change-Id: I6454cf52cb2fc616a96663823de997591b63dfae --- ci/linux-presubmit.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/linux-presubmit.sh b/ci/linux-presubmit.sh index 0818ef0b..71471886 100644 --- a/ci/linux-presubmit.sh +++ b/ci/linux-presubmit.sh @@ -31,7 +31,7 @@ set -euox pipefail -readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20220113" +readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20220217" readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20210617" if [[ -z ${GTEST_ROOT:-} ]]; then