Commit 216004e0 authored by Lingxi-Li's avatar Lingxi-Li

Add `CAF_ERROR()` and fix `CAF_FAIL()`

parent e703fecb
...@@ -127,7 +127,7 @@ CAF_TEST(round_robin_actor_pool) { ...@@ -127,7 +127,7 @@ CAF_TEST(round_robin_actor_pool) {
); );
}, },
after(std::chrono::milliseconds(250)) >> [] { after(std::chrono::milliseconds(250)) >> [] {
CAF_TEST_ERROR("didn't receive a down message"); CAF_ERROR("didn't receive a down message");
} }
); );
CAF_MESSAGE("about to send exit to workers"); CAF_MESSAGE("about to send exit to workers");
...@@ -143,7 +143,7 @@ CAF_TEST(round_robin_actor_pool) { ...@@ -143,7 +143,7 @@ CAF_TEST(round_robin_actor_pool) {
workers.erase(pos); workers.erase(pos);
}, },
after(std::chrono::milliseconds(250)) >> [] { after(std::chrono::milliseconds(250)) >> [] {
CAF_TEST_ERROR("didn't receive a down message"); CAF_ERROR("didn't receive a down message");
} }
); );
} }
...@@ -164,7 +164,7 @@ CAF_TEST(broadcast_actor_pool) { ...@@ -164,7 +164,7 @@ CAF_TEST(broadcast_actor_pool) {
results.push_back(res); results.push_back(res);
}, },
after(std::chrono::milliseconds(250)) >> [] { after(std::chrono::milliseconds(250)) >> [] {
CAF_TEST_ERROR("didn't receive a result"); CAF_ERROR("didn't receive a result");
} }
); );
CAF_CHECK_EQUAL(results.size(), 25u); CAF_CHECK_EQUAL(results.size(), 25u);
...@@ -182,7 +182,7 @@ CAF_TEST(random_actor_pool) { ...@@ -182,7 +182,7 @@ CAF_TEST(random_actor_pool) {
CAF_CHECK_EQUAL(res, 3); CAF_CHECK_EQUAL(res, 3);
}, },
after(std::chrono::milliseconds(250)) >> [] { after(std::chrono::milliseconds(250)) >> [] {
CAF_TEST_ERROR("didn't receive a down message"); CAF_ERROR("didn't receive a down message");
} }
); );
} }
......
...@@ -101,7 +101,7 @@ CAF_TEST(receive_atoms) { ...@@ -101,7 +101,7 @@ CAF_TEST(receive_atoms) {
CAF_MESSAGE("drain mailbox"); CAF_MESSAGE("drain mailbox");
}, },
after(std::chrono::seconds(0)) >> [] { after(std::chrono::seconds(0)) >> [] {
CAF_TEST_ERROR("mailbox empty"); CAF_ERROR("mailbox empty");
} }
); );
atom_value x = atom("abc"); atom_value x = atom("abc");
...@@ -114,7 +114,7 @@ CAF_TEST(receive_atoms) { ...@@ -114,7 +114,7 @@ CAF_TEST(receive_atoms) {
CAF_MESSAGE("received 'abc'"); CAF_MESSAGE("received 'abc'");
}, },
others >> [] { others >> [] {
CAF_TEST_ERROR("unexpected message"); CAF_ERROR("unexpected message");
} }
); );
} }
......
...@@ -246,7 +246,7 @@ behavior high_priority_testee(event_based_actor* self) { ...@@ -246,7 +246,7 @@ behavior high_priority_testee(event_based_actor* self) {
// 'a' must be self->received before 'b' // 'a' must be self->received before 'b'
return { return {
[=](b_atom) { [=](b_atom) {
CAF_TEST_ERROR("received 'b' before 'a'"); CAF_ERROR("received 'b' before 'a'");
self->quit(); self->quit();
}, },
[=](a_atom) { [=](a_atom) {
...@@ -257,12 +257,12 @@ behavior high_priority_testee(event_based_actor* self) { ...@@ -257,12 +257,12 @@ behavior high_priority_testee(event_based_actor* self) {
self->quit(); self->quit();
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
); );
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
}; };
} }
...@@ -291,7 +291,7 @@ behavior slave(event_based_actor* self, actor master) { ...@@ -291,7 +291,7 @@ behavior slave(event_based_actor* self, actor master) {
self->quit(msg.reason); self->quit(msg.reason);
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
}; };
} }
...@@ -359,7 +359,7 @@ CAF_TEST(self_receive_with_zero_timeout) { ...@@ -359,7 +359,7 @@ CAF_TEST(self_receive_with_zero_timeout) {
scoped_actor self{system}; scoped_actor self{system};
self->receive( self->receive(
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
}, },
after(chrono::seconds(0)) >> [] { /* mailbox empty */ } after(chrono::seconds(0)) >> [] { /* mailbox empty */ }
); );
...@@ -374,7 +374,7 @@ CAF_TEST(mirror) { ...@@ -374,7 +374,7 @@ CAF_TEST(mirror) {
CAF_CHECK_EQUAL(msg, "hello mirror"); CAF_CHECK_EQUAL(msg, "hello mirror");
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
); );
self->send_exit(mirror, exit_reason::user_shutdown); self->send_exit(mirror, exit_reason::user_shutdown);
...@@ -384,11 +384,11 @@ CAF_TEST(mirror) { ...@@ -384,11 +384,11 @@ CAF_TEST(mirror) {
CAF_MESSAGE("received `down_msg`"); CAF_MESSAGE("received `down_msg`");
} }
else { else {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
); );
} }
...@@ -402,7 +402,7 @@ CAF_TEST(detached_mirror) { ...@@ -402,7 +402,7 @@ CAF_TEST(detached_mirror) {
CAF_CHECK_EQUAL(msg, "hello mirror"); CAF_CHECK_EQUAL(msg, "hello mirror");
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
); );
self->send_exit(mirror, exit_reason::user_shutdown); self->send_exit(mirror, exit_reason::user_shutdown);
...@@ -412,11 +412,11 @@ CAF_TEST(detached_mirror) { ...@@ -412,11 +412,11 @@ CAF_TEST(detached_mirror) {
CAF_MESSAGE("received `down_msg`"); CAF_MESSAGE("received `down_msg`");
} }
else { else {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
); );
} }
...@@ -431,7 +431,7 @@ CAF_TEST(priority_aware_mirror) { ...@@ -431,7 +431,7 @@ CAF_TEST(priority_aware_mirror) {
CAF_CHECK_EQUAL(msg, "hello mirror"); CAF_CHECK_EQUAL(msg, "hello mirror");
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
); );
self->send_exit(mirror, exit_reason::user_shutdown); self->send_exit(mirror, exit_reason::user_shutdown);
...@@ -441,11 +441,11 @@ CAF_TEST(priority_aware_mirror) { ...@@ -441,11 +441,11 @@ CAF_TEST(priority_aware_mirror) {
CAF_MESSAGE("received `down_msg`"); CAF_MESSAGE("received `down_msg`");
} }
else { else {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
); );
} }
...@@ -474,7 +474,7 @@ CAF_TEST(echo_actor_messaging) { ...@@ -474,7 +474,7 @@ CAF_TEST(echo_actor_messaging) {
CAF_CHECK_EQUAL(arg, "hello echo"); CAF_CHECK_EQUAL(arg, "hello echo");
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
); );
} }
...@@ -521,13 +521,13 @@ CAF_TEST(requests) { ...@@ -521,13 +521,13 @@ CAF_TEST(requests) {
return "goodbye!"; return "goodbye!";
}, },
after(chrono::minutes(1)) >> [] { after(chrono::minutes(1)) >> [] {
CAF_TEST_ERROR("Error in unit test."); CAF_ERROR("Error in unit test.");
abort(); abort();
} }
); );
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
); );
}); });
...@@ -543,7 +543,7 @@ CAF_TEST(requests) { ...@@ -543,7 +543,7 @@ CAF_TEST(requests) {
); );
self->receive ( self->receive (
on("goodbye!") >> [] { CAF_MESSAGE("Received \"goodbye!\""); }, on("goodbye!") >> [] { CAF_MESSAGE("Received \"goodbye!\""); },
after(chrono::seconds(1)) >> [] { CAF_TEST_ERROR("Unexpected timeout"); } after(chrono::seconds(1)) >> [] { CAF_ERROR("Unexpected timeout"); }
); );
self->receive ( self->receive (
[&](const down_msg& dm) { [&](const down_msg& dm) {
...@@ -554,17 +554,17 @@ CAF_TEST(requests) { ...@@ -554,17 +554,17 @@ CAF_TEST(requests) {
self->await_all_other_actors_done(); self->await_all_other_actors_done();
self->request(sync_testee, "!?").receive( self->request(sync_testee, "!?").receive(
[] { [] {
CAF_TEST_ERROR("Unexpected empty message"); CAF_ERROR("Unexpected empty message");
}, },
[&](error& err) { [&](error& err) {
if (err == sec::request_receiver_down) if (err == sec::request_receiver_down)
CAF_MESSAGE("received `request_receiver_down`"); CAF_MESSAGE("received `request_receiver_down`");
else else
CAF_TEST_ERROR("received unexpected error: " CAF_ERROR("received unexpected error: "
<< self->system().render(err)); << self->system().render(err));
}, },
after(chrono::microseconds(1)) >> [] { after(chrono::microseconds(1)) >> [] {
CAF_TEST_ERROR("Unexpected timeout"); CAF_ERROR("Unexpected timeout");
} }
); );
} }
...@@ -634,7 +634,7 @@ CAF_TEST(constructor_attach) { ...@@ -634,7 +634,7 @@ CAF_TEST(constructor_attach) {
behavior make_behavior() { behavior make_behavior() {
return { return {
others >> [=] { others >> [=] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
}; };
} }
...@@ -755,7 +755,7 @@ CAF_TEST(kill_the_immortal) { ...@@ -755,7 +755,7 @@ CAF_TEST(kill_the_immortal) {
self->trap_exit(true); self->trap_exit(true);
return { return {
others >> [=] { others >> [=] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
}; };
}); });
......
...@@ -91,7 +91,7 @@ ptrdiff_t invoked(message_handler expr, const Ts&... xs) { ...@@ -91,7 +91,7 @@ ptrdiff_t invoked(message_handler expr, const Ts&... xs) {
reset(); reset();
} }
if (results.size() > 1) { if (results.size() > 1) {
CAF_TEST_ERROR("make_message() yielded a different result than " CAF_ERROR("make_message() yielded a different result than "
"message_builder(...).to_message()"); "message_builder(...).to_message()");
return -2; return -2;
} }
......
...@@ -42,7 +42,7 @@ using namespace caf; ...@@ -42,7 +42,7 @@ using namespace caf;
CAF_TEST(apply) { CAF_TEST(apply) {
auto f1 = [] { auto f1 = [] {
CAF_TEST_ERROR("f1 invoked!"); CAF_ERROR("f1 invoked!");
}; };
auto f2 = [](int i) { auto f2 = [](int i) {
CAF_CHECK_EQUAL(i, 42); CAF_CHECK_EQUAL(i, 42);
......
...@@ -85,7 +85,7 @@ behavior tester::make_behavior() { ...@@ -85,7 +85,7 @@ behavior tester::make_behavior() {
quit(); quit();
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
}; };
} }
......
...@@ -237,7 +237,7 @@ behavior server(event_based_actor* self) { ...@@ -237,7 +237,7 @@ behavior server(event_based_actor* self) {
return skip_message(); return skip_message();
}, },
others >> [=] { others >> [=] {
CAF_TEST_ERROR("Unexpected message:" << to_string(self->current_message())); CAF_ERROR("Unexpected message:" << to_string(self->current_message()));
die(); die();
} }
); );
...@@ -246,7 +246,7 @@ behavior server(event_based_actor* self) { ...@@ -246,7 +246,7 @@ behavior server(event_based_actor* self) {
return skip_message(); return skip_message();
}, },
others >> [=] { others >> [=] {
CAF_TEST_ERROR("Unexpected message:" << to_string(self->current_message())); CAF_ERROR("Unexpected message:" << to_string(self->current_message()));
die(); die();
} }
}; };
...@@ -288,7 +288,7 @@ CAF_TEST(pending_quit) { ...@@ -288,7 +288,7 @@ CAF_TEST(pending_quit) {
system.spawn([mirror](event_based_actor* self) { system.spawn([mirror](event_based_actor* self) {
self->request(mirror, 42).then( self->request(mirror, 42).then(
[](int) { [](int) {
CAF_TEST_ERROR("received result, should've been terminated already"); CAF_ERROR("received result, should've been terminated already");
}, },
[](const error& err) { [](const error& err) {
CAF_CHECK(err == sec::request_receiver_down); CAF_CHECK(err == sec::request_receiver_down);
...@@ -315,7 +315,7 @@ CAF_TEST(request) { ...@@ -315,7 +315,7 @@ CAF_TEST(request) {
++invocations; ++invocations;
}, },
[&](const error& err) { [&](const error& err) {
CAF_TEST_ERROR("Error: " << s->system().render(err)); CAF_ERROR("Error: " << s->system().render(err));
} }
); );
s->request(foi, f_atom::value).receive( s->request(foi, f_atom::value).receive(
...@@ -324,7 +324,7 @@ CAF_TEST(request) { ...@@ -324,7 +324,7 @@ CAF_TEST(request) {
++invocations; ++invocations;
}, },
[&](const error& err) { [&](const error& err) {
CAF_TEST_ERROR("Error: " << s->system().render(err)); CAF_ERROR("Error: " << s->system().render(err));
} }
); );
CAF_CHECK_EQUAL(invocations, 2); CAF_CHECK_EQUAL(invocations, 2);
...@@ -350,7 +350,7 @@ CAF_TEST(request) { ...@@ -350,7 +350,7 @@ CAF_TEST(request) {
CAF_CHECK_EQUAL(dm.reason, exit_reason::user_shutdown); CAF_CHECK_EQUAL(dm.reason, exit_reason::user_shutdown);
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message: " CAF_ERROR("Unexpected message: "
<< to_string(self->current_message())); << to_string(self->current_message()));
} }
); );
...@@ -371,13 +371,13 @@ CAF_TEST(request) { ...@@ -371,13 +371,13 @@ CAF_TEST(request) {
CAF_MESSAGE("received `ok_atom`"); CAF_MESSAGE("received `ok_atom`");
}, },
[](error_atom) { [](error_atom) {
CAF_TEST_ERROR("A didn't receive sync response"); CAF_ERROR("A didn't receive sync response");
}, },
[&](const down_msg& dm) -> maybe<skip_message_t> { [&](const down_msg& dm) -> maybe<skip_message_t> {
if (dm.reason == exit_reason::normal) { if (dm.reason == exit_reason::normal) {
return skip_message(); return skip_message();
} }
CAF_TEST_ERROR("A exited for reason " << to_string(dm.reason)); CAF_ERROR("A exited for reason " << to_string(dm.reason));
return none; return none;
} }
); );
...@@ -398,7 +398,7 @@ CAF_TEST(request) { ...@@ -398,7 +398,7 @@ CAF_TEST(request) {
CAF_MESSAGE("`await_all_other_actors_done` finished"); CAF_MESSAGE("`await_all_other_actors_done` finished");
self->request(self, no_way_atom::value).receive( self->request(self, no_way_atom::value).receive(
[&](int) { [&](int) {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
}, },
after(milliseconds(50)) >> [] { after(milliseconds(50)) >> [] {
CAF_MESSAGE("Got timeout"); CAF_MESSAGE("Got timeout");
...@@ -416,17 +416,17 @@ CAF_TEST(request) { ...@@ -416,17 +416,17 @@ CAF_TEST(request) {
"synchronous request message\""); "synchronous request message\"");
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message: " CAF_ERROR("Unexpected message: "
<< to_string(self->current_message())); << to_string(self->current_message()));
}, },
after(milliseconds(0)) >> [] { after(milliseconds(0)) >> [] {
CAF_TEST_ERROR("Unexpected timeout"); CAF_ERROR("Unexpected timeout");
} }
); );
// mailbox should be empty now // mailbox should be empty now
self->receive( self->receive(
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message: " CAF_ERROR("Unexpected message: "
<< to_string(self->current_message())); << to_string(self->current_message()));
}, },
after(milliseconds(0)) >> [] { after(milliseconds(0)) >> [] {
...@@ -439,11 +439,11 @@ CAF_TEST(request) { ...@@ -439,11 +439,11 @@ CAF_TEST(request) {
bool timeout_occured = false; bool timeout_occured = false;
self->request(c, milliseconds(500), hi_there_atom::value).receive( self->request(c, milliseconds(500), hi_there_atom::value).receive(
[&](hi_there_atom) { [&](hi_there_atom) {
CAF_TEST_ERROR("C did reply to 'HiThere'"); CAF_ERROR("C did reply to 'HiThere'");
}, },
[&](const error& err) { [&](const error& err) {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
CAF_TEST_ERROR("Error: " << self->system().render(err)); CAF_ERROR("Error: " << self->system().render(err));
}, },
after(milliseconds(500)) >> [&] { after(milliseconds(500)) >> [&] {
CAF_MESSAGE("timeout occured"); CAF_MESSAGE("timeout occured");
...@@ -457,7 +457,7 @@ CAF_TEST(request) { ...@@ -457,7 +457,7 @@ CAF_TEST(request) {
}, },
[&](const error& err) { [&](const error& err) {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
CAF_TEST_ERROR("Error: " << self->system().render(err)); CAF_ERROR("Error: " << self->system().render(err));
} }
); );
self->send_exit(c, exit_reason::user_shutdown); self->send_exit(c, exit_reason::user_shutdown);
...@@ -482,7 +482,7 @@ CAF_TEST(request) { ...@@ -482,7 +482,7 @@ CAF_TEST(request) {
CAF_CHECK(s->current_sender() == work); CAF_CHECK(s->current_sender() == work);
}, },
[&](const error& err) { [&](const error& err) {
CAF_TEST_ERROR("Error: " << s->system().render(err)); CAF_ERROR("Error: " << s->system().render(err));
} }
); );
// first 'request', then 'idle' // first 'request', then 'idle'
...@@ -493,7 +493,7 @@ CAF_TEST(request) { ...@@ -493,7 +493,7 @@ CAF_TEST(request) {
CAF_CHECK(s->current_sender() == work); CAF_CHECK(s->current_sender() == work);
}, },
[&](const error& err) { [&](const error& err) {
CAF_TEST_ERROR("Error: " << s->system().render(err)); CAF_ERROR("Error: " << s->system().render(err));
} }
); );
s->quit(exit_reason::user_shutdown); s->quit(exit_reason::user_shutdown);
...@@ -503,7 +503,7 @@ CAF_TEST(request) { ...@@ -503,7 +503,7 @@ CAF_TEST(request) {
CAF_CHECK_EQUAL(dm.reason, exit_reason::user_shutdown); CAF_CHECK_EQUAL(dm.reason, exit_reason::user_shutdown);
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message: " CAF_ERROR("Unexpected message: "
<< to_string(self->current_message())); << to_string(self->current_message()));
} }
); );
......
...@@ -51,7 +51,7 @@ behavior ping1(event_based_actor* self, const actor& pong_actor) { ...@@ -51,7 +51,7 @@ behavior ping1(event_based_actor* self, const actor& pong_actor) {
[=](send_ping_atom) { [=](send_ping_atom) {
self->request(pong_actor, ping_atom::value).then( self->request(pong_actor, ping_atom::value).then(
[=](pong_atom) { [=](pong_atom) {
CAF_TEST_ERROR("received pong atom"); CAF_ERROR("received pong atom");
self->quit(exit_reason::user_shutdown); self->quit(exit_reason::user_shutdown);
}, },
after(std::chrono::milliseconds(100)) >> [=] { after(std::chrono::milliseconds(100)) >> [=] {
...@@ -71,7 +71,7 @@ behavior ping2(event_based_actor* self, const actor& pong_actor) { ...@@ -71,7 +71,7 @@ behavior ping2(event_based_actor* self, const actor& pong_actor) {
[=](send_ping_atom) { [=](send_ping_atom) {
self->request(pong_actor, ping_atom::value).then( self->request(pong_actor, ping_atom::value).then(
[=](pong_atom) { [=](pong_atom) {
CAF_TEST_ERROR("received pong atom"); CAF_ERROR("received pong atom");
self->quit(exit_reason::user_shutdown); self->quit(exit_reason::user_shutdown);
}, },
after(std::chrono::milliseconds(100)) >> [=] { after(std::chrono::milliseconds(100)) >> [=] {
...@@ -94,7 +94,7 @@ behavior ping3(event_based_actor* self, const actor& pong_actor) { ...@@ -94,7 +94,7 @@ behavior ping3(event_based_actor* self, const actor& pong_actor) {
[=](send_ping_atom) { [=](send_ping_atom) {
self->request(pong_actor, ping_atom::value).then( self->request(pong_actor, ping_atom::value).then(
[=](pong_atom) { [=](pong_atom) {
CAF_TEST_ERROR("received pong atom"); CAF_ERROR("received pong atom");
self->quit(exit_reason::user_shutdown); self->quit(exit_reason::user_shutdown);
}, },
after(std::chrono::milliseconds(100)) >> [=] { after(std::chrono::milliseconds(100)) >> [=] {
...@@ -114,7 +114,7 @@ behavior ping4(event_based_actor* self, const actor& pong_actor) { ...@@ -114,7 +114,7 @@ behavior ping4(event_based_actor* self, const actor& pong_actor) {
[=](send_ping_atom) { [=](send_ping_atom) {
self->request(pong_actor, ping_atom::value).then( self->request(pong_actor, ping_atom::value).then(
[=](pong_atom) { [=](pong_atom) {
CAF_TEST_ERROR("received pong atom"); CAF_ERROR("received pong atom");
self->quit(exit_reason::user_shutdown); self->quit(exit_reason::user_shutdown);
}, },
after(std::chrono::milliseconds(100)) >> [=] { after(std::chrono::milliseconds(100)) >> [=] {
...@@ -135,7 +135,7 @@ void ping5(event_based_actor* self, const actor& pong_actor) { ...@@ -135,7 +135,7 @@ void ping5(event_based_actor* self, const actor& pong_actor) {
auto flag = std::make_shared<int>(0); auto flag = std::make_shared<int>(0);
self->request(pong_actor, ping_atom::value).then( self->request(pong_actor, ping_atom::value).then(
[=](pong_atom) { [=](pong_atom) {
CAF_TEST_ERROR("received pong atom"); CAF_ERROR("received pong atom");
*flag = 1; *flag = 1;
}, },
after(std::chrono::milliseconds(100)) >> [=] { after(std::chrono::milliseconds(100)) >> [=] {
...@@ -147,7 +147,7 @@ void ping5(event_based_actor* self, const actor& pong_actor) { ...@@ -147,7 +147,7 @@ void ping5(event_based_actor* self, const actor& pong_actor) {
); );
self->request(pong_actor, ping_atom::value).await( self->request(pong_actor, ping_atom::value).await(
[=](pong_atom) { [=](pong_atom) {
CAF_TEST_ERROR("received pong atom"); CAF_ERROR("received pong atom");
*flag = 3; *flag = 3;
}, },
after(std::chrono::milliseconds(100)) >> [=] { after(std::chrono::milliseconds(100)) >> [=] {
......
...@@ -94,7 +94,7 @@ CAF_TEST(test_serial_reply) { ...@@ -94,7 +94,7 @@ CAF_TEST(test_serial_reply) {
CAF_MESSAGE("received 'ho'"); CAF_MESSAGE("received 'ho'");
}, },
[&](const error& err) { [&](const error& err) {
CAF_TEST_ERROR("Error: " << self->system().render(err)); CAF_ERROR("Error: " << self->system().render(err));
} }
); );
self->send_exit(master, exit_reason::user_shutdown); self->send_exit(master, exit_reason::user_shutdown);
......
...@@ -321,7 +321,7 @@ int_actor::behavior_type int_fun2(int_actor::pointer self) { ...@@ -321,7 +321,7 @@ int_actor::behavior_type int_fun2(int_actor::pointer self) {
self->quit(); self->quit();
}, },
[=](const exit_msg&) { [=](const exit_msg&) {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
}; };
} }
...@@ -399,7 +399,7 @@ CAF_TEST(event_testee_series) { ...@@ -399,7 +399,7 @@ CAF_TEST(event_testee_series) {
result = str; result = str;
}, },
after(chrono::minutes(1)) >> [&] { after(chrono::minutes(1)) >> [&] {
CAF_TEST_ERROR("event_testee does not reply"); CAF_ERROR("event_testee does not reply");
throw runtime_error("event_testee does not reply"); throw runtime_error("event_testee does not reply");
} }
); );
......
...@@ -261,7 +261,7 @@ CAF_TEST(triangle_setup) { ...@@ -261,7 +261,7 @@ CAF_TEST(triangle_setup) {
bool is_jupiter = r.opts.count("jupiter") > 0; bool is_jupiter = r.opts.count("jupiter") > 0;
bool has_port = r.opts.count("port") > 0; bool has_port = r.opts.count("port") > 0;
if (((is_mars || is_jupiter) && ! has_port) || (is_mars && is_jupiter)) { if (((is_mars || is_jupiter) && ! has_port) || (is_mars && is_jupiter)) {
CAF_TEST_ERROR("need a port when running Mars or Jupiter and cannot " CAF_ERROR("need a port when running Mars or Jupiter and cannot "
"both at the same time"); "both at the same time");
return; return;
} }
......
...@@ -58,11 +58,11 @@ void ping(event_based_actor* self, size_t num_pings) { ...@@ -58,11 +58,11 @@ void ping(event_based_actor* self, size_t num_pings) {
return std::make_tuple(ping_atom::value, value + 1); return std::make_tuple(ping_atom::value, value + 1);
}, },
others >> [=] { others >> [=] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
}); });
}, },
others >> [=] { others >> [=] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
); );
} }
...@@ -83,14 +83,14 @@ void pong(event_based_actor* self) { ...@@ -83,14 +83,14 @@ void pong(event_based_actor* self) {
self->quit(dm.reason); self->quit(dm.reason);
}, },
others >> [=] { others >> [=] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
); );
// reply to 'ping' // reply to 'ping'
return std::make_tuple(pong_atom::value, value); return std::make_tuple(pong_atom::value, value);
}, },
others >> [=] { others >> [=] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
); );
} }
...@@ -157,7 +157,7 @@ behavior peer_acceptor_fun(broker* self, const actor& buddy) { ...@@ -157,7 +157,7 @@ behavior peer_acceptor_fun(broker* self, const actor& buddy) {
return self->add_tcp_doorman(0, "127.0.0.1").second; return self->add_tcp_doorman(0, "127.0.0.1").second;
}, },
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
}; };
} }
...@@ -186,7 +186,7 @@ void run_server(int argc, char** argv) { ...@@ -186,7 +186,7 @@ void run_server(int argc, char** argv) {
child = std::thread([=] { run_client(argc, argv, port); }); child = std::thread([=] { run_client(argc, argv, port); });
}, },
[&](const error& err) { [&](const error& err) {
CAF_TEST_ERROR("Error: " << self->system().render(err)); CAF_ERROR("Error: " << self->system().render(err));
} }
); );
self->await_all_other_actors_done(); self->await_all_other_actors_done();
......
...@@ -62,7 +62,7 @@ behavior ping_behavior(local_actor* self, size_t ping_msgs) { ...@@ -62,7 +62,7 @@ behavior ping_behavior(local_actor* self, size_t ping_msgs) {
[=](pong_atom, int value) -> message { [=](pong_atom, int value) -> message {
CAF_LOG_TRACE(CAF_ARG(value)); CAF_LOG_TRACE(CAF_ARG(value));
if (! self->current_sender()) { if (! self->current_sender()) {
CAF_TEST_ERROR("current_sender() invalid!"); CAF_ERROR("current_sender() invalid!");
} }
CAF_MESSAGE("received {'pong', " << value << "}"); CAF_MESSAGE("received {'pong', " << value << "}");
if (++s_pongs >= ping_msgs) { if (++s_pongs >= ping_msgs) {
...@@ -166,7 +166,7 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) { ...@@ -166,7 +166,7 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) {
self->become( self->become(
[=](const down_msg& dm) { [=](const down_msg& dm) {
if (dm.reason != exit_reason::normal) { if (dm.reason != exit_reason::normal) {
CAF_TEST_ERROR("reflector exited for non-normal exit reason!"); CAF_ERROR("reflector exited for non-normal exit reason!");
} }
if (++*downs == 5) { if (++*downs == 5) {
CAF_MESSAGE("down increased to 5, about to quit"); CAF_MESSAGE("down increased to 5, about to quit");
...@@ -175,11 +175,11 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) { ...@@ -175,11 +175,11 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) {
} }
}, },
others >> [=] { others >> [=] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
self->quit(exit_reason::user_shutdown); self->quit(exit_reason::user_shutdown);
}, },
after(chrono::seconds(3)) >> [=] { after(chrono::seconds(3)) >> [=] {
CAF_TEST_ERROR("did only receive " << *downs << " down messages"); CAF_ERROR("did only receive " << *downs << " down messages");
self->quit(exit_reason::user_shutdown); self->quit(exit_reason::user_shutdown);
} }
); );
...@@ -187,18 +187,18 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) { ...@@ -187,18 +187,18 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) {
}, },
after(std::chrono::seconds(6)) >> [=] { after(std::chrono::seconds(6)) >> [=] {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
CAF_TEST_ERROR("Unexpected timeout"); CAF_ERROR("Unexpected timeout");
self->quit(exit_reason::user_shutdown); self->quit(exit_reason::user_shutdown);
} }
); );
}, },
[=](const error& err) { [=](const error& err) {
CAF_TEST_ERROR("Error: " << self->system().render(err)); CAF_ERROR("Error: " << self->system().render(err));
self->quit(exit_reason::user_shutdown); self->quit(exit_reason::user_shutdown);
}, },
after(chrono::seconds(10)) >> [=] { after(chrono::seconds(10)) >> [=] {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
CAF_TEST_ERROR("Unexpected timeout"); CAF_ERROR("Unexpected timeout");
self->quit(exit_reason::user_shutdown); self->quit(exit_reason::user_shutdown);
} }
); );
......
...@@ -48,7 +48,7 @@ behavior client(event_based_actor* self, actor serv) { ...@@ -48,7 +48,7 @@ behavior client(event_based_actor* self, actor serv) {
self->send(serv, ok_atom::value); self->send(serv, ok_atom::value);
return { return {
others >> [=] { others >> [=] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
}; };
} }
...@@ -90,7 +90,7 @@ behavior server(stateful_actor<server_state>* self) { ...@@ -90,7 +90,7 @@ behavior server(stateful_actor<server_state>* self) {
}, },
[=](const error& err) { [=](const error& err) {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
CAF_TEST_ERROR("Error: " << self->system().render(err)); CAF_ERROR("Error: " << self->system().render(err));
} }
}; };
} }
......
...@@ -67,11 +67,11 @@ behavior ping(event_based_actor* self, size_t num_pings) { ...@@ -67,11 +67,11 @@ behavior ping(event_based_actor* self, size_t num_pings) {
return std::make_tuple(ping_atom::value, value + 1); return std::make_tuple(ping_atom::value, value + 1);
}, },
others >> [=] { others >> [=] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
}); });
}, },
others >> [=] { others >> [=] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
}; };
} }
...@@ -92,14 +92,14 @@ behavior pong(event_based_actor* self) { ...@@ -92,14 +92,14 @@ behavior pong(event_based_actor* self) {
self->quit(dm.reason); self->quit(dm.reason);
}, },
others >> [=] { others >> [=] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
); );
// reply to 'ping' // reply to 'ping'
return std::make_tuple(pong_atom::value, value); return std::make_tuple(pong_atom::value, value);
}, },
others >> [=] { others >> [=] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
}; };
} }
......
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
behavior make_behavior() override { behavior make_behavior() override {
return { return {
others >> [&] { others >> [&] {
CAF_TEST_ERROR("Unexpected message"); CAF_ERROR("Unexpected message");
} }
}; };
} }
......
...@@ -132,6 +132,8 @@ public: ...@@ -132,6 +132,8 @@ public:
// constructs spacing given a line number. // constructs spacing given a line number.
const char* fill(size_t line); const char* fill(size_t line);
void remove_trailing_spaces(std::string& x);
} // namespace detail } // namespace detail
/// Logs messages for the test framework. /// Logs messages for the test framework.
...@@ -175,12 +177,15 @@ public: ...@@ -175,12 +177,15 @@ public:
stream& operator<<(const std::string& str); stream& operator<<(const std::string& str);
std::string str() const;
private: private:
void flush(); void flush();
logger& logger_; logger& logger_;
level level_; level level_;
std::ostringstream buf_; std::ostringstream buf_;
std::string str_;
}; };
static bool init(int lvl_cons, int lvl_file, const std::string& logfile); static bool init(int lvl_cons, int lvl_file, const std::string& logfile);
...@@ -377,24 +382,8 @@ showable<T> show(const T &x) { ...@@ -377,24 +382,8 @@ showable<T> show(const T &x) {
return showable<T>{x}; return showable<T>{x};
} }
inline bool check(test* parent, const char *file, size_t line, bool check(test* parent, const char *file, size_t line,
const char *expr, bool should_fail, bool result) { const char *expr, bool should_fail, bool result);
std::stringstream ss;
if (result) {
ss << engine::color(green) << "** "
<< engine::color(blue) << file << engine::color(yellow) << ":"
<< engine::color(blue) << line << fill(line) << engine::color(reset)
<< expr;
parent->pass(ss.str());
} else {
ss << engine::color(red) << "!! "
<< engine::color(blue) << file << engine::color(yellow) << ":"
<< engine::color(blue) << line << fill(line) << engine::color(reset)
<< expr;
parent->fail(ss.str(), should_fail);
}
return result;
}
template <class T, class U> template <class T, class U>
bool check(test* parent, const char *file, size_t line, bool check(test* parent, const char *file, size_t line,
...@@ -427,19 +416,14 @@ bool check(test* parent, const char *file, size_t line, ...@@ -427,19 +416,14 @@ bool check(test* parent, const char *file, size_t line,
// on the global namespace so that it can hidden via namespace-scoping // on the global namespace so that it can hidden via namespace-scoping
using caf_test_case_auto_fixture = caf::test::dummy_fixture; using caf_test_case_auto_fixture = caf::test::dummy_fixture;
#define CAF_TEST_PR(level, msg, colorcode) \ #define CAF_TEST_PRINT(level, msg, colorcode) \
::caf::test::logger::instance(). level () \ (::caf::test::logger::instance(). level () \
<< ::caf::test::engine::color(::caf::test:: colorcode ) \ << ::caf::test::engine::color(::caf::test:: colorcode ) \
<< " -> " << ::caf::test::engine::color(::caf::test::reset) << msg << '\n' << " -> " << ::caf::test::engine::color(::caf::test::reset) << msg << '\n')
#define CAF_TEST_ERROR(msg) \
CAF_TEST_PR(info, msg, red)
#define CAF_TEST_INFO(msg) \ #define CAF_TEST_PRINT_ERROR(msg) CAF_TEST_PRINT(info, msg, red)
CAF_TEST_PR(info, msg, yellow) #define CAF_TEST_PRINT_INFO(msg) CAF_TEST_PRINT(info, msg, yellow)
#define CAF_TEST_PRINT_VERBOSE(msg) CAF_TEST_PRINT(verbose, msg, yellow)
#define CAF_TEST_VERBOSE(msg) \
CAF_TEST_PR(verbose, msg, yellow)
#define CAF_PASTE_CONCAT(lhs, rhs) lhs ## rhs #define CAF_PASTE_CONCAT(lhs, rhs) lhs ## rhs
...@@ -458,6 +442,15 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture; ...@@ -458,6 +442,15 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
#define CAF_PRED_EXPR(pred, x_expr, y_expr) "("#x_expr") "#pred" ("#y_expr")" #define CAF_PRED_EXPR(pred, x_expr, y_expr) "("#x_expr") "#pred" ("#y_expr")"
#define CAF_FUNC_EXPR(func, x_expr, y_expr) #func"("#x_expr", "#y_expr")" #define CAF_FUNC_EXPR(func, x_expr, y_expr) #func"("#x_expr", "#y_expr")"
#define CAF_ERROR(msg) \
do { \
auto CAF_UNIQUE(__str) = CAF_TEST_PRINT_ERROR(msg).str(); \
::caf::test::detail::remove_trailing_spaces(CAF_UNIQUE(__str)); \
::caf::test::engine::current_test()->fail(CAF_UNIQUE(__str), false); \
::caf::test::engine::last_check_file(__FILE__); \
::caf::test::engine::last_check_line(__LINE__); \
} while(false)
#define CAF_CHECK(...) \ #define CAF_CHECK(...) \
do { \ do { \
static_cast<void>(::caf::test::detail::check( \ static_cast<void>(::caf::test::detail::check( \
...@@ -502,7 +495,9 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture; ...@@ -502,7 +495,9 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
#define CAF_FAIL(msg) \ #define CAF_FAIL(msg) \
do { \ do { \
CAF_TEST_ERROR(msg); \ auto CAF_UNIQUE(__str) = CAF_TEST_PRINT_ERROR(msg).str(); \
::caf::test::detail::remove_trailing_spaces(CAF_UNIQUE(__str)); \
::caf::test::engine::current_test()->fail(CAF_UNIQUE(__str), false); \
throw ::caf::test::detail::require_error{"test failure"}; \ throw ::caf::test::detail::require_error{"test failure"}; \
} while(false) } while(false)
...@@ -583,6 +578,6 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture; ...@@ -583,6 +578,6 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
#define CAF_REQUIRE_GREATER(x, y) CAF_REQUIRE_PRED(> , x, y) #define CAF_REQUIRE_GREATER(x, y) CAF_REQUIRE_PRED(> , x, y)
#define CAF_REQUIRE_GREATER_EQUAL(x, y) CAF_REQUIRE_PRED(>=, x, y) #define CAF_REQUIRE_GREATER_EQUAL(x, y) CAF_REQUIRE_PRED(>=, x, y)
#define CAF_MESSAGE(msg) CAF_TEST_VERBOSE(msg) #define CAF_MESSAGE(msg) CAF_TEST_PRINT_VERBOSE(msg)
#endif // CAF_TEST_UNIT_TEST_HPP #endif // CAF_TEST_UNIT_TEST_HPP
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define CAF_TEST_UNIT_TEST_IMPL_HPP #define CAF_TEST_UNIT_TEST_IMPL_HPP
#include <regex> #include <regex>
#include <cctype>
#include <thread> #include <thread>
#include <cassert> #include <cassert>
#include <cstdlib> #include <cstdlib>
...@@ -140,6 +141,29 @@ const char* fill(size_t line) { ...@@ -140,6 +141,29 @@ const char* fill(size_t line) {
} }
} }
void remove_trailing_spaces(std::string& x) {
x.erase(std::find_if_not(x.rbegin(), x.rend(), ::isspace).base(), x.end());
}
bool check(test* parent, const char *file, size_t line,
const char *expr, bool should_fail, bool result) {
std::stringstream ss;
if (result) {
ss << engine::color(green) << "** "
<< engine::color(blue) << file << engine::color(yellow) << ":"
<< engine::color(blue) << line << fill(line) << engine::color(reset)
<< expr;
parent->pass(ss.str());
} else {
ss << engine::color(red) << "!! "
<< engine::color(blue) << file << engine::color(yellow) << ":"
<< engine::color(blue) << line << fill(line) << engine::color(reset)
<< expr;
parent->fail(ss.str(), should_fail);
}
return result;
}
} // namespace detail } // namespace detail
logger::stream::stream(logger& l, level lvl) : logger_(l), level_(lvl) { logger::stream::stream(logger& l, level lvl) : logger_(l), level_(lvl) {
...@@ -183,12 +207,17 @@ logger::stream& logger::stream::operator<<(const std::string& str) { ...@@ -183,12 +207,17 @@ logger::stream& logger::stream::operator<<(const std::string& str) {
return *this; return *this;
} }
std::string logger::stream::str() const {
return str_;
}
void logger::stream::flush() { void logger::stream::flush() {
logger_.log(level_, buf_.str()); auto str = buf_.str();
buf_.str(""); buf_.str("");
logger_.log(level_, str);
str_ += str;
} }
bool logger::init(int lvl_cons, int lvl_file, const std::string& logfile) { bool logger::init(int lvl_cons, int lvl_file, const std::string& logfile) {
instance().level_console_ = static_cast<level>(lvl_cons); instance().level_console_ = static_cast<level>(lvl_cons);
instance().level_file_ = static_cast<level>(lvl_file); instance().level_file_ = static_cast<level>(lvl_file);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment