[llvm] [orc-rt] Use the Error matchers in SPSWrapperFunctionTest (PR #228804)

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 3 18:41:13 PDT 2026


https://github.com/lhames created https://github.com/llvm/llvm-project/pull/228804

Use the Error matchers introduced in 4c8a437d0487 to clean up error tests in SPSWrapperFunctionTest.

>From 6cf3b659510db88682d3dc0eea1b3fdfe3a6fd81 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Thu, 1 Oct 2026 16:20:55 +1000
Subject: [PATCH] [orc-rt] Use the Error matchers in SPSWrapperFunctionTest

Use the Error matchers introduced in 4c8a437d0487 to clean up error
tests in SPSWrapperFunctionTest.
---
 .../support/sps/SPSWrapperFunctionTest.cpp    | 61 ++++++++++++++-----
 1 file changed, 45 insertions(+), 16 deletions(-)

diff --git a/orc-rt/test/unit/support/sps/SPSWrapperFunctionTest.cpp b/orc-rt/test/unit/support/sps/SPSWrapperFunctionTest.cpp
index 44b81f62a0d69..ffc06aaaf8b7d 100644
--- a/orc-rt/test/unit/support/sps/SPSWrapperFunctionTest.cpp
+++ b/orc-rt/test/unit/support/sps/SPSWrapperFunctionTest.cpp
@@ -11,6 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "CommonTestUtils.h"
+#include "ErrorMatchers.h"
 
 #include "orc-rt/support/WrapperFunction.h"
 #include "orc-rt/support/move_only_function.h"
@@ -45,11 +46,11 @@ static void void_noop_sps_wrapper(orc_rt_SessionRef S,
 
 TEST(SPSWrapperFunctionUtilsTest, VoidNoop) {
   bool Ran = false;
-  SPSWrapperFunction<void()>::call(DirectCaller(nullptr, void_noop_sps_wrapper),
-                                   [&](Error Err) {
-                                     cantFail(std::move(Err));
-                                     Ran = true;
-                                   });
+  SPSWrapperFunction<void()>::call(
+      DirectCaller(nullptr, void_noop_sps_wrapper), [&](Error Err) {
+        EXPECT_THAT_ERROR(std::move(Err), Succeeded());
+        Ran = true;
+      });
   EXPECT_TRUE(Ran);
 }
 
@@ -68,7 +69,11 @@ TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaLambda) {
   int32_t Result = 0;
   SPSWrapperFunction<int32_t(int32_t, int32_t)>::call(
       DirectCaller(nullptr, add_via_lambda_sps_wrapper),
-      [&](Expected<int32_t> R) { Result = cantFail(std::move(R)); }, 41, 1);
+      [&](Expected<int32_t> R) {
+        ASSERT_THAT_EXPECTED(R, Succeeded());
+        Result = *R;
+      },
+      41, 1);
   EXPECT_EQ(Result, 42);
 }
 
@@ -76,7 +81,11 @@ TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunction) {
   int32_t Result = 0;
   SPSWrapperFunction<int32_t(int32_t, int32_t)>::call(
       DirectCaller(nullptr, add_via_function_sps_wrapper),
-      [&](Expected<int32_t> R) { Result = cantFail(std::move(R)); }, 41, 1);
+      [&](Expected<int32_t> R) {
+        ASSERT_THAT_EXPECTED(R, Succeeded());
+        Result = *R;
+      },
+      41, 1);
   EXPECT_EQ(Result, 42);
 }
 
@@ -91,7 +100,11 @@ TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunctionPointer) {
   int32_t Result = 0;
   SPSWrapperFunction<int32_t(int32_t, int32_t)>::call(
       DirectCaller(nullptr, add_via_function_pointer_sps_wrapper),
-      [&](Expected<int32_t> R) { Result = cantFail(std::move(R)); }, 41, 1);
+      [&](Expected<int32_t> R) {
+        ASSERT_THAT_EXPECTED(R, Succeeded());
+        Result = *R;
+      },
+      41, 1);
   EXPECT_EQ(Result, 42);
 }
 
@@ -112,7 +125,10 @@ TEST(SPSWrapperFunctionUtilsTest, RoundTripStringViaSpan) {
   std::string Result;
   SPSWrapperFunction<SPSString(SPSString)>::call(
       DirectCaller(nullptr, round_trip_string_via_span_sps_wrapper),
-      [&](Expected<std::string> R) { Result = cantFail(std::move(R)); },
+      [&](Expected<std::string> R) {
+        ASSERT_THAT_EXPECTED(R, Succeeded());
+        Result = std::move(*R);
+      },
       std::string_view("hello, world!"));
   EXPECT_EQ(Result, "hello, world!");
 }
@@ -137,7 +153,8 @@ TEST(SPSWrapperFunctionUtilsTest, TransparentConversionErrorSuccessCase) {
       DirectCaller(nullptr, improbable_feat_sps_wrapper),
       [&](Expected<Error> E) {
         DidRun = true;
-        cantFail(cantFail(std::move(E)));
+        ASSERT_THAT_EXPECTED(E, Succeeded());
+        EXPECT_THAT_ERROR(std::move(*E), Succeeded());
       },
       true);
 
@@ -148,7 +165,10 @@ TEST(SPSWrapperFunctionUtilsTest, TransparentConversionErrorFailureCase) {
   std::string ErrMsg;
   SPSWrapperFunction<SPSError(bool)>::call(
       DirectCaller(nullptr, improbable_feat_sps_wrapper),
-      [&](Expected<Error> E) { ErrMsg = toString(cantFail(std::move(E))); },
+      [&](Expected<Error> E) {
+        ASSERT_THAT_EXPECTED(E, Succeeded());
+        ErrMsg = toString(std::move(*E));
+      },
       false);
 
   EXPECT_EQ(ErrMsg, "crushed by boulder");
@@ -173,7 +193,9 @@ TEST(SPSWrapperFunctionUtilsTest, TransparentConversionExpectedSuccessCase) {
   SPSWrapperFunction<SPSExpected<int32_t>(int32_t)>::call(
       DirectCaller(nullptr, halve_number_sps_wrapper),
       [&](Expected<Expected<int32_t>> R) {
-        Result = cantFail(cantFail(std::move(R)));
+        ASSERT_THAT_EXPECTED(R, Succeeded());
+        ASSERT_THAT_EXPECTED(*R, Succeeded());
+        Result = **R;
       },
       2);
 
@@ -185,7 +207,8 @@ TEST(SPSWrapperFunctionUtilsTest, TransparentConversionExpectedFailureCase) {
   SPSWrapperFunction<SPSExpected<int32_t>(int32_t)>::call(
       DirectCaller(nullptr, halve_number_sps_wrapper),
       [&](Expected<Expected<int32_t>> R) {
-        ErrMsg = toString(cantFail(std::move(R)).takeError());
+        ASSERT_THAT_EXPECTED(R, Succeeded());
+        ErrMsg = toString(R->takeError());
       },
       3);
 
@@ -232,7 +255,7 @@ TEST(SPSWrapperFunctionUtilsTest, HandlerWithReferences) {
       call(
           DirectCaller(nullptr, handle_with_reference_types_sps_wrapper),
           [&](Error R) {
-            cantFail(std::move(R));
+            EXPECT_THAT_ERROR(std::move(R), Succeeded());
             DidRun = true;
           },
           OpCounter<0>(), OpCounter<1>(), OpCounter<2>(), OpCounter<3>());
@@ -292,7 +315,10 @@ TEST(SPSWrapperFunctionUtilsTest, HandleWtihAsyncMethod) {
   int32_t Result = 0;
   SPSWrapperFunction<int32_t(SPSExecutorAddr, int32_t, int32_t)>::call(
       DirectCaller(nullptr, adder_add_async_sps_wrapper),
-      [&](Expected<int32_t> R) { Result = cantFail(std::move(R)); },
+      [&](Expected<int32_t> R) {
+        ASSERT_THAT_EXPECTED(R, Succeeded());
+        Result = *R;
+      },
       ExecutorAddr::fromPtr(A.get()), 41, 1);
 
   EXPECT_EQ(Result, 42);
@@ -312,7 +338,10 @@ TEST(SPSWrapperFunctionUtilsTest, HandleWithSyncMethod) {
   int32_t Result = 0;
   SPSWrapperFunction<int32_t(SPSExecutorAddr, int32_t, int32_t)>::call(
       DirectCaller(nullptr, adder_add_sync_sps_wrapper),
-      [&](Expected<int32_t> R) { Result = cantFail(std::move(R)); },
+      [&](Expected<int32_t> R) {
+        ASSERT_THAT_EXPECTED(R, Succeeded());
+        Result = *R;
+      },
       ExecutorAddr::fromPtr(A.get()), 41, 1);
 
   EXPECT_EQ(Result, 42);



More information about the llvm-commits mailing list