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());
}

View File

@@ -17,6 +17,7 @@
*/
//==============================================================================
#include "util/MockAssert.hpp"
#include "util/async/AnyStopToken.hpp"
#include <boost/asio/spawn.hpp>
@@ -38,7 +39,6 @@ struct FakeStopToken {
} // namespace
struct AnyStopTokenTests : public TestWithParam<bool> {};
using AnyStopTokenDeathTest = AnyStopTokenTests;
INSTANTIATE_TEST_CASE_P(AnyStopTokenGroup, AnyStopTokenTests, ValuesIn({true, false}), [](auto const& info) {
return info.param ? "true" : "false";
@@ -61,9 +61,11 @@ TEST_P(AnyStopTokenTests, IsStopRequestedCallPropagated)
EXPECT_EQ(stopToken, flag);
}
TEST_F(AnyStopTokenDeathTest, ConversionToYieldContextAssertsIfUnsupported)
struct AnyStopTokenAssertTest : common::util::WithMockAssert {};
TEST_F(AnyStopTokenAssertTest, ConversionToYieldContextAssertsIfUnsupported)
{
EXPECT_DEATH(
[[maybe_unused]] auto unused = static_cast<boost::asio::yield_context>(AnyStopToken{FakeStopToken{}}), ".*"
EXPECT_CLIO_ASSERT_FAIL(
[[maybe_unused]] auto unused = static_cast<boost::asio::yield_context>(AnyStopToken{FakeStopToken{}})
);
}