Skip to content

Commit

Permalink
test: add failing test_spawn_return_moveonly()
Browse files Browse the repository at this point in the history
add a test case to reproduce chriskohlhoff#1543

Signed-off-by: Casey Bodley <cbodley@redhat.com>
  • Loading branch information
cbodley committed Oct 18, 2024
1 parent 2431068 commit e0cb0e0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions asio/src/tests/unit/spawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,38 @@ void test_spawn_exception()
}
}

std::unique_ptr<int> factory_coroutine(asio::yield_context)
{
return std::make_unique<int>(42);
}

void test_spawn_return_moveonly()
{
asio::io_context ctx;

std::unique_ptr<int> result;
bool called = false;
asio::spawn(ctx, factory_coroutine,
[&](std::exception_ptr, std::unique_ptr<int> r)
{
result = std::move(r);
called = true;
});

ctx.poll();
ASIO_CHECK(ctx.stopped());

ASIO_CHECK(called);
ASIO_CHECK(result);
ASIO_CHECK(*result == 42);
}

ASIO_TEST_SUITE
(
"spawn",
ASIO_TEST_CASE(test_spawn_with_any_completion_handler)
ASIO_TEST_CASE(test_spawn_deferred)
ASIO_TEST_CASE(test_spawn_cancel)
ASIO_TEST_CASE(test_spawn_exception)
ASIO_TEST_CASE(test_spawn_return_moveonly)
)

0 comments on commit e0cb0e0

Please sign in to comment.