Skip to content

Commit 3757fa6

Browse files
authored
[orc-rt] Add testcase for Expected<Expected<T>> support. (#161660)
Follows addition of Expected<Error> support (99ce206), and has essentially the same motivation: supporting RPC calls to functions returning Expected<T>, where the RPC infrastructure wants to be able to wrap that result in its own Expected.
1 parent 8f2466b commit 3757fa6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

orc-rt/unittests/ErrorTest.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,31 @@ TEST(ErrorTest, ExpectedError) {
409409
}
410410
}
411411

412+
// Test that Expected<Expected<T>> works as expected.
413+
TEST(ErrorTest, ExpectedExpected) {
414+
{
415+
// Test success-success case.
416+
Expected<Expected<int>> E(Expected<int>(42), ForceExpectedSuccessValue());
417+
EXPECT_TRUE(!!E);
418+
cantFail(E.takeError());
419+
auto EI = std::move(*E);
420+
EXPECT_TRUE(!!EI);
421+
cantFail(EI.takeError());
422+
EXPECT_EQ(*EI, 42);
423+
}
424+
425+
{
426+
// Test "failure" success case.
427+
Expected<Expected<int>> E(Expected<int>(make_error<StringError>("foo")),
428+
ForceExpectedSuccessValue());
429+
EXPECT_TRUE(!!E);
430+
cantFail(E.takeError());
431+
auto EI = std::move(*E);
432+
EXPECT_FALSE(!!EI);
433+
EXPECT_EQ(toString(EI.takeError()), "foo");
434+
}
435+
}
436+
412437
// Test that the ExitOnError utility works as expected.
413438
TEST(ErrorTest, CantFailSuccess) {
414439
cantFail(Error::success());

0 commit comments

Comments
 (0)