From 18c43a214c8f67112678ae1053cb179972948b4c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 19 Dec 2023 13:46:48 -0800 Subject: [PATCH] Cleanup test --- test/format-test.cc | 19 ++++++++----------- test/util.h | 26 ++++++++++++++------------ 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/test/format-test.cc b/test/format-test.cc index d6802f79..a9dd41a2 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -499,20 +499,17 @@ TEST(format_test, arg_errors) { EXPECT_THROW_MSG((void)fmt::format(runtime("{00}"), 42), format_error, "invalid format string"); - char format_str[buffer_size]; - safe_sprintf(format_str, "{%u", INT_MAX); - EXPECT_THROW_MSG((void)fmt::format(runtime(format_str)), format_error, + auto int_max = std::to_string(INT_MAX); + EXPECT_THROW_MSG((void)fmt::format(runtime("{" + int_max)), format_error, "invalid format string"); - safe_sprintf(format_str, "{%u}", INT_MAX); - EXPECT_THROW_MSG((void)fmt::format(runtime(format_str)), format_error, - "argument not found"); + EXPECT_THROW_MSG((void)fmt::format(runtime("{" + int_max + "}")), + format_error, "argument not found"); - safe_sprintf(format_str, "{%u", INT_MAX + 1u); - EXPECT_THROW_MSG((void)fmt::format(runtime(format_str)), format_error, + auto int_maxer = std::to_string(INT_MAX + 1u); + EXPECT_THROW_MSG((void)fmt::format(runtime("{" + int_maxer)), format_error, "invalid format string"); - safe_sprintf(format_str, "{%u}", INT_MAX + 1u); - EXPECT_THROW_MSG((void)fmt::format(runtime(format_str)), format_error, - "argument not found"); + EXPECT_THROW_MSG((void)fmt::format(runtime("{" + int_maxer + "}")), + format_error, "argument not found"); } template struct test_format { diff --git a/test/util.h b/test/util.h index 9120e22e..803cdeea 100644 --- a/test/util.h +++ b/test/util.h @@ -29,9 +29,9 @@ void safe_sprintf(char (&buffer)[SIZE], const char* format, ...) { extern const char* const file_content; // Opens a buffered file for reading. -fmt::buffered_file open_buffered_file(FILE** fp = nullptr); +auto open_buffered_file(FILE** fp = nullptr) -> fmt::buffered_file; -inline FILE* safe_fopen(const char* filename, const char* mode) { +inline auto safe_fopen(const char* filename, const char* mode) -> FILE* { #if defined(_WIN32) && !defined(__MINGW32__) // Fix MSVC warning about "unsafe" fopen. FILE* f = nullptr; @@ -51,17 +51,17 @@ template class basic_test_string { public: explicit basic_test_string(const Char* value = empty) : value_(value) {} - const std::basic_string& value() const { return value_; } + auto value() const -> const std::basic_string& { return value_; } }; template const Char basic_test_string::empty[] = {0}; -typedef basic_test_string test_string; -typedef basic_test_string test_wstring; +using test_string = basic_test_string; +using test_wstring = basic_test_string; template -std::basic_ostream& operator<<(std::basic_ostream& os, - const basic_test_string& s) { +auto operator<<(std::basic_ostream& os, const basic_test_string& s) + -> std::basic_ostream& { os << s.value(); return os; } @@ -72,10 +72,12 @@ class date { public: date(int year, int month, int day) : year_(year), month_(month), day_(day) {} - int year() const { return year_; } - int month() const { return month_; } - int day() const { return day_; } + auto year() const -> int { return year_; } + auto month() const -> int { return month_; } + auto day() const -> int { return day_; } }; -// Returns a locale with the given name if available or classic locale otherwise. -std::locale get_locale(const char* name, const char* alt_name = nullptr); +// Returns a locale with the given name if available or classic locale +// otherwise. +auto get_locale(const char* name, const char* alt_name = nullptr) + -> std::locale;