Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GTest/GMock structure, apply some fixes #2256

Merged
merged 4 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 4 additions & 40 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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 ()
Expand All @@ -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 ()
Expand Down
2 changes: 1 addition & 1 deletion test/args-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<fmt::format_context>();
Expand Down
2 changes: 1 addition & 1 deletion test/assert-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/compile-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion test/core-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <string> // std::string
#include <type_traits> // std::is_same

#include "gmock.h"
#include "gmock/gmock.h"

#if defined(FMT_COMPILE_TIME_CHECKS) && FMT_COMPILE_TIME_CHECKS
# include "fmt/format.h"
Expand Down
2 changes: 1 addition & 1 deletion test/format-impl-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#undef index

#include "gmock.h"
#include "gmock/gmock.h"
#include "gtest-extra.h"
#include "mock-allocator.h"
#include "util.h"
Expand Down
2 changes: 1 addition & 1 deletion test/gtest-extra.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <string>

#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_ \
Expand Down
3 changes: 3 additions & 0 deletions test/gtest/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Disable clang-format here
DisableFormat: true
SortIncludes: Never
31 changes: 31 additions & 0 deletions test/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 9 additions & 1 deletion test/gtest/gtest.h → test/gtest/gtest/gtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -6336,6 +6336,14 @@ struct SharedPayload : SharedPayloadBase {
T value;
};

template <typename T>
using is_trivially_copy_constructible =
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5
std::has_trivial_copy_constructor<T>;
#else
std::is_trivially_copy_constructible<T>;
#endif

// An internal class for implementing Matcher<T>, which will derive
// from it. We put functionalities common to all Matcher<T>
// specializations here to avoid code duplication.
Expand Down Expand Up @@ -6509,7 +6517,7 @@ class MatcherBase : private MatcherDescriberInterface {
template <typename M>
static constexpr bool IsInlined() {
return sizeof(M) <= sizeof(Buffer) && alignof(M) <= alignof(Buffer) &&
std::is_pod<M>::value &&
is_trivially_copy_constructible<M>::value &&
std::is_trivially_destructible<M>::value;
}

Expand Down
2 changes: 1 addition & 1 deletion test/locale-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <complex>

#include "gmock.h"
#include "gmock/gmock.h"

using fmt::detail::max_value;

Expand Down
2 changes: 1 addition & 1 deletion test/mock-allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define FMT_MOCK_ALLOCATOR_H_

#include "fmt/format.h"
#include "gmock.h"
#include "gmock/gmock.h"

template <typename T> class mock_allocator {
public:
Expand Down
2 changes: 1 addition & 1 deletion test/ostream-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ template <> struct formatter<test> : formatter<int> {

#include "fmt/ostream.h"
#include "fmt/ranges.h"
#include "gmock.h"
#include "gmock/gmock.h"
#include "gtest-extra.h"
#include "util.h"

Expand Down
2 changes: 1 addition & 1 deletion test/posix-mock-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# undef ERROR
#endif

#include "gmock.h"
#include "gmock/gmock.h"
#include "gtest-extra.h"
#include "util.h"

Expand Down
2 changes: 1 addition & 1 deletion test/ranges-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <string>
#include <vector>

#include "gtest.h"
#include "gtest/gtest.h"

#if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 601
# define FMT_RANGES_TEST_ENABLE_C_STYLE_ARRAY
Expand Down
2 changes: 1 addition & 1 deletion test/scan-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <climits>

#include "gmock.h"
#include "gmock/gmock.h"
#include "gtest-extra.h"

TEST(ScanTest, ReadText) {
Expand Down
2 changes: 1 addition & 1 deletion test/std-format-test.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <format>

#include "gtest.h"
#include "gtest/gtest.h"

TEST(StdFormatTest, Escaping) {
using namespace std;
Expand Down
2 changes: 1 addition & 1 deletion test/test-assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <stdexcept>

#include "gtest.h"
#include "gtest/gtest.h"

class assertion_failure : public std::logic_error {
public:
Expand Down
2 changes: 1 addition & 1 deletion test/test-main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <cstdlib>

#include "gtest.h"
#include "gtest/gtest.h"

#ifdef _WIN32
# include <windows.h>
Expand Down