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) {
);
},
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");
......@@ -143,7 +143,7 @@ CAF_TEST(round_robin_actor_pool) {
workers.erase(pos);
},
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) {
results.push_back(res);
},
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);
......@@ -182,7 +182,7 @@ CAF_TEST(random_actor_pool) {
CAF_CHECK_EQUAL(res, 3);
},
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) {
CAF_MESSAGE("drain mailbox");
},
after(std::chrono::seconds(0)) >> [] {
CAF_TEST_ERROR("mailbox empty");
CAF_ERROR("mailbox empty");
}
);
atom_value x = atom("abc");
......@@ -114,7 +114,7 @@ CAF_TEST(receive_atoms) {
CAF_MESSAGE("received 'abc'");
},
others >> [] {
CAF_TEST_ERROR("unexpected message");
CAF_ERROR("unexpected message");
}
);
}
......
......@@ -246,7 +246,7 @@ behavior high_priority_testee(event_based_actor* self) {
// 'a' must be self->received before 'b'
return {
[=](b_atom) {
CAF_TEST_ERROR("received 'b' before 'a'");
CAF_ERROR("received 'b' before 'a'");
self->quit();
},
[=](a_atom) {
......@@ -257,12 +257,12 @@ behavior high_priority_testee(event_based_actor* self) {
self->quit();
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
);
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
};
}
......@@ -291,7 +291,7 @@ behavior slave(event_based_actor* self, actor master) {
self->quit(msg.reason);
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
};
}
......@@ -359,7 +359,7 @@ CAF_TEST(self_receive_with_zero_timeout) {
scoped_actor self{system};
self->receive(
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
},
after(chrono::seconds(0)) >> [] { /* mailbox empty */ }
);
......@@ -374,7 +374,7 @@ CAF_TEST(mirror) {
CAF_CHECK_EQUAL(msg, "hello mirror");
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
);
self->send_exit(mirror, exit_reason::user_shutdown);
......@@ -384,11 +384,11 @@ CAF_TEST(mirror) {
CAF_MESSAGE("received `down_msg`");
}
else {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
);
}
......@@ -402,7 +402,7 @@ CAF_TEST(detached_mirror) {
CAF_CHECK_EQUAL(msg, "hello mirror");
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
);
self->send_exit(mirror, exit_reason::user_shutdown);
......@@ -412,11 +412,11 @@ CAF_TEST(detached_mirror) {
CAF_MESSAGE("received `down_msg`");
}
else {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
);
}
......@@ -431,7 +431,7 @@ CAF_TEST(priority_aware_mirror) {
CAF_CHECK_EQUAL(msg, "hello mirror");
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
);
self->send_exit(mirror, exit_reason::user_shutdown);
......@@ -441,11 +441,11 @@ CAF_TEST(priority_aware_mirror) {
CAF_MESSAGE("received `down_msg`");
}
else {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
);
}
......@@ -474,7 +474,7 @@ CAF_TEST(echo_actor_messaging) {
CAF_CHECK_EQUAL(arg, "hello echo");
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
);
}
......@@ -521,13 +521,13 @@ CAF_TEST(requests) {
return "goodbye!";
},
after(chrono::minutes(1)) >> [] {
CAF_TEST_ERROR("Error in unit test.");
CAF_ERROR("Error in unit test.");
abort();
}
);
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
);
});
......@@ -543,7 +543,7 @@ CAF_TEST(requests) {
);
self->receive (
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 (
[&](const down_msg& dm) {
......@@ -554,17 +554,17 @@ CAF_TEST(requests) {
self->await_all_other_actors_done();
self->request(sync_testee, "!?").receive(
[] {
CAF_TEST_ERROR("Unexpected empty message");
CAF_ERROR("Unexpected empty message");
},
[&](error& err) {
if (err == sec::request_receiver_down)
CAF_MESSAGE("received `request_receiver_down`");
else
CAF_TEST_ERROR("received unexpected error: "
CAF_ERROR("received unexpected error: "
<< self->system().render(err));
},
after(chrono::microseconds(1)) >> [] {
CAF_TEST_ERROR("Unexpected timeout");
CAF_ERROR("Unexpected timeout");
}
);
}
......@@ -634,7 +634,7 @@ CAF_TEST(constructor_attach) {
behavior make_behavior() {
return {
others >> [=] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
};
}
......@@ -755,7 +755,7 @@ CAF_TEST(kill_the_immortal) {
self->trap_exit(true);
return {
others >> [=] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
};
});
......
......@@ -91,8 +91,8 @@ ptrdiff_t invoked(message_handler expr, const Ts&... xs) {
reset();
}
if (results.size() > 1) {
CAF_TEST_ERROR("make_message() yielded a different result than "
"message_builder(...).to_message()");
CAF_ERROR("make_message() yielded a different result than "
"message_builder(...).to_message()");
return -2;
}
return *results.begin();
......
......@@ -42,7 +42,7 @@ using namespace caf;
CAF_TEST(apply) {
auto f1 = [] {
CAF_TEST_ERROR("f1 invoked!");
CAF_ERROR("f1 invoked!");
};
auto f2 = [](int i) {
CAF_CHECK_EQUAL(i, 42);
......
......@@ -85,7 +85,7 @@ behavior tester::make_behavior() {
quit();
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
};
}
......
......@@ -237,7 +237,7 @@ behavior server(event_based_actor* self) {
return skip_message();
},
others >> [=] {
CAF_TEST_ERROR("Unexpected message:" << to_string(self->current_message()));
CAF_ERROR("Unexpected message:" << to_string(self->current_message()));
die();
}
);
......@@ -246,7 +246,7 @@ behavior server(event_based_actor* self) {
return skip_message();
},
others >> [=] {
CAF_TEST_ERROR("Unexpected message:" << to_string(self->current_message()));
CAF_ERROR("Unexpected message:" << to_string(self->current_message()));
die();
}
};
......@@ -288,7 +288,7 @@ CAF_TEST(pending_quit) {
system.spawn([mirror](event_based_actor* self) {
self->request(mirror, 42).then(
[](int) {
CAF_TEST_ERROR("received result, should've been terminated already");
CAF_ERROR("received result, should've been terminated already");
},
[](const error& err) {
CAF_CHECK(err == sec::request_receiver_down);
......@@ -315,7 +315,7 @@ CAF_TEST(request) {
++invocations;
},
[&](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(
......@@ -324,7 +324,7 @@ CAF_TEST(request) {
++invocations;
},
[&](const error& err) {
CAF_TEST_ERROR("Error: " << s->system().render(err));
CAF_ERROR("Error: " << s->system().render(err));
}
);
CAF_CHECK_EQUAL(invocations, 2);
......@@ -350,8 +350,8 @@ CAF_TEST(request) {
CAF_CHECK_EQUAL(dm.reason, exit_reason::user_shutdown);
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message: "
<< to_string(self->current_message()));
CAF_ERROR("Unexpected message: "
<< to_string(self->current_message()));
}
);
auto mirror = system.spawn<sync_mirror>();
......@@ -371,13 +371,13 @@ CAF_TEST(request) {
CAF_MESSAGE("received `ok_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> {
if (dm.reason == exit_reason::normal) {
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;
}
);
......@@ -398,7 +398,7 @@ CAF_TEST(request) {
CAF_MESSAGE("`await_all_other_actors_done` finished");
self->request(self, no_way_atom::value).receive(
[&](int) {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
},
after(milliseconds(50)) >> [] {
CAF_MESSAGE("Got timeout");
......@@ -416,18 +416,18 @@ CAF_TEST(request) {
"synchronous request message\"");
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message: "
CAF_ERROR("Unexpected message: "
<< to_string(self->current_message()));
},
after(milliseconds(0)) >> [] {
CAF_TEST_ERROR("Unexpected timeout");
CAF_ERROR("Unexpected timeout");
}
);
// mailbox should be empty now
self->receive(
others >> [&] {
CAF_TEST_ERROR("Unexpected message: "
<< to_string(self->current_message()));
CAF_ERROR("Unexpected message: "
<< to_string(self->current_message()));
},
after(milliseconds(0)) >> [] {
CAF_MESSAGE("Mailbox is empty, all good");
......@@ -439,11 +439,11 @@ CAF_TEST(request) {
bool timeout_occured = false;
self->request(c, milliseconds(500), hi_there_atom::value).receive(
[&](hi_there_atom) {
CAF_TEST_ERROR("C did reply to 'HiThere'");
CAF_ERROR("C did reply to 'HiThere'");
},
[&](const error& err) {
CAF_LOG_TRACE("");
CAF_TEST_ERROR("Error: " << self->system().render(err));
CAF_ERROR("Error: " << self->system().render(err));
},
after(milliseconds(500)) >> [&] {
CAF_MESSAGE("timeout occured");
......@@ -457,7 +457,7 @@ CAF_TEST(request) {
},
[&](const error& err) {
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);
......@@ -482,7 +482,7 @@ CAF_TEST(request) {
CAF_CHECK(s->current_sender() == work);
},
[&](const error& err) {
CAF_TEST_ERROR("Error: " << s->system().render(err));
CAF_ERROR("Error: " << s->system().render(err));
}
);
// first 'request', then 'idle'
......@@ -493,7 +493,7 @@ CAF_TEST(request) {
CAF_CHECK(s->current_sender() == work);
},
[&](const error& err) {
CAF_TEST_ERROR("Error: " << s->system().render(err));
CAF_ERROR("Error: " << s->system().render(err));
}
);
s->quit(exit_reason::user_shutdown);
......@@ -503,8 +503,8 @@ CAF_TEST(request) {
CAF_CHECK_EQUAL(dm.reason, exit_reason::user_shutdown);
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message: "
<< to_string(self->current_message()));
CAF_ERROR("Unexpected message: "
<< to_string(self->current_message()));
}
);
}
......
......@@ -51,7 +51,7 @@ behavior ping1(event_based_actor* self, const actor& pong_actor) {
[=](send_ping_atom) {
self->request(pong_actor, ping_atom::value).then(
[=](pong_atom) {
CAF_TEST_ERROR("received pong atom");
CAF_ERROR("received pong atom");
self->quit(exit_reason::user_shutdown);
},
after(std::chrono::milliseconds(100)) >> [=] {
......@@ -71,7 +71,7 @@ behavior ping2(event_based_actor* self, const actor& pong_actor) {
[=](send_ping_atom) {
self->request(pong_actor, ping_atom::value).then(
[=](pong_atom) {
CAF_TEST_ERROR("received pong atom");
CAF_ERROR("received pong atom");
self->quit(exit_reason::user_shutdown);
},
after(std::chrono::milliseconds(100)) >> [=] {
......@@ -94,7 +94,7 @@ behavior ping3(event_based_actor* self, const actor& pong_actor) {
[=](send_ping_atom) {
self->request(pong_actor, ping_atom::value).then(
[=](pong_atom) {
CAF_TEST_ERROR("received pong atom");
CAF_ERROR("received pong atom");
self->quit(exit_reason::user_shutdown);
},
after(std::chrono::milliseconds(100)) >> [=] {
......@@ -114,7 +114,7 @@ behavior ping4(event_based_actor* self, const actor& pong_actor) {
[=](send_ping_atom) {
self->request(pong_actor, ping_atom::value).then(
[=](pong_atom) {
CAF_TEST_ERROR("received pong atom");
CAF_ERROR("received pong atom");
self->quit(exit_reason::user_shutdown);
},
after(std::chrono::milliseconds(100)) >> [=] {
......@@ -135,7 +135,7 @@ void ping5(event_based_actor* self, const actor& pong_actor) {
auto flag = std::make_shared<int>(0);
self->request(pong_actor, ping_atom::value).then(
[=](pong_atom) {
CAF_TEST_ERROR("received pong atom");
CAF_ERROR("received pong atom");
*flag = 1;
},
after(std::chrono::milliseconds(100)) >> [=] {
......@@ -147,7 +147,7 @@ void ping5(event_based_actor* self, const actor& pong_actor) {
);
self->request(pong_actor, ping_atom::value).await(
[=](pong_atom) {
CAF_TEST_ERROR("received pong atom");
CAF_ERROR("received pong atom");
*flag = 3;
},
after(std::chrono::milliseconds(100)) >> [=] {
......
......@@ -94,7 +94,7 @@ CAF_TEST(test_serial_reply) {
CAF_MESSAGE("received 'ho'");
},
[&](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);
......
......@@ -321,7 +321,7 @@ int_actor::behavior_type int_fun2(int_actor::pointer self) {
self->quit();
},
[=](const exit_msg&) {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
};
}
......@@ -399,7 +399,7 @@ CAF_TEST(event_testee_series) {
result = str;
},
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");
}
);
......
......@@ -261,8 +261,8 @@ CAF_TEST(triangle_setup) {
bool is_jupiter = r.opts.count("jupiter") > 0;
bool has_port = r.opts.count("port") > 0;
if (((is_mars || is_jupiter) && ! has_port) || (is_mars && is_jupiter)) {
CAF_TEST_ERROR("need a port when running Mars or Jupiter and cannot "
"both at the same time");
CAF_ERROR("need a port when running Mars or Jupiter and cannot "
"both at the same time");
return;
}
// enable automatic connections
......
......@@ -58,11 +58,11 @@ void ping(event_based_actor* self, size_t num_pings) {
return std::make_tuple(ping_atom::value, value + 1);
},
others >> [=] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
});
},
others >> [=] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
);
}
......@@ -83,14 +83,14 @@ void pong(event_based_actor* self) {
self->quit(dm.reason);
},
others >> [=] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
);
// reply to 'ping'
return std::make_tuple(pong_atom::value, value);
},
others >> [=] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
);
}
......@@ -157,7 +157,7 @@ behavior peer_acceptor_fun(broker* self, const actor& buddy) {
return self->add_tcp_doorman(0, "127.0.0.1").second;
},
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
};
}
......@@ -186,7 +186,7 @@ void run_server(int argc, char** argv) {
child = std::thread([=] { run_client(argc, argv, port); });
},
[&](const error& err) {
CAF_TEST_ERROR("Error: " << self->system().render(err));
CAF_ERROR("Error: " << self->system().render(err));
}
);
self->await_all_other_actors_done();
......
......@@ -62,7 +62,7 @@ behavior ping_behavior(local_actor* self, size_t ping_msgs) {
[=](pong_atom, int value) -> message {
CAF_LOG_TRACE(CAF_ARG(value));
if (! self->current_sender()) {
CAF_TEST_ERROR("current_sender() invalid!");
CAF_ERROR("current_sender() invalid!");
}
CAF_MESSAGE("received {'pong', " << value << "}");
if (++s_pongs >= ping_msgs) {
......@@ -166,7 +166,7 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) {
self->become(
[=](const down_msg& dm) {
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) {
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) {
}
},
others >> [=] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
self->quit(exit_reason::user_shutdown);
},
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);
}
);
......@@ -187,18 +187,18 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) {
},
after(std::chrono::seconds(6)) >> [=] {
CAF_LOG_TRACE("");
CAF_TEST_ERROR("Unexpected timeout");
CAF_ERROR("Unexpected timeout");
self->quit(exit_reason::user_shutdown);
}
);
},
[=](const error& err) {
CAF_TEST_ERROR("Error: " << self->system().render(err));
CAF_ERROR("Error: " << self->system().render(err));
self->quit(exit_reason::user_shutdown);
},
after(chrono::seconds(10)) >> [=] {
CAF_LOG_TRACE("");
CAF_TEST_ERROR("Unexpected timeout");
CAF_ERROR("Unexpected timeout");
self->quit(exit_reason::user_shutdown);
}
);
......
......@@ -48,7 +48,7 @@ behavior client(event_based_actor* self, actor serv) {
self->send(serv, ok_atom::value);
return {
others >> [=] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
};
}
......@@ -90,7 +90,7 @@ behavior server(stateful_actor<server_state>* self) {
},
[=](const error& err) {
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) {
return std::make_tuple(ping_atom::value, value + 1);
},
others >> [=] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
});
},
others >> [=] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
};
}
......@@ -92,14 +92,14 @@ behavior pong(event_based_actor* self) {
self->quit(dm.reason);
},
others >> [=] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
);
// reply to 'ping'
return std::make_tuple(pong_atom::value, value);
},
others >> [=] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
};
}
......
......@@ -48,7 +48,7 @@ public:
behavior make_behavior() override {
return {
others >> [&] {
CAF_TEST_ERROR("Unexpected message");
CAF_ERROR("Unexpected message");
}
};
}
......
......@@ -132,6 +132,8 @@ public:
// constructs spacing given a line number.
const char* fill(size_t line);
void remove_trailing_spaces(std::string& x);
} // namespace detail
/// Logs messages for the test framework.
......@@ -175,12 +177,15 @@ public:
stream& operator<<(const std::string& str);
std::string str() const;
private:
void flush();
logger& logger_;
level level_;
std::ostringstream buf_;
std::string str_;
};
static bool init(int lvl_cons, int lvl_file, const std::string& logfile);
......@@ -377,24 +382,8 @@ showable<T> show(const T &x) {
return showable<T>{x};
}
inline 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;
}
bool check(test* parent, const char *file, size_t line,
const char *expr, bool should_fail, bool result);
template <class T, class U>
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
using caf_test_case_auto_fixture = caf::test::dummy_fixture;
#define CAF_TEST_PR(level, msg, colorcode) \
::caf::test::logger::instance(). level () \
#define CAF_TEST_PRINT(level, msg, colorcode) \
(::caf::test::logger::instance(). level () \
<< ::caf::test::engine::color(::caf::test:: colorcode ) \
<< " -> " << ::caf::test::engine::color(::caf::test::reset) << msg << '\n'
#define CAF_TEST_ERROR(msg) \
CAF_TEST_PR(info, msg, red)
<< " -> " << ::caf::test::engine::color(::caf::test::reset) << msg << '\n')
#define CAF_TEST_INFO(msg) \
CAF_TEST_PR(info, msg, yellow)
#define CAF_TEST_VERBOSE(msg) \
CAF_TEST_PR(verbose, msg, yellow)
#define CAF_TEST_PRINT_ERROR(msg) CAF_TEST_PRINT(info, msg, red)
#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_PASTE_CONCAT(lhs, rhs) lhs ## rhs
......@@ -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_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(...) \
do { \
static_cast<void>(::caf::test::detail::check( \
......@@ -502,7 +495,9 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
#define CAF_FAIL(msg) \
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"}; \
} while(false)
......@@ -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_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
......@@ -21,6 +21,7 @@
#define CAF_TEST_UNIT_TEST_IMPL_HPP
#include <regex>
#include <cctype>
#include <thread>
#include <cassert>
#include <cstdlib>
......@@ -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
logger::stream::stream(logger& l, level lvl) : logger_(l), level_(lvl) {
......@@ -183,12 +207,17 @@ logger::stream& logger::stream::operator<<(const std::string& str) {
return *this;
}
std::string logger::stream::str() const {
return str_;
}
void logger::stream::flush() {
logger_.log(level_, buf_.str());
auto str = buf_.str();
buf_.str("");
logger_.log(level_, str);
str_ += str;
}
bool logger::init(int lvl_cons, int lvl_file, const std::string& logfile) {
instance().level_console_ = static_cast<level>(lvl_cons);
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