From 846004d08191ed3c340dd214acd64ff8f1396a7b Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 2 Oct 2025 22:49:22 +1000 Subject: [PATCH] [orc-rt] Add testcase for Expected> support. Follows addition of Expected support (99ce2062462), and has essentially the same motivation: supporting RPC calls to functions returning Expected, where the RPC infrastructure wants to be able to wrap that result in its own Expected. --- orc-rt/unittests/ErrorTest.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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());