From 6c5bbca0c1e5e716e13781674e8a8fe3250d0f38 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 25 Aug 2018 18:10:42 +0300 Subject: [PATCH] Added clone tests --- README.md | 2 +- tests/test_misc.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b79812a3..0bf357b7 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ void daily_example() ``` --- -#### Cloning loggers +#### Cloning loggers ```c++ // clone a logger and give it new name. // Useful for creating subsystem loggers from some "root" logger diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index 2de4fb26..7bdfa881 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -91,3 +91,48 @@ TEST_CASE("periodic flush", "[periodic_flush]") spdlog::flush_every(std::chrono::seconds(0)); spdlog::drop_all(); } + + +TEST_CASE("clone", "[clone]") +{ + using namespace spdlog; + + auto logger = spdlog::create("orig"); + auto cloned = logger->clone("clone"); + + REQUIRE(cloned->name() == "clone"); + REQUIRE(logger->sinks() == cloned->sinks()); + REQUIRE(logger->level() == cloned->level()); + REQUIRE(logger->flush_level() == cloned->flush_level()); + logger->info("Some message 1"); + cloned->info("Some message 2"); + + auto test_sink = std::static_pointer_cast(cloned->sinks()[0]); + REQUIRE(test_sink->msg_counter() == 2); + + spdlog::drop_all(); +} + +TEST_CASE("clone async", "[clone]") +{ + using namespace spdlog; + + auto logger = spdlog::create_async("orig"); + auto cloned = logger->clone("clone"); + + REQUIRE(cloned->name() == "clone"); + REQUIRE(logger->sinks() == cloned->sinks()); + REQUIRE(logger->level() == cloned->level()); + REQUIRE(logger->flush_level() == cloned->flush_level()); + + logger->info("Some message 1"); + cloned->info("Some message 2"); + + spdlog::details::os::sleep_for_millis(10); + + auto test_sink = std::static_pointer_cast(cloned->sinks()[0]); + REQUIRE(test_sink->msg_counter() == 2); + + + spdlog::drop_all(); +}