mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 10:01:33 +08:00
Updated tests
This commit is contained in:
parent
cdbf2e361b
commit
81fa788bca
@ -95,13 +95,6 @@
|
||||
// #define SPDLOG_FMT_EXTERNAL
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Uncomment to use printf-style messages in your logs instead of the usual
|
||||
// format-style used by default.
|
||||
//
|
||||
// #define SPDLOG_FMT_PRINTF
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Uncomment to enable wchar_t support (convert to utf8)
|
||||
//
|
||||
|
@ -1,5 +1,5 @@
|
||||
CXX ?= g++
|
||||
CXXFLAGS = -Wall -pedantic -std=c++11 -pthread -O3 -I../include
|
||||
CXXFLAGS = -Wall -pedantic -std=c++11 -pthread -O3 -I../include -fmax-errors=1
|
||||
LDPFALGS = -pthread
|
||||
|
||||
CPP_FILES := $(wildcard *.cpp)
|
||||
|
@ -11,7 +11,8 @@ static const std::string target_filename = "logs/file_helper_test.txt";
|
||||
static void write_with_helper(file_helper &helper, size_t howmany)
|
||||
{
|
||||
log_msg msg;
|
||||
msg.formatted << std::string(howmany, '1');
|
||||
|
||||
fmt::format_to(msg.formatted, "{}", std::string(howmany, '1'));
|
||||
helper.write(msg);
|
||||
helper.flush();
|
||||
}
|
||||
|
@ -85,8 +85,9 @@ TEST_CASE("daily_logger", "[daily_logger]]")
|
||||
// calculate filename (time based)
|
||||
std::string basename = "logs/daily_log";
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
fmt::MemoryWriter w;
|
||||
w.write("{}_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min);
|
||||
fmt::memory_buffer w;
|
||||
fmt::format_to(
|
||||
w, "{}_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min);
|
||||
|
||||
auto logger = spdlog::daily_logger_mt("logger", basename, 0, 0);
|
||||
logger->flush_on(spdlog::level::info);
|
||||
@ -95,7 +96,7 @@ TEST_CASE("daily_logger", "[daily_logger]]")
|
||||
logger->info("Test message {}", i);
|
||||
}
|
||||
|
||||
auto filename = w.str();
|
||||
auto filename = fmt::to_string(w);
|
||||
REQUIRE(count_lines(filename) == 10);
|
||||
}
|
||||
|
||||
@ -107,8 +108,8 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger_dateonly]]")
|
||||
// calculate filename (time based)
|
||||
std::string basename = "logs/daily_dateonly";
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
fmt::MemoryWriter w;
|
||||
w.write("{}_{:04d}-{:02d}-{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
fmt::memory_buffer w;
|
||||
fmt::format_to(w, "{}_{:04d}-{:02d}-{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
|
||||
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
@ -117,7 +118,7 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger_dateonly]]")
|
||||
logger->info("Test message {}", i);
|
||||
}
|
||||
logger->flush();
|
||||
auto filename = w.str();
|
||||
auto filename = fmt::to_string(w);
|
||||
REQUIRE(count_lines(filename) == 10);
|
||||
}
|
||||
|
||||
@ -126,9 +127,9 @@ struct custom_daily_file_name_calculator
|
||||
static spdlog::filename_t calc_filename(const spdlog::filename_t &basename)
|
||||
{
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
fmt::MemoryWriter w;
|
||||
w.write("{}{:04d}{:02d}{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
return w.str();
|
||||
fmt::memory_buffer w;
|
||||
fmt::format_to(w, "{}{:04d}{:02d}{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
return fmt::to_string(w);
|
||||
}
|
||||
};
|
||||
|
||||
@ -140,8 +141,8 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger_custom]]")
|
||||
// calculate filename (time based)
|
||||
std::string basename = "logs/daily_dateonly";
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
fmt::MemoryWriter w;
|
||||
w.write("{}{:04d}{:02d}{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
fmt::memory_buffer w;
|
||||
fmt::format_to(w, "{}{:04d}{:02d}{:02d}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
|
||||
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
@ -150,7 +151,7 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger_custom]]")
|
||||
}
|
||||
|
||||
logger->flush();
|
||||
auto filename = w.str();
|
||||
auto filename = fmt::to_string(w);
|
||||
REQUIRE(count_lines(filename) == 10);
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ TEST_CASE("color range test1", "[pattern_formatter]")
|
||||
{
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^%v%$", spdlog::pattern_time_type::local, "\n");
|
||||
spdlog::details::log_msg msg;
|
||||
msg.raw << "Hello";
|
||||
fmt::format_to(msg.raw, "Hello");
|
||||
formatter->format(msg);
|
||||
REQUIRE(msg.color_range_start == 0);
|
||||
REQUIRE(msg.color_range_end == 5);
|
||||
@ -98,7 +98,7 @@ TEST_CASE("color range test4", "[pattern_formatter]")
|
||||
{
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("XX%^YYY%$", spdlog::pattern_time_type::local, "\n");
|
||||
spdlog::details::log_msg msg;
|
||||
msg.raw << "ignored";
|
||||
fmt::format_to(msg.raw, "ignored");
|
||||
formatter->format(msg);
|
||||
REQUIRE(msg.color_range_start == 2);
|
||||
REQUIRE(msg.color_range_end == 5);
|
||||
|
Loading…
Reference in New Issue
Block a user