[llvm] [orc-rt] Use the Error matchers in AllocActionTest (PR #228680)

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 3 01:39:37 PDT 2026


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

Use the Error matchers introduced in 4c8a437d0487 to clean up error checks in AllocActionTest.

>From 90c70af3d64a3a00d54935fd16b648c0fc8765ad Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Thu, 1 Oct 2026 09:28:43 +1000
Subject: [PATCH] [orc-rt] Use the Error matchers in AllocActionTest

Use the Error matchers introduced in 4c8a437d0487 to clean up error
checks in AllocActionTest.
---
 orc-rt/test/unit/support/AllocActionTest.cpp | 36 ++++++++------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/orc-rt/test/unit/support/AllocActionTest.cpp b/orc-rt/test/unit/support/AllocActionTest.cpp
index 7903cacaaec706..7a42fbc804786c 100644
--- a/orc-rt/test/unit/support/AllocActionTest.cpp
+++ b/orc-rt/test/unit/support/AllocActionTest.cpp
@@ -19,6 +19,7 @@
 #include "gtest/gtest.h"
 
 #include "CommonTestUtils.h"
+#include "ErrorMatchers.h"
 
 #include <cstring>
 
@@ -126,12 +127,12 @@ TEST(AllocActionTest, RunFinalizationActionsComplete) {
   InitialActions.push_back({MakeAAOnVal(increment_int_ptr_action),
                             MakeAAOnVal(decrement_int_ptr_action)});
 
-  auto DeallocActions =
-      cantFail(runFinalizeActions(std::move(InitialActions), noErrors));
+  auto DeallocActions = runFinalizeActions(std::move(InitialActions), noErrors);
+  ASSERT_THAT_EXPECTED(DeallocActions, Succeeded());
 
   EXPECT_EQ(Val, 2);
 
-  runDeallocActions(std::move(DeallocActions), noErrors);
+  runDeallocActions(std::move(*DeallocActions), noErrors);
 
   EXPECT_EQ(Val, 0);
 }
@@ -159,14 +160,8 @@ TEST(AllocActionTest, RunFinalizeActionsFail) {
       {MakeAA(increment_int_ptr_action, &AfterFailurePairVal),
        MakeAA(increment_int_ptr_action, &AfterFailurePairVal)});
 
-  auto DeallocActions = runFinalizeActions(std::move(InitialActions), noErrors);
-
-  if (DeallocActions) {
-    ADD_FAILURE() << "Failed to report error from runFinalizeActions";
-    return;
-  }
-
-  EXPECT_EQ(toString(DeallocActions.takeError()), std::string("failed"));
+  ASSERT_THAT_EXPECTED(runFinalizeActions(std::move(InitialActions), noErrors),
+                       FailedWithMessage("failed"));
 
   // First pair fully ran: +1 from its finalize action, +1 from its dealloc
   // action during cleanup.
@@ -192,14 +187,14 @@ TEST(AllocActionTest, RunFinalizeActionsNullFinalize) {
   InitialActions.push_back({AllocAction(nullptr, WrapperFunctionBuffer()),
                             MakeAAOnVal(decrement_int_ptr_action)});
 
-  auto DeallocActions =
-      cantFail(runFinalizeActions(std::move(InitialActions), noErrors));
+  auto DeallocActions = runFinalizeActions(std::move(InitialActions), noErrors);
+  ASSERT_THAT_EXPECTED(DeallocActions, Succeeded());
 
   // Both dealloc actions should be included in the returned list, despite one
   // of them having a null finalize action.
-  EXPECT_EQ(DeallocActions.size(), 2U);
+  EXPECT_EQ(DeallocActions->size(), 2U);
 
-  runDeallocActions(std::move(DeallocActions), noErrors);
+  runDeallocActions(std::move(*DeallocActions), noErrors);
 
   EXPECT_EQ(Val, -1);
 }
@@ -217,13 +212,13 @@ TEST(AllocActionTest, RunFinalizeActionsNullDealloc) {
   InitialActions.push_back({MakeAAOnVal(increment_int_ptr_action),
                             AllocAction(nullptr, WrapperFunctionBuffer())});
 
-  auto DeallocActions =
-      cantFail(runFinalizeActions(std::move(InitialActions), noErrors));
+  auto DeallocActions = runFinalizeActions(std::move(InitialActions), noErrors);
+  ASSERT_THAT_EXPECTED(DeallocActions, Succeeded());
 
   // Null dealloc actions should be filtered out of the returned list.
-  EXPECT_EQ(DeallocActions.size(), 1U);
+  EXPECT_EQ(DeallocActions->size(), 1U);
 
-  runDeallocActions(std::move(DeallocActions), noErrors);
+  runDeallocActions(std::move(*DeallocActions), noErrors);
 
   EXPECT_EQ(Val, 1);
 }
@@ -285,8 +280,7 @@ TEST(AllocActionTest, RunFinalizeActionsFailReportsCleanupErrors) {
       runFinalizeActions(std::move(InitialActions), AccumulateErrors(ErrMsgs));
 
   // The finalize failure is the returned error...
-  ASSERT_FALSE(DeallocActions);
-  EXPECT_EQ(toString(DeallocActions.takeError()), std::string("failed_2"));
+  ASSERT_THAT_EXPECTED(DeallocActions, FailedWithMessage("failed_2"));
 
   // ...while the cleanup dealloc failure is reported out-of-band.
   ASSERT_EQ(ErrMsgs.size(), 1U);



More information about the llvm-commits mailing list