Fix the logger test when built without systemd
This commit is contained in:
+10
-3
@@ -10,6 +10,13 @@ using namespace std::string_literals;
|
|||||||
|
|
||||||
TEST_CASE("Basic logging")
|
TEST_CASE("Basic logging")
|
||||||
{
|
{
|
||||||
|
#ifdef SYSTEMD_FOUND
|
||||||
|
const std::string debug_header = "<7>";
|
||||||
|
const std::string error_header = "<3>";
|
||||||
|
#else
|
||||||
|
const std::string debug_header = "[DEBUG]: ";
|
||||||
|
const std::string error_header = "[ERROR]: ";
|
||||||
|
#endif
|
||||||
Logger::instance().reset();
|
Logger::instance().reset();
|
||||||
GIVEN("A logger with log_level 0")
|
GIVEN("A logger with log_level 0")
|
||||||
{
|
{
|
||||||
@@ -19,14 +26,14 @@ TEST_CASE("Basic logging")
|
|||||||
IoTester<std::ostream> out(std::cout);
|
IoTester<std::ostream> out(std::cout);
|
||||||
log_debug("debug");
|
log_debug("debug");
|
||||||
THEN("debug logs are written")
|
THEN("debug logs are written")
|
||||||
CHECK(out.str() == "<7>tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\tdebug\n");
|
CHECK(out.str() == debug_header + "tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\tdebug\n");
|
||||||
}
|
}
|
||||||
WHEN("we log some errors")
|
WHEN("we log some errors")
|
||||||
{
|
{
|
||||||
IoTester<std::ostream> out(std::cout);
|
IoTester<std::ostream> out(std::cout);
|
||||||
log_error("error");
|
log_error("error");
|
||||||
THEN("error logs are written")
|
THEN("error logs are written")
|
||||||
CHECK(out.str() == "<3>tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\terror\n");
|
CHECK(out.str() == error_header + "tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\terror\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GIVEN("A logger with log_level 3")
|
GIVEN("A logger with log_level 3")
|
||||||
@@ -44,7 +51,7 @@ TEST_CASE("Basic logging")
|
|||||||
IoTester<std::ostream> out(std::cout);
|
IoTester<std::ostream> out(std::cout);
|
||||||
log_error("error");
|
log_error("error");
|
||||||
THEN("error logs are still written")
|
THEN("error logs are still written")
|
||||||
CHECK(out.str() == "<3>tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\terror\n");
|
CHECK(out.str() == error_header + "tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\terror\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user