[llvm] r329703 - [Testing/Support] Make Failed() matcher work with abstract error types
Pavel Labath via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 10 07:11:53 PDT 2018
Author: labath
Date: Tue Apr 10 07:11:53 2018
New Revision: 329703
URL: http://llvm.org/viewvc/llvm-project?rev=329703&view=rev
Log:
[Testing/Support] Make Failed() matcher work with abstract error types
Failed<ErrorInfoBase>() did not compile, because it was attempting to
create a copy of the Error object when passing it to the nested matcher,
which was not possible because ErrorInfoBase is abstract.
This commit fixes the problem by making sure we pass the ErrorInfo
object by reference, which also improves the handling of non-abstract
objects, as we avoid potentially slicing an object during the copy.
Modified:
llvm/trunk/include/llvm/Testing/Support/Error.h
llvm/trunk/unittests/Support/ErrorTest.cpp
Modified: llvm/trunk/include/llvm/Testing/Support/Error.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Testing/Support/Error.h?rev=329703&r1=329702&r2=329703&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Testing/Support/Error.h (original)
+++ llvm/trunk/include/llvm/Testing/Support/Error.h Tue Apr 10 07:11:53 2018
@@ -85,7 +85,7 @@ private:
template <typename InfoT>
class ErrorMatchesMono : public testing::MatcherInterface<const ErrorHolder &> {
public:
- explicit ErrorMatchesMono(Optional<testing::Matcher<InfoT>> Matcher)
+ explicit ErrorMatchesMono(Optional<testing::Matcher<InfoT &>> Matcher)
: Matcher(std::move(Matcher)) {}
bool MatchAndExplain(const ErrorHolder &Holder,
@@ -127,7 +127,7 @@ public:
}
private:
- Optional<testing::Matcher<InfoT>> Matcher;
+ Optional<testing::Matcher<InfoT &>> Matcher;
};
} // namespace detail
@@ -152,7 +152,7 @@ testing::Matcher<const detail::ErrorHold
template <typename InfoT, typename M>
testing::Matcher<const detail::ErrorHolder &> Failed(M Matcher) {
return MakeMatcher(new detail::ErrorMatchesMono<InfoT>(
- testing::SafeMatcherCast<InfoT>(Matcher)));
+ testing::SafeMatcherCast<InfoT &>(Matcher)));
}
template <typename M>
Modified: llvm/trunk/unittests/Support/ErrorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ErrorTest.cpp?rev=329703&r1=329702&r2=329703&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/ErrorTest.cpp (original)
+++ llvm/trunk/unittests/Support/ErrorTest.cpp Tue Apr 10 07:11:53 2018
@@ -749,6 +749,7 @@ TEST(Error, ErrorMatchers) {
"Expected: failed with Error of given type and the error is an object "
"whose given property is equal to 1\n"
" Actual: failed (CustomError { 0})");
+ EXPECT_THAT_ERROR(make_error<CustomError>(0), Failed<ErrorInfoBase>());
EXPECT_THAT_EXPECTED(Expected<int>(0), Succeeded());
EXPECT_NONFATAL_FAILURE(
More information about the llvm-commits
mailing list