Use `EXCLUDE_FROM_ALL` in `add_subdirectory` to prevent `make install` from including lots of headers from gtest/gmock.
```
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
```
Add a new RAII MemoryIsNotDeallocated class that excludes memory allocations from Microsoft’s debug CRT leak detection report.
We use this RAII class to silence 2 false positive leaks that are caused by memory allocations that are intentionally never deallocated.
*Background*
The MS debug CRT has a lightweight memory leak detection mechanism that can only detect if a memory allocation is missing a matching deallocation.
Consequently, it will report a false positive leak for memory that’s intentionally never deallocated. For example, memory that’s reachable for the entire lifetime of a app.
Note the MS debug CRT is always tracking memory allocations but the final memory leak report is disabled by default. As you can’t avoid paying for its cost, you may as well use it.
The memory leak report can be enabled by calling the following function
#ifdef _MSC_VER
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
#endif // _MSC_VER
anywhere before exiting main.
For example, the following are the false positive leaks reported before this change;
Detected memory leaks!
Dumping objects ->
{750} normal block at 0x015DF938, 8 bytes long.
Data: < ] > 00 F9 5D 01 00 00 00 00
{749} normal block at 0x015DEE60, 32 bytes long.
Data: <` ] ` ] ` ] > 60 EE 5D 01 60 EE 5D 01 60 EE 5D 01 01 01 CD CD
{748} normal block at 0x015DF900, 12 bytes long.
Data: <8 ] ` ] > 38 F9 5D 01 60 EE 5D 01 00 00 00 00
{747} normal block at 0x015DA0F8, 24 bytes long.
Data: < > FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00
Object dump complete.
As you can see from above it’s not easy to identify the above are false positives. Consequently, if false positive leaks are not fixed or silenced, then it becomes impractical to identify real memory leaks.
Re-use existing background color for Widows' console window.
This fixes a problem where the background color for ColoredPrintf would be BLACK even if the user's console is using a different BG color.
The mechanics of suppressing debugger trapping and Windows Error Reporting for the crashed child process in a death test are currently guarded under the `GTEST_HAS_SEH` macro. This seems unnecessary, as the logic does not call any APIs related to Structured Error Handling.
Replace the guarding macro with the more permissive `GTEST_OS_WINDOWS`, so that Windows toolchains without SEH support (e.g. MinGW) can benefit from it.
Fixes: #1116
This merges a Google-internal change (117235625).
Original CL description:
This CL was created manually in about an hour with sed, a Python script
to find all the places unqualified 'string' was mentioned, and some help
from Emacs to add the "std::" qualifications, plus a few manual tweaks.
This upstreams a Google-internal change.
Original CL description:
The C++ standard says that function pointers are not implicitly
convertible to object pointers. Visual Studio disregards that and allows
implicit conversion between function pointers and object points, and
enough code relies on this that clang follows suit in
Microsoft-compatibility mode.
However, clang emits a -Wmicrosoft-cast warning when such a conversion
is done:
E:\b\c\b\win_clang\src\sandbox\win\src\sync_dispatcher.cc(42,7):
warning: implicit conversion between pointer-to-function and
pointer-to-object is a Microsoft extension [-Wmicrosoft-cast]
This change fixes this warning in gtest, while hopefully not changing
any behavior. The change does two things:
1. It replaces the if in DefaultPrintTo with SFINAE
2. In C++11 mode, it uses enable_if<is_function<>> instead of
ImplicitlyConvertible<T*, const void*> to check if the
explicit cast is needed.
With this change, functions will use the branch with the reintpret_casts
with Visual Studio and clang/win, and clang no longer needs to warn
that it implicitly converts a function pointer to a void pointer.
Fixes the following errors:
hash_map(17): error C2338: <hash_map> is deprecated and will be REMOVED. Please use <unordered_map>. You can define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS to acknowledge that you have received this warning. [googlemock\gtest\gtest-printers_test.vcxproj]
hash_set(17): error C2338: <hash_set> is deprecated and will be REMOVED. Please use <unordered_set>. You can define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS to acknowledge that you have received this warning. [googlemock\gtest\gtest-printers_test.vcxproj]
googletest\test\gtest_catch_exceptions_test_.cc(152): error C2220: warning treated as error - no 'object' file generated
googletest\test\gtest_catch_exceptions_test_.cc(152): warning C4297: 'CxxExceptionInDestructorTest::~CxxExceptionInDestructorTest': function assumed not to throw an exception but does
googletest\test\gtest_catch_exceptions_test_.cc(152): note: destructor or deallocator has a (possibly implicit) non-throwing exception specification
There were already some checks for _MSC_VER in the code, so this commit
continues in that vein.
`gtest-config --version` reports wrong version.
Made against master branch but please note that this affects tag release-1.8.0 and the distribution tarballs.
If REGISTER_TYPED_TEST_CASE_P is included in a header file, but
the .cc file does not declare INSTANTIATE_TYPED_TEST_CASE_P, an
unused-variable warning may be raised by the compiler.
googletest doesn't currently build with clang's very aggressive
-Wformat-nonliteral warning. It requires that all non-literal format
strings come from the argument of a function annotated with a compatible
format attribute.
Fixing that reports that ColoredPrintf's callers weren't passing the
normal -Wformat warning. Some messages were passed directly into the
format string rather than via "%s".
Adds instructions for how to add gtest and gmock to
another CMake project directly. Downloading of the
googletest sources happens as configure time, allowing
it to be added to the main build directly via the
add_subdirectory() command. This ensures googletest is
built with the same compiler settings, etc. and will
typically result in a more robust and more convenient
build arrangement.
Replaced legacy syntax of cmake add_test() with more modern syntax.
This allows running gtests's own tests on remote (cross) systems
using CMAKE_CROSSCOMPILING_EMULATOR with cmake-3.3 or newer.
If $XML_OUTPUT_FILE is set, and $GTEST_OUTPUT and --gtest_output are not
specified, produce output as if GTEST_OUTPUT=xml:$XML_OUTPUT_FILE had
been set.
Put occurrences of "#include" in a code span so they are not interpreted
as headers.
Other documents were not broken because the #include was not at the
start of the line, but put them in code spans anyway just in case the
text gets refilled in the future.
This fixes these warnings:
…\gtest\googletest\test\gtest-port_test.cc(78) : error C2220: warning treated as error - no 'object' file generated
…\gtest\googletest\test\gtest-port_test.cc(78) : warning C4309: 'static_cast' : truncation of constant value
…\gtest\googletest\test\gtest-port_test.cc(79) : warning C4309: 'static_cast' : truncation of constant value
…\gtest\googlemock\test\gmock-matchers_test.cc(2712) : error C2220: warning treated as error - no 'object' file generated
…\gtest\googlemock\test\gmock-matchers_test.cc(2706) : while compiling class template member function 'testing::gmock_matchers_test::FloatingPointTest<float>::FloatingPointTest(void)'
…\gtest\googlemock\test\gmock-matchers_test.cc(2896) : see reference to function template instantiation 'testing::gmock_matchers_test::FloatingPointTest<float>::FloatingPointTest(void)' being compiled
…\gtest\googlemock\test\gmock-matchers_test.cc(2896) : see reference to class template instantiation 'testing::gmock_matchers_test::FloatingPointTest<float>' being compiled
…\gtest\googlemock\test\gmock-matchers_test.cc(2712) : warning C4267: 'argument' : conversion from 'size_t' to 'const unsigned int', possible loss of data
…\gtest\googlemock\test\gmock-matchers_test.cc(2714) : warning C4267: 'argument' : conversion from 'size_t' to 'const unsigned int', possible loss of data
…\gtest\googlemock\test\gmock-matchers_test.cc(2716) : warning C4267: 'argument' : conversion from 'size_t' to 'const unsigned int', possible loss of data
…\gtest\googlemock\test\gmock-matchers_test.cc(2717) : warning C4267: 'argument' : conversion from 'size_t' to 'const unsigned int', possible loss of data
…\gtest\googlemock\test\gmock-matchers_test.cc(2718) : warning C4267: 'argument' : conversion from 'size_t' to 'const unsigned int', possible loss of data
…\gtest\googlemock\test\gmock-matchers_test.cc(2721) : warning C4267: 'argument' : conversion from 'size_t' to 'const unsigned int', possible loss of data
…\gtest\googlemock\test\gmock-matchers_test.cc(2723) : warning C4267: 'argument' : conversion from 'size_t' to 'const unsigned int', possible loss of data
When this option is set gtest itself is built with -fvisibility=hidden
with gcc and clang. This replicates MSVC's default behaviour with gcc
and clang.
Project file contained the 'README' instead of 'README.md'
that's why the build failed with the fact that it can't
copy this file for its proper location.
Signed-off-by: Gergő Nagy <gergo@getcodie.com>