~singpolyma/biboumi

ref: fdb3e739b0f1969e83250d98bda27b938a207f81 biboumi/tests/logger.cpp -rw-r--r-- 1.6 KiB
fdb3e739 — louiz’ Typos: negociat… -> negotiat… 1 year, 8 months ago
                                                                                
66887c22 Florent Le Coz
7e07a174 Florent Le Coz
66887c22 Florent Le Coz
6b245ee6 louiz’
5a2e6116 louiz’
66887c22 Florent Le Coz
7e07a174 Florent Le Coz
66887c22 Florent Le Coz
6b245ee6 louiz’
550ab46f louiz’
66887c22 Florent Le Coz
550ab46f louiz’
66887c22 Florent Le Coz
6b245ee6 louiz’
550ab46f louiz’
66887c22 Florent Le Coz
6b245ee6 louiz’
550ab46f louiz’
66887c22 Florent Le Coz
550ab46f louiz’
66887c22 Florent Le Coz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#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")
{
  const std::string debug_header = "[DEBUG]: ";
  const std::string error_header = "[ERROR]: ";
  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");
        }
    }
}