diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6ab80dee862d..a769419ac0a0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,44 +1,11 @@ -#------------------------------------------------------------------------------ -# Build the google test library - -# We compile Google Test ourselves instead of using pre-compiled libraries. -# See the Google Test FAQ "Why is it not recommended to install a -# pre-compiled copy of Google Test (for example, into /usr/local)?" -# at http://code.google.com/p/googletest/wiki/FAQ for more details. -add_library(gmock STATIC - 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_include_directories(gmock SYSTEM PUBLIC . gmock gtest) - -find_package(Threads) -if (Threads_FOUND) - target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT}) -else () - target_compile_definitions(gmock PUBLIC GTEST_HAS_PTHREAD=0) -endif () - -target_compile_definitions(gmock PUBLIC GTEST_LANG_CXX11=1) - -if (MSVC) - # Disable MSVC warnings of _CRT_INSECURE_DEPRECATE functions. - target_compile_definitions(gmock PRIVATE _CRT_SECURE_NO_WARNINGS) - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # Disable MSVC warnings of POSIX functions. - target_compile_options(gmock PUBLIC -Wno-deprecated-declarations) - endif () -endif () - -# Silence MSVC tr1 deprecation warning in gmock. -target_compile_definitions(gmock - PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING=1) +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_include_directories(test-main SYSTEM PUBLIC gtest gmock) -target_link_libraries(test-main gmock fmt) +target_link_libraries(test-main gtest fmt) include(CheckCXXCompilerFlag) @@ -75,7 +42,6 @@ function(add_fmt_test name) if (FMT_WERROR) target_compile_options(${name} PRIVATE ${WERROR_FLAG}) endif () - target_include_directories(${name} SYSTEM PUBLIC gtest gmock) add_test(NAME ${name} COMMAND ${name}) endfunction() @@ -122,8 +88,7 @@ if (NOT MSVC_STATIC_RUNTIME) posix-mock-test.cc ../src/format.cc ${TEST_MAIN_SRC}) target_include_directories( posix-mock-test PRIVATE ${PROJECT_SOURCE_DIR}/include) - target_link_libraries(posix-mock-test gmock) - target_include_directories(posix-mock-test SYSTEM PUBLIC gtest gmock) + target_link_libraries(posix-mock-test gtest) if (FMT_PEDANTIC) target_compile_options(posix-mock-test PRIVATE ${PEDANTIC_COMPILE_FLAGS}) endif () @@ -136,8 +101,7 @@ endif () add_fmt_executable(header-only-test header-only-test.cc header-only-test2.cc test-main.cc) -target_link_libraries(header-only-test gmock) -target_include_directories(header-only-test SYSTEM PUBLIC gtest gmock) +target_link_libraries(header-only-test gtest) if (TARGET fmt-header-only) target_link_libraries(header-only-test fmt-header-only) else () diff --git a/test/args-test.cc b/test/args-test.cc index 3fa4f70dd82e..a7421bc5299d 100644 --- a/test/args-test.cc +++ b/test/args-test.cc @@ -7,7 +7,7 @@ #include "fmt/args.h" -#include "gtest.h" +#include "gtest/gtest.h" TEST(args_test, basic) { auto store = fmt::dynamic_format_arg_store(); diff --git a/test/assert-test.cc b/test/assert-test.cc index d2e5dd07dbbb..c74e617e68f3 100644 --- a/test/assert-test.cc +++ b/test/assert-test.cc @@ -10,7 +10,7 @@ // For the license information refer to format.h. #include "fmt/core.h" -#include "gtest.h" +#include "gtest/gtest.h" TEST(assert_test, fail) { #if GTEST_HAS_DEATH_TEST diff --git a/test/compile-test.cc b/test/compile-test.cc index 56056ec4b53f..8d015ccbe6fc 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -15,7 +15,7 @@ #include "fmt/chrono.h" #include "fmt/compile.h" -#include "gmock.h" +#include "gmock/gmock.h" #include "gtest-extra.h" #include "util.h" diff --git a/test/core-test.cc b/test/core-test.cc index 3df04618e33f..d5a70291429b 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -20,7 +20,7 @@ #include // std::string #include // std::is_same -#include "gmock.h" +#include "gmock/gmock.h" #if defined(FMT_COMPILE_TIME_CHECKS) && FMT_COMPILE_TIME_CHECKS # include "fmt/format.h" diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index 201aa03b2914..c332a8c2415b 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -15,7 +15,7 @@ #include "../src/format.cc" #include "fmt/printf.h" -#include "gmock.h" +#include "gmock/gmock.h" #include "gtest-extra.h" #include "util.h" diff --git a/test/format-test.cc b/test/format-test.cc index 1145ac3adfcd..429cd437aa82 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -30,7 +30,7 @@ #undef index -#include "gmock.h" +#include "gmock/gmock.h" #include "gtest-extra.h" #include "mock-allocator.h" #include "util.h" diff --git a/test/gtest-extra.h b/test/gtest-extra.h index 01c70ddbf06d..001155ab1f6f 100644 --- a/test/gtest-extra.h +++ b/test/gtest-extra.h @@ -11,7 +11,7 @@ #include #include "fmt/os.h" -#include "gmock.h" +#include "gmock/gmock.h" #define FMT_TEST_THROW_(statement, expected_exception, expected_message, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ diff --git a/test/gtest/.clang-format b/test/gtest/.clang-format new file mode 100644 index 000000000000..ec09b9b6bb1a --- /dev/null +++ b/test/gtest/.clang-format @@ -0,0 +1,3 @@ +# Disable clang-format here +DisableFormat: true +SortIncludes: Never diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt new file mode 100644 index 000000000000..1282d62afac6 --- /dev/null +++ b/test/gtest/CMakeLists.txt @@ -0,0 +1,31 @@ +#------------------------------------------------------------------------------ +# Build the google test library + +# We compile Google Test ourselves instead of using pre-compiled libraries. +# See the Google Test FAQ "Why is it not recommended to install a +# pre-compiled copy of Google Test (for example, into /usr/local)?" +# at http://code.google.com/p/googletest/wiki/FAQ for more details. +add_library(gtest STATIC + gmock-gtest-all.cc gmock/gmock.h gtest/gtest.h gtest/gtest-spi.h) +target_compile_definitions(gtest PUBLIC GTEST_HAS_STD_WSTRING=1) +target_include_directories(gtest SYSTEM PUBLIC .) + +find_package(Threads) +if (Threads_FOUND) + target_link_libraries(gtest ${CMAKE_THREAD_LIBS_INIT}) +else () + target_compile_definitions(gtest PUBLIC GTEST_HAS_PTHREAD=0) +endif () + +if (MSVC) + # Disable MSVC warnings of _CRT_INSECURE_DEPRECATE functions. + target_compile_definitions(gtest PRIVATE _CRT_SECURE_NO_WARNINGS) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Disable MSVC warnings of POSIX functions. + target_compile_options(gtest PUBLIC -Wno-deprecated-declarations) + endif () +endif () + +# Silence MSVC tr1 deprecation warning in gmock. +target_compile_definitions(gtest + PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING=1) diff --git a/test/gmock-gtest-all.cc b/test/gtest/gmock-gtest-all.cc similarity index 100% rename from test/gmock-gtest-all.cc rename to test/gtest/gmock-gtest-all.cc diff --git a/test/gmock/gmock.h b/test/gtest/gmock/gmock.h similarity index 100% rename from test/gmock/gmock.h rename to test/gtest/gmock/gmock.h diff --git a/test/gtest/gtest-spi.h b/test/gtest/gtest/gtest-spi.h similarity index 100% rename from test/gtest/gtest-spi.h rename to test/gtest/gtest/gtest-spi.h diff --git a/test/gtest/gtest.h b/test/gtest/gtest/gtest.h similarity index 99% rename from test/gtest/gtest.h rename to test/gtest/gtest/gtest.h index a3c845334934..55a31d0a87dc 100644 --- a/test/gtest/gtest.h +++ b/test/gtest/gtest/gtest.h @@ -6336,6 +6336,14 @@ struct SharedPayload : SharedPayloadBase { T value; }; +template +using is_trivially_copy_constructible = +#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5 + std::has_trivial_copy_constructor; +#else + std::is_trivially_copy_constructible; +#endif + // An internal class for implementing Matcher, which will derive // from it. We put functionalities common to all Matcher // specializations here to avoid code duplication. @@ -6509,7 +6517,7 @@ class MatcherBase : private MatcherDescriberInterface { template static constexpr bool IsInlined() { return sizeof(M) <= sizeof(Buffer) && alignof(M) <= alignof(Buffer) && - std::is_pod::value && + is_trivially_copy_constructible::value && std::is_trivially_destructible::value; } diff --git a/test/locale-test.cc b/test/locale-test.cc index db55923dce98..2ae9b3bcb940 100644 --- a/test/locale-test.cc +++ b/test/locale-test.cc @@ -9,7 +9,7 @@ #include -#include "gmock.h" +#include "gmock/gmock.h" using fmt::detail::max_value; diff --git a/test/mock-allocator.h b/test/mock-allocator.h index 513a62e8bb32..d821bca4c133 100644 --- a/test/mock-allocator.h +++ b/test/mock-allocator.h @@ -9,7 +9,7 @@ #define FMT_MOCK_ALLOCATOR_H_ #include "fmt/format.h" -#include "gmock.h" +#include "gmock/gmock.h" template class mock_allocator { public: diff --git a/test/ostream-test.cc b/test/ostream-test.cc index 68094222fc71..f97dd37f93f1 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -24,7 +24,7 @@ template <> struct formatter : formatter { #include "fmt/ostream.h" #include "fmt/ranges.h" -#include "gmock.h" +#include "gmock/gmock.h" #include "gtest-extra.h" #include "util.h" diff --git a/test/posix-mock-test.cc b/test/posix-mock-test.cc index a9711c8788ee..a40fbce9caca 100644 --- a/test/posix-mock-test.cc +++ b/test/posix-mock-test.cc @@ -26,7 +26,7 @@ # undef ERROR #endif -#include "gmock.h" +#include "gmock/gmock.h" #include "gtest-extra.h" #include "util.h" diff --git a/test/ranges-test.cc b/test/ranges-test.cc index 8fee3e14e6b8..c03966499d72 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -16,7 +16,7 @@ #include #include -#include "gtest.h" +#include "gtest/gtest.h" #if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 601 # define FMT_RANGES_TEST_ENABLE_C_STYLE_ARRAY diff --git a/test/scan-test.cc b/test/scan-test.cc index 962de54c878d..dcac93375a42 100644 --- a/test/scan-test.cc +++ b/test/scan-test.cc @@ -11,7 +11,7 @@ #include -#include "gmock.h" +#include "gmock/gmock.h" #include "gtest-extra.h" TEST(ScanTest, ReadText) { diff --git a/test/std-format-test.cc b/test/std-format-test.cc index 916a7c5ed3a2..7b51a6ec50b8 100644 --- a/test/std-format-test.cc +++ b/test/std-format-test.cc @@ -1,6 +1,6 @@ #include -#include "gtest.h" +#include "gtest/gtest.h" TEST(StdFormatTest, Escaping) { using namespace std; diff --git a/test/test-assert.h b/test/test-assert.h index 3406e1ba3ddb..da0ac321cb03 100644 --- a/test/test-assert.h +++ b/test/test-assert.h @@ -10,7 +10,7 @@ #include -#include "gtest.h" +#include "gtest/gtest.h" class assertion_failure : public std::logic_error { public: diff --git a/test/test-main.cc b/test/test-main.cc index 8db257d60ba4..b69cc5002c35 100644 --- a/test/test-main.cc +++ b/test/test-main.cc @@ -7,7 +7,7 @@ #include -#include "gtest.h" +#include "gtest/gtest.h" #ifdef _WIN32 # include