0066ad2d38
9e554999c Update version b34d92b05 Bump version d39ece187 Make rst2md runnable and update changelog fe2d715ff Update changelog 27b306701 Update changelog 68837079a Update changelog c98b202eb Update changelog 587a7f663 Update changelog and docs 84e5170c9 Update changelog and deprecate visit 130e412b6 Update changelog and docs 0bbdca5b8 Fix conversion warnings (#989) 77a724480 Implement fill/align/width for strftime-like formatting 3e01376e0 Implement fill/align/width parsing in chrono formatter 1f92f8a9d Remove noexcept 8668639ae Get rid of null_terminating_iterator in format 93fd473b8 Add support for builtin terminal colors. (#974) 61ad543c3 Windows .sln filename changed from FORMAT to FMT 7f7504b3f Clean up docs 37f599b1a Fix docs 8c2e15aed Make printf work in search (#164) de71db6d4 Fix asan error (#977) b180b3915 Fix default formatting 24594c747 Disable printing the reset escape code when no style modifiers where applied. (#973) b0f222471 Implement default chrono formatting 749276072 Add file stream support for stylized text printing. (#967) f54f3d0fb Move chrono-specific code to a separate header bf1f1c73e Fix time test b6bc6ec24 Add default ctor and fix use of constexpr macros in text_style acfa95d4a Workaround a bug in MSVC's strftime (#965) 628f83058 More chrono formatting aa3b5aba4 Implement locale-specific minute formatting 639de2175 Workaround more MSVC bugs 3242ddf7b Fix warnings bd1104046 Workaround a bug in MSVC 81b5c4a5f Add experimental emphasis support (#961) 7c4eb0fbe Fix warnings in time.h 2d624218b Fix another warning b31680990 Fix a warning b10ccb83e Add rpclib to projects 0497875ff Stop the orgy of casts 37dc495b9 Simplify MSVC workaround 2ff4996d0 Fix ambiguous complier error C2666 in vs2017.The '+' opeator may cause ambiguity.Avoid implicit conversion. 77656c672 Fix sign-conversion warnings reported by Clang7 ea5e4790b Fix formatting 86681c4bb Update README.rst e867768ee Do not override user provided compile flag 0c7f5c3ca Update README.rst e7e2ab107 Make return type of basic_format_args::max_size() consistent. 29352af36 Update README.rst 68214bd90 More time formatting bcf3fcd67 Clean up bit fiddling for argument packing 9dcf127fa Workaround a bogus MSVC warning b8b06e3e1 Fix conversion warnings in Grisu 322b2594e Implement more time specifiers 0835f1ba3 Use full paths for fmt.pc.in a084495d7 Add Ceph to projects fa1d4dbcf Fix warnings 2b2cfdac1 Update docs 99744f8f8 Suppress unfixable warning f5fe84923 Specialize formatter for chrono durations a5a9805a9 First stub at the datetime format parser 645c76a9a Fix dummy warnings fecb2d6f0 Eliminate msvc compiler warnings (#931) 64690d3a9 Add context_base::arg() 01640f44c Fully qualify dummy_int (#941) e37d6a984 add make_printf_args and make_wprintf_args functions (#934) 982ee5c69 parse_context -> format_parse_context b7b854855 thousands_sep -> thousands_sep_impl (#939) 00a8cc832 Fix formatting 33fbb3a7e Fix remaining linker errors. bd6121596 Disable fmt-impl-test in windows + shared lib. 702b3d161 Fix link error in windows with shared library. 9d4ef9435 Install pdb files. 6c95fb356 Default Context to format_context 16b78ee62 fix incompatibilities with c++2a mode in clang 19e008876 More locale support f2ee98810 Improve locale support 1385050e2 More formatter tests 03c1b110a Fix gcc 4.4 build cc805c616 Test enabled formatters e01579231 Disallow leading zeros in arg-id 34030deca Cleanup warning flags 6b26e3f2d Manifest & Gradle comment d286c9775 Update for Gradle build d951f6dfe Get latest Gradle (ver. 4.10.2) a23d59247 Fix check_format_string (#925) 36161284e Update docs 38f355d87 Revert "find sphinx-build before calling build.py" 324eac1aa Make locales work with any character type bdda4d603 Simplify compile-time strings 5ee1a4bc8 check for property 'mutable iterator' and SFINAE on it 2dea780fb change type naming and fix sfinae bug b98e8301d add non-char support for compile-time format check ccd3e8bbf Make is_constructible public (#918) 437315380 Update usage.rst 73cfd8f32 Fix colored print ec384302d additional test for print with background color 0a96c032b Parameterize v*printf on string type (#920) 61e6d2e38 Fix core version of vformat_to ea4010d70 Merge has_to_string_view into is_string 486fff597 Add sprintf_format instantiations and remove syntactic noise 1e3dcbba8 fix: 'format_to_n' compiles 'std::back_inserter' arguments f0328f8e3 Use char_traits::length in string_view ctor (#914) 895fb9845 Disallow gcc 4.4 failures 20c708bf6 Fix build on gcc 4.4 9d0c9c4bb cmake: output share/fmt.pc 2d2326a76 Fix compilation with older gcc 1ec027230 Get rid of FMT_UNION 2c81c851b Adapt any string-like type to be used by {fmt} just like the standard string types already supported. The adaption is totally non-intrusive. 846c644e8 Workeround broken sprintf in MSVC 13d472bd8 Compute output size for grisu b71d3fe7a Remove use_grisu 847abb6f8 Fix test dda47c946 Merge min_digits and max_digits 292462215 Fix naming of basic_format_specs members bda5f9a55 Replace grisu2_specs with core_format_specs b1ca608ba Remove unused empty_spec e8efdef8d Avoid extra copy 98f1c1fe8 Remove unused code 50b18a3c1 Integrate Grisu 699297520 Implement Grisu rounding 4bb76ef0c Remove redundant definition of print ddd7caf38 Fix locale-dependent formatting (#905) 10e03e695 use found python executable for launching sphinx-build 07200f445 find sphinx-build before calling build.py 08a65c228 Workaround broken constexpr in MSVC2017 167f8fe32 Fix a typo in api.rst 57983423c Remove signbit workaround 7bebb3e12 Clarify overload resolution in docs 939fbe556 Remove basic_fixed_buffer. 61f81a071 minor documentation corrections f27defc63 Parameterize printf functions on the type of the format string. 6a685571d Make 'std::*::basic_string_view' a valid argument type for 'format_str' parameters. 87a0408c6 Fix ostream.h build 2b5acad4a Remove redundant size argument to write_padded 655ce5338 is_format_string -> is_string fea712abb Parameterize ostream functions on the type of the format string. f16a118e8 Fix non-matching char types. 041bf83d9 Improve fmt::format readability 229903239 Document how to write a formatter for a type hierarchy f5480635c visit -> visit_format_arg cdf3fa08d Put related code together in fmt/core.h 38325248e Count width in code points (#628) deb901b9e Parameterize core functions on the type of the format string. 0f98de301 Update docs c797708fc Workaround strlen being non-constexpr in ARM toolchain 49b4c1e9d Update docs 63a87beba Add to_string_view 4e0c31465 checked_format_args -> checked_args c3538a1ee Simplify variadic functions further 2d7d0835d Simplify variadic functions 3f4cfa6c6 Implement UTF-8 string support f8027414f Impelement char8_t support 76a47d41c Cleanup the use of FMT_CHAR 267fdc7a1 Parameterize core functions on the type of the format string. 5bced1242 Parameterize more functions on string type 674999c52 fix vs2017 warning fmt::v5::localtime 'not all control paths return a value'. e4fea22d1 Make char8_t a strongly-typed enum 66992e90d Clarify that writing to memory_buffer appends (#877) e864acfdb Fix compilation with intel compilers (ICC/ICPC) v14.0 4cf21f58b constrain templated format_to on proper format string type. d7f17613f Fix compilation on platforms with exotic double (#878) e4ca37ccf Parameterize format_to on string type (#880) d66fa2216 Reduce syntactic noise 48e6dcd0f Implement workarounds for gcc 4.4 0ea3221d3 Remove is_named_arg and add FMT_CHAR 73c53d783 Parameterize 'printf(rgb color, ...)' and 'vprint_rgb(rgb color, ...)' on the type of the format string. d41be23ac Simplify string_view detection 2def9e4c8 Remove FMT_DTOR_NOEXCEPT ff6e46ed9 More cleanup 715f2b4c0 Remove require_wchar and internalize no_formatter_error ec0cdc46f Workaround Windows slowness git-subtree-dir: externals/fmt git-subtree-split: 9e554999ce02cf86fcdfe74fe740c4fe3f5a56d5
161 lines
5.4 KiB
C++
161 lines
5.4 KiB
C++
// Formatting library for C++ - custom Google Test assertions
|
|
//
|
|
// Copyright (c) 2012 - present, Victor Zverovich
|
|
// All rights reserved.
|
|
//
|
|
// For the license information refer to format.h.
|
|
|
|
#ifndef FMT_GTEST_EXTRA_H_
|
|
#define FMT_GTEST_EXTRA_H_
|
|
|
|
#include <string>
|
|
#include "gmock.h"
|
|
|
|
#include "fmt/core.h"
|
|
|
|
#ifndef FMT_USE_FILE_DESCRIPTORS
|
|
# define FMT_USE_FILE_DESCRIPTORS 0
|
|
#endif
|
|
|
|
#if FMT_USE_FILE_DESCRIPTORS
|
|
# include "fmt/posix.h"
|
|
#endif
|
|
|
|
#define FMT_TEST_THROW_(statement, expected_exception, expected_message, fail) \
|
|
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
|
if (::testing::AssertionResult gtest_ar = ::testing::AssertionSuccess()) { \
|
|
std::string gtest_expected_message = expected_message; \
|
|
bool gtest_caught_expected = false; \
|
|
try { \
|
|
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
|
} \
|
|
catch (expected_exception const& e) { \
|
|
if (gtest_expected_message != e.what()) { \
|
|
gtest_ar \
|
|
<< #statement " throws an exception with a different message.\n" \
|
|
<< "Expected: " << gtest_expected_message << "\n" \
|
|
<< " Actual: " << e.what(); \
|
|
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
|
} \
|
|
gtest_caught_expected = true; \
|
|
} \
|
|
catch (...) { \
|
|
gtest_ar << \
|
|
"Expected: " #statement " throws an exception of type " \
|
|
#expected_exception ".\n Actual: it throws a different type."; \
|
|
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
|
} \
|
|
if (!gtest_caught_expected) { \
|
|
gtest_ar << \
|
|
"Expected: " #statement " throws an exception of type " \
|
|
#expected_exception ".\n Actual: it throws nothing."; \
|
|
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
|
} \
|
|
} else \
|
|
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
|
|
fail(gtest_ar.failure_message())
|
|
|
|
// Tests that the statement throws the expected exception and the exception's
|
|
// what() method returns expected message.
|
|
#define EXPECT_THROW_MSG(statement, expected_exception, expected_message) \
|
|
FMT_TEST_THROW_(statement, expected_exception, \
|
|
expected_message, GTEST_NONFATAL_FAILURE_)
|
|
|
|
std::string format_system_error(int error_code, fmt::string_view message);
|
|
|
|
#define EXPECT_SYSTEM_ERROR(statement, error_code, message) \
|
|
EXPECT_THROW_MSG(statement, fmt::system_error, \
|
|
format_system_error(error_code, message))
|
|
|
|
#if FMT_USE_FILE_DESCRIPTORS
|
|
|
|
// Captures file output by redirecting it to a pipe.
|
|
// The output it can handle is limited by the pipe capacity.
|
|
class OutputRedirect {
|
|
private:
|
|
FILE *file_;
|
|
fmt::file original_; // Original file passed to redirector.
|
|
fmt::file read_end_; // Read end of the pipe where the output is redirected.
|
|
|
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(OutputRedirect);
|
|
|
|
void flush();
|
|
void restore();
|
|
|
|
public:
|
|
explicit OutputRedirect(FILE *file);
|
|
~OutputRedirect() FMT_NOEXCEPT;
|
|
|
|
// Restores the original file, reads output from the pipe into a string
|
|
// and returns it.
|
|
std::string restore_and_read();
|
|
};
|
|
|
|
#define FMT_TEST_WRITE_(statement, expected_output, file, fail) \
|
|
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
|
if (::testing::AssertionResult gtest_ar = ::testing::AssertionSuccess()) { \
|
|
std::string gtest_expected_output = expected_output; \
|
|
OutputRedirect gtest_redir(file); \
|
|
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
|
std::string gtest_output = gtest_redir.restore_and_read(); \
|
|
if (gtest_output != gtest_expected_output) { \
|
|
gtest_ar \
|
|
<< #statement " produces different output.\n" \
|
|
<< "Expected: " << gtest_expected_output << "\n" \
|
|
<< " Actual: " << gtest_output; \
|
|
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
|
} \
|
|
} else \
|
|
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
|
|
fail(gtest_ar.failure_message())
|
|
|
|
// Tests that the statement writes the expected output to file.
|
|
#define EXPECT_WRITE(file, statement, expected_output) \
|
|
FMT_TEST_WRITE_(statement, expected_output, file, GTEST_NONFATAL_FAILURE_)
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
// Suppresses Windows assertions on invalid file descriptors, making
|
|
// POSIX functions return proper error codes instead of crashing on Windows.
|
|
class SuppressAssert {
|
|
private:
|
|
_invalid_parameter_handler original_handler_;
|
|
int original_report_mode_;
|
|
|
|
static void handle_invalid_parameter(const wchar_t *,
|
|
const wchar_t *, const wchar_t *, unsigned , uintptr_t) {}
|
|
|
|
public:
|
|
SuppressAssert()
|
|
: original_handler_(_set_invalid_parameter_handler(handle_invalid_parameter)),
|
|
original_report_mode_(_CrtSetReportMode(_CRT_ASSERT, 0)) {
|
|
}
|
|
~SuppressAssert() {
|
|
_set_invalid_parameter_handler(original_handler_);
|
|
_CrtSetReportMode(_CRT_ASSERT, original_report_mode_);
|
|
}
|
|
};
|
|
|
|
# define SUPPRESS_ASSERT(statement) { SuppressAssert sa; statement; }
|
|
#else
|
|
# define SUPPRESS_ASSERT(statement) statement
|
|
#endif // _MSC_VER
|
|
|
|
#define EXPECT_SYSTEM_ERROR_NOASSERT(statement, error_code, message) \
|
|
EXPECT_SYSTEM_ERROR(SUPPRESS_ASSERT(statement), error_code, message)
|
|
|
|
// Attempts to read count characters from a file.
|
|
std::string read(fmt::file &f, std::size_t count);
|
|
|
|
#define EXPECT_READ(file, expected_content) \
|
|
EXPECT_EQ(expected_content, read(file, std::strlen(expected_content)))
|
|
|
|
#endif // FMT_USE_FILE_DESCRIPTORS
|
|
|
|
template <typename Mock>
|
|
struct ScopedMock : testing::StrictMock<Mock> {
|
|
ScopedMock() { Mock::instance = this; }
|
|
~ScopedMock() { Mock::instance = FMT_NULL; }
|
|
};
|
|
|
|
#endif // FMT_GTEST_EXTRA_H_
|