test: Add assert mock to avoid death tests (#1947)

Fixes #1750
This commit is contained in:
Sergey Kuznetsov
2025-03-07 18:11:52 +00:00
committed by GitHub
parent 8a08c5e6ce
commit c57fe1e6e4
30 changed files with 411 additions and 295 deletions

View File

@@ -17,6 +17,7 @@
*/
//==============================================================================
#include "util/MockAssert.hpp"
#include "util/MockOperation.hpp"
#include "util/async/AnyOperation.hpp"
#include "util/async/Error.hpp"
@@ -32,7 +33,7 @@
using namespace util::async;
using namespace ::testing;
struct AnyOperationTests : Test {
struct AnyOperationTests : virtual Test {
using OperationType = MockOperation<std::expected<std::any, ExecutionError>>;
using StoppableOperationType = MockStoppableOperation<std::expected<std::any, ExecutionError>>;
using ScheduledOperationType = MockScheduledOperation<std::expected<std::any, ExecutionError>>;
@@ -49,7 +50,6 @@ struct AnyOperationTests : Test {
AnyOperation<void> scheduledVoidOp{impl::ErasedOperation(static_cast<ScheduledOperationType&>(mockScheduledOp))};
AnyOperation<void> repeatingOp{impl::ErasedOperation(static_cast<RepeatingOperationType&>(mockRepeatingOp))};
};
using AnyOperationDeathTest = AnyOperationTests;
TEST_F(AnyOperationTests, Move)
{
@@ -134,12 +134,14 @@ TEST_F(AnyOperationTests, RepeatingOpInvokeCallPropagated)
repeatingOp.invoke();
}
TEST_F(AnyOperationDeathTest, CallAbortOnNonStoppableOrCancellableOperation)
struct AnyOperationAssertTest : common::util::WithMockAssert, AnyOperationTests {};
TEST_F(AnyOperationAssertTest, CallAbortOnNonStoppableOrCancellableOperation)
{
EXPECT_DEATH(voidOp.abort(), ".*");
EXPECT_CLIO_ASSERT_FAIL(voidOp.abort());
}
TEST_F(AnyOperationDeathTest, CallInvokeOnNonForceInvocableOperation)
TEST_F(AnyOperationAssertTest, CallInvokeOnNonForceInvocableOperation)
{
EXPECT_DEATH(voidOp.invoke(), ".*");
EXPECT_CLIO_ASSERT_FAIL(voidOp.invoke());
}