[llvm] [orc-rt] Add testcase for Expected<Expected<T>> support. (PR #161660)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 2 05:54:10 PDT 2025
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/161660
Follows addition of Expected<Error> support (99ce2062462), 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.
>From 846004d08191ed3c340dd214acd64ff8f1396a7b Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Thu, 2 Oct 2025 22:49:22 +1000
Subject: [PATCH] [orc-rt] Add testcase for Expected<Expected<T>> support.
Follows addition of Expected<Error> support (99ce2062462), 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.
---
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<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());
More information about the llvm-commits
mailing list