0
0
mirror of https://github.com/google/googletest.git synced 2025-03-12 11:01:01 +00:00

Merge branch 'google:main' into feat/qn9090

This commit is contained in:
Chris Johnson 2023-06-22 12:01:48 -05:00 committed by GitHub
commit b2a2d36f3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 151 additions and 199 deletions

4
.gitignore vendored
View File

@ -24,6 +24,10 @@ Win32-Release/
x64-Debug/ x64-Debug/
x64-Release/ x64-Release/
# VSCode files
.cache/
cmake-variants.yaml
# Ignore autoconf / automake files # Ignore autoconf / automake files
Makefile.in Makefile.in
aclocal.m4 aclocal.m4

View File

@ -1,19 +1,7 @@
# Note: CMake support is community-based. The maintainers do not use CMake # Note: CMake support is community-based. The maintainers do not use CMake
# internally. # internally.
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.13)
if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif (POLICY CMP0048)
if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif (POLICY CMP0069)
if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif (POLICY CMP0077)
project(googletest-distribution) project(googletest-distribution)
set(GOOGLETEST_VERSION 1.13.0) set(GOOGLETEST_VERSION 1.13.0)

View File

@ -27,8 +27,8 @@ The 1.13.x branch requires at least C++14.
#### Continuous Integration #### Continuous Integration
We use Google's internal systems for continuous integration. \ We use Google's internal systems for continuous integration. \
GitHub Actions were added for the convenience of open source contributors. They GitHub Actions were added for the convenience of open-source contributors. They
are exclusively maintained by the open source community and not used by the are exclusively maintained by the open-source community and not used by the
GoogleTest team. GoogleTest team.
#### Coming Soon #### Coming Soon
@ -52,40 +52,39 @@ documentation. We recommend starting with the
More information about building GoogleTest can be found at More information about building GoogleTest can be found at
[googletest/README.md](googletest/README.md). [googletest/README.md](googletest/README.md).
| Feature | Description | ## Features
| ---------------------------- | --------------------------------------------- |
| xUnit test framework | Googletest is based on the | * xUnit test framework: \
: : [xUnit](https\://en.wikipedia.org/wiki/XUnit) : Googletest is based on the [xUnit](https://en.wikipedia.org/wiki/XUnit)
: : testing framework, a popular architecture for : testing framework, a popular architecture for unit testing
: : unit testing : * Test discovery: \
| Test discovery | Googletest automatically discovers and runs | Googletest automatically discovers and runs your tests, eliminating the need
: : your tests, eliminating the need to manually : to manually register your tests
: : register your tests : * Rich set of assertions: \
| Rich set of assertions | Googletest provides a variety of assertions, | Googletest provides a variety of assertions, such as equality, inequality,
: : such as equality, inequality, exceptions, and : exceptions, and more, making it easy to test your code
: : more, making it easy to test your code : * User-defined assertions: \
| User-defined assertions | You can define your own assertions with | You can define your own assertions with Googletest, making it simple to
: : Googletest, making it simple to write tests : write tests that are specific to your code
: : that are specific to your code : * Death tests: \
| Death tests | Googletest supports death tests, which verify | Googletest supports death tests, which verify that your code exits in a
: : that your code exits in a certain way, making : certain way, making it useful for testing error-handling code
: : it useful for testing error-handling code : * Fatal and non-fatal failures: \
| Fatal and non-fatal failures | You can specify whether a test failure should | You can specify whether a test failure should be treated as fatal or
: : be treated as fatal or non-fatal with : non-fatal with Googletest, allowing tests to continue running even if a
: : Googletest, allowing tests to continue : failure occurs
: : running even if a failure occurs : * Value-parameterized tests: \
| Value-parameterized tests | Googletest supports value-parameterized | Googletest supports value-parameterized tests, which run multiple times with
: : tests, which run multiple times with : different input values, making it useful for testing functions that take
: : different input values, making it useful for : different inputs
: : testing functions that take different inputs : * Type-parameterized tests: \
| Type-parameterized tests | Googletest also supports type-parameterized | Googletest also supports type-parameterized tests, which run with different
: : tests, which run with different data types, : data types, making it useful for testing functions that work with different
: : making it useful for testing functions that : data types
: : work with different data types : * Various options for running tests: \
| Various options for running | Googletest provides many options for running | Googletest provides many options for running tests including running
: tests : tests, including running individual tests, : individual tests, running tests in a specific order and running tests in
: : running tests in a specific order, and : parallel
: : running tests in parallel :
## Supported Platforms ## Supported Platforms
@ -93,7 +92,7 @@ GoogleTest follows Google's
[Foundational C++ Support Policy](https://opensource.google/documentation/policies/cplusplus-support). [Foundational C++ Support Policy](https://opensource.google/documentation/policies/cplusplus-support).
See See
[this table](https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md) [this table](https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md)
for a list of currently supported versions compilers, platforms, and build for a list of currently supported versions of compilers, platforms, and build
tools. tools.
## Who Is Using GoogleTest? ## Who Is Using GoogleTest?

View File

@ -697,9 +697,9 @@ TEST(AbcTest, Xyz) {
EXPECT_CALL(foo, DoThat(_, _)); EXPECT_CALL(foo, DoThat(_, _));
int n = 0; int n = 0;
EXPECT_EQ('+', foo.DoThis(5)); // FakeFoo::DoThis() is invoked. EXPECT_EQ(foo.DoThis(5), '+'); // FakeFoo::DoThis() is invoked.
foo.DoThat("Hi", &n); // FakeFoo::DoThat() is invoked. foo.DoThat("Hi", &n); // FakeFoo::DoThat() is invoked.
EXPECT_EQ(2, n); EXPECT_EQ(n, 2);
} }
``` ```
@ -1129,11 +1129,11 @@ using STL's `<functional>` header is just painful). For example, here's a
predicate that's satisfied by any number that is >= 0, <= 100, and != 50: predicate that's satisfied by any number that is >= 0, <= 100, and != 50:
```cpp ```cpp
using testing::AllOf; using ::testing::AllOf;
using testing::Ge; using ::testing::Ge;
using testing::Le; using ::testing::Le;
using testing::Matches; using ::testing::Matches;
using testing::Ne; using ::testing::Ne;
... ...
Matches(AllOf(Ge(0), Le(100), Ne(50))) Matches(AllOf(Ge(0), Le(100), Ne(50)))
``` ```
@ -1861,7 +1861,7 @@ error. So, what shall you do?
Though you may be tempted, DO NOT use `std::ref()`: Though you may be tempted, DO NOT use `std::ref()`:
```cpp ```cpp
using testing::Return; using ::testing::Return;
class MockFoo : public Foo { class MockFoo : public Foo {
public: public:
@ -1873,7 +1873,7 @@ class MockFoo : public Foo {
EXPECT_CALL(foo, GetValue()) EXPECT_CALL(foo, GetValue())
.WillRepeatedly(Return(std::ref(x))); // Wrong! .WillRepeatedly(Return(std::ref(x))); // Wrong!
x = 42; x = 42;
EXPECT_EQ(42, foo.GetValue()); EXPECT_EQ(foo.GetValue(), 42);
``` ```
Unfortunately, it doesn't work here. The above code will fail with error: Unfortunately, it doesn't work here. The above code will fail with error:
@ -1895,14 +1895,14 @@ the expectation is set, and `Return(std::ref(x))` will always return 0.
returns the value pointed to by `pointer` at the time the action is *executed*: returns the value pointed to by `pointer` at the time the action is *executed*:
```cpp ```cpp
using testing::ReturnPointee; using ::testing::ReturnPointee;
... ...
int x = 0; int x = 0;
MockFoo foo; MockFoo foo;
EXPECT_CALL(foo, GetValue()) EXPECT_CALL(foo, GetValue())
.WillRepeatedly(ReturnPointee(&x)); // Note the & here. .WillRepeatedly(ReturnPointee(&x)); // Note the & here.
x = 42; x = 42;
EXPECT_EQ(42, foo.GetValue()); // This will succeed now. EXPECT_EQ(foo.GetValue(), 42); // This will succeed now.
``` ```
### Combining Actions ### Combining Actions
@ -2264,7 +2264,7 @@ TEST_F(FooTest, Test) {
EXPECT_CALL(foo, DoThis(2)) EXPECT_CALL(foo, DoThis(2))
.WillOnce(Invoke(NewPermanentCallback(SignOfSum, 5))); .WillOnce(Invoke(NewPermanentCallback(SignOfSum, 5)));
EXPECT_EQ('+', foo.DoThis(2)); // Invokes SignOfSum(5, 2). EXPECT_EQ(foo.DoThis(2), '+'); // Invokes SignOfSum(5, 2).
} }
``` ```
@ -2771,11 +2771,13 @@ returns a null `unique_ptr`, thats what youll get if you dont specify a
action: action:
```cpp ```cpp
using ::testing::IsNull;
...
// Use the default action. // Use the default action.
EXPECT_CALL(mock_buzzer_, MakeBuzz("hello")); EXPECT_CALL(mock_buzzer_, MakeBuzz("hello"));
// Triggers the previous EXPECT_CALL. // Triggers the previous EXPECT_CALL.
EXPECT_EQ(nullptr, mock_buzzer_.MakeBuzz("hello")); EXPECT_THAT(mock_buzzer_.MakeBuzz("hello"), IsNull());
``` ```
If you are not happy with the default action, you can tweak it as usual; see If you are not happy with the default action, you can tweak it as usual; see
@ -3194,9 +3196,9 @@ flag. For example, given the test program:
```cpp ```cpp
#include "gmock/gmock.h" #include "gmock/gmock.h"
using testing::_; using ::testing::_;
using testing::HasSubstr; using ::testing::HasSubstr;
using testing::Return; using ::testing::Return;
class MockFoo { class MockFoo {
public: public:
@ -3817,15 +3819,15 @@ If the built-in actions don't work for you, you can easily define your own one.
All you need is a call operator with a signature compatible with the mocked All you need is a call operator with a signature compatible with the mocked
function. So you can use a lambda: function. So you can use a lambda:
``` ```cpp
MockFunction<int(int)> mock; MockFunction<int(int)> mock;
EXPECT_CALL(mock, Call).WillOnce([](const int input) { return input * 7; }); EXPECT_CALL(mock, Call).WillOnce([](const int input) { return input * 7; });
EXPECT_EQ(14, mock.AsStdFunction()(2)); EXPECT_EQ(mock.AsStdFunction()(2), 14);
``` ```
Or a struct with a call operator (even a templated one): Or a struct with a call operator (even a templated one):
``` ```cpp
struct MultiplyBy { struct MultiplyBy {
template <typename T> template <typename T>
T operator()(T arg) { return arg * multiplier; } T operator()(T arg) { return arg * multiplier; }
@ -3840,16 +3842,16 @@ struct MultiplyBy {
It's also fine for the callable to take no arguments, ignoring the arguments It's also fine for the callable to take no arguments, ignoring the arguments
supplied to the mock function: supplied to the mock function:
``` ```cpp
MockFunction<int(int)> mock; MockFunction<int(int)> mock;
EXPECT_CALL(mock, Call).WillOnce([] { return 17; }); EXPECT_CALL(mock, Call).WillOnce([] { return 17; });
EXPECT_EQ(17, mock.AsStdFunction()(0)); EXPECT_EQ(mock.AsStdFunction()(0), 17);
``` ```
When used with `WillOnce`, the callable can assume it will be called at most When used with `WillOnce`, the callable can assume it will be called at most
once and is allowed to be a move-only type: once and is allowed to be a move-only type:
``` ```cpp
// An action that contains move-only types and has an &&-qualified operator, // An action that contains move-only types and has an &&-qualified operator,
// demanding in the type system that it be called at most once. This can be // demanding in the type system that it be called at most once. This can be
// used with WillOnce, but the compiler will reject it if handed to // used with WillOnce, but the compiler will reject it if handed to

View File

@ -19,19 +19,15 @@ examples here we assume you want to compile the sample
Using `pkg-config` in CMake is fairly easy: Using `pkg-config` in CMake is fairly easy:
```cmake ```cmake
cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0048 NEW)
project(my_gtest_pkgconfig VERSION 0.0.1 LANGUAGES CXX)
find_package(PkgConfig) find_package(PkgConfig)
pkg_search_module(GTEST REQUIRED gtest_main) pkg_search_module(GTEST REQUIRED gtest_main)
add_executable(testapp samples/sample3_unittest.cc) add_executable(testapp)
target_link_libraries(testapp ${GTEST_LDFLAGS}) target_sources(testapp PRIVATE samples/sample3_unittest.cc)
target_compile_options(testapp PUBLIC ${GTEST_CFLAGS}) target_link_libraries(testapp PRIVATE ${GTEST_LDFLAGS})
target_compile_options(testapp PRIVATE ${GTEST_CFLAGS})
include(CTest) enable_testing()
add_test(first_and_only_test testapp) add_test(first_and_only_test testapp)
``` ```

View File

@ -42,7 +42,7 @@ Since GoogleTest is based on the popular xUnit architecture, you'll feel right
at home if you've used JUnit or PyUnit before. If not, it will take you about 10 at home if you've used JUnit or PyUnit before. If not, it will take you about 10
minutes to learn the basics and get started. So let's go! minutes to learn the basics and get started. So let's go!
## Beware of the nomenclature ## Beware of the Nomenclature
{: .callout .note} {: .callout .note}
*Note:* There might be some confusion arising from different definitions of the *Note:* There might be some confusion arising from different definitions of the

View File

@ -36,8 +36,7 @@ endif()
# as ${gmock_SOURCE_DIR} and to the root binary directory as # as ${gmock_SOURCE_DIR} and to the root binary directory as
# ${gmock_BINARY_DIR}. # ${gmock_BINARY_DIR}.
# Language "C" is required for find_package(Threads). # Language "C" is required for find_package(Threads).
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.13)
cmake_policy(SET CMP0048 NEW)
project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
if (COMMAND set_up_hermetic_build) if (COMMAND set_up_hermetic_build)
@ -101,18 +100,14 @@ else()
target_link_libraries(gmock_main PUBLIC gmock) target_link_libraries(gmock_main PUBLIC gmock)
set_target_properties(gmock_main PROPERTIES VERSION ${GOOGLETEST_VERSION}) set_target_properties(gmock_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
endif() endif()
# If the CMake version supports it, attach header directory information
# to the targets for when we are part of a parent build (ie being pulled string(REPLACE ";" "$<SEMICOLON>" dirs "${gmock_build_include_dirs}")
# in via add_subdirectory() rather than being a standalone build). target_include_directories(gmock SYSTEM INTERFACE
if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") "$<BUILD_INTERFACE:${dirs}>"
string(REPLACE ";" "$<SEMICOLON>" dirs "${gmock_build_include_dirs}") "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(gmock SYSTEM INTERFACE target_include_directories(gmock_main SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>" "$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>") "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(gmock_main SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
endif()
######################################################################## ########################################################################
# #
@ -136,11 +131,7 @@ if (gmock_build_tests)
enable_testing() enable_testing()
if (MINGW OR CYGWIN) if (MINGW OR CYGWIN)
if (CMAKE_VERSION VERSION_LESS "2.8.12") add_compile_options("-Wa,-mbig-obj")
add_compile_options("-Wa,-mbig-obj")
else()
add_definitions("-Wa,-mbig-obj")
endif()
endif() endif()
############################################################ ############################################################

View File

@ -46,14 +46,9 @@ endif()
# Project version: # Project version:
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.13)
cmake_policy(SET CMP0048 NEW)
project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
if (POLICY CMP0063) # Visibility
cmake_policy(SET CMP0063 NEW)
endif (POLICY CMP0063)
if (COMMAND set_up_hermetic_build) if (COMMAND set_up_hermetic_build)
set_up_hermetic_build() set_up_hermetic_build()
endif() endif()
@ -100,12 +95,14 @@ if (INSTALL_GTEST)
set(version_file "${generated_dir}/${cmake_package_name}ConfigVersion.cmake") set(version_file "${generated_dir}/${cmake_package_name}ConfigVersion.cmake")
write_basic_package_version_file(${version_file} VERSION ${GOOGLETEST_VERSION} COMPATIBILITY AnyNewerVersion) write_basic_package_version_file(${version_file} VERSION ${GOOGLETEST_VERSION} COMPATIBILITY AnyNewerVersion)
install(EXPORT ${targets_export_name} install(EXPORT ${targets_export_name}
COMPONENT "${PROJECT_NAME}"
NAMESPACE ${cmake_package_name}:: NAMESPACE ${cmake_package_name}::
DESTINATION ${cmake_files_install_dir}) DESTINATION ${cmake_files_install_dir})
set(config_file "${generated_dir}/${cmake_package_name}Config.cmake") set(config_file "${generated_dir}/${cmake_package_name}Config.cmake")
configure_package_config_file("${gtest_SOURCE_DIR}/cmake/Config.cmake.in" configure_package_config_file("${gtest_SOURCE_DIR}/cmake/Config.cmake.in"
"${config_file}" INSTALL_DESTINATION ${cmake_files_install_dir}) "${config_file}" INSTALL_DESTINATION ${cmake_files_install_dir})
install(FILES ${version_file} ${config_file} install(FILES ${version_file} ${config_file}
COMPONENT "${PROJECT_NAME}"
DESTINATION ${cmake_files_install_dir}) DESTINATION ${cmake_files_install_dir})
endif() endif()
@ -143,18 +140,13 @@ if(GTEST_HAS_ABSL)
endif() endif()
cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc) cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc)
set_target_properties(gtest_main PROPERTIES VERSION ${GOOGLETEST_VERSION}) set_target_properties(gtest_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
# If the CMake version supports it, attach header directory information string(REPLACE ";" "$<SEMICOLON>" dirs "${gtest_build_include_dirs}")
# to the targets for when we are part of a parent build (ie being pulled target_include_directories(gtest SYSTEM INTERFACE
# in via add_subdirectory() rather than being a standalone build). "$<BUILD_INTERFACE:${dirs}>"
if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
string(REPLACE ";" "$<SEMICOLON>" dirs "${gtest_build_include_dirs}") target_include_directories(gtest_main SYSTEM INTERFACE
target_include_directories(gtest SYSTEM INTERFACE "$<BUILD_INTERFACE:${dirs}>"
"$<BUILD_INTERFACE:${dirs}>" "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(gtest_main SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
endif()
if(CMAKE_SYSTEM_NAME MATCHES "QNX") if(CMAKE_SYSTEM_NAME MATCHES "QNX")
target_link_libraries(gtest PUBLIC regex) target_link_libraries(gtest PUBLIC regex)
endif() endif()

View File

@ -124,10 +124,10 @@ match the project in which it is included.
#### C++ Standard Version #### C++ Standard Version
An environment that supports C++11 is required in order to successfully build An environment that supports C++14 is required in order to successfully build
GoogleTest. One way to ensure this is to specify the standard in the top-level GoogleTest. One way to ensure this is to specify the standard in the top-level
project, for example by using the `set(CMAKE_CXX_STANDARD 11)` command along project, for example by using the `set(CMAKE_CXX_STANDARD 14)` command along
with `set(CMAKE_CXX_STANDARD_REQUIRED ON). If this is not feasible, for example with `set(CMAKE_CXX_STANDARD_REQUIRED ON)`. If this is not feasible, for example
in a C project using GoogleTest for validation, then it can be specified by in a C project using GoogleTest for validation, then it can be specified by
adding it to the options for cmake via the`-DCMAKE_CXX_FLAGS` option. adding it to the options for cmake via the`-DCMAKE_CXX_FLAGS` option.

View File

@ -12,14 +12,6 @@
# Test and Google Mock's option() definitions, and thus must be # Test and Google Mock's option() definitions, and thus must be
# called *after* the options have been defined. # called *after* the options have been defined.
if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif (POLICY CMP0054)
if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif (POLICY CMP0069)
# Tweaks CMake's default compiler/linker settings to suit Google Test's needs. # Tweaks CMake's default compiler/linker settings to suit Google Test's needs.
# #
# This must be a macro(), as inside a function string() can only # This must be a macro(), as inside a function string() can only
@ -196,23 +188,14 @@ function(cxx_library_with_type name type cxx_flags)
set_target_properties(${name} set_target_properties(${name}
PROPERTIES PROPERTIES
COMPILE_DEFINITIONS "GTEST_CREATE_SHARED_LIBRARY=1") COMPILE_DEFINITIONS "GTEST_CREATE_SHARED_LIBRARY=1")
if (NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") target_compile_definitions(${name} INTERFACE
target_compile_definitions(${name} INTERFACE $<INSTALL_INTERFACE:GTEST_LINKED_AS_SHARED_LIBRARY=1>)
$<INSTALL_INTERFACE:GTEST_LINKED_AS_SHARED_LIBRARY=1>)
endif()
endif() endif()
if (DEFINED GTEST_HAS_PTHREAD) if (DEFINED GTEST_HAS_PTHREAD)
if ("${CMAKE_VERSION}" VERSION_LESS "3.1.0") target_link_libraries(${name} PUBLIC Threads::Threads)
set(threads_spec ${CMAKE_THREAD_LIBS_INIT})
else()
set(threads_spec Threads::Threads)
endif()
target_link_libraries(${name} PUBLIC ${threads_spec})
endif() endif()
if (NOT "${CMAKE_VERSION}" VERSION_LESS "3.8") target_compile_features(${name} PUBLIC cxx_std_14)
target_compile_features(${name} PUBLIC cxx_std_14)
endif()
endfunction() endfunction()
######################################################################## ########################################################################
@ -264,22 +247,7 @@ function(cxx_executable name dir libs)
${name} "${cxx_default}" "${libs}" "${dir}/${name}.cc" ${ARGN}) ${name} "${cxx_default}" "${libs}" "${dir}/${name}.cc" ${ARGN})
endfunction() endfunction()
# CMP0094 policy enables finding a Python executable in the LOCATION order, as find_package(Python3)
# specified by the PATH environment variable.
if (POLICY CMP0094)
cmake_policy(SET CMP0094 NEW)
endif()
# Sets PYTHONINTERP_FOUND and PYTHON_EXECUTABLE.
if ("${CMAKE_VERSION}" VERSION_LESS "3.12.0")
find_package(PythonInterp)
set(PYTHONINTERP_FOUND ${PYTHONINTERP_FOUND} CACHE INTERNAL "")
set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE INTERNAL "")
else()
find_package(Python COMPONENTS Interpreter)
set(PYTHONINTERP_FOUND ${Python_Interpreter_FOUND} CACHE INTERNAL "")
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE} CACHE INTERNAL "")
endif()
# cxx_test_with_flags(name cxx_flags libs srcs...) # cxx_test_with_flags(name cxx_flags libs srcs...)
# #
@ -305,34 +273,22 @@ endfunction()
# creates a Python test with the given name whose main module is in # creates a Python test with the given name whose main module is in
# test/name.py. It does nothing if Python is not installed. # test/name.py. It does nothing if Python is not installed.
function(py_test name) function(py_test name)
if (PYTHONINTERP_FOUND) if (NOT Python3_Interpreter_FOUND)
if ("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 3.1) return()
if (CMAKE_CONFIGURATION_TYPES) endif()
# Multi-configuration build generators as for Visual Studio save
# output in a subdirectory of CMAKE_CURRENT_BINARY_DIR (Debug, get_cmake_property(is_multi "GENERATOR_IS_MULTI_CONFIG")
# Release etc.), so we have to provide it here. set(build_dir "${CMAKE_CURRENT_BINARY_DIR}")
add_test(NAME ${name} if (is_multi)
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>")
--build_dir=${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG> ${ARGN}) endif()
else (CMAKE_CONFIGURATION_TYPES)
# Single-configuration build generators like Makefile generators add_test(NAME ${name}
# don't have subdirs below CMAKE_CURRENT_BINARY_DIR. COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py
add_test(NAME ${name} --build_dir=${build_dir} ${ARGN})
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py
--build_dir=${CMAKE_CURRENT_BINARY_DIR} ${ARGN}) # Make the Python import path consistent between Bazel and CMake.
endif (CMAKE_CONFIGURATION_TYPES) set_tests_properties(${name} PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_SOURCE_DIR})
else()
# ${CMAKE_CURRENT_BINARY_DIR} is known at configuration time, so we can
# directly bind it from cmake. ${CTEST_CONFIGURATION_TYPE} is known
# only at ctest runtime (by calling ctest -c <Configuration>), so
# we have to escape $ to delay variable substitution here.
add_test(NAME ${name}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py
--build_dir=${CMAKE_CURRENT_BINARY_DIR}/\${CTEST_CONFIGURATION_TYPE} ${ARGN})
endif()
# Make the Python import path consistent between Bazel and CMake.
set_tests_properties(${name} PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_SOURCE_DIR})
endif(PYTHONINTERP_FOUND)
endfunction() endfunction()
# install_project(targets...) # install_project(targets...)
@ -341,10 +297,12 @@ endfunction()
function(install_project) function(install_project)
if(INSTALL_GTEST) if(INSTALL_GTEST)
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/" install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
COMPONENT "${PROJECT_NAME}"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# Install the project targets. # Install the project targets.
install(TARGETS ${ARGN} install(TARGETS ${ARGN}
EXPORT ${targets_export_name} EXPORT ${targets_export_name}
COMPONENT "${PROJECT_NAME}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
@ -356,6 +314,7 @@ function(install_project)
get_target_property(t_pdb_output_directory ${t} PDB_OUTPUT_DIRECTORY) get_target_property(t_pdb_output_directory ${t} PDB_OUTPUT_DIRECTORY)
install(FILES install(FILES
"${t_pdb_output_directory}/\${CMAKE_INSTALL_CONFIG_NAME}/$<$<CONFIG:Debug>:${t_pdb_name_debug}>$<$<NOT:$<CONFIG:Debug>>:${t_pdb_name}>.pdb" "${t_pdb_output_directory}/\${CMAKE_INSTALL_CONFIG_NAME}/$<$<CONFIG:Debug>:${t_pdb_name_debug}>$<$<NOT:$<CONFIG:Debug>>:${t_pdb_name}>.pdb"
COMPONENT "${PROJECT_NAME}"
DESTINATION ${CMAKE_INSTALL_LIBDIR} DESTINATION ${CMAKE_INSTALL_LIBDIR}
OPTIONAL) OPTIONAL)
endforeach() endforeach()
@ -366,6 +325,7 @@ function(install_project)
configure_file("${PROJECT_SOURCE_DIR}/cmake/${t}.pc.in" configure_file("${PROJECT_SOURCE_DIR}/cmake/${t}.pc.in"
"${configured_pc}" @ONLY) "${configured_pc}" @ONLY)
install(FILES "${configured_pc}" install(FILES "${configured_pc}"
COMPONENT "${PROJECT_NAME}"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endforeach() endforeach()
endif() endif()

View File

@ -1055,6 +1055,10 @@ class GTEST_API_ TestEventListeners {
return default_xml_generator_; return default_xml_generator_;
} }
// Controls whether events will be forwarded by the repeater to the
// listeners in the list.
void SuppressEventForwarding(bool);
private: private:
friend class TestSuite; friend class TestSuite;
friend class TestInfo; friend class TestInfo;
@ -1084,7 +1088,6 @@ class GTEST_API_ TestEventListeners {
// Controls whether events will be forwarded by the repeater to the // Controls whether events will be forwarded by the repeater to the
// listeners in the list. // listeners in the list.
bool EventForwardingEnabled() const; bool EventForwardingEnabled() const;
void SuppressEventForwarding();
// The actual list of listeners. // The actual list of listeners.
internal::TestEventRepeater* repeater_; internal::TestEventRepeater* repeater_;

View File

@ -1128,7 +1128,7 @@ DeathTest::TestRole NoExecDeathTest::AssumeRole() {
LogToStderr(); LogToStderr();
// Event forwarding to the listeners of event listener API mush be shut // Event forwarding to the listeners of event listener API mush be shut
// down in death test subprocesses. // down in death test subprocesses.
GetUnitTestImpl()->listeners()->SuppressEventForwarding(); GetUnitTestImpl()->listeners()->SuppressEventForwarding(true);
g_in_fast_death_test_child = true; g_in_fast_death_test_child = true;
return EXECUTE_TEST; return EXECUTE_TEST;
} else { } else {

View File

@ -672,7 +672,7 @@ class GTEST_API_ UnitTestImpl {
void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc, void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc,
internal::TearDownTestSuiteFunc tear_down_tc, internal::TearDownTestSuiteFunc tear_down_tc,
TestInfo* test_info) { TestInfo* test_info) {
#ifdef GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_FILE_SYSTEM
// In order to support thread-safe death tests, we need to // In order to support thread-safe death tests, we need to
// remember the original working directory when the test program // remember the original working directory when the test program
// was first invoked. We cannot do this in RUN_ALL_TESTS(), as // was first invoked. We cannot do this in RUN_ALL_TESTS(), as
@ -685,7 +685,7 @@ class GTEST_API_ UnitTestImpl {
GTEST_CHECK_(!original_working_dir_.IsEmpty()) GTEST_CHECK_(!original_working_dir_.IsEmpty())
<< "Failed to get the current working directory."; << "Failed to get the current working directory.";
} }
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_FILE_SYSTEM
GetTestSuite(test_info->test_suite_name(), test_info->type_param(), GetTestSuite(test_info->test_suite_name(), test_info->type_param(),
set_up_tc, tear_down_tc) set_up_tc, tear_down_tc)

View File

@ -3019,7 +3019,8 @@ void TestSuite::Run() {
internal::HandleExceptionsInMethodIfSupported( internal::HandleExceptionsInMethodIfSupported(
this, &TestSuite::RunSetUpTestSuite, "SetUpTestSuite()"); this, &TestSuite::RunSetUpTestSuite, "SetUpTestSuite()");
const bool skip_all = ad_hoc_test_result().Failed(); const bool skip_all =
ad_hoc_test_result().Failed() || ad_hoc_test_result().Skipped();
start_timestamp_ = internal::GetTimeInMillis(); start_timestamp_ = internal::GetTimeInMillis();
internal::Timer timer; internal::Timer timer;
@ -5155,8 +5156,8 @@ bool TestEventListeners::EventForwardingEnabled() const {
return repeater_->forwarding_enabled(); return repeater_->forwarding_enabled();
} }
void TestEventListeners::SuppressEventForwarding() { void TestEventListeners::SuppressEventForwarding(bool suppress) {
repeater_->set_forwarding_enabled(false); repeater_->set_forwarding_enabled(!suppress);
} }
// class UnitTest // class UnitTest
@ -5634,7 +5635,7 @@ void UnitTestImpl::RecordProperty(const TestProperty& test_property) {
// subprocess. Must not be called before InitGoogleTest. // subprocess. Must not be called before InitGoogleTest.
void UnitTestImpl::SuppressTestEventsIfInSubprocess() { void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
if (internal_run_death_test_flag_ != nullptr) if (internal_run_death_test_flag_ != nullptr)
listeners()->SuppressEventForwarding(); listeners()->SuppressEventForwarding(true);
} }
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST

View File

@ -12,7 +12,7 @@ Expected equality of these values:
3 3
Stack trace: (omitted) Stack trace: (omitted)
[==========] Running 89 tests from 42 test suites. [==========] Running 90 tests from 43 test suites.
[----------] Global test environment set-up. [----------] Global test environment set-up.
FooEnvironment::SetUp() called. FooEnvironment::SetUp() called.
BarEnvironment::SetUp() called. BarEnvironment::SetUp() called.
@ -967,6 +967,15 @@ Stack trace: (omitted)
googletest-output-test_.cc:#: Skipped googletest-output-test_.cc:#: Skipped
[ SKIPPED ] TestSuiteThatFailsToSetUp.ShouldNotRun [ SKIPPED ] TestSuiteThatFailsToSetUp.ShouldNotRun
[----------] 1 test from TestSuiteThatSkipsInSetUp
googletest-output-test_.cc:#: Skipped
Skip entire test suite
Stack trace: (omitted)
[ RUN ] TestSuiteThatSkipsInSetUp.ShouldNotRun
googletest-output-test_.cc:#: Skipped
[ SKIPPED ] TestSuiteThatSkipsInSetUp.ShouldNotRun
[----------] 1 test from PrintingFailingParams/FailingParamTest [----------] 1 test from PrintingFailingParams/FailingParamTest
[ RUN ] PrintingFailingParams/FailingParamTest.Fails/0 [ RUN ] PrintingFailingParams/FailingParamTest.Fails/0
googletest-output-test_.cc:#: Failure googletest-output-test_.cc:#: Failure
@ -1043,10 +1052,11 @@ Failed
Expected fatal failure. Expected fatal failure.
Stack trace: (omitted) Stack trace: (omitted)
[==========] 89 tests from 42 test suites ran. [==========] 90 tests from 43 test suites ran.
[ PASSED ] 31 tests. [ PASSED ] 31 tests.
[ SKIPPED ] 1 test, listed below: [ SKIPPED ] 2 tests, listed below:
[ SKIPPED ] TestSuiteThatFailsToSetUp.ShouldNotRun [ SKIPPED ] TestSuiteThatFailsToSetUp.ShouldNotRun
[ SKIPPED ] TestSuiteThatSkipsInSetUp.ShouldNotRun
[ FAILED ] 57 tests, listed below: [ FAILED ] 57 tests, listed below:
[ FAILED ] NonfatalFailureTest.EscapesStringOperands [ FAILED ] NonfatalFailureTest.EscapesStringOperands
[ FAILED ] NonfatalFailureTest.DiffForLongStrings [ FAILED ] NonfatalFailureTest.DiffForLongStrings

View File

@ -1007,6 +1007,12 @@ class TestSuiteThatFailsToSetUp : public testing::Test {
}; };
TEST_F(TestSuiteThatFailsToSetUp, ShouldNotRun) { std::abort(); } TEST_F(TestSuiteThatFailsToSetUp, ShouldNotRun) { std::abort(); }
class TestSuiteThatSkipsInSetUp : public testing::Test {
public:
static void SetUpTestSuite() { GTEST_SKIP() << "Skip entire test suite"; }
};
TEST_F(TestSuiteThatSkipsInSetUp, ShouldNotRun) { std::abort(); }
// The main function. // The main function.
// //
// The idea is to use Google Test to run all the tests we have defined (some // The idea is to use Google Test to run all the tests we have defined (some

View File

@ -173,7 +173,7 @@ class TestEventListenersAccessor {
} }
static void SuppressEventForwarding(TestEventListeners* listeners) { static void SuppressEventForwarding(TestEventListeners* listeners) {
listeners->SuppressEventForwarding(); listeners->SuppressEventForwarding(true);
} }
}; };