aboutsummaryrefslogtreecommitdiff
path: root/orc-rt/unittests/ErrorTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'orc-rt/unittests/ErrorTest.cpp')
-rw-r--r--orc-rt/unittests/ErrorTest.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/orc-rt/unittests/ErrorTest.cpp b/orc-rt/unittests/ErrorTest.cpp
index 3fd8279..260b6afc 100644
--- a/orc-rt/unittests/ErrorTest.cpp
+++ b/orc-rt/unittests/ErrorTest.cpp
@@ -386,6 +386,54 @@ TEST(ErrorTest, ExpectedCovariance) {
(void)!!A2;
}
+// Test that Expected<Error> works as expected.
+TEST(ErrorTest, ExpectedError) {
+ {
+ // Test success-success case.
+ Expected<Error> E(Error::success(), ForceExpectedSuccessValue());
+ EXPECT_TRUE(!!E);
+ cantFail(E.takeError());
+ auto Err = std::move(*E);
+ EXPECT_FALSE(!!Err);
+ }
+
+ {
+ // Test "failure" success case.
+ Expected<Error> E(make_error<StringError>("foo"),
+ ForceExpectedSuccessValue());
+ EXPECT_TRUE(!!E);
+ cantFail(E.takeError());
+ auto Err = std::move(*E);
+ EXPECT_TRUE(!!Err);
+ EXPECT_EQ(toString(std::move(Err)), "foo");
+ }
+}
+
+// Test that Expected<Expected<T>> works as expected.
+TEST(ErrorTest, ExpectedExpected) {
+ {
+ // Test success-success case.
+ Expected<Expected<int>> E(Expected<int>(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<Expected<int>> E(Expected<int>(make_error<StringError>("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());