Enable pedantic warnings on tests
This commit is contained in:
parent
16533b275b
commit
6ba5f70f99
103
.ropeproject/config.py
Normal file
103
.ropeproject/config.py
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
# The default ``config.py``
|
||||||
|
# flake8: noqa
|
||||||
|
|
||||||
|
|
||||||
|
def set_prefs(prefs):
|
||||||
|
"""This function is called before opening the project"""
|
||||||
|
|
||||||
|
# Specify which files and folders to ignore in the project.
|
||||||
|
# Changes to ignored resources are not added to the history and
|
||||||
|
# VCSs. Also they are not returned in `Project.get_files()`.
|
||||||
|
# Note that ``?`` and ``*`` match all characters but slashes.
|
||||||
|
# '*.pyc': matches 'test.pyc' and 'pkg/test.pyc'
|
||||||
|
# 'mod*.pyc': matches 'test/mod1.pyc' but not 'mod/1.pyc'
|
||||||
|
# '.svn': matches 'pkg/.svn' and all of its children
|
||||||
|
# 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o'
|
||||||
|
# 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o'
|
||||||
|
prefs['ignored_resources'] = [
|
||||||
|
'*.pyc', '*~', '.ropeproject', '.hg', '.svn', '_svn',
|
||||||
|
'.git', '.tox', '.env', 'env', 'venv', 'node_modules',
|
||||||
|
'bower_components'
|
||||||
|
]
|
||||||
|
|
||||||
|
# Specifies which files should be considered python files. It is
|
||||||
|
# useful when you have scripts inside your project. Only files
|
||||||
|
# ending with ``.py`` are considered to be python files by
|
||||||
|
# default.
|
||||||
|
#prefs['python_files'] = ['*.py']
|
||||||
|
|
||||||
|
# Custom source folders: By default rope searches the project
|
||||||
|
# for finding source folders (folders that should be searched
|
||||||
|
# for finding modules). You can add paths to that list. Note
|
||||||
|
# that rope guesses project source folders correctly most of the
|
||||||
|
# time; use this if you have any problems.
|
||||||
|
# The folders should be relative to project root and use '/' for
|
||||||
|
# separating folders regardless of the platform rope is running on.
|
||||||
|
# 'src/my_source_folder' for instance.
|
||||||
|
#prefs.add('source_folders', 'src')
|
||||||
|
|
||||||
|
# You can extend python path for looking up modules
|
||||||
|
#prefs.add('python_path', '~/python/')
|
||||||
|
|
||||||
|
# Should rope save object information or not.
|
||||||
|
prefs['save_objectdb'] = True
|
||||||
|
prefs['compress_objectdb'] = False
|
||||||
|
|
||||||
|
# If `True`, rope analyzes each module when it is being saved.
|
||||||
|
prefs['automatic_soa'] = True
|
||||||
|
# The depth of calls to follow in static object analysis
|
||||||
|
prefs['soa_followed_calls'] = 0
|
||||||
|
|
||||||
|
# If `False` when running modules or unit tests "dynamic object
|
||||||
|
# analysis" is turned off. This makes them much faster.
|
||||||
|
prefs['perform_doa'] = True
|
||||||
|
|
||||||
|
# Rope can check the validity of its object DB when running.
|
||||||
|
prefs['validate_objectdb'] = True
|
||||||
|
|
||||||
|
# How many undos to hold?
|
||||||
|
prefs['max_history_items'] = 32
|
||||||
|
|
||||||
|
# Shows whether to save history across sessions.
|
||||||
|
prefs['save_history'] = True
|
||||||
|
prefs['compress_history'] = False
|
||||||
|
|
||||||
|
# Set the number spaces used for indenting. According to
|
||||||
|
# :PEP:`8`, it is best to use 4 spaces. Since most of rope's
|
||||||
|
# unit-tests use 4 spaces it is more reliable, too.
|
||||||
|
prefs['indent_size'] = 4
|
||||||
|
|
||||||
|
# Builtin and c-extension modules that are allowed to be imported
|
||||||
|
# and inspected by rope.
|
||||||
|
prefs['extension_modules'] = []
|
||||||
|
|
||||||
|
# Add all standard c-extensions to extension_modules list.
|
||||||
|
prefs['import_dynload_stdmods'] = True
|
||||||
|
|
||||||
|
# If `True` modules with syntax errors are considered to be empty.
|
||||||
|
# The default value is `False`; When `False` syntax errors raise
|
||||||
|
# `rope.base.exceptions.ModuleSyntaxError` exception.
|
||||||
|
prefs['ignore_syntax_errors'] = False
|
||||||
|
|
||||||
|
# If `True`, rope ignores unresolvable imports. Otherwise, they
|
||||||
|
# appear in the importing namespace.
|
||||||
|
prefs['ignore_bad_imports'] = False
|
||||||
|
|
||||||
|
# If `True`, rope will insert new module imports as
|
||||||
|
# `from <package> import <module>` by default.
|
||||||
|
prefs['prefer_module_from_imports'] = False
|
||||||
|
|
||||||
|
# If `True`, rope will transform a comma list of imports into
|
||||||
|
# multiple separate import statements when organizing
|
||||||
|
# imports.
|
||||||
|
prefs['split_imports'] = False
|
||||||
|
|
||||||
|
# If `True`, rope will sort imports alphabetically by module name
|
||||||
|
# instead of alphabetically by import statement, with from imports
|
||||||
|
# after normal imports.
|
||||||
|
prefs['sort_imports_alphabetically'] = False
|
||||||
|
|
||||||
|
|
||||||
|
def project_opened(project):
|
||||||
|
"""This function is called after opening the project"""
|
||||||
|
# Do whatever you like here!
|
||||||
BIN
.ropeproject/globalnames
Normal file
BIN
.ropeproject/globalnames
Normal file
Binary file not shown.
BIN
.ropeproject/history
Normal file
BIN
.ropeproject/history
Normal file
Binary file not shown.
BIN
.ropeproject/objectdb
Normal file
BIN
.ropeproject/objectdb
Normal file
Binary file not shown.
@ -1,6 +1,6 @@
|
|||||||
message(STATUS "CMake version: ${CMAKE_VERSION}")
|
message(STATUS "CMake version: ${CMAKE_VERSION}")
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.8.12)
|
cmake_minimum_required(VERSION 3.1.0)
|
||||||
|
|
||||||
# Determine if fmt is built as a subproject (using add_subdirectory)
|
# Determine if fmt is built as a subproject (using add_subdirectory)
|
||||||
# or if it is the master project.
|
# or if it is the master project.
|
||||||
@ -28,20 +28,12 @@ if (NOT CMAKE_BUILD_TYPE)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF)
|
option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF)
|
||||||
|
option(FMT_WERROR "Halt the compilation with an error on compiler warnings." OFF)
|
||||||
|
|
||||||
# Options that control generation of various targets.
|
# Options that control generation of various targets.
|
||||||
option(FMT_DOC "Generate the doc target." ${MASTER_PROJECT})
|
option(FMT_DOC "Generate the doc target." ${MASTER_PROJECT})
|
||||||
option(FMT_INSTALL "Generate the install target." ${MASTER_PROJECT})
|
option(FMT_INSTALL "Generate the install target." ${MASTER_PROJECT})
|
||||||
option(FMT_TEST "Generate the test target." ${MASTER_PROJECT})
|
option(FMT_TEST "Generate the test target." ${MASTER_PROJECT})
|
||||||
option(FMT_USE_CPP14 "Enable the addition of C++14 compiler flags." ON)
|
|
||||||
|
|
||||||
if (NOT CMAKE_CXX_STANDARD)
|
|
||||||
if (FMT_USE_CPP14)
|
|
||||||
set(CMAKE_CXX_STANDARD 14)
|
|
||||||
else ()
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
project(FMT)
|
project(FMT)
|
||||||
|
|
||||||
@ -66,6 +58,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
|
|||||||
"${CMAKE_CURRENT_SOURCE_DIR}/support/cmake")
|
"${CMAKE_CURRENT_SOURCE_DIR}/support/cmake")
|
||||||
|
|
||||||
include(cxx14)
|
include(cxx14)
|
||||||
|
include(CheckCXXCompilerFlag)
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||||
set(PEDANTIC_COMPILE_FLAGS -pedantic-errors -Wall -Wextra -pedantic
|
set(PEDANTIC_COMPILE_FLAGS -pedantic-errors -Wall -Wextra -pedantic
|
||||||
@ -76,16 +69,16 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
|||||||
-Wctor-dtor-privacy -Wdisabled-optimization
|
-Wctor-dtor-privacy -Wdisabled-optimization
|
||||||
-Winvalid-pch -Wmissing-declarations -Woverloaded-virtual
|
-Winvalid-pch -Wmissing-declarations -Woverloaded-virtual
|
||||||
-Wno-sign-conversion -Wno-shadow -Wno-format-nonliteral
|
-Wno-sign-conversion -Wno-shadow -Wno-format-nonliteral
|
||||||
-Wno-dangling-else)
|
-Wno-dangling-else -Wno-ctor-dtor-privacy)
|
||||||
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
|
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
|
||||||
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wnoexcept)
|
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wnoexcept)
|
||||||
endif ()
|
endif ()
|
||||||
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
|
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
|
||||||
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wdouble-promotion
|
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wdouble-promotion
|
||||||
-Wtrampolines -Wzero-as-null-pointer-constant -Wuseless-cast
|
-Wtrampolines -Wzero-as-null-pointer-constant -Wuseless-cast
|
||||||
-Wvector-operation-performance -Wsized-deallocation)
|
-Wvector-operation-performance -Wsized-deallocation)
|
||||||
endif ()
|
endif ()
|
||||||
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
|
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
|
||||||
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wshift-overflow=2
|
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wshift-overflow=2
|
||||||
-Wnull-dereference -Wduplicated-cond)
|
-Wnull-dereference -Wduplicated-cond)
|
||||||
endif ()
|
endif ()
|
||||||
@ -100,9 +93,22 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|||||||
-Wno-global-constructors -Wno-disabled-macro-expansion
|
-Wno-global-constructors -Wno-disabled-macro-expansion
|
||||||
-Wno-switch-enum -Wno-documentation-unknown-command
|
-Wno-switch-enum -Wno-documentation-unknown-command
|
||||||
-Wno-gnu-string-literal-operator-template -Wno-unused-member-function
|
-Wno-gnu-string-literal-operator-template -Wno-unused-member-function
|
||||||
-Wno-format-nonliteral -Wno-missing-noreturn -Wno-undefined-func-template)
|
-Wno-format-nonliteral -Wno-missing-noreturn -Wno-undefined-func-template
|
||||||
|
-Wno-shadow -Wno-sign-conversion -Wno-used-but-marked-unused
|
||||||
|
-Wno-covered-switch-default -Wno-missing-variable-declarations
|
||||||
|
-Wno-double-promotion)
|
||||||
|
|
||||||
set(WERROR_FLAG -Werror)
|
set(WERROR_FLAG -Werror)
|
||||||
|
|
||||||
|
check_cxx_compiler_flag(-Wno-zero-as-null-pointer-constant HAS_NULLPTR_WARNING)
|
||||||
|
if (HAS_NULLPTR_WARNING)
|
||||||
|
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wno-zero-as-null-pointer-constant)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
check_cxx_compiler_flag(-Wno-gnu-string-literal-operator-template HAS_GNU_UDL_WARNING)
|
||||||
|
if (HAS_GNU_UDL_WARNING)
|
||||||
|
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wno-gnu-string-literal-operator-template)
|
||||||
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
@ -153,9 +159,6 @@ endif ()
|
|||||||
add_library(fmt ${FMT_SOURCES} ${FMT_HEADERS} README.rst ChangeLog.rst)
|
add_library(fmt ${FMT_SOURCES} ${FMT_HEADERS} README.rst ChangeLog.rst)
|
||||||
add_library(fmt::fmt ALIAS fmt)
|
add_library(fmt::fmt ALIAS fmt)
|
||||||
|
|
||||||
# Starting with CMake 3.1 the CXX_STANDARD property can be used instead.
|
|
||||||
# Don't export -std since it may break projects that use other standards.
|
|
||||||
target_compile_options(fmt PRIVATE ${CPP14_FLAG})
|
|
||||||
if (FMT_WERROR)
|
if (FMT_WERROR)
|
||||||
target_compile_options(fmt PRIVATE ${WERROR_FLAG})
|
target_compile_options(fmt PRIVATE ${WERROR_FLAG})
|
||||||
endif ()
|
endif ()
|
||||||
@ -180,17 +183,14 @@ if (BUILD_SHARED_LIBS)
|
|||||||
target_compile_definitions(fmt PRIVATE FMT_EXPORT INTERFACE FMT_SHARED)
|
target_compile_definitions(fmt PRIVATE FMT_EXPORT INTERFACE FMT_SHARED)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Additionally define a header-only library when CMake is new enough.
|
add_library(fmt-header-only INTERFACE)
|
||||||
if (CMAKE_VERSION VERSION_GREATER 3.1.0 OR CMAKE_VERSION VERSION_EQUAL 3.1.0)
|
add_library(fmt::fmt-header-only ALIAS fmt-header-only)
|
||||||
add_library(fmt-header-only INTERFACE)
|
|
||||||
add_library(fmt::fmt-header-only ALIAS fmt-header-only)
|
|
||||||
|
|
||||||
target_compile_definitions(fmt-header-only INTERFACE FMT_HEADER_ONLY=1)
|
target_compile_definitions(fmt-header-only INTERFACE FMT_HEADER_ONLY=1)
|
||||||
|
|
||||||
target_include_directories(fmt-header-only INTERFACE
|
target_include_directories(fmt-header-only INTERFACE
|
||||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||||
$<INSTALL_INTERFACE:include>)
|
$<INSTALL_INTERFACE:include>)
|
||||||
endif ()
|
|
||||||
|
|
||||||
# Install targets.
|
# Install targets.
|
||||||
if (FMT_INSTALL)
|
if (FMT_INSTALL)
|
||||||
|
|||||||
@ -48,6 +48,12 @@
|
|||||||
# define FMT_HAS_GXX_CXX11 0
|
# define FMT_HAS_GXX_CXX11 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# define FMT_MSC_VER _MSC_VER
|
||||||
|
#else
|
||||||
|
# define FMT_MSC_VER 0
|
||||||
|
#endif
|
||||||
|
|
||||||
// Check if relaxed c++14 constexpr is supported.
|
// Check if relaxed c++14 constexpr is supported.
|
||||||
// GCC doesn't allow throw in constexpr until version 6 (bug 67371).
|
// GCC doesn't allow throw in constexpr until version 6 (bug 67371).
|
||||||
#ifndef FMT_USE_CONSTEXPR
|
#ifndef FMT_USE_CONSTEXPR
|
||||||
|
|||||||
@ -51,12 +51,6 @@
|
|||||||
# define FMT_ICC_VERSION 0
|
# define FMT_ICC_VERSION 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
# define FMT_MSC_VER _MSC_VER
|
|
||||||
#else
|
|
||||||
# define FMT_MSC_VER 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 406) || \
|
#if (defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 406) || \
|
||||||
FMT_CLANG_VERSION
|
FMT_CLANG_VERSION
|
||||||
# pragma GCC diagnostic push
|
# pragma GCC diagnostic push
|
||||||
@ -96,7 +90,7 @@
|
|||||||
# if FMT_EXCEPTIONS
|
# if FMT_EXCEPTIONS
|
||||||
# define FMT_THROW(x) throw x
|
# define FMT_THROW(x) throw x
|
||||||
# else
|
# else
|
||||||
# define FMT_THROW(x) assert(false)
|
# define FMT_THROW(x) do { static_cast<void>(sizeof(x)); assert(false); } while(false);
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -139,11 +139,11 @@ using make_index_sequence = std::make_index_sequence<N>;
|
|||||||
#else
|
#else
|
||||||
template <typename T, T... N>
|
template <typename T, T... N>
|
||||||
struct integer_sequence {
|
struct integer_sequence {
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
|
|
||||||
static FMT_CONSTEXPR std::size_t size() {
|
static FMT_CONSTEXPR std::size_t size() {
|
||||||
return sizeof...(N);
|
return sizeof...(N);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <std::size_t... N>
|
template <std::size_t... N>
|
||||||
|
|||||||
@ -1,67 +1,52 @@
|
|||||||
# C++14 feature support detection
|
# C++14 feature support detection
|
||||||
|
|
||||||
if (NOT FMT_USE_CPP14)
|
include(CheckCXXSourceCompiles)
|
||||||
return()
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
|
|
||||||
if (FMT_USE_CPP14)
|
if (NOT CMAKE_CXX_STANDARD)
|
||||||
check_cxx_compiler_flag(-std=c++14 HAVE_STD_CPP14_FLAG)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
if (HAVE_STD_CPP14_FLAG)
|
endif()
|
||||||
# Check if including cmath works with -std=c++14 and -O3.
|
message(STATUS "CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
|
||||||
# It may not in MinGW due to bug http://ehc.ac/p/mingw/bugs/2250/.
|
|
||||||
set(CMAKE_REQUIRED_FLAGS "-std=c++14 -O3")
|
if (CMAKE_CXX_STANDARD EQUAL 20)
|
||||||
check_cxx_source_compiles("
|
check_cxx_compiler_flag(-std=c++20 has_std_20_flag)
|
||||||
#include <cmath>
|
check_cxx_compiler_flag(-std=c++2a has_std_2a_flag)
|
||||||
int main() {}" FMT_CPP14_CMATH)
|
|
||||||
# Check if including <unistd.h> works with -std=c++14.
|
if (has_std_20_flag)
|
||||||
# It may not in MinGW due to bug http://sourceforge.net/p/mingw/bugs/2024/.
|
set(CXX_STANDARD_FLAG -std=c++20)
|
||||||
check_cxx_source_compiles("
|
elseif (has_std_2a_flag)
|
||||||
#include <unistd.h>
|
set(CXX_STANDARD_FLAG -std=c++2a)
|
||||||
int main() {}" FMT_CPP14_UNISTD_H)
|
endif ()
|
||||||
# Check if snprintf works with -std=c++14. It may not in MinGW.
|
elseif (CMAKE_CXX_STANDARD EQUAL 17)
|
||||||
check_cxx_source_compiles("
|
check_cxx_compiler_flag(-std=c++17 has_std_17_flag)
|
||||||
#include <stdio.h>
|
check_cxx_compiler_flag(-std=c++1z has_std_1z_flag)
|
||||||
int main() {
|
|
||||||
char buffer[10];
|
if (has_std_17_flag)
|
||||||
snprintf(buffer, 10, \"foo\");
|
set(CXX_STANDARD_FLAG -std=c++17)
|
||||||
}" FMT_CPP14_SNPRINTF)
|
elseif (has_std_1z_flag)
|
||||||
if (FMT_CPP14_CMATH AND FMT_CPP14_UNISTD_H AND FMT_CPP14_SNPRINTF)
|
set(CXX_STANDARD_FLAG -std=c++1z)
|
||||||
set(CPP14_FLAG -std=c++14)
|
endif ()
|
||||||
else ()
|
elseif (CMAKE_CXX_STANDARD EQUAL 14)
|
||||||
check_cxx_compiler_flag(-std=gnu++14 HAVE_STD_GNUPP14_FLAG)
|
check_cxx_compiler_flag(-std=c++14 has_std_14_flag)
|
||||||
if (HAVE_STD_CPP14_FLAG)
|
check_cxx_compiler_flag(-std=c++1y has_std_1y_flag)
|
||||||
set(CPP14_FLAG -std=gnu++14)
|
|
||||||
endif ()
|
if (has_std_14_flag)
|
||||||
endif ()
|
set(CXX_STANDARD_FLAG -std=c++14)
|
||||||
set(CMAKE_REQUIRED_FLAGS )
|
elseif (has_std_1y_flag)
|
||||||
else ()
|
set(CXX_STANDARD_FLAG -std=c++1y)
|
||||||
check_cxx_compiler_flag(-std=c++1y HAVE_STD_CPP1Y_FLAG)
|
endif ()
|
||||||
if (HAVE_STD_CPP1Y_FLAG)
|
elseif (CMAKE_CXX_STANDARD EQUAL 11)
|
||||||
set(CPP14_FLAG -std=c++1y)
|
check_cxx_compiler_flag(-std=c++11 has_std_14_flag)
|
||||||
else ()
|
check_cxx_compiler_flag(-std=c++0x has_std_0x_flag)
|
||||||
# Fallback on c++11 if c++14 is not available.
|
|
||||||
check_cxx_compiler_flag(-std=c++11 HAVE_STD_CPP11_FLAG)
|
if (has_std_11_flag)
|
||||||
if (HAVE_STD_CPP11_FLAG)
|
set(CXX_STANDARD_FLAG -std=c++11)
|
||||||
set(CPP14_FLAG -std=c++11)
|
elseif (has_std_0x_flag)
|
||||||
else ()
|
set(CXX_STANDARD_FLAG -std=c++0x)
|
||||||
check_cxx_compiler_flag(-std=c++0x HAVE_STD_CPP0X_FLAG)
|
|
||||||
if (HAVE_STD_CPP0X_FLAG)
|
|
||||||
set(CPP14_FLAG -std=c++0x)
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
endif ()
|
|
||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (CMAKE_CXX_STANDARD)
|
set(CMAKE_REQUIRED_FLAGS ${CXX_STANDARD_FLAG})
|
||||||
# Don't use -std compiler flag if CMAKE_CXX_STANDARD is specified.
|
|
||||||
set(CPP14_FLAG )
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
message(STATUS "CPP14_FLAG: ${CPP14_FLAG}")
|
|
||||||
set(CMAKE_REQUIRED_FLAGS ${CPP14_FLAG})
|
|
||||||
|
|
||||||
# Check if variadic templates are working and not affected by GCC bug 39653:
|
# Check if variadic templates are working and not affected by GCC bug 39653:
|
||||||
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39653
|
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39653
|
||||||
@ -69,17 +54,26 @@ check_cxx_source_compiles("
|
|||||||
template <class T, class ...Types>
|
template <class T, class ...Types>
|
||||||
struct S { typedef typename S<Types...>::type type; };
|
struct S { typedef typename S<Types...>::type type; };
|
||||||
int main() {}" SUPPORTS_VARIADIC_TEMPLATES)
|
int main() {}" SUPPORTS_VARIADIC_TEMPLATES)
|
||||||
|
if (NOT SUPPORTS_VARIADIC_TEMPLATES)
|
||||||
|
set (SUPPORTS_VARIADIC_TEMPLATES OFF)
|
||||||
|
endif ()
|
||||||
|
|
||||||
# Check if initializer lists are supported.
|
# Check if initializer lists are supported.
|
||||||
check_cxx_source_compiles("
|
check_cxx_source_compiles("
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
int main() {}" SUPPORTS_INITIALIZER_LIST)
|
int main() {}" SUPPORTS_INITIALIZER_LIST)
|
||||||
|
if (NOT SUPPORTS_INITIALIZER_LIST)
|
||||||
|
set (SUPPORTS_INITIALIZER_LIST OFF)
|
||||||
|
endif ()
|
||||||
|
|
||||||
# Check if enum bases are available
|
# Check if enum bases are available
|
||||||
check_cxx_source_compiles("
|
check_cxx_source_compiles("
|
||||||
enum C : char {A};
|
enum C : char {A};
|
||||||
int main() {}"
|
int main() {}"
|
||||||
SUPPORTS_ENUM_BASE)
|
SUPPORTS_ENUM_BASE)
|
||||||
|
if (NOT SUPPORTS_ENUM_BASE)
|
||||||
|
set (SUPPORTS_ENUM_BASE OFF)
|
||||||
|
endif ()
|
||||||
|
|
||||||
# Check if type traits are available
|
# Check if type traits are available
|
||||||
check_cxx_source_compiles("
|
check_cxx_source_compiles("
|
||||||
@ -87,11 +81,17 @@ check_cxx_source_compiles("
|
|||||||
class C { void operator=(const C&); };
|
class C { void operator=(const C&); };
|
||||||
int main() { static_assert(!std::is_copy_assignable<C>::value, \"\"); }"
|
int main() { static_assert(!std::is_copy_assignable<C>::value, \"\"); }"
|
||||||
SUPPORTS_TYPE_TRAITS)
|
SUPPORTS_TYPE_TRAITS)
|
||||||
|
if (NOT SUPPORTS_TYPE_TRAITS)
|
||||||
|
set (SUPPORTS_TYPE_TRAITS OFF)
|
||||||
|
endif ()
|
||||||
|
|
||||||
# Check if user-defined literals are available
|
# Check if user-defined literals are available
|
||||||
check_cxx_source_compiles("
|
check_cxx_source_compiles("
|
||||||
void operator\"\" _udl(long double);
|
void operator\"\" _udl(long double);
|
||||||
int main() {}"
|
int main() {}"
|
||||||
SUPPORTS_USER_DEFINED_LITERALS)
|
SUPPORTS_USER_DEFINED_LITERALS)
|
||||||
|
if (NOT SUPPORTS_USER_DEFINED_LITERALS)
|
||||||
|
set (SUPPORTS_USER_DEFINED_LITERALS OFF)
|
||||||
|
endif ()
|
||||||
|
|
||||||
set(CMAKE_REQUIRED_FLAGS )
|
set(CMAKE_REQUIRED_FLAGS )
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
# Build the project on Travis CI.
|
# Build the project on Travis CI.
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import errno, os, re, shutil, subprocess, sys, tempfile, urllib
|
import errno, os, shutil, subprocess, sys, urllib
|
||||||
from subprocess import call, check_call, check_output, Popen, PIPE, STDOUT
|
from subprocess import call, check_call, Popen, PIPE, STDOUT
|
||||||
|
|
||||||
def rmtree_if_exists(dir):
|
def rmtree_if_exists(dir):
|
||||||
try:
|
try:
|
||||||
@ -85,14 +85,12 @@ test_build_dir = os.path.join(fmt_dir, "_build_test")
|
|||||||
|
|
||||||
# Configure library.
|
# Configure library.
|
||||||
makedirs_if_not_exist(build_dir)
|
makedirs_if_not_exist(build_dir)
|
||||||
common_cmake_flags = [
|
cmake_flags = [
|
||||||
'-DCMAKE_INSTALL_PREFIX=' + install_dir, '-DCMAKE_BUILD_TYPE=' + build
|
'-DCMAKE_INSTALL_PREFIX=' + install_dir, '-DCMAKE_BUILD_TYPE=' + build,
|
||||||
|
'-DCMAKE_CXX_STANDARD=' + standard
|
||||||
]
|
]
|
||||||
extra_cmake_flags = []
|
|
||||||
if standard != '14':
|
|
||||||
extra_cmake_flags = ['-DCMAKE_CXX_STANDARD=' + standard]
|
|
||||||
check_call(['cmake', '-DFMT_DOC=OFF', '-DFMT_PEDANTIC=ON', '-DFMT_WERROR=ON', fmt_dir] +
|
check_call(['cmake', '-DFMT_DOC=OFF', '-DFMT_PEDANTIC=ON', '-DFMT_WERROR=ON', fmt_dir] +
|
||||||
common_cmake_flags + extra_cmake_flags, cwd=build_dir)
|
cmake_flags, cwd=build_dir)
|
||||||
|
|
||||||
# Build library.
|
# Build library.
|
||||||
check_call(['make', '-j4'], cwd=build_dir)
|
check_call(['make', '-j4'], cwd=build_dir)
|
||||||
@ -101,7 +99,7 @@ check_call(['make', '-j4'], cwd=build_dir)
|
|||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env['CTEST_OUTPUT_ON_FAILURE'] = '1'
|
env['CTEST_OUTPUT_ON_FAILURE'] = '1'
|
||||||
if call(['make', 'test'], env=env, cwd=build_dir):
|
if call(['make', 'test'], env=env, cwd=build_dir):
|
||||||
with open('Testing/Temporary/LastTest.log', 'r') as f:
|
with open(os.path.join(build_dir, 'Testing', 'Temporary', 'LastTest.log'), 'r') as f:
|
||||||
print(f.read())
|
print(f.read())
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
@ -110,7 +108,6 @@ check_call(['make', 'install'], cwd=build_dir)
|
|||||||
|
|
||||||
# Test installation.
|
# Test installation.
|
||||||
makedirs_if_not_exist(test_build_dir)
|
makedirs_if_not_exist(test_build_dir)
|
||||||
check_call(['cmake', '-DCMAKE_CXX_STANDARD=' + standard,
|
check_call(['cmake', os.path.join(fmt_dir, "test", "find-package-test")] +
|
||||||
os.path.join(fmt_dir, "test", "find-package-test")] +
|
cmake_flags, cwd=test_build_dir)
|
||||||
common_cmake_flags, cwd=test_build_dir)
|
|
||||||
check_call(['make', '-j4'], cwd=test_build_dir)
|
check_call(['make', '-j4'], cwd=test_build_dir)
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
add_library(gmock STATIC
|
add_library(gmock STATIC
|
||||||
gmock-gtest-all.cc gmock/gmock.h gtest/gtest.h gtest/gtest-spi.h)
|
gmock-gtest-all.cc gmock/gmock.h gtest/gtest.h gtest/gtest-spi.h)
|
||||||
target_compile_definitions(gmock PUBLIC GTEST_HAS_STD_WSTRING=1)
|
target_compile_definitions(gmock PUBLIC GTEST_HAS_STD_WSTRING=1)
|
||||||
target_include_directories(gmock PUBLIC .)
|
target_include_directories(gmock SYSTEM PUBLIC . gmock gtest)
|
||||||
|
|
||||||
find_package(Threads)
|
find_package(Threads)
|
||||||
if (Threads_FOUND)
|
if (Threads_FOUND)
|
||||||
@ -42,6 +42,7 @@ set(TEST_MAIN_SRC test-main.cc gtest-extra.cc gtest-extra.h util.cc)
|
|||||||
add_library(test-main STATIC ${TEST_MAIN_SRC})
|
add_library(test-main STATIC ${TEST_MAIN_SRC})
|
||||||
target_compile_definitions(test-main PUBLIC
|
target_compile_definitions(test-main PUBLIC
|
||||||
FMT_USE_FILE_DESCRIPTORS=$<BOOL:${HAVE_OPEN}>)
|
FMT_USE_FILE_DESCRIPTORS=$<BOOL:${HAVE_OPEN}>)
|
||||||
|
target_include_directories(test-main SYSTEM PUBLIC gtest gmock)
|
||||||
target_link_libraries(test-main gmock fmt)
|
target_link_libraries(test-main gmock fmt)
|
||||||
|
|
||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
@ -56,7 +57,7 @@ endif ()
|
|||||||
# Use less strict pedantic flags for the tests because GMock doesn't compile
|
# Use less strict pedantic flags for the tests because GMock doesn't compile
|
||||||
# cleanly with -pedantic and -std=c++98.
|
# cleanly with -pedantic and -std=c++98.
|
||||||
if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||||
set(PEDANTIC_COMPILE_FLAGS -Wall -Wextra -Wno-long-long -Wno-variadic-macros)
|
#set(PEDANTIC_COMPILE_FLAGS -Wall -Wextra -Wno-long-long -Wno-variadic-macros)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
function(add_fmt_executable name)
|
function(add_fmt_executable name)
|
||||||
@ -79,6 +80,7 @@ function(add_fmt_test name)
|
|||||||
if (FMT_PEDANTIC)
|
if (FMT_PEDANTIC)
|
||||||
target_compile_options(${name} PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
target_compile_options(${name} PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
||||||
endif ()
|
endif ()
|
||||||
|
target_include_directories(${name} SYSTEM PUBLIC gtest gmock)
|
||||||
add_test(NAME ${name} COMMAND ${name})
|
add_test(NAME ${name} COMMAND ${name})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
@ -100,6 +102,10 @@ if (HAVE_OPEN)
|
|||||||
posix-mock-test PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
posix-mock-test PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||||
target_compile_definitions(posix-mock-test PRIVATE FMT_USE_FILE_DESCRIPTORS=1)
|
target_compile_definitions(posix-mock-test PRIVATE FMT_USE_FILE_DESCRIPTORS=1)
|
||||||
target_link_libraries(posix-mock-test gmock)
|
target_link_libraries(posix-mock-test gmock)
|
||||||
|
target_include_directories(posix-mock-test SYSTEM PUBLIC gtest gmock)
|
||||||
|
if (FMT_PEDANTIC)
|
||||||
|
target_compile_options(posix-mock-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
||||||
|
endif ()
|
||||||
add_test(NAME posix-mock-test COMMAND posix-mock-test)
|
add_test(NAME posix-mock-test COMMAND posix-mock-test)
|
||||||
add_fmt_test(posix-test)
|
add_fmt_test(posix-test)
|
||||||
endif ()
|
endif ()
|
||||||
@ -107,6 +113,7 @@ endif ()
|
|||||||
add_fmt_executable(header-only-test
|
add_fmt_executable(header-only-test
|
||||||
header-only-test.cc header-only-test2.cc test-main.cc)
|
header-only-test.cc header-only-test2.cc test-main.cc)
|
||||||
target_link_libraries(header-only-test gmock)
|
target_link_libraries(header-only-test gmock)
|
||||||
|
target_include_directories(header-only-test SYSTEM PUBLIC gtest gmock)
|
||||||
if (TARGET fmt-header-only)
|
if (TARGET fmt-header-only)
|
||||||
target_link_libraries(header-only-test fmt-header-only)
|
target_link_libraries(header-only-test fmt-header-only)
|
||||||
else ()
|
else ()
|
||||||
@ -122,8 +129,14 @@ if (HAVE_FNO_EXCEPTIONS_FLAG)
|
|||||||
target_include_directories(
|
target_include_directories(
|
||||||
noexception-test PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
noexception-test PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||||
target_compile_options(noexception-test PRIVATE -fno-exceptions)
|
target_compile_options(noexception-test PRIVATE -fno-exceptions)
|
||||||
|
if (FMT_PEDANTIC)
|
||||||
|
target_compile_options(noexception-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
||||||
|
endif ()
|
||||||
|
target_include_directories(noexception-test SYSTEM PUBLIC gtest gmock)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
message(STATUS "FMT_PEDANTIC: ${FMT_PEDANTIC}")
|
||||||
|
|
||||||
if (FMT_PEDANTIC)
|
if (FMT_PEDANTIC)
|
||||||
# Test that the library compiles without windows.h.
|
# Test that the library compiles without windows.h.
|
||||||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||||
@ -131,8 +144,14 @@ if (FMT_PEDANTIC)
|
|||||||
target_include_directories(
|
target_include_directories(
|
||||||
no-windows-h-test PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
no-windows-h-test PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||||
target_compile_definitions(no-windows-h-test PRIVATE FMT_USE_WINDOWS_H=0)
|
target_compile_definitions(no-windows-h-test PRIVATE FMT_USE_WINDOWS_H=0)
|
||||||
|
if (FMT_PEDANTIC)
|
||||||
|
target_compile_options(no-windows-h-test ${PEDANTIC_COMPILE_FLAGS})
|
||||||
|
endif ()
|
||||||
|
target_include_directories(no-windows-h-test SYSTEM PUBLIC gtest gmock)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
message(STATUS USER_DEFINED_LITERALS: ${SUPPORTS_USER_DEFINED_LITERALS})
|
||||||
|
|
||||||
add_test(compile-test ${CMAKE_CTEST_COMMAND}
|
add_test(compile-test ${CMAKE_CTEST_COMMAND}
|
||||||
--build-and-test
|
--build-and-test
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/compile-test"
|
"${CMAKE_CURRENT_SOURCE_DIR}/compile-test"
|
||||||
@ -142,6 +161,8 @@ if (FMT_PEDANTIC)
|
|||||||
--build-options
|
--build-options
|
||||||
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
|
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
|
||||||
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
|
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
|
||||||
|
"-DCXX_STANDARD_FLAG=${CXX_STANDARD_FLAG}"
|
||||||
|
"-DPEDANTIC_COMPILE_FLAGS=${PEDANTIC_COMPILE_FLAGS}"
|
||||||
"-DSUPPORTS_USER_DEFINED_LITERALS=${SUPPORTS_USER_DEFINED_LITERALS}")
|
"-DSUPPORTS_USER_DEFINED_LITERALS=${SUPPORTS_USER_DEFINED_LITERALS}")
|
||||||
|
|
||||||
# test if the targets are findable from the build directory
|
# test if the targets are findable from the build directory
|
||||||
@ -156,6 +177,7 @@ if (FMT_PEDANTIC)
|
|||||||
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
|
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
|
||||||
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
|
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
|
||||||
"-DFMT_DIR=${PROJECT_BINARY_DIR}"
|
"-DFMT_DIR=${PROJECT_BINARY_DIR}"
|
||||||
|
"-DPEDANTIC_COMPILE_FLAGS=${PEDANTIC_COMPILE_FLAGS}"
|
||||||
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
|
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
|
||||||
|
|
||||||
# test if the targets are findable when add_subdirectory is used
|
# test if the targets are findable when add_subdirectory is used
|
||||||
@ -169,5 +191,6 @@ if (FMT_PEDANTIC)
|
|||||||
--build-options
|
--build-options
|
||||||
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
|
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
|
||||||
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
|
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
|
||||||
|
"-DPEDANTIC_COMPILE_FLAGS=${PEDANTIC_COMPILE_FLAGS}"
|
||||||
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
|
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 2.8.12)
|
cmake_minimum_required(VERSION 3.1.0)
|
||||||
|
|
||||||
project(fmt-test)
|
project(fmt-test)
|
||||||
|
|
||||||
@ -6,8 +6,12 @@ add_subdirectory(../.. fmt)
|
|||||||
|
|
||||||
add_executable(library-test "main.cc")
|
add_executable(library-test "main.cc")
|
||||||
target_link_libraries(library-test fmt::fmt)
|
target_link_libraries(library-test fmt::fmt)
|
||||||
|
target_compile_options(library-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
||||||
|
target_include_directories(library-test PUBLIC SYSTEM .)
|
||||||
|
|
||||||
if (TARGET fmt::fmt-header-only)
|
if (TARGET fmt::fmt-header-only)
|
||||||
add_executable(header-only-test "main.cc")
|
add_executable(header-only-test "main.cc")
|
||||||
target_link_libraries(header-only-test fmt::fmt-header-only)
|
target_link_libraries(header-only-test fmt::fmt-header-only)
|
||||||
|
target_compile_options(header-only-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
||||||
|
target_include_directories(header-only-test PUBLIC SYSTEM .)
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
// For the license information refer to format.h.
|
// For the license information refer to format.h.
|
||||||
|
|
||||||
#include "fmt/core.h"
|
#include "fmt/core.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest.h"
|
||||||
|
|
||||||
#if GTEST_HAS_DEATH_TEST
|
#if GTEST_HAS_DEATH_TEST
|
||||||
# define EXPECT_DEBUG_DEATH_IF_SUPPORTED(statement, regex) \
|
# define EXPECT_DEBUG_DEATH_IF_SUPPORTED(statement, regex) \
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
# Test if compile errors are produced where necessary.
|
# Test if compile errors are produced where necessary.
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.8)
|
cmake_minimum_required(VERSION 3.1.0)
|
||||||
|
|
||||||
include(CheckCXXSourceCompiles)
|
include(CheckCXXSourceCompiles)
|
||||||
|
include(CheckCXXCompilerFlag)
|
||||||
|
|
||||||
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
|
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
|
||||||
|
set(CMAKE_REQUIRED_FLAGS ${CXX_STANDARD_FLAG} ${PEDANTIC_COMPILE_FLAGS})
|
||||||
|
|
||||||
function (generate_source result fragment)
|
function (generate_source result fragment)
|
||||||
set(${result} "
|
set(${result} "
|
||||||
|
|||||||
@ -22,13 +22,21 @@ class custom_arg_formatter :
|
|||||||
using base::operator();
|
using base::operator();
|
||||||
|
|
||||||
iterator operator()(double value) {
|
iterator operator()(double value) {
|
||||||
if (round(value * pow(10, spec().precision())) == 0)
|
#if FMT_GCC_VERSION
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
||||||
|
#endif
|
||||||
|
// Comparing a float to 0.0 is safe
|
||||||
|
if (round(value * pow(10, spec().precision())) == 0.0)
|
||||||
value = 0;
|
value = 0;
|
||||||
return base::operator()(value);
|
return base::operator()(value);
|
||||||
|
#if FMT_GCC_VERSION
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string custom_vformat(fmt::string_view format_str, fmt::format_args args) {
|
static std::string custom_vformat(fmt::string_view format_str, fmt::format_args args) {
|
||||||
fmt::memory_buffer buffer;
|
fmt::memory_buffer buffer;
|
||||||
// Pass custom argument formatter as a template arg to vwrite.
|
// Pass custom argument formatter as a template arg to vwrite.
|
||||||
fmt::vformat_to<custom_arg_formatter>(buffer, format_str, args);
|
fmt::vformat_to<custom_arg_formatter>(buffer, format_str, args);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 2.8.12)
|
cmake_minimum_required(VERSION 3.1.0)
|
||||||
|
|
||||||
project(fmt-test)
|
project(fmt-test)
|
||||||
|
|
||||||
@ -6,8 +6,12 @@ find_package(FMT REQUIRED)
|
|||||||
|
|
||||||
add_executable(library-test main.cc)
|
add_executable(library-test main.cc)
|
||||||
target_link_libraries(library-test fmt::fmt)
|
target_link_libraries(library-test fmt::fmt)
|
||||||
|
target_compile_options(library-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
||||||
|
target_include_directories(library-test PUBLIC SYSTEM .)
|
||||||
|
|
||||||
if (TARGET fmt::fmt-header-only)
|
if (TARGET fmt::fmt-header-only)
|
||||||
add_executable(header-only-test main.cc)
|
add_executable(header-only-test main.cc)
|
||||||
target_link_libraries(header-only-test fmt::fmt-header-only)
|
target_link_libraries(header-only-test fmt::fmt-header-only)
|
||||||
|
target_compile_options(header-only-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
||||||
|
target_include_directories(header-only-test PUBLIC SYSTEM .)
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
#include "gmock.h"
|
||||||
#include "gtest-extra.h"
|
#include "gtest-extra.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
@ -52,9 +52,9 @@ TEST(FormatTest, FormatNegativeNaN) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatTest, StrError) {
|
TEST(FormatTest, StrError) {
|
||||||
char *message = 0;
|
char *message = nullptr;
|
||||||
char buffer[BUFFER_SIZE];
|
char buffer[BUFFER_SIZE];
|
||||||
EXPECT_ASSERT(fmt::safe_strerror(EDOM, message = 0, 0), "invalid buffer");
|
EXPECT_ASSERT(fmt::safe_strerror(EDOM, message = nullptr, 0), "invalid buffer");
|
||||||
EXPECT_ASSERT(fmt::safe_strerror(EDOM, message = buffer, 0),
|
EXPECT_ASSERT(fmt::safe_strerror(EDOM, message = buffer, 0),
|
||||||
"invalid buffer");
|
"invalid buffer");
|
||||||
buffer[0] = 'x';
|
buffer[0] = 'x';
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
#include "gmock.h"
|
||||||
|
|
||||||
// Test that the library compiles if None is defined to 0 as done by xlib.h.
|
// Test that the library compiles if None is defined to 0 as done by xlib.h.
|
||||||
#define None 0
|
#define None 0
|
||||||
@ -1024,7 +1024,7 @@ TEST(FormatterTest, FormatCString) {
|
|||||||
EXPECT_EQ("test", format("{0:s}", "test"));
|
EXPECT_EQ("test", format("{0:s}", "test"));
|
||||||
char nonconst[] = "nonconst";
|
char nonconst[] = "nonconst";
|
||||||
EXPECT_EQ("nonconst", format("{0}", nonconst));
|
EXPECT_EQ("nonconst", format("{0}", nonconst));
|
||||||
EXPECT_THROW_MSG(format("{0}", reinterpret_cast<const char*>(0)),
|
EXPECT_THROW_MSG(format("{0}", static_cast<const char*>(nullptr)),
|
||||||
format_error, "string pointer is null");
|
format_error, "string pointer is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1046,7 +1046,7 @@ TEST(FormatterTest, FormatUCharString) {
|
|||||||
|
|
||||||
TEST(FormatterTest, FormatPointer) {
|
TEST(FormatterTest, FormatPointer) {
|
||||||
check_unknown_types(reinterpret_cast<void*>(0x1234), "p", "pointer");
|
check_unknown_types(reinterpret_cast<void*>(0x1234), "p", "pointer");
|
||||||
EXPECT_EQ("0x0", format("{0}", reinterpret_cast<void*>(0)));
|
EXPECT_EQ("0x0", format("{0}", static_cast<void*>(nullptr)));
|
||||||
EXPECT_EQ("0x1234", format("{0}", reinterpret_cast<void*>(0x1234)));
|
EXPECT_EQ("0x1234", format("{0}", reinterpret_cast<void*>(0x1234)));
|
||||||
EXPECT_EQ("0x1234", format("{0:p}", reinterpret_cast<void*>(0x1234)));
|
EXPECT_EQ("0x1234", format("{0:p}", reinterpret_cast<void*>(0x1234)));
|
||||||
EXPECT_EQ("0x" + std::string(sizeof(void*) * CHAR_BIT / 4, 'f'),
|
EXPECT_EQ("0x" + std::string(sizeof(void*) * CHAR_BIT / 4, 'f'),
|
||||||
@ -1148,7 +1148,7 @@ TEST(FormatterTest, FormatExamples) {
|
|||||||
FILE *ftest = safe_fopen(filename, "r");
|
FILE *ftest = safe_fopen(filename, "r");
|
||||||
if (ftest) fclose(ftest);
|
if (ftest) fclose(ftest);
|
||||||
int error_code = errno;
|
int error_code = errno;
|
||||||
EXPECT_TRUE(ftest == 0);
|
EXPECT_TRUE(ftest == nullptr);
|
||||||
EXPECT_SYSTEM_ERROR({
|
EXPECT_SYSTEM_ERROR({
|
||||||
FILE *f = safe_fopen(filename, "r");
|
FILE *f = safe_fopen(filename, "r");
|
||||||
if (!f)
|
if (!f)
|
||||||
@ -1309,7 +1309,7 @@ TEST(StrTest, Convert) {
|
|||||||
EXPECT_EQ("2012-12-9", s);
|
EXPECT_EQ("2012-12-9", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string vformat_message(int id, const char *format, fmt::format_args args) {
|
static std::string vformat_message(int id, const char *format, fmt::format_args args) {
|
||||||
fmt::memory_buffer buffer;
|
fmt::memory_buffer buffer;
|
||||||
format_to(buffer, "[{}] ", id);
|
format_to(buffer, "[{}] ", id);
|
||||||
vformat_to(buffer, format, args);
|
vformat_to(buffer, format, args);
|
||||||
@ -1421,7 +1421,7 @@ class mock_arg_formatter:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void custom_vformat(fmt::string_view format_str, fmt::format_args args) {
|
static void custom_vformat(fmt::string_view format_str, fmt::format_args args) {
|
||||||
fmt::memory_buffer buffer;
|
fmt::memory_buffer buffer;
|
||||||
fmt::vformat_to<mock_arg_formatter>(buffer, format_str, args);
|
fmt::vformat_to<mock_arg_formatter>(buffer, format_str, args);
|
||||||
}
|
}
|
||||||
@ -1516,6 +1516,9 @@ TEST(FormatTest, FormatToN) {
|
|||||||
EXPECT_EQ(6u, result.size);
|
EXPECT_EQ(6u, result.size);
|
||||||
EXPECT_EQ(buffer + 3, result.out);
|
EXPECT_EQ(buffer + 3, result.out);
|
||||||
EXPECT_EQ("foox", fmt::string_view(buffer, 4));
|
EXPECT_EQ("foox", fmt::string_view(buffer, 4));
|
||||||
|
|
||||||
|
// Workaround for potentially unused macro
|
||||||
|
static_cast<void>(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FMT_USE_CONSTEXPR
|
#if FMT_USE_CONSTEXPR
|
||||||
@ -1794,12 +1797,14 @@ FMT_CONSTEXPR bool test_error(const char *fmt, const char *expected_error) {
|
|||||||
return equal(actual_error, expected_error);
|
return equal(actual_error, expected_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define EXPECT_ERROR_NOARGS(fmt, error) \
|
||||||
|
static_assert(test_error(fmt, error), "")
|
||||||
#define EXPECT_ERROR(fmt, error, ...) \
|
#define EXPECT_ERROR(fmt, error, ...) \
|
||||||
static_assert(test_error<__VA_ARGS__>(fmt, error), "")
|
static_assert(test_error<__VA_ARGS__>(fmt, error), "")
|
||||||
|
|
||||||
TEST(FormatTest, FormatStringErrors) {
|
TEST(FormatTest, FormatStringErrors) {
|
||||||
EXPECT_ERROR("foo", nullptr);
|
EXPECT_ERROR_NOARGS("foo", nullptr);
|
||||||
EXPECT_ERROR("}", "unmatched '}' in format string");
|
EXPECT_ERROR_NOARGS("}", "unmatched '}' in format string");
|
||||||
EXPECT_ERROR("{0:s", "unknown format specifier", Date);
|
EXPECT_ERROR("{0:s", "unknown format specifier", Date);
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
// This causes an internal compiler error in MSVC2017.
|
// This causes an internal compiler error in MSVC2017.
|
||||||
@ -1807,7 +1812,7 @@ TEST(FormatTest, FormatStringErrors) {
|
|||||||
EXPECT_ERROR("{:{<}", "invalid fill character '{'", int);
|
EXPECT_ERROR("{:{<}", "invalid fill character '{'", int);
|
||||||
EXPECT_ERROR("{:10000000000}", "number is too big", int);
|
EXPECT_ERROR("{:10000000000}", "number is too big", int);
|
||||||
EXPECT_ERROR("{:.10000000000}", "number is too big", int);
|
EXPECT_ERROR("{:.10000000000}", "number is too big", int);
|
||||||
EXPECT_ERROR("{:x}", "argument index out of range");
|
EXPECT_ERROR_NOARGS("{:x}", "argument index out of range");
|
||||||
EXPECT_ERROR("{:=}", "format specifier requires numeric argument",
|
EXPECT_ERROR("{:=}", "format specifier requires numeric argument",
|
||||||
const char *);
|
const char *);
|
||||||
EXPECT_ERROR("{:+}", "format specifier requires numeric argument",
|
EXPECT_ERROR("{:+}", "format specifier requires numeric argument",
|
||||||
@ -1834,15 +1839,15 @@ TEST(FormatTest, FormatStringErrors) {
|
|||||||
EXPECT_ERROR("{:s}", "invalid type specifier", void *);
|
EXPECT_ERROR("{:s}", "invalid type specifier", void *);
|
||||||
#endif
|
#endif
|
||||||
EXPECT_ERROR("{foo", "missing '}' in format string", int);
|
EXPECT_ERROR("{foo", "missing '}' in format string", int);
|
||||||
EXPECT_ERROR("{10000000000}", "number is too big");
|
EXPECT_ERROR_NOARGS("{10000000000}", "number is too big");
|
||||||
EXPECT_ERROR("{0x}", "invalid format string");
|
EXPECT_ERROR_NOARGS("{0x}", "invalid format string");
|
||||||
EXPECT_ERROR("{-}", "invalid format string");
|
EXPECT_ERROR_NOARGS("{-}", "invalid format string");
|
||||||
EXPECT_ERROR("{:{0x}}", "invalid format string", int);
|
EXPECT_ERROR("{:{0x}}", "invalid format string", int);
|
||||||
EXPECT_ERROR("{:{-}}", "invalid format string", int);
|
EXPECT_ERROR("{:{-}}", "invalid format string", int);
|
||||||
EXPECT_ERROR("{:.{0x}}", "invalid format string", int);
|
EXPECT_ERROR("{:.{0x}}", "invalid format string", int);
|
||||||
EXPECT_ERROR("{:.{-}}", "invalid format string", int);
|
EXPECT_ERROR("{:.{-}}", "invalid format string", int);
|
||||||
EXPECT_ERROR("{:.x}", "missing precision specifier", int);
|
EXPECT_ERROR("{:.x}", "missing precision specifier", int);
|
||||||
EXPECT_ERROR("{}", "argument index out of range");
|
EXPECT_ERROR_NOARGS("{}", "argument index out of range");
|
||||||
EXPECT_ERROR("{1}", "argument index out of range", int);
|
EXPECT_ERROR("{1}", "argument index out of range", int);
|
||||||
EXPECT_ERROR("{1}{}",
|
EXPECT_ERROR("{1}{}",
|
||||||
"cannot switch from manual to automatic argument indexing",
|
"cannot switch from manual to automatic argument indexing",
|
||||||
|
|||||||
@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
// This line ensures that gtest.h can be compiled on its own, even
|
// This line ensures that gtest.h can be compiled on its own, even
|
||||||
// when it's fused.
|
// when it's fused.
|
||||||
#include "gtest/gtest.h"
|
#include "gtest.h"
|
||||||
|
|
||||||
// The following lines pull in the real gtest *.cc files.
|
// The following lines pull in the real gtest *.cc files.
|
||||||
// Copyright 2005, Google Inc.
|
// Copyright 2005, Google Inc.
|
||||||
|
|||||||
@ -235,7 +235,7 @@
|
|||||||
|
|
||||||
// Most of the types needed for porting Google Mock are also required
|
// Most of the types needed for porting Google Mock are also required
|
||||||
// for Google Test and are defined in gtest-port.h.
|
// for Google Test and are defined in gtest-port.h.
|
||||||
#include "gtest/gtest.h"
|
#include "gtest.h"
|
||||||
|
|
||||||
// To avoid conditional compilation everywhere, we make it
|
// To avoid conditional compilation everywhere, we make it
|
||||||
// gmock-port.h's responsibility to #include the header implementing
|
// gmock-port.h's responsibility to #include the header implementing
|
||||||
|
|||||||
@ -340,10 +340,10 @@ TEST(OutputRedirectTest, FlushErrorInCtor) {
|
|||||||
// Put a character in a file buffer.
|
// Put a character in a file buffer.
|
||||||
EXPECT_EQ('x', fputc('x', f.get()));
|
EXPECT_EQ('x', fputc('x', f.get()));
|
||||||
FMT_POSIX(close(write_fd));
|
FMT_POSIX(close(write_fd));
|
||||||
scoped_ptr<OutputRedirect> redir;
|
scoped_ptr<OutputRedirect> redir{nullptr};
|
||||||
EXPECT_SYSTEM_ERROR_NOASSERT(redir.reset(new OutputRedirect(f.get())),
|
EXPECT_SYSTEM_ERROR_NOASSERT(redir.reset(new OutputRedirect(f.get())),
|
||||||
EBADF, "cannot flush stream");
|
EBADF, "cannot flush stream");
|
||||||
redir.reset();
|
redir.reset(nullptr);
|
||||||
write_copy.dup2(write_fd); // "undo" close or dtor will fail
|
write_copy.dup2(write_fd); // "undo" close or dtor will fail
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,7 +352,7 @@ TEST(OutputRedirectTest, DupErrorInCtor) {
|
|||||||
int fd = (f.fileno)();
|
int fd = (f.fileno)();
|
||||||
file copy = file::dup(fd);
|
file copy = file::dup(fd);
|
||||||
FMT_POSIX(close(fd));
|
FMT_POSIX(close(fd));
|
||||||
scoped_ptr<OutputRedirect> redir;
|
scoped_ptr<OutputRedirect> redir{nullptr};
|
||||||
EXPECT_SYSTEM_ERROR_NOASSERT(redir.reset(new OutputRedirect(f.get())),
|
EXPECT_SYSTEM_ERROR_NOASSERT(redir.reset(new OutputRedirect(f.get())),
|
||||||
EBADF, fmt::format("cannot duplicate file descriptor {}", fd));
|
EBADF, fmt::format("cannot duplicate file descriptor {}", fd));
|
||||||
copy.dup2(fd); // "undo" close or dtor will fail
|
copy.dup2(fd); // "undo" close or dtor will fail
|
||||||
@ -403,7 +403,7 @@ TEST(OutputRedirectTest, ErrorInDtor) {
|
|||||||
// output in EXPECT_STDERR and the second close will break output
|
// output in EXPECT_STDERR and the second close will break output
|
||||||
// redirection.
|
// redirection.
|
||||||
FMT_POSIX(close(write_fd));
|
FMT_POSIX(close(write_fd));
|
||||||
SUPPRESS_ASSERT(redir.reset());
|
SUPPRESS_ASSERT(redir.reset(nullptr));
|
||||||
}, format_system_error(EBADF, "cannot flush stream"));
|
}, format_system_error(EBADF, "cannot flush stream"));
|
||||||
write_copy.dup2(write_fd); // "undo" close or dtor of buffered_file will fail
|
write_copy.dup2(write_fd); // "undo" close or dtor of buffered_file will fail
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,7 +75,7 @@ std::string read(file &f, std::size_t count) {
|
|||||||
do {
|
do {
|
||||||
n = f.read(&buffer[offset], count - offset);
|
n = f.read(&buffer[offset], count - offset);
|
||||||
// We can't read more than size_t bytes since count has type size_t.
|
// We can't read more than size_t bytes since count has type size_t.
|
||||||
offset += static_cast<std::size_t>(n);
|
offset += n;
|
||||||
} while (offset < count && n != 0);
|
} while (offset < count && n != 0);
|
||||||
buffer.resize(offset);
|
buffer.resize(offset);
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
#define FMT_GTEST_EXTRA_H_
|
#define FMT_GTEST_EXTRA_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <gmock/gmock.h>
|
#include "gmock.h"
|
||||||
|
|
||||||
#include "fmt/core.h"
|
#include "fmt/core.h"
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ std::string read(fmt::file &f, std::size_t count);
|
|||||||
template <typename Mock>
|
template <typename Mock>
|
||||||
struct ScopedMock : testing::StrictMock<Mock> {
|
struct ScopedMock : testing::StrictMock<Mock> {
|
||||||
ScopedMock() { Mock::instance = this; }
|
ScopedMock() { Mock::instance = this; }
|
||||||
~ScopedMock() { Mock::instance = 0; }
|
~ScopedMock() { Mock::instance = nullptr; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FMT_GTEST_EXTRA_H_
|
#endif // FMT_GTEST_EXTRA_H_
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
#ifndef FMT_MOCK_ALLOCATOR_H_
|
#ifndef FMT_MOCK_ALLOCATOR_H_
|
||||||
#define FMT_MOCK_ALLOCATOR_H_
|
#define FMT_MOCK_ALLOCATOR_H_
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
#include "gmock.h"
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class MockAllocator {
|
class MockAllocator {
|
||||||
@ -28,7 +28,7 @@ class AllocatorRef {
|
|||||||
public:
|
public:
|
||||||
typedef typename Allocator::value_type value_type;
|
typedef typename Allocator::value_type value_type;
|
||||||
|
|
||||||
explicit AllocatorRef(Allocator *alloc = 0) : alloc_(alloc) {}
|
explicit AllocatorRef(Allocator *alloc = nullptr) : alloc_(alloc) {}
|
||||||
|
|
||||||
AllocatorRef(const AllocatorRef &other) : alloc_(other.alloc_) {}
|
AllocatorRef(const AllocatorRef &other) : alloc_(other.alloc_) {}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ class AllocatorRef {
|
|||||||
private:
|
private:
|
||||||
void move(AllocatorRef &other) {
|
void move(AllocatorRef &other) {
|
||||||
alloc_ = other.alloc_;
|
alloc_ = other.alloc_;
|
||||||
other.alloc_ = 0;
|
other.alloc_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -8,29 +8,29 @@
|
|||||||
#include "fmt/ostream.h"
|
#include "fmt/ostream.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "gmock/gmock.h"
|
#include "gmock.h"
|
||||||
#include "gtest-extra.h"
|
#include "gtest-extra.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
using fmt::format;
|
using fmt::format;
|
||||||
using fmt::format_error;
|
using fmt::format_error;
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, const Date &d) {
|
static std::ostream &operator<<(std::ostream &os, const Date &d) {
|
||||||
os << d.year() << '-' << d.month() << '-' << d.day();
|
os << d.year() << '-' << d.month() << '-' << d.day();
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wostream &operator<<(std::wostream &os, const Date &d) {
|
static std::wostream &operator<<(std::wostream &os, const Date &d) {
|
||||||
os << d.year() << L'-' << d.month() << L'-' << d.day();
|
os << d.year() << L'-' << d.month() << L'-' << d.day();
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum TestEnum {};
|
enum TestEnum {};
|
||||||
std::ostream &operator<<(std::ostream &os, TestEnum) {
|
static std::ostream &operator<<(std::ostream &os, TestEnum) {
|
||||||
return os << "TestEnum";
|
return os << "TestEnum";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wostream &operator<<(std::wostream &os, TestEnum) {
|
static std::wostream &operator<<(std::wostream &os, TestEnum) {
|
||||||
return os << L"TestEnum";
|
return os << L"TestEnum";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ TEST(OStreamTest, FormatSpecs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct EmptyTest {};
|
struct EmptyTest {};
|
||||||
std::ostream &operator<<(std::ostream &os, EmptyTest) {
|
static std::ostream &operator<<(std::ostream &os, EmptyTest) {
|
||||||
return os << "";
|
return os << "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {
|
|||||||
} os(streambuf);
|
} os(streambuf);
|
||||||
|
|
||||||
testing::InSequence sequence;
|
testing::InSequence sequence;
|
||||||
const char *data = 0;
|
const char *data = nullptr;
|
||||||
std::size_t size = max_size;
|
std::size_t size = max_size;
|
||||||
do {
|
do {
|
||||||
typedef std::make_unsigned<std::streamsize>::type ustreamsize;
|
typedef std::make_unsigned<std::streamsize>::type ustreamsize;
|
||||||
@ -154,7 +154,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {
|
|||||||
EXPECT_CALL(streambuf, xsputn(data, static_cast<std::streamsize>(n)))
|
EXPECT_CALL(streambuf, xsputn(data, static_cast<std::streamsize>(n)))
|
||||||
.WillOnce(testing::Return(max_streamsize));
|
.WillOnce(testing::Return(max_streamsize));
|
||||||
data += n;
|
data += n;
|
||||||
size -= static_cast<std::size_t>(n);
|
size -= n;
|
||||||
} while (size != 0);
|
} while (size != 0);
|
||||||
fmt::internal::write(os, buffer);
|
fmt::internal::write(os, buffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,9 @@
|
|||||||
// For the license information refer to format.h.
|
// For the license information refer to format.h.
|
||||||
|
|
||||||
// Disable bogus MSVC warnings.
|
// Disable bogus MSVC warnings.
|
||||||
#define _CRT_SECURE_NO_WARNINGS
|
#ifdef _MSC_VER
|
||||||
|
# define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "posix-mock.h"
|
#include "posix-mock.h"
|
||||||
#include "../src/posix.cc"
|
#include "../src/posix.cc"
|
||||||
@ -21,7 +23,7 @@
|
|||||||
# undef ERROR
|
# undef ERROR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
#include "gmock.h"
|
||||||
#include "gtest-extra.h"
|
#include "gtest-extra.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
@ -131,7 +133,7 @@ int test::dup2(int fildes, int fildes2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FILE *test::fdopen(int fildes, const char *mode) {
|
FILE *test::fdopen(int fildes, const char *mode) {
|
||||||
EMULATE_EINTR(fdopen, 0);
|
EMULATE_EINTR(fdopen, nullptr);
|
||||||
return ::FMT_POSIX(fdopen(fildes, mode));
|
return ::FMT_POSIX(fdopen(fildes, mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +162,7 @@ int test::pipe(int *pfds, unsigned psize, int textmode) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
FILE *test::fopen(const char *filename, const char *mode) {
|
FILE *test::fopen(const char *filename, const char *mode) {
|
||||||
EMULATE_EINTR(fopen, 0);
|
EMULATE_EINTR(fopen, nullptr);
|
||||||
return ::fopen(filename, mode);
|
return ::fopen(filename, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +195,7 @@ int (test::fileno)(FILE *stream) {
|
|||||||
# define EXPECT_EQ_POSIX(expected, actual)
|
# define EXPECT_EQ_POSIX(expected, actual)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void write_file(fmt::cstring_view filename, fmt::string_view content) {
|
static void write_file(fmt::cstring_view filename, fmt::string_view content) {
|
||||||
fmt::buffered_file f(filename, "w");
|
fmt::buffered_file f(filename, "w");
|
||||||
f.print("{}", content);
|
f.print("{}", content);
|
||||||
}
|
}
|
||||||
@ -214,7 +216,7 @@ TEST(UtilTest, GetPageSize) {
|
|||||||
|
|
||||||
TEST(FileTest, OpenRetry) {
|
TEST(FileTest, OpenRetry) {
|
||||||
write_file("test", "there must be something here");
|
write_file("test", "there must be something here");
|
||||||
scoped_ptr<file> f;
|
scoped_ptr<file> f{nullptr};
|
||||||
EXPECT_RETRY(f.reset(new file("test", file::RDONLY)),
|
EXPECT_RETRY(f.reset(new file("test", file::RDONLY)),
|
||||||
open, "cannot open file test");
|
open, "cannot open file test");
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@ -230,7 +232,7 @@ TEST(FileTest, CloseNoRetryInDtor) {
|
|||||||
int saved_close_count = 0;
|
int saved_close_count = 0;
|
||||||
EXPECT_WRITE(stderr, {
|
EXPECT_WRITE(stderr, {
|
||||||
close_count = 1;
|
close_count = 1;
|
||||||
f.reset();
|
f.reset(nullptr);
|
||||||
saved_close_count = close_count;
|
saved_close_count = close_count;
|
||||||
close_count = 0;
|
close_count = 0;
|
||||||
}, format_system_error(EINTR, "cannot close file") + "\n");
|
}, format_system_error(EINTR, "cannot close file") + "\n");
|
||||||
@ -383,7 +385,7 @@ TEST(FileTest, FdopenNoRetry) {
|
|||||||
|
|
||||||
TEST(BufferedFileTest, OpenRetry) {
|
TEST(BufferedFileTest, OpenRetry) {
|
||||||
write_file("test", "there must be something here");
|
write_file("test", "there must be something here");
|
||||||
scoped_ptr<buffered_file> f;
|
scoped_ptr<buffered_file> f{nullptr};
|
||||||
EXPECT_RETRY(f.reset(new buffered_file("test", "r")),
|
EXPECT_RETRY(f.reset(new buffered_file("test", "r")),
|
||||||
fopen, "cannot open file test");
|
fopen, "cannot open file test");
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@ -400,7 +402,7 @@ TEST(BufferedFileTest, CloseNoRetryInDtor) {
|
|||||||
int saved_fclose_count = 0;
|
int saved_fclose_count = 0;
|
||||||
EXPECT_WRITE(stderr, {
|
EXPECT_WRITE(stderr, {
|
||||||
fclose_count = 1;
|
fclose_count = 1;
|
||||||
f.reset();
|
f.reset(nullptr);
|
||||||
saved_fclose_count = fclose_count;
|
saved_fclose_count = fclose_count;
|
||||||
fclose_count = 0;
|
fclose_count = 0;
|
||||||
}, format_system_error(EINTR, "cannot close file") + "\n");
|
}, format_system_error(EINTR, "cannot close file") + "\n");
|
||||||
@ -436,8 +438,9 @@ TEST(ScopedMock, Scope) {
|
|||||||
ScopedMock<TestMock> mock;
|
ScopedMock<TestMock> mock;
|
||||||
EXPECT_EQ(&mock, TestMock::instance);
|
EXPECT_EQ(&mock, TestMock::instance);
|
||||||
TestMock © = mock;
|
TestMock © = mock;
|
||||||
|
static_cast<void>(copy);
|
||||||
}
|
}
|
||||||
EXPECT_EQ(0, TestMock::instance);
|
EXPECT_EQ(nullptr, TestMock::instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FMT_LOCALE
|
#ifdef FMT_LOCALE
|
||||||
@ -504,7 +507,7 @@ TEST(LocaleTest, Locale) {
|
|||||||
#endif
|
#endif
|
||||||
ScopedMock<LocaleMock> mock;
|
ScopedMock<LocaleMock> mock;
|
||||||
LocaleType impl = reinterpret_cast<LocaleType>(42);
|
LocaleType impl = reinterpret_cast<LocaleType>(42);
|
||||||
EXPECT_CALL(mock, newlocale(LC_NUMERIC_MASK, StrEq("C"), 0))
|
EXPECT_CALL(mock, newlocale(LC_NUMERIC_MASK, StrEq("C"), nullptr))
|
||||||
.WillOnce(Return(impl));
|
.WillOnce(Return(impl));
|
||||||
EXPECT_CALL(mock, freelocale(impl));
|
EXPECT_CALL(mock, freelocale(impl));
|
||||||
fmt::Locale locale;
|
fmt::Locale locale;
|
||||||
|
|||||||
@ -23,12 +23,12 @@ using fmt::file;
|
|||||||
using testing::internal::scoped_ptr;
|
using testing::internal::scoped_ptr;
|
||||||
|
|
||||||
// Checks if the file is open by reading one character from it.
|
// Checks if the file is open by reading one character from it.
|
||||||
bool isopen(int fd) {
|
static bool isopen(int fd) {
|
||||||
char buffer;
|
char buffer;
|
||||||
return FMT_POSIX(read(fd, &buffer, 1)) == 1;
|
return FMT_POSIX(read(fd, &buffer, 1)) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isclosed(int fd) {
|
static bool isclosed(int fd) {
|
||||||
char buffer;
|
char buffer;
|
||||||
std::streamsize result = 0;
|
std::streamsize result = 0;
|
||||||
SUPPRESS_ASSERT(result = FMT_POSIX(read(fd, &buffer, 1)));
|
SUPPRESS_ASSERT(result = FMT_POSIX(read(fd, &buffer, 1)));
|
||||||
@ -36,7 +36,7 @@ bool isclosed(int fd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Opens a file for reading.
|
// Opens a file for reading.
|
||||||
file open_file() {
|
static file open_file() {
|
||||||
file read_end, write_end;
|
file read_end, write_end;
|
||||||
file::pipe(read_end, write_end);
|
file::pipe(read_end, write_end);
|
||||||
write_end.write(FILE_CONTENT, std::strlen(FILE_CONTENT));
|
write_end.write(FILE_CONTENT, std::strlen(FILE_CONTENT));
|
||||||
@ -45,7 +45,7 @@ file open_file() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attempts to write a string to a file.
|
// Attempts to write a string to a file.
|
||||||
void write(file &f, fmt::string_view s) {
|
static void write(file &f, fmt::string_view s) {
|
||||||
std::size_t num_chars_left = s.size();
|
std::size_t num_chars_left = s.size();
|
||||||
const char *ptr = s.data();
|
const char *ptr = s.data();
|
||||||
do {
|
do {
|
||||||
@ -53,32 +53,32 @@ void write(file &f, fmt::string_view s) {
|
|||||||
ptr += count;
|
ptr += count;
|
||||||
// We can't write more than size_t bytes since num_chars_left
|
// We can't write more than size_t bytes since num_chars_left
|
||||||
// has type size_t.
|
// has type size_t.
|
||||||
num_chars_left -= static_cast<std::size_t>(count);
|
num_chars_left -= count;
|
||||||
} while (num_chars_left != 0);
|
} while (num_chars_left != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BufferedFileTest, DefaultCtor) {
|
TEST(BufferedFileTest, DefaultCtor) {
|
||||||
buffered_file f;
|
buffered_file f;
|
||||||
EXPECT_TRUE(f.get() == 0);
|
EXPECT_TRUE(f.get() == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BufferedFileTest, MoveCtor) {
|
TEST(BufferedFileTest, MoveCtor) {
|
||||||
buffered_file bf = open_buffered_file();
|
buffered_file bf = open_buffered_file();
|
||||||
FILE *fp = bf.get();
|
FILE *fp = bf.get();
|
||||||
EXPECT_TRUE(fp != 0);
|
EXPECT_TRUE(fp != nullptr);
|
||||||
buffered_file bf2(std::move(bf));
|
buffered_file bf2(std::move(bf));
|
||||||
EXPECT_EQ(fp, bf2.get());
|
EXPECT_EQ(fp, bf2.get());
|
||||||
EXPECT_TRUE(bf.get() == 0);
|
EXPECT_TRUE(bf.get() == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BufferedFileTest, MoveAssignment) {
|
TEST(BufferedFileTest, MoveAssignment) {
|
||||||
buffered_file bf = open_buffered_file();
|
buffered_file bf = open_buffered_file();
|
||||||
FILE *fp = bf.get();
|
FILE *fp = bf.get();
|
||||||
EXPECT_TRUE(fp != 0);
|
EXPECT_TRUE(fp != nullptr);
|
||||||
buffered_file bf2;
|
buffered_file bf2;
|
||||||
bf2 = std::move(bf);
|
bf2 = std::move(bf);
|
||||||
EXPECT_EQ(fp, bf2.get());
|
EXPECT_EQ(fp, bf2.get());
|
||||||
EXPECT_TRUE(bf.get() == 0);
|
EXPECT_TRUE(bf.get() == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BufferedFileTest, MoveAssignmentClosesFile) {
|
TEST(BufferedFileTest, MoveAssignmentClosesFile) {
|
||||||
@ -90,13 +90,13 @@ TEST(BufferedFileTest, MoveAssignmentClosesFile) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(BufferedFileTest, MoveFromTemporaryInCtor) {
|
TEST(BufferedFileTest, MoveFromTemporaryInCtor) {
|
||||||
FILE *fp = 0;
|
FILE *fp = nullptr;
|
||||||
buffered_file f(open_buffered_file(&fp));
|
buffered_file f(open_buffered_file(&fp));
|
||||||
EXPECT_EQ(fp, f.get());
|
EXPECT_EQ(fp, f.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BufferedFileTest, MoveFromTemporaryInAssignment) {
|
TEST(BufferedFileTest, MoveFromTemporaryInAssignment) {
|
||||||
FILE *fp = 0;
|
FILE *fp = nullptr;
|
||||||
buffered_file f;
|
buffered_file f;
|
||||||
f = open_buffered_file(&fp);
|
f = open_buffered_file(&fp);
|
||||||
EXPECT_EQ(fp, f.get());
|
EXPECT_EQ(fp, f.get());
|
||||||
@ -126,7 +126,7 @@ TEST(BufferedFileTest, CloseErrorInDtor) {
|
|||||||
// output in EXPECT_STDERR and the second close will break output
|
// output in EXPECT_STDERR and the second close will break output
|
||||||
// redirection.
|
// redirection.
|
||||||
FMT_POSIX(close(f->fileno()));
|
FMT_POSIX(close(f->fileno()));
|
||||||
SUPPRESS_ASSERT(f.reset());
|
SUPPRESS_ASSERT(f.reset(nullptr));
|
||||||
}, format_system_error(EBADF, "cannot close file") + "\n");
|
}, format_system_error(EBADF, "cannot close file") + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ TEST(BufferedFileTest, Close) {
|
|||||||
buffered_file f = open_buffered_file();
|
buffered_file f = open_buffered_file();
|
||||||
int fd = f.fileno();
|
int fd = f.fileno();
|
||||||
f.close();
|
f.close();
|
||||||
EXPECT_TRUE(f.get() == 0);
|
EXPECT_TRUE(f.get() == nullptr);
|
||||||
EXPECT_TRUE(isclosed(fd));
|
EXPECT_TRUE(isclosed(fd));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ TEST(BufferedFileTest, CloseError) {
|
|||||||
buffered_file f = open_buffered_file();
|
buffered_file f = open_buffered_file();
|
||||||
FMT_POSIX(close(f.fileno()));
|
FMT_POSIX(close(f.fileno()));
|
||||||
EXPECT_SYSTEM_ERROR_NOASSERT(f.close(), EBADF, "cannot close file");
|
EXPECT_SYSTEM_ERROR_NOASSERT(f.close(), EBADF, "cannot close file");
|
||||||
EXPECT_TRUE(f.get() == 0);
|
EXPECT_TRUE(f.get() == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BufferedFileTest, Fileno) {
|
TEST(BufferedFileTest, Fileno) {
|
||||||
@ -209,7 +209,7 @@ TEST(FileTest, MoveAssignmentClosesFile) {
|
|||||||
EXPECT_TRUE(isclosed(old_fd));
|
EXPECT_TRUE(isclosed(old_fd));
|
||||||
}
|
}
|
||||||
|
|
||||||
file OpenBufferedFile(int &fd) {
|
static file OpenBufferedFile(int &fd) {
|
||||||
file f = open_file();
|
file f = open_file();
|
||||||
fd = f.descriptor();
|
fd = f.descriptor();
|
||||||
return f;
|
return f;
|
||||||
@ -253,7 +253,7 @@ TEST(FileTest, CloseErrorInDtor) {
|
|||||||
// output in EXPECT_STDERR and the second close will break output
|
// output in EXPECT_STDERR and the second close will break output
|
||||||
// redirection.
|
// redirection.
|
||||||
FMT_POSIX(close(f->descriptor()));
|
FMT_POSIX(close(f->descriptor()));
|
||||||
SUPPRESS_ASSERT(f.reset());
|
SUPPRESS_ASSERT(f.reset(nullptr));
|
||||||
}, format_system_error(EBADF, "cannot close file") + "\n");
|
}, format_system_error(EBADF, "cannot close file") + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,13 +20,13 @@ using fmt::format_error;
|
|||||||
const unsigned BIG_NUM = INT_MAX + 1u;
|
const unsigned BIG_NUM = INT_MAX + 1u;
|
||||||
|
|
||||||
// Makes format string argument positional.
|
// Makes format string argument positional.
|
||||||
std::string make_positional(fmt::string_view format) {
|
static std::string make_positional(fmt::string_view format) {
|
||||||
std::string s(format.data(), format.size());
|
std::string s(format.data(), format.size());
|
||||||
s.replace(s.find('%'), 1, "%1$");
|
s.replace(s.find('%'), 1, "%1$");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring make_positional(fmt::wstring_view format) {
|
static std::wstring make_positional(fmt::wstring_view format) {
|
||||||
std::wstring s(format.data(), format.size());
|
std::wstring s(format.data(), format.size());
|
||||||
s.replace(s.find(L'%'), 1, L"%1$");
|
s.replace(s.find(L'%'), 1, L"%1$");
|
||||||
return s;
|
return s;
|
||||||
@ -410,7 +410,7 @@ TEST(PrintfTest, Inf) {
|
|||||||
double inf = std::numeric_limits<double>::infinity();
|
double inf = std::numeric_limits<double>::infinity();
|
||||||
for (const char* type = "fega"; *type; ++type) {
|
for (const char* type = "fega"; *type; ++type) {
|
||||||
EXPECT_PRINTF("inf", fmt::format("%{}", *type), inf);
|
EXPECT_PRINTF("inf", fmt::format("%{}", *type), inf);
|
||||||
char upper = std::toupper(*type);
|
char upper = static_cast<char>(std::toupper(*type));
|
||||||
EXPECT_PRINTF("INF", fmt::format("%{}", upper), inf);
|
EXPECT_PRINTF("INF", fmt::format("%{}", upper), inf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -426,11 +426,11 @@ TEST(PrintfTest, Char) {
|
|||||||
|
|
||||||
TEST(PrintfTest, String) {
|
TEST(PrintfTest, String) {
|
||||||
EXPECT_PRINTF("abc", "%s", "abc");
|
EXPECT_PRINTF("abc", "%s", "abc");
|
||||||
const char *null_str = 0;
|
const char *null_str = nullptr;
|
||||||
EXPECT_PRINTF("(null)", "%s", null_str);
|
EXPECT_PRINTF("(null)", "%s", null_str);
|
||||||
EXPECT_PRINTF(" (null)", "%10s", null_str);
|
EXPECT_PRINTF(" (null)", "%10s", null_str);
|
||||||
EXPECT_PRINTF(L"abc", L"%s", L"abc");
|
EXPECT_PRINTF(L"abc", L"%s", L"abc");
|
||||||
const wchar_t *null_wstr = 0;
|
const wchar_t *null_wstr = nullptr;
|
||||||
EXPECT_PRINTF(L"(null)", L"%s", null_wstr);
|
EXPECT_PRINTF(L"(null)", L"%s", null_wstr);
|
||||||
EXPECT_PRINTF(L" (null)", L"%10s", null_wstr);
|
EXPECT_PRINTF(L" (null)", L"%10s", null_wstr);
|
||||||
}
|
}
|
||||||
@ -439,22 +439,22 @@ TEST(PrintfTest, Pointer) {
|
|||||||
int n;
|
int n;
|
||||||
void *p = &n;
|
void *p = &n;
|
||||||
EXPECT_PRINTF(fmt::format("{}", p), "%p", p);
|
EXPECT_PRINTF(fmt::format("{}", p), "%p", p);
|
||||||
p = 0;
|
p = nullptr;
|
||||||
EXPECT_PRINTF("(nil)", "%p", p);
|
EXPECT_PRINTF("(nil)", "%p", p);
|
||||||
EXPECT_PRINTF(" (nil)", "%10p", p);
|
EXPECT_PRINTF(" (nil)", "%10p", p);
|
||||||
const char *s = "test";
|
const char *s = "test";
|
||||||
EXPECT_PRINTF(fmt::format("{:p}", s), "%p", s);
|
EXPECT_PRINTF(fmt::format("{:p}", s), "%p", s);
|
||||||
const char *null_str = 0;
|
const char *null_str = nullptr;
|
||||||
EXPECT_PRINTF("(nil)", "%p", null_str);
|
EXPECT_PRINTF("(nil)", "%p", null_str);
|
||||||
|
|
||||||
p = &n;
|
p = &n;
|
||||||
EXPECT_PRINTF(fmt::format(L"{}", p), L"%p", p);
|
EXPECT_PRINTF(fmt::format(L"{}", p), L"%p", p);
|
||||||
p = 0;
|
p = nullptr;
|
||||||
EXPECT_PRINTF(L"(nil)", L"%p", p);
|
EXPECT_PRINTF(L"(nil)", L"%p", p);
|
||||||
EXPECT_PRINTF(L" (nil)", L"%10p", p);
|
EXPECT_PRINTF(L" (nil)", L"%10p", p);
|
||||||
const wchar_t *w = L"test";
|
const wchar_t *w = L"test";
|
||||||
EXPECT_PRINTF(fmt::format(L"{:p}", w), L"%p", w);
|
EXPECT_PRINTF(fmt::format(L"{:p}", w), L"%p", w);
|
||||||
const wchar_t *null_wstr = 0;
|
const wchar_t *null_wstr = nullptr;
|
||||||
EXPECT_PRINTF(L"(nil)", L"%p", null_wstr);
|
EXPECT_PRINTF(L"(nil)", L"%p", null_wstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#include "fmt/ranges.h"
|
#include "fmt/ranges.h"
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
// For the license information refer to format.h.
|
// For the license information refer to format.h.
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <gtest/gtest.h>
|
#include "gtest.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
#define _CRT_SECURE_NO_WARNINGS
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
#include "gmock.h"
|
||||||
#include "fmt/time.h"
|
#include "fmt/time.h"
|
||||||
|
|
||||||
TEST(TimeTest, Format) {
|
TEST(TimeTest, Format) {
|
||||||
@ -26,7 +26,7 @@ TEST(TimeTest, GrowBuffer) {
|
|||||||
for (int i = 0; i < 30; ++i)
|
for (int i = 0; i < 30; ++i)
|
||||||
s += "%c";
|
s += "%c";
|
||||||
s += "}\n";
|
s += "}\n";
|
||||||
std::time_t t = std::time(0);
|
std::time_t t = std::time(nullptr);
|
||||||
fmt::format(s, *std::localtime(&t));
|
fmt::format(s, *std::localtime(&t));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ TEST(TimeTest, EmptyResult) {
|
|||||||
EXPECT_EQ("", fmt::format("{}", std::tm()));
|
EXPECT_EQ("", fmt::format("{}", std::tm()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EqualTime(const std::tm &lhs, const std::tm &rhs) {
|
static bool EqualTime(const std::tm &lhs, const std::tm &rhs) {
|
||||||
return lhs.tm_sec == rhs.tm_sec &&
|
return lhs.tm_sec == rhs.tm_sec &&
|
||||||
lhs.tm_min == rhs.tm_min &&
|
lhs.tm_min == rhs.tm_min &&
|
||||||
lhs.tm_hour == rhs.tm_hour &&
|
lhs.tm_hour == rhs.tm_hour &&
|
||||||
@ -47,13 +47,13 @@ bool EqualTime(const std::tm &lhs, const std::tm &rhs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TimeTest, LocalTime) {
|
TEST(TimeTest, LocalTime) {
|
||||||
std::time_t t = std::time(0);
|
std::time_t t = std::time(nullptr);
|
||||||
std::tm tm = *std::localtime(&t);
|
std::tm tm = *std::localtime(&t);
|
||||||
EXPECT_TRUE(EqualTime(tm, fmt::localtime(t)));
|
EXPECT_TRUE(EqualTime(tm, fmt::localtime(t)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TimeTest, GMTime) {
|
TEST(TimeTest, GMTime) {
|
||||||
std::time_t t = std::time(0);
|
std::time_t t = std::time(nullptr);
|
||||||
std::tm tm = *std::gmtime(&t);
|
std::tm tm = *std::gmtime(&t);
|
||||||
EXPECT_TRUE(EqualTime(tm, fmt::gmtime(t)));
|
EXPECT_TRUE(EqualTime(tm, fmt::gmtime(t)));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
# include <type_traits>
|
# include <type_traits>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
#include "gmock.h"
|
||||||
#include "gtest-extra.h"
|
#include "gtest-extra.h"
|
||||||
#include "mock-allocator.h"
|
#include "mock-allocator.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@ -71,8 +71,8 @@ struct formatter<Test, Char> {
|
|||||||
};
|
};
|
||||||
FMT_END_NAMESPACE
|
FMT_END_NAMESPACE
|
||||||
|
|
||||||
void CheckForwarding(
|
static void CheckForwarding(
|
||||||
MockAllocator<int> &alloc, AllocatorRef< MockAllocator<int> > &ref) {
|
MockAllocator<int> &alloc, AllocatorRef<MockAllocator<int>> &ref) {
|
||||||
int mem;
|
int mem;
|
||||||
// Check if value_type is properly defined.
|
// Check if value_type is properly defined.
|
||||||
AllocatorRef< MockAllocator<int> >::value_type *ptr = &mem;
|
AllocatorRef< MockAllocator<int> >::value_type *ptr = &mem;
|
||||||
@ -92,7 +92,7 @@ TEST(AllocatorTest, AllocatorRef) {
|
|||||||
TestAllocatorRef ref2(ref);
|
TestAllocatorRef ref2(ref);
|
||||||
CheckForwarding(alloc, ref2);
|
CheckForwarding(alloc, ref2);
|
||||||
TestAllocatorRef ref3;
|
TestAllocatorRef ref3;
|
||||||
EXPECT_EQ(0, ref3.get());
|
EXPECT_EQ(nullptr, ref3.get());
|
||||||
ref3 = ref;
|
ref3 = ref;
|
||||||
CheckForwarding(alloc, ref3);
|
CheckForwarding(alloc, ref3);
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ TEST(BufferTest, Nonmoveable) {
|
|||||||
// A test buffer with a dummy grow method.
|
// A test buffer with a dummy grow method.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct TestBuffer : basic_buffer<T> {
|
struct TestBuffer : basic_buffer<T> {
|
||||||
void grow(std::size_t capacity) { this->set(0, capacity); }
|
void grow(std::size_t capacity) { this->set(nullptr, capacity); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -132,23 +132,23 @@ struct MockBuffer : basic_buffer<T> {
|
|||||||
TEST(BufferTest, Ctor) {
|
TEST(BufferTest, Ctor) {
|
||||||
{
|
{
|
||||||
MockBuffer<int> buffer;
|
MockBuffer<int> buffer;
|
||||||
EXPECT_EQ(0, &buffer[0]);
|
EXPECT_EQ(nullptr, &buffer[0]);
|
||||||
EXPECT_EQ(0u, buffer.size());
|
EXPECT_EQ(static_cast<size_t>(0), buffer.size());
|
||||||
EXPECT_EQ(0u, buffer.capacity());
|
EXPECT_EQ(static_cast<size_t>(0), buffer.capacity());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int dummy;
|
int dummy;
|
||||||
MockBuffer<int> buffer(&dummy);
|
MockBuffer<int> buffer(&dummy);
|
||||||
EXPECT_EQ(&dummy, &buffer[0]);
|
EXPECT_EQ(&dummy, &buffer[0]);
|
||||||
EXPECT_EQ(0u, buffer.size());
|
EXPECT_EQ(static_cast<size_t>(0), buffer.size());
|
||||||
EXPECT_EQ(0u, buffer.capacity());
|
EXPECT_EQ(static_cast<size_t>(0), buffer.capacity());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int dummy;
|
int dummy;
|
||||||
std::size_t capacity = std::numeric_limits<std::size_t>::max();
|
std::size_t capacity = std::numeric_limits<std::size_t>::max();
|
||||||
MockBuffer<int> buffer(&dummy, capacity);
|
MockBuffer<int> buffer(&dummy, capacity);
|
||||||
EXPECT_EQ(&dummy, &buffer[0]);
|
EXPECT_EQ(&dummy, &buffer[0]);
|
||||||
EXPECT_EQ(0u, buffer.size());
|
EXPECT_EQ(static_cast<size_t>(0), buffer.size());
|
||||||
EXPECT_EQ(capacity, buffer.capacity());
|
EXPECT_EQ(capacity, buffer.capacity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,7 +201,7 @@ TEST(BufferTest, Clear) {
|
|||||||
TestBuffer<char> buffer;
|
TestBuffer<char> buffer;
|
||||||
buffer.resize(20);
|
buffer.resize(20);
|
||||||
buffer.resize(0);
|
buffer.resize(0);
|
||||||
EXPECT_EQ(0u, buffer.size());
|
EXPECT_EQ(static_cast<size_t>(0), buffer.size());
|
||||||
EXPECT_EQ(20u, buffer.capacity());
|
EXPECT_EQ(20u, buffer.capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ TEST(BufferTest, AppendAllocatesEnoughStorage) {
|
|||||||
|
|
||||||
TEST(MemoryBufferTest, Ctor) {
|
TEST(MemoryBufferTest, Ctor) {
|
||||||
basic_memory_buffer<char, 123> buffer;
|
basic_memory_buffer<char, 123> buffer;
|
||||||
EXPECT_EQ(0u, buffer.size());
|
EXPECT_EQ(static_cast<size_t>(0), buffer.size());
|
||||||
EXPECT_EQ(123u, buffer.capacity());
|
EXPECT_EQ(123u, buffer.capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ TEST(MemoryBufferTest, Ctor) {
|
|||||||
|
|
||||||
typedef AllocatorRef< std::allocator<char> > TestAllocator;
|
typedef AllocatorRef< std::allocator<char> > TestAllocator;
|
||||||
|
|
||||||
void check_move_buffer(const char *str,
|
static void check_move_buffer(const char *str,
|
||||||
basic_memory_buffer<char, 5, TestAllocator> &buffer) {
|
basic_memory_buffer<char, 5, TestAllocator> &buffer) {
|
||||||
std::allocator<char> *alloc = buffer.get_allocator().get();
|
std::allocator<char> *alloc = buffer.get_allocator().get();
|
||||||
basic_memory_buffer<char, 5, TestAllocator> buffer2(std::move(buffer));
|
basic_memory_buffer<char, 5, TestAllocator> buffer2(std::move(buffer));
|
||||||
@ -248,7 +248,7 @@ void check_move_buffer(const char *str,
|
|||||||
EXPECT_EQ(str, std::string(&buffer2[0], buffer2.size()));
|
EXPECT_EQ(str, std::string(&buffer2[0], buffer2.size()));
|
||||||
EXPECT_EQ(5u, buffer2.capacity());
|
EXPECT_EQ(5u, buffer2.capacity());
|
||||||
// Move should transfer allocator.
|
// Move should transfer allocator.
|
||||||
EXPECT_EQ(0, buffer.get_allocator().get());
|
EXPECT_EQ(nullptr, buffer.get_allocator().get());
|
||||||
EXPECT_EQ(alloc, buffer2.get_allocator().get());
|
EXPECT_EQ(alloc, buffer2.get_allocator().get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +273,7 @@ TEST(MemoryBufferTest, MoveCtor) {
|
|||||||
EXPECT_GT(buffer2.capacity(), 5u);
|
EXPECT_GT(buffer2.capacity(), 5u);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_move_assign_buffer(
|
static void check_move_assign_buffer(
|
||||||
const char *str, basic_memory_buffer<char, 5> &buffer) {
|
const char *str, basic_memory_buffer<char, 5> &buffer) {
|
||||||
basic_memory_buffer<char, 5> buffer2;
|
basic_memory_buffer<char, 5> buffer2;
|
||||||
buffer2 = std::move(buffer);
|
buffer2 = std::move(buffer);
|
||||||
@ -335,7 +335,7 @@ TEST(MemoryBufferTest, Grow) {
|
|||||||
TEST(MemoryBufferTest, Allocator) {
|
TEST(MemoryBufferTest, Allocator) {
|
||||||
typedef AllocatorRef< MockAllocator<char> > TestAllocator;
|
typedef AllocatorRef< MockAllocator<char> > TestAllocator;
|
||||||
basic_memory_buffer<char, 10, TestAllocator> buffer;
|
basic_memory_buffer<char, 10, TestAllocator> buffer;
|
||||||
EXPECT_EQ(0, buffer.get_allocator().get());
|
EXPECT_EQ(nullptr, buffer.get_allocator().get());
|
||||||
StrictMock< MockAllocator<char> > alloc;
|
StrictMock< MockAllocator<char> > alloc;
|
||||||
char mem;
|
char mem;
|
||||||
{
|
{
|
||||||
@ -376,7 +376,7 @@ TEST(MemoryBufferTest, ExceptionInDeallocate) {
|
|||||||
TEST(FixedBufferTest, Ctor) {
|
TEST(FixedBufferTest, Ctor) {
|
||||||
char array[10] = "garbage";
|
char array[10] = "garbage";
|
||||||
fmt::basic_fixed_buffer<char> buffer(array, sizeof(array));
|
fmt::basic_fixed_buffer<char> buffer(array, sizeof(array));
|
||||||
EXPECT_EQ(0u, buffer.size());
|
EXPECT_EQ(static_cast<size_t>(0), buffer.size());
|
||||||
EXPECT_EQ(10u, buffer.capacity());
|
EXPECT_EQ(10u, buffer.capacity());
|
||||||
EXPECT_EQ(array, buffer.data());
|
EXPECT_EQ(array, buffer.data());
|
||||||
}
|
}
|
||||||
@ -384,7 +384,7 @@ TEST(FixedBufferTest, Ctor) {
|
|||||||
TEST(FixedBufferTest, CompileTimeSizeCtor) {
|
TEST(FixedBufferTest, CompileTimeSizeCtor) {
|
||||||
char array[10] = "garbage";
|
char array[10] = "garbage";
|
||||||
fmt::basic_fixed_buffer<char> buffer(array);
|
fmt::basic_fixed_buffer<char> buffer(array);
|
||||||
EXPECT_EQ(0u, buffer.size());
|
EXPECT_EQ(static_cast<size_t>(0), buffer.size());
|
||||||
EXPECT_EQ(10u, buffer.capacity());
|
EXPECT_EQ(10u, buffer.capacity());
|
||||||
EXPECT_EQ(array, buffer.data());
|
EXPECT_EQ(array, buffer.data());
|
||||||
}
|
}
|
||||||
@ -439,7 +439,7 @@ struct custom_context {
|
|||||||
|
|
||||||
const char *format(const T &, custom_context& ctx) {
|
const char *format(const T &, custom_context& ctx) {
|
||||||
ctx.called = true;
|
ctx.called = true;
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -583,8 +583,8 @@ TEST(UtilTest, WStringArg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(UtilTest, PointerArg) {
|
TEST(UtilTest, PointerArg) {
|
||||||
void *p = 0;
|
void *p = nullptr;
|
||||||
const void *cp = 0;
|
const void *cp = nullptr;
|
||||||
CHECK_ARG_(char, cp, p);
|
CHECK_ARG_(char, cp, p);
|
||||||
CHECK_ARG_(wchar_t, cp, p);
|
CHECK_ARG_(wchar_t, cp, p);
|
||||||
CHECK_ARG(cp, );
|
CHECK_ARG(cp, );
|
||||||
@ -772,7 +772,7 @@ TEST(UtilTest, FormatSystemError) {
|
|||||||
fmt::print("warning: std::allocator allocates {} chars", max_size);
|
fmt::print("warning: std::allocator allocates {} chars", max_size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fmt::format_system_error(message, EDOM, fmt::string_view(0, max_size));
|
fmt::format_system_error(message, EDOM, fmt::string_view(nullptr, max_size));
|
||||||
EXPECT_EQ(fmt::format("error {}", EDOM), to_string(message));
|
EXPECT_EQ(fmt::format("error {}", EDOM), to_string(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -868,7 +868,7 @@ TEST(UtilTest, IsEnumConvertibleToInt) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST(UtilTest, ParseNonnegativeInt) {
|
TEST(UtilTest, ParseNonnegativeInt) {
|
||||||
if (std::numeric_limits<int>::max() != (1 << 31)) {
|
if (std::numeric_limits<int>::max() != static_cast<int>(static_cast<unsigned>(1) << 31)) {
|
||||||
fmt::print("Skipping parse_nonnegative_int test\n");
|
fmt::print("Skipping parse_nonnegative_int test\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,7 +35,7 @@ std::string get_system_error(int error_code);
|
|||||||
extern const char *const FILE_CONTENT;
|
extern const char *const FILE_CONTENT;
|
||||||
|
|
||||||
// Opens a buffered file for reading.
|
// Opens a buffered file for reading.
|
||||||
fmt::buffered_file open_buffered_file(FILE **fp = 0);
|
fmt::buffered_file open_buffered_file(FILE **fp = nullptr);
|
||||||
|
|
||||||
inline FILE *safe_fopen(const char *filename, const char *mode) {
|
inline FILE *safe_fopen(const char *filename, const char *mode) {
|
||||||
#if defined(_WIN32) && !defined(__MINGW32__)
|
#if defined(_WIN32) && !defined(__MINGW32__)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user