-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheager_task.cpp
69 lines (54 loc) · 1.56 KB
/
eager_task.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <gtest/gtest.h>
#include <exception>
#include <functional>
#include "eager_task.h"
#include "task.h"
using namespace wwa::coro;
TEST(EagerTaskTest, Basic)
{
bool flag = false;
const auto func = [](std::reference_wrapper<bool> f) -> eager_task {
f.get() = true;
co_return;
};
func(flag);
EXPECT_TRUE(flag);
}
TEST(EagerTaskTest, RunAwaitable)
{
bool flag = false;
const auto func = [](std::reference_wrapper<bool> f) -> task<> {
f.get() = true;
co_return;
};
run_awaitable(func, flag);
EXPECT_TRUE(flag);
}
TEST(SimpleTaskDeathTest, UnhandledException)
{
static const std::string message = "This was the coldest night";
std::set_terminate([] {
if (std::current_exception()) {
try {
std::rethrow_exception(std::current_exception());
}
catch (const std::exception& e) {
std::cerr << "Unhandled exception: " << e.what() << "\n";
}
}
std::exit(1); // NOLINT(concurrency-mt-unsafe)
});
const auto func = []() -> eager_task {
throw std::runtime_error(message);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunreachable-code"
co_return;
#pragma clang diagnostic pop
};
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wswitch-default"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
EXPECT_DEATH(func(), message);
#pragma clang diagnostic pop
}