Fix character issues in test_errors.cpp

parent c691769e
......@@ -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);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment