From 1d5b6d7ae6c062bc671cf032281efafc31e02fdb Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 12 Nov 2018 15:59:03 +0200 Subject: [PATCH] Added test of pattern_formatter::clone() --- tests/test_misc.cpp | 2 +- tests/test_pattern_formatter.cpp | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index f69a3487..f46410b5 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -92,7 +92,7 @@ TEST_CASE("periodic flush", "[periodic_flush]") spdlog::drop_all(); } -TEST_CASE("clone", "[clone]") +TEST_CASE("clone-logger", "[clone]") { using namespace spdlog; diff --git a/tests/test_pattern_formatter.cpp b/tests/test_pattern_formatter.cpp index a098ab26..edbb84ef 100644 --- a/tests/test_pattern_formatter.cpp +++ b/tests/test_pattern_formatter.cpp @@ -16,6 +16,7 @@ static std::string log_to_str(const std::string &msg, const Args &... args) return oss.str(); } + TEST_CASE("custom eol", "[pattern_formatter]") { std::string msg = "Hello custom eol test"; @@ -194,3 +195,35 @@ TEST_CASE("left_padded_max", "[pattern_formatter]") "[pattern_tester ]" " Some message\n"); } + + +TEST_CASE("clone-default-formatter", "[pattern_formatter]") +{ + auto formatter_1 = std::make_shared(); + auto formatter_2 = formatter_1->clone(); + std::string logger_name = "test"; + spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "some message"); + + fmt::memory_buffer formatted_1; + fmt::memory_buffer formatted_2; + formatter_1->format(msg, formatted_1); + formatter_2->format(msg, formatted_2); + + + REQUIRE( fmt::to_string(formatted_1) == fmt::to_string(formatted_2)); +} + + +TEST_CASE("clone-formatter", "[pattern_formatter]") +{ + auto formatter_1 = std::make_shared("%D %X [%] %v [%n] %v"); + auto formatter_2 = formatter_1->clone(); + std::string logger_name = "test"; + spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "some message"); + + fmt::memory_buffer formatted_1; + fmt::memory_buffer formatted_2; + formatter_1->format(msg, formatted_1); + formatter_2->format(msg, formatted_2); + REQUIRE(fmt::to_string(formatted_1) == fmt::to_string(formatted_2)); +}