Googletest export
Makes testing::ResultOf() work with non-copyable arguments. PiperOrigin-RevId: 271222632
This commit is contained in:
parent
a783ade7c2
commit
cb3f7ce1de
|
@ -1858,7 +1858,9 @@ struct CallableTraits {
|
|||
static void CheckIsValid(Functor /* functor */) {}
|
||||
|
||||
template <typename T>
|
||||
static auto Invoke(Functor f, T arg) -> decltype(f(arg)) { return f(arg); }
|
||||
static auto Invoke(Functor f, const T& arg) -> decltype(f(arg)) {
|
||||
return f(arg);
|
||||
}
|
||||
};
|
||||
|
||||
// Specialization for function pointers.
|
||||
|
@ -1889,7 +1891,7 @@ class ResultOfMatcher {
|
|||
|
||||
template <typename T>
|
||||
operator Matcher<T>() const {
|
||||
return Matcher<T>(new Impl<T>(callable_, matcher_));
|
||||
return Matcher<T>(new Impl<const T&>(callable_, matcher_));
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -4318,6 +4318,16 @@ TEST(ResultOfTest, WorksForLambdas) {
|
|||
EXPECT_FALSE(matcher.Matches(1));
|
||||
}
|
||||
|
||||
TEST(ResultOfTest, WorksForNonCopyableArguments) {
|
||||
Matcher<std::unique_ptr<int>> matcher = ResultOf(
|
||||
[](const std::unique_ptr<int>& str_len) {
|
||||
return std::string(static_cast<size_t>(*str_len), 'x');
|
||||
},
|
||||
"xxx");
|
||||
EXPECT_TRUE(matcher.Matches(std::unique_ptr<int>(new int(3))));
|
||||
EXPECT_FALSE(matcher.Matches(std::unique_ptr<int>(new int(1))));
|
||||
}
|
||||
|
||||
const int* ReferencingFunction(const int& n) { return &n; }
|
||||
|
||||
struct ReferencingFunctor {
|
||||
|
|
Loading…
Reference in New Issue
Block a user