summaryrefslogtreecommitdiff
path: root/tests/logger.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/logger.cpp')
-rw-r--r--tests/logger.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/logger.cpp b/tests/logger.cpp
new file mode 100644
index 0000000..d4fb055
--- /dev/null
+++ b/tests/logger.cpp
@@ -0,0 +1,50 @@
+#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")
+{
+ 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("debug");
+ THEN("debug logs are written")
+ CHECK(out.str() == "<7>tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\tdebug\n");
+ }
+ WHEN("we log some errors")
+ {
+ IoTester<std::ostream> out(std::cout);
+ log_error("error");
+ THEN("error logs are written")
+ CHECK(out.str() == "<3>tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\terror\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("debug");
+ THEN("nothing is written")
+ CHECK(out.str().empty());
+ }
+ WHEN("we log some errors")
+ {
+ IoTester<std::ostream> out(std::cout);
+ log_error("error");
+ THEN("error logs are still written")
+ CHECK(out.str() == "<3>tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\terror\n");
+ }
+ }
+}