From 81fa788bca225221450aab8edc5ea412b0ac4613 Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 12 Jun 2018 22:43:49 +0300 Subject: [PATCH] Updated tests --- include/spdlog/tweakme.h | 7 ------- tests/Makefile | 2 +- tests/file_helper.cpp | 3 ++- tests/file_log.cpp | 25 +++++++++++++------------ tests/test_pattern_formatter.cpp | 4 ++-- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/include/spdlog/tweakme.h b/include/spdlog/tweakme.h index ecc106d1..65c564e7 100644 --- a/include/spdlog/tweakme.h +++ b/include/spdlog/tweakme.h @@ -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) // diff --git a/tests/Makefile b/tests/Makefile index c238331a..00c7c589 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -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) diff --git a/tests/file_helper.cpp b/tests/file_helper.cpp index 931c3f3e..9ef8f26a 100644 --- a/tests/file_helper.cpp +++ b/tests/file_helper.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(); } diff --git a/tests/file_log.cpp b/tests/file_log.cpp index 3c4f22c5..9cef256d 100644 --- a/tests/file_log.cpp +++ b/tests/file_log.cpp @@ -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("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("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); } diff --git a/tests/test_pattern_formatter.cpp b/tests/test_pattern_formatter.cpp index c6700041..b9a17aea 100644 --- a/tests/test_pattern_formatter.cpp +++ b/tests/test_pattern_formatter.cpp @@ -68,7 +68,7 @@ TEST_CASE("color range test1", "[pattern_formatter]") { auto formatter = std::make_shared("%^%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("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);