mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-24 06:32:06 +08:00
Fix character issues in test_errors.cpp
This commit is contained in:
parent
c691769e46
commit
f0a4ddd78b
@ -5,6 +5,9 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define SIMPLE_LOG "test_logs/simple_log.txt"
|
||||
#define SIMPLE_ASYNC_LOG "test_logs/simple_async_log.txt"
|
||||
|
||||
class failing_sink : public spdlog::sinks::base_sink<std::mutex>
|
||||
{
|
||||
protected:
|
||||
@ -22,7 +25,7 @@ protected:
|
||||
TEST_CASE("default_error_handler", "[errors]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
std::string filename = "test_logs/simple_log.txt";
|
||||
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
|
||||
|
||||
auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("test-error", filename, true);
|
||||
logger->set_pattern("%v");
|
||||
@ -31,8 +34,8 @@ TEST_CASE("default_error_handler", "[errors]]")
|
||||
logger->flush();
|
||||
|
||||
using spdlog::details::os::default_eol;
|
||||
REQUIRE(file_contents(filename) == fmt::format("Test message 2{}", default_eol));
|
||||
REQUIRE(count_lines(filename) == 1);
|
||||
REQUIRE(file_contents(SIMPLE_LOG) == fmt::format("Test message 2{}", default_eol));
|
||||
REQUIRE(count_lines(SIMPLE_LOG) == 1);
|
||||
}
|
||||
|
||||
struct custom_ex
|
||||
@ -40,7 +43,7 @@ struct custom_ex
|
||||
TEST_CASE("custom_error_handler", "[errors]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
std::string filename = "test_logs/simple_log.txt";
|
||||
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
|
||||
auto logger = spdlog::create<spdlog::sinks::basic_file_sink_mt>("logger", filename, true);
|
||||
logger->flush_on(spdlog::level::info);
|
||||
logger->set_error_handler([=](const std::string &) { throw custom_ex(); });
|
||||
@ -48,7 +51,7 @@ TEST_CASE("custom_error_handler", "[errors]]")
|
||||
|
||||
REQUIRE_THROWS_AS(logger->info("Bad format msg {} {}", "xxx"), custom_ex);
|
||||
logger->info("Good message #2");
|
||||
require_message_count(filename, 2);
|
||||
require_message_count(SIMPLE_LOG, 2);
|
||||
}
|
||||
|
||||
TEST_CASE("default_error_handler2", "[errors]]")
|
||||
@ -72,7 +75,7 @@ TEST_CASE("async_error_handler", "[errors]]")
|
||||
prepare_logdir();
|
||||
std::string err_msg("log failed with some msg");
|
||||
|
||||
std::string filename = "test_logs/simple_async_log.txt";
|
||||
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_ASYNC_LOG);
|
||||
{
|
||||
spdlog::init_thread_pool(128, 1);
|
||||
auto logger = spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("logger", filename, true);
|
||||
@ -90,7 +93,7 @@ TEST_CASE("async_error_handler", "[errors]]")
|
||||
spdlog::drop("logger"); // force logger to drain the queue and shutdown
|
||||
}
|
||||
spdlog::init_thread_pool(128, 1);
|
||||
require_message_count(filename, 2);
|
||||
require_message_count(SIMPLE_ASYNC_LOG, 2);
|
||||
REQUIRE(file_contents("test_logs/custom_err.txt") == err_msg);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user