diff options
Diffstat (limited to 'llvm/unittests/Support/ErrorTest.cpp')
| -rw-r--r-- | llvm/unittests/Support/ErrorTest.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp index 1807547..fadb00c 100644 --- a/llvm/unittests/Support/ErrorTest.cpp +++ b/llvm/unittests/Support/ErrorTest.cpp @@ -416,7 +416,7 @@ TEST(Error, ExpectedCovariance) { A2 = Expected<std::unique_ptr<D>>(nullptr); } -TEST(Error, ECError) { +TEST(Error, ErrorCodeConversions) { // Round-trip a success value to check that it converts correctly. EXPECT_EQ(errorToErrorCode(errorCodeToError(std::error_code())), std::error_code()) @@ -427,6 +427,29 @@ TEST(Error, ECError) { errc::invalid_argument) << "std::error_code error value should round-trip via Error " "conversions"; + + // Round-trip a success value through ErrorOr/Expected to check that it + // converts correctly. + { + auto Orig = ErrorOr<int>(42); + auto RoundTripped = + expectedToErrorOr(errorOrToExpected(ErrorOr<int>(42))); + EXPECT_EQ(*Orig, *RoundTripped) + << "ErrorOr<T> success value should round-trip via Expected<T> " + "conversions."; + } + + // Round-trip a failure value through ErrorOr/Expected to check that it + // converts correctly. + { + auto Orig = ErrorOr<int>(errc::invalid_argument); + auto RoundTripped = + expectedToErrorOr( + errorOrToExpected(ErrorOr<int>(errc::invalid_argument))); + EXPECT_EQ(Orig.getError(), RoundTripped.getError()) + << "ErrorOr<T> failure value should round-trip via Expected<T> " + "conversions."; + } } } // end anon namespace |
