diff options
author | Pavel Labath <labath@google.com> | 2017-12-13 10:00:38 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2017-12-13 10:00:38 +0000 |
commit | 1f8ac167fe871171f7ab93f59314f8b493ef1d39 (patch) | |
tree | 3013a7a524e501cd586130c7810c6deb43c03fc4 /unittests | |
parent | 6d0dcae300a6ea513e58e4bf7593856050c512d7 (diff) |
[Testing/Support] Make the HasValue matcher composable
Summary:
This makes it possible to run an arbitrary matcher on the value
contained within the Expected<T> object.
To do this, I've needed to fully spell out the matcher, instead of using
the shorthand MATCHER_P macro.
The slight gotcha here is that standard template deduction will fail if
one tries to match HasValue(47) against an Expected<int &> -- the
workaround is to use HasValue(testing::Eq(47)).
The explanations produced by this matcher have changed a bit, since now
we delegate to the nested matcher to print the value. Since these don't
put quotes around the value, I've changed our PrintTo methods to match.
Reviewers: zturner
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D41065
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320561 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Support/ErrorTest.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/unittests/Support/ErrorTest.cpp b/unittests/Support/ErrorTest.cpp index 213ed55c721..2629e640f79 100644 --- a/unittests/Support/ErrorTest.cpp +++ b/unittests/Support/ErrorTest.cpp @@ -735,23 +735,34 @@ TEST(Error, ErrorMatchers) { EXPECT_THAT_EXPECTED(Expected<int>(make_error<CustomError>(0)), Failed()); EXPECT_NONFATAL_FAILURE( EXPECT_THAT_EXPECTED(Expected<int>(0), Failed()), - "Expected: failed\n Actual: succeeded with value \"0\""); + "Expected: failed\n Actual: succeeded with value 0"); EXPECT_THAT_EXPECTED(Expected<int>(0), HasValue(0)); EXPECT_NONFATAL_FAILURE( EXPECT_THAT_EXPECTED(Expected<int>(make_error<CustomError>(0)), HasValue(0)), - "Expected: succeeded with value \"0\"\n" + "Expected: succeeded with value (is equal to 0)\n" " Actual: failed (CustomError { 0})"); EXPECT_NONFATAL_FAILURE( EXPECT_THAT_EXPECTED(Expected<int>(1), HasValue(0)), - "Expected: succeeded with value \"0\"\n" - " Actual: succeeded with value \"1\", but \"1\" != \"0\""); + "Expected: succeeded with value (is equal to 0)\n" + " Actual: succeeded with value 1, (isn't equal to 0)"); EXPECT_THAT_EXPECTED(Expected<int &>(make_error<CustomError>(0)), Failed()); int a = 1; EXPECT_THAT_EXPECTED(Expected<int &>(a), Succeeded()); - EXPECT_THAT_EXPECTED(Expected<int &>(a), HasValue(1)); + EXPECT_THAT_EXPECTED(Expected<int &>(a), HasValue(testing::Eq(1))); + + EXPECT_THAT_EXPECTED(Expected<int>(1), HasValue(testing::Gt(0))); + EXPECT_NONFATAL_FAILURE( + EXPECT_THAT_EXPECTED(Expected<int>(0), HasValue(testing::Gt(1))), + "Expected: succeeded with value (is > 1)\n" + " Actual: succeeded with value 0, (isn't > 1)"); + EXPECT_NONFATAL_FAILURE( + EXPECT_THAT_EXPECTED(Expected<int>(make_error<CustomError>(0)), + HasValue(testing::Gt(1))), + "Expected: succeeded with value (is > 1)\n" + " Actual: failed (CustomError { 0})"); } } // end anon namespace |