diff --git a/orc-rt/unittests/ErrorTest.cpp b/orc-rt/unittests/ErrorTest.cpp index 6b1fc1635b5b8..260b6afc2ae95 100644 --- a/orc-rt/unittests/ErrorTest.cpp +++ b/orc-rt/unittests/ErrorTest.cpp @@ -409,6 +409,31 @@ TEST(ErrorTest, ExpectedError) { } } +// Test that Expected> works as expected. +TEST(ErrorTest, ExpectedExpected) { + { + // Test success-success case. + Expected> E(Expected(42), ForceExpectedSuccessValue()); + EXPECT_TRUE(!!E); + cantFail(E.takeError()); + auto EI = std::move(*E); + EXPECT_TRUE(!!EI); + cantFail(EI.takeError()); + EXPECT_EQ(*EI, 42); + } + + { + // Test "failure" success case. + Expected> E(Expected(make_error("foo")), + ForceExpectedSuccessValue()); + EXPECT_TRUE(!!E); + cantFail(E.takeError()); + auto EI = std::move(*E); + EXPECT_FALSE(!!EI); + EXPECT_EQ(toString(EI.takeError()), "foo"); + } +} + // Test that the ExitOnError utility works as expected. TEST(ErrorTest, CantFailSuccess) { cantFail(Error::success());