From 2d09ed35cfabc8032545a401e883aafd3efda048 Mon Sep 17 00:00:00 2001 From: Dzmitry Ivaniuk Date: Fri, 29 Sep 2023 17:26:23 +0300 Subject: cmake: Fix comments in cmake files Remove extra spaces. Fix so that the comment line starts with a capital letter and ends with a dot. --- CMakeLists.txt | 2 +- googlemock/CMakeLists.txt | 20 +++++++++---------- googletest/CMakeLists.txt | 26 ++++++++++++------------ googletest/cmake/internal_utils.cmake | 37 +++++++++++++++++------------------ 4 files changed, 42 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 089ac987..24d41c29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ enable_testing() include(CMakeDependentOption) 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(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) diff --git a/googlemock/CMakeLists.txt b/googlemock/CMakeLists.txt index a9aa0723..428bd9f8 100644 --- a/googlemock/CMakeLists.txt +++ b/googlemock/CMakeLists.txt @@ -5,7 +5,7 @@ # CMake build script for Google Mock. # # 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'. option(gmock_build_tests "Build all of Google Mock's own tests." OFF) @@ -44,7 +44,7 @@ if (COMMAND set_up_hermetic_build) endif() # 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 # if they are the same (the default). add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/${gtest_dir}") @@ -60,9 +60,9 @@ else() endif() # 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. -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. 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. -# 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 # a user aggressive about warnings. if (MSVC) @@ -111,7 +111,7 @@ target_include_directories(gmock_main SYSTEM INTERFACE ######################################################################## # -# Install rules +# Install rules. 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 # Google Mock itself. # -# 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 +# 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 # or specifying the -Dgmock_build_tests=ON flag when running cmake. if (gmock_build_tests) @@ -187,7 +187,7 @@ if (gmock_build_tests) cxx_shared_library(shared_gmock_main "${cxx_default}" "${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 # 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 diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index caafa8c7..51a67c91 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -5,7 +5,7 @@ # CMake build script for Google Test. # # 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'. # 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. # @@ -44,7 +44,7 @@ endif() # ${gtest_BINARY_DIR}. # Language "C" is required for find_package(Threads). -# Project version: +# Project version. cmake_minimum_required(VERSION 3.13) project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) @@ -53,7 +53,7 @@ if (COMMAND set_up_hermetic_build) set_up_hermetic_build() 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") # 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. # Needed to set the namespace for both the export targets and the -# alias libraries +# alias libraries. set(cmake_package_name GTest CACHE INTERNAL "") # 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. -# 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 # aggressive about warnings. 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) ######################################################################## # # Samples on how to link user tests with gtest or gtest_main. # -# They are not built by default. To build them, set the -# gtest_build_samples option to ON. You can do it by running ccmake +# They are not built by default. To build them, set the +# gtest_build_samples option to ON. You can do it by running ccmake # or specifying the -Dgtest_build_samples=ON flag when running cmake. if (gtest_build_samples) @@ -185,8 +185,8 @@ endif() # You can skip this section if you aren't interested in testing # Google Test itself. # -# 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 +# 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 # or specifying the -Dgtest_build_tests=ON flag when running cmake. if (gtest_build_tests) @@ -268,7 +268,7 @@ if (gtest_build_tests) py_test(gtest_skip_environment_check_output_test) # 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( googletest-catch-exceptions-no-ex-test_ "${cxx_no_exception}" diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index d4f67f43..d5c82745 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -29,7 +29,7 @@ macro(fix_default_compiler_settings_) CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) if (NOT BUILD_SHARED_LIBS AND NOT gtest_force_shared_crt) # 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 # 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 @@ -55,11 +55,11 @@ macro(fix_default_compiler_settings_) endmacro() # 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. macro(config_compiler_and_linker) # 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) if (NOT gtest_disable_pthreads AND NOT MINGW) # 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_no_exception_flags "-EHs-c- -D_HAS_EXCEPTIONS=0") set(cxx_no_rtti_flags "-GR-") - # Suppress "unreachable code" warning + # Suppress "unreachable code" warning, # https://stackoverflow.com/questions/3232669 explains the issue. set(cxx_base_flags "${cxx_base_flags} -wd4702") # 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_no_exception_flags "-fno-exceptions") # 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. set(cxx_no_rtti_flags "-fno-rtti -DGTEST_HAS_RTTI=0") set(cxx_strict_flags @@ -127,7 +127,7 @@ macro(config_compiler_and_linker) set(cxx_exception_flags "-qeh") set(cxx_no_exception_flags "-qnoeh") # 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. set(cxx_no_rtti_flags "-qnortti -DGTEST_HAS_RTTI=0") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "HP") @@ -157,7 +157,7 @@ macro(config_compiler_and_linker) set(cxx_strict "${cxx_default} ${cxx_strict_flags}") 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. function(cxx_library_with_type name type cxx_flags) # type can be either STATIC or SHARED to denote a static or shared library. @@ -167,15 +167,14 @@ function(cxx_library_with_type name type cxx_flags) set_target_properties(${name} PROPERTIES COMPILE_FLAGS "${cxx_flags}") - # Set the output directory for build artifacts + # Set the output directory for build artifacts. set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" - 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) set_target_properties(${name} PROPERTIES @@ -212,7 +211,7 @@ endfunction() # 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. function(cxx_executable_with_flags name cxx_flags libs) add_executable(${name} ${ARGN}) @@ -239,8 +238,8 @@ endfunction() # cxx_executable(name dir lib srcs...) # -# 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 +# 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 # the source file list. function(cxx_executable name dir libs) cxx_executable_with_flags( @@ -251,7 +250,7 @@ find_package(Python3) # 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. function(cxx_test_with_flags name cxx_flags libs) cxx_executable_with_flags(${name} "${cxx_flags}" "${libs}" ${ARGN}) @@ -260,8 +259,8 @@ endfunction() # cxx_test(name libs srcs...) # -# creates a named test target that depends on the given libs and is -# built from the given source files. Unlike cxx_test_with_flags, +# Creates a named test target that depends on the given libs and is +# built from the given source files. Unlike cxx_test_with_flags, # test/name.cc is already implicitly included in the source file list. function(cxx_test name libs) cxx_test_with_flags("${name}" "${cxx_default}" "${libs}" @@ -270,8 +269,8 @@ endfunction() # py_test(name) # -# creates a Python test with the given name whose main module is in -# test/name.py. It does nothing if Python is not installed. +# Creates a Python test with the given name whose main module is in +# test/name.py. It does nothing if Python is not installed. function(py_test name) if (NOT Python3_Interpreter_FOUND) return() @@ -307,7 +306,7 @@ function(install_project) ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - # Install PDBs + # Install PDBs. foreach(t ${ARGN}) get_target_property(t_pdb_name ${t} COMPILE_PDB_NAME) get_target_property(t_pdb_name_debug ${t} COMPILE_PDB_NAME_DEBUG) -- cgit v1.2.3 From beb552fb47e9e8a6ddab20526663c2dddd601ec6 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Tue, 3 Oct 2023 11:41:17 -0700 Subject: gmock_cook_book: Document `DoAll`'s return type requirement The requirement is vaguely documented by "Only the return value of the last action in the sequence will be used.". However, this can be misleading, as users could potentially expect default-constructed values to be returned in absence of a matching return type. PiperOrigin-RevId: 570450839 Change-Id: Ibd98a6e6b2aaf2a8cfc15ed6aeab442526eab98e --- docs/gmock_cook_book.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/gmock_cook_book.md b/docs/gmock_cook_book.md index da10918c..5e9b6647 100644 --- a/docs/gmock_cook_book.md +++ b/docs/gmock_cook_book.md @@ -1927,6 +1927,12 @@ class MockFoo : public Foo { 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} If you want to verify that a method is called with a particular argument but the -- cgit v1.2.3 From 2dd1c131950043a8ad5ab0d2dda0e0970596586a Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 5 Oct 2023 14:12:08 -0700 Subject: Fix RE::Init for Android and NetBSD. This is a somewhat recent change for Android (I'm not clear on whether it's a recent change for NetBSD, or if Android was just very behind on its implementation), so while this worked fine as recently as API 32 devices, REG_GNU is required for API 34 (API 33 untested). A test actually caught this, but https://github.com/google/googletest/pull/4334 "fixed" the test rather than the implementation. This CL also reverts the test change so it can catch the failure. PiperOrigin-RevId: 571126374 Change-Id: I420dfcedea58f2c8b605f699515d744006c0a9d9 --- googletest/src/gtest-port.cc | 15 +++++++++++++-- googletest/test/googletest-port-test.cc | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index e9d12d92..3bb7dd45 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -697,13 +697,24 @@ bool RE::PartialMatch(const char* str, const RE& re) { void RE::Init(const char* 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 // full match. const size_t full_regex_len = strlen(regex) + 10; char* const full_pattern = new char[full_regex_len]; snprintf(full_pattern, full_regex_len, "^(%s)$", regex); - is_valid_ = regcomp(&full_regex_, full_pattern, REG_EXTENDED) == 0; + is_valid_ = regcomp(&full_regex_, full_pattern, reg_flags) == 0; // We want to call regcomp(&partial_regex_, ...) even if the // previous expression returns false. Otherwise partial_regex_ may // not be properly initialized can may cause trouble when it's @@ -714,7 +725,7 @@ void RE::Init(const char* regex) { // regex. We change it to an equivalent form "()" to be safe. if (is_valid_) { const char* const partial_regex = (*regex == '\0') ? "()" : regex; - is_valid_ = regcomp(&partial_regex_, partial_regex, REG_EXTENDED) == 0; + is_valid_ = regcomp(&partial_regex_, partial_regex, reg_flags) == 0; } EXPECT_TRUE(is_valid_) << "Regular expression \"" << regex diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index 8d210260..9f05a019 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -418,8 +418,8 @@ TYPED_TEST(RETest, ImplicitConstructorWorks) { const RE simple(TypeParam("hello")); EXPECT_STREQ("hello", simple.pattern()); - const RE normal(TypeParam(".*([[:alnum:]_]+)")); - EXPECT_STREQ(".*([[:alnum:]_]+)", normal.pattern()); + const RE normal(TypeParam(".*(\\w+)")); + EXPECT_STREQ(".*(\\w+)", normal.pattern()); } // Tests that RE's constructors reject invalid regular expressions. -- cgit v1.2.3 From 829c19901dac454ced475fec6a11e8e1b8a61549 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Tue, 17 Oct 2023 09:18:09 -0700 Subject: gtest-death-test-internal: Delete obsolete string constants These are not used anywhere in googletest and they are in namespace `testing::internal` PiperOrigin-RevId: 574171727 Change-Id: I5f668157a81ba3efaed77c1302b40cf07eeda52b --- googletest/include/gtest/internal/gtest-death-test-internal.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-death-test-internal.h b/googletest/include/gtest/internal/gtest-death-test-internal.h index 8e9c988b..61536d65 100644 --- a/googletest/include/gtest/internal/gtest-death-test-internal.h +++ b/googletest/include/gtest/internal/gtest-death-test-internal.h @@ -52,9 +52,7 @@ GTEST_DECLARE_string_(internal_run_death_test); namespace testing { namespace internal { -// Names of the flags (needed for parsing Google Test flags). -const char kDeathTestStyleFlag[] = "death_test_style"; -const char kDeathTestUseFork[] = "death_test_use_fork"; +// Name of the flag (needed for parsing Google Test flag). const char kInternalRunDeathTestFlag[] = "internal_run_death_test"; #ifdef GTEST_HAS_DEATH_TEST -- cgit v1.2.3 From 9bb354fa8325fa31faa1e12627b25ab445e6eed3 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 17 Oct 2023 23:50:03 -0700 Subject: s/::testing::/testing::/ in test documentation outside of using statements to align with best practice PiperOrigin-RevId: 574377544 Change-Id: I0ca69a3bf14cc1aab75784eba220a48bf50cef04 --- docs/primer.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/primer.md b/docs/primer.md index 4901e1ab..8b98da2a 100644 --- a/docs/primer.md +++ b/docs/primer.md @@ -210,7 +210,7 @@ objects for several different tests. 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. 2. Inside the class, declare any objects you plan to use. 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. ```c++ -class QueueTest : public ::testing::Test { +class QueueTest : public testing::Test { protected: void SetUp() override { // q0_ remains empty @@ -402,7 +402,7 @@ namespace project { namespace { // The fixture for testing class Foo. -class FooTest : public ::testing::Test { +class FooTest : public testing::Test { protected: // You can remove any or all of the following functions if their bodies would // be empty. @@ -450,14 +450,14 @@ TEST_F(FooTest, DoesXyz) { } // namespace my int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); + testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } ``` -The `::testing::InitGoogleTest()` function parses the command line for -GoogleTest flags, and removes all recognized flags. This allows the user to -control a test program's behavior via various flags, which we'll cover in the +The `testing::InitGoogleTest()` function parses the command line for GoogleTest +flags, and removes all recognized flags. This allows the user to 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 `RUN_ALL_TESTS()`, or the flags won't be properly initialized. -- cgit v1.2.3 From 116b7e55281c4200151524b093ecc03757a4ffda Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 19 Oct 2023 13:54:41 -0700 Subject: Improve error message for invalid parameterized test names. PiperOrigin-RevId: 574992011 Change-Id: Id6030a9e5f317966186cc48ef2c09ad97fa15d3e --- googletest/include/gtest/internal/gtest-param-util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h index dd39e98a..b04f7020 100644 --- a/googletest/include/gtest/internal/gtest-param-util.h +++ b/googletest/include/gtest/internal/gtest-param-util.h @@ -584,8 +584,8 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { GTEST_CHECK_(IsValidParamName(param_name)) << "Parameterized test name '" << param_name - << "' is invalid (contains spaces, dashes, underscores, or " - "non-alphanumeric characters), in " + << "' is invalid (contains spaces, dashes, or any " + "non-alphanumeric characters other than underscores), in " << file << " line " << line << "" << std::endl; GTEST_CHECK_(test_param_names.count(param_name) == 0) -- cgit v1.2.3 From 518387203b573f35477fa6872dd54620e70d2bdb Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Mon, 23 Oct 2023 10:10:45 -0700 Subject: StartsWith: Explicitly construct matcher-typed strings from matchee parameter The current implementation breaks for absl::string_view on gcc, c++14: https://godbolt.org/z/Tzd3q1fqx Closes #4391 PiperOrigin-RevId: 575853981 Change-Id: I7b782598add480eb69d4ca27ea4a4bf5f758f6a3 --- googlemock/include/gmock/gmock-matchers.h | 4 ++-- googlemock/test/gmock-matchers-comparisons_test.cc | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 0f677137..8052c74a 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -1048,7 +1048,7 @@ class StartsWithMatcher { template bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { - const StringType& s2(s); + const StringType s2(s); return s2.length() >= prefix_.length() && s2.substr(0, prefix_.length()) == prefix_; } @@ -1102,7 +1102,7 @@ class EndsWithMatcher { template bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { - const StringType& s2(s); + const StringType s2(s); return s2.length() >= suffix_.length() && s2.substr(s2.length() - suffix_.length()) == suffix_; } diff --git a/googlemock/test/gmock-matchers-comparisons_test.cc b/googlemock/test/gmock-matchers-comparisons_test.cc index b2ce99e1..5b75b457 100644 --- a/googlemock/test/gmock-matchers-comparisons_test.cc +++ b/googlemock/test/gmock-matchers-comparisons_test.cc @@ -1769,6 +1769,15 @@ TEST(StartsWithTest, CanDescribeSelf) { 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). TEST(EndsWithTest, MatchesStringWithGivenSuffix) { -- cgit v1.2.3 From 7f036c5563af7d0329f20e8bb42effb04629f0c0 Mon Sep 17 00:00:00 2001 From: Theo Buehler Date: Wed, 25 Oct 2023 07:17:52 +0200 Subject: Add missing include for raise(3) If SIGTRAP is defined, this file may end up using raise(3), which is defined in csignal, leading to a compilation failure on at least OpenBSD/sparc64 with gcc 8. --- googletest/src/gtest.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 99b22ed3..dcf4e269 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -43,6 +43,7 @@ #include #include // NOLINT #include +#include #include #include #include -- cgit v1.2.3 From 5b7fd63d6d69f1754d5f3be956949484ebac06d5 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 26 Oct 2023 13:14:13 -0700 Subject: Export gmock-spec-builders. gmock.h is the umbrella header to be used for rest of the library, and it also enables users to export certain details. This wasn't working for some interfaces like EXPECT_CALL because gmock-spec-builders wasn't explicitly exported. PiperOrigin-RevId: 576966583 Change-Id: Ie050430cf11384977cd95f4ed6e73235d6857057 --- googlemock/include/gmock/gmock.h | 1 + 1 file changed, 1 insertion(+) diff --git a/googlemock/include/gmock/gmock.h b/googlemock/include/gmock/gmock.h index 2ca4f7ac..c78fb8ee 100644 --- a/googlemock/include/gmock/gmock.h +++ b/googlemock/include/gmock/gmock.h @@ -60,6 +60,7 @@ #include "gmock/gmock-more-actions.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-spec-builders.h" // IWYU pragma: export #include "gmock/internal/gmock-internal-utils.h" #include "gmock/internal/gmock-port.h" -- cgit v1.2.3 From 76bb2afb8b522d24496ad1c757a49784fbfa2e42 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 27 Nov 2023 13:31:59 -0800 Subject: Implement `testing::Rethrow` to throw exceptions more easily via `std::exception_ptr` We avoid overloading or specializing `testing::Throw` as this is fundamentally a different operation than throwing the object. However, we disable the corresponding overload of `testing::Throw` to prevent likely mistakes in the usage. Fixes: #4412 PiperOrigin-RevId: 585745469 Change-Id: I03bb585427ce51983d914e88f2bf65a13545c920 --- googlemock/include/gmock/gmock-actions.h | 24 +++++++++++++++++++++--- googlemock/test/gmock_link_test.h | 9 +++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index f20258bc..fab99933 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -135,6 +135,7 @@ #endif #include +#include #include #include #include @@ -1746,6 +1747,13 @@ struct ThrowAction { return [copy](Args...) -> R { throw copy; }; } }; +struct RethrowAction { + std::exception_ptr exception; + template + operator Action() const { // NOLINT + return [ex = exception](Args...) -> R { std::rethrow_exception(ex); }; + } +}; #endif // GTEST_HAS_EXCEPTIONS } // namespace internal @@ -2062,13 +2070,23 @@ internal::ReturnPointeeAction ReturnPointee(Ptr pointer) { return {pointer}; } -// Action Throw(exception) can be used in a mock function of any type -// to throw the given exception. Any copyable value can be thrown. #if GTEST_HAS_EXCEPTIONS +// Action Throw(exception) can be used in a mock function of any type +// to throw the given exception. Any copyable value can be thrown, +// except for std::exception_ptr, which is likely a mistake if +// thrown directly. template -internal::ThrowAction::type> Throw(T&& exception) { +typename std::enable_if< + !std::is_base_of::type>::value, + internal::ThrowAction::type>>::type +Throw(T&& exception) { return {std::forward(exception)}; } +// Action Rethrow(exception_ptr) can be used in a mock function of any type +// to rethrow any exception_ptr. Note that the same object is thrown each time. +inline internal::RethrowAction Rethrow(std::exception_ptr exception) { + return {std::move(exception)}; +} #endif // GTEST_HAS_EXCEPTIONS namespace internal { diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h index db11c2d2..cf0a985b 100644 --- a/googlemock/test/gmock_link_test.h +++ b/googlemock/test/gmock_link_test.h @@ -187,6 +187,7 @@ using testing::SetErrnoAndReturn; #if GTEST_HAS_EXCEPTIONS using testing::Throw; +using testing::Rethrow; #endif using testing::ContainsRegex; @@ -416,6 +417,14 @@ TEST(LinkTest, TestThrow) { EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Throw(42)); EXPECT_THROW(mock.VoidFromString(nullptr), int); } +// Tests the linkage of the Rethrow action. +TEST(LinkTest, TestRethrow) { + Mock mock; + + EXPECT_CALL(mock, VoidFromString(_)) + .WillOnce(Rethrow(std::make_exception_ptr(42))); + EXPECT_THROW(mock.VoidFromString(nullptr), int); +} #endif // GTEST_HAS_EXCEPTIONS // The ACTION*() macros trigger warning C4100 (unreferenced formal -- cgit v1.2.3 From 48b373f6e0019cc766b4e088201fc90fe1373fe2 Mon Sep 17 00:00:00 2001 From: Tamas Kenez Date: Fri, 1 Dec 2023 23:09:45 +0100 Subject: Allow using external absl and re2. --- CMakeLists.txt | 9 +++++++++ googletest/cmake/Config.cmake.in | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 24d41c29..9e6d6440 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,15 @@ 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(GTEST_HAS_ABSL "Use Abseil and RE2. Requires Abseil and RE2 to be separately added to the build." OFF) +if(GTEST_HAS_ABSL) + if(NOT TARGET absl::base) + find_package(absl REQUIRED) + endif() + if(NOT TARGET re2::re2) + find_package(re2 REQUIRED) + endif() +endif() + if(BUILD_GMOCK) add_subdirectory( googlemock ) else() diff --git a/googletest/cmake/Config.cmake.in b/googletest/cmake/Config.cmake.in index 12be4498..3f706612 100644 --- a/googletest/cmake/Config.cmake.in +++ b/googletest/cmake/Config.cmake.in @@ -4,6 +4,10 @@ if (@GTEST_HAS_PTHREAD@) set(THREADS_PREFER_PTHREAD_FLAG @THREADS_PREFER_PTHREAD_FLAG@) find_dependency(Threads) endif() +if (@GTEST_HAS_ABSL@) + find_dependency(absl) + find_dependency(re2) +endif() include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") check_required_components("@project_name@") -- cgit v1.2.3 From 8760db154aec99c70cb487d99aead838212d4986 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Mon, 4 Dec 2023 13:41:38 -0800 Subject: Skip find_package(Python3) when not building tests #4424 claims this saves several seconds of build time Closes #4424 PiperOrigin-RevId: 587827426 Change-Id: I207779a6539f9af16a39d6b40887770dc930b74f --- googletest/cmake/internal_utils.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 21887b2e..580ac1cb 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -247,7 +247,9 @@ function(cxx_executable name dir libs) ${name} "${cxx_default}" "${libs}" "${dir}/${name}.cc" ${ARGN}) endfunction() -find_package(Python3) +if(gtest_build_tests) + find_package(Python3) +endif() # cxx_test_with_flags(name cxx_flags libs srcs...) # -- cgit v1.2.3 From eb80f759d595874a5e905a3342bd8e2af4c0a12d Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 11 Dec 2023 16:16:45 -0800 Subject: Remove unnecessary conversion `GetAbsolutePathToOutputFile` returns a `std::string` and `OpenFileForWriting` takes a `std::string&`. PiperOrigin-RevId: 589984409 Change-Id: I75be9cb105f49b3a279a5d33b1b82dfcfc912cfd --- googletest/src/gtest.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 85d45b58..479b2ee3 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -6203,8 +6203,8 @@ void UnitTestImpl::ListTestsMatchingFilter() { #if GTEST_HAS_FILE_SYSTEM const std::string& output_format = UnitTestOptions::GetOutputFormat(); if (output_format == "xml" || output_format == "json") { - FILE* fileout = OpenFileForWriting( - UnitTestOptions::GetAbsolutePathToOutputFile().c_str()); + FILE* fileout = + OpenFileForWriting(UnitTestOptions::GetAbsolutePathToOutputFile()); std::stringstream stream; if (output_format == "xml") { XmlUnitTestResultPrinter( -- cgit v1.2.3 From 530d5c8c84abd2a46f38583ee817743c9b3a42b4 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 12 Dec 2023 17:40:15 -0800 Subject: Add `FAIL_AT` macro variant of `FAIL` matching `ADD_FAILURE`, `ADD_FAILURE_AT` `FAIL_AT` is shorthand for `GTEST_FAIL_AT` like `FAIL` is for `GTEST_FAIL`. PiperOrigin-RevId: 590393926 Change-Id: I68263af8fa2f98ca0bbef509d475c84e22068018 --- googletest/include/gtest/gtest.h | 1 + 1 file changed, 1 insertion(+) diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index a932e686..45400fd0 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -1751,6 +1751,7 @@ class TestWithParam : public Test, public WithParamInterface {}; // generic name and clashes with some other libraries. #if !(defined(GTEST_DONT_DEFINE_FAIL) && GTEST_DONT_DEFINE_FAIL) #define FAIL() GTEST_FAIL() +#define FAIL_AT(file, line) GTEST_FAIL_AT(file, line) #endif // Generates a success with a generic message. -- cgit v1.2.3 From 8495449f075543dbac005d6c33118e58ad770d75 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 18 Dec 2023 10:14:04 -0800 Subject: Fix data race in leak detection TSAN identified a data race between updates to the states_ map (ex. in Mock::UnregisterLocked) and the iteration done in this destructor. Writes to the map use g_gmock_mutex, but the destructor does not acquire it. Acquiring the lock here fixes the data race. It should only be possible to trigger this TSAN finding in cases where a mock object is deleted by a thread other than the main thread. PiperOrigin-RevId: 591935393 Change-Id: I9dd1faa40058d78e165a91333346514b4b73365c --- googlemock/src/gmock-spec-builders.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index de894716..fb67ab09 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -490,6 +490,7 @@ class MockObjectRegistry { // failure, unless the user explicitly asked us to ignore it. ~MockObjectRegistry() { if (!GMOCK_FLAG_GET(catch_leaked_mocks)) return; + internal::MutexLock l(&internal::g_gmock_mutex); int leaked_count = 0; for (StateMap::const_iterator it = states_.begin(); it != states_.end(); -- cgit v1.2.3 From cde9a745a66dc349dde300cb357974ef4f4b11fc Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Tue, 19 Dec 2023 13:55:58 -0800 Subject: Fix broken links in primer.md Closes #4432 PiperOrigin-RevId: 592335698 Change-Id: I9859451981f58f1426255067d702a0767718b1d5 --- docs/primer.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/primer.md b/docs/primer.md index 8b98da2a..0f90c039 100644 --- a/docs/primer.md +++ b/docs/primer.md @@ -73,8 +73,8 @@ Meaning Exercise a particular program path with specific input values and verify the results | [TEST()](#simple-tests) | [Test Case][istqb test case] -[istqb test case]: https://glossary.istqb.org/en/search/test%20case -[istqb test suite]: https://glossary.istqb.org/en/search/test%20suite +[istqb test case]: https://glossary.istqb.org/en_US/term/test-case-2 +[istqb test suite]: https://glossary.istqb.org/en_US/term/test-suite-1-3 ## Basic Concepts -- cgit v1.2.3 From 96eadf659fb75ecda943bd97413c71d4c17c4f43 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 22 Dec 2023 08:50:31 -0800 Subject: Minor documentation correction. PiperOrigin-RevId: 593126348 Change-Id: I78e12ab5dd2e5acc69b21250bdb04e62990b6309 --- docs/reference/mocking.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference/mocking.md b/docs/reference/mocking.md index ab37ebf3..3ad49527 100644 --- a/docs/reference/mocking.md +++ b/docs/reference/mocking.md @@ -81,8 +81,8 @@ EXPECT_CALL(mock_object, method_name(matchers...)) .Times(cardinality) // Can be used at most once .InSequence(sequences...) // Can be used any number of times .After(expectations...) // Can be used any number of times - .WillOnce(action) // Can be used any number of times - .WillRepeatedly(action) // Can be used at most once + .WillRepeatedly(action) // Can be used any number of times + .WillOnce(action) // Can be used at most once .RetiresOnSaturation(); // Can be used at most once ``` -- cgit v1.2.3 From dddb219c3eb96d7f9200f09b0a381f016e6b4562 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 28 Dec 2023 04:03:13 -0800 Subject: Accept move-only callables in `InvokeArguments` PiperOrigin-RevId: 594223533 Change-Id: I491fae7d851d4e0df07fb3627416949071fec8d6 --- googlemock/include/gmock/gmock-more-actions.h | 2 +- googlemock/test/gmock-more-actions_test.cc | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/googlemock/include/gmock/gmock-more-actions.h b/googlemock/include/gmock/gmock-more-actions.h index 40300766..dd90e31f 100644 --- a/googlemock/include/gmock/gmock-more-actions.h +++ b/googlemock/include/gmock/gmock-more-actions.h @@ -606,7 +606,7 @@ struct InvokeArgumentAction { internal::FlatTuple args_tuple(FlatTupleConstructTag{}, std::forward(args)...); return params.Apply([&](const Params &...unpacked_params) { - auto &&callable = args_tuple.template Get(); + auto &&callable = std::move(args_tuple.template Get()); return internal::InvokeArgument( std::forward(callable), unpacked_params...); }); diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 9980f3bc..16af6892 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -85,6 +85,12 @@ struct UnaryFunctor { int operator()(bool x) { return x ? 1 : -1; } }; +struct UnaryMoveOnlyFunctor : UnaryFunctor { + UnaryMoveOnlyFunctor() = default; + UnaryMoveOnlyFunctor(const UnaryMoveOnlyFunctor&) = delete; + UnaryMoveOnlyFunctor(UnaryMoveOnlyFunctor&&) = default; +}; + const char* Binary(const char* input, short n) { return input + n; } // NOLINT int Ternary(int x, char y, short z) { return x + y + z; } // NOLINT @@ -698,12 +704,18 @@ TEST(InvokeArgumentTest, Function0) { EXPECT_EQ(1, a.Perform(std::make_tuple(2, &Nullary))); } -// Tests using InvokeArgument with a unary function. +// Tests using InvokeArgument with a unary functor. TEST(InvokeArgumentTest, Functor1) { Action a = InvokeArgument<0>(true); // NOLINT EXPECT_EQ(1, a.Perform(std::make_tuple(UnaryFunctor()))); } +// Tests using InvokeArgument with a unary move-only functor. +TEST(InvokeArgumentTest, Functor1MoveOnly) { + Action a = InvokeArgument<0>(true); // NOLINT + EXPECT_EQ(1, a.Perform(std::make_tuple(UnaryMoveOnlyFunctor()))); +} + // Tests using InvokeArgument with a 5-ary function. TEST(InvokeArgumentTest, Function5) { Action a = // NOLINT -- cgit v1.2.3 From 3b26f7e53bbe287deb57c75c796f17c9a82229a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kosi=C5=84ski?= Date: Tue, 9 Jan 2024 08:38:41 -0800 Subject: Disable -Wfloat-equal in AppropriateResolution(). This function makes exact floating point that are correct in this context, but trigger the compiler warning. PiperOrigin-RevId: 596944060 Change-Id: I4bba3c2abcf3ac189107530978961955ad47d6f0 --- googletest/include/gtest/gtest-printers.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 1b12ef68..0007a2a9 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -552,6 +552,10 @@ int AppropriateResolution(FloatType val) { int full = std::numeric_limits::max_digits10; if (val < 0) val = -val; +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif if (val < 1000000) { FloatType mulfor6 = 1e10; if (val >= 100000.0) { // 100,000 to 999,999 @@ -595,6 +599,9 @@ int AppropriateResolution(FloatType val) { val) return 6; } +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif return full; } -- cgit v1.2.3 From 7f409cb3c04694cdf867a04f11121eab35a67597 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 9 Jan 2024 09:38:37 -0800 Subject: Add a note about argv requiring NULL termination. Fixes: #4434 PiperOrigin-RevId: 596960654 Change-Id: I1f70cc0801764fe0328030c46254f82eb9893a49 --- docs/reference/testing.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/reference/testing.md b/docs/reference/testing.md index ead66b36..81640fd4 100644 --- a/docs/reference/testing.md +++ b/docs/reference/testing.md @@ -1317,7 +1317,9 @@ tests. Initializes GoogleTest. This must be called before calling [`RUN_ALL_TESTS()`](#RUN_ALL_TESTS). In particular, it parses the command line for the flags that GoogleTest recognizes. Whenever a GoogleTest flag is seen, it -is removed from `argv`, and `*argc` is decremented. +is removed from `argv`, and `*argc` is decremented. Keep in mind that `argv` +must terminate with a `NULL` pointer (i.e. `argv[argc]` is `NULL`), which is +already the case with the default `argv` passed to `main`. No value is returned. Instead, the GoogleTest flag variables are updated. -- cgit v1.2.3 From 7c07a863693b0c831f80473f7c6905d7e458682c Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Tue, 9 Jan 2024 13:01:48 -0800 Subject: Update CI builds to use Bazel 7.0.0 --features=external_include_paths has been removed from Windows builds since it appears cause build command errors currently PiperOrigin-RevId: 597020418 Change-Id: Ie37be0d05f3a154ab0d3c3f7d39b4e2c0ed650a3 --- ci/linux-presubmit.sh | 7 +++---- ci/macos-presubmit.sh | 2 +- ci/windows-presubmit.bat | 3 +-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/ci/linux-presubmit.sh b/ci/linux-presubmit.sh index a1caa272..1e05998e 100644 --- a/ci/linux-presubmit.sh +++ b/ci/linux-presubmit.sh @@ -31,7 +31,7 @@ set -euox pipefail -readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20230816" +readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20231218" readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20230120" if [[ -z ${GTEST_ROOT:-} ]]; then @@ -80,7 +80,6 @@ time docker run \ --copt="-Wuninitialized" \ --copt="-Wundef" \ --copt="-Wno-error=pragmas" \ - --distdir="/bazel-distdir" \ --features=external_include_paths \ --keep_going \ --show_timestamps \ @@ -102,7 +101,7 @@ for std in ${STD}; do --copt="-Wuninitialized" \ --copt="-Wundef" \ --define="absl=${absl}" \ - --distdir="/bazel-distdir" \ + --enable_bzlmod=false \ --features=external_include_paths \ --keep_going \ --show_timestamps \ @@ -127,7 +126,7 @@ for std in ${STD}; do --copt="-Wuninitialized" \ --copt="-Wundef" \ --define="absl=${absl}" \ - --distdir="/bazel-distdir" \ + --enable_bzlmod=false \ --features=external_include_paths \ --keep_going \ --linkopt="--gcc-toolchain=/usr/local" \ diff --git a/ci/macos-presubmit.sh b/ci/macos-presubmit.sh index 681ebc2a..1033282e 100644 --- a/ci/macos-presubmit.sh +++ b/ci/macos-presubmit.sh @@ -53,7 +53,7 @@ done # Test the Bazel build # If we are running on Kokoro, check for a versioned Bazel binary. -KOKORO_GFILE_BAZEL_BIN="bazel-5.1.1-darwin-x86_64" +KOKORO_GFILE_BAZEL_BIN="bazel-7.0.0-darwin-x86_64" if [[ ${KOKORO_GFILE_DIR:-} ]] && [[ -f ${KOKORO_GFILE_DIR}/${KOKORO_GFILE_BAZEL_BIN} ]]; then BAZEL_BIN="${KOKORO_GFILE_DIR}/${KOKORO_GFILE_BAZEL_BIN}" chmod +x ${BAZEL_BIN} diff --git a/ci/windows-presubmit.bat b/ci/windows-presubmit.bat index 48962eb9..38565fbf 100644 --- a/ci/windows-presubmit.bat +++ b/ci/windows-presubmit.bat @@ -1,6 +1,6 @@ SETLOCAL ENABLEDELAYEDEXPANSION -SET BAZEL_EXE=%KOKORO_GFILE_DIR%\bazel-5.1.1-windows-x86_64.exe +SET BAZEL_EXE=%KOKORO_GFILE_DIR%\bazel-7.0.0-windows-x86_64.exe SET PATH=C:\Python34;%PATH% SET BAZEL_PYTHON=C:\python34\python.exe @@ -51,7 +51,6 @@ SET BAZEL_VS=C:\Program Files\Microsoft Visual Studio\2022\Community --compilation_mode=dbg ^ --copt=/std:c++14 ^ --copt=/WX ^ - --features=external_include_paths ^ --keep_going ^ --test_output=errors ^ --test_tag_filters=-no_test_msvc2017 -- cgit v1.2.3 From f57505314bca32c5c5f186fd52c3cb720bf1853c Mon Sep 17 00:00:00 2001 From: Michael Leslie Date: Wed, 10 Jan 2024 11:34:22 -0800 Subject: only apply -lregex for qnx710 and newer --- googletest/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index 51a67c91..dce6a7c9 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -147,7 +147,7 @@ target_include_directories(gtest SYSTEM INTERFACE target_include_directories(gtest_main SYSTEM INTERFACE "$" "$/${CMAKE_INSTALL_INCLUDEDIR}>") -if(CMAKE_SYSTEM_NAME MATCHES "QNX") +if(CMAKE_SYSTEM_NAME MATCHES "QNX" AND CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL 7.1) target_link_libraries(gtest PUBLIC regex) endif() target_link_libraries(gtest_main PUBLIC gtest) -- cgit v1.2.3 From cfe5076a8b99ce7979b0b5d328ff8a9199e04eef Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 16 Jan 2024 11:18:39 -0800 Subject: Do not emit stack traces for messages generated by GTEST_SKIP() Stack traces in assertion failures are an extremely useful tool for developers tasked with investigating failing tests. It's difficult to understate this. In contrast to ordinary test assertions (e.g., ASSERT_TRUE or EXPECT_FALSE), GTEST_SKIP is a developer-authored directive to skip one or more tests. Stack traces emitted in skip messages do not give the developer useful information, as the skip message itself contains the code location where GTEST_SKIP was used. In addition to being noise in the output, symbolization of stack traces is not free. In some Chromium configurations, symbolization in a skipped test can incur a cost in excess of 25 seconds for a test that otherwise takes 0-1ms; see https://crbug.com/1517343#c9. In this CL, we suppress generation and emission of stack traces for kSkip messages to reduce the output noise and overhead of GTEST_SKIP(). PiperOrigin-RevId: 598899010 Change-Id: I46926fed452c8d7edcb3d636d8fed42cb6c0a9e9 --- googletest/src/gtest.cc | 7 ++++++- googletest/test/googletest-output-test-golden-lin.txt | 1 - googletest/test/gtest_xml_output_unittest.py | 15 +++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 479b2ee3..46212e74 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -459,7 +459,12 @@ void AssertHelper::operator=(const Message& message) const { UnitTest::GetInstance()->AddTestPartResult( data_->type, data_->file, data_->line, AppendUserMessage(data_->message, message), - UnitTest::GetInstance()->impl()->CurrentOsStackTraceExceptTop(1) + // Suppress emission of the stack trace for GTEST_SKIP() since skipping is + // an intentional act by the developer rather than a failure requiring + // investigation. + data_->type != TestPartResult::kSkip + ? UnitTest::GetInstance()->impl()->CurrentOsStackTraceExceptTop(1) + : "" // Skips the stack frame for this function itself. ); // NOLINT } diff --git a/googletest/test/googletest-output-test-golden-lin.txt b/googletest/test/googletest-output-test-golden-lin.txt index 6ddf822f..e06856a2 100644 --- a/googletest/test/googletest-output-test-golden-lin.txt +++ b/googletest/test/googletest-output-test-golden-lin.txt @@ -970,7 +970,6 @@ googletest-output-test_.cc:#: Skipped [----------] 1 test from TestSuiteThatSkipsInSetUp googletest-output-test_.cc:#: Skipped Skip entire test suite -Stack trace: (omitted) [ RUN ] TestSuiteThatSkipsInSetUp.ShouldNotRun googletest-output-test_.cc:#: Skipped diff --git a/googletest/test/gtest_xml_output_unittest.py b/googletest/test/gtest_xml_output_unittest.py index 422569e4..c3fea2c0 100755 --- a/googletest/test/gtest_xml_output_unittest.py +++ b/googletest/test/gtest_xml_output_unittest.py @@ -112,20 +112,23 @@ Invalid characters in brackets []%(stack)s]]> - + - + - + -- cgit v1.2.3 From f6f920d2ba09f3951af59045cd31c42e95bf127a Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 16 Jan 2024 12:55:45 -0800 Subject: Make posix::FileNo available under !GTEST_HAS_FILE_SYSTEM This enables automatic color output without filesystem support, as that only requires testing to see if the output is a terminal. Fixes: #4439 PiperOrigin-RevId: 598929397 Change-Id: Idca7490e6e090951a78cd1cdd710f41d756a68b4 --- googletest/include/gtest/internal/gtest-port.h | 11 +++++++++-- googletest/src/gtest.cc | 6 ++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index d061a49b..f2b591df 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -2005,7 +2005,9 @@ inline std::string StripTrailingSpaces(std::string str) { namespace posix { // File system porting. -#if GTEST_HAS_FILE_SYSTEM +// Note: Not every I/O-related function is related to file systems, so don't +// just disable all of them here. For example, fileno() and isatty(), etc. must +// always be available in order to detect if a pipe points to a terminal. #ifdef GTEST_OS_WINDOWS typedef struct _stat StatStruct; @@ -2016,27 +2018,32 @@ inline int FileNo(FILE* file) { return reinterpret_cast(_fileno(file)); } // time and thus not defined there. #else inline int FileNo(FILE* file) { return _fileno(file); } +#if GTEST_HAS_FILE_SYSTEM inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); } inline int RmDir(const char* dir) { return _rmdir(dir); } inline bool IsDir(const StatStruct& st) { return (_S_IFDIR & st.st_mode) != 0; } +#endif #endif // GTEST_OS_WINDOWS_MOBILE #elif defined(GTEST_OS_ESP8266) typedef struct stat StatStruct; inline int FileNo(FILE* file) { return fileno(file); } +#if GTEST_HAS_FILE_SYSTEM inline int Stat(const char* path, StatStruct* buf) { // stat function not implemented on ESP8266 return 0; } inline int RmDir(const char* dir) { return rmdir(dir); } inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } +#endif #else typedef struct stat StatStruct; inline int FileNo(FILE* file) { return fileno(file); } +#if GTEST_HAS_FILE_SYSTEM inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); } #ifdef GTEST_OS_QURT // QuRT doesn't support any directory functions, including rmdir @@ -2045,9 +2052,9 @@ inline int RmDir(const char*) { return 0; } inline int RmDir(const char* dir) { return rmdir(dir); } #endif inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } +#endif #endif // GTEST_OS_WINDOWS -#endif // GTEST_HAS_FILE_SYSTEM // Other functions with a different name on Windows. diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 46212e74..8a19c50c 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -3288,11 +3288,9 @@ static void ColoredPrintf(GTestColor color, const char* fmt, ...) { va_start(args, fmt); static const bool in_color_mode = -#if GTEST_HAS_FILE_SYSTEM + // We don't condition this on GTEST_HAS_FILE_SYSTEM because we still need + // to be able to detect terminal I/O regardless. ShouldUseColor(posix::IsATTY(posix::FileNo(stdout)) != 0); -#else - false; -#endif // GTEST_HAS_FILE_SYSTEM const bool use_color = in_color_mode && (color != GTestColor::kDefault); -- cgit v1.2.3 From 96cd50c082d880a9aab6455dcc5817cfbf0ea45f Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 18 Jan 2024 14:23:34 -0800 Subject: If GTEST_NO_ABSL_FLAGS is #defined, then the Abseil flag library will not be used by googletest, even if GTEST_HAS_ABSL is #defined. PiperOrigin-RevId: 599625032 Change-Id: Ieb994a15683dec89e88578120071eca8ac9fead1 --- googletest/include/gtest/internal/gtest-port.h | 12 +++++++----- googletest/src/gtest.cc | 8 +++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index f2b591df..fa457b78 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -338,9 +338,10 @@ #define GTEST_HAS_NOTIFICATION_ 0 #endif -#ifdef GTEST_HAS_ABSL -#include "absl/flags/declare.h" +#if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS) +#define GTEST_INTERNAL_HAS_ABSL_FLAGS // Used only in this file. #include "absl/flags/flag.h" +#include "absl/flags/declare.h" #include "absl/flags/reflection.h" #endif @@ -2252,7 +2253,7 @@ using TimeInMillis = int64_t; // Represents time in milliseconds. #endif // !defined(GTEST_FLAG) // Pick a command line flags implementation. -#ifdef GTEST_HAS_ABSL +#ifdef GTEST_INTERNAL_HAS_ABSL_FLAGS // Macros for defining flags. #define GTEST_DEFINE_bool_(name, default_val, doc) \ @@ -2277,7 +2278,8 @@ using TimeInMillis = int64_t; // Represents time in milliseconds. (void)(::absl::SetFlag(>EST_FLAG(name), value)) #define GTEST_USE_OWN_FLAGFILE_FLAG_ 0 -#else // GTEST_HAS_ABSL +#undef GTEST_INTERNAL_HAS_ABSL_FLAGS +#else // ndef GTEST_INTERNAL_HAS_ABSL_FLAGS // Macros for defining flags. #define GTEST_DEFINE_bool_(name, default_val, doc) \ @@ -2319,7 +2321,7 @@ using TimeInMillis = int64_t; // Represents time in milliseconds. #define GTEST_FLAG_SET(name, value) (void)(::testing::GTEST_FLAG(name) = value) #define GTEST_USE_OWN_FLAGFILE_FLAG_ 1 -#endif // GTEST_HAS_ABSL +#endif // GTEST_INTERNAL_HAS_ABSL_FLAGS // Thread annotations #if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 8a19c50c..7dc80594 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -162,6 +162,10 @@ #define GTEST_HAS_BUILTIN(x) 0 #endif // defined(__has_builtin) +#if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS) +#define GTEST_HAS_ABSL_FLAGS +#endif + namespace testing { using internal::CountIf; @@ -6688,7 +6692,7 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) { // remain in place. Unrecognized flags are not reported and do not cause the // program to exit. void ParseGoogleTestFlagsOnly(int* argc, char** argv) { -#ifdef GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL_FLAGS if (*argc <= 0) return; std::vector positional_args; @@ -6774,11 +6778,13 @@ void InitGoogleTestImpl(int* argc, CharType** argv) { #ifdef GTEST_HAS_ABSL absl::InitializeSymbolizer(g_argvs[0].c_str()); +#ifdef GTEST_HAS_ABSL_FLAGS // When using the Abseil Flags library, set the program usage message to the // help message, but remove the color-encoding from the message first. absl::SetProgramUsageMessage(absl::StrReplaceAll( kColorEncodedHelpMessage, {{"@D", ""}, {"@R", ""}, {"@G", ""}, {"@Y", ""}, {"@@", "@"}})); +#endif // GTEST_HAS_ABSL_FLAGS #endif // GTEST_HAS_ABSL ParseGoogleTestFlagsOnly(argc, argv); -- cgit v1.2.3 From ffc477e705589a697b062c366480d80fe6124e9b Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Mon, 22 Jan 2024 10:11:40 -0800 Subject: googletest: Fix incorrect comment about `value_param` of `internal::MakeAndRegisterTestInfo` This was probably a copy-paste from the comment about `type_param`. PiperOrigin-RevId: 600493462 Change-Id: I4a41c2673dd6560db0f68856aab3d32b103164b1 --- googletest/include/gtest/internal/gtest-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 4f077fcf..806b0862 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -555,7 +555,7 @@ struct SuiteApiResolver : T { // type_param: the name of the test's type parameter, or NULL if // this is not a typed or a type-parameterized test. // value_param: text representation of the test's value parameter, -// or NULL if this is not a type-parameterized test. +// or NULL if this is not a value-parameterized test. // code_location: code location where the test is defined // fixture_class_id: ID of the test fixture class // set_up_tc: pointer to the function that sets up the test suite -- cgit v1.2.3 From 563ebf1769af08d448765c31064260e1a16fcced Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 23 Jan 2024 07:02:01 -0800 Subject: Fix double-promotion warnings in AppropriateResolution() When -Wdouble-promotion is enabled, the templatized function AppropriateResolution fails to compile since its float instantiation promotes floats to doubles when doing arithmetic and comparisons. Add static casts to resolve these errors. PiperOrigin-RevId: 600776333 Change-Id: Ia530b4bbca6ddce27caf0a817196d87efef711cb --- googletest/include/gtest/gtest-printers.h | 49 ++++++++++++++++++------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 0007a2a9..b2822bcd 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -124,7 +124,7 @@ #if GTEST_INTERNAL_HAS_STD_SPAN #include // NOLINT -#endif // GTEST_INTERNAL_HAS_STD_SPAN +#endif // GTEST_INTERNAL_HAS_STD_SPAN namespace testing { @@ -241,8 +241,8 @@ struct StreamPrinter { // ADL (possibly involving implicit conversions). // (Use SFINAE via return type, because it seems GCC < 12 doesn't handle name // lookup properly when we do it in the template parameter list.) - static auto PrintValue(const T& value, ::std::ostream* os) - -> decltype((void)(*os << value)) { + static auto PrintValue(const T& value, + ::std::ostream* os) -> decltype((void)(*os << value)) { // Call streaming operator found by ADL, possibly with implicit conversions // of the arguments. *os << value; @@ -558,43 +558,50 @@ int AppropriateResolution(FloatType val) { #endif if (val < 1000000) { FloatType mulfor6 = 1e10; - if (val >= 100000.0) { // 100,000 to 999,999 + // Without these static casts, the template instantiation for float would + // fail to compile when -Wdouble-promotion is enabled, as the arithmetic and + // comparison logic would promote floats to doubles. + if (val >= static_cast(100000.0)) { // 100,000 to 999,999 mulfor6 = 1.0; - } else if (val >= 10000.0) { + } else if (val >= static_cast(10000.0)) { mulfor6 = 1e1; - } else if (val >= 1000.0) { + } else if (val >= static_cast(1000.0)) { mulfor6 = 1e2; - } else if (val >= 100.0) { + } else if (val >= static_cast(100.0)) { mulfor6 = 1e3; - } else if (val >= 10.0) { + } else if (val >= static_cast(10.0)) { mulfor6 = 1e4; - } else if (val >= 1.0) { + } else if (val >= static_cast(1.0)) { mulfor6 = 1e5; - } else if (val >= 0.1) { + } else if (val >= static_cast(0.1)) { mulfor6 = 1e6; - } else if (val >= 0.01) { + } else if (val >= static_cast(0.01)) { mulfor6 = 1e7; - } else if (val >= 0.001) { + } else if (val >= static_cast(0.001)) { mulfor6 = 1e8; - } else if (val >= 0.0001) { + } else if (val >= static_cast(0.0001)) { mulfor6 = 1e9; } - if (static_cast(static_cast(val * mulfor6 + 0.5)) / + if (static_cast(static_cast( + val * mulfor6 + (static_cast(0.5)))) / mulfor6 == val) return 6; - } else if (val < 1e10) { - FloatType divfor6 = 1.0; - if (val >= 1e9) { // 1,000,000,000 to 9,999,999,999 + } else if (val < static_cast(1e10)) { + FloatType divfor6 = static_cast(1.0); + if (val >= static_cast(1e9)) { // 1,000,000,000 to 9,999,999,999 divfor6 = 10000; - } else if (val >= 1e8) { // 100,000,000 to 999,999,999 + } else if (val >= + static_cast(1e8)) { // 100,000,000 to 999,999,999 divfor6 = 1000; - } else if (val >= 1e7) { // 10,000,000 to 99,999,999 + } else if (val >= + static_cast(1e7)) { // 10,000,000 to 99,999,999 divfor6 = 100; - } else if (val >= 1e6) { // 1,000,000 to 9,999,999 + } else if (val >= static_cast(1e6)) { // 1,000,000 to 9,999,999 divfor6 = 10; } - if (static_cast(static_cast(val / divfor6 + 0.5)) * + if (static_cast(static_cast( + val / divfor6 + (static_cast(0.5)))) * divfor6 == val) return 6; -- cgit v1.2.3