Skip to content

Commit

Permalink
test/co/TestInvokeTask: add a test which throws from inside the Invok…
Browse files Browse the repository at this point in the history
…eTask function
  • Loading branch information
MaxKellermann committed Nov 20, 2023
1 parent e6a30cb commit e6bc1c6
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion test/co/TestInvokeTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ MakeInvokeTask(int &i, auto &task) noexcept
++i;
}

static Co::InvokeTask
ThrowInvokeTask(int &i)
{
if constexpr (false)
/* force this to be a coroutine */
co_return;

++i;
throw "error";
}

static Co::Task<void>
ThrowTask(int &i)
{
Expand Down Expand Up @@ -143,7 +154,24 @@ TEST(InvokeTask, EagerTask)
ASSERT_EQ(task_i, 1);
}

TEST(InvokeTask, Throw)
TEST(InvokeTask, Throw1)
{
int i = 0;

auto invoke = ThrowInvokeTask(i);
ASSERT_TRUE(invoke);
ASSERT_EQ(i, 0);

Completion c;
c.Start(invoke);
ASSERT_FALSE(invoke);
ASSERT_TRUE(c.done);
ASSERT_TRUE(c.error);

ASSERT_EQ(i, 1);
}

TEST(InvokeTask, Throw2)
{
int task_i = 0, invoke_i = 0;

Expand Down

0 comments on commit e6bc1c6

Please sign in to comment.