ci: Use Nix-based images for all workflows except pre-commit (#3098)

This commit is contained in:
Ayaz Salikhov
2026-06-16 22:50:43 +01:00
committed by GitHub
parent e24216c8a9
commit fa057bd876
69 changed files with 846 additions and 1431 deletions

View File

@@ -5,10 +5,10 @@
#include "util/MockStrand.hpp"
#include "util/async/AnyStopToken.hpp"
#include "util/async/Error.hpp"
#include "util/async/impl/Any.hpp"
#include <gmock/gmock.h>
#include <any>
#include <chrono>
#include <expected>
#include <functional>
@@ -18,6 +18,8 @@ struct MockExecutionContext {
template <typename T>
using ValueType = std::expected<T, util::async::ExecutionError>;
using Any = util::async::impl::Any;
using StopSource = MockStopSource;
using StopToken = MockStopToken;
using Strand = MockStrand;
@@ -34,36 +36,35 @@ struct MockExecutionContext {
template <typename T>
using RepeatingOperation = MockRepeatingOperation<T>;
MOCK_METHOD(Operation<std::any> const&, execute, (std::function<std::any()>), ());
MOCK_METHOD(Operation<Any> const&, execute, (std::function<Any()>), ());
MOCK_METHOD(
Operation<std::any> const&,
Operation<Any> const&,
execute,
(std::function<std::any()>, std::optional<std::chrono::milliseconds>),
(std::function<Any()>, std::optional<std::chrono::milliseconds>),
()
);
MOCK_METHOD(
StoppableOperation<std::any> const&,
StoppableOperation<Any> const&,
execute,
(std::function<std::any(util::async::AnyStopToken)>,
std::optional<std::chrono::milliseconds>),
(std::function<Any(util::async::AnyStopToken)>, std::optional<std::chrono::milliseconds>),
()
);
MOCK_METHOD(
ScheduledOperation<std::any> const&,
ScheduledOperation<Any> const&,
scheduleAfter,
(std::chrono::milliseconds, std::function<std::any(util::async::AnyStopToken)>),
(std::chrono::milliseconds, std::function<Any(util::async::AnyStopToken)>),
()
);
MOCK_METHOD(
ScheduledOperation<std::any> const&,
ScheduledOperation<Any> const&,
scheduleAfter,
(std::chrono::milliseconds, std::function<std::any(util::async::AnyStopToken, bool)>),
(std::chrono::milliseconds, std::function<Any(util::async::AnyStopToken, bool)>),
()
);
MOCK_METHOD(
RepeatingOperation<std::any> const&,
RepeatingOperation<Any> const&,
executeRepeatedly,
(std::chrono::milliseconds, std::function<std::any()>),
(std::chrono::milliseconds, std::function<Any()>),
()
);
MOCK_METHOD(void, submit, (std::function<void()>), ());

View File

@@ -3,10 +3,10 @@
#include "util/MockOperation.hpp"
#include "util/async/AnyStopToken.hpp"
#include "util/async/Error.hpp"
#include "util/async/impl/Any.hpp"
#include <gmock/gmock.h>
#include <any>
#include <chrono>
#include <expected>
#include <functional>
@@ -16,6 +16,8 @@ struct MockStrand {
template <typename T>
using ValueType = std::expected<T, util::async::ExecutionError>;
using Any = util::async::impl::Any;
template <typename T>
using Operation = MockOperation<T>;
@@ -25,30 +27,29 @@ struct MockStrand {
template <typename T>
using RepeatingOperation = MockRepeatingOperation<T>;
MOCK_METHOD(Operation<std::any> const&, execute, (std::function<std::any()>), (const));
MOCK_METHOD(Operation<Any> const&, execute, (std::function<Any()>), (const));
MOCK_METHOD(
Operation<std::any> const&,
Operation<Any> const&,
execute,
(std::function<std::any()>, std::optional<std::chrono::milliseconds>),
(std::function<Any()>, std::optional<std::chrono::milliseconds>),
(const)
);
MOCK_METHOD(
StoppableOperation<std::any> const&,
StoppableOperation<Any> const&,
execute,
(std::function<std::any(util::async::AnyStopToken)>),
(std::function<Any(util::async::AnyStopToken)>),
(const)
);
MOCK_METHOD(
StoppableOperation<std::any> const&,
StoppableOperation<Any> const&,
execute,
(std::function<std::any(util::async::AnyStopToken)>,
std::optional<std::chrono::milliseconds>),
(std::function<Any(util::async::AnyStopToken)>, std::optional<std::chrono::milliseconds>),
(const)
);
MOCK_METHOD(
RepeatingOperation<std::any> const&,
RepeatingOperation<Any> const&,
executeRepeatedly,
(std::chrono::milliseconds, std::function<std::any()>),
(std::chrono::milliseconds, std::function<Any()>),
(const)
);
MOCK_METHOD(void, submit, (std::function<void()>), (const));

View File

@@ -28,3 +28,5 @@ set_target_properties(
clio_integration_tests
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)
patch_nix_binary(clio_integration_tests)

View File

@@ -239,6 +239,8 @@ set_target_properties(
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)
patch_nix_binary(clio_tests)
# Generate `coverage_report` target if coverage is enabled
if(coverage)
if(DEFINED CODE_COVERAGE_REPORT_FORMAT)

View File

@@ -10,6 +10,7 @@
#include "util/async/Outcome.hpp"
#include "util/async/context/SyncExecutionContext.hpp"
#include "util/async/context/impl/Cancellation.hpp"
#include "util/async/impl/Any.hpp"
#include "util/async/impl/ErasedOperation.hpp"
#include <gmock/gmock.h>
@@ -105,8 +106,8 @@ struct AnyExecutionContextTests : Test {
TEST_F(AnyExecutionContextTests, Move)
{
auto mockOp = OperationType<std::any>{};
EXPECT_CALL(mockExecutionContext, execute(A<std::function<std::any()>>()))
auto mockOp = OperationType<impl::Any>{};
EXPECT_CALL(mockExecutionContext, execute(A<std::function<impl::Any()>>()))
.WillOnce(ReturnRef(mockOp));
EXPECT_CALL(mockOp, get());
@@ -116,8 +117,8 @@ TEST_F(AnyExecutionContextTests, Move)
TEST_F(AnyExecutionContextTests, CopyIsRefCounted)
{
auto mockOp = OperationType<std::any>{};
EXPECT_CALL(mockExecutionContext, execute(A<std::function<std::any()>>()))
auto mockOp = OperationType<impl::Any>{};
EXPECT_CALL(mockExecutionContext, execute(A<std::function<impl::Any()>>()))
.WillOnce(ReturnRef(mockOp));
EXPECT_CALL(mockOp, get());
@@ -127,8 +128,8 @@ TEST_F(AnyExecutionContextTests, CopyIsRefCounted)
TEST_F(AnyExecutionContextTests, ExecuteWithoutTokenAndVoid)
{
auto mockOp = OperationType<std::any>{};
EXPECT_CALL(mockExecutionContext, execute(A<std::function<std::any()>>()))
auto mockOp = OperationType<impl::Any>{};
EXPECT_CALL(mockExecutionContext, execute(A<std::function<impl::Any()>>()))
.WillOnce(ReturnRef(mockOp));
EXPECT_CALL(mockOp, get());
@@ -140,17 +141,17 @@ TEST_F(AnyExecutionContextTests, ExecuteWithoutTokenAndVoid)
TEST_F(AnyExecutionContextTests, ExecuteWithoutTokenAndVoidThrowsException)
{
auto mockOp = OperationType<std::any>{};
EXPECT_CALL(mockExecutionContext, execute(A<std::function<std::any()>>()))
.WillOnce([](auto&&) -> OperationType<std::any> const& { throw 0; });
auto mockOp = OperationType<impl::Any>{};
EXPECT_CALL(mockExecutionContext, execute(A<std::function<impl::Any()>>()))
.WillOnce([](auto&&) -> OperationType<impl::Any> const& { throw 0; });
EXPECT_ANY_THROW([[maybe_unused]] auto unused = ctx.execute([] { throw 0; }));
}
TEST_F(AnyExecutionContextTests, ExecuteWithStopTokenAndVoid)
{
auto mockOp = StoppableOperationType<std::any>{};
EXPECT_CALL(mockExecutionContext, execute(A<std::function<std::any(AnyStopToken)>>(), _))
auto mockOp = StoppableOperationType<impl::Any>{};
EXPECT_CALL(mockExecutionContext, execute(A<std::function<impl::Any(AnyStopToken)>>(), _))
.WillOnce(ReturnRef(mockOp));
EXPECT_CALL(mockOp, get());
@@ -162,17 +163,17 @@ TEST_F(AnyExecutionContextTests, ExecuteWithStopTokenAndVoid)
TEST_F(AnyExecutionContextTests, ExecuteWithStopTokenAndVoidThrowsException)
{
EXPECT_CALL(mockExecutionContext, execute(A<std::function<std::any(AnyStopToken)>>(), _))
.WillOnce([](auto&&, auto) -> StoppableOperationType<std::any> const& { throw 0; });
EXPECT_CALL(mockExecutionContext, execute(A<std::function<impl::Any(AnyStopToken)>>(), _))
.WillOnce([](auto&&, auto) -> StoppableOperationType<impl::Any> const& { throw 0; });
EXPECT_ANY_THROW([[maybe_unused]] auto unused = ctx.execute([](auto) { throw 0; }));
}
TEST_F(AnyExecutionContextTests, ExecuteWithStopTokenAndReturnValue)
{
auto mockOp = StoppableOperationType<std::any>{};
auto mockOp = StoppableOperationType<impl::Any>{};
EXPECT_CALL(mockOp, get()).WillOnce(Return(std::make_any<int>(42)));
EXPECT_CALL(mockExecutionContext, execute(A<std::function<std::any(AnyStopToken)>>(), _))
EXPECT_CALL(mockExecutionContext, execute(A<std::function<impl::Any(AnyStopToken)>>(), _))
.WillOnce(ReturnRef(mockOp));
auto op = ctx.execute([](auto) -> int { throw 0; });
@@ -183,19 +184,19 @@ TEST_F(AnyExecutionContextTests, ExecuteWithStopTokenAndReturnValue)
TEST_F(AnyExecutionContextTests, ExecuteWithStopTokenAndReturnValueThrowsException)
{
EXPECT_CALL(mockExecutionContext, execute(A<std::function<std::any(AnyStopToken)>>(), _))
.WillOnce([](auto&&, auto) -> StoppableOperationType<std::any> const& { throw 0; });
EXPECT_CALL(mockExecutionContext, execute(A<std::function<impl::Any(AnyStopToken)>>(), _))
.WillOnce([](auto&&, auto) -> StoppableOperationType<impl::Any> const& { throw 0; });
EXPECT_ANY_THROW([[maybe_unused]] auto unused = ctx.execute([](auto) -> int { throw 0; }));
}
TEST_F(AnyExecutionContextTests, TimerCancellation)
{
auto mockScheduledOp = ScheduledOperationType<std::any>{};
auto mockScheduledOp = ScheduledOperationType<impl::Any>{};
EXPECT_CALL(mockScheduledOp, cancel());
EXPECT_CALL(
mockExecutionContext,
scheduleAfter(std::chrono::milliseconds{12}, A<std::function<std::any(AnyStopToken)>>())
scheduleAfter(std::chrono::milliseconds{12}, A<std::function<impl::Any(AnyStopToken)>>())
)
.WillOnce(ReturnRef(mockScheduledOp));
@@ -207,13 +208,13 @@ TEST_F(AnyExecutionContextTests, TimerCancellation)
TEST_F(AnyExecutionContextTests, TimerExecuted)
{
auto mockScheduledOp = ScheduledOperationType<std::any>{};
auto mockScheduledOp = ScheduledOperationType<impl::Any>{};
EXPECT_CALL(mockScheduledOp, get()).WillOnce(Return(std::make_any<int>(42)));
EXPECT_CALL(
mockExecutionContext,
scheduleAfter(std::chrono::milliseconds{12}, A<std::function<std::any(AnyStopToken)>>())
scheduleAfter(std::chrono::milliseconds{12}, A<std::function<impl::Any(AnyStopToken)>>())
)
.WillOnce([&mockScheduledOp](auto, auto&&) -> ScheduledOperationType<std::any> const& {
.WillOnce([&mockScheduledOp](auto, auto&&) -> ScheduledOperationType<impl::Any> const& {
return mockScheduledOp;
});
@@ -225,12 +226,12 @@ TEST_F(AnyExecutionContextTests, TimerExecuted)
TEST_F(AnyExecutionContextTests, TimerWithBoolHandlerCancellation)
{
auto mockScheduledOp = ScheduledOperationType<std::any>{};
auto mockScheduledOp = ScheduledOperationType<impl::Any>{};
EXPECT_CALL(mockScheduledOp, cancel());
EXPECT_CALL(
mockExecutionContext,
scheduleAfter(
std::chrono::milliseconds{12}, A<std::function<std::any(AnyStopToken, bool)>>()
std::chrono::milliseconds{12}, A<std::function<impl::Any(AnyStopToken, bool)>>()
)
)
.WillOnce(ReturnRef(mockScheduledOp));
@@ -243,15 +244,15 @@ TEST_F(AnyExecutionContextTests, TimerWithBoolHandlerCancellation)
TEST_F(AnyExecutionContextTests, TimerWithBoolHandlerExecuted)
{
auto mockScheduledOp = ScheduledOperationType<std::any>{};
auto mockScheduledOp = ScheduledOperationType<impl::Any>{};
EXPECT_CALL(mockScheduledOp, get()).WillOnce(Return(std::make_any<int>(42)));
EXPECT_CALL(
mockExecutionContext,
scheduleAfter(
std::chrono::milliseconds{12}, A<std::function<std::any(AnyStopToken, bool)>>()
std::chrono::milliseconds{12}, A<std::function<impl::Any(AnyStopToken, bool)>>()
)
)
.WillOnce([&mockScheduledOp](auto, auto&&) -> ScheduledOperationType<std::any> const& {
.WillOnce([&mockScheduledOp](auto, auto&&) -> ScheduledOperationType<impl::Any> const& {
return mockScheduledOp;
});
@@ -264,13 +265,13 @@ TEST_F(AnyExecutionContextTests, TimerWithBoolHandlerExecuted)
TEST_F(AnyExecutionContextTests, RepeatingOperation)
{
auto mockRepeatingOp = RepeatingOperationType<std::any>{};
auto mockRepeatingOp = RepeatingOperationType<impl::Any>{};
EXPECT_CALL(mockRepeatingOp, wait());
EXPECT_CALL(
mockExecutionContext,
executeRepeatedly(std::chrono::milliseconds{1}, A<std::function<std::any()>>())
executeRepeatedly(std::chrono::milliseconds{1}, A<std::function<impl::Any()>>())
)
.WillOnce([&mockRepeatingOp] -> RepeatingOperationType<std::any> const& {
.WillOnce([&mockRepeatingOp] -> RepeatingOperationType<impl::Any> const& {
return mockRepeatingOp;
});
@@ -281,11 +282,11 @@ TEST_F(AnyExecutionContextTests, RepeatingOperation)
TEST_F(AnyExecutionContextTests, StrandExecuteWithVoid)
{
auto mockOp = OperationType<std::any>{};
auto mockOp = OperationType<impl::Any>{};
auto mockStrand = StrandType{};
EXPECT_CALL(mockOp, get());
EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand));
EXPECT_CALL(mockStrand, execute(A<std::function<std::any()>>())).WillOnce(ReturnRef(mockOp));
EXPECT_CALL(mockStrand, execute(A<std::function<impl::Any()>>())).WillOnce(ReturnRef(mockOp));
auto strand = ctx.makeStrand();
static_assert(std::is_same_v<decltype(strand), AnyStrand>);
@@ -300,8 +301,8 @@ TEST_F(AnyExecutionContextTests, StrandExecuteWithVoidThrowsException)
{
auto mockStrand = StrandType{};
EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand));
EXPECT_CALL(mockStrand, execute(A<std::function<std::any()>>()))
.WillOnce([](auto&&) -> OperationType<std::any> const& { throw 0; });
EXPECT_CALL(mockStrand, execute(A<std::function<impl::Any()>>()))
.WillOnce([](auto&&) -> OperationType<impl::Any> const& { throw 0; });
auto strand = ctx.makeStrand();
static_assert(std::is_same_v<decltype(strand), AnyStrand>);
@@ -311,11 +312,11 @@ TEST_F(AnyExecutionContextTests, StrandExecuteWithVoidThrowsException)
TEST_F(AnyExecutionContextTests, StrandExecuteWithReturnValue)
{
auto mockOp = OperationType<std::any>{};
auto mockOp = OperationType<impl::Any>{};
auto mockStrand = StrandType{};
EXPECT_CALL(mockOp, get()).WillOnce(Return(std::make_any<int>(42)));
EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand));
EXPECT_CALL(mockStrand, execute(A<std::function<std::any()>>())).WillOnce(ReturnRef(mockOp));
EXPECT_CALL(mockStrand, execute(A<std::function<impl::Any()>>())).WillOnce(ReturnRef(mockOp));
auto strand = ctx.makeStrand();
static_assert(std::is_same_v<decltype(strand), AnyStrand>);
@@ -330,8 +331,8 @@ TEST_F(AnyExecutionContextTests, StrandExecuteWithReturnValueThrowsException)
{
auto mockStrand = StrandType{};
EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand));
EXPECT_CALL(mockStrand, execute(A<std::function<std::any()>>()))
.WillOnce([](auto&&) -> OperationType<std::any> const& { throw 0; });
EXPECT_CALL(mockStrand, execute(A<std::function<impl::Any()>>()))
.WillOnce([](auto&&) -> OperationType<impl::Any> const& { throw 0; });
auto strand = ctx.makeStrand();
static_assert(std::is_same_v<decltype(strand), AnyStrand>);
@@ -341,11 +342,11 @@ TEST_F(AnyExecutionContextTests, StrandExecuteWithReturnValueThrowsException)
TEST_F(AnyExecutionContextTests, StrandExecuteWithStopTokenAndVoid)
{
auto mockOp = StoppableOperationType<std::any>{};
auto mockOp = StoppableOperationType<impl::Any>{};
auto mockStrand = StrandType{};
EXPECT_CALL(mockOp, get());
EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand));
EXPECT_CALL(mockStrand, execute(A<std::function<std::any(AnyStopToken)>>(), _))
EXPECT_CALL(mockStrand, execute(A<std::function<impl::Any(AnyStopToken)>>(), _))
.WillOnce(ReturnRef(mockOp));
auto strand = ctx.makeStrand();
@@ -361,8 +362,8 @@ TEST_F(AnyExecutionContextTests, StrandExecuteWithStopTokenAndVoidThrowsExceptio
{
auto mockStrand = StrandType{};
EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand));
EXPECT_CALL(mockStrand, execute(A<std::function<std::any(AnyStopToken)>>(), _))
.WillOnce([](auto&&, auto) -> StoppableOperationType<std::any> const& { throw 0; });
EXPECT_CALL(mockStrand, execute(A<std::function<impl::Any(AnyStopToken)>>(), _))
.WillOnce([](auto&&, auto) -> StoppableOperationType<impl::Any> const& { throw 0; });
auto strand = ctx.makeStrand();
static_assert(std::is_same_v<decltype(strand), AnyStrand>);
@@ -372,11 +373,11 @@ TEST_F(AnyExecutionContextTests, StrandExecuteWithStopTokenAndVoidThrowsExceptio
TEST_F(AnyExecutionContextTests, StrandExecuteWithStopTokenAndReturnValue)
{
auto mockOp = StoppableOperationType<std::any>{};
auto mockOp = StoppableOperationType<impl::Any>{};
auto mockStrand = StrandType{};
EXPECT_CALL(mockOp, get()).WillOnce(Return(std::make_any<int>(42)));
EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand));
EXPECT_CALL(mockStrand, execute(A<std::function<std::any(AnyStopToken)>>(), _))
EXPECT_CALL(mockStrand, execute(A<std::function<impl::Any(AnyStopToken)>>(), _))
.WillOnce(ReturnRef(mockOp));
auto strand = ctx.makeStrand();
@@ -392,8 +393,8 @@ TEST_F(AnyExecutionContextTests, StrandExecuteWithStopTokenAndReturnValueThrowsE
{
auto mockStrand = StrandType{};
EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand));
EXPECT_CALL(mockStrand, execute(A<std::function<std::any(AnyStopToken)>>(), _))
.WillOnce([](auto&&, auto) -> StoppableOperationType<std::any> const& { throw 0; });
EXPECT_CALL(mockStrand, execute(A<std::function<impl::Any(AnyStopToken)>>(), _))
.WillOnce([](auto&&, auto) -> StoppableOperationType<impl::Any> const& { throw 0; });
auto strand = ctx.makeStrand();
static_assert(std::is_same_v<decltype(strand), AnyStrand>);

View File

@@ -2,6 +2,7 @@
#include "util/MockOperation.hpp"
#include "util/async/AnyOperation.hpp"
#include "util/async/Error.hpp"
#include "util/async/impl/Any.hpp"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -15,10 +16,10 @@ using namespace util::async;
using namespace ::testing;
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>>;
using RepeatingOperationType = MockRepeatingOperation<std::expected<std::any, ExecutionError>>;
using OperationType = MockOperation<std::expected<impl::Any, ExecutionError>>;
using StoppableOperationType = MockStoppableOperation<std::expected<impl::Any, ExecutionError>>;
using ScheduledOperationType = MockScheduledOperation<std::expected<impl::Any, ExecutionError>>;
using RepeatingOperationType = MockRepeatingOperation<std::expected<impl::Any, ExecutionError>>;
NaggyMock<OperationType> mockOp;
NaggyMock<StoppableOperationType> mockStoppableOp;
@@ -40,7 +41,7 @@ struct AnyOperationTests : virtual Test {
TEST_F(AnyOperationTests, Move)
{
EXPECT_CALL(mockOp, get()).WillOnce(Return(std::any{}));
EXPECT_CALL(mockOp, get()).WillOnce(Return(impl::Any{}));
auto yoink = std::move(voidOp);
auto res = yoink.get();
ASSERT_TRUE(res);
@@ -48,7 +49,7 @@ TEST_F(AnyOperationTests, Move)
TEST_F(AnyOperationTests, VoidDataYieldsNoError)
{
EXPECT_CALL(mockOp, get()).WillOnce(Return(std::any{}));
EXPECT_CALL(mockOp, get()).WillOnce(Return(impl::Any{}));
auto res = voidOp.get();
ASSERT_TRUE(res);
}

View File

@@ -3,6 +3,7 @@
#include "util/async/AnyOperation.hpp"
#include "util/async/AnyStopToken.hpp"
#include "util/async/AnyStrand.hpp"
#include "util/async/impl/Any.hpp"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -33,8 +34,8 @@ struct AnyStrandTests : ::testing::Test {
TEST_F(AnyStrandTests, Move)
{
auto mockOp = OperationType<std::any>{};
EXPECT_CALL(mockStrand, execute(An<std::function<std::any()>>())).WillOnce(ReturnRef(mockOp));
auto mockOp = OperationType<impl::Any>{};
EXPECT_CALL(mockStrand, execute(An<std::function<impl::Any()>>())).WillOnce(ReturnRef(mockOp));
EXPECT_CALL(mockOp, get());
auto mineNow = std::move(strand);
@@ -43,8 +44,8 @@ TEST_F(AnyStrandTests, Move)
TEST_F(AnyStrandTests, CopyIsRefCounted)
{
auto mockOp = OperationType<std::any>{};
EXPECT_CALL(mockStrand, execute(An<std::function<std::any()>>())).WillOnce(ReturnRef(mockOp));
auto mockOp = OperationType<impl::Any>{};
EXPECT_CALL(mockStrand, execute(An<std::function<impl::Any()>>())).WillOnce(ReturnRef(mockOp));
auto yoink = strand;
ASSERT_TRUE(yoink.execute([] { throw 0; }).get());
@@ -52,8 +53,8 @@ TEST_F(AnyStrandTests, CopyIsRefCounted)
TEST_F(AnyStrandTests, ExecuteWithoutTokenAndVoid)
{
auto mockOp = OperationType<std::any>{};
EXPECT_CALL(mockStrand, execute(An<std::function<std::any()>>())).WillOnce(ReturnRef(mockOp));
auto mockOp = OperationType<impl::Any>{};
EXPECT_CALL(mockStrand, execute(An<std::function<impl::Any()>>())).WillOnce(ReturnRef(mockOp));
auto op = strand.execute([] {});
static_assert(std::is_same_v<decltype(op), AnyOperation<void>>);
@@ -63,17 +64,17 @@ TEST_F(AnyStrandTests, ExecuteWithoutTokenAndVoid)
TEST_F(AnyStrandTests, ExecuteWithoutTokenAndVoidThrowsException)
{
auto mockOp = OperationType<std::any>{};
EXPECT_CALL(mockStrand, execute(An<std::function<std::any()>>()))
.WillOnce([](auto&&) -> OperationType<std::any> const& { throw 0; });
auto mockOp = OperationType<impl::Any>{};
EXPECT_CALL(mockStrand, execute(An<std::function<impl::Any()>>()))
.WillOnce([](auto&&) -> OperationType<impl::Any> const& { throw 0; });
EXPECT_ANY_THROW([[maybe_unused]] auto unused = strand.execute([] {}));
}
TEST_F(AnyStrandTests, ExecuteWithStopTokenAndVoid)
{
auto mockOp = StoppableOperationType<std::any>{};
EXPECT_CALL(mockStrand, execute(An<std::function<std::any(AnyStopToken)>>(), _))
auto mockOp = StoppableOperationType<impl::Any>{};
EXPECT_CALL(mockStrand, execute(An<std::function<impl::Any(AnyStopToken)>>(), _))
.WillOnce(ReturnRef(mockOp));
auto op = strand.execute([](auto) {});
@@ -84,17 +85,17 @@ TEST_F(AnyStrandTests, ExecuteWithStopTokenAndVoid)
TEST_F(AnyStrandTests, ExecuteWithStopTokenAndVoidThrowsException)
{
EXPECT_CALL(mockStrand, execute(An<std::function<std::any(AnyStopToken)>>(), _))
.WillOnce([](auto&&, auto) -> StoppableOperationType<std::any> const& { throw 0; });
EXPECT_CALL(mockStrand, execute(An<std::function<impl::Any(AnyStopToken)>>(), _))
.WillOnce([](auto&&, auto) -> StoppableOperationType<impl::Any> const& { throw 0; });
EXPECT_ANY_THROW([[maybe_unused]] auto unused = strand.execute([](auto) {}));
}
TEST_F(AnyStrandTests, ExecuteWithStopTokenAndReturnValue)
{
auto mockOp = StoppableOperationType<std::any>{};
auto mockOp = StoppableOperationType<impl::Any>{};
EXPECT_CALL(mockOp, get()).WillOnce(Return(std::make_any<int>(42)));
EXPECT_CALL(mockStrand, execute(An<std::function<std::any(AnyStopToken)>>(), _))
EXPECT_CALL(mockStrand, execute(An<std::function<impl::Any(AnyStopToken)>>(), _))
.WillOnce(ReturnRef(mockOp));
auto op = strand.execute([](auto) { return 42; });
@@ -105,17 +106,17 @@ TEST_F(AnyStrandTests, ExecuteWithStopTokenAndReturnValue)
TEST_F(AnyStrandTests, ExecuteWithStopTokenAndReturnValueThrowsException)
{
EXPECT_CALL(mockStrand, execute(An<std::function<std::any(AnyStopToken)>>(), _))
.WillOnce([](auto&&, auto) -> StoppableOperationType<std::any> const& { throw 0; });
EXPECT_CALL(mockStrand, execute(An<std::function<impl::Any(AnyStopToken)>>(), _))
.WillOnce([](auto&&, auto) -> StoppableOperationType<impl::Any> const& { throw 0; });
EXPECT_ANY_THROW([[maybe_unused]] auto unused = strand.execute([](auto) { return 42; }));
}
TEST_F(AnyStrandTests, ExecuteWithTimeoutAndStopTokenAndReturnValue)
{
auto mockOp = StoppableOperationType<std::any>{};
auto mockOp = StoppableOperationType<impl::Any>{};
EXPECT_CALL(mockOp, get()).WillOnce(Return(std::make_any<int>(42)));
EXPECT_CALL(mockStrand, execute(An<std::function<std::any(AnyStopToken)>>(), _))
EXPECT_CALL(mockStrand, execute(An<std::function<impl::Any(AnyStopToken)>>(), _))
.WillOnce(ReturnRef(mockOp));
auto op = strand.execute([](auto) { return 42; }, std::chrono::milliseconds{1});
@@ -126,8 +127,8 @@ TEST_F(AnyStrandTests, ExecuteWithTimeoutAndStopTokenAndReturnValue)
TEST_F(AnyStrandTests, ExecuteWithTimeoutAndStopTokenAndReturnValueThrowsException)
{
EXPECT_CALL(mockStrand, execute(An<std::function<std::any(AnyStopToken)>>(), _))
.WillOnce([](auto&&, auto) -> StoppableOperationType<std::any> const& { throw 0; });
EXPECT_CALL(mockStrand, execute(An<std::function<impl::Any(AnyStopToken)>>(), _))
.WillOnce([](auto&&, auto) -> StoppableOperationType<impl::Any> const& { throw 0; });
EXPECT_ANY_THROW(
[[maybe_unused]] auto unused =
@@ -137,12 +138,12 @@ TEST_F(AnyStrandTests, ExecuteWithTimeoutAndStopTokenAndReturnValueThrowsExcepti
TEST_F(AnyStrandTests, RepeatingOperation)
{
auto mockRepeatingOp = RepeatingOperationType<std::any>{};
auto mockRepeatingOp = RepeatingOperationType<impl::Any>{};
EXPECT_CALL(mockRepeatingOp, wait());
EXPECT_CALL(
mockStrand, executeRepeatedly(std::chrono::milliseconds{1}, A<std::function<std::any()>>())
mockStrand, executeRepeatedly(std::chrono::milliseconds{1}, A<std::function<impl::Any()>>())
)
.WillOnce([&mockRepeatingOp] -> RepeatingOperationType<std::any> const& {
.WillOnce([&mockRepeatingOp] -> RepeatingOperationType<impl::Any> const& {
return mockRepeatingOp;
});