Skip to content

Commit

Permalink
Additional task types for throwing coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaldwin committed Oct 12, 2020
1 parent e7c45f6 commit 65de5a6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion inc/coro/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct promise<void> : public promise_base

auto get_return_object() noexcept -> task_type;

auto return_void() -> void
auto return_void() noexcept -> void
{

}
Expand Down
35 changes: 34 additions & 1 deletion test/test_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,47 @@ TEST_CASE("task resume from promise to coroutine handles of different types")
REQUIRE(coro_handle2.done());
}

TEST_CASE("task throws")
TEST_CASE("task throws void")
{
auto task = []() -> coro::task<void>
{
throw std::runtime_error{"I always throw."};
co_return;
}();

task.resume();
REQUIRE(task.is_ready());
REQUIRE_THROWS_AS(task.promise().return_value(), std::runtime_error);
}

TEST_CASE("task throws non-void l-value")
{
auto task = []() -> coro::task<int>
{
throw std::runtime_error{"I always throw."};
co_return 42;
}();

task.resume();
REQUIRE(task.is_ready());
REQUIRE_THROWS_AS(task.promise().return_value(), std::runtime_error);
}

TEST_CASE("task throws non-void r-value")
{
struct type
{
int m_value;
};

auto task = []() -> coro::task<type>
{
type return_value{42};

throw std::runtime_error{"I always throw."};
co_return std::move(return_value);
}();

task.resume();
REQUIRE(task.is_ready());
REQUIRE_THROWS_AS(task.promise().return_value(), std::runtime_error);
Expand Down

0 comments on commit 65de5a6

Please sign in to comment.