Compare commits

..

No commits in common. "b10fad38c4026a29ea6561ab15fc4818170d1c10" and "e47544ad31cb3ceecd04cc13e8fe556f8df9fe0b" have entirely different histories.

14 changed files with 60 additions and 86 deletions

View File

@ -15,7 +15,7 @@ enable_testing()
include(CMakeDependentOption) include(CMakeDependentOption)
include(GNUInstallDirs) include(GNUInstallDirs)
# Note that googlemock target already builds googletest. #Note that googlemock target already builds googletest
option(BUILD_GMOCK "Builds the googlemock subproject" ON) option(BUILD_GMOCK "Builds the googlemock subproject" ON)
option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON) option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON)
option(GTEST_HAS_ABSL "Use Abseil and RE2. Requires Abseil and RE2 to be separately added to the build." OFF) option(GTEST_HAS_ABSL "Use Abseil and RE2. Requires Abseil and RE2 to be separately added to the build." OFF)

View File

@ -1927,12 +1927,6 @@ class MockFoo : public Foo {
action_n)); action_n));
``` ```
The return value of the last action **must** match the return type of the mocked
method. In the example above, `action_n` could be `Return(true)`, or a lambda
that returns a `bool`, but not `SaveArg`, which returns `void`. Otherwise the
signature of `DoAll` would not match the signature expected by `WillOnce`, which
is the signature of the mocked method, and it wouldn't compile.
### Verifying Complex Arguments {#SaveArgVerify} ### Verifying Complex Arguments {#SaveArgVerify}
If you want to verify that a method is called with a particular argument but the If you want to verify that a method is called with a particular argument but the

View File

@ -210,7 +210,7 @@ objects for several different tests.
To create a fixture: To create a fixture:
1. Derive a class from `testing::Test` . Start its body with `protected:`, as 1. Derive a class from `::testing::Test` . Start its body with `protected:`, as
we'll want to access fixture members from sub-classes. we'll want to access fixture members from sub-classes.
2. Inside the class, declare any objects you plan to use. 2. Inside the class, declare any objects you plan to use.
3. If necessary, write a default constructor or `SetUp()` function to prepare 3. If necessary, write a default constructor or `SetUp()` function to prepare
@ -271,7 +271,7 @@ First, define a fixture class. By convention, you should give it the name
`FooTest` where `Foo` is the class being tested. `FooTest` where `Foo` is the class being tested.
```c++ ```c++
class QueueTest : public testing::Test { class QueueTest : public ::testing::Test {
protected: protected:
void SetUp() override { void SetUp() override {
// q0_ remains empty // q0_ remains empty
@ -402,7 +402,7 @@ namespace project {
namespace { namespace {
// The fixture for testing class Foo. // The fixture for testing class Foo.
class FooTest : public testing::Test { class FooTest : public ::testing::Test {
protected: protected:
// You can remove any or all of the following functions if their bodies would // You can remove any or all of the following functions if their bodies would
// be empty. // be empty.
@ -450,14 +450,14 @@ TEST_F(FooTest, DoesXyz) {
} // namespace my } // namespace my
int main(int argc, char **argv) { int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
``` ```
The `testing::InitGoogleTest()` function parses the command line for GoogleTest The `::testing::InitGoogleTest()` function parses the command line for
flags, and removes all recognized flags. This allows the user to control a test GoogleTest flags, and removes all recognized flags. This allows the user to
program's behavior via various flags, which we'll cover in the control a test program's behavior via various flags, which we'll cover in the
[AdvancedGuide](advanced.md). You **must** call this function before calling [AdvancedGuide](advanced.md). You **must** call this function before calling
`RUN_ALL_TESTS()`, or the flags won't be properly initialized. `RUN_ALL_TESTS()`, or the flags won't be properly initialized.

View File

@ -5,7 +5,7 @@
# CMake build script for Google Mock. # CMake build script for Google Mock.
# #
# To run the tests for Google Mock itself on Linux, use 'make test' or # To run the tests for Google Mock itself on Linux, use 'make test' or
# ctest. You can select which tests to run using 'ctest -R regex'. # ctest. You can select which tests to run using 'ctest -R regex'.
# For more options, run 'ctest --help'. # For more options, run 'ctest --help'.
option(gmock_build_tests "Build all of Google Mock's own tests." OFF) option(gmock_build_tests "Build all of Google Mock's own tests." OFF)
@ -44,7 +44,7 @@ if (COMMAND set_up_hermetic_build)
endif() endif()
# Instructs CMake to process Google Test's CMakeLists.txt and add its # Instructs CMake to process Google Test's CMakeLists.txt and add its
# targets to the current scope. We are placing Google Test's binary # targets to the current scope. We are placing Google Test's binary
# directory in a subdirectory of our own as VC compilation may break # directory in a subdirectory of our own as VC compilation may break
# if they are the same (the default). # if they are the same (the default).
add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/${gtest_dir}") add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/${gtest_dir}")
@ -60,9 +60,9 @@ else()
endif() endif()
# Although Google Test's CMakeLists.txt calls this function, the # Although Google Test's CMakeLists.txt calls this function, the
# changes there don't affect the current scope. Therefore we have to # changes there don't affect the current scope. Therefore we have to
# call it again here. # call it again here.
config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake
# Adds Google Mock's and Google Test's header directories to the search path. # Adds Google Mock's and Google Test's header directories to the search path.
set(gmock_build_include_dirs set(gmock_build_include_dirs
@ -75,10 +75,10 @@ include_directories(${gmock_build_include_dirs})
######################################################################## ########################################################################
# #
# Defines the gmock & gmock_main libraries. User tests should link # Defines the gmock & gmock_main libraries. User tests should link
# with one of them. # with one of them.
# Google Mock libraries. We build them using more strict warnings than what # Google Mock libraries. We build them using more strict warnings than what
# are used for other targets, to ensure that Google Mock can be compiled by # are used for other targets, to ensure that Google Mock can be compiled by
# a user aggressive about warnings. # a user aggressive about warnings.
if (MSVC) if (MSVC)
@ -111,7 +111,7 @@ target_include_directories(gmock_main SYSTEM INTERFACE
######################################################################## ########################################################################
# #
# Install rules. # Install rules
install_project(gmock gmock_main) install_project(gmock gmock_main)
######################################################################## ########################################################################
@ -121,8 +121,8 @@ install_project(gmock gmock_main)
# You can skip this section if you aren't interested in testing # You can skip this section if you aren't interested in testing
# Google Mock itself. # Google Mock itself.
# #
# The tests are not built by default. To build them, set the # The tests are not built by default. To build them, set the
# gmock_build_tests option to ON. You can do it by running ccmake # gmock_build_tests option to ON. You can do it by running ccmake
# or specifying the -Dgmock_build_tests=ON flag when running cmake. # or specifying the -Dgmock_build_tests=ON flag when running cmake.
if (gmock_build_tests) if (gmock_build_tests)
@ -187,7 +187,7 @@ if (gmock_build_tests)
cxx_shared_library(shared_gmock_main "${cxx_default}" cxx_shared_library(shared_gmock_main "${cxx_default}"
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
# Tests that a binary can be built with Google Mock as a shared library. On # Tests that a binary can be built with Google Mock as a shared library. On
# some system configurations, it may not possible to run the binary without # some system configurations, it may not possible to run the binary without
# knowing more details about the system configurations. We do not try to run # knowing more details about the system configurations. We do not try to run
# this binary. To get a more robust shared library coverage, configure with # this binary. To get a more robust shared library coverage, configure with

View File

@ -1048,7 +1048,7 @@ class StartsWithMatcher {
template <typename MatcheeStringType> template <typename MatcheeStringType>
bool MatchAndExplain(const MatcheeStringType& s, bool MatchAndExplain(const MatcheeStringType& s,
MatchResultListener* /* listener */) const { MatchResultListener* /* listener */) const {
const StringType s2(s); const StringType& s2(s);
return s2.length() >= prefix_.length() && return s2.length() >= prefix_.length() &&
s2.substr(0, prefix_.length()) == prefix_; s2.substr(0, prefix_.length()) == prefix_;
} }
@ -1102,7 +1102,7 @@ class EndsWithMatcher {
template <typename MatcheeStringType> template <typename MatcheeStringType>
bool MatchAndExplain(const MatcheeStringType& s, bool MatchAndExplain(const MatcheeStringType& s,
MatchResultListener* /* listener */) const { MatchResultListener* /* listener */) const {
const StringType s2(s); const StringType& s2(s);
return s2.length() >= suffix_.length() && return s2.length() >= suffix_.length() &&
s2.substr(s2.length() - suffix_.length()) == suffix_; s2.substr(s2.length() - suffix_.length()) == suffix_;
} }

View File

@ -60,7 +60,6 @@
#include "gmock/gmock-more-actions.h" // IWYU pragma: export #include "gmock/gmock-more-actions.h" // IWYU pragma: export
#include "gmock/gmock-more-matchers.h" // IWYU pragma: export #include "gmock/gmock-more-matchers.h" // IWYU pragma: export
#include "gmock/gmock-nice-strict.h" // IWYU pragma: export #include "gmock/gmock-nice-strict.h" // IWYU pragma: export
#include "gmock/gmock-spec-builders.h" // IWYU pragma: export
#include "gmock/internal/gmock-internal-utils.h" #include "gmock/internal/gmock-internal-utils.h"
#include "gmock/internal/gmock-port.h" #include "gmock/internal/gmock-port.h"

View File

@ -1769,15 +1769,6 @@ TEST(StartsWithTest, CanDescribeSelf) {
EXPECT_EQ("starts with \"Hi\"", Describe(m)); EXPECT_EQ("starts with \"Hi\"", Describe(m));
} }
TEST(StartsWithTest, WorksWithStringMatcherOnStringViewMatchee) {
#if GTEST_INTERNAL_HAS_STRING_VIEW
EXPECT_THAT(internal::StringView("talk to me goose"),
StartsWith(std::string("talk")));
#else
GTEST_SKIP() << "Not applicable without internal::StringView.";
#endif // GTEST_INTERNAL_HAS_STRING_VIEW
}
// Tests EndsWith(s). // Tests EndsWith(s).
TEST(EndsWithTest, MatchesStringWithGivenSuffix) { TEST(EndsWithTest, MatchesStringWithGivenSuffix) {

View File

@ -5,7 +5,7 @@
# CMake build script for Google Test. # CMake build script for Google Test.
# #
# To run the tests for Google Test itself on Linux, use 'make test' or # To run the tests for Google Test itself on Linux, use 'make test' or
# ctest. You can select which tests to run using 'ctest -R regex'. # ctest. You can select which tests to run using 'ctest -R regex'.
# For more options, run 'ctest --help'. # For more options, run 'ctest --help'.
# When other libraries are using a shared version of runtime libraries, # When other libraries are using a shared version of runtime libraries,
@ -35,7 +35,7 @@ endif()
######################################################################## ########################################################################
# #
# Project-wide settings. # Project-wide settings
# Name of the project. # Name of the project.
# #
@ -44,7 +44,7 @@ endif()
# ${gtest_BINARY_DIR}. # ${gtest_BINARY_DIR}.
# Language "C" is required for find_package(Threads). # Language "C" is required for find_package(Threads).
# Project version. # Project version:
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
@ -53,7 +53,7 @@ if (COMMAND set_up_hermetic_build)
set_up_hermetic_build() set_up_hermetic_build()
endif() endif()
# These commands only run if this is the main project. # These commands only run if this is the main project
if(CMAKE_PROJECT_NAME STREQUAL "gtest" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution") if(CMAKE_PROJECT_NAME STREQUAL "gtest" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution")
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
@ -83,7 +83,7 @@ include(cmake/internal_utils.cmake)
config_compiler_and_linker() # Defined in internal_utils.cmake. config_compiler_and_linker() # Defined in internal_utils.cmake.
# Needed to set the namespace for both the export targets and the # Needed to set the namespace for both the export targets and the
# alias libraries. # alias libraries
set(cmake_package_name GTest CACHE INTERNAL "") set(cmake_package_name GTest CACHE INTERNAL "")
# Create the CMake package file descriptors. # Create the CMake package file descriptors.
@ -114,10 +114,10 @@ include_directories(${gtest_build_include_dirs})
######################################################################## ########################################################################
# #
# Defines the gtest & gtest_main libraries. User tests should link # Defines the gtest & gtest_main libraries. User tests should link
# with one of them. # with one of them.
# Google Test libraries. We build them using more strict warnings than what # Google Test libraries. We build them using more strict warnings than what
# are used for other targets, to ensure that gtest can be compiled by a user # are used for other targets, to ensure that gtest can be compiled by a user
# aggressive about warnings. # aggressive about warnings.
cxx_library(gtest "${cxx_strict}" src/gtest-all.cc) cxx_library(gtest "${cxx_strict}" src/gtest-all.cc)
@ -154,15 +154,15 @@ target_link_libraries(gtest_main PUBLIC gtest)
######################################################################## ########################################################################
# #
# Install rules. # Install rules
install_project(gtest gtest_main) install_project(gtest gtest_main)
######################################################################## ########################################################################
# #
# Samples on how to link user tests with gtest or gtest_main. # Samples on how to link user tests with gtest or gtest_main.
# #
# They are not built by default. To build them, set the # They are not built by default. To build them, set the
# gtest_build_samples option to ON. You can do it by running ccmake # gtest_build_samples option to ON. You can do it by running ccmake
# or specifying the -Dgtest_build_samples=ON flag when running cmake. # or specifying the -Dgtest_build_samples=ON flag when running cmake.
if (gtest_build_samples) if (gtest_build_samples)
@ -185,8 +185,8 @@ endif()
# You can skip this section if you aren't interested in testing # You can skip this section if you aren't interested in testing
# Google Test itself. # Google Test itself.
# #
# The tests are not built by default. To build them, set the # The tests are not built by default. To build them, set the
# gtest_build_tests option to ON. You can do it by running ccmake # gtest_build_tests option to ON. You can do it by running ccmake
# or specifying the -Dgtest_build_tests=ON flag when running cmake. # or specifying the -Dgtest_build_tests=ON flag when running cmake.
if (gtest_build_tests) if (gtest_build_tests)
@ -268,7 +268,7 @@ if (gtest_build_tests)
py_test(gtest_skip_environment_check_output_test) py_test(gtest_skip_environment_check_output_test)
# Visual Studio .NET 2003 does not support STL with exceptions disabled. # Visual Studio .NET 2003 does not support STL with exceptions disabled.
if (NOT MSVC OR MSVC_VERSION GREATER 1310) # 1310 is Visual Studio .NET 2003 if (NOT MSVC OR MSVC_VERSION GREATER 1310) # 1310 is Visual Studio .NET 2003
cxx_executable_with_flags( cxx_executable_with_flags(
googletest-catch-exceptions-no-ex-test_ googletest-catch-exceptions-no-ex-test_
"${cxx_no_exception}" "${cxx_no_exception}"

View File

@ -29,7 +29,7 @@ macro(fix_default_compiler_settings_)
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if (NOT BUILD_SHARED_LIBS AND NOT gtest_force_shared_crt) if (NOT BUILD_SHARED_LIBS AND NOT gtest_force_shared_crt)
# When Google Test is built as a shared library, it should also use # When Google Test is built as a shared library, it should also use
# shared runtime libraries. Otherwise, it may end up with multiple # shared runtime libraries. Otherwise, it may end up with multiple
# copies of runtime library data in different modules, resulting in # copies of runtime library data in different modules, resulting in
# hard-to-find crashes. When it is built as a static library, it is # hard-to-find crashes. When it is built as a static library, it is
# preferable to use CRT as static libraries, as we don't have to rely # preferable to use CRT as static libraries, as we don't have to rely
@ -55,11 +55,11 @@ macro(fix_default_compiler_settings_)
endmacro() endmacro()
# Defines the compiler/linker flags used to build Google Test and # Defines the compiler/linker flags used to build Google Test and
# Google Mock. You can tweak these definitions to suit your need. A # Google Mock. You can tweak these definitions to suit your need. A
# variable's value is empty before it's explicitly assigned to. # variable's value is empty before it's explicitly assigned to.
macro(config_compiler_and_linker) macro(config_compiler_and_linker)
# Note: pthreads on MinGW is not supported, even if available # Note: pthreads on MinGW is not supported, even if available
# instead, we use windows threading primitives. # instead, we use windows threading primitives
unset(GTEST_HAS_PTHREAD) unset(GTEST_HAS_PTHREAD)
if (NOT gtest_disable_pthreads AND NOT MINGW) if (NOT gtest_disable_pthreads AND NOT MINGW)
# Defines CMAKE_USE_PTHREADS_INIT and CMAKE_THREAD_LIBS_INIT. # Defines CMAKE_USE_PTHREADS_INIT and CMAKE_THREAD_LIBS_INIT.
@ -79,7 +79,7 @@ macro(config_compiler_and_linker)
set(cxx_exception_flags "-EHsc -D_HAS_EXCEPTIONS=1") set(cxx_exception_flags "-EHsc -D_HAS_EXCEPTIONS=1")
set(cxx_no_exception_flags "-EHs-c- -D_HAS_EXCEPTIONS=0") set(cxx_no_exception_flags "-EHs-c- -D_HAS_EXCEPTIONS=0")
set(cxx_no_rtti_flags "-GR-") set(cxx_no_rtti_flags "-GR-")
# Suppress "unreachable code" warning, # Suppress "unreachable code" warning
# https://stackoverflow.com/questions/3232669 explains the issue. # https://stackoverflow.com/questions/3232669 explains the issue.
set(cxx_base_flags "${cxx_base_flags} -wd4702") set(cxx_base_flags "${cxx_base_flags} -wd4702")
# Ensure MSVC treats source files as UTF-8 encoded. # Ensure MSVC treats source files as UTF-8 encoded.
@ -110,7 +110,7 @@ macro(config_compiler_and_linker)
set(cxx_exception_flags "-fexceptions") set(cxx_exception_flags "-fexceptions")
set(cxx_no_exception_flags "-fno-exceptions") set(cxx_no_exception_flags "-fno-exceptions")
# Until version 4.3.2, GCC doesn't define a macro to indicate # Until version 4.3.2, GCC doesn't define a macro to indicate
# whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI # whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI
# explicitly. # explicitly.
set(cxx_no_rtti_flags "-fno-rtti -DGTEST_HAS_RTTI=0") set(cxx_no_rtti_flags "-fno-rtti -DGTEST_HAS_RTTI=0")
set(cxx_strict_flags set(cxx_strict_flags
@ -127,7 +127,7 @@ macro(config_compiler_and_linker)
set(cxx_exception_flags "-qeh") set(cxx_exception_flags "-qeh")
set(cxx_no_exception_flags "-qnoeh") set(cxx_no_exception_flags "-qnoeh")
# Until version 9.0, Visual Age doesn't define a macro to indicate # Until version 9.0, Visual Age doesn't define a macro to indicate
# whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI # whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI
# explicitly. # explicitly.
set(cxx_no_rtti_flags "-qnortti -DGTEST_HAS_RTTI=0") set(cxx_no_rtti_flags "-qnortti -DGTEST_HAS_RTTI=0")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "HP") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "HP")
@ -157,7 +157,7 @@ macro(config_compiler_and_linker)
set(cxx_strict "${cxx_default} ${cxx_strict_flags}") set(cxx_strict "${cxx_default} ${cxx_strict_flags}")
endmacro() endmacro()
# Defines the gtest & gtest_main libraries. User tests should link # Defines the gtest & gtest_main libraries. User tests should link
# with one of them. # with one of them.
function(cxx_library_with_type name type cxx_flags) function(cxx_library_with_type name type cxx_flags)
# type can be either STATIC or SHARED to denote a static or shared library. # type can be either STATIC or SHARED to denote a static or shared library.
@ -167,7 +167,7 @@ function(cxx_library_with_type name type cxx_flags)
set_target_properties(${name} set_target_properties(${name}
PROPERTIES PROPERTIES
COMPILE_FLAGS "${cxx_flags}") COMPILE_FLAGS "${cxx_flags}")
# Set the output directory for build artifacts. # Set the output directory for build artifacts
set_target_properties(${name} set_target_properties(${name}
PROPERTIES PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
@ -175,7 +175,7 @@ function(cxx_library_with_type name type cxx_flags)
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
# Make PDBs match library name. # make PDBs match library name
get_target_property(pdb_debug_postfix ${name} DEBUG_POSTFIX) get_target_property(pdb_debug_postfix ${name} DEBUG_POSTFIX)
set_target_properties(${name} set_target_properties(${name}
PROPERTIES PROPERTIES
@ -212,7 +212,7 @@ endfunction()
# cxx_executable_with_flags(name cxx_flags libs srcs...) # cxx_executable_with_flags(name cxx_flags libs srcs...)
# #
# Creates a named C++ executable that depends on the given libraries and # creates a named C++ executable that depends on the given libraries and
# is built from the given source files with the given compiler flags. # is built from the given source files with the given compiler flags.
function(cxx_executable_with_flags name cxx_flags libs) function(cxx_executable_with_flags name cxx_flags libs)
add_executable(${name} ${ARGN}) add_executable(${name} ${ARGN})
@ -239,8 +239,8 @@ endfunction()
# cxx_executable(name dir lib srcs...) # cxx_executable(name dir lib srcs...)
# #
# Creates a named target that depends on the given libs and is built # creates a named target that depends on the given libs and is built
# from the given source files. dir/name.cc is implicitly included in # from the given source files. dir/name.cc is implicitly included in
# the source file list. # the source file list.
function(cxx_executable name dir libs) function(cxx_executable name dir libs)
cxx_executable_with_flags( cxx_executable_with_flags(
@ -251,7 +251,7 @@ find_package(Python3)
# cxx_test_with_flags(name cxx_flags libs srcs...) # cxx_test_with_flags(name cxx_flags libs srcs...)
# #
# Creates a named C++ test that depends on the given libs and is built # creates a named C++ test that depends on the given libs and is built
# from the given source files with the given compiler flags. # from the given source files with the given compiler flags.
function(cxx_test_with_flags name cxx_flags libs) function(cxx_test_with_flags name cxx_flags libs)
cxx_executable_with_flags(${name} "${cxx_flags}" "${libs}" ${ARGN}) cxx_executable_with_flags(${name} "${cxx_flags}" "${libs}" ${ARGN})
@ -260,8 +260,8 @@ endfunction()
# cxx_test(name libs srcs...) # cxx_test(name libs srcs...)
# #
# Creates a named test target that depends on the given libs and is # creates a named test target that depends on the given libs and is
# built from the given source files. Unlike cxx_test_with_flags, # built from the given source files. Unlike cxx_test_with_flags,
# test/name.cc is already implicitly included in the source file list. # test/name.cc is already implicitly included in the source file list.
function(cxx_test name libs) function(cxx_test name libs)
cxx_test_with_flags("${name}" "${cxx_default}" "${libs}" cxx_test_with_flags("${name}" "${cxx_default}" "${libs}"
@ -270,8 +270,8 @@ endfunction()
# py_test(name) # py_test(name)
# #
# 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 (NOT Python3_Interpreter_FOUND) if (NOT Python3_Interpreter_FOUND)
return() return()
@ -307,7 +307,7 @@ function(install_project)
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# Install PDBs. # Install PDBs
foreach(t ${ARGN}) foreach(t ${ARGN})
get_target_property(t_pdb_name ${t} COMPILE_PDB_NAME) get_target_property(t_pdb_name ${t} COMPILE_PDB_NAME)
get_target_property(t_pdb_name_debug ${t} COMPILE_PDB_NAME_DEBUG) get_target_property(t_pdb_name_debug ${t} COMPILE_PDB_NAME_DEBUG)

View File

@ -52,7 +52,9 @@ GTEST_DECLARE_string_(internal_run_death_test);
namespace testing { namespace testing {
namespace internal { namespace internal {
// Name of the flag (needed for parsing Google Test flag). // Names of the flags (needed for parsing Google Test flags).
const char kDeathTestStyleFlag[] = "death_test_style";
const char kDeathTestUseFork[] = "death_test_use_fork";
const char kInternalRunDeathTestFlag[] = "internal_run_death_test"; const char kInternalRunDeathTestFlag[] = "internal_run_death_test";
#ifdef GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST

View File

@ -584,8 +584,8 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
GTEST_CHECK_(IsValidParamName(param_name)) GTEST_CHECK_(IsValidParamName(param_name))
<< "Parameterized test name '" << param_name << "Parameterized test name '" << param_name
<< "' is invalid (contains spaces, dashes, or any " << "' is invalid (contains spaces, dashes, underscores, or "
"non-alphanumeric characters other than underscores), in " "non-alphanumeric characters), in "
<< file << " line " << line << "" << std::endl; << file << " line " << line << "" << std::endl;
GTEST_CHECK_(test_param_names.count(param_name) == 0) GTEST_CHECK_(test_param_names.count(param_name) == 0)

View File

@ -697,24 +697,13 @@ bool RE::PartialMatch(const char* str, const RE& re) {
void RE::Init(const char* regex) { void RE::Init(const char* regex) {
pattern_ = regex; pattern_ = regex;
// NetBSD (and Android, which takes its regex implemntation from NetBSD) does
// not include the GNU regex extensions (such as Perl style character classes
// like \w) in REG_EXTENDED. REG_EXTENDED is only specified to include the
// [[:alpha:]] style character classes. Enable REG_GNU wherever it is defined
// so users can use those extensions.
#if defined(REG_GNU)
constexpr int reg_flags = REG_EXTENDED | REG_GNU;
#else
constexpr int reg_flags = REG_EXTENDED;
#endif
// Reserves enough bytes to hold the regular expression used for a // Reserves enough bytes to hold the regular expression used for a
// full match. // full match.
const size_t full_regex_len = strlen(regex) + 10; const size_t full_regex_len = strlen(regex) + 10;
char* const full_pattern = new char[full_regex_len]; char* const full_pattern = new char[full_regex_len];
snprintf(full_pattern, full_regex_len, "^(%s)$", regex); snprintf(full_pattern, full_regex_len, "^(%s)$", regex);
is_valid_ = regcomp(&full_regex_, full_pattern, reg_flags) == 0; is_valid_ = regcomp(&full_regex_, full_pattern, REG_EXTENDED) == 0;
// We want to call regcomp(&partial_regex_, ...) even if the // We want to call regcomp(&partial_regex_, ...) even if the
// previous expression returns false. Otherwise partial_regex_ may // previous expression returns false. Otherwise partial_regex_ may
// not be properly initialized can may cause trouble when it's // not be properly initialized can may cause trouble when it's
@ -725,7 +714,7 @@ void RE::Init(const char* regex) {
// regex. We change it to an equivalent form "()" to be safe. // regex. We change it to an equivalent form "()" to be safe.
if (is_valid_) { if (is_valid_) {
const char* const partial_regex = (*regex == '\0') ? "()" : regex; const char* const partial_regex = (*regex == '\0') ? "()" : regex;
is_valid_ = regcomp(&partial_regex_, partial_regex, reg_flags) == 0; is_valid_ = regcomp(&partial_regex_, partial_regex, REG_EXTENDED) == 0;
} }
EXPECT_TRUE(is_valid_) EXPECT_TRUE(is_valid_)
<< "Regular expression \"" << regex << "Regular expression \"" << regex

View File

@ -43,7 +43,6 @@
#include <algorithm> #include <algorithm>
#include <chrono> // NOLINT #include <chrono> // NOLINT
#include <cmath> #include <cmath>
#include <csignal> // NOLINT: raise(3) is used on some platforms
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>

View File

@ -418,8 +418,8 @@ TYPED_TEST(RETest, ImplicitConstructorWorks) {
const RE simple(TypeParam("hello")); const RE simple(TypeParam("hello"));
EXPECT_STREQ("hello", simple.pattern()); EXPECT_STREQ("hello", simple.pattern());
const RE normal(TypeParam(".*(\\w+)")); const RE normal(TypeParam(".*([[:alnum:]_]+)"));
EXPECT_STREQ(".*(\\w+)", normal.pattern()); EXPECT_STREQ(".*([[:alnum:]_]+)", normal.pattern());
} }
// Tests that RE's constructors reject invalid regular expressions. // Tests that RE's constructors reject invalid regular expressions.