1
2#include "includes.h"
3
4template<class T>
5std::string log_info(const T& what, spdlog::level::level_enum logger_level = spdlog::level::info)
6{
7
8    std::ostringstream oss;
9    auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
10
11    spdlog::logger oss_logger("oss", oss_sink);
12    oss_logger.set_level(logger_level);
13    oss_logger.set_pattern("%v");
14    oss_logger.info(what);
15
16    return oss.str().substr(0, oss.str().length() - spdlog::details::os::eol_size);
17}
18
19
20
21
22
23
24TEST_CASE("basic_logging ", "[basic_logging]")
25{
26    //const char
27    REQUIRE(log_info("Hello") == "Hello");
28    REQUIRE(log_info("") == "");
29
30    //std::string
31    REQUIRE(log_info(std::string("Hello")) == "Hello");
32    REQUIRE(log_info(std::string()) == std::string());
33
34    //Numbers
35    REQUIRE(log_info(5) == "5");
36    REQUIRE(log_info(5.6) == "5.6");
37
38    //User defined class
39    //REQUIRE(log_info(some_logged_class("some_val")) == "some_val");
40}
41
42
43TEST_CASE("log_levels", "[log_levels]")
44{
45    REQUIRE(log_info("Hello", spdlog::level::err) == "");
46    REQUIRE(log_info("Hello", spdlog::level::critical) == "");
47    REQUIRE(log_info("Hello", spdlog::level::info) == "Hello");
48    REQUIRE(log_info("Hello", spdlog::level::debug) == "Hello");
49    REQUIRE(log_info("Hello", spdlog::level::trace) == "Hello");
50}
51
52
53
54
55
56
57