Cleanup tests
This commit is contained in:
parent
c9c0e5077d
commit
38127d9ec0
@ -1,8 +1,5 @@
|
||||
add_subdirectory(gtest)
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Build the actual library tests
|
||||
|
||||
set(TEST_MAIN_SRC test-main.cc gtest-extra.cc gtest-extra.h util.cc)
|
||||
add_library(test-main STATIC ${TEST_MAIN_SRC})
|
||||
target_link_libraries(test-main gtest fmt)
|
||||
@ -32,8 +29,19 @@ endfunction()
|
||||
# Adds a test.
|
||||
# Usage: add_fmt_test(name srcs...)
|
||||
function(add_fmt_test name)
|
||||
add_fmt_executable(${name} ${name}.cc ${ARGN})
|
||||
target_link_libraries(${name} test-main)
|
||||
cmake_parse_arguments(ADD_FMT_TEST "HEADER_ONLY" "" "" ${ARGN})
|
||||
|
||||
set(sources ${name}.cc ${ADD_FMT_TEST_UNPARSED_ARGUMENTS})
|
||||
set(libs test-main)
|
||||
if (ADD_FMT_TEST_HEADER_ONLY)
|
||||
set(sources ${sources} ${TEST_MAIN_SRC} ../src/os.cc)
|
||||
set(libs gtest fmt-header-only)
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wno-weak-vtables)
|
||||
endif ()
|
||||
endif ()
|
||||
add_fmt_executable(${name} ${sources})
|
||||
target_link_libraries(${name} ${libs})
|
||||
|
||||
# Define if certain C++ features can be used.
|
||||
if (FMT_PEDANTIC)
|
||||
@ -56,7 +64,7 @@ if (MSVC)
|
||||
target_compile_options(format-test PRIVATE /bigobj)
|
||||
endif ()
|
||||
if (NOT (MSVC AND BUILD_SHARED_LIBS))
|
||||
add_fmt_test(format-impl-test)
|
||||
add_fmt_test(format-impl-test HEADER_ONLY)
|
||||
endif ()
|
||||
add_fmt_test(locale-test)
|
||||
add_fmt_test(ostream-test)
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "fmt/chrono.h"
|
||||
|
||||
#include "gtest-extra.h"
|
||||
#include "gtest-extra.h" // EXPECT_THROW_MSG
|
||||
|
||||
auto make_tm() -> std::tm {
|
||||
auto time = std::tm();
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#include <iterator> // std::back_inserter
|
||||
|
||||
#include "gtest-extra.h"
|
||||
#include "gtest-extra.h" // EXPECT_WRITE
|
||||
|
||||
TEST(color_test, format) {
|
||||
EXPECT_EQ(fmt::format(fg(fmt::rgb(255, 20, 30)), "rgb(255,20,30)"),
|
||||
|
@ -5,11 +5,8 @@
|
||||
//
|
||||
// For the license information refer to format.h.
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <iterator>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "fmt/chrono.h"
|
||||
#include "fmt/color.h"
|
||||
@ -27,7 +24,7 @@ void test_format_api() {
|
||||
fmt::to_string(42);
|
||||
fmt::to_wstring(42);
|
||||
|
||||
std::list<char> out;
|
||||
std::vector<char> out;
|
||||
fmt::format_to(std::back_inserter(out), FMT_STRING("{}"), 42);
|
||||
|
||||
char buffer[4];
|
||||
@ -53,7 +50,7 @@ void test_text_style() {
|
||||
}
|
||||
|
||||
void test_range() {
|
||||
std::array<char, 5> hello = {'h', 'e', 'l', 'l', 'o'};
|
||||
std::vector<char> hello = {'h', 'e', 'l', 'l', 'o'};
|
||||
fmt::format(FMT_STRING("{}"), hello);
|
||||
}
|
||||
|
||||
|
@ -8,18 +8,14 @@
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
// clang-format off
|
||||
#include "test-assert.h"
|
||||
// clang-format on
|
||||
|
||||
// Use the header-only mode to test the implementation.
|
||||
#include "../src/format.cc"
|
||||
#include "fmt/format.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest-extra.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
using fmt::detail::bigint;
|
||||
using fmt::detail::fp;
|
||||
using fmt::detail::max_value;
|
||||
@ -308,7 +304,7 @@ TEST(fp_test, grisu_format_compiles_with_on_ieee_double) {
|
||||
format_float(0.42, -1, fmt::detail::float_specs(), buf);
|
||||
}
|
||||
|
||||
TEST(FormatTest, StrError) {
|
||||
TEST(format_impl_test, strerror) {
|
||||
char* message = nullptr;
|
||||
char buffer[BUFFER_SIZE];
|
||||
EXPECT_ASSERT(fmt::detail::safe_strerror(EDOM, message = nullptr, 0),
|
||||
@ -343,7 +339,7 @@ TEST(FormatTest, StrError) {
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(FormatTest, FormatErrorCode) {
|
||||
TEST(format_impl_test, format_error_code) {
|
||||
std::string msg = "error 42", sep = ": ";
|
||||
{
|
||||
fmt::memory_buffer buffer;
|
||||
@ -353,8 +349,8 @@ TEST(FormatTest, FormatErrorCode) {
|
||||
}
|
||||
{
|
||||
fmt::memory_buffer buffer;
|
||||
std::string prefix(fmt::inline_buffer_size - msg.size() - sep.size() + 1,
|
||||
'x');
|
||||
auto prefix =
|
||||
std::string(fmt::inline_buffer_size - msg.size() - sep.size() + 1, 'x');
|
||||
fmt::detail::format_error_code(buffer, 42, prefix);
|
||||
EXPECT_EQ(msg, to_string(buffer));
|
||||
}
|
||||
@ -363,7 +359,8 @@ TEST(FormatTest, FormatErrorCode) {
|
||||
// Test maximum buffer size.
|
||||
msg = fmt::format("error {}", codes[i]);
|
||||
fmt::memory_buffer buffer;
|
||||
std::string prefix(fmt::inline_buffer_size - msg.size() - sep.size(), 'x');
|
||||
auto prefix =
|
||||
std::string(fmt::inline_buffer_size - msg.size() - sep.size(), 'x');
|
||||
fmt::detail::format_error_code(buffer, codes[i], prefix);
|
||||
EXPECT_EQ(prefix + sep + msg, to_string(buffer));
|
||||
size_t size = fmt::inline_buffer_size;
|
||||
@ -376,7 +373,7 @@ TEST(FormatTest, FormatErrorCode) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(FormatTest, ComputeWidth) {
|
||||
TEST(format_impl_test, compute_width) {
|
||||
EXPECT_EQ(4,
|
||||
fmt::detail::compute_width(
|
||||
fmt::basic_string_view<fmt::detail::char8_type>(
|
||||
@ -393,12 +390,12 @@ template <typename Int> void test_count_digits() {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UtilTest, CountDigits) {
|
||||
TEST(format_impl_test, count_digits) {
|
||||
test_count_digits<uint32_t>();
|
||||
test_count_digits<uint64_t>();
|
||||
}
|
||||
|
||||
TEST(UtilTest, WriteFallbackUIntPtr) {
|
||||
TEST(format_impl_test, write_fallback_uintptr) {
|
||||
std::string s;
|
||||
fmt::detail::write_ptr<char>(
|
||||
std::back_inserter(s),
|
||||
@ -407,7 +404,11 @@ TEST(UtilTest, WriteFallbackUIntPtr) {
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
TEST(UtilTest, WriteConsoleSignature) {
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
TEST(format_impl_test, write_console_signature) {
|
||||
decltype(WriteConsoleW)* p = fmt::detail::WriteConsoleW;
|
||||
(void)p;
|
||||
}
|
||||
|
1464
test/format-test.cc
1464
test/format-test.cc
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,11 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
void throw_assertion_failure(const char* message);
|
||||
#define FMT_ASSERT(condition, message) \
|
||||
if (!(condition)) throw_assertion_failure(message);
|
||||
|
||||
#include "gtest-extra.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
class assertion_failure : public std::logic_error {
|
||||
@ -28,9 +33,6 @@ inline void throw_assertion_failure(const char* message) {
|
||||
throw assertion_failure(message);
|
||||
}
|
||||
|
||||
#define FMT_ASSERT(condition, message) \
|
||||
if (!(condition)) throw_assertion_failure(message);
|
||||
|
||||
// Expects an assertion failure.
|
||||
#define EXPECT_ASSERT(stmt, message) \
|
||||
FMT_TEST_THROW_(stmt, assertion_failure, message, GTEST_NONFATAL_FAILURE_)
|
||||
|
10
test/util.cc
10
test/util.cc
@ -9,16 +9,6 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
void increment(char* s) {
|
||||
for (int i = static_cast<int>(std::strlen(s)) - 1; i >= 0; --i) {
|
||||
if (s[i] != '9') {
|
||||
++s[i];
|
||||
break;
|
||||
}
|
||||
s[i] = '0';
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_system_error(int error_code) {
|
||||
#if defined(__MINGW32__) || !defined(_WIN32)
|
||||
return strerror(error_code);
|
||||
|
@ -27,9 +27,6 @@ void safe_sprintf(char (&buffer)[SIZE], const char* format, ...) {
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
// Increment a number in a string.
|
||||
void increment(char* s);
|
||||
|
||||
std::string get_system_error(int error_code);
|
||||
|
||||
extern const char* const FILE_CONTENT;
|
||||
|
Loading…
Reference in New Issue
Block a user