mirror of
https://github.com/google/googletest.git
synced 2026-02-08 18:56:46 +08:00
Merge branch 'google:main' into master
This commit is contained in:
commit
6c2582f97f
@ -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)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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 ";" "$<SEMICOLON>" dirs "${gmock_build_include_dirs}")
|
||||
target_include_directories(gmock SYSTEM INTERFACE
|
||||
"$<BUILD_INTERFACE:${gmock_build_include_dirs}>"
|
||||
"$<BUILD_INTERFACE:${dirs}>"
|
||||
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
target_include_directories(gmock_main SYSTEM INTERFACE
|
||||
"$<BUILD_INTERFACE:${gmock_build_include_dirs}>"
|
||||
"$<BUILD_INTERFACE:${dirs}>"
|
||||
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
endif()
|
||||
|
||||
|
||||
@ -2206,13 +2206,21 @@ template <typename Callable, typename InnerMatcher>
|
||||
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<Callable>::CheckIsValid(callable_);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
operator Matcher<T>() const {
|
||||
return Matcher<T>(new Impl<const T&>(callable_, matcher_));
|
||||
return Matcher<T>(
|
||||
new Impl<const T&>(result_description_, callable_, matcher_));
|
||||
}
|
||||
|
||||
private:
|
||||
@ -2225,16 +2233,27 @@ class ResultOfMatcher {
|
||||
|
||||
public:
|
||||
template <typename M>
|
||||
Impl(const CallableStorageType& callable, const M& matcher)
|
||||
: callable_(callable), matcher_(MatcherCast<ResultType>(matcher)) {}
|
||||
Impl(const std::string& result_description,
|
||||
const CallableStorageType& callable, const M& matcher)
|
||||
: result_description_(result_description),
|
||||
callable_(callable),
|
||||
matcher_(MatcherCast<ResultType>(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<ResultType> matcher_;
|
||||
}; // class Impl
|
||||
|
||||
const std::string result_description_;
|
||||
const CallableStorageType callable_;
|
||||
const InnerMatcher matcher_;
|
||||
};
|
||||
@ -4422,6 +4443,16 @@ internal::ResultOfMatcher<Callable, InnerMatcher> ResultOf(
|
||||
std::move(matcher));
|
||||
}
|
||||
|
||||
// Same as ResultOf() above, but also takes a description of the `callable`
|
||||
// result to provide better error messages.
|
||||
template <typename Callable, typename InnerMatcher>
|
||||
internal::ResultOfMatcher<Callable, InnerMatcher> ResultOf(
|
||||
const std::string& result_description, Callable callable,
|
||||
InnerMatcher matcher) {
|
||||
return internal::ResultOfMatcher<Callable, InnerMatcher>(
|
||||
result_description, std::move(callable), std::move(matcher));
|
||||
}
|
||||
|
||||
// String matchers.
|
||||
|
||||
// Matches a string equal to str.
|
||||
|
||||
@ -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<int> 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; }
|
||||
|
||||
|
||||
@ -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 ";" "$<SEMICOLON>" dirs "${gtest_build_include_dirs}")
|
||||
target_include_directories(gtest SYSTEM INTERFACE
|
||||
"$<BUILD_INTERFACE:${gtest_build_include_dirs}>"
|
||||
"$<BUILD_INTERFACE:${dirs}>"
|
||||
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
target_include_directories(gtest_main SYSTEM INTERFACE
|
||||
"$<BUILD_INTERFACE:${gtest_build_include_dirs}>"
|
||||
"$<BUILD_INTERFACE:${dirs}>"
|
||||
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
endif()
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "QNX")
|
||||
|
||||
@ -45,11 +45,13 @@
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <iomanip>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <ostream> // NOLINT
|
||||
#include <sstream>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/gtest-assertion-result.h"
|
||||
@ -727,6 +729,11 @@ static bool PatternMatchesString(const std::string& name_str,
|
||||
|
||||
namespace {
|
||||
|
||||
bool IsGlobPattern(const std::string& pattern) {
|
||||
return std::any_of(pattern.begin(), pattern.end(),
|
||||
[](const char c) { return c == '?' || c == '*'; });
|
||||
}
|
||||
|
||||
class UnitTestFilter {
|
||||
public:
|
||||
UnitTestFilter() = default;
|
||||
@ -734,13 +741,25 @@ 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_);
|
||||
std::vector<std::string> all_patterns;
|
||||
SplitString(filter, ':', &all_patterns);
|
||||
const auto exact_match_patterns_begin = std::partition(
|
||||
all_patterns.begin(), all_patterns.end(), &IsGlobPattern);
|
||||
|
||||
glob_patterns_.reserve(static_cast<size_t>(
|
||||
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(
|
||||
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
|
||||
// the filter.
|
||||
bool MatchesName(const std::string& name) const {
|
||||
return std::any_of(patterns_.begin(), patterns_.end(),
|
||||
return exact_match_patterns_.count(name) > 0 ||
|
||||
std::any_of(glob_patterns_.begin(), glob_patterns_.end(),
|
||||
[&name](const std::string& pattern) {
|
||||
return PatternMatchesString(
|
||||
name, pattern.c_str(),
|
||||
@ -749,7 +768,8 @@ class UnitTestFilter {
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> patterns_;
|
||||
std::vector<std::string> glob_patterns_;
|
||||
std::unordered_set<std::string> exact_match_patterns_;
|
||||
};
|
||||
|
||||
class PositiveAndNegativeUnitTestFilter {
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user