diff options
author | Vasudev Kamath <vasudev@copyninja.info> | 2016-10-23 21:09:40 +0530 |
---|---|---|
committer | Vasudev Kamath <vasudev@copyninja.info> | 2016-10-23 21:09:40 +0530 |
commit | eda4b75b1cff83336e87da90efca9fd6b4ced2c7 (patch) | |
tree | 491317ce50b5d19bc434ccc4b448d1bc70520177 /tests/logger.cpp | |
parent | 716c40e4ec45f8d538695225f4f06d541d959084 (diff) | |
parent | 0f14fe83ef53b08bd8fa09670c82f4996c329bdc (diff) | |
download | biboumi-eda4b75b1cff83336e87da90efca9fd6b4ced2c7.tar.gz biboumi-eda4b75b1cff83336e87da90efca9fd6b4ced2c7.tar.bz2 biboumi-eda4b75b1cff83336e87da90efca9fd6b4ced2c7.tar.xz biboumi-eda4b75b1cff83336e87da90efca9fd6b4ced2c7.zip |
New upstream version 3.0upstream/3.0
Diffstat (limited to 'tests/logger.cpp')
-rw-r--r-- | tests/logger.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/logger.cpp b/tests/logger.cpp new file mode 100644 index 0000000..1d59a22 --- /dev/null +++ b/tests/logger.cpp @@ -0,0 +1,57 @@ +#include "catch.hpp" + +#include <logger/logger.hpp> +#include <config/config.hpp> + +#include "io_tester.hpp" +#include <iostream> + +using namespace std::string_literals; + +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(); + GIVEN("A logger with log_level 0") + { + Config::set("log_level", "0"); + WHEN("we log some debug text") + { + IoTester<std::ostream> out(std::cout); + log_debug("deb", "ug"); + THEN("debug logs are written") + CHECK(out.str() == debug_header + "tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\tdebug\n"); + } + WHEN("we log some errors") + { + IoTester<std::ostream> out(std::cout); + log_error("err", 12, "or"); + THEN("error logs are written") + CHECK(out.str() == error_header + "tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\terr12or\n"); + } + } + GIVEN("A logger with log_level 3") + { + Config::set("log_level", "3"); + WHEN("we log some debug text") + { + IoTester<std::ostream> out(std::cout); + log_debug(123, "debug"); + THEN("nothing is written") + CHECK(out.str().empty()); + } + WHEN("we log some errors") + { + IoTester<std::ostream> out(std::cout); + log_error(123, " errors"); + THEN("error logs are still written") + CHECK(out.str() == error_header + "tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\t123 errors\n"); + } + } +} |