Move implementation specific stuff from format.h to format.cc.

This commit is contained in:
Victor Zverovich
2014-08-15 08:40:03 -07:00
parent c7cfa7d4e7
commit fb32161fa4
4 changed files with 25 additions and 24 deletions

View File

@@ -1,17 +1,21 @@
set(TEST_MAIN_SRC test-main.cc gtest-extra.cc gtest-extra.h util.cc)
add_library(test-main ${TEST_MAIN_SRC})
target_link_libraries(test-main gtest format)
target_link_libraries(test-main gtest)
# Adds a test.
# Usage: add_fmt_test(name libs srcs...)
function(add_fmt_test name libs)
add_executable(${name} ${name}.cc ${ARGN})
cmake_parse_arguments(add_fmt_test CUSTOM_LINK "" "" ${ARGN})
add_executable(${name} ${name}.cc ${add_fmt_test_UNPARSED_ARGUMENTS})
target_link_libraries(${name} ${libs})
if (NOT add_fmt_test_CUSTOM_LINK)
target_link_libraries(${name} format)
endif ()
add_test(${name} ${name})
endfunction()
add_fmt_test(gtest-extra-test test-main)
add_fmt_test(format-test test-main)
add_fmt_test(format-test test-main CUSTOM_LINK ../posix.cc ../posix.h)
add_fmt_test(printf-test test-main)
foreach (target format-test printf-test)
if (CMAKE_COMPILER_IS_GNUCXX)

View File

@@ -35,6 +35,13 @@
#include <memory>
#include <sstream>
// Include format.cc instead of format.h to test implementation-specific stuff.
#include "format.cc"
#include "util.h"
#include "gtest-extra.h"
#include <stdint.h>
#if defined(_WIN32) && !defined(__MINGW32__)
// Fix MSVC warning about "unsafe" fopen.
FILE *safe_fopen(const char *filename, const char *mode) {
@@ -45,12 +52,6 @@ FILE *safe_fopen(const char *filename, const char *mode) {
#define fopen safe_fopen
#endif
#include "format.h"
#include "util.h"
#include "gtest-extra.h"
#include <stdint.h>
#undef min
#undef max
@@ -1230,7 +1231,7 @@ TEST(FormatterTest, FormatNaN) {
double nan = std::numeric_limits<double>::quiet_NaN();
EXPECT_EQ("nan", format("{}", nan));
EXPECT_EQ("+nan", format("{:+}", nan));
if (fmt::internal::signbit_noinline(-nan))
if (getsign(-nan))
EXPECT_EQ("-nan", format("{}", -nan));
else
fmt::print("Warning: compiler doesn't handle negative NaN correctly");