From 096014a45dc38dff993f5b7bb28a258d8323344b Mon Sep 17 00:00:00 2001 From: Paul Groke Date: Thu, 15 Sep 2022 13:36:49 +0200 Subject: [PATCH 01/75] work around GCC 6~11 ADL bug see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51577 ADL seems to work properly when we do the SFINAE check via the return type, but not when using a dummy template parameter fix #3992 --- googletest/include/gtest/gtest-printers.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 8e4d2953..19c3e0b6 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -205,12 +205,13 @@ struct StreamPrinter { // Don't accept member pointers here. We'd print them via implicit // conversion to bool, which isn't useful. typename = typename std::enable_if< - !std::is_member_pointer::value>::type, - // Only accept types for which we can find a streaming operator via - // ADL (possibly involving implicit conversions). - typename = decltype(std::declval() - << std::declval())> - static void PrintValue(const T& value, ::std::ostream* os) { + !std::is_member_pointer::value>::type> + // Only accept types for which we can find a streaming operator via + // 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)) { // Call streaming operator found by ADL, possibly with implicit conversions // of the arguments. *os << value; From ab669cad0eea4cbe59faf9a421ab01db30ebc13c Mon Sep 17 00:00:00 2001 From: Gonzalo Brito Gadeschi Date: Wed, 28 Dec 2022 06:00:31 -0800 Subject: [PATCH 02/75] Fix warnings with nvc++ as the compiler Closes #3849. --- googletest/include/gtest/internal/gtest-port.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 01bfd1f1..77549e84 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -794,7 +794,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // Ask the compiler not to perform tail call optimization inside // the marked function. #define GTEST_NO_TAIL_CALL_ __attribute__((disable_tail_calls)) -#elif __GNUC__ +#elif __GNUC__ && !defined(__NVCOMPILER) #define GTEST_NO_TAIL_CALL_ \ __attribute__((optimize("no-optimize-sibling-calls"))) #else From 3f9c7fcaa3e5a40cd3afc9a12327399f7b2a3496 Mon Sep 17 00:00:00 2001 From: Ben Yang Date: Thu, 2 Feb 2023 13:14:43 -0800 Subject: [PATCH 03/75] Update testing.md Fixed Parameter Generator table --- docs/reference/testing.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/reference/testing.md b/docs/reference/testing.md index 62cdcc1c..877dfa32 100644 --- a/docs/reference/testing.md +++ b/docs/reference/testing.md @@ -110,6 +110,7 @@ namespace: | `Bool()` | Yields sequence `{false, true}`. | | `Combine(g1, g2, ..., gN)` | Yields as `std::tuple` *n*-tuples all combinations (Cartesian product) of the values generated by the given *n* generators `g1`, `g2`, ..., `gN`. | | `ConvertGenerator(g)` | Yields values generated by generator `g`, `static_cast` to `T`. | + The optional last argument *`name_generator`* is a function or functor that generates custom test name suffixes based on the test parameters. The function must accept an argument of type From b80a07ffe627b20781516f51c548367d1e4d57dd Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 13 Feb 2023 13:45:19 -0800 Subject: [PATCH 04/75] Avoid reliance on header without RTTI on MSVC Fixes: #4144 PiperOrigin-RevId: 509322023 Change-Id: I52bdf6c25ff433327e174d3f9583b3d50b872d58 --- googletest/include/gtest/internal/gtest-port.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index b4fa3f07..bedd67d3 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -2352,7 +2352,8 @@ using Any = ::absl::any; } // namespace testing #else #ifdef __has_include -#if __has_include() && __cplusplus >= 201703L +#if __has_include() && __cplusplus >= 201703L && \ + (!defined(_MSC_VER) || GTEST_HAS_RTTI) // Otherwise for C++17 and higher use std::any for UniversalPrinter<> // specializations. #define GTEST_INTERNAL_HAS_ANY 1 From 2057566e4e16c88f1fea4d6c96b2e2bfb87507a6 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 14 Feb 2023 08:32:59 -0800 Subject: [PATCH 05/75] Remove some filesystem APIs and tests under !GTEST_HAS_FILE_SYSTEM PiperOrigin-RevId: 509537606 Change-Id: I68f7054e34b1fe76c1fd85099fffa4ee3c2b00c0 --- googletest/src/gtest.cc | 7 ++++++- googletest/test/gtest_dirs_test.cc | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index f79f915f..a60a042c 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -2325,7 +2325,9 @@ static std::vector GetReservedAttributesForElement( return std::vector(); } +#if GTEST_HAS_FILE_SYSTEM // TODO(jdesprez): Merge the two getReserved attributes once skip is improved +// This function is only used when file systems are enabled. static std::vector GetReservedOutputAttributesForElement( const std::string& xml_element) { if (xml_element == "testsuites") { @@ -2340,6 +2342,7 @@ static std::vector GetReservedOutputAttributesForElement( // This code is unreachable but some compilers may not realizes that. return std::vector(); } +#endif static std::string FormatWordList(const std::vector& words) { Message word_list; @@ -6802,7 +6805,7 @@ std::string TempDir() { #endif } -#if !defined(GTEST_CUSTOM_SRCDIR_FUNCTION_) +#if GTEST_HAS_FILE_SYSTEM && !defined(GTEST_CUSTOM_SRCDIR_FUNCTION_) // Returns the directory path (including terminating separator) of the current // executable as derived from argv[0]. static std::string GetCurrentExecutableDirectory() { @@ -6811,6 +6814,7 @@ static std::string GetCurrentExecutableDirectory() { } #endif +#if GTEST_HAS_FILE_SYSTEM std::string SrcDir() { #if defined(GTEST_CUSTOM_SRCDIR_FUNCTION_) return GTEST_CUSTOM_SRCDIR_FUNCTION_(); @@ -6825,6 +6829,7 @@ std::string SrcDir() { '/'); #endif } +#endif // Class ScopedTrace diff --git a/googletest/test/gtest_dirs_test.cc b/googletest/test/gtest_dirs_test.cc index c0da9ac4..1a5b63d3 100644 --- a/googletest/test/gtest_dirs_test.cc +++ b/googletest/test/gtest_dirs_test.cc @@ -7,6 +7,8 @@ #include "gtest/gtest.h" #include "gtest/internal/gtest-port.h" +#if GTEST_HAS_FILE_SYSTEM + namespace { class SetEnv { @@ -94,4 +96,6 @@ TEST(SrcDirTest, NotInEnvironment) { EXPECT_NE(testing::SrcDir(), ""); } +#endif // GTEST_HAS_FILE_SYSTEM + } // namespace From f063cd25c90cbd4089a0ff96f5991df4f2721338 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 15 Feb 2023 15:21:19 -0800 Subject: [PATCH 06/75] Remove strdup usage PiperOrigin-RevId: 509947007 Change-Id: I31e1274afa889776829c877c40c9af589298dcf2 --- .../include/gtest/internal/gtest-port.h | 17 +--- googletest/src/gtest-death-test.cc | 94 +++++-------------- googletest/src/gtest-port.cc | 42 ++++----- googletest/test/gtest_unittest.cc | 16 ++-- 4 files changed, 54 insertions(+), 115 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index bedd67d3..ae7fb350 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -923,7 +923,7 @@ class GTEST_API_ RE { ~RE(); // Returns the string representation of the regex. - const char* pattern() const { return pattern_; } + const char* pattern() const { return pattern_.c_str(); } // FullMatch(str, re) returns true if and only if regular expression re // matches the entire str. @@ -941,7 +941,7 @@ class GTEST_API_ RE { private: void Init(const char* regex); - const char* pattern_; + std::string pattern_; bool is_valid_; #if GTEST_USES_POSIX_RE @@ -951,7 +951,7 @@ class GTEST_API_ RE { #else // GTEST_USES_SIMPLE_RE - const char* full_pattern_; // For FullMatch(); + std::string full_pattern_; // For FullMatch(); #endif }; @@ -2032,7 +2032,6 @@ inline int DoIsATTY(int fd) { return isatty(fd); } inline int StrCaseCmp(const char* s1, const char* s2) { return stricmp(s1, s2); } -inline char* StrDup(const char* src) { return strdup(src); } #else // !__BORLANDC__ #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS || GTEST_OS_IOS || \ GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || defined(ESP_PLATFORM) @@ -2043,24 +2042,14 @@ inline int DoIsATTY(int fd) { return _isatty(fd); } inline int StrCaseCmp(const char* s1, const char* s2) { return _stricmp(s1, s2); } -inline char* StrDup(const char* src) { return _strdup(src); } #endif // __BORLANDC__ -#elif GTEST_OS_ESP8266 - -inline int DoIsATTY(int fd) { return isatty(fd); } -inline int StrCaseCmp(const char* s1, const char* s2) { - return strcasecmp(s1, s2); -} -inline char* StrDup(const char* src) { return strdup(src); } - #else inline int DoIsATTY(int fd) { return isatty(fd); } inline int StrCaseCmp(const char* s1, const char* s2) { return strcasecmp(s1, s2); } -inline char* StrDup(const char* src) { return strdup(src); } #endif // GTEST_OS_WINDOWS diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index b6968a9c..7fcf9bf5 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -33,7 +33,9 @@ #include "gtest/gtest-death-test.h" #include +#include #include +#include #include "gtest/internal/custom/gtest.h" #include "gtest/internal/gtest-port.h" @@ -621,6 +623,17 @@ bool DeathTestImpl::Passed(bool status_ok) { return success; } +// Note: The return value points into args, so the return value's lifetime is +// bound to that of args. +std::unique_ptr CreateArgvFromArgs(std::vector& args) { + auto result = std::make_unique(args.size() + 1); + for (size_t i = 0; i < args.size(); ++i) { + result[i] = &args[i][0]; + } + result[args.size()] = nullptr; // extra null terminator + return result; +} + #if GTEST_OS_WINDOWS // WindowsDeathTest implements death tests on Windows. Due to the // specifics of starting new processes on Windows, death tests there are @@ -836,36 +849,6 @@ class FuchsiaDeathTest : public DeathTestImpl { zx::socket stderr_socket_; }; -// Utility class for accumulating command-line arguments. -class Arguments { - public: - Arguments() { args_.push_back(nullptr); } - - ~Arguments() { - for (std::vector::iterator i = args_.begin(); i != args_.end(); - ++i) { - free(*i); - } - } - void AddArgument(const char* argument) { - args_.insert(args_.end() - 1, posix::StrDup(argument)); - } - - template - void AddArguments(const ::std::vector& arguments) { - for (typename ::std::vector::const_iterator i = arguments.begin(); - i != arguments.end(); ++i) { - args_.insert(args_.end() - 1, posix::StrDup(i->c_str())); - } - } - char* const* Argv() { return &args_[0]; } - - int size() { return static_cast(args_.size()) - 1; } - - private: - std::vector args_; -}; - // Waits for the child in a death test to exit, returning its exit // status, or 0 if no child process exists. As a side effect, sets the // outcome data member. @@ -986,10 +969,10 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() { kInternalRunDeathTestFlag + "=" + file_ + "|" + StreamableToString(line_) + "|" + StreamableToString(death_test_index); - Arguments args; - args.AddArguments(GetInjectableArgvs()); - args.AddArgument(filter_flag.c_str()); - args.AddArgument(internal_flag.c_str()); + + std::vector args = GetInjectableArgvs(); + args.push_back(filter_flag); + args.push_back(internal_flag); // Build the pipe for communication with the child. zx_status_t status; @@ -1041,8 +1024,9 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() { GTEST_DEATH_TEST_CHECK_(status == ZX_OK); // Spawn the child process. - status = fdio_spawn_etc(child_job, FDIO_SPAWN_CLONE_ALL, args.Argv()[0], - args.Argv(), nullptr, 2, spawn_actions, + std::unique_ptr argv = CreateArgvFromArgs(args); + status = fdio_spawn_etc(child_job, FDIO_SPAWN_CLONE_ALL, argv[0], argv.get(), + nullptr, 2, spawn_actions, child_process_.reset_and_get_address(), nullptr); GTEST_DEATH_TEST_CHECK_(status == ZX_OK); @@ -1173,34 +1157,6 @@ class ExecDeathTest : public ForkingDeathTest { const int line_; }; -// Utility class for accumulating command-line arguments. -class Arguments { - public: - Arguments() { args_.push_back(nullptr); } - - ~Arguments() { - for (std::vector::iterator i = args_.begin(); i != args_.end(); - ++i) { - free(*i); - } - } - void AddArgument(const char* argument) { - args_.insert(args_.end() - 1, posix::StrDup(argument)); - } - - template - void AddArguments(const ::std::vector& arguments) { - for (typename ::std::vector::const_iterator i = arguments.begin(); - i != arguments.end(); ++i) { - args_.insert(args_.end() - 1, posix::StrDup(i->c_str())); - } - } - char* const* Argv() { return &args_[0]; } - - private: - std::vector args_; -}; - // A struct that encompasses the arguments to the child process of a // threadsafe-style death test process. struct ExecDeathTestArgs { @@ -1410,10 +1366,9 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() { StreamableToString(line_) + "|" + StreamableToString(death_test_index) + "|" + StreamableToString(pipe_fd[1]); - Arguments args; - args.AddArguments(GetArgvsForDeathTestChildProcess()); - args.AddArgument(filter_flag.c_str()); - args.AddArgument(internal_flag.c_str()); + std::vector args = GetArgvsForDeathTestChildProcess(); + args.push_back(filter_flag); + args.push_back(internal_flag); DeathTest::set_last_death_test_message(""); @@ -1422,7 +1377,8 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() { // is necessary. FlushInfoLog(); - const pid_t child_pid = ExecDeathTestSpawnChild(args.Argv(), pipe_fd[0]); + std::unique_ptr argv = CreateArgvFromArgs(args); + const pid_t child_pid = ExecDeathTestSpawnChild(argv.get(), pipe_fd[0]); GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1])); set_child_pid(child_pid); set_read_fd(pipe_fd[0]); diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index d797fe4d..105a3ec8 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -668,7 +668,6 @@ RE::~RE() { regfree(&partial_regex_); regfree(&full_regex_); } - free(const_cast(pattern_)); } // Returns true if and only if regular expression re matches the entire str. @@ -690,7 +689,7 @@ bool RE::PartialMatch(const char* str, const RE& re) { // Initializes an RE from its string representation. void RE::Init(const char* regex) { - pattern_ = posix::StrDup(regex); + pattern_ = regex; // Reserves enough bytes to hold the regular expression used for a // full match. @@ -920,27 +919,26 @@ bool MatchRegexAnywhere(const char* regex, const char* str) { // Implements the RE class. -RE::~RE() { - free(const_cast(pattern_)); - free(const_cast(full_pattern_)); -} +RE::~RE() = default; // Returns true if and only if regular expression re matches the entire str. bool RE::FullMatch(const char* str, const RE& re) { - return re.is_valid_ && MatchRegexAnywhere(re.full_pattern_, str); + return re.is_valid_ && MatchRegexAnywhere(re.full_pattern_.c_str(), str); } // Returns true if and only if regular expression re matches a substring of // str (including str itself). bool RE::PartialMatch(const char* str, const RE& re) { - return re.is_valid_ && MatchRegexAnywhere(re.pattern_, str); + return re.is_valid_ && MatchRegexAnywhere(re.pattern_.c_str(), str); } // Initializes an RE from its string representation. void RE::Init(const char* regex) { - pattern_ = full_pattern_ = nullptr; + full_pattern_.clear(); + pattern_.clear(); + if (regex != nullptr) { - pattern_ = posix::StrDup(regex); + pattern_ = regex; } is_valid_ = ValidateRegex(regex); @@ -949,25 +947,19 @@ void RE::Init(const char* regex) { return; } - const size_t len = strlen(regex); // Reserves enough bytes to hold the regular expression used for a - // full match: we need space to prepend a '^', append a '$', and - // terminate the string with '\0'. - char* buffer = static_cast(malloc(len + 3)); - full_pattern_ = buffer; + // full match: we need space to prepend a '^' and append a '$'. + full_pattern_.reserve(pattern_.size() + 2); - if (*regex != '^') - *buffer++ = '^'; // Makes sure full_pattern_ starts with '^'. + if (pattern_.empty() || pattern_.front() != '^') { + full_pattern_.push_back('^'); // Makes sure full_pattern_ starts with '^'. + } - // We don't use snprintf or strncpy, as they trigger a warning when - // compiled with VC++ 8.0. - memcpy(buffer, regex, len); - buffer += len; + full_pattern_.append(pattern_); - if (len == 0 || regex[len - 1] != '$') - *buffer++ = '$'; // Makes sure full_pattern_ ends with '$'. - - *buffer = '\0'; + if (pattern_.empty() || pattern_.back() != '$') { + full_pattern_.push_back('$'); // Makes sure full_pattern_ ends with '$'. + } } #endif // GTEST_USES_POSIX_RE diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index ecffa376..580ce837 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -60,6 +60,7 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) { #include #include +#include #include #include #include @@ -424,10 +425,12 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { private: void SetUp() override { - saved_tz_ = nullptr; + saved_tz_.reset(); - GTEST_DISABLE_MSC_DEPRECATED_PUSH_(/* getenv, strdup: deprecated */) - if (getenv("TZ")) saved_tz_ = strdup(getenv("TZ")); + GTEST_DISABLE_MSC_DEPRECATED_PUSH_(/* getenv: deprecated */) + if (const char* tz = getenv("TZ")) { + saved_tz_ = std::make_unique(tz); + } GTEST_DISABLE_MSC_DEPRECATED_POP_() // Set up the time zone for FormatEpochTimeInMillisAsIso8601 to use. We @@ -437,9 +440,8 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { } void TearDown() override { - SetTimeZone(saved_tz_); - free(const_cast(saved_tz_)); - saved_tz_ = nullptr; + SetTimeZone(saved_tz_ != nullptr ? saved_tz_->c_str() : nullptr); + saved_tz_.reset(); } static void SetTimeZone(const char* time_zone) { @@ -471,7 +473,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { #endif } - const char* saved_tz_; + std::unique_ptr saved_tz_; // Empty and null are different here }; const TimeInMillis FormatEpochTimeInMillisAsIso8601Test::kMillisPerSec; From 7a7231c442484be389fdf01594310349ca0e42a8 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 16 Feb 2023 07:33:08 -0800 Subject: [PATCH 07/75] Fix link in ReportUninterestingCall message This CL changes the link in the ReportUninterestingCall message from .../gmock_cook_book.md#knowing-when-to-expect to .../gmock_cook_book.md#knowing-when-to-expect-useoncall. This is necessary following https://github.com/google/googletest/commit/31ff597. PiperOrigin-RevId: 510138974 Change-Id: Ic98c84b07751d27dfc95eddbe7874f76d68b456f --- googlemock/src/gmock-spec-builders.cc | 2 +- googlemock/test/gmock-spec-builders_test.cc | 2 +- googlemock/test/gmock_output_test_golden.txt | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 7d7c55ad..afd802c3 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -297,7 +297,7 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) { "See " "https://github.com/google/googletest/blob/main/docs/" "gmock_cook_book.md#" - "knowing-when-to-expect for details.\n", + "knowing-when-to-expect-useoncall for details.\n", stack_frames_to_skip); break; default: // FAIL diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 487b6c3f..ad56ead0 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -2050,7 +2050,7 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture { "See " "https://github.com/google/googletest/blob/main/docs/" "gmock_cook_book.md#" - "knowing-when-to-expect for details."; + "knowing-when-to-expect-useoncall for details."; // A void-returning function. CaptureStdout(); diff --git a/googlemock/test/gmock_output_test_golden.txt b/googlemock/test/gmock_output_test_golden.txt index ac2a5e21..d6c03338 100644 --- a/googlemock/test/gmock_output_test_golden.txt +++ b/googlemock/test/gmock_output_test_golden.txt @@ -75,14 +75,14 @@ GMOCK WARNING: Uninteresting mock function call - returning default value. Function call: Bar2(0, 1) Returns: false -NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details. +NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect-useoncall for details. [ OK ] GMockOutputTest.UninterestingCall [ RUN ] GMockOutputTest.UninterestingCallToVoidFunction GMOCK WARNING: Uninteresting mock function call - returning directly. Function call: Bar3(0, 1) -NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details. +NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect-useoncall for details. [ OK ] GMockOutputTest.UninterestingCallToVoidFunction [ RUN ] GMockOutputTest.RetiredExpectation unknown file: Failure @@ -266,14 +266,14 @@ Uninteresting mock function call - taking default action specified at: FILE:#: Function call: Bar2(2, 2) Returns: true -NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details. +NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect-useoncall for details. GMOCK WARNING: Uninteresting mock function call - taking default action specified at: FILE:#: Function call: Bar2(1, 1) Returns: false -NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details. +NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect-useoncall for details. [ OK ] GMockOutputTest.UninterestingCallWithDefaultAction [ RUN ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction From fe5b7ef71e60072283d57e0417776d05eb4b3e7f Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Fri, 17 Feb 2023 23:22:27 -0800 Subject: [PATCH 08/75] Set CMP0069 policy to avoid warnings When googletest and googlemock are included as a git submodule and referenced as part of an existing CMake project, multiple warnings are printed out due to not setting a value for the CMP0069 policy. --- googletest/cmake/internal_utils.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 0438bef8..7b9f0b7f 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -16,6 +16,10 @@ if (POLICY CMP0054) cmake_policy(SET CMP0054 NEW) endif (POLICY CMP0054) +if (POLICY CMP0069) + cmake_policy(SET CMP0069 NEW) +endif (POLICY CMP0069) + # Tweaks CMake's default compiler/linker settings to suit Google Test's needs. # # This must be a macro(), as inside a function string() can only From 810fb81153d916e728853bd88b11fef365a95e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C5=A9=20Ph=E1=BA=A1m?= <39726720+VuPhamVan@users.noreply.github.com> Date: Sun, 19 Feb 2023 21:59:23 +0700 Subject: [PATCH 09/75] Fix typo --- docs/reference/assertions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/assertions.md b/docs/reference/assertions.md index 7bf03a3d..1cdff266 100644 --- a/docs/reference/assertions.md +++ b/docs/reference/assertions.md @@ -515,7 +515,7 @@ Verifies that *`expression`* is a success `HRESULT`. ### EXPECT_HRESULT_FAILED {#EXPECT_HRESULT_FAILED} `EXPECT_HRESULT_FAILED(`*`expression`*`)` \ -`EXPECT_HRESULT_FAILED(`*`expression`*`)` +`ASSERT_HRESULT_FAILED(`*`expression`*`)` Verifies that *`expression`* is a failure `HRESULT`. From 750d67d809700ae8fca6d610f7b41b71aa161808 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 21 Feb 2023 10:24:42 -0800 Subject: [PATCH 10/75] Remove int64_t cast in RecordProperty Historically, calls to RecordProperty with values that are convertible to int64_t have been casted to int64_t. The result was that types like float or double would be truncated when printed (e.g., 4.75 -> 4). This change removes the cast so that the types are printed in a more appropriate manner. PiperOrigin-RevId: 511238685 Change-Id: I80de5db14462da2a3e1f476086025ae514383a17 --- googletest/include/gtest/gtest.h | 2 +- googletest/test/googletest-json-outfiles-test.py | 10 +++++----- googletest/test/gtest_xml_outfile2_test_.cc | 4 +--- googletest/test/gtest_xml_outfiles_test.py | 10 +++++----- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 35c08026..6fdf5524 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -302,7 +302,7 @@ class GTEST_API_ Test { template ::value, bool> = true> static void RecordProperty(const std::string& key, const T& value) { - RecordProperty(key, (Message() << static_cast(value)).GetString()); + RecordProperty(key, (Message() << value).GetString()); } protected: diff --git a/googletest/test/googletest-json-outfiles-test.py b/googletest/test/googletest-json-outfiles-test.py index 83a56de1..ff157223 100644 --- a/googletest/test/googletest-json-outfiles-test.py +++ b/googletest/test/googletest-json-outfiles-test.py @@ -88,7 +88,7 @@ EXPECTED_2 = { 'time': '*', 'timestamp': '*', 'testsuite': [{ - 'name': 'TestInt64Properties', + 'name': 'TestInt64ConvertibleProperties', 'file': 'gtest_xml_outfile2_test_.cc', 'line': 41, 'status': 'RUN', @@ -97,11 +97,11 @@ EXPECTED_2 = { 'time': '*', 'classname': 'PropertyTwo', 'SetUpProp': '2', - 'TestFloatProperty': '3', - 'TestDoubleProperty': '4', + 'TestFloatProperty': '3.25', + 'TestDoubleProperty': '4.75', 'TestSizetProperty': '5', - 'TestBoolProperty': '1', - 'TestCharProperty': '65', + 'TestBoolProperty': 'true', + 'TestCharProperty': 'A', 'TestInt16Property': '6', 'TestInt32Property': '7', 'TestInt64Property': '8', diff --git a/googletest/test/gtest_xml_outfile2_test_.cc b/googletest/test/gtest_xml_outfile2_test_.cc index 5ee216df..ed58dc8d 100644 --- a/googletest/test/gtest_xml_outfile2_test_.cc +++ b/googletest/test/gtest_xml_outfile2_test_.cc @@ -38,9 +38,7 @@ class PropertyTwo : public testing::Test { void TearDown() override { RecordProperty("TearDownProp", 2); } }; -TEST_F(PropertyTwo, TestInt64Properties) { - // Floats and doubles are written as int64_t, so we test that the values - // written are truncated to int64_t. +TEST_F(PropertyTwo, TestInt64ConvertibleProperties) { float float_prop = 3.25; RecordProperty("TestFloatProperty", float_prop); diff --git a/googletest/test/gtest_xml_outfiles_test.py b/googletest/test/gtest_xml_outfiles_test.py index 7ee0f3c8..50291b0a 100755 --- a/googletest/test/gtest_xml_outfiles_test.py +++ b/googletest/test/gtest_xml_outfiles_test.py @@ -57,14 +57,14 @@ EXPECTED_XML_1 = """ EXPECTED_XML_2 = """ - + - - + + - - + + From 10493e3854db0c4709f9ddd1ac10b974d30219f5 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 21 Feb 2023 13:29:20 -0700 Subject: [PATCH 11/75] Fix error in_death_test_child_process: undeclared identifier The error occurs if !GTEST_HAS_DEATH_TEST on Windows. --- googletest/src/gtest.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index a60a042c..dd7752cf 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -5416,6 +5416,9 @@ int UnitTest::Run() { impl()->set_catch_exceptions(GTEST_FLAG_GET(catch_exceptions)); #if GTEST_OS_WINDOWS +#if !GTEST_HAS_DEATH_TEST + const bool in_death_test_child_process = false; +#endif // Either the user wants Google Test to catch exceptions thrown by the // tests or this is executing in the context of death test child // process. In either case the user does not want to see pop-up dialogs From d9a4bbcaf22d7cb37e42af3103019060d11bce3d Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Wed, 22 Feb 2023 08:18:00 -0800 Subject: [PATCH 12/75] Update googletest's test docker containers PiperOrigin-RevId: 511500508 Change-Id: Ib686f93d317b95ac9b9bcb0a5566500316ba1929 --- ci/linux-presubmit.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/linux-presubmit.sh b/ci/linux-presubmit.sh index 9e15d9a4..626989d2 100644 --- a/ci/linux-presubmit.sh +++ b/ci/linux-presubmit.sh @@ -31,8 +31,8 @@ set -euox pipefail -readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20220217" -readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20220621" +readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20230217" +readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20230120" if [[ -z ${GTEST_ROOT:-} ]]; then GTEST_ROOT="$(realpath $(dirname ${0})/..)" From 39a26e12d67ed6c21feeb606372bfee39a8e6d53 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Wed, 22 Feb 2023 09:02:08 -0800 Subject: [PATCH 13/75] Avoid redundant declaration of static constexpr members in c++17 Keep declarations in c++ < 17 using new macro, GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL. Fixes #4148. PiperOrigin-RevId: 511510401 Change-Id: I76c3f2fccf07a0978adcbe5f8f0203b9d0c33872 --- googletest/include/gtest/internal/gtest-internal.h | 2 ++ googletest/include/gtest/internal/gtest-port.h | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index e1eb2b51..73395048 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -900,8 +900,10 @@ class HasDebugStringAndShortDebugString { HasDebugStringType::value && HasShortDebugStringType::value; }; +#ifdef GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL template constexpr bool HasDebugStringAndShortDebugString::value; +#endif // When the compiler sees expression IsContainerTest(0), if C is an // STL-style container class, the first overload of IsContainerTest diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index ae7fb350..5cea3e02 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -2447,4 +2447,9 @@ using Variant = ::std::variant; #endif // __has_include #endif // GTEST_HAS_ABSL +#if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \ + GTEST_INTERNAL_CPLUSPLUS_LANG < 201703L +#define GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL 1 +#endif + #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ From d0ba3ccc7659a7af2ee5d2039f8e6978f35b67ce Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 23 Feb 2023 12:39:43 -0800 Subject: [PATCH 14/75] Added a missing semicolon for GTEST_FLAG_SET code snippet. PiperOrigin-RevId: 511858980 Change-Id: I0f9e6ffdeb8ae809d662eb3ff46eab5a109a8d93 --- docs/advanced.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced.md b/docs/advanced.md index 7d15dfdd..6b4c3f0b 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -562,7 +562,7 @@ The automated testing framework does not set the style flag. You can choose a particular style of death tests by setting the flag programmatically: ```c++ -GTEST_FLAG_SET(death_test_style, "threadsafe") +GTEST_FLAG_SET(death_test_style, "threadsafe"); ``` You can do this in `main()` to set the style for all death tests in the binary, From 3d787f5a0d58cfc37a0563bb15647a0d8aa2c1bf Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 24 Feb 2023 09:49:45 -0800 Subject: [PATCH 15/75] Add `const` qualifier to `gtest_sentinel` which doesn't change. PiperOrigin-RevId: 512094429 Change-Id: I29b116da65bc7471c43021d1650d90f7b2a685c2 --- googletest/include/gtest/internal/gtest-death-test-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-death-test-internal.h b/googletest/include/gtest/internal/gtest-death-test-internal.h index 4687dae2..21f3d29f 100644 --- a/googletest/include/gtest/internal/gtest-death-test-internal.h +++ b/googletest/include/gtest/internal/gtest-death-test-internal.h @@ -238,7 +238,7 @@ inline Matcher MakeDeathTestMatcher( } \ break; \ case ::testing::internal::DeathTest::EXECUTE_TEST: { \ - ::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \ + const ::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \ gtest_dt); \ GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \ gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \ From 95d8c7ac4389b38b197bc7521dffb62508653eb5 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 27 Feb 2023 11:21:04 -0800 Subject: [PATCH 16/75] Reformat to current g3doc style guide. No content changes. PiperOrigin-RevId: 512681427 Change-Id: I88b22d82430ed145b8342747adf300f3e734d43b --- docs/primer.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/primer.md b/docs/primer.md index 2ffbf53b..80c2d0a6 100644 --- a/docs/primer.md +++ b/docs/primer.md @@ -45,23 +45,23 @@ minutes to learn the basics and get started. So let's go! ## Beware of the nomenclature {: .callout .note} -_Note:_ There might be some confusion arising from different definitions of the -terms _Test_, _Test Case_ and _Test Suite_, so beware of misunderstanding these. +*Note:* There might be some confusion arising from different definitions of the +terms *Test*, *Test Case* and *Test Suite*, so beware of misunderstanding these. -Historically, googletest started to use the term _Test Case_ for grouping +Historically, googletest started to use the term *Test Case* for grouping related tests, whereas current publications, including International Software Testing Qualifications Board ([ISTQB](http://www.istqb.org/)) materials and various textbooks on software quality, use the term -_[Test Suite][istqb test suite]_ for this. +*[Test Suite][istqb test suite]* for this. -The related term _Test_, as it is used in googletest, corresponds to the term -_[Test Case][istqb test case]_ of ISTQB and others. +The related term *Test*, as it is used in googletest, corresponds to the term +*[Test Case][istqb test case]* of ISTQB and others. -The term _Test_ is commonly of broad enough sense, including ISTQB's definition -of _Test Case_, so it's not much of a problem here. But the term _Test Case_ as +The term *Test* is commonly of broad enough sense, including ISTQB's definition +of *Test Case*, so it's not much of a problem here. But the term *Test Case* as was used in Google Test is of contradictory sense and thus confusing. -googletest recently started replacing the term _Test Case_ with _Test Suite_. +googletest recently started replacing the term *Test Case* with *Test Suite*. The preferred API is *TestSuite*. The older TestCase API is being slowly deprecated and refactored away. @@ -381,7 +381,7 @@ If a fatal failure happens the subsequent steps will be skipped. ## Writing the main() Function -Most users should _not_ need to write their own `main` function and instead link +Most users should *not* need to write their own `main` function and instead link with `gtest_main` (as opposed to with `gtest`), which defines a suitable entry point. See the end of this section for details. The remainder of this section should only apply when you need to do something custom before the tests run that @@ -476,7 +476,7 @@ NOTE: `ParseGUnitFlags()` is deprecated in favor of `InitGoogleTest()`. * Google Test is designed to be thread-safe. The implementation is thread-safe on systems where the `pthreads` library is available. It is currently - _unsafe_ to use Google Test assertions from two threads concurrently on + *unsafe* to use Google Test assertions from two threads concurrently on other systems (e.g. Windows). In most tests this is not an issue as usually the assertions are done in the main thread. If you want to help, you can volunteer to implement the necessary synchronization primitives in From 6882aa0987c6d3266a05bbec609587a6f80510b9 Mon Sep 17 00:00:00 2001 From: Phoebe Liang Date: Mon, 27 Feb 2023 13:02:26 -0800 Subject: [PATCH 17/75] Reorder printers list. PiperOrigin-RevId: 512708763 Change-Id: I1f24f2e1d17359aee5aa4cdf614c9357872ca03b --- googletest/include/gtest/gtest-printers.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 7d7e77c1..739d5452 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -306,9 +306,10 @@ template void PrintWithFallback(const T& value, ::std::ostream* os) { using Printer = typename FindFirstPrinter< T, void, ContainerPrinter, FunctionPointerPrinter, PointerPrinter, + ProtobufPrinter, internal_stream_operator_without_lexical_name_lookup::StreamPrinter, - ProtobufPrinter, ConvertibleToIntegerPrinter, - ConvertibleToStringViewPrinter, RawBytesPrinter, FallbackPrinter>::type; + ConvertibleToIntegerPrinter, ConvertibleToStringViewPrinter, + RawBytesPrinter, FallbackPrinter>::type; Printer::PrintValue(value, os); } From 8aa75fa7712d04185c974d535cd6e678a253e9fa Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 27 Feb 2023 18:46:37 -0800 Subject: [PATCH 18/75] Eliminate argv list action parameter. PiperOrigin-RevId: 512791992 Change-Id: Ie7fc37ea06ea7d9f595268c9ec84a0e144c297bb --- WORKSPACE | 8 ++++---- googletest/src/gtest.cc | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 0f10a6a9..cb5f83fa 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,10 +3,10 @@ workspace(name = "com_google_googletest") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( - name = "com_google_absl", # 2023-01-10T21:08:25Z - sha256 = "f9a4e749f42c386a32a90fddf0e2913ed408d10c42f7f33ccf4c59ac4f0d1d05", - strip_prefix = "abseil-cpp-52835439ca90d86b27bf8cd1708296e95604d724", - urls = ["https://github.com/abseil/abseil-cpp/archive/52835439ca90d86b27bf8cd1708296e95604d724.zip"], + name = "com_google_absl", # 2023-02-27T15:50:25Z + sha256 = "baf8e734ac3ce213a889ce7c248b981ee1730e2093e32808e0f0a910dc985f76", + strip_prefix = "abseil-cpp-0c1114c4fb83c844c7fd74708338cca1d3d9b0dc", + urls = ["https://github.com/abseil/abseil-cpp/archive/0c1114c4fb83c844c7fd74708338cca1d3d9b0dc.zip"], ) # Note this must use a commit from the `abseil` branch of the RE2 project. diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 8195e5f1..fb578d58 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -6667,8 +6667,7 @@ void ParseGoogleTestFlagsOnly(int* argc, char** argv) { if (*argc > 0) { // absl::ParseCommandLine() requires *argc > 0. auto positional_args = absl::flags_internal::ParseCommandLineImpl( - *argc, argv, absl::flags_internal::ArgvListAction::kRemoveParsedArgs, - absl::flags_internal::UsageFlagsAction::kHandleUsage, + *argc, argv, absl::flags_internal::UsageFlagsAction::kHandleUsage, absl::flags_internal::OnUndefinedFlag::kReportUndefined); // Any command-line positional arguments not part of any command-line flag // (or arguments to a flag) are copied back out to argv, with the program From 555486f408ab4906118eddf11c856da7f8690f14 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 28 Feb 2023 08:16:34 -0800 Subject: [PATCH 19/75] Rephrase the description of TEST_F() arguments for clarity. PiperOrigin-RevId: 512937964 Change-Id: Ifa6369a80dc7d8efe60511417496d58317cfc28d --- docs/primer.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/primer.md b/docs/primer.md index 80c2d0a6..d559fe84 100644 --- a/docs/primer.md +++ b/docs/primer.md @@ -227,14 +227,14 @@ When using a fixture, use `TEST_F()` instead of `TEST()` as it allows you to access objects and subroutines in the test fixture: ```c++ -TEST_F(TestFixtureName, TestName) { +TEST_F(TestFixtureClassName, TestName) { ... test body ... } ``` -Like `TEST()`, the first argument is the test suite name, but for `TEST_F()` -this must be the name of the test fixture class. You've probably guessed: `_F` -is for fixture. +Unlike `TEST()`, in `TEST_F()` the first argument must be the name of the test +fixture class. (`_F` stands for "Fixture"). No test suite name is specified for +this macro. Unfortunately, the C++ macro system does not allow us to create a single macro that can handle both types of tests. Using the wrong macro causes a compiler From cead3d57c93ff8c4e5c1bbae57a5c0b0b0f6e168 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 3 Mar 2023 02:24:39 -0800 Subject: [PATCH 20/75] Internal Code Change PiperOrigin-RevId: 513770561 Change-Id: I82fbed177c6ba4e2e5b776ae3e0255c868e32e25 --- googlemock/src/gmock-internal-utils.cc | 2 +- googlemock/src/gmock-matchers.cc | 2 +- googlemock/src/gmock-spec-builders.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc index 31d55650..774cce33 100644 --- a/googlemock/src/gmock-internal-utils.cc +++ b/googlemock/src/gmock-internal-utils.cc @@ -87,7 +87,7 @@ GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name) { (!IsDigit(prev_char) && IsDigit(*p)); if (IsAlNum(*p)) { - if (starts_new_word && result != "") result += ' '; + if (starts_new_word && !result.empty()) result += ' '; result += ToLower(*p); } } diff --git a/googlemock/src/gmock-matchers.cc b/googlemock/src/gmock-matchers.cc index 5810b6aa..07bba4f0 100644 --- a/googlemock/src/gmock-matchers.cc +++ b/googlemock/src/gmock-matchers.cc @@ -53,7 +53,7 @@ GTEST_API_ std::string FormatMatcherDescription( bool negation, const char* matcher_name, const std::vector& param_names, const Strings& param_values) { std::string result = ConvertIdentifierNameToWords(matcher_name); - if (param_values.size() >= 1) { + if (!param_values.empty()) { result += " " + JoinAsKeyValueTuple(param_names, param_values); } return negation ? "not (" + result + ")" : result; diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index afd802c3..a7fe9117 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -503,7 +503,7 @@ class MockObjectRegistry { std::cout << internal::FormatFileLocation(state.first_used_file, state.first_used_line); std::cout << " ERROR: this mock object"; - if (state.first_used_test != "") { + if (!state.first_used_test.empty()) { std::cout << " (used in test " << state.first_used_test_suite << "." << state.first_used_test << ")"; } From 23142843f7c875907a6ed7985174a6e346e82c3d Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 3 Mar 2023 15:54:32 -0800 Subject: [PATCH 21/75] Use "#ifdef GTEST_OS_..." instead of "#if GTEST_OS_..." This is compatible with compiling with "-Wundef" (#3267). PiperOrigin-RevId: 513943378 Change-Id: I47cf5fabbb77be061c4483a0adc54511af6b191c --- googlemock/include/gmock/gmock-actions.h | 4 +- googlemock/include/gmock/gmock-nice-strict.h | 2 +- googlemock/src/gmock-spec-builders.cc | 6 +- googlemock/src/gmock_main.cc | 8 +- googlemock/test/gmock-actions_test.cc | 2 +- googlemock/test/gmock-function-mocker_test.cc | 12 +- googlemock/test/gmock-internal-utils_test.cc | 4 +- googlemock/test/gmock_link_test.h | 6 +- googletest/include/gtest/gtest-death-test.h | 2 +- googletest/include/gtest/gtest.h | 2 +- .../include/gtest/internal/gtest-internal.h | 4 +- .../include/gtest/internal/gtest-port.h | 157 +++++++++++------- .../include/gtest/internal/gtest-string.h | 2 +- googletest/src/gtest-death-test.cc | 46 ++--- googletest/src/gtest-filepath.cc | 38 +++-- googletest/src/gtest-internal-inl.h | 4 +- googletest/src/gtest-port.cc | 54 +++--- googletest/src/gtest.cc | 67 ++++---- googletest/src/gtest_main.cc | 8 +- .../googletest-break-on-failure-unittest_.cc | 8 +- googletest/test/googletest-death-test-test.cc | 24 +-- googletest/test/googletest-filepath-test.cc | 24 +-- googletest/test/googletest-options-test.cc | 24 +-- googletest/test/googletest-output-test_.cc | 2 +- googletest/test/googletest-port-test.cc | 26 +-- googletest/test/googletest-printers-test.cc | 2 +- googletest/test/gtest_unittest.cc | 30 ++-- 27 files changed, 305 insertions(+), 263 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 1cffde2b..c0bb8a9c 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -1273,7 +1273,7 @@ class AssignAction { const T2 value_; }; -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE // Implements the SetErrnoAndReturn action to simulate return from // various system calls and libc functions. @@ -1926,7 +1926,7 @@ PolymorphicAction> Assign(T1* ptr, T2 val) { return MakePolymorphicAction(internal::AssignAction(ptr, val)); } -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE // Creates an action that sets errno and returns the appropriate error. template diff --git a/googlemock/include/gmock/gmock-nice-strict.h b/googlemock/include/gmock/gmock-nice-strict.h index 4f0eb35d..056d4714 100644 --- a/googlemock/include/gmock/gmock-nice-strict.h +++ b/googlemock/include/gmock/gmock-nice-strict.h @@ -98,7 +98,7 @@ constexpr bool HasStrictnessModifier() { // deregistration. This guarantees that MockClass's constructor and destructor // run with the same level of strictness as its instance methods. -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW && \ +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW) && \ (defined(_MSC_VER) || defined(__clang__)) // We need to mark these classes with this declspec to ensure that // the empty base class optimization is performed. diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index a7fe9117..5a98fafd 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -48,10 +48,10 @@ #include "gtest/gtest.h" #include "gtest/internal/gtest-port.h" -#if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC +#if defined(GTEST_OS_CYGWIN) || defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC) #include // NOLINT #endif -#if GTEST_OS_QURT +#ifdef GTEST_OS_QURT #include #endif @@ -526,7 +526,7 @@ class MockObjectRegistry { // RUN_ALL_TESTS() has already returned when this destructor is // called. Therefore we cannot use the normal Google Test // failure reporting mechanism. -#if GTEST_OS_QURT +#ifdef GTEST_OS_QURT qurt_exception_raise_fatal(); #else _exit(1); // We cannot call exit() as it is not reentrant and diff --git a/googlemock/src/gmock_main.cc b/googlemock/src/gmock_main.cc index b411c5ec..fb37b53a 100644 --- a/googlemock/src/gmock_main.cc +++ b/googlemock/src/gmock_main.cc @@ -32,8 +32,8 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -#if GTEST_OS_ESP8266 || GTEST_OS_ESP32 -#if GTEST_OS_ESP8266 +#if defined(GTEST_OS_ESP8266) || defined(GTEST_OS_ESP32) +#ifdef GTEST_OS_ESP8266 extern "C" { #endif void setup() { @@ -43,7 +43,7 @@ void setup() { testing::InitGoogleMock(); } void loop() { RUN_ALL_TESTS(); } -#if GTEST_OS_ESP8266 +#ifdef GTEST_OS_ESP8266 } #endif @@ -55,7 +55,7 @@ void loop() { RUN_ALL_TESTS(); } // Windows. See the following link to track the current status of this bug: // https://web.archive.org/web/20170912203238/connect.microsoft.com/VisualStudio/feedback/details/394464/wmain-link-error-in-the-static-library // // NOLINT -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE #include // NOLINT GTEST_API_ int _tmain(int argc, TCHAR** argv) { diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index f2d3042f..7734830e 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1592,7 +1592,7 @@ TEST(WithArgsTest, RefQualifiedInnerAction) { EXPECT_EQ(19, mock.AsStdFunction()(0, 17)); } -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE class SetErrnoAndReturnTest : public testing::Test { protected: diff --git a/googlemock/test/gmock-function-mocker_test.cc b/googlemock/test/gmock-function-mocker_test.cc index e211aff9..4db498d8 100644 --- a/googlemock/test/gmock-function-mocker_test.cc +++ b/googlemock/test/gmock-function-mocker_test.cc @@ -35,7 +35,7 @@ // Silence C4503 (decorated name length exceeded) for MSVC. GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503) -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // MSDN says the header file to be included for STDMETHOD is BaseTyps.h but // we are getting compiler errors if we use basetyps.h, hence including // objbase.h for definition of STDMETHOD. @@ -120,7 +120,7 @@ class FooInterface { virtual int RefQualifiedOverloaded() & = 0; virtual int RefQualifiedOverloaded() && = 0; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS STDMETHOD_(int, CTNullary)() = 0; STDMETHOD_(bool, CTUnary)(int x) = 0; STDMETHOD_(int, CTDecimal) @@ -178,7 +178,7 @@ class MockFoo : public FooInterface { MOCK_METHOD(int (*)(bool), ReturnsFunctionPointer1, (int), ()); MOCK_METHOD(fn_ptr, ReturnsFunctionPointer2, (int), ()); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS MOCK_METHOD(int, CTNullary, (), (Calltype(STDMETHODCALLTYPE))); MOCK_METHOD(bool, CTUnary, (int), (Calltype(STDMETHODCALLTYPE))); MOCK_METHOD(int, CTDecimal, @@ -248,7 +248,7 @@ class LegacyMockFoo : public FooInterface { MOCK_METHOD1(ReturnsFunctionPointer1, int (*(int))(bool)); MOCK_METHOD1(ReturnsFunctionPointer2, fn_ptr(int)); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTNullary, int()); MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTUnary, bool(int)); // NOLINT MOCK_METHOD10_WITH_CALLTYPE(STDMETHODCALLTYPE, CTDecimal, @@ -404,7 +404,7 @@ TYPED_TEST(FunctionMockerTest, MocksTypeWithTemplatedCopyCtor) { EXPECT_TRUE(this->foo_->TypeWithTemplatedCopyCtor(TemplatedCopyable())); } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Tests mocking a nullary function with calltype. TYPED_TEST(FunctionMockerTest, MocksNullaryFunctionWithCallType) { EXPECT_CALL(this->mock_foo_, CTNullary()) @@ -620,7 +620,7 @@ TYPED_TEST(TemplateMockTest, MethodWithCommaInReturnTypeWorks) { EXPECT_EQ(a_map, mock.ReturnTypeWithComma(1)); } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Tests mocking template interfaces with calltype. template diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index 932bece5..360d02ae 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -56,7 +56,7 @@ #include "src/gtest-internal-inl.h" #undef GTEST_IMPLEMENTATION_ -#if GTEST_OS_CYGWIN +#ifdef GTEST_OS_CYGWIN #include // For ssize_t. NOLINT #endif @@ -167,7 +167,7 @@ TEST(KindOfTest, Integer) { EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long long)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(wchar_t)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t)); // NOLINT -#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN +#if defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC) || defined(GTEST_OS_CYGWIN) // ssize_t is not defined on Windows and possibly some other OSes. EXPECT_EQ(kInteger, GMOCK_KIND_OF_(ssize_t)); // NOLINT #endif diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h index 95a8cb80..8d2abb1a 100644 --- a/googlemock/test/gmock_link_test.h +++ b/googlemock/test/gmock_link_test.h @@ -116,7 +116,7 @@ #include "gmock/gmock.h" -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE #include #endif @@ -181,7 +181,7 @@ using testing::WithArg; using testing::WithArgs; using testing::WithoutArgs; -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE using testing::SetErrnoAndReturn; #endif @@ -306,7 +306,7 @@ TEST(LinkTest, TestSetArrayArgument) { mock.VoidFromString(&ch); } -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE // Tests the linkage of the SetErrnoAndReturn action. TEST(LinkTest, TestSetErrnoAndReturn) { diff --git a/googletest/include/gtest/gtest-death-test.h b/googletest/include/gtest/gtest-death-test.h index 84e5a5bb..b793528b 100644 --- a/googletest/include/gtest/gtest-death-test.h +++ b/googletest/include/gtest/gtest-death-test.h @@ -203,7 +203,7 @@ class GTEST_API_ ExitedWithCode { const int exit_code_; }; -#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA +#if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA) // Tests that an exit code describes an exit due to termination by a // given signal. class GTEST_API_ KilledBySignal { diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 6fdf5524..2bf64938 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -1999,7 +1999,7 @@ GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2, GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2, double val1, double val2); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Macros that test for HRESULT failure and success, these are only useful // on Windows, and rely on Windows SDK macros and APIs to compile. diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 73395048..ae2ca95e 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -41,7 +41,7 @@ #include "gtest/internal/gtest-port.h" -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX #include #include #include @@ -457,7 +457,7 @@ class TestFactoryImpl : public TestFactoryBase { Test* CreateTest() override { return new TestClass; } }; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Predicate-formatters for implementing the HRESULT checking macros // {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED} diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 5cea3e02..f2b0bbf9 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -361,13 +361,13 @@ // Brings in definitions for functions used in the testing::internal::posix // namespace (read, write, close, chdir, isatty, stat). We do not currently // use them on Windows Mobile. -#if GTEST_OS_WINDOWS -#if !GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS +#ifndef GTEST_OS_WINDOWS_MOBILE #include #include #endif // In order to avoid having to include , use forward declaration -#if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR) +#if defined(GTEST_OS_WINDOWS_MINGW) && !defined(__MINGW64_VERSION_MAJOR) // MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two // separate (equivalent) structs, instead of using typedef typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION; @@ -377,7 +377,7 @@ typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION; // WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION. typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #endif -#elif GTEST_OS_XTENSA +#elif defined(GTEST_OS_XTENSA) #include // Xtensa toolchains define strcasecmp in the string.h header instead of // strings.h. string.h is already included. @@ -389,7 +389,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #include #endif // GTEST_OS_WINDOWS -#if GTEST_OS_LINUX_ANDROID +#ifdef GTEST_OS_LINUX_ANDROID // Used to define __ANDROID_API__ matching the target NDK API level. #include // NOLINT #endif @@ -397,13 +397,17 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // Defines this to true if and only if Google Test can use POSIX regular // expressions. #ifndef GTEST_HAS_POSIX_RE -#if GTEST_OS_LINUX_ANDROID +#ifdef GTEST_OS_LINUX_ANDROID // On Android, is only available starting with Gingerbread. #define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9) #else -#define GTEST_HAS_POSIX_RE \ - !(GTEST_OS_WINDOWS || GTEST_OS_XTENSA || GTEST_OS_QURT) +#if !(defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_XTENSA) || \ + defined(GTEST_OS_QURT)) +#define GTEST_HAS_POSIX_RE 1 +#else +#define GTEST_HAS_POSIX_RE 0 #endif +#endif // GTEST_OS_LINUX_ANDROID #endif // Select the regular expression implementation. @@ -472,11 +476,14 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // Cygwin 1.7 and below doesn't support ::std::wstring. // Solaris' libc++ doesn't support it either. Android has // no support for it at least as recent as Froyo (2.2). -#define GTEST_HAS_STD_WSTRING \ - (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ - GTEST_OS_HAIKU || GTEST_OS_ESP32 || GTEST_OS_ESP8266 || \ - GTEST_OS_XTENSA || GTEST_OS_QURT)) - +#if (!(defined(GTEST_OS_LINUX_ANDROID) || defined(GTEST_OS_CYGWIN) || \ + defined(GTEST_OS_SOLARIS) || defined(GTEST_OS_HAIKU) || \ + defined(GTEST_OS_ESP32) || defined(GTEST_OS_ESP8266) || \ + defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT))) +#define GTEST_HAS_STD_WSTRING 1 +#else +#define GTEST_HAS_STD_WSTRING 0 +#endif #endif // GTEST_HAS_STD_WSTRING #ifndef GTEST_HAS_FILE_SYSTEM @@ -506,7 +513,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // -frtti -fno-exceptions, the build fails at link time with undefined // references to __cxa_bad_typeid. Note sure if STL or toolchain bug, // so disable RTTI when detected. -#if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && !defined(__EXCEPTIONS) +#if defined(GTEST_OS_LINUX_ANDROID) && defined(_STLPORT_MAJOR) && \ + !defined(__EXCEPTIONS) #define GTEST_HAS_RTTI 0 #else #define GTEST_HAS_RTTI 1 @@ -554,11 +562,17 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // // To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0 // to your compiler flags. -#define GTEST_HAS_PTHREAD \ - (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX || GTEST_OS_QNX || \ - GTEST_OS_FREEBSD || GTEST_OS_NACL || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \ - GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_OPENBSD || \ - GTEST_OS_HAIKU || GTEST_OS_GNU_HURD) +#if (defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC) || \ + defined(GTEST_OS_HPUX) || defined(GTEST_OS_QNX) || \ + defined(GTEST_OS_FREEBSD) || defined(GTEST_OS_NACL) || \ + defined(GTEST_OS_NETBSD) || defined(GTEST_OS_FUCHSIA) || \ + defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \ + defined(GTEST_OS_OPENBSD) || defined(GTEST_OS_HAIKU) || \ + defined(GTEST_OS_GNU_HURD)) +#define GTEST_HAS_PTHREAD 1 +#else +#define GTEST_HAS_PTHREAD 0 +#endif #endif // GTEST_HAS_PTHREAD #if GTEST_HAS_PTHREAD @@ -577,8 +591,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #ifndef GTEST_HAS_CLONE // The user didn't tell us, so we need to figure it out. -#if GTEST_OS_LINUX && !defined(__ia64__) -#if GTEST_OS_LINUX_ANDROID +#if defined(GTEST_OS_LINUX) && !defined(__ia64__) +#if defined(GTEST_OS_LINUX_ANDROID) // On Android, clone() became available at different API levels for each 32-bit // architecture. #if defined(__LP64__) || (defined(__arm__) && __ANDROID_API__ >= 9) || \ @@ -603,9 +617,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // By default, we assume that stream redirection is supported on all // platforms except known mobile / embedded ones. Also, if the port doesn't have // a file system, stream redirection is not supported. -#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ - GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA || \ - GTEST_OS_QURT || !GTEST_HAS_FILE_SYSTEM +#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \ + defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \ + defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT) || \ + !GTEST_HAS_FILE_SYSTEM #define GTEST_HAS_STREAM_REDIRECTION 0 #else #define GTEST_HAS_STREAM_REDIRECTION 1 @@ -614,13 +629,16 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // Determines whether to support death tests. // pops up a dialog window that cannot be suppressed programmatically. -#if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ - (GTEST_OS_MAC && !GTEST_OS_IOS) || \ - (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER) || GTEST_OS_WINDOWS_MINGW || \ - GTEST_OS_AIX || GTEST_OS_HPUX || GTEST_OS_OPENBSD || GTEST_OS_QNX || \ - GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \ - GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_HAIKU || \ - GTEST_OS_GNU_HURD) +#if (defined(GTEST_OS_LINUX) || defined(GTEST_OS_CYGWIN) || \ + defined(GTEST_OS_SOLARIS) || \ + (defined(GTEST_OS_MAC) && !defined(GTEST_OS_IOS)) || \ + (defined(GTEST_OS_WINDOWS_DESKTOP) && _MSC_VER) || \ + defined(GTEST_OS_WINDOWS_MINGW) || defined(GTEST_OS_AIX) || \ + defined(GTEST_OS_HPUX) || defined(GTEST_OS_OPENBSD) || \ + defined(GTEST_OS_QNX) || defined(GTEST_OS_FREEBSD) || \ + defined(GTEST_OS_NETBSD) || defined(GTEST_OS_FUCHSIA) || \ + defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \ + defined(GTEST_OS_HAIKU) || defined(GTEST_OS_GNU_HURD)) // Death tests require a file system to work properly. #if GTEST_HAS_FILE_SYSTEM #define GTEST_HAS_DEATH_TEST 1 @@ -638,14 +656,21 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #endif // Determines whether the system compiler uses UTF-16 for encoding wide strings. -#define GTEST_WIDE_STRING_USES_UTF16_ \ - (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_AIX || GTEST_OS_OS2) +#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_CYGWIN) || \ + defined(GTEST_OS_AIX) || defined(GTEST_OS_OS2) +#define GTEST_WIDE_STRING_USES_UTF16_ 1 +#else +#define GTEST_WIDE_STRING_USES_UTF16_ 0 +#endif // Determines whether test results can be streamed to a socket. -#if GTEST_OS_LINUX || GTEST_OS_GNU_KFREEBSD || GTEST_OS_DRAGONFLY || \ - GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_OPENBSD || \ - GTEST_OS_GNU_HURD +#if defined(GTEST_OS_LINUX) || defined(GTEST_OS_GNU_KFREEBSD) || \ + defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \ + defined(GTEST_OS_NETBSD) || defined(GTEST_OS_OPENBSD) || \ + defined(GTEST_OS_GNU_HURD) #define GTEST_CAN_STREAM_RESULTS_ 1 +#else +#define GTEST_CAN_STREAM_RESULTS_ 0 #endif // Defines some utility macros. @@ -759,10 +784,14 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #ifndef GTEST_IS_THREADSAFE -#define GTEST_IS_THREADSAFE \ - (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \ - (GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) || \ - GTEST_HAS_PTHREAD) +#if (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \ + (defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_PHONE) && \ + !defined(GTEST_OS_WINDOWS_RT)) || \ + GTEST_HAS_PTHREAD) +#define GTEST_IS_THREADSAFE 1 +#else +#define GTEST_IS_THREADSAFE 0 +#endif #endif // GTEST_IS_THREADSAFE @@ -1185,7 +1214,7 @@ void ClearInjectableArgvs(); // Defines synchronization primitives. #if GTEST_IS_THREADSAFE -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Provides leak-safe Windows kernel handle ownership. // Used in death tests and in threading support. class GTEST_API_ AutoHandle { @@ -1264,7 +1293,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 // On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD // defined, but we don't want to use MinGW's pthreads implementation, which // has conformance problems with some versions of the POSIX standard. -#if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW +#if GTEST_HAS_PTHREAD && !defined(GTEST_OS_WINDOWS_MINGW) // As a C-function, ThreadFuncWithCLinkage cannot be templated itself. // Consequently, it cannot select a correct instantiation of ThreadWithParam @@ -1350,7 +1379,8 @@ class ThreadWithParam : public ThreadWithParamBase { // Mutex and ThreadLocal have already been imported into the namespace. // Nothing to do here. -#elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT +#elif defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_PHONE) && \ + !defined(GTEST_OS_WINDOWS_RT) // Mutex implements mutex on Windows platforms. It is used in conjunction // with class MutexLock: @@ -1903,7 +1933,7 @@ class GTEST_API_ ThreadLocal { // we cannot detect it. GTEST_API_ size_t GetThreadCount(); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS #define GTEST_PATH_SEP_ "\\" #define GTEST_HAS_ALT_PATH_SEP_ 1 #else @@ -1980,11 +2010,11 @@ namespace posix { // File system porting. #if GTEST_HAS_FILE_SYSTEM -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS typedef struct _stat StatStruct; -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE inline int FileNo(FILE* file) { return reinterpret_cast(_fileno(file)); } // Stat(), RmDir(), and IsDir() are not needed on Windows CE at this // time and thus not defined there. @@ -1995,7 +2025,7 @@ inline int RmDir(const char* dir) { return _rmdir(dir); } inline bool IsDir(const StatStruct& st) { return (_S_IFDIR & st.st_mode) != 0; } #endif // GTEST_OS_WINDOWS_MOBILE -#elif GTEST_OS_ESP8266 +#elif defined(GTEST_OS_ESP8266) typedef struct stat StatStruct; inline int FileNo(FILE* file) { return fileno(file); } @@ -2012,7 +2042,7 @@ typedef struct stat StatStruct; inline int FileNo(FILE* file) { return fileno(file); } inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); } -#if GTEST_OS_QURT +#ifdef GTEST_OS_QURT // QuRT doesn't support any directory functions, including rmdir inline int RmDir(const char*) { return 0; } #else @@ -2025,7 +2055,7 @@ inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } // Other functions with a different name on Windows. -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS #ifdef __BORLANDC__ inline int DoIsATTY(int fd) { return isatty(fd); } @@ -2033,8 +2063,9 @@ inline int StrCaseCmp(const char* s1, const char* s2) { return stricmp(s1, s2); } #else // !__BORLANDC__ -#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS || GTEST_OS_IOS || \ - GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || defined(ESP_PLATFORM) +#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_ZOS) || \ + defined(GTEST_OS_IOS) || defined(GTEST_OS_WINDOWS_PHONE) || \ + defined(GTEST_OS_WINDOWS_RT) || defined(ESP_PLATFORM) inline int DoIsATTY(int /* fd */) { return 0; } #else inline int DoIsATTY(int fd) { return _isatty(fd); } @@ -2072,13 +2103,13 @@ GTEST_DISABLE_MSC_DEPRECATED_PUSH_() // StrError() aren't needed on Windows CE at this time and thus not // defined there. #if GTEST_HAS_FILE_SYSTEM -#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \ - !GTEST_OS_WINDOWS_RT && !GTEST_OS_ESP8266 && !GTEST_OS_XTENSA && \ - !GTEST_OS_QURT +#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_WINDOWS_PHONE) && \ + !defined(GTEST_OS_WINDOWS_RT) && !defined(GTEST_OS_ESP8266) && \ + !defined(GTEST_OS_XTENSA) && !defined(GTEST_OS_QURT) inline int ChDir(const char* dir) { return chdir(dir); } #endif inline FILE* FOpen(const char* path, const char* mode) { -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW) struct wchar_codecvt : public std::codecvt {}; std::wstring_convert converter; std::wstring wide_path = converter.from_bytes(path); @@ -2088,14 +2119,14 @@ inline FILE* FOpen(const char* path, const char* mode) { return fopen(path, mode); #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW } -#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT +#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT) inline FILE* FReopen(const char* path, const char* mode, FILE* stream) { return freopen(path, mode, stream); } inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); } #endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT inline int FClose(FILE* fp) { return fclose(fp); } -#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT +#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT) inline int Read(int fd, void* buf, unsigned int count) { return static_cast(read(fd, buf, count)); } @@ -2106,14 +2137,14 @@ inline int Close(int fd) { return close(fd); } #endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT #endif // GTEST_HAS_FILE_SYSTEM -#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT +#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT) inline const char* StrError(int errnum) { return strerror(errnum); } #endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT inline const char* GetEnv(const char* name) { -#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ - GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA || \ - GTEST_OS_QURT +#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \ + defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \ + defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT) // We are on an embedded platform, which has no environment variables. static_cast(name); // To prevent 'unused argument' warning. return nullptr; @@ -2129,7 +2160,7 @@ inline const char* GetEnv(const char* name) { GTEST_DISABLE_MSC_DEPRECATED_POP_() -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE // Windows CE has no C library. The abort() function is used in // several places in Google Test. This implementation provides a reasonable // imitation of standard behaviour. @@ -2145,7 +2176,7 @@ GTEST_DISABLE_MSC_DEPRECATED_POP_() // MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate // function in order to achieve that. We use macro definition here because // snprintf is a variadic function. -#if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE +#if defined(_MSC_VER) && !defined(GTEST_OS_WINDOWS_MOBILE) // MSVC 2005 and above support variadic macros. #define GTEST_SNPRINTF_(buffer, size, format, ...) \ _snprintf_s(buffer, size, size, format, __VA_ARGS__) diff --git a/googletest/include/gtest/internal/gtest-string.h b/googletest/include/gtest/internal/gtest-string.h index cc0dd752..7c05b583 100644 --- a/googletest/include/gtest/internal/gtest-string.h +++ b/googletest/include/gtest/internal/gtest-string.h @@ -73,7 +73,7 @@ class GTEST_API_ String { // memory using malloc(). static const char* CloneCString(const char* c_str); -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be // able to pass strings to Win32 APIs on CE we need to convert them // to 'Unicode', UTF-16. diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index 7fcf9bf5..f91eba22 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -42,7 +42,7 @@ #if GTEST_HAS_DEATH_TEST -#if GTEST_OS_MAC +#ifdef GTEST_OS_MAC #include #endif // GTEST_OS_MAC @@ -50,24 +50,24 @@ #include #include -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX #include #endif // GTEST_OS_LINUX #include -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS #include #else #include #include #endif // GTEST_OS_WINDOWS -#if GTEST_OS_QNX +#ifdef GTEST_OS_QNX #include #endif // GTEST_OS_QNX -#if GTEST_OS_FUCHSIA +#ifdef GTEST_OS_FUCHSIA #include #include #include @@ -139,7 +139,7 @@ namespace internal { // Valid only for fast death tests. Indicates the code is running in the // child process of a fast style death test. -#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA +#if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA) static bool g_in_fast_death_test_child = false; #endif @@ -149,7 +149,7 @@ static bool g_in_fast_death_test_child = false; // tests. IMPORTANT: This is an internal utility. Using it may break the // implementation of death tests. User code MUST NOT use it. bool InDeathTestChild() { -#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA +#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA) // On Windows and Fuchsia, death tests are thread-safe regardless of the value // of the death_test_style flag. @@ -171,7 +171,7 @@ ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) {} // ExitedWithCode function-call operator. bool ExitedWithCode::operator()(int exit_status) const { -#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA +#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA) return exit_status == exit_code_; @@ -182,7 +182,7 @@ bool ExitedWithCode::operator()(int exit_status) const { #endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA } -#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA +#if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA) // KilledBySignal constructor. KilledBySignal::KilledBySignal(int signum) : signum_(signum) {} @@ -209,7 +209,7 @@ namespace internal { static std::string ExitSummary(int exit_code) { Message m; -#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA +#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA) m << "Exited with exit status " << exit_code; @@ -236,7 +236,7 @@ bool ExitedUnsuccessfully(int exit_status) { return !ExitedWithCode(0)(exit_status); } -#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA +#if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA) // Generates a textual failure message when a death test finds more than // one thread running, or cannot determine the number of threads, prior // to executing the given statement. It is the responsibility of the @@ -265,7 +265,7 @@ static const char kDeathTestReturned = 'R'; static const char kDeathTestThrew = 'T'; static const char kDeathTestInternalError = 'I'; -#if GTEST_OS_FUCHSIA +#ifdef GTEST_OS_FUCHSIA // File descriptor used for the pipe in the child process. static const int kFuchsiaReadPipeFd = 3; @@ -634,7 +634,7 @@ std::unique_ptr CreateArgvFromArgs(std::vector& args) { return result; } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // WindowsDeathTest implements death tests on Windows. Due to the // specifics of starting new processes on Windows, death tests there are // always threadsafe, and Google Test considers the @@ -821,7 +821,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() { return OVERSEE_TEST; } -#elif GTEST_OS_FUCHSIA +#elif defined(GTEST_OS_FUCHSIA) class FuchsiaDeathTest : public DeathTestImpl { public: @@ -1164,7 +1164,7 @@ struct ExecDeathTestArgs { int close_fd; // File descriptor to close; the read end of a pipe }; -#if GTEST_OS_QNX +#ifdef GTEST_OS_QNX extern "C" char** environ; #else // GTEST_OS_QNX // The main function for a threadsafe-style death test child process. @@ -1245,7 +1245,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { ExecDeathTestArgs args = {argv, close_fd}; pid_t child_pid = -1; -#if GTEST_OS_QNX +#ifdef GTEST_OS_QNX // Obtains the current directory and sets it to be closed in the child // process. const int cwd_fd = open(".", O_RDONLY); @@ -1276,7 +1276,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd)); #else // GTEST_OS_QNX -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX // When a SIGPROF signal is received while fork() or clone() are executing, // the process may hang. To avoid this, we ignore SIGPROF here and re-enable // it after the call to fork()/clone() is complete. @@ -1327,7 +1327,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { _exit(0); } #endif // GTEST_OS_QNX -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX GTEST_DEATH_TEST_CHECK_SYSCALL_( sigaction(SIGPROF, &saved_sigprof_action, nullptr)); #endif // GTEST_OS_LINUX @@ -1419,14 +1419,14 @@ bool DefaultDeathTestFactory::Create(const char* statement, } } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS if (GTEST_FLAG_GET(death_test_style) == "threadsafe" || GTEST_FLAG_GET(death_test_style) == "fast") { *test = new WindowsDeathTest(statement, std::move(matcher), file, line); } -#elif GTEST_OS_FUCHSIA +#elif defined(GTEST_OS_FUCHSIA) if (GTEST_FLAG_GET(death_test_style) == "threadsafe" || GTEST_FLAG_GET(death_test_style) == "fast") { @@ -1453,7 +1453,7 @@ bool DefaultDeathTestFactory::Create(const char* statement, return true; } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Recreates the pipe and event handles from the provided parameters, // signals the event, and returns a file descriptor wrapped around the pipe // handle. This function is called in the child process only. @@ -1530,7 +1530,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() { SplitString(GTEST_FLAG_GET(internal_run_death_test), '|', &fields); int write_fd = -1; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS unsigned int parent_process_id = 0; size_t write_handle_as_size_t = 0; @@ -1547,7 +1547,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() { write_fd = GetStatusFileDescriptor(parent_process_id, write_handle_as_size_t, event_handle_as_size_t); -#elif GTEST_OS_FUCHSIA +#elif defined(GTEST_OS_FUCHSIA) if (fields.size() != 3 || !ParseNaturalNumber(fields[1], &line) || !ParseNaturalNumber(fields[2], &index)) { diff --git a/googletest/src/gtest-filepath.cc b/googletest/src/gtest-filepath.cc index 940585db..48dee13e 100644 --- a/googletest/src/gtest-filepath.cc +++ b/googletest/src/gtest-filepath.cc @@ -34,9 +34,9 @@ #include "gtest/gtest-message.h" #include "gtest/internal/gtest-port.h" -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE #include -#elif GTEST_OS_WINDOWS +#elif defined(GTEST_OS_WINDOWS) #include #include #else @@ -47,7 +47,7 @@ #include "gtest/internal/gtest-string.h" -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS #define GTEST_PATH_MAX_ _MAX_PATH #elif defined(PATH_MAX) #define GTEST_PATH_MAX_ PATH_MAX @@ -62,7 +62,7 @@ namespace testing { namespace internal { -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // On Windows, '\\' is the standard path separator, but many tools and the // Windows API also accept '/' as an alternate path separator. Unless otherwise // noted, a file path can contain either kind of path separators, or a mixture @@ -70,7 +70,7 @@ namespace internal { const char kPathSeparator = '\\'; const char kAlternatePathSeparator = '/'; const char kAlternatePathSeparatorString[] = "/"; -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE // Windows CE doesn't have a current directory. You should not use // the current directory in tests on Windows CE, but this at least // provides a reasonable fallback. @@ -96,19 +96,20 @@ static bool IsPathSeparator(char c) { // Returns the current working directory, or "" if unsuccessful. FilePath FilePath::GetCurrentDir() { -#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ - GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_ESP32 || \ - GTEST_OS_XTENSA || GTEST_OS_QURT +#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \ + defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \ + defined(GTEST_OS_ESP32) || defined(GTEST_OS_XTENSA) || \ + defined(GTEST_OS_QURT) // These platforms do not have a current directory, so we just return // something reasonable. return FilePath(kCurrentDirectoryString); -#elif GTEST_OS_WINDOWS +#elif defined(GTEST_OS_WINDOWS) char cwd[GTEST_PATH_MAX_ + 1] = {'\0'}; return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? "" : cwd); #else char cwd[GTEST_PATH_MAX_ + 1] = {'\0'}; char* result = getcwd(cwd, sizeof(cwd)); -#if GTEST_OS_NACL +#ifdef GTEST_OS_NACL // getcwd will likely fail in NaCl due to the sandbox, so return something // reasonable. The user may have provided a shim implementation for getcwd, // however, so fallback only when failure is detected. @@ -151,7 +152,7 @@ size_t FilePath::CalculateRootLength() const { const auto& path = pathname_; auto s = path.begin(); auto end = path.end(); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS if (end - s >= 2 && s[1] == ':' && (end - s == 2 || IsPathSeparator(s[2])) && (('A' <= s[0] && s[0] <= 'Z') || ('a' <= s[0] && s[0] <= 'z'))) { // A typical absolute path like "C:\Windows" or "D:" @@ -244,7 +245,7 @@ FilePath FilePath::ConcatPaths(const FilePath& directory, // Returns true if pathname describes something findable in the file-system, // either a file, directory, or whatever. bool FilePath::FileOrDirectoryExists() const { -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str()); const DWORD attributes = GetFileAttributes(unicode); delete[] unicode; @@ -259,7 +260,7 @@ bool FilePath::FileOrDirectoryExists() const { // that exists. bool FilePath::DirectoryExists() const { bool result = false; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Don't strip off trailing separator if path is a root directory on // Windows (like "C:\\"). const FilePath& path(IsRootDirectory() ? *this @@ -268,7 +269,7 @@ bool FilePath::DirectoryExists() const { const FilePath& path(*this); #endif -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE LPCWSTR unicode = String::AnsiToUtf16(path.c_str()); const DWORD attributes = GetFileAttributes(unicode); delete[] unicode; @@ -344,14 +345,15 @@ bool FilePath::CreateDirectoriesRecursively() const { // directory for any reason, including if the parent directory does not // exist. Not named "CreateDirectory" because that's a macro on Windows. bool FilePath::CreateFolder() const { -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE FilePath removed_sep(this->RemoveTrailingPathSeparator()); LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str()); int result = CreateDirectory(unicode, nullptr) ? 0 : -1; delete[] unicode; -#elif GTEST_OS_WINDOWS +#elif defined(GTEST_OS_WINDOWS) int result = _mkdir(pathname_.c_str()); -#elif GTEST_OS_ESP8266 || GTEST_OS_XTENSA || GTEST_OS_QURT +#elif defined(GTEST_OS_ESP8266) || defined(GTEST_OS_XTENSA) || \ + defined(GTEST_OS_QURT) // do nothing int result = 0; #else @@ -380,7 +382,7 @@ void FilePath::Normalize() { auto out = pathname_.begin(); auto i = pathname_.cbegin(); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // UNC paths are treated specially if (pathname_.end() - i >= 3 && IsPathSeparator(*i) && IsPathSeparator(*(i + 1)) && !IsPathSeparator(*(i + 2))) { diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index 9fbcfd34..036c3415 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -55,7 +55,7 @@ #include // NOLINT #endif -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS #include // NOLINT #endif // GTEST_OS_WINDOWS @@ -384,7 +384,7 @@ class GTEST_API_ UnitTestOptions { static bool FilterMatchesTest(const std::string& test_suite_name, const std::string& test_name); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Function for supporting the gtest_catch_exception flag. // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 105a3ec8..da4d12d8 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -38,7 +38,7 @@ #include #include -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS #include #include #include @@ -51,32 +51,34 @@ #include #endif // GTEST_OS_WINDOWS -#if GTEST_OS_MAC +#ifdef GTEST_OS_MAC #include #include #include #endif // GTEST_OS_MAC -#if GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \ - GTEST_OS_NETBSD || GTEST_OS_OPENBSD +#if defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \ + defined(GTEST_OS_GNU_KFREEBSD) || defined(GTEST_OS_NETBSD) || \ + defined(GTEST_OS_OPENBSD) #include -#if GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD +#if defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \ + defined(GTEST_OS_GNU_KFREEBSD) #include #endif #endif -#if GTEST_OS_QNX +#ifdef GTEST_OS_QNX #include #include #include #endif // GTEST_OS_QNX -#if GTEST_OS_AIX +#ifdef GTEST_OS_AIX #include #include #endif // GTEST_OS_AIX -#if GTEST_OS_FUCHSIA +#ifdef GTEST_OS_FUCHSIA #include #include #endif // GTEST_OS_FUCHSIA @@ -90,7 +92,7 @@ namespace testing { namespace internal { -#if GTEST_OS_LINUX || GTEST_OS_GNU_HURD +#if defined(GTEST_OS_LINUX) || defined(GTEST_OS_GNU_HURD) namespace { template @@ -113,7 +115,7 @@ size_t GetThreadCount() { return ReadProcFileField(filename, 19); } -#elif GTEST_OS_MAC +#elif defined(GTEST_OS_MAC) size_t GetThreadCount() { const task_t task = mach_task_self(); @@ -131,20 +133,20 @@ size_t GetThreadCount() { } } -#elif GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \ - GTEST_OS_NETBSD +#elif defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \ + defined(GTEST_OS_GNU_KFREEBSD) || defined(GTEST_OS_NETBSD) -#if GTEST_OS_NETBSD +#ifdef GTEST_OS_NETBSD #undef KERN_PROC #define KERN_PROC KERN_PROC2 #define kinfo_proc kinfo_proc2 #endif -#if GTEST_OS_DRAGONFLY +#ifdef GTEST_OS_DRAGONFLY #define KP_NLWP(kp) (kp.kp_nthreads) -#elif GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD +#elif defined(GTEST_OS_FREEBSD) || defined(GTEST_OS_GNU_KFREEBSD) #define KP_NLWP(kp) (kp.ki_numthreads) -#elif GTEST_OS_NETBSD +#elif defined(GTEST_OS_NETBSD) #define KP_NLWP(kp) (kp.p_nlwps) #endif @@ -156,7 +158,7 @@ size_t GetThreadCount() { KERN_PROC, KERN_PROC_PID, getpid(), -#if GTEST_OS_NETBSD +#ifdef GTEST_OS_NETBSD sizeof(struct kinfo_proc), 1, #endif @@ -169,7 +171,7 @@ size_t GetThreadCount() { } return static_cast(KP_NLWP(info)); } -#elif GTEST_OS_OPENBSD +#elif defined(GTEST_OS_OPENBSD) // Returns the number of threads running in the process, or 0 to indicate that // we cannot detect it. @@ -206,7 +208,7 @@ size_t GetThreadCount() { return nthreads; } -#elif GTEST_OS_QNX +#elif defined(GTEST_OS_QNX) // Returns the number of threads running in the process, or 0 to indicate that // we cannot detect it. @@ -226,7 +228,7 @@ size_t GetThreadCount() { } } -#elif GTEST_OS_AIX +#elif defined(GTEST_OS_AIX) size_t GetThreadCount() { struct procentry64 entry; @@ -239,7 +241,7 @@ size_t GetThreadCount() { } } -#elif GTEST_OS_FUCHSIA +#elif defined(GTEST_OS_FUCHSIA) size_t GetThreadCount() { int dummy_buffer; @@ -264,7 +266,7 @@ size_t GetThreadCount() { #endif // GTEST_OS_LINUX -#if GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS +#if defined(GTEST_IS_THREADSAFE) && defined(GTEST_OS_WINDOWS) AutoHandle::AutoHandle() : handle_(INVALID_HANDLE_VALUE) {} @@ -1027,7 +1029,7 @@ class CapturedStream { public: // The ctor redirects the stream to a temporary file. explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) { -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS char temp_dir_path[MAX_PATH + 1] = {'\0'}; // NOLINT char temp_file_path[MAX_PATH + 1] = {'\0'}; // NOLINT @@ -1046,7 +1048,7 @@ class CapturedStream { // directory, so we create the temporary file in a temporary directory. std::string name_template; -#if GTEST_OS_LINUX_ANDROID +#ifdef GTEST_OS_LINUX_ANDROID // Note: Android applications are expected to call the framework's // Context.getExternalStorageDirectory() method through JNI to get // the location of the world-writable SD Card directory. However, @@ -1059,7 +1061,7 @@ class CapturedStream { // '/sdcard' and other variants cannot be relied on, as they are not // guaranteed to be mounted, or may have a delay in mounting. name_template = "/data/local/tmp/"; -#elif GTEST_OS_IOS +#elif defined(GTEST_OS_IOS) char user_temp_dir[PATH_MAX + 1]; // Documented alternative to NSTemporaryDirectory() (for obtaining creating @@ -1246,7 +1248,7 @@ void ClearInjectableArgvs() { } #endif // GTEST_HAS_DEATH_TEST -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE namespace posix { void Abort() { DebugBreak(); diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index fb578d58..88bbcd20 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -61,7 +61,7 @@ #include "gtest/internal/custom/gtest.h" #include "gtest/internal/gtest-port.h" -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX #include // NOLINT #include // NOLINT @@ -74,18 +74,18 @@ #include -#elif GTEST_OS_ZOS +#elif defined(GTEST_OS_ZOS) #include // NOLINT // On z/OS we additionally need strings.h for strcasecmp. #include // NOLINT -#elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE. +#elif defined(GTEST_OS_WINDOWS_MOBILE) // We are on Windows CE. #include // NOLINT #undef min -#elif GTEST_OS_WINDOWS // We are on Windows proper. +#elif defined(GTEST_OS_WINDOWS) // We are on Windows proper. #include // NOLINT #undef min @@ -99,7 +99,7 @@ #include // NOLINT #include // NOLINT -#if GTEST_OS_WINDOWS_MINGW +#ifdef GTEST_OS_WINDOWS_MINGW #include // NOLINT #endif // GTEST_OS_WINDOWS_MINGW @@ -125,11 +125,11 @@ #include "src/gtest-internal-inl.h" -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS #define vsnprintf _vsnprintf #endif // GTEST_OS_WINDOWS -#if GTEST_OS_MAC +#ifdef GTEST_OS_MAC #ifndef GTEST_OS_IOS #include #endif @@ -630,7 +630,7 @@ static ::std::vector g_argvs; FilePath GetCurrentExecutableName() { FilePath result; -#if GTEST_OS_WINDOWS || GTEST_OS_OS2 +#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_OS2) result.Set(FilePath(GetArgvs()[0]).RemoveExtension("exe")); #else result.Set(FilePath(GetArgvs()[0])); @@ -1165,7 +1165,7 @@ TimeInMillis GetTimeInMillis() { // class String. -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE // Creates a UTF-16 wide string from the given ANSI string, allocating // memory using new. The caller is responsible for deleting the return // value using delete[]. Returns the wide string, or NULL if the @@ -1867,14 +1867,14 @@ AssertionResult IsNotSubstring(const char* needle_expr, namespace internal { -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS namespace { // Helper function for IsHRESULT{SuccessFailure} predicates AssertionResult HRESULTFailureHelper(const char* expr, const char* expected, long hr) { // NOLINT -#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE +#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_TV_TITLE) // Windows CE doesn't support FormatMessage. const char error_text[] = ""; @@ -2135,9 +2135,9 @@ bool String::CaseInsensitiveWideCStringEquals(const wchar_t* lhs, if (rhs == nullptr) return false; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS return _wcsicmp(lhs, rhs) == 0; -#elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID +#elif defined(GTEST_OS_LINUX) && !defined(GTEST_OS_LINUX_ANDROID) return wcscasecmp(lhs, rhs) == 0; #else // Android, Mac OS X and Cygwin don't define wcscasecmp. @@ -3144,7 +3144,7 @@ static void PrintTestPartResult(const TestPartResult& test_part_result) { // following statements add the test part result message to the Output // window such that the user can double-click on it to jump to the // corresponding source code location; otherwise they do nothing. -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) // We don't call OutputDebugString*() on Windows Mobile, as printing // to stdout is done by OutputDebugString() there already - we don't // want the same message printed twice. @@ -3154,8 +3154,9 @@ static void PrintTestPartResult(const TestPartResult& test_part_result) { } // class PrettyUnitTestResultPrinter -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \ - !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) && \ + !defined(GTEST_OS_WINDOWS_PHONE) && !defined(GTEST_OS_WINDOWS_RT) && \ + !defined(GTEST_OS_WINDOWS_MINGW) // Returns the character attribute for the given color. static WORD GetColorAttribute(GTestColor color) { @@ -3227,7 +3228,7 @@ bool ShouldUseColor(bool stdout_is_tty) { const char* const gtest_color = c.c_str(); if (String::CaseInsensitiveCStringEquals(gtest_color, "auto")) { -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW) // On Windows the TERM variable is usually not set, but the // console there does support colors. return stdout_is_tty; @@ -3282,8 +3283,9 @@ static void ColoredPrintf(GTestColor color, const char* fmt, ...) { return; } -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \ - !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) && \ + !defined(GTEST_OS_WINDOWS_PHONE) && !defined(GTEST_OS_WINDOWS_RT) && \ + !defined(GTEST_OS_WINDOWS_MINGW) const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); // Gets the current text color. @@ -5036,7 +5038,7 @@ class ScopedPrematureExitFile { } ~ScopedPrematureExitFile() { -#if !GTEST_OS_ESP8266 +#ifndef GTEST_OS_ESP8266 if (!premature_exit_filepath_.empty()) { int retval = remove(premature_exit_filepath_.c_str()); if (retval) { @@ -5332,7 +5334,8 @@ void UnitTest::AddTestPartResult(TestPartResult::Type result_type, // with another testing framework) and specify the former on the // command line for debugging. if (GTEST_FLAG_GET(break_on_failure)) { -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_PHONE) && \ + !defined(GTEST_OS_WINDOWS_RT) // Using DebugBreak on Windows allows gtest to still break into a debugger // when a failure happens and both the --gtest_break_on_failure and // the --gtest_catch_exceptions flags are specified. @@ -5417,26 +5420,28 @@ int UnitTest::Run() { // used for the duration of the program. impl()->set_catch_exceptions(GTEST_FLAG_GET(catch_exceptions)); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Either the user wants Google Test to catch exceptions thrown by the // tests or this is executing in the context of death test child // process. In either case the user does not want to see pop-up dialogs // about crashes - they are expected. if (impl()->catch_exceptions() || in_death_test_child_process) { -#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT +#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_WINDOWS_PHONE) && \ + !defined(GTEST_OS_WINDOWS_RT) // SetErrorMode doesn't exist on CE. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); #endif // !GTEST_OS_WINDOWS_MOBILE -#if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE +#if (defined(_MSC_VER) || defined(GTEST_OS_WINDOWS_MINGW)) && \ + !defined(GTEST_OS_WINDOWS_MOBILE) // Death test children can be terminated with _abort(). On Windows, // _abort() can show a dialog with a warning message. This forces the // abort message to go to stderr instead. _set_error_mode(_OUT_TO_STDERR); #endif -#if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE +#if defined(_MSC_VER) && !defined(GTEST_OS_WINDOWS_MOBILE) // In the debug version, Visual Studio pops up a separate dialog // offering a choice to debug the aborted program. We need to suppress // this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement @@ -6520,7 +6525,7 @@ static const char kColorEncodedHelpMessage[] = #endif // GTEST_CAN_STREAM_RESULTS_ "\n" "Assertion Behavior:\n" -#if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS +#if defined(GTEST_HAS_DEATH_TEST) && !defined(GTEST_OS_WINDOWS) " @G--" GTEST_FLAG_PREFIX_ "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n" " Set the default death test style.\n" @@ -6687,7 +6692,7 @@ void ParseGoogleTestFlagsOnly(int* argc, char** argv) { // Fix the value of *_NSGetArgc() on macOS, but if and only if // *_NSGetArgv() == argv // Only applicable to char** version of argv -#if GTEST_OS_MAC +#ifdef GTEST_OS_MAC #ifndef GTEST_OS_IOS if (*_NSGetArgv() == argv) { *_NSGetArgc() = *argc; @@ -6799,9 +6804,9 @@ static std::string GetDirFromEnv( std::string TempDir() { #if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_) return GTEST_CUSTOM_TEMPDIR_FUNCTION_(); -#elif GTEST_OS_WINDOWS || GTEST_OS_WINDOWS_MOBILE +#elif defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_WINDOWS_MOBILE) return GetDirFromEnv({"TEST_TMPDIR", "TEMP"}, "\\temp\\", '\\'); -#elif GTEST_OS_LINUX_ANDROID +#elif defined(GTEST_OS_LINUX_ANDROID) return GetDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/data/local/tmp/", '/'); #else return GetDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/tmp/", '/'); @@ -6821,10 +6826,10 @@ static std::string GetCurrentExecutableDirectory() { std::string SrcDir() { #if defined(GTEST_CUSTOM_SRCDIR_FUNCTION_) return GTEST_CUSTOM_SRCDIR_FUNCTION_(); -#elif GTEST_OS_WINDOWS || GTEST_OS_WINDOWS_MOBILE +#elif defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_WINDOWS_MOBILE) return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(), '\\'); -#elif GTEST_OS_LINUX_ANDROID +#elif defined(GTEST_OS_LINUX_ANDROID) return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(), '/'); #else diff --git a/googletest/src/gtest_main.cc b/googletest/src/gtest_main.cc index 5abaa29f..c2e3b3cc 100644 --- a/googletest/src/gtest_main.cc +++ b/googletest/src/gtest_main.cc @@ -31,10 +31,10 @@ #include "gtest/gtest.h" -#if GTEST_OS_ESP8266 || GTEST_OS_ESP32 +#if defined(GTEST_OS_ESP8266) || defined(GTEST_OS_ESP32) // Arduino-like platforms: program entry points are setup/loop instead of main. -#if GTEST_OS_ESP8266 +#ifdef GTEST_OS_ESP8266 extern "C" { #endif @@ -42,11 +42,11 @@ void setup() { testing::InitGoogleTest(); } void loop() { RUN_ALL_TESTS(); } -#if GTEST_OS_ESP8266 +#ifdef GTEST_OS_ESP8266 } #endif -#elif GTEST_OS_QURT +#elif defined(GTEST_OS_QURT) // QuRT: program entry point is main, but argc/argv are unusable. GTEST_API_ int main() { diff --git a/googletest/test/googletest-break-on-failure-unittest_.cc b/googletest/test/googletest-break-on-failure-unittest_.cc index 324294f3..337e34c3 100644 --- a/googletest/test/googletest-break-on-failure-unittest_.cc +++ b/googletest/test/googletest-break-on-failure-unittest_.cc @@ -39,7 +39,7 @@ #include "gtest/gtest.h" -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS #include #include #endif @@ -49,7 +49,7 @@ namespace { // A test that's expected to fail. TEST(Foo, Bar) { EXPECT_EQ(2, 3); } -#if GTEST_HAS_SEH && !GTEST_OS_WINDOWS_MOBILE +#if GTEST_HAS_SEH && !defined(GTEST_OS_WINDOWS_MOBILE) // On Windows Mobile global exception handlers are not supported. LONG WINAPI ExitWithExceptionCode(struct _EXCEPTION_POINTERS* exception_pointers) { @@ -60,12 +60,12 @@ ExitWithExceptionCode(struct _EXCEPTION_POINTERS* exception_pointers) { } // namespace int main(int argc, char** argv) { -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Suppresses display of the Windows error dialog upon encountering // a general protection fault (segment violation). SetErrorMode(SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS); -#if GTEST_HAS_SEH && !GTEST_OS_WINDOWS_MOBILE +#if GTEST_HAS_SEH && !defined(GTEST_OS_WINDOWS_MOBILE) // The default unhandled exception filter does not always exit // with the exception code as exit code - for example it exits with diff --git a/googletest/test/googletest-death-test-test.cc b/googletest/test/googletest-death-test-test.cc index 515b5998..a361a574 100644 --- a/googletest/test/googletest-death-test-test.cc +++ b/googletest/test/googletest-death-test-test.cc @@ -39,7 +39,7 @@ using testing::internal::AlwaysTrue; #if GTEST_HAS_DEATH_TEST -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS #include // For chdir(). #include // For O_BINARY #include @@ -52,7 +52,7 @@ using testing::internal::AlwaysTrue; #include #include -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX #include #endif // GTEST_OS_LINUX @@ -200,7 +200,7 @@ int DieInDebugElse12(int* sideeffect) { return 12; } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Death in dbg due to Windows CRT assertion failure, not opt. int DieInCRTDebugElse12(int* sideeffect) { @@ -220,7 +220,7 @@ int DieInCRTDebugElse12(int* sideeffect) { #endif // GTEST_OS_WINDOWS -#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA +#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA) // Tests the ExitedWithCode predicate. TEST(ExitStatusPredicateTest, ExitedWithCode) { @@ -374,7 +374,7 @@ TEST_F(TestForDeathTest, FastDeathTestInChangedDir) { ASSERT_DEATH(_exit(1), ""); } -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX void SigprofAction(int, siginfo_t*, void*) { /* no op */ } @@ -641,7 +641,7 @@ TEST_F(TestForDeathTest, TestExpectDebugDeath) { #endif } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/crtsetreportmode // In debug mode, the calls to _CrtSetReportMode and _CrtSetReportFile enable @@ -693,7 +693,7 @@ void ExpectDebugDeathHelper(bool* aborted) { *aborted = false; } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) { printf( "This test should be considered failing if it shows " @@ -805,14 +805,14 @@ static void TestExitMacros() { EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1), ""); ASSERT_EXIT(_exit(42), testing::ExitedWithCode(42), ""); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Of all signals effects on the process exit code, only those of SIGABRT // are documented on Windows. // See https://msdn.microsoft.com/en-us/query-bi/m/dwwzkt4c. EXPECT_EXIT(raise(SIGABRT), testing::ExitedWithCode(3), "") << "b_ar"; -#elif !GTEST_OS_FUCHSIA +#elif !defined(GTEST_OS_FUCHSIA) // Fuchsia has no unix signals. EXPECT_EXIT(raise(SIGKILL), testing::KilledBySignal(SIGKILL), "") << "foo"; @@ -1177,7 +1177,7 @@ TEST(GetLastErrnoDescription, GetLastErrnoDescriptionWorks) { EXPECT_STREQ("", GetLastErrnoDescription().c_str()); } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS TEST(AutoHandleTest, AutoHandleWorks) { HANDLE handle = ::CreateEvent(NULL, FALSE, FALSE, NULL); ASSERT_NE(INVALID_HANDLE_VALUE, handle); @@ -1204,7 +1204,7 @@ TEST(AutoHandleTest, AutoHandleWorks) { } #endif // GTEST_OS_WINDOWS -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS typedef unsigned __int64 BiggestParsable; typedef signed __int64 BiggestSignedParsable; #else @@ -1301,7 +1301,7 @@ TEST(ParseNaturalNumberTest, WorksForShorterIntegers) { EXPECT_EQ(123, char_result); } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS TEST(EnvironmentTest, HandleFitsIntoSizeT) { ASSERT_TRUE(sizeof(HANDLE) <= sizeof(size_t)); } diff --git a/googletest/test/googletest-filepath-test.cc b/googletest/test/googletest-filepath-test.cc index 5f0c9c2f..0a33d714 100644 --- a/googletest/test/googletest-filepath-test.cc +++ b/googletest/test/googletest-filepath-test.cc @@ -41,9 +41,9 @@ #include "gtest/internal/gtest-filepath.h" #include "src/gtest-internal-inl.h" -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE #include // NOLINT -#elif GTEST_OS_WINDOWS +#elif defined(GTEST_OS_WINDOWS) #include // NOLINT #endif // GTEST_OS_WINDOWS_MOBILE @@ -51,7 +51,7 @@ namespace testing { namespace internal { namespace { -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE // Windows CE doesn't have the remove C function. int remove(const char* path) { @@ -80,7 +80,7 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) { const FilePath cwd = FilePath::GetCurrentDir(); posix::ChDir(original_dir.c_str()); -#if GTEST_OS_WINDOWS || GTEST_OS_OS2 +#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_OS2) // Skips the ":". const char* const cwd_without_drive = strchr(cwd.c_str(), ':'); @@ -174,7 +174,7 @@ TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileNameForAlternateSeparator) { // RemoveFileName "" -> "./" TEST(RemoveFileNameTest, EmptyName) { -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE // On Windows CE, we use the root as the current directory. EXPECT_EQ(GTEST_PATH_SEP_, FilePath("").RemoveFileName().string()); #else @@ -357,7 +357,7 @@ TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) { } TEST(DirectoryTest, RootDirectoryExists) { -#if GTEST_OS_WINDOWS // We are on Windows. +#ifdef GTEST_OS_WINDOWS // We are on Windows. char current_drive[_MAX_PATH]; // NOLINT current_drive[0] = static_cast(_getdrive() + 'A' - 1); current_drive[1] = ':'; @@ -369,7 +369,7 @@ TEST(DirectoryTest, RootDirectoryExists) { #endif // GTEST_OS_WINDOWS } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) { const int saved_drive_ = _getdrive(); // Find a drive that doesn't exist. Start with 'Z' to avoid common ones. @@ -387,7 +387,7 @@ TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) { } #endif // GTEST_OS_WINDOWS -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE // Windows CE _does_ consider an empty directory to exist. TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) { EXPECT_FALSE(FilePath("").DirectoryExists()); @@ -395,7 +395,7 @@ TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) { #endif // !GTEST_OS_WINDOWS_MOBILE TEST(DirectoryTest, CurrentDirectoryExists) { -#if GTEST_OS_WINDOWS // We are on Windows. +#ifdef GTEST_OS_WINDOWS // We are on Windows. #ifndef _WIN32_CE // Windows CE doesn't have a current directory. EXPECT_TRUE(FilePath(".").DirectoryExists()); @@ -423,7 +423,7 @@ TEST(NormalizeTest, MultipleConsecutiveSeparatorsInMidstring) { // "/bar" == //bar" == "///bar" TEST(NormalizeTest, MultipleConsecutiveSeparatorsAtStringStart) { EXPECT_EQ(GTEST_PATH_SEP_ "bar", FilePath(GTEST_PATH_SEP_ "bar").string()); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS EXPECT_EQ(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar", FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string()); #else @@ -620,7 +620,7 @@ TEST(FilePathTest, IsDirectory) { TEST(FilePathTest, IsAbsolutePath) { EXPECT_FALSE(FilePath("is" GTEST_PATH_SEP_ "relative").IsAbsolutePath()); EXPECT_FALSE(FilePath("").IsAbsolutePath()); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS EXPECT_TRUE( FilePath("c:\\" GTEST_PATH_SEP_ "is_not" GTEST_PATH_SEP_ "relative") .IsAbsolutePath()); @@ -638,7 +638,7 @@ TEST(FilePathTest, IsAbsolutePath) { } TEST(FilePathTest, IsRootDirectory) { -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS EXPECT_TRUE(FilePath("a:\\").IsRootDirectory()); EXPECT_TRUE(FilePath("Z:/").IsRootDirectory()); EXPECT_TRUE(FilePath("e://").IsRootDirectory()); diff --git a/googletest/test/googletest-options-test.cc b/googletest/test/googletest-options-test.cc index 87463209..b712c06f 100644 --- a/googletest/test/googletest-options-test.cc +++ b/googletest/test/googletest-options-test.cc @@ -40,11 +40,11 @@ #include "gtest/gtest.h" -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE #include -#elif GTEST_OS_WINDOWS +#elif defined(GTEST_OS_WINDOWS) #include -#elif GTEST_OS_OS2 +#elif defined(GTEST_OS_OS2) // For strcasecmp on OS/2 #include #endif // GTEST_OS_WINDOWS_MOBILE @@ -92,7 +92,7 @@ TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) { .string(); const std::string& output_file = UnitTestOptions::GetAbsolutePathToOutputFile(); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str()); #else EXPECT_EQ(expected_output_file, output_file.c_str()); @@ -101,19 +101,19 @@ TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) { TEST(OutputFileHelpersTest, GetCurrentExecutableName) { const std::string exe_str = GetCurrentExecutableName().string(); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS const bool success = _strcmpi("googletest-options-test", exe_str.c_str()) == 0 || _strcmpi("gtest-options-ex_test", exe_str.c_str()) == 0 || _strcmpi("gtest_all_test", exe_str.c_str()) == 0 || _strcmpi("gtest_dll_test", exe_str.c_str()) == 0; -#elif GTEST_OS_OS2 +#elif defined(GTEST_OS_OS2) const bool success = strcasecmp("googletest-options-test", exe_str.c_str()) == 0 || strcasecmp("gtest-options-ex_test", exe_str.c_str()) == 0 || strcasecmp("gtest_all_test", exe_str.c_str()) == 0 || strcasecmp("gtest_dll_test", exe_str.c_str()) == 0; -#elif GTEST_OS_FUCHSIA +#elif defined(GTEST_OS_FUCHSIA) const bool success = exe_str == "app"; #else const bool success = @@ -123,7 +123,7 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) { if (!success) FAIL() << "GetCurrentExecutableName() returns " << exe_str; } -#if !GTEST_OS_FUCHSIA +#ifndef GTEST_OS_FUCHSIA class XmlOutputChangeDirTest : public Test { protected: @@ -176,7 +176,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) { .string(); const std::string& output_file = UnitTestOptions::GetAbsolutePathToOutputFile(); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str()); #else EXPECT_EQ(expected_output_file, output_file.c_str()); @@ -184,7 +184,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) { } TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) { -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS GTEST_FLAG_SET(output, "xml:c:\\tmp\\filename.abc"); EXPECT_EQ(FilePath("c:\\tmp\\filename.abc").string(), UnitTestOptions::GetAbsolutePathToOutputFile()); @@ -196,7 +196,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) { } TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) { -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS const std::string path = "c:\\tmp\\"; #else const std::string path = "/tmp/"; @@ -208,7 +208,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) { const std::string& output_file = UnitTestOptions::GetAbsolutePathToOutputFile(); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str()); #else EXPECT_EQ(expected_output_file, output_file.c_str()); diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc index 1bace982..090fb070 100644 --- a/googletest/test/googletest-output-test_.cc +++ b/googletest/test/googletest-output-test_.cc @@ -1028,7 +1028,7 @@ int main(int argc, char** argv) { if (GTEST_FLAG_GET(internal_run_death_test) != "") { // Skip the usual output capturing if we're running as the child // process of an threadsafe-style death test. -#if GTEST_OS_WINDOWS +#if defined(GTEST_OS_WINDOWS) posix::FReopen("nul:", "w", stdout); #else posix::FReopen("/dev/null", "w", stdout); diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index bb536ac5..a93572a9 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -32,7 +32,7 @@ #include "gtest/internal/gtest-port.h" -#if GTEST_OS_MAC +#ifdef GTEST_OS_MAC #include #endif // GTEST_OS_MAC @@ -281,9 +281,11 @@ TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownFileAndLine) { EXPECT_EQ("unknown file", FormatCompilerIndependentFileLocation(nullptr, -1)); } -#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_QNX || GTEST_OS_FUCHSIA || \ - GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \ - GTEST_OS_NETBSD || GTEST_OS_OPENBSD || GTEST_OS_GNU_HURD +#if defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC) || \ + defined(GTEST_OS_QNX) || defined(GTEST_OS_FUCHSIA) || \ + defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \ + defined(GTEST_OS_GNU_KFREEBSD) || defined(GTEST_OS_NETBSD) || \ + defined(GTEST_OS_OPENBSD) || defined(GTEST_OS_GNU_HURD) void* ThreadFunc(void* data) { internal::Mutex* mutex = static_cast(data); mutex->Lock(); @@ -916,7 +918,7 @@ TEST(RETest, PartialMatchWorks) { #endif // GTEST_USES_POSIX_RE -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE TEST(CaptureTest, CapturesStdout) { CaptureStdout(); @@ -1064,7 +1066,7 @@ class AtomicCounterWithMutex { GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&memory_barrier_mutex)); GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&memory_barrier_mutex)); -#elif GTEST_OS_WINDOWS +#elif defined(GTEST_OS_WINDOWS) // On Windows, performing an interlocked access puts up a memory barrier. volatile LONG dummy = 0; ::InterlockedIncrement(&dummy); @@ -1146,14 +1148,14 @@ class DestructorCall { public: DestructorCall() { invoked_ = false; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS wait_event_.Reset(::CreateEvent(NULL, TRUE, FALSE, NULL)); GTEST_CHECK_(wait_event_.Get() != NULL); #endif } bool CheckDestroyed() const { -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS if (::WaitForSingleObject(wait_event_.Get(), 1000) != WAIT_OBJECT_0) return false; #endif @@ -1162,7 +1164,7 @@ class DestructorCall { void ReportDestroyed() { invoked_ = true; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS ::SetEvent(wait_event_.Get()); #endif } @@ -1178,7 +1180,7 @@ class DestructorCall { private: bool invoked_; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS AutoHandle wait_event_; #endif static std::vector* const list_; @@ -1278,12 +1280,12 @@ TEST(ThreadLocalTest, ThreadLocalMutationsAffectOnlyCurrentThread) { #endif // GTEST_IS_THREADSAFE -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS TEST(WindowsTypesTest, HANDLEIsVoidStar) { StaticAssertTypeEq(); } -#if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR) +#if defined(GTEST_OS_WINDOWS_MINGW) && !defined(__MINGW64_VERSION_MAJOR) TEST(WindowsTypesTest, _CRITICAL_SECTIONIs_CRITICAL_SECTION) { StaticAssertTypeEq(); } diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index 34aa9245..fa8b084d 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -432,7 +432,7 @@ TEST(PrintBuiltInTypeTest, Integer) { // Size types. TEST(PrintBuiltInTypeTest, Size_t) { EXPECT_EQ("1", Print(sizeof('a'))); // size_t. -#if !GTEST_OS_WINDOWS +#ifndef GTEST_OS_WINDOWS // Windows has no ssize_t type. EXPECT_EQ("-2", Print(static_cast(-2))); // ssize_t. #endif // !GTEST_OS_WINDOWS diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 580ce837..461297ab 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -448,7 +448,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { // tzset() distinguishes between the TZ variable being present and empty // and not being present, so we have to consider the case of time_zone // being NULL. -#if defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW +#if defined(_MSC_VER) || defined(GTEST_OS_WINDOWS_MINGW) // ...Unless it's MSVC, whose standard library's _putenv doesn't // distinguish between an empty and a missing variable. const std::string env_var = @@ -458,7 +458,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { tzset(); GTEST_DISABLE_MSC_WARNINGS_POP_() #else -#if GTEST_OS_LINUX_ANDROID && __ANDROID_API__ < 21 +#if defined(GTEST_OS_LINUX_ANDROID) && __ANDROID_API__ < 21 // Work around KitKat bug in tzset by setting "UTC" before setting "UTC+00". // See https://github.com/android/ndk/issues/1604. setenv("TZ", "UTC", 1); @@ -1090,7 +1090,7 @@ TEST(StringTest, CaseInsensitiveWideCStringEquals) { EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L"FOOBAR", L"foobar")); } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Tests String::ShowWideCString(). TEST(StringTest, ShowWideCString) { @@ -1099,7 +1099,7 @@ TEST(StringTest, ShowWideCString) { EXPECT_STREQ("foo", String::ShowWideCString(L"foo").c_str()); } -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE TEST(StringTest, AnsiAndUtf16Null) { EXPECT_EQ(NULL, String::AnsiToUtf16(NULL)); EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL)); @@ -1676,7 +1676,7 @@ TEST_F(GTestFlagSaverTest, VerifyGTestFlags) { VerifyAndModifyFlags(); } // value. If the value argument is "", unsets the environment // variable. The caller must ensure that both arguments are not NULL. static void SetEnv(const char* name, const char* value) { -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE // Environment variables are not supported on Windows CE. return; #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) @@ -1699,7 +1699,7 @@ static void SetEnv(const char* name, const char* value) { // We cast away the 'const' since that would work for both variants. putenv(const_cast(added_env[name]->c_str())); delete prev_env; -#elif GTEST_OS_WINDOWS // If we are on Windows proper. +#elif defined(GTEST_OS_WINDOWS) // If we are on Windows proper. _putenv((Message() << name << "=" << value).GetString().c_str()); #else if (*value == '\0') { @@ -1710,7 +1710,7 @@ static void SetEnv(const char* name, const char* value) { #endif // GTEST_OS_WINDOWS_MOBILE } -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE // Environment variables are not supported on Windows CE. using testing::internal::Int32FromGTestEnv; @@ -1819,7 +1819,7 @@ TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) { // Tests that Int32FromEnvOrDie() parses the value of the var or // returns the correct default. // Environment variables are not supported on Windows CE. -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) { EXPECT_EQ(333, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333)); SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "123"); @@ -1892,7 +1892,7 @@ TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) { // Tests that sharding is enabled if total_shards > 1 and // we are not in a death test subprocess. // Environment variables are not supported on Windows CE. -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) { SetEnv(index_var_, "4"); SetEnv(total_var_, "22"); @@ -3926,7 +3926,7 @@ TEST(AssertionTest, NamedEnum) { enum { kCaseA = -1, -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX // We want to test the case where the size of the anonymous enum is // larger than sizeof(int), to make sure our implementation of the @@ -3949,7 +3949,7 @@ enum { }; TEST(AssertionTest, AnonymousEnum) { -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX EXPECT_EQ(static_cast(kCaseA), static_cast(kCaseB)); @@ -3983,7 +3983,7 @@ TEST(AssertionTest, AnonymousEnum) { #endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC) -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS static HRESULT UnexpectedHRESULTFailure() { return E_UNEXPECTED; } @@ -4343,7 +4343,7 @@ TEST(AssertionWithMessageTest, ASSERT_TRUE) { "(null)(null)"); } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Tests using wide strings in assertion messages. TEST(AssertionWithMessageTest, WideStringMessage) { EXPECT_NONFATAL_FAILURE( @@ -6224,7 +6224,7 @@ TEST_F(ParseFlagsTest, AbseilPositionalFlags) { } #endif -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Tests parsing wide strings. TEST_F(ParseFlagsTest, WideStrings) { const wchar_t* argv[] = {L"foo.exe", @@ -6614,7 +6614,7 @@ TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) { TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) { GTEST_FLAG_SET(color, "auto"); -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW) // On Windows, we ignore the TERM variable as it's usually not set. SetEnv("TERM", "dumb"); From a08c03c5f52802c50a541d7283be31a4c3177807 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 3 Mar 2023 15:56:41 -0800 Subject: [PATCH 22/75] Always specify definitions for internal macros These macros should only be used within googletest, so changing them will not affect external users. This allows compiling with -Wundef (#3267). PiperOrigin-RevId: 513943800 Change-Id: I697b1005c29b0d5af06f583f202d86db48b567b9 --- .../include/gtest/internal/gtest-port.h | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index f2b0bbf9..ba5e9bc3 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -202,16 +202,17 @@ // is suppressed. // GTEST_INTERNAL_HAS_ANY - for enabling UniversalPrinter or // UniversalPrinter specializations. +// Always defined to 0 or 1. // GTEST_INTERNAL_HAS_OPTIONAL - for enabling UniversalPrinter // or // UniversalPrinter -// specializations. +// specializations. Always defined to 0 or 1. // GTEST_INTERNAL_HAS_STRING_VIEW - for enabling Matcher or // Matcher -// specializations. +// specializations. Always defined to 0 or 1. // GTEST_INTERNAL_HAS_VARIANT - for enabling UniversalPrinter or // UniversalPrinter -// specializations. +// specializations. Always defined to 0 or 1. // // Synchronization: // Mutex, MutexLock, ThreadLocal, GetThreadCount() @@ -2389,6 +2390,10 @@ using Any = ::std::any; #endif // __has_include #endif // GTEST_HAS_ABSL +#ifndef GTEST_INTERNAL_HAS_ANY +#define GTEST_INTERNAL_HAS_ANY 0 +#endif + #if GTEST_HAS_ABSL // Always use absl::optional for UniversalPrinter<> specializations if // googletest is built with absl support. @@ -2421,6 +2426,10 @@ inline ::std::nullopt_t Nullopt() { return ::std::nullopt; } #endif // __has_include #endif // GTEST_HAS_ABSL +#ifndef GTEST_INTERNAL_HAS_OPTIONAL +#define GTEST_INTERNAL_HAS_OPTIONAL 0 +#endif + #if GTEST_HAS_ABSL // Always use absl::string_view for Matcher<> specializations if googletest // is built with absl support. @@ -2449,6 +2458,10 @@ using StringView = ::std::string_view; #endif // __has_include #endif // GTEST_HAS_ABSL +#ifndef GTEST_INTERNAL_HAS_STRING_VIEW +#define GTEST_INTERNAL_HAS_STRING_VIEW 0 +#endif + #if GTEST_HAS_ABSL // Always use absl::variant for UniversalPrinter<> specializations if googletest // is built with absl support. @@ -2478,6 +2491,10 @@ using Variant = ::std::variant; #endif // __has_include #endif // GTEST_HAS_ABSL +#ifndef GTEST_INTERNAL_HAS_VARIANT +#define GTEST_INTERNAL_HAS_VARIANT 0 +#endif + #if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \ GTEST_INTERNAL_CPLUSPLUS_LANG < 201703L #define GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL 1 From 7b1ced0682af5fb10e4619457552cd11936c294a Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 3 Mar 2023 15:59:04 -0800 Subject: [PATCH 23/75] Only define GTEST_IS_THREADSAFE to 1, not 0 According to the comments, "Feature-indicating macros", such as GTEST_IS_THREADSAFE should be defined to 1 when supported and otherwise undefined (never 0). PiperOrigin-RevId: 513944266 Change-Id: I0f5c8bed107a5f20e957ec7c70339540ca2fe831 --- googletest/include/gtest/internal/gtest-port.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index ba5e9bc3..b757c7d8 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -790,8 +790,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; !defined(GTEST_OS_WINDOWS_RT)) || \ GTEST_HAS_PTHREAD) #define GTEST_IS_THREADSAFE 1 -#else -#define GTEST_IS_THREADSAFE 0 #endif #endif // GTEST_IS_THREADSAFE From dc10c3b5e55c1101e7759bdb7bf9790cebbf4ad2 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 3 Mar 2023 16:01:13 -0800 Subject: [PATCH 24/75] Use "#ifdef" with public macros This allows compilation with "-Wundef" (#3267). PiperOrigin-RevId: 513944726 Change-Id: I1a3854bb2333d5dec6c0ff91ee1eddd9a766ab91 --- googlemock/test/gmock-matchers-misc_test.cc | 2 +- googlemock/test/gmock-spec-builders_test.cc | 2 +- googletest/include/gtest/gtest-death-test.h | 4 ++-- googletest/include/gtest/gtest.h | 2 +- .../gtest/internal/gtest-death-test-internal.h | 2 +- googletest/include/gtest/internal/gtest-port.h | 16 ++++++++-------- googletest/src/gtest-death-test.cc | 4 ++-- googletest/src/gtest-internal-inl.h | 10 +++++----- googletest/src/gtest-port.cc | 6 +++--- googletest/src/gtest.cc | 12 ++++++------ googletest/test/googletest-death-test-test.cc | 4 ++-- googletest/test/googletest-death-test_ex_test.cc | 2 +- googletest/test/googletest-output-test_.cc | 10 +++++----- googletest/test/googletest-port-test.cc | 10 +++++----- googletest/test/gtest_help_test_.cc | 2 +- googletest/test/gtest_stress_test.cc | 2 +- googletest/test/gtest_unittest.cc | 10 +++++----- 17 files changed, 50 insertions(+), 50 deletions(-) diff --git a/googlemock/test/gmock-matchers-misc_test.cc b/googlemock/test/gmock-matchers-misc_test.cc index c1e4f352..0c7aa499 100644 --- a/googlemock/test/gmock-matchers-misc_test.cc +++ b/googlemock/test/gmock-matchers-misc_test.cc @@ -200,7 +200,7 @@ TEST(IsTrueTest, IsTrueIsFalse) { EXPECT_THAT(nonnull_unique, Not(IsFalse())); } -#if GTEST_HAS_TYPED_TEST +#ifdef GTEST_HAS_TYPED_TEST // Tests ContainerEq with different container types, and // different element types. diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index ad56ead0..d53196b3 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -1088,7 +1088,7 @@ TEST(UnexpectedCallTest, UnsatisfiedPrerequisites) { // Verifies that the failure message contains the two unsatisfied // pre-requisites but not the satisfied one. -#if GTEST_USES_POSIX_RE +#ifdef GTEST_USES_POSIX_RE EXPECT_THAT(r.message(), ContainsRegex( // POSIX RE doesn't understand the (?s) prefix, but has no diff --git a/googletest/include/gtest/gtest-death-test.h b/googletest/include/gtest/gtest-death-test.h index b793528b..08fef8c7 100644 --- a/googletest/include/gtest/gtest-death-test.h +++ b/googletest/include/gtest/gtest-death-test.h @@ -51,7 +51,7 @@ GTEST_DECLARE_string_(death_test_style); namespace testing { -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST namespace internal { @@ -328,7 +328,7 @@ class GTEST_API_ KilledBySignal { // death tests are supported; otherwise they just issue a warning. This is // useful when you are combining death test assertions with normal test // assertions in one test. -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST #define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ EXPECT_DEATH(statement, regex) #define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 2bf64938..c1001d67 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -600,7 +600,7 @@ class GTEST_API_ TestInfo { const TestResult* result() const { return &result_; } private: -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST friend class internal::DefaultDeathTestFactory; #endif // GTEST_HAS_DEATH_TEST friend class Test; diff --git a/googletest/include/gtest/internal/gtest-death-test-internal.h b/googletest/include/gtest/internal/gtest-death-test-internal.h index 21f3d29f..522eed85 100644 --- a/googletest/include/gtest/internal/gtest-death-test-internal.h +++ b/googletest/include/gtest/internal/gtest-death-test-internal.h @@ -57,7 +57,7 @@ const char kDeathTestStyleFlag[] = "death_test_style"; const char kDeathTestUseFork[] = "death_test_use_fork"; const char kInternalRunDeathTestFlag[] = "internal_run_death_test"; -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ /* class A needs to have dll-interface to be used by clients of class B */) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index b757c7d8..29503db0 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -161,10 +161,10 @@ // NOT define them. // // These macros are public so that portable tests can be written. -// Such tests typically surround code using a feature with an #if +// Such tests typically surround code using a feature with an #ifdef // which controls that code. For example: // -// #if GTEST_HAS_DEATH_TEST +// #ifdef GTEST_HAS_DEATH_TEST // EXPECT_DEATH(DoSomethingDeadly()); // #endif // @@ -794,7 +794,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #endif // GTEST_IS_THREADSAFE -#if GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE // Some platforms don't support including these threading related headers. #include // NOLINT #include // NOLINT @@ -909,7 +909,7 @@ GTEST_API_ bool IsTrue(bool condition); // Defines RE. -#if GTEST_USES_RE2 +#ifdef GTEST_USES_RE2 // This is almost `using RE = ::RE2`, except it is copy-constructible, and it // needs to disambiguate the `std::string`, `absl::string_view`, and `const @@ -934,7 +934,7 @@ class GTEST_API_ RE { RE2 regex_; }; -#elif GTEST_USES_POSIX_RE || GTEST_USES_SIMPLE_RE +#elif defined(GTEST_USES_POSIX_RE) || defined(GTEST_USES_SIMPLE_RE) // A simple C++ wrapper for . It uses the POSIX Extended // Regular Expression syntax. @@ -972,7 +972,7 @@ class GTEST_API_ RE { std::string pattern_; bool is_valid_; -#if GTEST_USES_POSIX_RE +#ifdef GTEST_USES_POSIX_RE regex_t full_regex_; // For FullMatch(). regex_t partial_regex_; // For PartialMatch(). @@ -1200,7 +1200,7 @@ GTEST_API_ std::string ReadEntireFile(FILE* file); // All command line arguments. GTEST_API_ std::vector GetArgvs(); -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST std::vector GetInjectableArgvs(); // Deprecated: pass the args vector by value instead. @@ -1211,7 +1211,7 @@ void ClearInjectableArgvs(); #endif // GTEST_HAS_DEATH_TEST // Defines synchronization primitives. -#if GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE #ifdef GTEST_OS_WINDOWS // Provides leak-safe Windows kernel handle ownership. diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index f91eba22..649b17b5 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -40,7 +40,7 @@ #include "gtest/internal/custom/gtest.h" #include "gtest/internal/gtest-port.h" -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST #ifdef GTEST_OS_MAC #include @@ -133,7 +133,7 @@ GTEST_DEFINE_string_( namespace testing { -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST namespace internal { diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index 036c3415..007e0498 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -672,7 +672,7 @@ class GTEST_API_ UnitTestImpl { void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc, internal::TearDownTestSuiteFunc tear_down_tc, TestInfo* test_info) { -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST // In order to support thread-safe death tests, we need to // remember the original working directory when the test program // was first invoked. We cannot do this in RUN_ALL_TESTS(), as @@ -778,7 +778,7 @@ class GTEST_API_ UnitTestImpl { return gtest_trace_stack_.get(); } -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST void InitDeathTestSubprocessControlInfo() { internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag()); } @@ -943,7 +943,7 @@ class GTEST_API_ UnitTestImpl { // How long the test took to run, in milliseconds. TimeInMillis elapsed_time_; -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST // The decomposed components of the gtest_internal_run_death_test flag, // parsed when RUN_ALL_TESTS is called. std::unique_ptr internal_run_death_test_flag_; @@ -967,7 +967,7 @@ inline UnitTestImpl* GetUnitTestImpl() { return UnitTest::GetInstance()->impl(); } -#if GTEST_USES_SIMPLE_RE +#ifdef GTEST_USES_SIMPLE_RE // Internal helper functions for implementing the simple regular // expression matcher. @@ -993,7 +993,7 @@ GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str); GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv); GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv); -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST // Returns the message describing the last system error, regardless of the // platform. diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index da4d12d8..994fabd4 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -657,7 +657,7 @@ void ThreadLocalRegistry::OnThreadLocalDestroyed( #endif // GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS -#if GTEST_USES_POSIX_RE +#ifdef GTEST_USES_POSIX_RE // Implements RE. Currently only needed for death tests. @@ -719,7 +719,7 @@ void RE::Init(const char* regex) { delete[] full_pattern; } -#elif GTEST_USES_SIMPLE_RE +#elif defined(GTEST_USES_SIMPLE_RE) // Returns true if and only if ch appears anywhere in str (excluding the // terminating '\0' character). @@ -1221,7 +1221,7 @@ std::string ReadEntireFile(FILE* file) { return content; } -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST static const std::vector* g_injected_test_argvs = nullptr; // Owned. diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 88bbcd20..7ffbf418 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -5018,7 +5018,7 @@ void OsStackTraceGetter::UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_) { #endif // GTEST_HAS_ABSL } -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST // A helper class that creates the premature-exit file in its // constructor and deletes the file in its destructor. class ScopedPrematureExitFile { @@ -5383,7 +5383,7 @@ void UnitTest::RecordProperty(const std::string& key, // We don't protect this under mutex_, as we only support calling it // from the main thread. int UnitTest::Run() { -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST const bool in_death_test_child_process = GTEST_FLAG_GET(internal_run_death_test).length() > 0; @@ -5560,7 +5560,7 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent) random_(0), // Will be reseeded before first use. start_timestamp_(0), elapsed_time_(0), -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST death_test_factory_(new DefaultDeathTestFactory), #endif // Will be overridden by the flag before first use. @@ -5600,7 +5600,7 @@ void UnitTestImpl::RecordProperty(const TestProperty& test_property) { test_result->RecordProperty(xml_element, test_property); } -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST // Disables event forwarding if the control is currently in a death test // subprocess. Must not be called before InitGoogleTest. void UnitTestImpl::SuppressTestEventsIfInSubprocess() { @@ -5663,7 +5663,7 @@ void UnitTestImpl::PostFlagParsingInit() { listeners()->Append(new GTEST_CUSTOM_TEST_EVENT_LISTENER_()); #endif // defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_) -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST InitDeathTestSubprocessControlInfo(); SuppressTestEventsIfInSubprocess(); #endif // GTEST_HAS_DEATH_TEST @@ -5801,7 +5801,7 @@ bool UnitTestImpl::RunAllTests() { // death test. bool in_subprocess_for_death_test = false; -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST in_subprocess_for_death_test = (internal_run_death_test_flag_.get() != nullptr); #if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_) diff --git a/googletest/test/googletest-death-test-test.cc b/googletest/test/googletest-death-test-test.cc index a361a574..3579ce88 100644 --- a/googletest/test/googletest-death-test-test.cc +++ b/googletest/test/googletest-death-test-test.cc @@ -37,7 +37,7 @@ using testing::internal::AlwaysFalse; using testing::internal::AlwaysTrue; -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST #ifdef GTEST_OS_WINDOWS #include // For chdir(). @@ -1353,7 +1353,7 @@ void DieWithMessage(const char* message) { TEST(MatcherDeathTest, DoesNotBreakBareRegexMatching) { // googletest tests this, of course; here we ensure that including googlemock // has not broken it. -#if GTEST_USES_POSIX_RE +#ifdef GTEST_USES_POSIX_RE EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I d[aeiou]e"); #else EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I di?e"); diff --git a/googletest/test/googletest-death-test_ex_test.cc b/googletest/test/googletest-death-test_ex_test.cc index f2515e37..34d55013 100644 --- a/googletest/test/googletest-death-test_ex_test.cc +++ b/googletest/test/googletest-death-test_ex_test.cc @@ -33,7 +33,7 @@ #include "gtest/gtest-death-test.h" #include "gtest/gtest.h" -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST #if GTEST_HAS_SEH #include // For RaiseException(). diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc index 090fb070..1a496ac8 100644 --- a/googletest/test/googletest-output-test_.cc +++ b/googletest/test/googletest-output-test_.cc @@ -41,7 +41,7 @@ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127 /* conditional expression is constant */) -#if GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE using testing::ScopedFakeTestPartResultReporter; using testing::TestPartResultArray; @@ -247,7 +247,7 @@ TEST(SCOPED_TRACETest, CanBeRepeated) { << "contain trace point A, B, and D."; } -#if GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE // Tests that SCOPED_TRACE()s can be used concurrently from multiple // threads. Namely, an assertion should be affected by // SCOPED_TRACE()s in its own thread only. @@ -773,7 +773,7 @@ REGISTER_TYPED_TEST_SUITE_P(DetectNotInstantiatedTypesTest, Used); // typedef ::testing::Types MyTypes; // INSTANTIATE_TYPED_TEST_SUITE_P(All, DetectNotInstantiatedTypesTest, MyTypes); -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST // We rely on the golden file to verify that tests whose test case // name ends with DeathTest are run first. @@ -851,7 +851,7 @@ TEST_F(ExpectFailureTest, ExpectNonFatalFailure) { "failure."); } -#if GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE class ExpectFailureWithThreadsTest : public ExpectFailureTest { protected: @@ -1024,7 +1024,7 @@ int main(int argc, char** argv) { std::count(argv, argv + argc, std::string("internal_skip_environment_and_ad_hoc_tests")) > 0; -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST if (GTEST_FLAG_GET(internal_run_death_test) != "") { // Skip the usual output capturing if we're running as the child // process of an threadsafe-style death test. diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index a93572a9..f3ebda9f 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -361,7 +361,7 @@ TEST(GtestCheckDeathTest, DiesWithCorrectOutputOnFailure) { const char regex[] = #ifdef _MSC_VER "googletest-port-test\\.cc\\(\\d+\\):" -#elif GTEST_USES_POSIX_RE +#elif defined(GTEST_USES_POSIX_RE) "googletest-port-test\\.cc:[0-9]+" #else "googletest-port-test\\.cc:\\d+" @@ -372,7 +372,7 @@ TEST(GtestCheckDeathTest, DiesWithCorrectOutputOnFailure) { regex); } -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST TEST(GtestCheckDeathTest, LivesSilentlyOnSuccess) { EXPECT_EXIT( @@ -399,7 +399,7 @@ TEST(RegexEngineSelectionTest, SelectsCorrectRegexEngine) { #endif } -#if GTEST_USES_POSIX_RE +#ifdef GTEST_USES_POSIX_RE template class RETest : public ::testing::Test {}; @@ -456,7 +456,7 @@ TYPED_TEST(RETest, PartialMatchWorks) { EXPECT_FALSE(RE::PartialMatch(TypeParam("zza"), re)); } -#elif GTEST_USES_SIMPLE_RE +#elif defined(GTEST_USES_SIMPLE_RE) TEST(IsInSetTest, NulCharIsNotInAnySet) { EXPECT_FALSE(IsInSet('\0', "")); @@ -1011,7 +1011,7 @@ TEST(ThreadLocalTest, PointerAndConstPointerReturnSameValue) { EXPECT_EQ(thread_local_string.pointer(), const_thread_local_string.pointer()); } -#if GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE void AddTwo(int* param) { *param += 2; } diff --git a/googletest/test/gtest_help_test_.cc b/googletest/test/gtest_help_test_.cc index da289f05..18b5f3cd 100644 --- a/googletest/test/gtest_help_test_.cc +++ b/googletest/test/gtest_help_test_.cc @@ -39,6 +39,6 @@ TEST(HelpFlagTest, ShouldNotBeRun) { ASSERT_TRUE(false) << "Tests shouldn't be run when --help is specified."; } -#if GTEST_HAS_DEATH_TEST +#ifdef GTEST_HAS_DEATH_TEST TEST(DeathTest, UsedByPythonScriptToDetectSupportForDeathTestsInThisBinary) {} #endif diff --git a/googletest/test/gtest_stress_test.cc b/googletest/test/gtest_stress_test.cc index 24b173ff..af9733ad 100644 --- a/googletest/test/gtest_stress_test.cc +++ b/googletest/test/gtest_stress_test.cc @@ -35,7 +35,7 @@ #include "gtest/gtest.h" #include "src/gtest-internal-inl.h" -#if GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE namespace testing { namespace { diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 461297ab..2f137d24 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -270,7 +270,7 @@ using testing::internal::CaptureStdout; using testing::internal::GetCapturedStdout; #endif -#if GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE using testing::internal::ThreadWithParam; #endif @@ -1189,7 +1189,7 @@ TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) { EXPECT_EQ(1, results.size()); } -#if GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE class ScopedFakeTestPartResultReporterWithThreadsTest : public ScopedFakeTestPartResultReporterTest { @@ -1347,7 +1347,7 @@ TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) { ""); } -#if GTEST_IS_THREADSAFE +#ifdef GTEST_IS_THREADSAFE typedef ScopedFakeTestPartResultReporterWithThreadsTest ExpectFailureWithThreadsTest; @@ -6178,7 +6178,7 @@ TEST_F(ParseFlagsTest, FilterBad) { const char* argv2[] = {"foo.exe", "--gtest_filter", nullptr}; -#if GTEST_HAS_ABSL && GTEST_HAS_DEATH_TEST +#if GTEST_HAS_ABSL && defined(GTEST_HAS_DEATH_TEST) // Invalid flag arguments are a fatal error when using the Abseil Flags. EXPECT_EXIT(GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter(""), true), testing::ExitedWithCode(1), @@ -6197,7 +6197,7 @@ TEST_F(ParseFlagsTest, OutputEmpty) { const char* argv2[] = {"foo.exe", "--gtest_output", nullptr}; -#if GTEST_HAS_ABSL && GTEST_HAS_DEATH_TEST +#if GTEST_HAS_ABSL && defined(GTEST_HAS_DEATH_TEST) // Invalid flag arguments are a fatal error when using the Abseil Flags. EXPECT_EXIT(GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), true), testing::ExitedWithCode(1), From 16feffa8fa7cb6e061787ce345c16eb24326d2ce Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 3 Mar 2023 16:03:22 -0800 Subject: [PATCH 25/75] Replace "#if GTEST_HAS_ABSL" with "#ifdef GTEST_HAS_ABSL" This allows compilation with "-Wundef" (#3267). PiperOrigin-RevId: 513945230 Change-Id: I45ef19c7ff3d20e97216bd031d406a03365471da --- googletest/include/gtest/gtest-printers.h | 2 +- googletest/include/gtest/internal/gtest-port.h | 15 ++++++++------- googletest/src/gtest-internal-inl.h | 2 +- googletest/src/gtest.cc | 12 ++++++------ googletest/test/googletest-port-test.cc | 2 +- googletest/test/gtest_unittest.cc | 10 +++++----- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 739d5452..b2d7b0a3 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -857,7 +857,7 @@ class UniversalPrinter> { public: static void Print(const Variant& value, ::std::ostream* os) { *os << '('; -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL absl::visit(Visitor{os, value.index()}, value); #else std::visit(Visitor{os, value.index()}, value); diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 29503db0..9a35de0f 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -178,6 +178,7 @@ // define themselves. // GTEST_USES_SIMPLE_RE - our own simple regex is used; // the above RE\b(s) are mutually exclusive. +// GTEST_HAS_ABSL - Google Test is compiled with Abseil. // Misc public macros // ------------------ @@ -304,7 +305,7 @@ #include "gtest/internal/custom/gtest-port.h" #include "gtest/internal/gtest-port-arch.h" -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL #include "absl/flags/declare.h" #include "absl/flags/flag.h" #include "absl/flags/reflection.h" @@ -412,7 +413,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #endif // Select the regular expression implementation. -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL // When using Abseil, RE2 is required. #include "absl/strings/string_view.h" #include "re2/re2.h" @@ -2248,7 +2249,7 @@ using TimeInMillis = int64_t; // Represents time in milliseconds. #endif // !defined(GTEST_FLAG) // Pick a command line flags implementation. -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL // Macros for defining flags. #define GTEST_DEFINE_bool_(name, default_val, doc) \ @@ -2359,7 +2360,7 @@ const char* StringFromGTestEnv(const char* flag, const char* default_val); #endif // !defined(GTEST_INTERNAL_DEPRECATED) -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL // Always use absl::any for UniversalPrinter<> specializations if googletest // is built with absl support. #define GTEST_INTERNAL_HAS_ANY 1 @@ -2392,7 +2393,7 @@ using Any = ::std::any; #define GTEST_INTERNAL_HAS_ANY 0 #endif -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL // Always use absl::optional for UniversalPrinter<> specializations if // googletest is built with absl support. #define GTEST_INTERNAL_HAS_OPTIONAL 1 @@ -2428,7 +2429,7 @@ inline ::std::nullopt_t Nullopt() { return ::std::nullopt; } #define GTEST_INTERNAL_HAS_OPTIONAL 0 #endif -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL // Always use absl::string_view for Matcher<> specializations if googletest // is built with absl support. #define GTEST_INTERNAL_HAS_STRING_VIEW 1 @@ -2460,7 +2461,7 @@ using StringView = ::std::string_view; #define GTEST_INTERNAL_HAS_STRING_VIEW 0 #endif -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL // Always use absl::variant for UniversalPrinter<> specializations if googletest // is built with absl support. #define GTEST_INTERNAL_HAS_VARIANT 1 diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index 007e0498..16841b55 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -442,7 +442,7 @@ class OsStackTraceGetter : public OsStackTraceGetterInterface { void UponLeavingGTest() override; private: -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL Mutex mutex_; // Protects all internal state. // We save the stack frame below the frame that calls user code. diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 7ffbf418..0dd3ebad 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -135,7 +135,7 @@ #endif #endif -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL #include "absl/debugging/failure_signal_handler.h" #include "absl/debugging/stacktrace.h" #include "absl/debugging/symbolize.h" @@ -4958,7 +4958,7 @@ const char* const OsStackTraceGetterInterface::kElidedFramesMarker = std::string OsStackTraceGetter::CurrentStackTrace(int max_depth, int skip_count) GTEST_LOCK_EXCLUDED_(mutex_) { -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL std::string result; if (max_depth <= 0) { @@ -5007,7 +5007,7 @@ std::string OsStackTraceGetter::CurrentStackTrace(int max_depth, int skip_count) } void OsStackTraceGetter::UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_) { -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL void* caller_frame = nullptr; if (absl::GetStackTrace(&caller_frame, 1, 3) <= 0) { caller_frame = nullptr; @@ -5686,7 +5686,7 @@ void UnitTestImpl::PostFlagParsingInit() { ConfigureStreamingOutput(); #endif // GTEST_CAN_STREAM_RESULTS_ -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL if (GTEST_FLAG_GET(install_failure_signal_handler)) { absl::FailureSignalHandlerOptions options; absl::InstallFailureSignalHandler(options); @@ -6668,7 +6668,7 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) { // Parses the command line for Google Test flags, without initializing // other parts of Google Test. void ParseGoogleTestFlagsOnly(int* argc, char** argv) { -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL if (*argc > 0) { // absl::ParseCommandLine() requires *argc > 0. auto positional_args = absl::flags_internal::ParseCommandLineImpl( @@ -6720,7 +6720,7 @@ void InitGoogleTestImpl(int* argc, CharType** argv) { g_argvs.push_back(StreamableToString(argv[i])); } -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL absl::InitializeSymbolizer(g_argvs[0].c_str()); // When using the Abseil Flags library, set the program usage message to the diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index f3ebda9f..d01ccaae 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -390,7 +390,7 @@ TEST(GtestCheckDeathTest, LivesSilentlyOnSuccess) { // the platform. The test will produce compiler errors in case of failure. // For simplicity, we only cover the most important platforms here. TEST(RegexEngineSelectionTest, SelectsCorrectRegexEngine) { -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL EXPECT_TRUE(GTEST_USES_RE2); #elif GTEST_HAS_POSIX_RE EXPECT_TRUE(GTEST_USES_POSIX_RE); diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 2f137d24..aea8e1f2 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -6178,12 +6178,12 @@ TEST_F(ParseFlagsTest, FilterBad) { const char* argv2[] = {"foo.exe", "--gtest_filter", nullptr}; -#if GTEST_HAS_ABSL && defined(GTEST_HAS_DEATH_TEST) +#if defined(GTEST_HAS_ABSL) && defined(GTEST_HAS_DEATH_TEST) // Invalid flag arguments are a fatal error when using the Abseil Flags. EXPECT_EXIT(GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter(""), true), testing::ExitedWithCode(1), "ERROR: Missing the value for the flag 'gtest_filter'"); -#elif !GTEST_HAS_ABSL +#elif !defined(GTEST_HAS_ABSL) GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter(""), true); #else static_cast(argv); @@ -6197,12 +6197,12 @@ TEST_F(ParseFlagsTest, OutputEmpty) { const char* argv2[] = {"foo.exe", "--gtest_output", nullptr}; -#if GTEST_HAS_ABSL && defined(GTEST_HAS_DEATH_TEST) +#if defined(GTEST_HAS_ABSL) && defined(GTEST_HAS_DEATH_TEST) // Invalid flag arguments are a fatal error when using the Abseil Flags. EXPECT_EXIT(GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), true), testing::ExitedWithCode(1), "ERROR: Missing the value for the flag 'gtest_output'"); -#elif !GTEST_HAS_ABSL +#elif !defined(GTEST_HAS_ABSL) GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), true); #else static_cast(argv); @@ -6210,7 +6210,7 @@ TEST_F(ParseFlagsTest, OutputEmpty) { #endif } -#if GTEST_HAS_ABSL +#ifdef GTEST_HAS_ABSL TEST_F(ParseFlagsTest, AbseilPositionalFlags) { const char* argv[] = {"foo.exe", "--gtest_throw_on_failure=1", "--", "--other_flag", nullptr}; From 0bdd45085ab7e81dc7fc9dc3ac9bb20110be3db7 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 3 Mar 2023 16:05:40 -0800 Subject: [PATCH 26/75] Remove GTEST_FOR_GOOGLE_ macro The "more details" warning message printed by this macro is no longer needed. PiperOrigin-RevId: 513945729 Change-Id: I644910216dbef2fe92eee3a648f2078e705cc7a1 --- googletest/src/gtest.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 0dd3ebad..55f8e507 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -5966,10 +5966,6 @@ bool UnitTestImpl::RunAllTests() { "() before calling RUN_ALL_TESTS(). This is INVALID. Soon " GTEST_NAME_ " will start to enforce the valid usage. " "Please fix it ASAP, or IT WILL START TO FAIL.\n"); // NOLINT -#if GTEST_FOR_GOOGLE_ - ColoredPrintf(GTestColor::kRed, - "For more details, see http://wiki/Main/ValidGUnitMain.\n"); -#endif // GTEST_FOR_GOOGLE_ } return !failed; From 2ddba266914d6437c313d36f73a4be3a6172e638 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 3 Mar 2023 16:07:40 -0800 Subject: [PATCH 27/75] Always specify definitions for internal macros These macros should only be used within googletest, so changing them will not affect external users. This allows compiling with -Wundef (#3267). PiperOrigin-RevId: 513946162 Change-Id: I2f2b7df9123adeba4147593b2b55fde349ccce4f --- .../include/gtest/internal/gtest-port.h | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 9a35de0f..ba90620e 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -214,6 +214,14 @@ // GTEST_INTERNAL_HAS_VARIANT - for enabling UniversalPrinter or // UniversalPrinter // specializations. Always defined to 0 or 1. +// GTEST_USE_OWN_FLAGFILE_FLAG_ - Always defined to 0 or 1. +// GTEST_HAS_CXXABI_H_ - Always defined to 0 or 1. +// GTEST_CAN_STREAM_RESULTS_ - Always defined to 0 or 1. +// GTEST_HAS_ALT_PATH_SEP_ - Always defined to 0 or 1. +// GTEST_WIDE_STRING_USES_UTF16_ - Always defined to 0 or 1. +// GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ - Always defined to 0 or 1. +// GTEST_HAS_DOWNCAST_ - Always defined to 0 or 1. +// GTEST_HAS_NOTIFICATION_- Always defined to 0 or 1. // // Synchronization: // Mutex, MutexLock, ThreadLocal, GetThreadCount() @@ -305,6 +313,18 @@ #include "gtest/internal/custom/gtest-port.h" #include "gtest/internal/gtest-port-arch.h" +#ifndef GTEST_HAS_DOWNCAST_ +#define GTEST_HAS_DOWNCAST_ 0 +#endif + +#ifndef GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ +#define GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ 0 +#endif + +#ifndef GTEST_HAS_NOTIFICATION_ +#define GTEST_HAS_NOTIFICATION_ 0 +#endif + #ifdef GTEST_HAS_ABSL #include "absl/flags/declare.h" #include "absl/flags/flag.h" From d92a270d2d9d6bb7ed3bf7dc3f698028550a65ef Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 3 Mar 2023 16:09:49 -0800 Subject: [PATCH 28/75] Fix compilation with -Wundef. Fixes #3267 PiperOrigin-RevId: 513946600 Change-Id: I0dd1daa04aeb735a238c4c0af6676565d64cbc21 --- googletest/cmake/internal_utils.cmake | 4 +-- googletest/include/gtest/gtest.h | 28 +++++++++---------- .../include/gtest/internal/gtest-port.h | 10 +++++-- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 0438bef8..b09da33f 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -91,13 +91,13 @@ macro(config_compiler_and_linker) set(cxx_base_flags "${cxx_base_flags} -utf-8") endif() elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(cxx_base_flags "-Wall -Wshadow -Wconversion") + set(cxx_base_flags "-Wall -Wshadow -Wconversion -Wundef") set(cxx_exception_flags "-fexceptions") set(cxx_no_exception_flags "-fno-exceptions") set(cxx_strict_flags "-W -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wredundant-decls") set(cxx_no_rtti_flags "-fno-rtti") elseif (CMAKE_COMPILER_IS_GNUCXX) - set(cxx_base_flags "-Wall -Wshadow") + set(cxx_base_flags "-Wall -Wshadow -Wundef") if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0) set(cxx_base_flags "${cxx_base_flags} -Wno-error=dangling-else") endif() diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index c1001d67..04a84f32 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -1747,7 +1747,7 @@ class TestWithParam : public Test, public WithParamInterface {}; // Define this macro to 1 to omit the definition of FAIL(), which is a // generic name and clashes with some other libraries. -#if !GTEST_DONT_DEFINE_FAIL +#if !(defined(GTEST_DONT_DEFINE_FAIL) && GTEST_DONT_DEFINE_FAIL) #define FAIL() GTEST_FAIL() #endif @@ -1756,7 +1756,7 @@ class TestWithParam : public Test, public WithParamInterface {}; // Define this macro to 1 to omit the definition of SUCCEED(), which // is a generic name and clashes with some other libraries. -#if !GTEST_DONT_DEFINE_SUCCEED +#if !(defined(GTEST_DONT_DEFINE_SUCCEED) && GTEST_DONT_DEFINE_SUCCEED) #define SUCCEED() GTEST_SUCCEED() #endif @@ -1800,19 +1800,19 @@ class TestWithParam : public Test, public WithParamInterface {}; // Define these macros to 1 to omit the definition of the corresponding // EXPECT or ASSERT, which clashes with some users' own code. -#if !GTEST_DONT_DEFINE_EXPECT_TRUE +#if !(defined(GTEST_DONT_DEFINE_EXPECT_TRUE) && GTEST_DONT_DEFINE_EXPECT_TRUE) #define EXPECT_TRUE(condition) GTEST_EXPECT_TRUE(condition) #endif -#if !GTEST_DONT_DEFINE_EXPECT_FALSE +#if !(defined(GTEST_DONT_DEFINE_EXPECT_FALSE) && GTEST_DONT_DEFINE_EXPECT_FALSE) #define EXPECT_FALSE(condition) GTEST_EXPECT_FALSE(condition) #endif -#if !GTEST_DONT_DEFINE_ASSERT_TRUE +#if !(defined(GTEST_DONT_DEFINE_ASSERT_TRUE) && GTEST_DONT_DEFINE_ASSERT_TRUE) #define ASSERT_TRUE(condition) GTEST_ASSERT_TRUE(condition) #endif -#if !GTEST_DONT_DEFINE_ASSERT_FALSE +#if !(defined(GTEST_DONT_DEFINE_ASSERT_FALSE) && GTEST_DONT_DEFINE_ASSERT_FALSE) #define ASSERT_FALSE(condition) GTEST_ASSERT_FALSE(condition) #endif @@ -1891,27 +1891,27 @@ class TestWithParam : public Test, public WithParamInterface {}; // Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of // ASSERT_XY(), which clashes with some users' own code. -#if !GTEST_DONT_DEFINE_ASSERT_EQ +#if !(defined(GTEST_DONT_DEFINE_ASSERT_EQ) && GTEST_DONT_DEFINE_ASSERT_EQ) #define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2) #endif -#if !GTEST_DONT_DEFINE_ASSERT_NE +#if !(defined(GTEST_DONT_DEFINE_ASSERT_NE) && GTEST_DONT_DEFINE_ASSERT_NE) #define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2) #endif -#if !GTEST_DONT_DEFINE_ASSERT_LE +#if !(defined(GTEST_DONT_DEFINE_ASSERT_LE) && GTEST_DONT_DEFINE_ASSERT_LE) #define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2) #endif -#if !GTEST_DONT_DEFINE_ASSERT_LT +#if !(defined(GTEST_DONT_DEFINE_ASSERT_LT) && GTEST_DONT_DEFINE_ASSERT_LT) #define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2) #endif -#if !GTEST_DONT_DEFINE_ASSERT_GE +#if !(defined(GTEST_DONT_DEFINE_ASSERT_GE) && GTEST_DONT_DEFINE_ASSERT_GE) #define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2) #endif -#if !GTEST_DONT_DEFINE_ASSERT_GT +#if !(defined(GTEST_DONT_DEFINE_ASSERT_GT) && GTEST_DONT_DEFINE_ASSERT_GT) #define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2) #endif @@ -2169,7 +2169,7 @@ constexpr bool StaticAssertTypeEq() noexcept { // Define this macro to 1 to omit the definition of TEST(), which // is a generic name and clashes with some other libraries. -#if !GTEST_DONT_DEFINE_TEST +#if !(defined(GTEST_DONT_DEFINE_TEST) && GTEST_DONT_DEFINE_TEST) #define TEST(test_suite_name, test_name) GTEST_TEST(test_suite_name, test_name) #endif @@ -2201,7 +2201,7 @@ constexpr bool StaticAssertTypeEq() noexcept { #define GTEST_TEST_F(test_fixture, test_name) \ GTEST_TEST_(test_fixture, test_name, test_fixture, \ ::testing::internal::GetTypeId()) -#if !GTEST_DONT_DEFINE_TEST_F +#if !(defined(GTEST_DONT_DEFINE_TEST_F) && GTEST_DONT_DEFINE_TEST_F) #define TEST_F(test_fixture, test_name) GTEST_TEST_F(test_fixture, test_name) #endif diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index ba90620e..72533605 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -469,8 +469,12 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // cleanups prior to that. To reliably check for C++ exception availability with // clang, check for // __EXCEPTIONS && __has_feature(cxx_exceptions). -#define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions)) -#elif defined(__GNUC__) && __EXCEPTIONS +#if defined(__EXCEPTIONS) && __EXCEPTIONS && __has_feature(cxx_exceptions) +#define GTEST_HAS_EXCEPTIONS 1 +#else +#define GTEST_HAS_EXCEPTIONS 0 +#endif +#elif defined(__GNUC__) && defined(__EXCEPTIONS) && __EXCEPTIONS // gcc defines __EXCEPTIONS to 1 if and only if exceptions are enabled. #define GTEST_HAS_EXCEPTIONS 1 #elif defined(__SUNPRO_CC) @@ -478,7 +482,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // detecting whether they are enabled or not. Therefore, we assume that // they are enabled unless the user tells us otherwise. #define GTEST_HAS_EXCEPTIONS 1 -#elif defined(__IBMCPP__) && __EXCEPTIONS +#elif defined(__IBMCPP__) && defined(__EXCEPTIONS) && __EXCEPTIONS // xlC defines __EXCEPTIONS to 1 if and only if exceptions are enabled. #define GTEST_HAS_EXCEPTIONS 1 #elif defined(__HP_aCC) From e1ee0fa3e121e819c7a76d4d3b417de8f73ebfd7 Mon Sep 17 00:00:00 2001 From: Dino Radakovic Date: Mon, 6 Mar 2023 09:03:15 -0800 Subject: [PATCH 29/75] Fix indentation syntax error in feature request issue template Fixes #4166 PiperOrigin-RevId: 514427586 Change-Id: I947b2a0f3687430f27e37fcd2b3fff8b1cb0b16e --- .github/ISSUE_TEMPLATE/10-feature_request.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/10-feature_request.yml b/.github/ISSUE_TEMPLATE/10-feature_request.yml index 91ad0417..f3bbc091 100644 --- a/.github/ISSUE_TEMPLATE/10-feature_request.yml +++ b/.github/ISSUE_TEMPLATE/10-feature_request.yml @@ -10,21 +10,21 @@ body: description: We recommend using the latest commit from GitHub in your projects. validations: required: true - - type: textarea + - type: textarea id: why attributes: label: Why do we need this feature? description: Ideally, explain why a combination of existing features cannot be used instead. validations: required: true - - type: textarea + - type: textarea id: proposal attributes: label: Describe the proposal. description: Include a detailed description of the feature, with usage examples. validations: required: true - - type: textarea + - type: textarea id: platform attributes: label: Is the feature specific to an operating system, compiler, or build system version? From 92f0d72507801f2d47533bfb2ad8960d93ed0224 Mon Sep 17 00:00:00 2001 From: Alexander Nikforov Date: Mon, 6 Mar 2023 16:34:55 -0800 Subject: [PATCH 30/75] __cpp_char8_t does not cover std::u8string implementation, but __cpp_lib_char8_t does --- googletest/include/gtest/gtest-printers.h | 2 +- googletest/src/gtest-printers.cc | 2 +- googletest/test/googletest-printers-test.cc | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 739d5452..09f7316f 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -1003,7 +1003,7 @@ template <> class UniversalTersePrinter : public UniversalTersePrinter { }; -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t template <> class UniversalTersePrinter { public: diff --git a/googletest/src/gtest-printers.cc b/googletest/src/gtest-printers.cc index d475ad36..de740e7d 100644 --- a/googletest/src/gtest-printers.cc +++ b/googletest/src/gtest-printers.cc @@ -528,7 +528,7 @@ void PrintStringTo(const ::std::string& s, ostream* os) { } } -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t void PrintU8StringTo(const ::std::u8string& s, ostream* os) { PrintCharsAsStringTo(s.data(), s.size(), os); } diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index 34aa9245..23c30f11 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -532,7 +532,9 @@ TEST(PrintU8StringTest, NonConst) { EXPECT_EQ(PrintPointer(p) + " pointing to u8\"\\xE4\\xB8\\x96\"", Print(static_cast(p))); } +#endif +#ifdef __cpp_lib_char8_t // NULL u8 string. TEST(PrintU8StringTest, Null) { const char8_t* p = nullptr; @@ -936,7 +938,7 @@ TEST(PrintWideStringTest, StringAmbiguousHex) { } #endif // GTEST_HAS_STD_WSTRING -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t TEST(PrintStringTest, U8String) { std::u8string str = u8"Hello, 世界"; EXPECT_EQ(str, str); // Verify EXPECT_EQ compiles with this type. From 1a727c27aa36c602b24bf170a301aec8686b88e8 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 7 Mar 2023 03:05:23 -0800 Subject: [PATCH 31/75] Internal Code Change PiperOrigin-RevId: 514678702 Change-Id: I5b0089d905152ccb85022be395ed340e42586234 --- googlemock/include/gmock/internal/gmock-internal-utils.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index afbdce03..b5283ed0 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -311,7 +311,8 @@ GTEST_API_ WithoutMatchers GetWithoutMatchers(); // crashes). template inline T Invalid() { - Assert(false, "", -1, "Internal error: attempt to return invalid value"); + Assert(/*condition=*/false, /*file=*/"", /*line=*/-1, + "Internal error: attempt to return invalid value"); #if defined(__GNUC__) || defined(__clang__) __builtin_unreachable(); #elif defined(_MSC_VER) From cf4f4400db41a70b87df127aee20fe802dae5520 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 7 Mar 2023 10:39:52 -0800 Subject: [PATCH 32/75] Suppress std::string DLL interface warning introduced in commit f063cd25c90cbd4089a0ff96f5991df4f2721338 Fixes #4171 PiperOrigin-RevId: 514777144 Change-Id: I6f4b309c407684522fc1bc94dcc980ea1fe09cd9 --- googletest/include/gtest/internal/gtest-port.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 72533605..0160fadc 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -960,6 +960,8 @@ class GTEST_API_ RE { }; #elif defined(GTEST_USES_POSIX_RE) || defined(GTEST_USES_SIMPLE_RE) +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ +/* class A needs to have dll-interface to be used by clients of class B */) // A simple C++ wrapper for . It uses the POSIX Extended // Regular Expression syntax. @@ -1008,7 +1010,7 @@ class GTEST_API_ RE { #endif }; - +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 #endif // ::testing::internal::RE implementation // Formats a source file path and a line number as they would appear From 678c1c73de2cf004d58f5dbbef299083997d924a Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 7 Mar 2023 15:34:10 -0800 Subject: [PATCH 33/75] Fix compilation of googletest-printers-test.cc when using -Wundef #3267 PiperOrigin-RevId: 514858420 Change-Id: Ic712aafad25f5e63ae48f647557de95cef890978 --- googletest/test/googletest-printers-test.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index fa8b084d..5fdc0867 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -1796,7 +1796,8 @@ TEST(UniversalPrintTest, SmartPointers) { std::shared_ptr p3(new int(1979)); EXPECT_EQ("(ptr = " + PrintPointer(p3.get()) + ", value = 1979)", PrintToString(p3)); -#if __cpp_lib_shared_ptr_arrays >= 201611L +#if defined(__cpp_lib_shared_ptr_arrays) && \ + (__cpp_lib_shared_ptr_arrays >= 201611L) std::shared_ptr p4(new int[2]); EXPECT_EQ("(" + PrintPointer(p4.get()) + ")", PrintToString(p4)); #endif @@ -1815,7 +1816,8 @@ TEST(UniversalPrintTest, SmartPointers) { EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr())); EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr())); EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr())); -#if __cpp_lib_shared_ptr_arrays >= 201611L +#if defined(__cpp_lib_shared_ptr_arrays) && \ + (__cpp_lib_shared_ptr_arrays >= 201611L) EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr())); EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr())); EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr())); From a798c2f10200b6293a5cc236b5f41b26c1ae7378 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 7 Mar 2023 15:57:28 -0800 Subject: [PATCH 34/75] Add -Wundef to the CI scripts when building with Bazel The CMake build already adds -Wundef for gcc/clang. This change makes sure that the gcc/clang Bazel builds also compile correctly with -Wundef (#3267). PiperOrigin-RevId: 514864451 Change-Id: I7798a4a4c68d037e23625db24ee29df454367734 --- ci/linux-presubmit.sh | 3 +++ ci/macos-presubmit.sh | 1 + 2 files changed, 4 insertions(+) diff --git a/ci/linux-presubmit.sh b/ci/linux-presubmit.sh index 626989d2..6bac8878 100644 --- a/ci/linux-presubmit.sh +++ b/ci/linux-presubmit.sh @@ -78,6 +78,7 @@ time docker run \ --copt="-Wall" \ --copt="-Werror" \ --copt="-Wuninitialized" \ + --copt="-Wundef" \ --copt="-Wno-error=pragmas" \ --distdir="/bazel-distdir" \ --features=external_include_paths \ @@ -99,6 +100,7 @@ for std in ${STD}; do --copt="-Wall" \ --copt="-Werror" \ --copt="-Wuninitialized" \ + --copt="-Wundef" \ --define="absl=${absl}" \ --distdir="/bazel-distdir" \ --features=external_include_paths \ @@ -123,6 +125,7 @@ for std in ${STD}; do --copt="-Wall" \ --copt="-Werror" \ --copt="-Wuninitialized" \ + --copt="-Wundef" \ --define="absl=${absl}" \ --distdir="/bazel-distdir" \ --features=external_include_paths \ diff --git a/ci/macos-presubmit.sh b/ci/macos-presubmit.sh index 8f35df58..681ebc2a 100644 --- a/ci/macos-presubmit.sh +++ b/ci/macos-presubmit.sh @@ -66,6 +66,7 @@ for absl in 0 1; do ${BAZEL_BIN} test ... \ --copt="-Wall" \ --copt="-Werror" \ + --copt="-Wundef" \ --cxxopt="-std=c++14" \ --define="absl=${absl}" \ --features=external_include_paths \ From 82a570453ccd9a9ca8a75b82aa1850b74ce27337 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 7 Mar 2023 22:33:13 -0800 Subject: [PATCH 35/75] Apply clang-tidy fixes PiperOrigin-RevId: 514936218 Change-Id: I24c443a2ca75c875052b0cf2d0a48e808d03ae43 --- googletest/test/googletest-listener-test.cc | 8 +------- googletest/test/googletest-output-test_.cc | 2 +- googletest/test/googletest-param-test-test.cc | 2 +- googletest/test/googletest-printers-test.cc | 1 - googletest/test/googletest-shuffle-test_.cc | 1 - googletest/test/gtest_unittest.cc | 5 ----- 6 files changed, 3 insertions(+), 16 deletions(-) diff --git a/googletest/test/googletest-listener-test.cc b/googletest/test/googletest-listener-test.cc index 89d01b37..654486d7 100644 --- a/googletest/test/googletest-listener-test.cc +++ b/googletest/test/googletest-listener-test.cc @@ -38,13 +38,7 @@ #include "gtest/internal/custom/gtest.h" using ::testing::AddGlobalTestEnvironment; -using ::testing::Environment; using ::testing::InitGoogleTest; -using ::testing::Test; -using ::testing::TestEventListener; -using ::testing::TestInfo; -using ::testing::TestPartResult; -using ::testing::TestSuite; using ::testing::UnitTest; // Used by tests to register their events. @@ -278,7 +272,7 @@ int main(int argc, char** argv) { AddGlobalTestEnvironment(new EnvironmentInvocationCatcher); - GTEST_CHECK_(events.size() == 0) + GTEST_CHECK_(events.empty()) << "AddGlobalTestEnvironment should not generate any events itself."; GTEST_FLAG_SET(repeat, 2); diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc index 1a496ac8..44d0fc13 100644 --- a/googletest/test/googletest-output-test_.cc +++ b/googletest/test/googletest-output-test_.cc @@ -1025,7 +1025,7 @@ int main(int argc, char** argv) { std::string("internal_skip_environment_and_ad_hoc_tests")) > 0; #ifdef GTEST_HAS_DEATH_TEST - if (GTEST_FLAG_GET(internal_run_death_test) != "") { + if (!GTEST_FLAG_GET(internal_run_death_test).empty()) { // Skip the usual output capturing if we're running as the child // process of an threadsafe-style death test. #if defined(GTEST_OS_WINDOWS) diff --git a/googletest/test/googletest-param-test-test.cc b/googletest/test/googletest-param-test-test.cc index 63db2860..c9c5e78e 100644 --- a/googletest/test/googletest-param-test-test.cc +++ b/googletest/test/googletest-param-test-test.cc @@ -221,7 +221,7 @@ class DogAdder { } DogAdder operator+(const DogAdder& other) const { Message msg; - msg << value_.c_str() << other.value_.c_str(); + msg << value_ << other.value_; return DogAdder(msg.GetString().c_str()); } bool operator<(const DogAdder& other) const { return value_ < other.value_; } diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index 5fdc0867..401e0463 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -266,7 +266,6 @@ using ::std::set; using ::std::vector; using ::testing::PrintToString; using ::testing::internal::FormatForComparisonFailureMessage; -using ::testing::internal::ImplicitCast_; using ::testing::internal::NativeArray; using ::testing::internal::RelationToSourceReference; using ::testing::internal::Strings; diff --git a/googletest/test/googletest-shuffle-test_.cc b/googletest/test/googletest-shuffle-test_.cc index a14e22f9..b570c488 100644 --- a/googletest/test/googletest-shuffle-test_.cc +++ b/googletest/test/googletest-shuffle-test_.cc @@ -35,7 +35,6 @@ namespace { using ::testing::EmptyTestEventListener; using ::testing::InitGoogleTest; -using ::testing::Message; using ::testing::Test; using ::testing::TestEventListeners; using ::testing::TestInfo; diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index aea8e1f2..768911ab 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -211,7 +211,6 @@ using testing::TestPartResult; using testing::TestPartResultArray; using testing::TestProperty; using testing::TestResult; -using testing::TestSuite; using testing::TimeInMillis; using testing::UnitTest; using testing::internal::AlwaysFalse; @@ -227,7 +226,6 @@ using testing::internal::FloatingPoint; using testing::internal::ForEach; using testing::internal::FormatEpochTimeInMillisAsIso8601; using testing::internal::FormatTimeInMillisAsSeconds; -using testing::internal::GetCurrentOsStackTraceExceptTop; using testing::internal::GetElementOr; using testing::internal::GetNextRandomSeed; using testing::internal::GetRandomSeedFromFlag; @@ -244,8 +242,6 @@ using testing::internal::IsNotContainer; using testing::internal::kMaxRandomSeed; using testing::internal::kTestTypeIdInGoogleTest; using testing::internal::NativeArray; -using testing::internal::OsStackTraceGetter; -using testing::internal::OsStackTraceGetterInterface; using testing::internal::ParseFlag; using testing::internal::RelationToSourceCopy; using testing::internal::RelationToSourceReference; @@ -259,7 +255,6 @@ using testing::internal::StreamableToString; using testing::internal::String; using testing::internal::TestEventListenersAccessor; using testing::internal::TestResultAccessor; -using testing::internal::UnitTestImpl; using testing::internal::WideStringToUtf8; using testing::internal::edit_distance::CalculateOptimalEdits; using testing::internal::edit_distance::CreateUnifiedDiff; From 48a1b110583dd55e5076952b2acd772d9aaf6372 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 8 Mar 2023 15:09:58 -0800 Subject: [PATCH 36/75] Add a comment to clarify Fuchsia process launcher requirement. PiperOrigin-RevId: 515154129 Change-Id: I3dd9e912e160d09d1f74a467336212701d4e1b7d --- googletest/src/gtest-death-test.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index 649b17b5..1bf2f312 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -1024,6 +1024,11 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() { GTEST_DEATH_TEST_CHECK_(status == ZX_OK); // Spawn the child process. + // Note: The test component must have `fuchsia.process.Launcher` declared + // in its manifest. (Fuchsia integration tests require creating a + // "Fuchsia Test Component" which contains a "Fuchsia Component Manifest") + // Launching processes is a privileged operation in Fuschia, and the + // declaration indicates that the ability is required for the component. std::unique_ptr argv = CreateArgvFromArgs(args); status = fdio_spawn_etc(child_job, FDIO_SPAWN_CLONE_ALL, argv[0], argv.get(), nullptr, 2, spawn_actions, From 50e07d1c92875e66138d5d5ee3bb46ef237115bb Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 9 Mar 2023 01:19:08 -0800 Subject: [PATCH 37/75] Apply clang-tidy fixes PiperOrigin-RevId: 515265927 Change-Id: Iea11668fa4bbf08f6d418a3823e836fb5b874dcc --- googletest/test/googletest-port-test.cc | 4 ++-- googletest/test/gtest_stress_test.cc | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index d01ccaae..1ba3f502 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -1104,9 +1104,9 @@ TEST(MutexTest, OnlyOneThreadCanLockAtATime) { // Creates and runs kThreadCount threads that increment locked_counter // kCycleCount times each. for (int i = 0; i < kThreadCount; ++i) { - counting_threads[i].reset(new ThreadType( + counting_threads[i] = std::make_unique( &CountingThreadFunc, make_pair(&locked_counter, kCycleCount), - &threads_can_start)); + &threads_can_start); } threads_can_start.Notify(); for (int i = 0; i < kThreadCount; ++i) counting_threads[i]->Join(); diff --git a/googletest/test/gtest_stress_test.cc b/googletest/test/gtest_stress_test.cc index af9733ad..0cf21852 100644 --- a/googletest/test/gtest_stress_test.cc +++ b/googletest/test/gtest_stress_test.cc @@ -30,6 +30,7 @@ // Tests that SCOPED_TRACE() and various Google Test assertions can be // used in a large number of threads concurrently. +#include #include #include "gtest/gtest.h" @@ -118,8 +119,8 @@ TEST(StressTest, CanUseScopedTraceAndAssertionsInManyThreads) { std::unique_ptr > threads[kThreadCount]; Notification threads_can_start; for (int i = 0; i != kThreadCount; i++) - threads[i].reset( - new ThreadWithParam(&ManyAsserts, i, &threads_can_start)); + threads[i] = std::make_unique>(&ManyAsserts, i, + &threads_can_start); threads_can_start.Notify(); From 2d3b36d40a04a34edd2d00cdc6e30a20602bb847 Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 2 Mar 2023 15:31:26 -0700 Subject: [PATCH 38/75] Environment variables are accessible in UWP/WinRT apps Environment variables, for example `GTEST_FILTER`, `GTEST_OUTPUT` can be set before getting WinRT app run. GoogleTest can read environment variables and use them. It's easier than setting and passing command line parameters to WinRT app. --- googletest/include/gtest/internal/gtest-port.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 0160fadc..eb78992f 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -2169,8 +2169,8 @@ inline const char* StrError(int errnum) { return strerror(errnum); } inline const char* GetEnv(const char* name) { #if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \ - defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \ - defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT) + defined(GTEST_OS_ESP8266) || defined(GTEST_OS_XTENSA) || \ + defined(GTEST_OS_QURT) // We are on an embedded platform, which has no environment variables. static_cast(name); // To prevent 'unused argument' warning. return nullptr; From 038e392ebd8081c756e180475cc361f711fb438d Mon Sep 17 00:00:00 2001 From: Lawrence Wolf-Sonkin Date: Fri, 10 Mar 2023 14:42:38 -0800 Subject: [PATCH 39/75] [gtest] Drop custom-rolled heterogeneous comparator functors in favor of C++ standard ones * Standard heterogeneous comparator functors such as `std::equal_to<>` and `std::less<>` [have been available since C++14](https://en.cppreference.com/w/cpp/utility/functional/less_void) * Now that [C++14 is the minimum supported version of C++ in Googletest](https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md), let's delete these duplications of the standard library PiperOrigin-RevId: 515743068 Change-Id: I1563a2f94039c3a6688429298555545a922f6d7e --- googlemock/include/gmock/gmock-matchers.h | 13 ++--- googletest/include/gtest/gtest-matchers.h | 65 ++++++----------------- 2 files changed, 23 insertions(+), 55 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index fc00c356..6b264d69 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -257,6 +257,7 @@ #include #include +#include #include #include #include @@ -1199,27 +1200,27 @@ class PairMatchBase { }; }; -class Eq2Matcher : public PairMatchBase { +class Eq2Matcher : public PairMatchBase> { public: static const char* Desc() { return "an equal pair"; } }; -class Ne2Matcher : public PairMatchBase { +class Ne2Matcher : public PairMatchBase> { public: static const char* Desc() { return "an unequal pair"; } }; -class Lt2Matcher : public PairMatchBase { +class Lt2Matcher : public PairMatchBase> { public: static const char* Desc() { return "a pair where the first < the second"; } }; -class Gt2Matcher : public PairMatchBase { +class Gt2Matcher : public PairMatchBase> { public: static const char* Desc() { return "a pair where the first > the second"; } }; -class Le2Matcher : public PairMatchBase { +class Le2Matcher : public PairMatchBase> { public: static const char* Desc() { return "a pair where the first <= the second"; } }; -class Ge2Matcher : public PairMatchBase { +class Ge2Matcher : public PairMatchBase> { public: static const char* Desc() { return "a pair where the first >= the second"; } }; diff --git a/googletest/include/gtest/gtest-matchers.h b/googletest/include/gtest/gtest-matchers.h index 4a60b0d0..d73d8341 100644 --- a/googletest/include/gtest/gtest-matchers.h +++ b/googletest/include/gtest/gtest-matchers.h @@ -40,6 +40,7 @@ #define GOOGLETEST_INCLUDE_GTEST_GTEST_MATCHERS_H_ #include +#include #include #include #include @@ -178,43 +179,6 @@ class MatcherInterface : public MatcherDescriberInterface { namespace internal { -struct AnyEq { - template - bool operator()(const A& a, const B& b) const { - return a == b; - } -}; -struct AnyNe { - template - bool operator()(const A& a, const B& b) const { - return a != b; - } -}; -struct AnyLt { - template - bool operator()(const A& a, const B& b) const { - return a < b; - } -}; -struct AnyGt { - template - bool operator()(const A& a, const B& b) const { - return a > b; - } -}; -struct AnyLe { - template - bool operator()(const A& a, const B& b) const { - return a <= b; - } -}; -struct AnyGe { - template - bool operator()(const A& a, const B& b) const { - return a >= b; - } -}; - // A match result listener that ignores the explanation. class DummyMatchResultListener : public MatchResultListener { public: @@ -758,50 +722,53 @@ class ComparisonBase { }; template -class EqMatcher : public ComparisonBase, Rhs, AnyEq> { +class EqMatcher : public ComparisonBase, Rhs, std::equal_to<>> { public: explicit EqMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyEq>(rhs) {} + : ComparisonBase, Rhs, std::equal_to<>>(rhs) {} static const char* Desc() { return "is equal to"; } static const char* NegatedDesc() { return "isn't equal to"; } }; template -class NeMatcher : public ComparisonBase, Rhs, AnyNe> { +class NeMatcher + : public ComparisonBase, Rhs, std::not_equal_to<>> { public: explicit NeMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyNe>(rhs) {} + : ComparisonBase, Rhs, std::not_equal_to<>>(rhs) {} static const char* Desc() { return "isn't equal to"; } static const char* NegatedDesc() { return "is equal to"; } }; template -class LtMatcher : public ComparisonBase, Rhs, AnyLt> { +class LtMatcher : public ComparisonBase, Rhs, std::less<>> { public: explicit LtMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyLt>(rhs) {} + : ComparisonBase, Rhs, std::less<>>(rhs) {} static const char* Desc() { return "is <"; } static const char* NegatedDesc() { return "isn't <"; } }; template -class GtMatcher : public ComparisonBase, Rhs, AnyGt> { +class GtMatcher : public ComparisonBase, Rhs, std::greater<>> { public: explicit GtMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyGt>(rhs) {} + : ComparisonBase, Rhs, std::greater<>>(rhs) {} static const char* Desc() { return "is >"; } static const char* NegatedDesc() { return "isn't >"; } }; template -class LeMatcher : public ComparisonBase, Rhs, AnyLe> { +class LeMatcher + : public ComparisonBase, Rhs, std::less_equal<>> { public: explicit LeMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyLe>(rhs) {} + : ComparisonBase, Rhs, std::less_equal<>>(rhs) {} static const char* Desc() { return "is <="; } static const char* NegatedDesc() { return "isn't <="; } }; template -class GeMatcher : public ComparisonBase, Rhs, AnyGe> { +class GeMatcher + : public ComparisonBase, Rhs, std::greater_equal<>> { public: explicit GeMatcher(const Rhs& rhs) - : ComparisonBase, Rhs, AnyGe>(rhs) {} + : ComparisonBase, Rhs, std::greater_equal<>>(rhs) {} static const char* Desc() { return "is >="; } static const char* NegatedDesc() { return "isn't >="; } }; From 391ce627def20c1e8a54d10b12949b15086473dd Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Sat, 11 Mar 2023 02:48:04 -0800 Subject: [PATCH 40/75] Internal Code Change PiperOrigin-RevId: 515855852 Change-Id: I8016eefd45c36089e189bbd1ebbe9fdabe68255b --- googlemock/include/gmock/gmock-matchers.h | 1 + 1 file changed, 1 insertion(+) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 6b264d69..a480576d 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -1474,6 +1474,7 @@ class SomeOfArrayMatcher { operator Matcher() const { // NOLINT using RawU = typename std::decay::type; std::vector> matchers; + matchers.reserve(matchers_.size()); for (const auto& matcher : matchers_) { matchers.push_back(MatcherCast(matcher)); } From f53219cdcb7b084ef57414efea92ee5b71989558 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Thu, 16 Mar 2023 10:47:38 -0700 Subject: [PATCH 41/75] Move transitive dependencies of googletest to googletest_deps.bzl to allow other bazel projects to depend on that rule instead of googletests' transitive dependencies directly. PiperOrigin-RevId: 517166391 Change-Id: I9158e24d3f9613f3bcc811c028e1a15f213b7c40 --- WORKSPACE | 19 +++---------------- googletest_deps.bzl | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 16 deletions(-) create mode 100644 googletest_deps.bzl diff --git a/WORKSPACE b/WORKSPACE index cb5f83fa..1c8ea24d 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,23 +1,10 @@ workspace(name = "com_google_googletest") +load("//:googletest_deps.bzl", "googletest_deps") +googletest_deps() + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -http_archive( - name = "com_google_absl", # 2023-02-27T15:50:25Z - sha256 = "baf8e734ac3ce213a889ce7c248b981ee1730e2093e32808e0f0a910dc985f76", - strip_prefix = "abseil-cpp-0c1114c4fb83c844c7fd74708338cca1d3d9b0dc", - urls = ["https://github.com/abseil/abseil-cpp/archive/0c1114c4fb83c844c7fd74708338cca1d3d9b0dc.zip"], -) - -# Note this must use a commit from the `abseil` branch of the RE2 project. -# https://github.com/google/re2/tree/abseil -http_archive( - name = "com_googlesource_code_re2", # 2022-12-21T14:29:10Z - sha256 = "b9ce3a51beebb38534d11d40f8928d40509b9e18a735f6a4a97ad3d014c87cb5", - strip_prefix = "re2-d0b1f8f2ecc2ea74956c7608b6f915175314ff0e", - urls = ["https://github.com/google/re2/archive/d0b1f8f2ecc2ea74956c7608b6f915175314ff0e.zip"], -) - http_archive( name = "rules_python", # 2023-01-10T22:00:51Z sha256 = "5de54486a60ad8948dabe49605bb1c08053e04001a431ab3e96745b4d97a4419", diff --git a/googletest_deps.bzl b/googletest_deps.bzl new file mode 100644 index 00000000..7fe80961 --- /dev/null +++ b/googletest_deps.bzl @@ -0,0 +1,22 @@ +"""Load dependencies needed to use the googletest library as a 3rd-party consumer.""" + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def googletest_deps(): + """Loads common dependencies needed to use the googletest library.""" + + if not native.existing_rule("com_googlesource_code_re2"): + http_archive( + name = "com_googlesource_code_re2", # 2022-12-21T14:29:10Z + sha256 = "b9ce3a51beebb38534d11d40f8928d40509b9e18a735f6a4a97ad3d014c87cb5", + strip_prefix = "re2-d0b1f8f2ecc2ea74956c7608b6f915175314ff0e", + urls = ["https://github.com/google/re2/archive/d0b1f8f2ecc2ea74956c7608b6f915175314ff0e.zip"], + ) + + if not native.existing_rule("com_google_absl"): + http_archive( + name = "com_google_absl", # 2023-02-27T15:50:25Z + sha256 = "baf8e734ac3ce213a889ce7c248b981ee1730e2093e32808e0f0a910dc985f76", + strip_prefix = "abseil-cpp-0c1114c4fb83c844c7fd74708338cca1d3d9b0dc", + urls = ["https://github.com/abseil/abseil-cpp/archive/0c1114c4fb83c844c7fd74708338cca1d3d9b0dc.zip"], + ) From 28219b169c62f110f7b85810b60bfdd4eedea9ef Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Sun, 19 Mar 2023 14:30:14 -0700 Subject: [PATCH 42/75] Fix typo in test case name. PiperOrigin-RevId: 517814929 Change-Id: I2bc498ba048d4deab1cf2a021487f63fe44c466d --- googletest/test/gtest_unittest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 768911ab..bd4fc60a 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -6975,7 +6975,7 @@ TEST(EventListenerTest, SuppressEventForwarding) { // Tests that events generated by Google Test are not forwarded in // death test subprocesses. -TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprecesses) { +TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprocesses) { EXPECT_DEATH_IF_SUPPORTED( { GTEST_CHECK_(TestEventListenersAccessor::EventForwardingEnabled( From 9fd3fb00ff2f94a8b4aad9f757e94bf89f9b8ead Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 20 Mar 2023 02:42:15 -0700 Subject: [PATCH 43/75] Remove unused using-declarations in sample unit tests PiperOrigin-RevId: 517910369 Change-Id: I87f29fb09bc83e7d1c7cffdf267b2f691d261c26 --- googletest/samples/sample10_unittest.cc | 1 - googletest/samples/sample9_unittest.cc | 1 - 2 files changed, 2 deletions(-) diff --git a/googletest/samples/sample10_unittest.cc b/googletest/samples/sample10_unittest.cc index 95b4811b..21079549 100644 --- a/googletest/samples/sample10_unittest.cc +++ b/googletest/samples/sample10_unittest.cc @@ -38,7 +38,6 @@ using ::testing::InitGoogleTest; using ::testing::Test; using ::testing::TestEventListeners; using ::testing::TestInfo; -using ::testing::TestPartResult; using ::testing::UnitTest; namespace { diff --git a/googletest/samples/sample9_unittest.cc b/googletest/samples/sample9_unittest.cc index d627ea7d..0a2f0970 100644 --- a/googletest/samples/sample9_unittest.cc +++ b/googletest/samples/sample9_unittest.cc @@ -40,7 +40,6 @@ using ::testing::Test; using ::testing::TestEventListeners; using ::testing::TestInfo; using ::testing::TestPartResult; -using ::testing::TestSuite; using ::testing::UnitTest; namespace { // Provides alternative output mode which produces minimal amount of From 471087fbfcbc3c66071189a67c313eb1d525ee51 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 20 Mar 2023 02:43:07 -0700 Subject: [PATCH 44/75] Introduce std::make_unique and bool literals where possible PiperOrigin-RevId: 517910526 Change-Id: I398704f4b2ca0a55c86a06ca8b47d34c8670ddd7 --- googlemock/test/gmock-actions_test.cc | 14 +++++--------- googlemock/test/gmock-matchers-comparisons_test.cc | 3 ++- googlemock/test/gmock-matchers-containers_test.cc | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 7734830e..ee9b889b 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -444,7 +444,7 @@ TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) { EXPECT_TRUE(DefaultValue>::Exists()); EXPECT_TRUE(DefaultValue>::Get() == nullptr); DefaultValue>::SetFactory( - [] { return std::unique_ptr(new int(42)); }); + [] { return std::make_unique(42); }); EXPECT_TRUE(DefaultValue>::Exists()); std::unique_ptr i = DefaultValue>::Get(); EXPECT_EQ(42, *i); @@ -1751,9 +1751,7 @@ TEST(ReturnNewTest, ConstructorThatTakes10Arguments) { delete c; } -std::unique_ptr UniquePtrSource() { - return std::unique_ptr(new int(19)); -} +std::unique_ptr UniquePtrSource() { return std::make_unique(19); } std::vector> VectorUniquePtrSource() { std::vector> out; @@ -1802,7 +1800,7 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) { // Check default value DefaultValue>::SetFactory( - [] { return std::unique_ptr(new int(42)); }); + [] { return std::make_unique(42); }); EXPECT_EQ(42, *mock.MakeUnique()); EXPECT_CALL(mock, MakeUnique()).WillRepeatedly(Invoke(UniquePtrSource)); @@ -1822,7 +1820,7 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) { TEST(MockMethodTest, CanTakeMoveOnlyValue) { MockClass mock; - auto make = [](int i) { return std::unique_ptr(new int(i)); }; + auto make = [](int i) { return std::make_unique(i); }; EXPECT_CALL(mock, TakeUnique(_)).WillRepeatedly([](std::unique_ptr i) { return *i; @@ -2053,9 +2051,7 @@ struct Double { } }; -std::unique_ptr UniqueInt(int i) { - return std::unique_ptr(new int(i)); -} +std::unique_ptr UniqueInt(int i) { return std::make_unique(i); } TEST(FunctorActionTest, ActionFromFunction) { Action a = &Add; diff --git a/googlemock/test/gmock-matchers-comparisons_test.cc b/googlemock/test/gmock-matchers-comparisons_test.cc index 0738aafb..b849990d 100644 --- a/googlemock/test/gmock-matchers-comparisons_test.cc +++ b/googlemock/test/gmock-matchers-comparisons_test.cc @@ -31,6 +31,7 @@ // // This file tests some commonly used argument matchers. +#include #include #include "test/gmock-matchers_test.h" @@ -1542,7 +1543,7 @@ TEST(PairTest, MatchesCorrectly) { TEST(PairTest, WorksWithMoveOnly) { pair, std::unique_ptr> p; - p.second.reset(new int(7)); + p.second = std::make_unique(7); EXPECT_THAT(p, Pair(Eq(nullptr), Ne(nullptr))); } diff --git a/googlemock/test/gmock-matchers-containers_test.cc b/googlemock/test/gmock-matchers-containers_test.cc index b40a26a4..c8d8ea37 100644 --- a/googlemock/test/gmock-matchers-containers_test.cc +++ b/googlemock/test/gmock-matchers-containers_test.cc @@ -1824,8 +1824,8 @@ TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) { } TEST(UnorderedElementsAreArrayTest, VectorBool) { - const bool a[] = {0, 1, 0, 1, 1}; - const bool b[] = {1, 0, 1, 1, 0}; + const bool a[] = {false, true, false, true, true}; + const bool b[] = {true, false, true, true, false}; std::vector expected(std::begin(a), std::end(a)); std::vector actual(std::begin(b), std::end(b)); StringMatchResultListener listener; From 3288c4deae0710464a0fd21316084c408798b960 Mon Sep 17 00:00:00 2001 From: Phoebe Liang Date: Mon, 20 Mar 2023 12:11:18 -0700 Subject: [PATCH 45/75] Revise documentation to include AbslStringify PiperOrigin-RevId: 518039451 Change-Id: Ife548d0f83266746ce1981bea31e70e6b43027c9 --- docs/advanced.md | 199 ++++++++++++++++++++++++++--------------------- 1 file changed, 111 insertions(+), 88 deletions(-) diff --git a/docs/advanced.md b/docs/advanced.md index 6b4c3f0b..d0369237 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -1,9 +1,9 @@ -# Advanced googletest Topics +# Advanced GoogleTest Topics ## Introduction -Now that you have read the [googletest Primer](primer.md) and learned how to -write tests using googletest, it's time to learn some new tricks. This document +Now that you have read the [GoogleTest Primer](primer.md) and learned how to +write tests using GoogleTest, it's time to learn some new tricks. This document will show you more assertions as well as how to construct complex failure messages, propagate fatal failures, reuse and speed up your test fixtures, and use various flags with your tests. @@ -25,7 +25,7 @@ Reference. ### Predicate Assertions for Better Error Messages -Even though googletest has a rich set of assertions, they can never be complete, +Even though GoogleTest has a rich set of assertions, they can never be complete, as it's impossible (nor a good idea) to anticipate all scenarios a user might run into. Therefore, sometimes a user has to use `EXPECT_TRUE()` to check a complex expression, for lack of a better macro. This has the problem of not @@ -35,7 +35,7 @@ failure message by themselves, streaming it into `EXPECT_TRUE()`. However, this is awkward especially when the expression has side-effects or is expensive to evaluate. -googletest gives you three different options to solve this problem: +GoogleTest gives you three different options to solve this problem: #### Using an Existing Boolean Function @@ -304,9 +304,9 @@ TEST_F(SkipFixture, SkipsOneTest) { As with assertion macros, you can stream a custom message into `GTEST_SKIP()`. -## Teaching googletest How to Print Your Values +## Teaching GoogleTest How to Print Your Values -When a test assertion such as `EXPECT_EQ` fails, googletest prints the argument +When a test assertion such as `EXPECT_EQ` fails, GoogleTest prints the argument values to help you debug. It does this using a user-extensible value printer. This printer knows how to print built-in C++ types, native arrays, STL @@ -315,73 +315,96 @@ prints the raw bytes in the value and hopes that you the user can figure it out. As mentioned earlier, the printer is *extensible*. That means you can teach it to do a better job at printing your particular type than to dump the bytes. To -do that, define `<<` for your type: - -```c++ -#include +do that, define an `AbslStringify()` overload as a `friend` function template +for your type: +```cpp namespace foo { -class Bar { // We want googletest to be able to print instances of this. -... - // Create a free inline friend function. - friend std::ostream& operator<<(std::ostream& os, const Bar& bar) { - return os << bar.DebugString(); // whatever needed to print bar to os +class Point { // We want GoogleTest to be able to print instances of this. + ... + // Provide a friend overload. + template + friend void AbslStringify(Sink& sink, const Point& point) { + absl::Format(&sink, "(%d, %d)", point.x, point.y); } + + int x; + int y; }; // If you can't declare the function in the class it's important that the -// << operator is defined in the SAME namespace that defines Bar. C++'s look-up -// rules rely on that. -std::ostream& operator<<(std::ostream& os, const Bar& bar) { - return os << bar.DebugString(); // whatever needed to print bar to os +// AbslStringify overload is defined in the SAME namespace that defines Point. +// C++'s look-up rules rely on that. +enum class EnumWithStringify { kMany = 0, kChoices = 1 }; + +template +void AbslStringify(Sink& sink, EnumWithStringify e) { + absl::Format(&sink, "%s", e == EnumWithStringify::kMany ? "Many" : "Choices"); } } // namespace foo ``` -Sometimes, this might not be an option: your team may consider it bad style to -have a `<<` operator for `Bar`, or `Bar` may already have a `<<` operator that -doesn't do what you want (and you cannot change it). If so, you can instead -define a `PrintTo()` function like this: +{: .callout .note} +Note: `AbslStringify()` utilizes a generic "sink" buffer to construct its +string. For more information about supported operations on `AbslStringify()`'s +sink, see go/abslstringify. + +`AbslStringify()` can also use `absl::StrFormat`'s catch-all `%v` type specifier +within its own format strings to perform type deduction. `Point` above could be +formatted as `"(%v, %v)"` for example, and deduce the `int` values as `%d`. + +Sometimes, `AbslStringify()` might not be an option: your team may wish to print +types with extra debugging information for testing purposes only. If so, you can +instead define a `PrintTo()` function like this: ```c++ #include namespace foo { -class Bar { +class Point { ... - friend void PrintTo(const Bar& bar, std::ostream* os) { - *os << bar.DebugString(); // whatever needed to print bar to os + friend void PrintTo(const Point& point, std::ostream* os) { + *os << "(" << point.x << "," << point.y << ")"; } + + int x; + int y; }; // If you can't declare the function in the class it's important that PrintTo() -// is defined in the SAME namespace that defines Bar. C++'s look-up rules rely -// on that. -void PrintTo(const Bar& bar, std::ostream* os) { - *os << bar.DebugString(); // whatever needed to print bar to os +// is defined in the SAME namespace that defines Point. C++'s look-up rules +// rely on that. +void PrintTo(const Point& point, std::ostream* os) { + *os << "(" << point.x << "," << point.y << ")"; } } // namespace foo ``` -If you have defined both `<<` and `PrintTo()`, the latter will be used when -googletest is concerned. This allows you to customize how the value appears in -googletest's output without affecting code that relies on the behavior of its -`<<` operator. +If you have defined both `AbslStringify()` and `PrintTo()`, the latter will be +used by GoogleTest. This allows you to customize how the value appears in +GoogleTest's output without affecting code that relies on the behavior of +`AbslStringify()`. -If you want to print a value `x` using googletest's value printer yourself, just +If you have an existing `<<` operator and would like to define an +`AbslStringify()`, the latter will be used for GoogleTest printing. + +If you want to print a value `x` using GoogleTest's value printer yourself, just call `::testing::PrintToString(x)`, which returns an `std::string`: ```c++ -vector > bar_ints = GetBarIntVector(); +vector > point_ints = GetPointIntVector(); -EXPECT_TRUE(IsCorrectBarIntVector(bar_ints)) - << "bar_ints = " << testing::PrintToString(bar_ints); +EXPECT_TRUE(IsCorrectPointIntVector(point_ints)) + << "point_ints = " << testing::PrintToString(point_ints); ``` +For more details regarding `AbslStringify()` and its integration with other +libraries, see go/abslstringify. + ## Death Tests In many applications, there are assertions that can cause application failure if @@ -451,7 +474,7 @@ Note that a death test only cares about three things: 3. does the stderr output match `matcher`? In particular, if `statement` generates an `ASSERT_*` or `EXPECT_*` failure, it -will **not** cause the death test to fail, as googletest assertions don't abort +will **not** cause the death test to fail, as GoogleTest assertions don't abort the process. ### Death Test Naming @@ -482,14 +505,14 @@ TEST_F(FooDeathTest, DoesThat) { ### Regular Expression Syntax -When built with Bazel and using Abseil, googletest uses the +When built with Bazel and using Abseil, GoogleTest uses the [RE2](https://github.com/google/re2/wiki/Syntax) syntax. Otherwise, for POSIX -systems (Linux, Cygwin, Mac), googletest uses the +systems (Linux, Cygwin, Mac), GoogleTest uses the [POSIX extended regular expression](http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html#tag_09_04) syntax. To learn about POSIX syntax, you may want to read this [Wikipedia entry](http://en.wikipedia.org/wiki/Regular_expression#POSIX_extended). -On Windows, googletest uses its own simple regular expression implementation. It +On Windows, GoogleTest uses its own simple regular expression implementation. It lacks many features. For example, we don't support union (`"x|y"`), grouping (`"(xy)"`), brackets (`"[xy]"`), and repetition count (`"x{5,7}"`), among others. Below is what we do support (`A` denotes a literal character, period @@ -519,7 +542,7 @@ Expression | Meaning `$` | matches the end of a string (not that of each line) `xy` | matches `x` followed by `y` -To help you determine which capability is available on your system, googletest +To help you determine which capability is available on your system, GoogleTest defines macros to govern which regular expression it is using. The macros are: `GTEST_USES_SIMPLE_RE=1` or `GTEST_USES_POSIX_RE=1`. If you want your death tests to work in all cases, you can either `#if` on these macros or use the more @@ -539,7 +562,7 @@ arrange that kind of environment. For example, statically-initialized modules may start threads before main is ever reached. Once threads have been created, it may be difficult or impossible to clean them up. -googletest has three features intended to raise awareness of threading issues. +GoogleTest has three features intended to raise awareness of threading issues. 1. A warning is emitted if multiple threads are running when a death test is encountered. @@ -592,7 +615,7 @@ TEST(MyDeathTest, TestTwo) { The `statement` argument of `ASSERT_EXIT()` can be any valid C++ statement. If it leaves the current function via a `return` statement or by throwing an -exception, the death test is considered to have failed. Some googletest macros +exception, the death test is considered to have failed. Some GoogleTest macros may return from the current function (e.g. `ASSERT_TRUE()`), so be sure to avoid them in `statement`. @@ -726,7 +749,7 @@ TEST(FooTest, Bar) { } ``` -To alleviate this, googletest provides three different solutions. You could use +To alleviate this, GoogleTest provides three different solutions. You could use either exceptions, the `(ASSERT|EXPECT)_NO_FATAL_FAILURE` assertions or the `HasFatalFailure()` function. They are described in the following two subsections. @@ -760,7 +783,7 @@ in it, the test will continue after the subroutine returns. This may not be what you want. Often people want fatal failures to propagate like exceptions. For that -googletest offers the following macros: +GoogleTest offers the following macros: Fatal assertion | Nonfatal assertion | Verifies ------------------------------------- | ------------------------------------- | -------- @@ -852,7 +875,7 @@ will output XML like this: > needs to be prefixed with `::testing::Test::` if used outside of the > `TEST` body and the test fixture class. > * *`key`* must be a valid XML attribute name, and cannot conflict with the -> ones already used by googletest (`name`, `status`, `time`, `classname`, +> ones already used by GoogleTest (`name`, `status`, `time`, `classname`, > `type_param`, and `value_param`). > * Calling `RecordProperty()` outside of the lifespan of a test is allowed. > If it's called outside of a test but between a test suite's @@ -863,13 +886,13 @@ will output XML like this: ## Sharing Resources Between Tests in the Same Test Suite -googletest creates a new test fixture object for each test in order to make +GoogleTest creates a new test fixture object for each test in order to make tests independent and easier to debug. However, sometimes tests use resources that are expensive to set up, making the one-copy-per-test model prohibitively expensive. If the tests don't change the resource, there's no harm in their sharing a -single resource copy. So, in addition to per-test set-up/tear-down, googletest +single resource copy. So, in addition to per-test set-up/tear-down, GoogleTest also supports per-test-suite set-up/tear-down. To use it: 1. In your test fixture class (say `FooTest` ), declare as `static` some member @@ -881,7 +904,7 @@ also supports per-test-suite set-up/tear-down. To use it: `u`!) to set up the shared resources and a `static void TearDownTestSuite()` function to tear them down. -That's it! googletest automatically calls `SetUpTestSuite()` before running the +That's it! GoogleTest automatically calls `SetUpTestSuite()` before running the *first test* in the `FooTest` test suite (i.e. before creating the first `FooTest` object), and calls `TearDownTestSuite()` after running the *last test* in it (i.e. after deleting the last `FooTest` object). In between, the tests can @@ -974,7 +997,7 @@ class Environment : public ::testing::Environment { }; ``` -Then, you register an instance of your environment class with googletest by +Then, you register an instance of your environment class with GoogleTest by calling the `::testing::AddGlobalTestEnvironment()` function: ```c++ @@ -991,7 +1014,7 @@ It's OK to register multiple environment objects. In this suite, their `SetUp()` will be called in the order they are registered, and their `TearDown()` will be called in the reverse order. -Note that googletest takes ownership of the registered environment objects. +Note that GoogleTest takes ownership of the registered environment objects. Therefore **do not delete them** by yourself. You should call `AddGlobalTestEnvironment()` before `RUN_ALL_TESTS()` is called, @@ -1501,12 +1524,12 @@ To test them, we use the following special techniques: ## "Catching" Failures -If you are building a testing utility on top of googletest, you'll want to test -your utility. What framework would you use to test it? googletest, of course. +If you are building a testing utility on top of GoogleTest, you'll want to test +your utility. What framework would you use to test it? GoogleTest, of course. The challenge is to verify that your testing utility reports failures correctly. In frameworks that report a failure by throwing an exception, you could catch -the exception and assert on it. But googletest doesn't use exceptions, so how do +the exception and assert on it. But GoogleTest doesn't use exceptions, so how do we test that a piece of code generates an expected failure? `"gtest/gtest-spi.h"` contains some constructs to do this. @@ -1649,9 +1672,9 @@ particular, you cannot find the test suite name in `SetUpTestSuite()`, `TearDownTestSuite()` (where you know the test suite name implicitly), or functions called from them. -## Extending googletest by Handling Test Events +## Extending GoogleTest by Handling Test Events -googletest provides an **event listener API** to let you receive notifications +GoogleTest provides an **event listener API** to let you receive notifications about the progress of a test program and test failures. The events you can listen to include the start and end of the test program, a test suite, or a test method, among others. You may use this API to augment or replace the standard @@ -1712,7 +1735,7 @@ Here's an example: ### Using Event Listeners To use the event listener you have defined, add an instance of it to the -googletest event listener list (represented by class +GoogleTest event listener list (represented by class [`TestEventListeners`](reference/testing.md#TestEventListeners) - note the "s" at the end of the name) in your `main()` function, before calling `RUN_ALL_TESTS()`: @@ -1723,7 +1746,7 @@ int main(int argc, char** argv) { // Gets hold of the event listener list. testing::TestEventListeners& listeners = testing::UnitTest::GetInstance()->listeners(); - // Adds a listener to the end. googletest takes the ownership. + // Adds a listener to the end. GoogleTest takes the ownership. listeners.Append(new MinimalistPrinter); return RUN_ALL_TESTS(); } @@ -1775,7 +1798,7 @@ See [sample10_unittest.cc] for an example of a failure-raising listener. ## Running Test Programs: Advanced Options -googletest test programs are ordinary executables. Once built, you can run them +GoogleTest test programs are ordinary executables. Once built, you can run them directly and affect their behavior via the following environment variables and/or command line flags. For the flags to work, your programs must call `::testing::InitGoogleTest()` before calling `RUN_ALL_TESTS()`. @@ -1808,10 +1831,10 @@ corresponding environment variable for this flag. #### Running a Subset of the Tests -By default, a googletest program runs all tests the user has defined. Sometimes, +By default, a GoogleTest program runs all tests the user has defined. Sometimes, you want to run only a subset of the tests (e.g. for debugging or quickly verifying a change). If you set the `GTEST_FILTER` environment variable or the -`--gtest_filter` flag to a filter string, googletest will only run the tests +`--gtest_filter` flag to a filter string, GoogleTest will only run the tests whose full names (in the form of `TestSuiteName.TestName`) match the filter. The format of a filter is a '`:`'-separated list of wildcard patterns (called @@ -1842,7 +1865,7 @@ For example: #### Stop test execution upon first failure -By default, a googletest program runs all tests the user has defined. In some +By default, a GoogleTest program runs all tests the user has defined. In some cases (e.g. iterative test development & execution) it may be desirable stop test execution upon first failure (trading improved latency for completeness). If `GTEST_FAIL_FAST` environment variable or `--gtest_fail_fast` flag is set, @@ -1859,7 +1882,7 @@ If you need to disable all tests in a test suite, you can either add `DISABLED_` to the front of the name of each test, or alternatively add it to the front of the test suite name. -For example, the following tests won't be run by googletest, even though they +For example, the following tests won't be run by GoogleTest, even though they will still be compiled: ```c++ @@ -1874,7 +1897,7 @@ TEST_F(DISABLED_BarTest, DoesXyz) { ... } {: .callout .note} NOTE: This feature should only be used for temporary pain-relief. You still have -to fix the disabled tests at a later date. As a reminder, googletest will print +to fix the disabled tests at a later date. As a reminder, GoogleTest will print a banner warning you if a test program contains any disabled tests. {: .callout .tip} @@ -1932,16 +1955,16 @@ You can specify the `--gtest_shuffle` flag (or set the `GTEST_SHUFFLE` environment variable to `1`) to run the tests in a program in a random order. This helps to reveal bad dependencies between tests. -By default, googletest uses a random seed calculated from the current time. +By default, GoogleTest uses a random seed calculated from the current time. Therefore you'll get a different order every time. The console output includes the random seed value, such that you can reproduce an order-related test failure later. To specify the random seed explicitly, use the `--gtest_random_seed=SEED` flag (or set the `GTEST_RANDOM_SEED` environment variable), where `SEED` is an integer in the range [0, 99999]. The seed value 0 is special: it tells -googletest to do the default behavior of calculating the seed from the current +GoogleTest to do the default behavior of calculating the seed from the current time. -If you combine this with `--gtest_repeat=N`, googletest will pick a different +If you combine this with `--gtest_repeat=N`, GoogleTest will pick a different random seed and re-shuffle the tests in each iteration. ### Distributing Test Functions to Multiple Machines @@ -2000,7 +2023,7 @@ shards, but here's one possible scenario: #### Colored Terminal Output -googletest can use colors in its terminal output to make it easier to spot the +GoogleTest can use colors in its terminal output to make it easier to spot the important information:
...
@@ -2025,25 +2048,25 @@ important information:
 
 You can set the `GTEST_COLOR` environment variable or the `--gtest_color`
 command line flag to `yes`, `no`, or `auto` (the default) to enable colors,
-disable colors, or let googletest decide. When the value is `auto`, googletest
+disable colors, or let GoogleTest decide. When the value is `auto`, GoogleTest
 will use colors if and only if the output goes to a terminal and (on non-Windows
 platforms) the `TERM` environment variable is set to `xterm` or `xterm-color`.
 
 #### Suppressing test passes
 
-By default, googletest prints 1 line of output for each test, indicating if it
+By default, GoogleTest prints 1 line of output for each test, indicating if it
 passed or failed. To show only test failures, run the test program with
 `--gtest_brief=1`, or set the GTEST_BRIEF environment variable to `1`.
 
 #### Suppressing the Elapsed Time
 
-By default, googletest prints the time it takes to run each test. To disable
+By default, GoogleTest prints the time it takes to run each test. To disable
 that, run the test program with the `--gtest_print_time=0` command line flag, or
 set the GTEST_PRINT_TIME environment variable to `0`.
 
 #### Suppressing UTF-8 Text Output
 
-In case of assertion failures, googletest prints expected and actual values of
+In case of assertion failures, GoogleTest prints expected and actual values of
 type `string` both as hex-encoded strings as well as in readable UTF-8 text if
 they contain valid non-ASCII UTF-8 characters. If you want to suppress the UTF-8
 text because, for example, you don't have an UTF-8 compatible output medium, run
@@ -2052,7 +2075,7 @@ environment variable to `0`.
 
 #### Generating an XML Report
 
-googletest can emit a detailed XML report to a file in addition to its normal
+GoogleTest can emit a detailed XML report to a file in addition to its normal
 textual output. The report contains the duration of each test, and thus can help
 you identify slow tests.
 
@@ -2063,15 +2086,15 @@ in which case the output can be found in the `test_detail.xml` file in the
 current directory.
 
 If you specify a directory (for example, `"xml:output/directory/"` on Linux or
-`"xml:output\directory\"` on Windows), googletest will create the XML file in
+`"xml:output\directory\"` on Windows), GoogleTest will create the XML file in
 that directory, named after the test executable (e.g. `foo_test.xml` for test
 program `foo_test` or `foo_test.exe`). If the file already exists (perhaps left
-over from a previous run), googletest will pick a different name (e.g.
+over from a previous run), GoogleTest will pick a different name (e.g.
 `foo_test_1.xml`) to avoid overwriting it.
 
 The report is based on the `junitreport` Ant task. Since that format was
 originally intended for Java, a little interpretation is required to make it
-apply to googletest tests, as shown here:
+apply to GoogleTest tests, as shown here:
 
 ```xml
 
@@ -2086,8 +2109,8 @@ apply to googletest tests, as shown here:
 ```
 
 *   The root `` element corresponds to the entire test program.
-*   `` elements correspond to googletest test suites.
-*   `` elements correspond to googletest test functions.
+*   `` elements correspond to GoogleTest test suites.
+*   `` elements correspond to GoogleTest test functions.
 
 For instance, the following program
 
@@ -2120,7 +2143,7 @@ could generate this report:
 Things to note:
 
 *   The `tests` attribute of a `` or `` element tells how
-    many test functions the googletest program or test suite contains, while the
+    many test functions the GoogleTest program or test suite contains, while the
     `failures` attribute tells how many of them failed.
 
 *   The `time` attribute expresses the duration of the test, test suite, or
@@ -2132,12 +2155,12 @@ Things to note:
 *   The `file` and `line` attributes record the source file location, where the
     test was defined.
 
-*   Each `` element corresponds to a single failed googletest
+*   Each `` element corresponds to a single failed GoogleTest
     assertion.
 
 #### Generating a JSON Report
 
-googletest can also emit a JSON report as an alternative format to XML. To
+GoogleTest can also emit a JSON report as an alternative format to XML. To
 generate the JSON report, set the `GTEST_OUTPUT` environment variable or the
 `--gtest_output` flag to the string `"json:path_to_output_file"`, which will
 create the file at the given location. You can also just use the string
@@ -2362,7 +2385,7 @@ variable has been set.
 
 When running test programs under a debugger, it's very convenient if the
 debugger can catch an assertion failure and automatically drop into interactive
-mode. googletest's *break-on-failure* mode supports this behavior.
+mode. GoogleTest's *break-on-failure* mode supports this behavior.
 
 To enable it, set the `GTEST_BREAK_ON_FAILURE` environment variable to a value
 other than `0`. Alternatively, you can use the `--gtest_break_on_failure`
@@ -2370,9 +2393,9 @@ command line flag.
 
 #### Disabling Catching Test-Thrown Exceptions
 
-googletest can be used either with or without exceptions enabled. If a test
+GoogleTest can be used either with or without exceptions enabled. If a test
 throws a C++ exception or (on Windows) a structured exception (SEH), by default
-googletest catches it, reports it as a test failure, and continues with the next
+GoogleTest catches it, reports it as a test failure, and continues with the next
 test method. This maximizes the coverage of a test run. Also, on Windows an
 uncaught exception will cause a pop-up window, so catching the exceptions allows
 you to run the tests automatically.
@@ -2410,4 +2433,4 @@ void __tsan_on_report() {
 ```
 
 After compiling your project with one of the sanitizers enabled, if a particular
-test triggers a sanitizer error, googletest will report that it failed.
+test triggers a sanitizer error, GoogleTest will report that it failed.

From e9faae170f8ab3086a76c299f19d659ba6079967 Mon Sep 17 00:00:00 2001
From: Abseil Team 
Date: Tue, 21 Mar 2023 02:35:52 -0700
Subject: [PATCH 46/75] Internal Code Change

PiperOrigin-RevId: 518213370
Change-Id: I88d0acc195dadf8d03cd15c8534c721141db14ea
---
 googlemock/include/gmock/gmock-matchers.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h
index a480576d..7c5d65cf 100644
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -563,7 +563,7 @@ namespace internal {
 // If the explanation is not empty, prints it to the ostream.
 inline void PrintIfNotEmpty(const std::string& explanation,
                             ::std::ostream* os) {
-  if (explanation != "" && os != nullptr) {
+  if (!explanation.empty() && os != nullptr) {
     *os << ", " << explanation;
   }
 }
@@ -2966,7 +2966,7 @@ class KeyMatcherImpl : public MatcherInterface {
     const bool match = inner_matcher_.MatchAndExplain(
         pair_getters::First(key_value, Rank0()), &inner_listener);
     const std::string explanation = inner_listener.str();
-    if (explanation != "") {
+    if (!explanation.empty()) {
       *listener << "whose first field is a value " << explanation;
     }
     return match;
@@ -3113,12 +3113,12 @@ class PairMatcherImpl : public MatcherInterface {
                       const std::string& second_explanation,
                       MatchResultListener* listener) const {
     *listener << "whose both fields match";
-    if (first_explanation != "") {
+    if (!first_explanation.empty()) {
       *listener << ", where the first field is a value " << first_explanation;
     }
-    if (second_explanation != "") {
+    if (!second_explanation.empty()) {
       *listener << ", ";
-      if (first_explanation != "") {
+      if (!first_explanation.empty()) {
         *listener << "and ";
       } else {
         *listener << "where ";

From 974e18ee6f146a2418f9cea83170c640e7d622d6 Mon Sep 17 00:00:00 2001
From: Abseil Team 
Date: Tue, 21 Mar 2023 10:06:47 -0700
Subject: [PATCH 47/75] Fix minor bug -- if ExecDeathTestChildMain() ever
 returns, we should exit with a non-zero status.

PiperOrigin-RevId: 518306642
Change-Id: I72fb2764e477acb0362593c63f7748c4f64db0c6
---
 googletest/src/gtest-death-test.cc | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc
index 1bf2f312..df04111e 100644
--- a/googletest/src/gtest-death-test.cc
+++ b/googletest/src/gtest-death-test.cc
@@ -1328,8 +1328,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
 #endif  // GTEST_HAS_CLONE
 
   if (use_fork && (child_pid = fork()) == 0) {
-    ExecDeathTestChildMain(&args);
-    _exit(0);
+    _exit(ExecDeathTestChildMain(&args));
   }
 #endif  // GTEST_OS_QNX
 #ifdef GTEST_OS_LINUX

From 5fce13091d223069436ad7a5aad53f026b0f2041 Mon Sep 17 00:00:00 2001
From: Aaron Jacobs 
Date: Wed, 22 Mar 2023 20:19:06 -0700
Subject: [PATCH 48/75] gtest.cc: add a newline after a failure when there is
 no OS stack trace.

This makes the behavior consistent when GTEST_STACK_TRACE_DEPTH is set to zero
and not: there is always vertical whitespace separating failure messages.

PiperOrigin-RevId: 518744611
Change-Id: I5b4af40633849850660504c3f497a76601d4311d
---
 googlemock/test/gmock_output_test_golden.txt  | 18 +++++++++++
 googletest/src/gtest.cc                       |  2 ++
 .../test/googletest-json-output-unittest.py   |  2 +-
 googletest/test/googletest-output-test.py     |  2 +-
 googletest/test/gtest_xml_output_unittest.py  | 30 +++++++++++--------
 5 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/googlemock/test/gmock_output_test_golden.txt b/googlemock/test/gmock_output_test_golden.txt
index d6c03338..a2256443 100644
--- a/googlemock/test/gmock_output_test_golden.txt
+++ b/googlemock/test/gmock_output_test_golden.txt
@@ -40,6 +40,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(0, _))...
            Actual: 1
          Expected: to be called once
            Actual: never called - unsatisfied and active
+
 [  FAILED  ] GMockOutputTest.UnexpectedCall
 [ RUN      ] GMockOutputTest.UnexpectedCallToVoidFunction
 unknown file: Failure
@@ -53,6 +54,7 @@ FILE:#: EXPECT_CALL(foo_, Bar3(0, _))...
            Actual: 1
          Expected: to be called once
            Actual: never called - unsatisfied and active
+
 [  FAILED  ] GMockOutputTest.UnexpectedCallToVoidFunction
 [ RUN      ] GMockOutputTest.ExcessiveCall
 FILE:#: Failure
@@ -61,6 +63,7 @@ Mock function called more times than expected - returning default value.
           Returns: false
          Expected: to be called once
            Actual: called twice - over-saturated and active
+
 [  FAILED  ] GMockOutputTest.ExcessiveCall
 [ RUN      ] GMockOutputTest.ExcessiveCallToVoidFunction
 FILE:#: Failure
@@ -68,6 +71,7 @@ Mock function called more times than expected - returning directly.
     Function call: Bar3(0, 1)
          Expected: to be called once
            Actual: called twice - over-saturated and active
+
 [  FAILED  ] GMockOutputTest.ExcessiveCallToVoidFunction
 [ RUN      ] GMockOutputTest.UninterestingCall
 
@@ -104,6 +108,7 @@ FILE:#: tried expectation #1: EXPECT_CALL(foo_, Bar2(0, 0))...
            Actual: 1
          Expected: to be called once
            Actual: never called - unsatisfied and active
+
 [  FAILED  ] GMockOutputTest.RetiredExpectation
 [ RUN      ] GMockOutputTest.UnsatisfiedPrerequisite
 unknown file: Failure
@@ -125,6 +130,7 @@ FILE:#: pre-requisite #0
                    (end of pre-requisites)
          Expected: to be called once
            Actual: never called - unsatisfied and active
+
 [  FAILED  ] GMockOutputTest.UnsatisfiedPrerequisite
 [ RUN      ] GMockOutputTest.UnsatisfiedPrerequisites
 unknown file: Failure
@@ -147,6 +153,7 @@ FILE:#: pre-requisite #1
                    (end of pre-requisites)
          Expected: to be called once
            Actual: never called - unsatisfied and active
+
 [  FAILED  ] GMockOutputTest.UnsatisfiedPrerequisites
 [ RUN      ] GMockOutputTest.UnsatisfiedWith
 FILE:#: Failure
@@ -154,16 +161,19 @@ Actual function call count doesn't match EXPECT_CALL(foo_, Bar2(_, _))...
     Expected args: are a pair where the first >= the second
          Expected: to be called once
            Actual: never called - unsatisfied and active
+
 [  FAILED  ] GMockOutputTest.UnsatisfiedWith
 [ RUN      ] GMockOutputTest.UnsatisfiedExpectation
 FILE:#: Failure
 Actual function call count doesn't match EXPECT_CALL(foo_, Bar2(0, _))...
          Expected: to be called twice
            Actual: called once - unsatisfied and active
+
 FILE:#: Failure
 Actual function call count doesn't match EXPECT_CALL(foo_, Bar(_, _, _))...
          Expected: to be called once
            Actual: never called - unsatisfied and active
+
 [  FAILED  ] GMockOutputTest.UnsatisfiedExpectation
 [ RUN      ] GMockOutputTest.MismatchArguments
 unknown file: Failure
@@ -180,6 +190,7 @@ FILE:#: EXPECT_CALL(foo_, Bar(Ref(s), _, Ge(0)))...
            Actual: -0.1
          Expected: to be called once
            Actual: never called - unsatisfied and active
+
 [  FAILED  ] GMockOutputTest.MismatchArguments
 [ RUN      ] GMockOutputTest.MismatchWith
 unknown file: Failure
@@ -194,6 +205,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))...
            Actual: don't match
          Expected: to be called once
            Actual: never called - unsatisfied and active
+
 [  FAILED  ] GMockOutputTest.MismatchWith
 [ RUN      ] GMockOutputTest.MismatchArgumentsAndWith
 unknown file: Failure
@@ -210,6 +222,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))...
            Actual: don't match
          Expected: to be called once
            Actual: never called - unsatisfied and active
+
 [  FAILED  ] GMockOutputTest.MismatchArgumentsAndWith
 [ RUN      ] GMockOutputTest.UnexpectedCallWithDefaultAction
 unknown file: Failure
@@ -227,6 +240,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(2, 2))...
            Actual: 0
          Expected: to be called once
            Actual: never called - unsatisfied and active
+
 unknown file: Failure
 
 Unexpected mock function call - taking default action specified at:
@@ -242,6 +256,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(2, 2))...
            Actual: 0
          Expected: to be called once
            Actual: never called - unsatisfied and active
+
 [  FAILED  ] GMockOutputTest.UnexpectedCallWithDefaultAction
 [ RUN      ] GMockOutputTest.ExcessiveCallWithDefaultAction
 FILE:#: Failure
@@ -251,6 +266,7 @@ FILE:#:
           Returns: true
          Expected: to be called once
            Actual: called twice - over-saturated and active
+
 FILE:#: Failure
 Mock function called more times than expected - taking default action specified at:
 FILE:#:
@@ -258,6 +274,7 @@ FILE:#:
           Returns: false
          Expected: to be called once
            Actual: called twice - over-saturated and active
+
 [  FAILED  ] GMockOutputTest.ExcessiveCallWithDefaultAction
 [ RUN      ] GMockOutputTest.UninterestingCallWithDefaultAction
 
@@ -293,6 +310,7 @@ FILE:#: Failure
 Value of: (std::tuple(42, true))
 Expected: is pair (first: is >= 48, second: true)
   Actual: (42, true)
+
 [  FAILED  ] GMockOutputTest.PrintsMatcher
 [  FAILED  ] GMockOutputTest.UnexpectedCall
 [  FAILED  ] GMockOutputTest.UnexpectedCallToVoidFunction
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 55f8e507..897c0cd9 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -5319,6 +5319,8 @@ void UnitTest::AddTestPartResult(TestPartResult::Type result_type,
 
   if (os_stack_trace.c_str() != nullptr && !os_stack_trace.empty()) {
     msg << internal::kStackTraceMarker << os_stack_trace;
+  } else {
+    msg << "\n";
   }
 
   const TestPartResult result = TestPartResult(
diff --git a/googletest/test/googletest-json-output-unittest.py b/googletest/test/googletest-json-output-unittest.py
index b3a08deb..e955e7b0 100644
--- a/googletest/test/googletest-json-output-unittest.py
+++ b/googletest/test/googletest-json-output-unittest.py
@@ -54,7 +54,7 @@ SUPPORTS_STACK_TRACES = NO_STACKTRACE_SUPPORT_FLAG not in sys.argv
 if SUPPORTS_STACK_TRACES:
   STACK_TRACE_TEMPLATE = '\nStack trace:\n*'
 else:
-  STACK_TRACE_TEMPLATE = ''
+  STACK_TRACE_TEMPLATE = '\n'
 
 EXPECTED_NON_EMPTY = {
     'tests': 26,
diff --git a/googletest/test/googletest-output-test.py b/googletest/test/googletest-output-test.py
index 347b8546..6d80d532 100755
--- a/googletest/test/googletest-output-test.py
+++ b/googletest/test/googletest-output-test.py
@@ -132,7 +132,7 @@ def RemoveStackTraces(output):
   """Removes all traces of stack traces from a Google Test program's output."""
 
   # *? means "find the shortest string that matches".
-  return re.sub(r'Stack trace:(.|\n)*?\n\n', '', output)
+  return re.sub(r'Stack trace:(.|\n)*?\n', '', output)
 
 
 def RemoveTime(output):
diff --git a/googletest/test/gtest_xml_output_unittest.py b/googletest/test/gtest_xml_output_unittest.py
index 5ca11cb6..e7e44fc1 100755
--- a/googletest/test/gtest_xml_output_unittest.py
+++ b/googletest/test/gtest_xml_output_unittest.py
@@ -59,8 +59,10 @@ SUPPORTS_STACK_TRACES = NO_STACKTRACE_SUPPORT_FLAG not in sys.argv
 
 if SUPPORTS_STACK_TRACES:
   STACK_TRACE_TEMPLATE = '\nStack trace:\n*'
+  STACK_TRACE_ENTITY_TEMPLATE = ''
 else:
-  STACK_TRACE_TEMPLATE = ''
+  STACK_TRACE_TEMPLATE = '\n'
+  STACK_TRACE_ENTITY_TEMPLATE = '
'
   # unittest.main() can't handle unknown flags
   sys.argv.remove(NO_STACKTRACE_SUPPORT_FLAG)
 
@@ -71,7 +73,7 @@ EXPECTED_NON_EMPTY_XML = """
   
   
     
-      
@@ -80,11 +82,11 @@ Expected equality of these values:
   
     
     
-      
-      
@@ -93,14 +95,14 @@ Expected equality of these values:
   
   
     
-      ]]>%(stack)s]]>
     
   
   
     
-      
     
@@ -110,19 +112,19 @@ Invalid characters in brackets []%(stack)s]]>
   
   
     
-      
     
     
-      
     
     
-      
-      
     
 
@@ -187,7 +189,8 @@ It is good practice to tell why you skip a test.%(stack)s]]>
     
   
 """ % {
-    'stack': STACK_TRACE_TEMPLATE
+    'stack': STACK_TRACE_TEMPLATE,
+    'stack_entity': STACK_TRACE_ENTITY_TEMPLATE,
 }
 
 EXPECTED_FILTERED_TEST_XML = """
@@ -221,14 +224,15 @@ EXPECTED_NO_TEST_XML = """
             timestamp="*" name="AllTests">
   
     
-      
     
   
 """ % {
-    'stack': STACK_TRACE_TEMPLATE
+    'stack': STACK_TRACE_TEMPLATE,
+    'stack_entity': STACK_TRACE_ENTITY_TEMPLATE,
 }
 
 GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME)

From 5d6ba6d3b0a836f373d5ae83688880381cb7b3d4 Mon Sep 17 00:00:00 2001
From: gonzalobg <65027571+gonzalobg@users.noreply.github.com>
Date: Thu, 23 Mar 2023 10:26:58 +0100
Subject: [PATCH 49/75] Add doc comment

---
 googletest/include/gtest/internal/gtest-port.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h
index 77549e84..adf6f0b5 100644
--- a/googletest/include/gtest/internal/gtest-port.h
+++ b/googletest/include/gtest/internal/gtest-port.h
@@ -794,7 +794,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
 // Ask the compiler not to perform tail call optimization inside
 // the marked function.
 #define GTEST_NO_TAIL_CALL_ __attribute__((disable_tail_calls))
-#elif __GNUC__ && !defined(__NVCOMPILER)
+#elif __GNUC__ && !defined(__NVCOMPILER) // NVIDIA C++ Compiler warnings
 #define GTEST_NO_TAIL_CALL_ \
   __attribute__((optimize("no-optimize-sibling-calls")))
 #else

From 6f01e3dc125e82f2d3d87839a8be52f610c732ea Mon Sep 17 00:00:00 2001
From: Abseil Team 
Date: Thu, 23 Mar 2023 03:07:47 -0700
Subject: [PATCH 50/75] Internal Code Change

PiperOrigin-RevId: 518810140
Change-Id: Id3f9471f827894761080bc9199b0a092dc829b5f
---
 googletest/src/gtest-assertion-result.cc |  4 ++--
 googletest/src/gtest-death-test.cc       |  2 +-
 googletest/src/gtest-test-part.cc        |  2 --
 googletest/src/gtest-typed-test.cc       |  2 +-
 googletest/src/gtest.cc                  | 11 +++++------
 5 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/googletest/src/gtest-assertion-result.cc b/googletest/src/gtest-assertion-result.cc
index f1c0b10d..39989216 100644
--- a/googletest/src/gtest-assertion-result.cc
+++ b/googletest/src/gtest-assertion-result.cc
@@ -44,7 +44,7 @@ namespace testing {
 // Used in EXPECT_TRUE/FALSE(assertion_result).
 AssertionResult::AssertionResult(const AssertionResult& other)
     : success_(other.success_),
-      message_(other.message_.get() != nullptr
+      message_(other.message_ != nullptr
                    ? new ::std::string(*other.message_)
                    : static_cast< ::std::string*>(nullptr)) {}
 
@@ -58,7 +58,7 @@ void AssertionResult::swap(AssertionResult& other) {
 // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
 AssertionResult AssertionResult::operator!() const {
   AssertionResult negation(!success_);
-  if (message_.get() != nullptr) negation << *message_;
+  if (message_ != nullptr) negation << *message_;
   return negation;
 }
 
diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc
index df04111e..0b87ba5b 100644
--- a/googletest/src/gtest-death-test.cc
+++ b/googletest/src/gtest-death-test.cc
@@ -1524,7 +1524,7 @@ static int GetStatusFileDescriptor(unsigned int parent_process_id,
 // initialized from the GTEST_FLAG(internal_run_death_test) flag if
 // the flag is specified; otherwise returns NULL.
 InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
-  if (GTEST_FLAG_GET(internal_run_death_test) == "") return nullptr;
+  if (GTEST_FLAG_GET(internal_run_death_test).empty()) return nullptr;
 
   // GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we
   // can use it here.
diff --git a/googletest/src/gtest-test-part.cc b/googletest/src/gtest-test-part.cc
index eb7c8d1c..df677e6f 100644
--- a/googletest/src/gtest-test-part.cc
+++ b/googletest/src/gtest-test-part.cc
@@ -37,8 +37,6 @@
 
 namespace testing {
 
-using internal::GetUnitTestImpl;
-
 // Gets the summary of the failure message by omitting the stack trace
 // in it.
 std::string TestPartResult::ExtractSummary(const char* message) {
diff --git a/googletest/src/gtest-typed-test.cc b/googletest/src/gtest-typed-test.cc
index a2828b83..9941306f 100644
--- a/googletest/src/gtest-typed-test.cc
+++ b/googletest/src/gtest-typed-test.cc
@@ -90,7 +90,7 @@ const char* TypedTestSuitePState::VerifyRegisteredTestNames(
   }
 
   const std::string& errors_str = errors.GetString();
-  if (errors_str != "") {
+  if (!errors_str.empty()) {
     fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
             errors_str.c_str());
     fflush(stderr);
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 897c0cd9..7832492d 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -408,7 +408,7 @@ uint32_t Random::Generate(uint32_t range) {
 // GTestIsInitialized() returns true if and only if the user has initialized
 // Google Test.  Useful for catching the user mistake of not initializing
 // Google Test before calling RUN_ALL_TESTS().
-static bool GTestIsInitialized() { return GetArgvs().size() > 0; }
+static bool GTestIsInitialized() { return !GetArgvs().empty(); }
 
 // Iterates over a vector of TestSuites, keeping a running sum of the
 // results of calling a given int-returning method on each.
@@ -5306,7 +5306,7 @@ void UnitTest::AddTestPartResult(TestPartResult::Type result_type,
   msg << message;
 
   internal::MutexLock lock(&mutex_);
-  if (impl_->gtest_trace_stack().size() > 0) {
+  if (!impl_->gtest_trace_stack().empty()) {
     msg << "\n" << GTEST_NAME_ << " trace:";
 
     for (size_t i = impl_->gtest_trace_stack().size(); i > 0; --i) {
@@ -5606,7 +5606,7 @@ void UnitTestImpl::RecordProperty(const TestProperty& test_property) {
 // Disables event forwarding if the control is currently in a death test
 // subprocess. Must not be called before InitGoogleTest.
 void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
-  if (internal_run_death_test_flag_.get() != nullptr)
+  if (internal_run_death_test_flag_ != nullptr)
     listeners()->SuppressEventForwarding();
 }
 #endif  // GTEST_HAS_DEATH_TEST
@@ -5622,7 +5622,7 @@ void UnitTestImpl::ConfigureXmlOutput() {
   } else if (output_format == "json") {
     listeners()->SetDefaultXmlGenerator(new JsonUnitTestResultPrinter(
         UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
-  } else if (output_format != "") {
+  } else if (!output_format.empty()) {
     GTEST_LOG_(WARNING) << "WARNING: unrecognized output format \""
                         << output_format << "\" ignored.";
   }
@@ -5804,8 +5804,7 @@ bool UnitTestImpl::RunAllTests() {
   bool in_subprocess_for_death_test = false;
 
 #ifdef GTEST_HAS_DEATH_TEST
-  in_subprocess_for_death_test =
-      (internal_run_death_test_flag_.get() != nullptr);
+  in_subprocess_for_death_test = (internal_run_death_test_flag_ != nullptr);
 #if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_)
   if (in_subprocess_for_death_test) {
     GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_();

From a0ced33ac6df214966bb90ba036e0a5666dca14e Mon Sep 17 00:00:00 2001
From: Abseil Team 
Date: Fri, 24 Mar 2023 00:22:33 -0700
Subject: [PATCH 51/75] Internal Code Change

PiperOrigin-RevId: 519071084
Change-Id: I6459d60606e93bf658e505544538367508722857
---
 googletest/include/gtest/gtest-assertion-result.h | 4 ++--
 googletest/include/gtest/gtest.h                  | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/googletest/include/gtest/gtest-assertion-result.h b/googletest/include/gtest/gtest-assertion-result.h
index addbb59c..62fbea6e 100644
--- a/googletest/include/gtest/gtest-assertion-result.h
+++ b/googletest/include/gtest/gtest-assertion-result.h
@@ -181,7 +181,7 @@ class GTEST_API_ AssertionResult {
   // assertion's expectation). When nothing has been streamed into the
   // object, returns an empty string.
   const char* message() const {
-    return message_.get() != nullptr ? message_->c_str() : "";
+    return message_ != nullptr ? message_->c_str() : "";
   }
   // Deprecated; please use message() instead.
   const char* failure_message() const { return message(); }
@@ -204,7 +204,7 @@ class GTEST_API_ AssertionResult {
  private:
   // Appends the contents of message to message_.
   void AppendMessage(const Message& a_message) {
-    if (message_.get() == nullptr) message_.reset(new ::std::string);
+    if (message_ == nullptr) message_.reset(new ::std::string);
     message_->append(a_message.GetString().c_str());
   }
 
diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h
index 04a84f32..e5438268 100644
--- a/googletest/include/gtest/gtest.h
+++ b/googletest/include/gtest/gtest.h
@@ -551,14 +551,14 @@ class GTEST_API_ TestInfo {
   // Returns the name of the parameter type, or NULL if this is not a typed
   // or a type-parameterized test.
   const char* type_param() const {
-    if (type_param_.get() != nullptr) return type_param_->c_str();
+    if (type_param_ != nullptr) return type_param_->c_str();
     return nullptr;
   }
 
   // Returns the text representation of the value parameter, or NULL if this
   // is not a value-parameterized test.
   const char* value_param() const {
-    if (value_param_.get() != nullptr) return value_param_->c_str();
+    if (value_param_ != nullptr) return value_param_->c_str();
     return nullptr;
   }
 
@@ -697,7 +697,7 @@ class GTEST_API_ TestSuite {
   // Returns the name of the parameter type, or NULL if this is not a
   // type-parameterized test suite.
   const char* type_param() const {
-    if (type_param_.get() != nullptr) return type_param_->c_str();
+    if (type_param_ != nullptr) return type_param_->c_str();
     return nullptr;
   }
 

From e9fb5c7bacc4a25b030569c92ff9f6925288f1c3 Mon Sep 17 00:00:00 2001
From: Abseil Team 
Date: Fri, 24 Mar 2023 05:57:22 -0700
Subject: [PATCH 52/75] Replace `const char*` with `absl::string_view` as the
 latter is preferred.

PiperOrigin-RevId: 519122695
Change-Id: I7dcf969d15d26ccc4b376e3ab6db7f4c08c7386f
---
 docs/advanced.md | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/docs/advanced.md b/docs/advanced.md
index d0369237..3871db13 100644
--- a/docs/advanced.md
+++ b/docs/advanced.md
@@ -1066,7 +1066,7 @@ they must be declared **public** rather than **protected** in order to use
 
 ```c++
 class FooTest :
-    public testing::TestWithParam {
+    public testing::TestWithParam {
   // You can implement all the usual fixture class members here.
   // To access the test parameter, call GetParam() from class
   // TestWithParam.
@@ -1077,7 +1077,7 @@ class BaseTest : public testing::Test {
   ...
 };
 class BarTest : public BaseTest,
-                public testing::WithParamInterface {
+                public testing::WithParamInterface {
   ...
 };
 ```
@@ -1148,8 +1148,8 @@ with parameter values `"cat"` and `"dog"` using the
 [`ValuesIn`](reference/testing.md#param-generators) parameter generator:
 
 ```c++
-const char* pets[] = {"cat", "dog"};
-INSTANTIATE_TEST_SUITE_P(Pets, FooTest, testing::ValuesIn(pets));
+constexpr absl::string_view kPets[] = {"cat", "dog"};
+INSTANTIATE_TEST_SUITE_P(Pets, FooTest, testing::ValuesIn(kPets));
 ```
 
 The tests from the instantiation above will have these names:

From 88af49efa72a06d56910d69ecfd87e3b330e5778 Mon Sep 17 00:00:00 2001
From: Derek Mauro 
Date: Mon, 27 Mar 2023 12:09:24 -0700
Subject: [PATCH 53/75] Migrate CI builds to MSVC 2022

PiperOrigin-RevId: 519792199
Change-Id: Ic821b264bf1aef5e03f22fb0e288dd9d56fd536b
---
 ci/windows-presubmit.bat | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/ci/windows-presubmit.bat b/ci/windows-presubmit.bat
index 8668ff35..5ec4131c 100644
--- a/ci/windows-presubmit.bat
+++ b/ci/windows-presubmit.bat
@@ -5,9 +5,11 @@ SET BAZEL_EXE=%KOKORO_GFILE_DIR%\bazel-5.1.1-windows-x86_64.exe
 SET PATH=C:\Python37;%PATH%
 SET BAZEL_PYTHON=C:\python37\python.exe
 SET BAZEL_SH=C:\tools\msys64\usr\bin\bash.exe
-SET CMAKE_BIN="C:\Program Files\CMake\bin\cmake.exe"
-SET CTEST_BIN="C:\Program Files\CMake\bin\ctest.exe"
+SET CMAKE_BIN="cmake.exe"
+SET CTEST_BIN="ctest.exe"
 SET CTEST_OUTPUT_ON_FAILURE=1
+SET CMAKE_BUILD_PARALLEL_LEVEL=16
+SET CTEST_PARALLEL_LEVEL=16
 
 IF EXIST git\googletest (
   CD git\googletest
@@ -18,12 +20,12 @@ IF EXIST git\googletest (
 IF %errorlevel% neq 0 EXIT /B 1
 
 :: ----------------------------------------------------------------------------
-:: CMake Visual Studio 15 2017 Win64
-MKDIR cmake_msvc2017
-CD cmake_msvc2017
+:: CMake Visual Studio 17 2022 Win64
+MKDIR cmake_msvc2022
+CD cmake_msvc2022
 
 %CMAKE_BIN% .. ^
-  -G "Visual Studio 15 2017 Win64" ^
+  -G "Visual Studio 17 2022 Win64" ^
   -DPYTHON_EXECUTABLE:FILEPATH=c:\python37\python.exe ^
   -DPYTHON_INCLUDE_DIR:PATH=c:\python37\include ^
   -DPYTHON_LIBRARY:FILEPATH=c:\python37\lib\site-packages\pip ^
@@ -39,12 +41,12 @@ IF %errorlevel% neq 0 EXIT /B 1
 IF %errorlevel% neq 0 EXIT /B 1
 
 CD ..
-RMDIR /S /Q cmake_msvc2017
+RMDIR /S /Q cmake_msvc2022
 
 :: ----------------------------------------------------------------------------
-:: Bazel Visual Studio 15 2017 Win64
+:: Bazel Visual Studio 17 2022 Win64
 
-SET BAZEL_VC=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC
+SET BAZEL_VS=C:\Program Files\Microsoft Visual Studio\2022\Community
 %BAZEL_EXE% test ... ^
   --compilation_mode=dbg ^
   --copt=/std:c++14 ^

From 13b1900717fe93238d615691b6d0d951b0e154c4 Mon Sep 17 00:00:00 2001
From: Derek Mauro 
Date: Tue, 28 Mar 2023 06:27:28 -0700
Subject: [PATCH 54/75] Remove the Win64 arch from the CMake Generator since
 this can't be used with MSVC 2022

We also have to use Python 3.4 since that is what the base image has,
however, I will create a new image soon that has a modern version
of Python.

PiperOrigin-RevId: 520010732
Change-Id: Icf2420fd97d2bbc310382a17793045b6e16d62bb
---
 ci/windows-presubmit.bat | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/ci/windows-presubmit.bat b/ci/windows-presubmit.bat
index 5ec4131c..48962eb9 100644
--- a/ci/windows-presubmit.bat
+++ b/ci/windows-presubmit.bat
@@ -2,8 +2,8 @@ SETLOCAL ENABLEDELAYEDEXPANSION
 
 SET BAZEL_EXE=%KOKORO_GFILE_DIR%\bazel-5.1.1-windows-x86_64.exe
 
-SET PATH=C:\Python37;%PATH%
-SET BAZEL_PYTHON=C:\python37\python.exe
+SET PATH=C:\Python34;%PATH%
+SET BAZEL_PYTHON=C:\python34\python.exe
 SET BAZEL_SH=C:\tools\msys64\usr\bin\bash.exe
 SET CMAKE_BIN="cmake.exe"
 SET CTEST_BIN="ctest.exe"
@@ -20,12 +20,12 @@ IF EXIST git\googletest (
 IF %errorlevel% neq 0 EXIT /B 1
 
 :: ----------------------------------------------------------------------------
-:: CMake Visual Studio 17 2022 Win64
+:: CMake
 MKDIR cmake_msvc2022
 CD cmake_msvc2022
 
 %CMAKE_BIN% .. ^
-  -G "Visual Studio 17 2022 Win64" ^
+  -G "Visual Studio 17 2022" ^
   -DPYTHON_EXECUTABLE:FILEPATH=c:\python37\python.exe ^
   -DPYTHON_INCLUDE_DIR:PATH=c:\python37\include ^
   -DPYTHON_LIBRARY:FILEPATH=c:\python37\lib\site-packages\pip ^
@@ -44,7 +44,7 @@ CD ..
 RMDIR /S /Q cmake_msvc2022
 
 :: ----------------------------------------------------------------------------
-:: Bazel Visual Studio 17 2022 Win64
+:: Bazel
 
 SET BAZEL_VS=C:\Program Files\Microsoft Visual Studio\2022\Community
 %BAZEL_EXE% test ... ^

From 3656c2713e08bd5dadae740f71ef37a92336027b Mon Sep 17 00:00:00 2001
From: Derek Mauro 
Date: Tue, 28 Mar 2023 07:02:23 -0700
Subject: [PATCH 55/75] Fix redundant redeclaration warning

Fixes #4200

PiperOrigin-RevId: 520017094
Change-Id: Id707a1c0489edde083771ccd412d7035612474dc
---
 googlemock/include/gmock/internal/gmock-internal-utils.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h
index b5283ed0..d3444386 100644
--- a/googlemock/include/gmock/internal/gmock-internal-utils.h
+++ b/googlemock/include/gmock/internal/gmock-internal-utils.h
@@ -465,8 +465,10 @@ struct Function {
   using MakeResultIgnoredValue = IgnoredValue(Args...);
 };
 
+#ifdef GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL
 template 
 constexpr size_t Function::ArgumentCount;
+#endif
 
 // Workaround for MSVC error C2039: 'type': is not a member of 'std'
 // when std::tuple_element is used.

From 0cd05c6ea982e5db608f81973faca52fe31f6ec3 Mon Sep 17 00:00:00 2001
From: Abseil Team 
Date: Wed, 29 Mar 2023 12:24:40 -0700
Subject: [PATCH 56/75] Update naming to "GoogleTest" in the GoogleTest Primer.

PiperOrigin-RevId: 520409541
Change-Id: I75a0b8615ece923137d4f5dcdb915f38e4c3b1b2
---
 docs/primer.md | 68 +++++++++++++++++++++++++-------------------------
 1 file changed, 34 insertions(+), 34 deletions(-)

diff --git a/docs/primer.md b/docs/primer.md
index d559fe84..31d63160 100644
--- a/docs/primer.md
+++ b/docs/primer.md
@@ -1,44 +1,44 @@
-# Googletest Primer
+# GoogleTest Primer
 
-## Introduction: Why googletest?
+## Introduction: Why GoogleTest?
 
-*googletest* helps you write better C++ tests.
+*GoogleTest* helps you write better C++ tests.
 
-googletest is a testing framework developed by the Testing Technology team with
+GoogleTest is a testing framework developed by the Testing Technology team with
 Google's specific requirements and constraints in mind. Whether you work on
-Linux, Windows, or a Mac, if you write C++ code, googletest can help you. And it
+Linux, Windows, or a Mac, if you write C++ code, GoogleTest can help you. And it
 supports *any* kind of tests, not just unit tests.
 
-So what makes a good test, and how does googletest fit in? We believe:
+So what makes a good test, and how does GoogleTest fit in? We believe:
 
 1.  Tests should be *independent* and *repeatable*. It's a pain to debug a test
-    that succeeds or fails as a result of other tests. googletest isolates the
+    that succeeds or fails as a result of other tests. GoogleTest isolates the
     tests by running each of them on a different object. When a test fails,
-    googletest allows you to run it in isolation for quick debugging.
+    GoogleTest allows you to run it in isolation for quick debugging.
 2.  Tests should be well *organized* and reflect the structure of the tested
-    code. googletest groups related tests into test suites that can share data
+    code. GoogleTest groups related tests into test suites that can share data
     and subroutines. This common pattern is easy to recognize and makes tests
     easy to maintain. Such consistency is especially helpful when people switch
     projects and start to work on a new code base.
 3.  Tests should be *portable* and *reusable*. Google has a lot of code that is
-    platform-neutral; its tests should also be platform-neutral. googletest
+    platform-neutral; its tests should also be platform-neutral. GoogleTest
     works on different OSes, with different compilers, with or without
-    exceptions, so googletest tests can work with a variety of configurations.
+    exceptions, so GoogleTest tests can work with a variety of configurations.
 4.  When tests fail, they should provide as much *information* about the problem
-    as possible. googletest doesn't stop at the first test failure. Instead, it
+    as possible. GoogleTest doesn't stop at the first test failure. Instead, it
     only stops the current test and continues with the next. You can also set up
     tests that report non-fatal failures after which the current test continues.
     Thus, you can detect and fix multiple bugs in a single run-edit-compile
     cycle.
 5.  The testing framework should liberate test writers from housekeeping chores
-    and let them focus on the test *content*. googletest automatically keeps
+    and let them focus on the test *content*. GoogleTest automatically keeps
     track of all tests defined, and doesn't require the user to enumerate them
     in order to run them.
-6.  Tests should be *fast*. With googletest, you can reuse shared resources
+6.  Tests should be *fast*. With GoogleTest, you can reuse shared resources
     across tests and pay for the set-up/tear-down only once, without making
     tests depend on each other.
 
-Since googletest is based on the popular xUnit architecture, you'll feel right
+Since GoogleTest is based on the popular xUnit architecture, you'll feel right
 at home if you've used JUnit or PyUnit before. If not, it will take you about 10
 minutes to learn the basics and get started. So let's go!
 
@@ -48,27 +48,27 @@ minutes to learn the basics and get started. So let's go!
 *Note:* There might be some confusion arising from different definitions of the
 terms *Test*, *Test Case* and *Test Suite*, so beware of misunderstanding these.
 
-Historically, googletest started to use the term *Test Case* for grouping
+Historically, GoogleTest started to use the term *Test Case* for grouping
 related tests, whereas current publications, including International Software
 Testing Qualifications Board ([ISTQB](http://www.istqb.org/)) materials and
 various textbooks on software quality, use the term
 *[Test Suite][istqb test suite]* for this.
 
-The related term *Test*, as it is used in googletest, corresponds to the term
+The related term *Test*, as it is used in GoogleTest, corresponds to the term
 *[Test Case][istqb test case]* of ISTQB and others.
 
 The term *Test* is commonly of broad enough sense, including ISTQB's definition
 of *Test Case*, so it's not much of a problem here. But the term *Test Case* as
 was used in Google Test is of contradictory sense and thus confusing.
 
-googletest recently started replacing the term *Test Case* with *Test Suite*.
+GoogleTest recently started replacing the term *Test Case* with *Test Suite*.
 The preferred API is *TestSuite*. The older TestCase API is being slowly
 deprecated and refactored away.
 
 So please be aware of the different definitions of the terms:
 
 
-Meaning                                                                              | googletest Term         | [ISTQB](http://www.istqb.org/) Term
+Meaning                                                                              | GoogleTest Term         | [ISTQB](http://www.istqb.org/) Term
 :----------------------------------------------------------------------------------- | :---------------------- | :----------------------------------
 Exercise a particular program path with specific input values and verify the results | [TEST()](#simple-tests) | [Test Case][istqb test case]
 
@@ -78,7 +78,7 @@ Exercise a particular program path with specific input values and verify the res
 
 ## Basic Concepts
 
-When using googletest, you start by writing *assertions*, which are statements
+When using GoogleTest, you start by writing *assertions*, which are statements
 that check whether a condition is true. An assertion's result can be *success*,
 *nonfatal failure*, or *fatal failure*. If a fatal failure occurs, it aborts the
 current function; otherwise the program continues normally.
@@ -98,11 +98,11 @@ assertion level and building up to tests and test suites.
 
 ## Assertions
 
-googletest assertions are macros that resemble function calls. You test a class
+GoogleTest assertions are macros that resemble function calls. You test a class
 or function by making assertions about its behavior. When an assertion fails,
-googletest prints the assertion's source file and line number location, along
+GoogleTest prints the assertion's source file and line number location, along
 with a failure message. You may also supply a custom failure message which will
-be appended to googletest's message.
+be appended to GoogleTest's message.
 
 The assertions come in pairs that test the same thing but have different effects
 on the current function. `ASSERT_*` versions generate fatal failures when they
@@ -149,7 +149,7 @@ To create a test:
 1.  Use the `TEST()` macro to define and name a test function. These are
     ordinary C++ functions that don't return a value.
 2.  In this function, along with any valid C++ statements you want to include,
-    use the various googletest assertions to check values.
+    use the various GoogleTest assertions to check values.
 3.  The test's result is determined by the assertions; if any assertion in the
     test fails (either fatally or non-fatally), or if the test crashes, the
     entire test fails. Otherwise, it succeeds.
@@ -190,7 +190,7 @@ TEST(FactorialTest, HandlesPositiveInput) {
 }
 ```
 
-googletest groups the test results by test suites, so logically related tests
+GoogleTest groups the test results by test suites, so logically related tests
 should be in the same test suite; in other words, the first argument to their
 `TEST()` should be the same. In the above example, we have two tests,
 `HandlesZeroInput` and `HandlesPositiveInput`, that belong to the same test
@@ -244,12 +244,12 @@ Also, you must first define a test fixture class before using it in a
 `TEST_F()`, or you'll get the compiler error "`virtual outside class
 declaration`".
 
-For each test defined with `TEST_F()`, googletest will create a *fresh* test
+For each test defined with `TEST_F()`, GoogleTest will create a *fresh* test
 fixture at runtime, immediately initialize it via `SetUp()`, run the test, clean
 up by calling `TearDown()`, and then delete the test fixture. Note that
 different tests in the same test suite have different test fixture objects, and
-googletest always deletes a test fixture before it creates the next one.
-googletest does **not** reuse the same test fixture for multiple tests. Any
+GoogleTest always deletes a test fixture before it creates the next one.
+GoogleTest does **not** reuse the same test fixture for multiple tests. Any
 changes one test makes to the fixture do not affect other tests.
 
 As an example, let's write tests for a FIFO queue class named `Queue`, which has
@@ -325,7 +325,7 @@ would lead to a segfault when `n` is `NULL`.
 
 When these tests run, the following happens:
 
-1.  googletest constructs a `QueueTest` object (let's call it `t1`).
+1.  GoogleTest constructs a `QueueTest` object (let's call it `t1`).
 2.  `t1.SetUp()` initializes `t1`.
 3.  The first test (`IsEmptyInitially`) runs on `t1`.
 4.  `t1.TearDown()` cleans up after the test finishes.
@@ -337,7 +337,7 @@ When these tests run, the following happens:
 
 ## Invoking the Tests
 
-`TEST()` and `TEST_F()` implicitly register their tests with googletest. So,
+`TEST()` and `TEST_F()` implicitly register their tests with GoogleTest. So,
 unlike with many other C++ testing frameworks, you don't have to re-list all
 your defined tests in order to run them.
 
@@ -348,7 +348,7 @@ test suites, or even different source files.
 
 When invoked, the `RUN_ALL_TESTS()` macro:
 
-*   Saves the state of all googletest flags.
+*   Saves the state of all GoogleTest flags.
 
 *   Creates a test fixture object for the first test.
 
@@ -360,7 +360,7 @@ When invoked, the `RUN_ALL_TESTS()` macro:
 
 *   Deletes the fixture.
 
-*   Restores the state of all googletest flags.
+*   Restores the state of all GoogleTest flags.
 
 *   Repeats the above steps for the next test, until all tests have run.
 
@@ -374,7 +374,7 @@ If a fatal failure happens the subsequent steps will be skipped.
 > return the value of `RUN_ALL_TESTS()`.
 >
 > Also, you should call `RUN_ALL_TESTS()` only **once**. Calling it more than
-> once conflicts with some advanced googletest features (e.g., thread-safe
+> once conflicts with some advanced GoogleTest features (e.g., thread-safe
 > [death tests](advanced.md#death-tests)) and thus is not supported.
 
 **Availability**: Linux, Windows, Mac.
@@ -456,7 +456,7 @@ int main(int argc, char **argv) {
 ```
 
 The `::testing::InitGoogleTest()` function parses the command line for
-googletest flags, and removes all recognized flags. This allows the user to
+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.

From b5fd99bbd55ebe1a3488b8ea3717fba089293457 Mon Sep 17 00:00:00 2001
From: Aaron Jacobs 
Date: Thu, 30 Mar 2023 13:34:34 -0700
Subject: [PATCH 57/75] gtest.cc: run tests within a test suite in a
 deterministic order.

Ensure that tests are run in the order specified in the source code, even if
they are registered manually using RegisterTest. There should be no behavior
change for the common case.

PiperOrigin-RevId: 520729483
Change-Id: I400c78400c6929fccae0676214d993251f31888f
---
 googletest/src/gtest.cc | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 7832492d..c2581fa0 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -44,6 +44,7 @@
 #include   // NOLINT
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2981,6 +2982,25 @@ void TestSuite::Run() {
 
   TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
 
+  // Ensure our tests are in a deterministic order.
+  //
+  // We do this by sorting lexicographically on (file, line number), providing
+  // an order matching what the user can see in the source code.
+  //
+  // In the common case the line number comparison shouldn't be necessary,
+  // because the registrations made by the TEST macro are executed in order
+  // within a translation unit. But this is not true of the manual registration
+  // API, and in more exotic scenarios a single file may be part of multiple
+  // translation units.
+  std::stable_sort(test_info_list_.begin(), test_info_list_.end(),
+                   [](const TestInfo* const a, const TestInfo* const b) {
+                     if (const int result = std::strcmp(a->file(), a->file())) {
+                       return result < 0;
+                     }
+
+                     return a->line() < b->line();
+                   });
+
   // Call both legacy and the new API
   repeater->OnTestSuiteStart(*this);
 //  Legacy API is deprecated but still available

From 7ee260c54921571b18b15049304426fe151c1265 Mon Sep 17 00:00:00 2001
From: Abseil Team 
Date: Mon, 3 Apr 2023 14:00:54 -0700
Subject: [PATCH 58/75] Rolled back due to breaking existing tests.

PiperOrigin-RevId: 521555658
Change-Id: I09742faceb82b2b7ceb423e850a8b50d532ad6ff
---
 googletest/src/gtest.cc | 20 --------------------
 1 file changed, 20 deletions(-)

diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index c2581fa0..7832492d 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -44,7 +44,6 @@
 #include   // NOLINT
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -2982,25 +2981,6 @@ void TestSuite::Run() {
 
   TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
 
-  // Ensure our tests are in a deterministic order.
-  //
-  // We do this by sorting lexicographically on (file, line number), providing
-  // an order matching what the user can see in the source code.
-  //
-  // In the common case the line number comparison shouldn't be necessary,
-  // because the registrations made by the TEST macro are executed in order
-  // within a translation unit. But this is not true of the manual registration
-  // API, and in more exotic scenarios a single file may be part of multiple
-  // translation units.
-  std::stable_sort(test_info_list_.begin(), test_info_list_.end(),
-                   [](const TestInfo* const a, const TestInfo* const b) {
-                     if (const int result = std::strcmp(a->file(), a->file())) {
-                       return result < 0;
-                     }
-
-                     return a->line() < b->line();
-                   });
-
   // Call both legacy and the new API
   repeater->OnTestSuiteStart(*this);
 //  Legacy API is deprecated but still available

From 057b4e904fd754135dc19ff557c14036fd316425 Mon Sep 17 00:00:00 2001
From: Abseil Team 
Date: Wed, 5 Apr 2023 13:18:59 -0700
Subject: [PATCH 59/75] gtest.cc: run tests within a test suite in a
 deterministic order.

Ensure that tests are run in the order specified in the source code, even if
they are registered manually using RegisterTest. There should be no behavior
change for the common case.

PiperOrigin-RevId: 522136303
Change-Id: If155e2666780af0e514fbbf5ff2b157d5fe2fef1
---
 googletest/src/gtest.cc | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 7832492d..15cee3f0 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -44,6 +44,7 @@
 #include   // NOLINT
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2981,6 +2982,25 @@ void TestSuite::Run() {
 
   TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
 
+  // Ensure our tests are in a deterministic order.
+  //
+  // We do this by sorting lexicographically on (file, line number), providing
+  // an order matching what the user can see in the source code.
+  //
+  // In the common case the line number comparison shouldn't be necessary,
+  // because the registrations made by the TEST macro are executed in order
+  // within a translation unit. But this is not true of the manual registration
+  // API, and in more exotic scenarios a single file may be part of multiple
+  // translation units.
+  std::stable_sort(test_info_list_.begin(), test_info_list_.end(),
+                   [](const TestInfo* const a, const TestInfo* const b) {
+                     if (const int result = std::strcmp(a->file(), b->file())) {
+                       return result < 0;
+                     }
+
+                     return a->line() < b->line();
+                   });
+
   // Call both legacy and the new API
   repeater->OnTestSuiteStart(*this);
 //  Legacy API is deprecated but still available

From 7f6f9c12adefe8130565b7425dc387d284c009e4 Mon Sep 17 00:00:00 2001
From: Abseil Team 
Date: Tue, 11 Apr 2023 07:41:03 -0700
Subject: [PATCH 60/75] Support --gtest_stream_result_to on macOS

This seems to just have been an oversight. POSIX socket APIs work just
fine on macOS.

Fixes https://github.com/google/googletest/issues/4214.

PiperOrigin-RevId: 523398386
Change-Id: I9d56cd9c6933318c1f0b0024f7fef44122fd0c83
---
 googletest/include/gtest/internal/gtest-port.h | 2 +-
 googletest/test/gtest_help_test.py             | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h
index 7846c9e1..656a2618 100644
--- a/googletest/include/gtest/internal/gtest-port.h
+++ b/googletest/include/gtest/internal/gtest-port.h
@@ -693,7 +693,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
 #if defined(GTEST_OS_LINUX) || defined(GTEST_OS_GNU_KFREEBSD) || \
     defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) ||  \
     defined(GTEST_OS_NETBSD) || defined(GTEST_OS_OPENBSD) ||     \
-    defined(GTEST_OS_GNU_HURD)
+    defined(GTEST_OS_GNU_HURD) || defined(GTEST_OS_MAC)
 #define GTEST_CAN_STREAM_RESULTS_ 1
 #else
 #define GTEST_CAN_STREAM_RESULTS_ 0
diff --git a/googletest/test/gtest_help_test.py b/googletest/test/gtest_help_test.py
index fda40bff..9261b87a 100755
--- a/googletest/test/gtest_help_test.py
+++ b/googletest/test/gtest_help_test.py
@@ -43,6 +43,7 @@ import sys
 from googletest.test import gtest_test_utils
 
 
+IS_DARWIN = os.name == 'posix' and os.uname()[0] == 'Darwin'
 IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
 IS_GNUHURD = os.name == 'posix' and os.uname()[0] == 'GNU'
 IS_GNUKFREEBSD = os.name == 'posix' and os.uname()[0] == 'GNU/kFreeBSD'
@@ -136,7 +137,7 @@ class GTestHelpTest(gtest_test_utils.TestCase):
 
     self.assertTrue(HELP_REGEX.search(output), output)
 
-    if IS_LINUX or IS_GNUHURD or IS_GNUKFREEBSD or IS_OPENBSD:
+    if IS_DARWIN or IS_LINUX or IS_GNUHURD or IS_GNUKFREEBSD or IS_OPENBSD:
       self.assertIn(STREAM_RESULT_TO_FLAG, output)
     else:
       self.assertNotIn(STREAM_RESULT_TO_FLAG, output)

From 8fa9461cc28e053d66f17132808d287ae51575e2 Mon Sep 17 00:00:00 2001
From: Abseil Team 
Date: Tue, 11 Apr 2023 10:54:26 -0700
Subject: [PATCH 61/75] Fix FunctionMocker compilation slowdown in
 9d21db9e0a60a1ea61ec19331c9bc0dd33e907b1

The slowdown appears to be due to an implicit conversion of distinct (yet semantically identical) lambdas to `std::function`. Lifting out the lambdas into functors that don't get re-instantiated reduces compilation times by nearly half.

Fixes #4156

PiperOrigin-RevId: 523447948
Change-Id: Ib0ae0761a54d7b1f2b706b14b2858eedf47e2297
---
 .../include/gmock/gmock-spec-builders.h       | 73 ++++++++++++++-----
 1 file changed, 55 insertions(+), 18 deletions(-)

diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h
index 4e498d8f..2a33acb1 100644
--- a/googlemock/include/gmock/gmock-spec-builders.h
+++ b/googlemock/include/gmock/gmock-spec-builders.h
@@ -204,6 +204,9 @@ class GTEST_API_ UntypedFunctionMockerBase {
 
   using UntypedExpectations = std::vector>;
 
+  struct UninterestingCallCleanupHandler;
+  struct FailureCleanupHandler;
+
   // Returns an Expectation object that references and co-owns exp,
   // which must be an expectation on this mock function.
   Expectation GetHandleOf(ExpectationBase* exp);
@@ -1396,6 +1399,41 @@ class Cleanup final {
   std::function f_;
 };
 
+struct UntypedFunctionMockerBase::UninterestingCallCleanupHandler {
+  CallReaction reaction;
+  std::stringstream& ss;
+
+  ~UninterestingCallCleanupHandler() {
+    ReportUninterestingCall(reaction, ss.str());
+  }
+};
+
+struct UntypedFunctionMockerBase::FailureCleanupHandler {
+  std::stringstream& ss;
+  std::stringstream& why;
+  std::stringstream& loc;
+  const ExpectationBase* untyped_expectation;
+  bool found;
+  bool is_excessive;
+
+  ~FailureCleanupHandler() {
+    ss << "\n" << why.str();
+
+    if (!found) {
+      // No expectation matches this call - reports a failure.
+      Expect(false, nullptr, -1, ss.str());
+    } else if (is_excessive) {
+      // We had an upper-bound violation and the failure message is in ss.
+      Expect(false, untyped_expectation->file(), untyped_expectation->line(),
+             ss.str());
+    } else {
+      // We had an expected call and the matching expectation is
+      // described in ss.
+      Log(kInfo, loc.str() + ss.str(), 2);
+    }
+  }
+};
+
 template 
 class FunctionMocker;
 
@@ -1794,8 +1832,15 @@ R FunctionMocker::InvokeWith(ArgumentTuple&& args)
     //
     // We use RAII to do the latter in case R is void or a non-moveable type. In
     // either case we can't assign it to a local variable.
-    const Cleanup report_uninteresting_call(
-        [&] { ReportUninterestingCall(reaction, ss.str()); });
+    //
+    // Note that std::bind() is essential here.
+    // We *don't* use any local callback types (like lambdas).
+    // Doing so slows down compilation dramatically because the *constructor* of
+    // std::function is re-instantiated with different template
+    // parameters each time.
+    const UninterestingCallCleanupHandler report_uninteresting_call = {
+        reaction, ss
+    };
 
     return PerformActionAndPrintResult(nullptr, std::move(args), ss.str(), ss);
   }
@@ -1839,22 +1884,14 @@ R FunctionMocker::InvokeWith(ArgumentTuple&& args)
   //
   // We use RAII to do the latter in case R is void or a non-moveable type. In
   // either case we can't assign it to a local variable.
-  const Cleanup handle_failures([&] {
-    ss << "\n" << why.str();
-
-    if (!found) {
-      // No expectation matches this call - reports a failure.
-      Expect(false, nullptr, -1, ss.str());
-    } else if (is_excessive) {
-      // We had an upper-bound violation and the failure message is in ss.
-      Expect(false, untyped_expectation->file(), untyped_expectation->line(),
-             ss.str());
-    } else {
-      // We had an expected call and the matching expectation is
-      // described in ss.
-      Log(kInfo, loc.str() + ss.str(), 2);
-    }
-  });
+  //
+  // Note that we *don't* use any local callback types (like lambdas) here.
+  // Doing so slows down compilation dramatically because the *constructor* of
+  // std::function is re-instantiated with different template
+  // parameters each time.
+  const FailureCleanupHandler handle_failures = {
+      ss, why, loc, untyped_expectation, found, is_excessive
+  };
 
   return PerformActionAndPrintResult(untyped_action, std::move(args), ss.str(),
                                      ss);

From 952560d3ec06eae08347d5e54faa8e3192d41b4d Mon Sep 17 00:00:00 2001
From: Jeryl Vaz 
Date: Fri, 14 Apr 2023 11:15:21 +0200
Subject: [PATCH 62/75] Suppress a clang-tidy warning in the MATCHER_P macro

---
 googlemock/include/gmock/gmock-matchers.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h
index 7c5d65cf..8936e497 100644
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -5544,6 +5544,7 @@ PolymorphicMatcher> ThrowsMessage(
                                                                                \
      private:                                                                  \
       ::std::string FormatDescription(bool negation) const {                   \
+        /* NOLINTNEXTLINE readability-redundant-string-init */                 \
         ::std::string gmock_description = (description);                       \
         if (!gmock_description.empty()) {                                      \
           return gmock_description;                                            \

From 922e0b7d805f5668b68762552f5cca9b3225acd5 Mon Sep 17 00:00:00 2001
From: Abseil Team 
Date: Mon, 17 Apr 2023 09:30:58 -0700
Subject: [PATCH 63/75] Update gMock Cookbook to reflect deprecation of
 testing::ByMove

PiperOrigin-RevId: 524868227
Change-Id: I702ede27570e3d3f06d534d6ccf8b39689105d07
---
 docs/gmock_cook_book.md | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/docs/gmock_cook_book.md b/docs/gmock_cook_book.md
index d11282fa..d57be58d 100644
--- a/docs/gmock_cook_book.md
+++ b/docs/gmock_cook_book.md
@@ -2781,26 +2781,21 @@ action:
 If you are not happy with the default action, you can tweak it as usual; see
 [Setting Default Actions](#OnCall).
 
-If you just need to return a pre-defined move-only value, you can use the
-`Return(ByMove(...))` action:
+If you just need to return a move-only value, you can use it in combination with
+`WillOnce`. For example:
 
 ```cpp
-  // When this fires, the unique_ptr<> specified by ByMove(...) will
-  // be returned.
-  EXPECT_CALL(mock_buzzer_, MakeBuzz("world"))
-      .WillOnce(Return(ByMove(std::make_unique(AccessLevel::kInternal))));
-
-  EXPECT_NE(nullptr, mock_buzzer_.MakeBuzz("world"));
+  EXPECT_CALL(mock_buzzer_, MakeBuzz("hello"))
+      .WillOnce(Return(std::make_unique(AccessLevel::kInternal)));
+  EXPECT_NE(nullptr, mock_buzzer_.MakeBuzz("hello"));
 ```
 
-Note that `ByMove()` is essential here - if you drop it, the code won’t compile.
-
-Quiz time! What do you think will happen if a `Return(ByMove(...))` action is
-performed more than once (e.g. you write `...
-.WillRepeatedly(Return(ByMove(...)));`)? Come think of it, after the first time
-the action runs, the source value will be consumed (since it’s a move-only
-value), so the next time around, there’s no value to move from -- you’ll get a
-run-time error that `Return(ByMove(...))` can only be run once.
+Quiz time! What do you think will happen if a `Return` action is performed more
+than once (e.g. you write `... .WillRepeatedly(Return(std::move(...)));`)? Come
+think of it, after the first time the action runs, the source value will be
+consumed (since it’s a move-only value), so the next time around, there’s no
+value to move from -- you’ll get a run-time error that `Return(std::move(...))`
+can only be run once.
 
 If you need your mock method to do more than just moving a pre-defined value,
 remember that you can always use a lambda or a callable object, which can do
@@ -2817,7 +2812,7 @@ pretty much anything you want:
 ```
 
 Every time this `EXPECT_CALL` fires, a new `unique_ptr` will be created
-and returned. You cannot do this with `Return(ByMove(...))`.
+and returned. You cannot do this with `Return(std::make_unique<...>(...))`.
 
 That covers returning move-only values; but how do we work with methods
 accepting move-only arguments? The answer is that they work normally, although
@@ -4298,7 +4293,7 @@ particular type than to dump the bytes.
 ### Mock std::function {#MockFunction}
 
 `std::function` is a general function type introduced in C++11. It is a
-preferred way of passing callbacks to new interfaces. Functions are copiable,
+preferred way of passing callbacks to new interfaces. Functions are copyable,
 and are not usually passed around by pointer, which makes them tricky to mock.
 But fear not - `MockFunction` can help you with that.
 

From 01bcf8c70dc0e4609d71540cb50ada3850b7a54e Mon Sep 17 00:00:00 2001
From: Tom Hughes 
Date: Thu, 20 Apr 2023 08:21:57 -0700
Subject: [PATCH 64/75] Make parameter names in function declaration match the
 names in the definitions

https://clang.llvm.org/extra/clang-tidy/checks/readability/inconsistent-declaration-parameter-name.html

PiperOrigin-RevId: 525752102
Change-Id: Ibf9d3d1dbae8f95cfc7c6ad29fe4b677f4ee19cf
---
 googletest/src/gtest.cc | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 15cee3f0..da52b1d1 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -3782,28 +3782,28 @@ class TestEventRepeater : public TestEventListener {
   bool forwarding_enabled() const { return forwarding_enabled_; }
   void set_forwarding_enabled(bool enable) { forwarding_enabled_ = enable; }
 
-  void OnTestProgramStart(const UnitTest& unit_test) override;
+  void OnTestProgramStart(const UnitTest& parameter) override;
   void OnTestIterationStart(const UnitTest& unit_test, int iteration) override;
-  void OnEnvironmentsSetUpStart(const UnitTest& unit_test) override;
-  void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) override;
+  void OnEnvironmentsSetUpStart(const UnitTest& parameter) override;
+  void OnEnvironmentsSetUpEnd(const UnitTest& parameter) override;
 //  Legacy API is deprecated but still available
 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
   void OnTestCaseStart(const TestSuite& parameter) override;
 #endif  //  GTEST_REMOVE_LEGACY_TEST_CASEAPI_
   void OnTestSuiteStart(const TestSuite& parameter) override;
-  void OnTestStart(const TestInfo& test_info) override;
-  void OnTestDisabled(const TestInfo& test_info) override;
-  void OnTestPartResult(const TestPartResult& result) override;
-  void OnTestEnd(const TestInfo& test_info) override;
+  void OnTestStart(const TestInfo& parameter) override;
+  void OnTestDisabled(const TestInfo& parameter) override;
+  void OnTestPartResult(const TestPartResult& parameter) override;
+  void OnTestEnd(const TestInfo& parameter) override;
 //  Legacy API is deprecated but still available
 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
   void OnTestCaseEnd(const TestCase& parameter) override;
 #endif  //  GTEST_REMOVE_LEGACY_TEST_CASEAPI_
   void OnTestSuiteEnd(const TestSuite& parameter) override;
-  void OnEnvironmentsTearDownStart(const UnitTest& unit_test) override;
-  void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) override;
+  void OnEnvironmentsTearDownStart(const UnitTest& parameter) override;
+  void OnEnvironmentsTearDownEnd(const UnitTest& parameter) override;
   void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override;
-  void OnTestProgramEnd(const UnitTest& unit_test) override;
+  void OnTestProgramEnd(const UnitTest& parameter) override;
 
  private:
   // Controls whether events will be forwarded to listeners_. Set to false

From d8a5fb7ee6373b9f4429a2beb5c1ef22d9f8b5b3 Mon Sep 17 00:00:00 2001
From: Tom Hughes 
Date: Thu, 20 Apr 2023 11:01:16 -0700
Subject: [PATCH 65/75] Add missing std includes

PiperOrigin-RevId: 525794940
Change-Id: Ib2639058610c91cbffbb0f22a5e71573e0cbd651
---
 .../test/googletest-json-outfiles-test.py     |  2 +-
 .../test/googletest-json-output-unittest.py   | 54 ++++++++---------
 googletest/test/googletest-output-test_.cc    |  3 +
 googletest/test/gtest_xml_outfile2_test_.cc   |  2 +
 googletest/test/gtest_xml_outfiles_test.py    |  2 +-
 googletest/test/gtest_xml_output_unittest.py  | 60 +++++++++----------
 googletest/test/gtest_xml_output_unittest_.cc |  2 +
 7 files changed, 66 insertions(+), 59 deletions(-)

diff --git a/googletest/test/googletest-json-outfiles-test.py b/googletest/test/googletest-json-outfiles-test.py
index ff157223..5626004e 100644
--- a/googletest/test/googletest-json-outfiles-test.py
+++ b/googletest/test/googletest-json-outfiles-test.py
@@ -90,7 +90,7 @@ EXPECTED_2 = {
         'testsuite': [{
             'name': 'TestInt64ConvertibleProperties',
             'file': 'gtest_xml_outfile2_test_.cc',
-            'line': 41,
+            'line': 43,
             'status': 'RUN',
             'result': 'COMPLETED',
             'timestamp': '*',
diff --git a/googletest/test/googletest-json-output-unittest.py b/googletest/test/googletest-json-output-unittest.py
index e955e7b0..cb976945 100644
--- a/googletest/test/googletest-json-output-unittest.py
+++ b/googletest/test/googletest-json-output-unittest.py
@@ -77,7 +77,7 @@ EXPECTED_NON_EMPTY = {
             'testsuite': [{
                 'name': 'Succeeds',
                 'file': 'gtest_xml_output_unittest_.cc',
-                'line': 51,
+                'line': 53,
                 'status': 'RUN',
                 'result': 'COMPLETED',
                 'time': '*',
@@ -96,7 +96,7 @@ EXPECTED_NON_EMPTY = {
             'testsuite': [{
                 'name': 'Fails',
                 'file': 'gtest_xml_output_unittest_.cc',
-                'line': 59,
+                'line': 61,
                 'status': 'RUN',
                 'result': 'COMPLETED',
                 'time': '*',
@@ -124,7 +124,7 @@ EXPECTED_NON_EMPTY = {
             'testsuite': [{
                 'name': 'DISABLED_test_not_run',
                 'file': 'gtest_xml_output_unittest_.cc',
-                'line': 66,
+                'line': 68,
                 'status': 'NOTRUN',
                 'result': 'SUPPRESSED',
                 'time': '*',
@@ -144,7 +144,7 @@ EXPECTED_NON_EMPTY = {
                 {
                     'name': 'Skipped',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 73,
+                    'line': 75,
                     'status': 'RUN',
                     'result': 'SKIPPED',
                     'time': '*',
@@ -154,7 +154,7 @@ EXPECTED_NON_EMPTY = {
                 {
                     'name': 'SkippedWithMessage',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 77,
+                    'line': 79,
                     'status': 'RUN',
                     'result': 'SKIPPED',
                     'time': '*',
@@ -164,7 +164,7 @@ EXPECTED_NON_EMPTY = {
                 {
                     'name': 'SkippedAfterFailure',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 81,
+                    'line': 83,
                     'status': 'RUN',
                     'result': 'COMPLETED',
                     'time': '*',
@@ -194,7 +194,7 @@ EXPECTED_NON_EMPTY = {
                 {
                     'name': 'Succeeds',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 86,
+                    'line': 88,
                     'status': 'RUN',
                     'result': 'COMPLETED',
                     'time': '*',
@@ -204,7 +204,7 @@ EXPECTED_NON_EMPTY = {
                 {
                     'name': 'Fails',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 91,
+                    'line': 93,
                     'status': 'RUN',
                     'result': 'COMPLETED',
                     'time': '*',
@@ -234,7 +234,7 @@ EXPECTED_NON_EMPTY = {
                 {
                     'name': 'DISABLED_test',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 96,
+                    'line': 98,
                     'status': 'NOTRUN',
                     'result': 'SUPPRESSED',
                     'time': '*',
@@ -254,7 +254,7 @@ EXPECTED_NON_EMPTY = {
             'testsuite': [{
                 'name': 'OutputsCData',
                 'file': 'gtest_xml_output_unittest_.cc',
-                'line': 100,
+                'line': 102,
                 'status': 'RUN',
                 'result': 'COMPLETED',
                 'time': '*',
@@ -282,7 +282,7 @@ EXPECTED_NON_EMPTY = {
             'testsuite': [{
                 'name': 'InvalidCharactersInMessage',
                 'file': 'gtest_xml_output_unittest_.cc',
-                'line': 107,
+                'line': 109,
                 'status': 'RUN',
                 'result': 'COMPLETED',
                 'time': '*',
@@ -313,7 +313,7 @@ EXPECTED_NON_EMPTY = {
                 {
                     'name': 'OneProperty',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 119,
+                    'line': 121,
                     'status': 'RUN',
                     'result': 'COMPLETED',
                     'time': '*',
@@ -324,7 +324,7 @@ EXPECTED_NON_EMPTY = {
                 {
                     'name': 'IntValuedProperty',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 123,
+                    'line': 125,
                     'status': 'RUN',
                     'result': 'COMPLETED',
                     'time': '*',
@@ -335,7 +335,7 @@ EXPECTED_NON_EMPTY = {
                 {
                     'name': 'ThreeProperties',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 127,
+                    'line': 129,
                     'status': 'RUN',
                     'result': 'COMPLETED',
                     'time': '*',
@@ -348,7 +348,7 @@ EXPECTED_NON_EMPTY = {
                 {
                     'name': 'TwoValuesForOneKeyUsesLastValue',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 133,
+                    'line': 135,
                     'status': 'RUN',
                     'result': 'COMPLETED',
                     'time': '*',
@@ -370,7 +370,7 @@ EXPECTED_NON_EMPTY = {
                 {
                     'name': 'RecordProperty',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 138,
+                    'line': 140,
                     'status': 'RUN',
                     'result': 'COMPLETED',
                     'time': '*',
@@ -381,7 +381,7 @@ EXPECTED_NON_EMPTY = {
                 {
                     'name': 'ExternalUtilityThatCallsRecordIntValuedProperty',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 151,
+                    'line': 153,
                     'status': 'RUN',
                     'result': 'COMPLETED',
                     'time': '*',
@@ -394,7 +394,7 @@ EXPECTED_NON_EMPTY = {
                         'ExternalUtilityThatCallsRecordStringValuedProperty'
                     ),
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 155,
+                    'line': 157,
                     'status': 'RUN',
                     'result': 'COMPLETED',
                     'time': '*',
@@ -416,7 +416,7 @@ EXPECTED_NON_EMPTY = {
                 'name': 'HasTypeParamAttribute',
                 'type_param': 'int',
                 'file': 'gtest_xml_output_unittest_.cc',
-                'line': 171,
+                'line': 173,
                 'status': 'RUN',
                 'result': 'COMPLETED',
                 'time': '*',
@@ -436,7 +436,7 @@ EXPECTED_NON_EMPTY = {
                 'name': 'HasTypeParamAttribute',
                 'type_param': 'long',
                 'file': 'gtest_xml_output_unittest_.cc',
-                'line': 171,
+                'line': 173,
                 'status': 'RUN',
                 'result': 'COMPLETED',
                 'time': '*',
@@ -456,7 +456,7 @@ EXPECTED_NON_EMPTY = {
                 'name': 'HasTypeParamAttribute',
                 'type_param': 'int',
                 'file': 'gtest_xml_output_unittest_.cc',
-                'line': 178,
+                'line': 180,
                 'status': 'RUN',
                 'result': 'COMPLETED',
                 'time': '*',
@@ -476,7 +476,7 @@ EXPECTED_NON_EMPTY = {
                 'name': 'HasTypeParamAttribute',
                 'type_param': 'long',
                 'file': 'gtest_xml_output_unittest_.cc',
-                'line': 178,
+                'line': 180,
                 'status': 'RUN',
                 'result': 'COMPLETED',
                 'time': '*',
@@ -497,7 +497,7 @@ EXPECTED_NON_EMPTY = {
                     'name': 'HasValueParamAttribute/0',
                     'value_param': '33',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 162,
+                    'line': 164,
                     'status': 'RUN',
                     'result': 'COMPLETED',
                     'time': '*',
@@ -508,7 +508,7 @@ EXPECTED_NON_EMPTY = {
                     'name': 'HasValueParamAttribute/1',
                     'value_param': '42',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 162,
+                    'line': 164,
                     'status': 'RUN',
                     'result': 'COMPLETED',
                     'time': '*',
@@ -519,7 +519,7 @@ EXPECTED_NON_EMPTY = {
                     'name': 'AnotherTestThatHasValueParamAttribute/0',
                     'value_param': '33',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 163,
+                    'line': 165,
                     'status': 'RUN',
                     'result': 'COMPLETED',
                     'time': '*',
@@ -530,7 +530,7 @@ EXPECTED_NON_EMPTY = {
                     'name': 'AnotherTestThatHasValueParamAttribute/1',
                     'value_param': '42',
                     'file': 'gtest_xml_output_unittest_.cc',
-                    'line': 163,
+                    'line': 165,
                     'status': 'RUN',
                     'result': 'COMPLETED',
                     'time': '*',
@@ -562,7 +562,7 @@ EXPECTED_FILTERED = {
         'testsuite': [{
             'name': 'Succeeds',
             'file': 'gtest_xml_output_unittest_.cc',
-            'line': 51,
+            'line': 53,
             'status': 'RUN',
             'result': 'COMPLETED',
             'time': '*',
diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc
index 44d0fc13..f1facf57 100644
--- a/googletest/test/googletest-output-test_.cc
+++ b/googletest/test/googletest-output-test_.cc
@@ -35,6 +35,9 @@
 
 #include 
 
+#include 
+#include 
+
 #include "gtest/gtest-spi.h"
 #include "gtest/gtest.h"
 #include "src/gtest-internal-inl.h"
diff --git a/googletest/test/gtest_xml_outfile2_test_.cc b/googletest/test/gtest_xml_outfile2_test_.cc
index ed58dc8d..4a76429c 100644
--- a/googletest/test/gtest_xml_outfile2_test_.cc
+++ b/googletest/test/gtest_xml_outfile2_test_.cc
@@ -30,6 +30,8 @@
 // gtest_xml_outfile2_test_ writes some xml via TestProperty used by
 // gtest_xml_outfiles_test.py
 
+#include 
+
 #include "gtest/gtest.h"
 
 class PropertyTwo : public testing::Test {
diff --git a/googletest/test/gtest_xml_outfiles_test.py b/googletest/test/gtest_xml_outfiles_test.py
index 50291b0a..d17cc0c9 100755
--- a/googletest/test/gtest_xml_outfiles_test.py
+++ b/googletest/test/gtest_xml_outfiles_test.py
@@ -57,7 +57,7 @@ EXPECTED_XML_1 = """
 EXPECTED_XML_2 = """
 
   
-    
+    
       
         
         
diff --git a/googletest/test/gtest_xml_output_unittest.py b/googletest/test/gtest_xml_output_unittest.py
index e7e44fc1..422569e4 100755
--- a/googletest/test/gtest_xml_output_unittest.py
+++ b/googletest/test/gtest_xml_output_unittest.py
@@ -69,10 +69,10 @@ else:
 EXPECTED_NON_EMPTY_XML = """
 
   
-    
+    
   
   
-    
+    
       
   
   
-    
-    
+    
+    
       
     
-    
+    
   
   
-    
+    
       ]]>%(stack)s]]>
     
   
   
-    
+    
       
     
   
   
-    
+    
   
   
-    
+    
       
     
-    
+    
       
     
-    
+    
       
 
   
   
-    
+    
       
         
       
     
-    
+    
       
         
       
     
-    
+    
       
         
         
         
       
     
-    
+    
       
         
       
     
   
   
-     
+     
        
          
        
      
-     
+     
        
          
        
      
-     
+     
        
          
        
      
   
   
-    
-    
-    
-    
+    
+    
+    
+    
   
   
-    
+    
   
   
-    
+    
   
   
-    
+    
   
   
-    
+    
   
 """ % {
     'stack': STACK_TRACE_TEMPLATE,
@@ -198,24 +198,24 @@ EXPECTED_FILTERED_TEST_XML = """
             timestamp="*" name="AllTests" ad_hoc_property="42">
   
-    
+    
   
 """
 
 EXPECTED_SHARDED_TEST_XML = """
 
   
-    
+    
   
   
-    
+    
       
         
       
     
   
   
-    
+    
   
 """
 
diff --git a/googletest/test/gtest_xml_output_unittest_.cc b/googletest/test/gtest_xml_output_unittest_.cc
index 4bdb0c7e..0ab33022 100644
--- a/googletest/test/gtest_xml_output_unittest_.cc
+++ b/googletest/test/gtest_xml_output_unittest_.cc
@@ -37,6 +37,8 @@
 // directly.
 // clang-format off
 
+#include 
+
 #include "gtest/gtest.h"
 
 using ::testing::InitGoogleTest;

From d7fb5e1af4a4840f28e442cb5414766d4fb17522 Mon Sep 17 00:00:00 2001
From: Tom Hughes 
Date: Thu, 20 Apr 2023 12:35:42 -0700
Subject: [PATCH 66/75] Fix spelling

PiperOrigin-RevId: 525820426
Change-Id: Ib5baa8da4a54ebb17b6ace12240ed03eedb46091
---
 googletest/test/googletest-port-test.cc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc
index 1ba3f502..94bb8e38 100644
--- a/googletest/test/googletest-port-test.cc
+++ b/googletest/test/googletest-port-test.cc
@@ -979,14 +979,14 @@ TEST(ThreadLocalTest, SingleParamConstructorInitializesToParam) {
   EXPECT_EQ(&i, t2.get());
 }
 
-class NoDefaultContructor {
+class NoDefaultConstructor {
  public:
-  explicit NoDefaultContructor(const char*) {}
-  NoDefaultContructor(const NoDefaultContructor&) {}
+  explicit NoDefaultConstructor(const char*) {}
+  NoDefaultConstructor(const NoDefaultConstructor&) {}
 };
 
 TEST(ThreadLocalTest, ValueDefaultContructorIsNotRequiredForParamVersion) {
-  ThreadLocal bar(NoDefaultContructor("foo"));
+  ThreadLocal bar(NoDefaultConstructor("foo"));
   bar.pointer();
 }
 

From 9c1efac2a1b6d836ef35e1dfb87b7addca361afe Mon Sep 17 00:00:00 2001
From: Tom Hughes 
Date: Thu, 20 Apr 2023 13:08:47 -0700
Subject: [PATCH 67/75] Use std::make_unique

PiperOrigin-RevId: 525828947
Change-Id: I66f47c835bc93ba171eba0da8df09eff89c6c77b
---
 googletest/include/gtest/gtest-assertion-result.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/googletest/include/gtest/gtest-assertion-result.h b/googletest/include/gtest/gtest-assertion-result.h
index 62fbea6e..56fe128f 100644
--- a/googletest/include/gtest/gtest-assertion-result.h
+++ b/googletest/include/gtest/gtest-assertion-result.h
@@ -204,7 +204,7 @@ class GTEST_API_ AssertionResult {
  private:
   // Appends the contents of message to message_.
   void AppendMessage(const Message& a_message) {
-    if (message_ == nullptr) message_.reset(new ::std::string);
+    if (message_ == nullptr) message_ = ::std::make_unique<::std::string>();
     message_->append(a_message.GetString().c_str());
   }
 

From a5308bb992c049b16b763f8910da70c208c5cede Mon Sep 17 00:00:00 2001
From: Tom Hughes 
Date: Thu, 20 Apr 2023 14:28:27 -0700
Subject: [PATCH 68/75] Add missing std includes

PiperOrigin-RevId: 525850646
Change-Id: I64387f5b933beb79cd05636dca81b7a75213383e
---
 googlemock/include/gmock/gmock-matchers.h            |  1 +
 googlemock/src/gmock-internal-utils.cc               |  1 +
 googlemock/src/gmock-spec-builders.cc                |  1 +
 googlemock/src/gmock.cc                              |  2 ++
 googlemock/test/gmock-actions_test.cc                |  3 +++
 googlemock/test/gmock-cardinalities_test.cc          |  2 ++
 googlemock/test/gmock-internal-utils_test.cc         |  1 +
 googlemock/test/gmock-matchers-arithmetic_test.cc    |  3 +++
 googlemock/test/gmock-matchers-comparisons_test.cc   |  3 +++
 googlemock/test/gmock-matchers-containers_test.cc    | 12 ++++++++++++
 googlemock/test/gmock-matchers-misc_test.cc          |  8 ++++++++
 googlemock/test/gmock-more-actions_test.cc           |  4 ++++
 googlemock/test/gmock_ex_test.cc                     |  2 ++
 googletest/samples/sample8_unittest.cc               |  2 ++
 googletest/src/gtest-death-test.cc                   |  2 ++
 googletest/src/gtest-filepath.cc                     |  3 +++
 googletest/src/gtest-port.cc                         |  4 ++++
 googletest/src/gtest-printers.cc                     |  2 ++
 googletest/src/gtest-test-part.cc                    |  3 +++
 googletest/src/gtest-typed-test.cc                   |  4 ++++
 googletest/src/gtest.cc                              |  3 +++
 googletest/test/googletest-death-test-test.cc        |  3 +++
 googletest/test/googletest-list-tests-unittest_.cc   |  3 +++
 googletest/test/googletest-listener-test.cc          |  1 +
 .../googletest-param-test-invalid-name2-test_.cc     |  2 ++
 googletest/test/googletest-printers-test.cc          |  2 ++
 googletest/test/gtest_stress_test.cc                 |  2 ++
 googletest/test/gtest_unittest.cc                    |  1 +
 28 files changed, 80 insertions(+)

diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h
index fb9f15e8..0f677137 100644
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -257,6 +257,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc
index 774cce33..5c2ce0d5 100644
--- a/googlemock/src/gmock-internal-utils.cc
+++ b/googlemock/src/gmock-internal-utils.cc
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 #include   // NOLINT
 #include 
 #include 
diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc
index 5a98fafd..df0660b1 100644
--- a/googlemock/src/gmock-spec-builders.cc
+++ b/googlemock/src/gmock-spec-builders.cc
@@ -40,6 +40,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/googlemock/src/gmock.cc b/googlemock/src/gmock.cc
index 5025656a..b5e714da 100644
--- a/googlemock/src/gmock.cc
+++ b/googlemock/src/gmock.cc
@@ -29,6 +29,8 @@
 
 #include "gmock/gmock.h"
 
+#include 
+
 #include "gmock/internal/gmock-port.h"
 
 GMOCK_DEFINE_bool_(catch_leaked_mocks, true,
diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc
index ee9b889b..f2305e52 100644
--- a/googlemock/test/gmock-actions_test.cc
+++ b/googlemock/test/gmock-actions_test.cc
@@ -37,8 +37,11 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
+#include 
 #include 
 
 #include "gmock/gmock.h"
diff --git a/googlemock/test/gmock-cardinalities_test.cc b/googlemock/test/gmock-cardinalities_test.cc
index cdd99563..77196d7a 100644
--- a/googlemock/test/gmock-cardinalities_test.cc
+++ b/googlemock/test/gmock-cardinalities_test.cc
@@ -31,6 +31,8 @@
 //
 // This file tests the built-in cardinalities.
 
+#include 
+
 #include "gmock/gmock.h"
 #include "gtest/gtest-spi.h"
 #include "gtest/gtest.h"
diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc
index 360d02ae..6c769a88 100644
--- a/googlemock/test/gmock-internal-utils_test.cc
+++ b/googlemock/test/gmock-internal-utils_test.cc
@@ -40,6 +40,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "gmock/gmock.h"
diff --git a/googlemock/test/gmock-matchers-arithmetic_test.cc b/googlemock/test/gmock-matchers-arithmetic_test.cc
index 2c5f4d0b..062e2ab3 100644
--- a/googlemock/test/gmock-matchers-arithmetic_test.cc
+++ b/googlemock/test/gmock-matchers-arithmetic_test.cc
@@ -31,7 +31,10 @@
 //
 // This file tests some commonly used argument matchers.
 
+#include 
 #include 
+#include 
+#include 
 
 #include "test/gmock-matchers_test.h"
 
diff --git a/googlemock/test/gmock-matchers-comparisons_test.cc b/googlemock/test/gmock-matchers-comparisons_test.cc
index b849990d..cf85eb56 100644
--- a/googlemock/test/gmock-matchers-comparisons_test.cc
+++ b/googlemock/test/gmock-matchers-comparisons_test.cc
@@ -31,7 +31,10 @@
 //
 // This file tests some commonly used argument matchers.
 
+#include 
 #include 
+#include 
+#include 
 #include 
 
 #include "test/gmock-matchers_test.h"
diff --git a/googlemock/test/gmock-matchers-containers_test.cc b/googlemock/test/gmock-matchers-containers_test.cc
index c8d8ea37..654a011a 100644
--- a/googlemock/test/gmock-matchers-containers_test.cc
+++ b/googlemock/test/gmock-matchers-containers_test.cc
@@ -31,6 +31,18 @@
 //
 // This file tests some commonly used argument matchers.
 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
 #include "gtest/gtest.h"
 
 // Silence warning C4244: 'initializing': conversion from 'int' to 'short',
diff --git a/googlemock/test/gmock-matchers-misc_test.cc b/googlemock/test/gmock-matchers-misc_test.cc
index 0c7aa499..b8f64587 100644
--- a/googlemock/test/gmock-matchers-misc_test.cc
+++ b/googlemock/test/gmock-matchers-misc_test.cc
@@ -31,6 +31,14 @@
 //
 // This file tests some commonly used argument matchers.
 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
 #include "gtest/gtest.h"
 
 // Silence warning C4244: 'initializing': conversion from 'int' to 'short',
diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc
index 866e1aba..ec7aea61 100644
--- a/googlemock/test/gmock-more-actions_test.cc
+++ b/googlemock/test/gmock-more-actions_test.cc
@@ -33,10 +33,14 @@
 
 #include "gmock/gmock-more-actions.h"
 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include "gmock/gmock.h"
 #include "gtest/gtest-spi.h"
diff --git a/googlemock/test/gmock_ex_test.cc b/googlemock/test/gmock_ex_test.cc
index 44e5e35f..e174122d 100644
--- a/googlemock/test/gmock_ex_test.cc
+++ b/googlemock/test/gmock_ex_test.cc
@@ -29,6 +29,8 @@
 
 // Tests Google Mock's functionality that depends on exceptions.
 
+#include 
+
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
diff --git a/googletest/samples/sample8_unittest.cc b/googletest/samples/sample8_unittest.cc
index 9717e286..4df81df0 100644
--- a/googletest/samples/sample8_unittest.cc
+++ b/googletest/samples/sample8_unittest.cc
@@ -32,6 +32,8 @@
 // and each test is given one combination as a parameter.
 
 // Use class definitions to test from this header.
+#include 
+
 #include "prime_tables.h"
 #include "gtest/gtest.h"
 namespace {
diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc
index 0b87ba5b..55b95782 100644
--- a/googletest/src/gtest-death-test.cc
+++ b/googletest/src/gtest-death-test.cc
@@ -34,6 +34,8 @@
 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 
diff --git a/googletest/src/gtest-filepath.cc b/googletest/src/gtest-filepath.cc
index 48dee13e..75f52bcf 100644
--- a/googletest/src/gtest-filepath.cc
+++ b/googletest/src/gtest-filepath.cc
@@ -31,6 +31,9 @@
 
 #include 
 
+#include 
+#include 
+
 #include "gtest/gtest-message.h"
 #include "gtest/internal/gtest-port.h"
 
diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc
index 994fabd4..77b618c4 100644
--- a/googletest/src/gtest-port.cc
+++ b/googletest/src/gtest-port.cc
@@ -37,6 +37,10 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
+#include 
 
 #ifdef GTEST_OS_WINDOWS
 #include 
diff --git a/googletest/src/gtest-printers.cc b/googletest/src/gtest-printers.cc
index de740e7d..2b470678 100644
--- a/googletest/src/gtest-printers.cc
+++ b/googletest/src/gtest-printers.cc
@@ -47,6 +47,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include   // NOLINT
 #include 
 #include 
diff --git a/googletest/src/gtest-test-part.cc b/googletest/src/gtest-test-part.cc
index df677e6f..6f8ddd7c 100644
--- a/googletest/src/gtest-test-part.cc
+++ b/googletest/src/gtest-test-part.cc
@@ -32,6 +32,9 @@
 
 #include "gtest/gtest-test-part.h"
 
+#include 
+#include 
+
 #include "gtest/internal/gtest-port.h"
 #include "src/gtest-internal-inl.h"
 
diff --git a/googletest/src/gtest-typed-test.cc b/googletest/src/gtest-typed-test.cc
index 9941306f..b251c09d 100644
--- a/googletest/src/gtest-typed-test.cc
+++ b/googletest/src/gtest-typed-test.cc
@@ -29,6 +29,10 @@
 
 #include "gtest/gtest-typed-test.h"
 
+#include 
+#include 
+#include 
+
 #include "gtest/gtest.h"
 
 namespace testing {
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index da52b1d1..01c0220b 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -48,13 +48,16 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include   // NOLINT
+#include 
 #include 
 #include 
+#include 
 #include 
 
 #include "gtest/gtest-assertion-result.h"
diff --git a/googletest/test/googletest-death-test-test.cc b/googletest/test/googletest-death-test-test.cc
index 3579ce88..4cc81b72 100644
--- a/googletest/test/googletest-death-test-test.cc
+++ b/googletest/test/googletest-death-test-test.cc
@@ -52,6 +52,9 @@ using testing::internal::AlwaysTrue;
 #include 
 #include 
 
+#include 
+#include 
+
 #ifdef GTEST_OS_LINUX
 #include 
 #endif  // GTEST_OS_LINUX
diff --git a/googletest/test/googletest-list-tests-unittest_.cc b/googletest/test/googletest-list-tests-unittest_.cc
index 5577e896..a1ea6cf4 100644
--- a/googletest/test/googletest-list-tests-unittest_.cc
+++ b/googletest/test/googletest-list-tests-unittest_.cc
@@ -36,6 +36,9 @@
 // This program will be invoked from a Python unit test.
 // Don't run it directly.
 
+#include 
+#include 
+
 #include "gtest/gtest.h"
 
 // Several different test cases and tests that will be listed.
diff --git a/googletest/test/googletest-listener-test.cc b/googletest/test/googletest-listener-test.cc
index 654486d7..d7c47c21 100644
--- a/googletest/test/googletest-listener-test.cc
+++ b/googletest/test/googletest-listener-test.cc
@@ -32,6 +32,7 @@
 // This file verifies Google Test event listeners receive events at the
 // right times.
 
+#include 
 #include 
 
 #include "gtest/gtest.h"
diff --git a/googletest/test/googletest-param-test-invalid-name2-test_.cc b/googletest/test/googletest-param-test-invalid-name2-test_.cc
index d0c44da5..6d88a9ce 100644
--- a/googletest/test/googletest-param-test-invalid-name2-test_.cc
+++ b/googletest/test/googletest-param-test-invalid-name2-test_.cc
@@ -27,6 +27,8 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+#include 
+
 #include "gtest/gtest.h"
 
 namespace {
diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc
index 7fa82d08..e667e8f0 100644
--- a/googletest/test/googletest-printers-test.cc
+++ b/googletest/test/googletest-printers-test.cc
@@ -42,9 +42,11 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/googletest/test/gtest_stress_test.cc b/googletest/test/gtest_stress_test.cc
index 0cf21852..af8e757d 100644
--- a/googletest/test/gtest_stress_test.cc
+++ b/googletest/test/gtest_stress_test.cc
@@ -30,7 +30,9 @@
 // Tests that SCOPED_TRACE() and various Google Test assertions can be
 // used in a large number of threads concurrently.
 
+#include 
 #include 
+#include 
 #include 
 
 #include "gtest/gtest.h"
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc
index bd4fc60a..57041f05 100644
--- a/googletest/test/gtest_unittest.cc
+++ b/googletest/test/gtest_unittest.cc
@@ -63,6 +63,7 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

From baf182e006bcb82ef5e0b407e350a1d4c444b76a Mon Sep 17 00:00:00 2001
From: Tom Hughes 
Date: Fri, 21 Apr 2023 08:42:11 -0700
Subject: [PATCH 69/75] Use the empty method to check for emptiness

PiperOrigin-RevId: 526046714
Change-Id: I6ad0deff2a7f6dfef75a643c95ad914c83b9ba38
---
 googlemock/test/gmock_test.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/googlemock/test/gmock_test.cc b/googlemock/test/gmock_test.cc
index 8f1bd5d0..8cfff306 100644
--- a/googlemock/test/gmock_test.cc
+++ b/googlemock/test/gmock_test.cc
@@ -174,6 +174,6 @@ TEST(WideInitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) {
 // Makes sure Google Mock flags can be accessed in code.
 TEST(FlagTest, IsAccessibleInCode) {
   bool dummy =
-      GMOCK_FLAG_GET(catch_leaked_mocks) && GMOCK_FLAG_GET(verbose) == "";
+      GMOCK_FLAG_GET(catch_leaked_mocks) && GMOCK_FLAG_GET(verbose).empty();
   (void)dummy;  // Avoids the "unused local variable" warning.
 }

From 783d00fd19865fcbc3065e3fb3e17144761fcf5a Mon Sep 17 00:00:00 2001
From: Tom Hughes 
Date: Fri, 21 Apr 2023 10:40:36 -0700
Subject: [PATCH 70/75] Use '=default' to define trivial
 constructor/destructors

https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-equals-default.html

PiperOrigin-RevId: 526079054
Change-Id: Ia4db21e3e5f58b90de05d52fd94b291ed06d785d
---
 googlemock/include/gmock/gmock-actions.h      |  8 +++---
 .../include/gmock/gmock-cardinalities.h       |  4 +--
 .../include/gmock/gmock-spec-builders.h       |  4 +--
 .../gmock/internal/gmock-internal-utils.h     |  2 +-
 googlemock/src/gmock-spec-builders.cc         |  8 +++---
 googlemock/test/gmock-actions_test.cc         |  2 +-
 googlemock/test/gmock-cardinalities_test.cc   |  2 +-
 googlemock/test/gmock-function-mocker_test.cc | 24 ++++++++---------
 .../test/gmock-matchers-arithmetic_test.cc    |  4 +--
 .../test/gmock-matchers-comparisons_test.cc   |  4 +--
 .../test/gmock-matchers-containers_test.cc    |  2 +-
 googlemock/test/gmock-nice-strict_test.cc     |  8 +++---
 googlemock/test/gmock-spec-builders_test.cc   | 14 +++++-----
 googlemock/test/gmock_leak_test_.cc           |  4 +--
 googlemock/test/gmock_link_test.h             |  4 +--
 googlemock/test/gmock_output_test_.cc         |  2 +-
 googletest/include/gtest/gtest-matchers.h     | 12 ++++-----
 googletest/include/gtest/gtest-test-part.h    |  4 +--
 googletest/include/gtest/gtest.h              |  6 ++---
 .../internal/gtest-death-test-internal.h      |  4 +--
 .../include/gtest/internal/gtest-internal.h   |  2 +-
 .../include/gtest/internal/gtest-param-util.h | 26 +++++++++----------
 .../include/gtest/internal/gtest-port.h       | 10 +++----
 googletest/samples/prime_tables.h             |  2 +-
 googletest/src/gtest-internal-inl.h           |  8 +++---
 googletest/src/gtest.cc                       |  8 +++---
 googletest/test/googletest-port-test.cc       |  4 +--
 googletest/test/googletest-printers-test.cc   |  6 ++---
 googletest/test/gtest_repeat_test.cc          |  2 +-
 googletest/test/gtest_unittest.cc             |  2 +-
 30 files changed, 96 insertions(+), 96 deletions(-)

diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h
index c0bb8a9c..bd9ba73e 100644
--- a/googlemock/include/gmock/gmock-actions.h
+++ b/googlemock/include/gmock/gmock-actions.h
@@ -611,7 +611,7 @@ class DefaultValue {
  private:
   class ValueProducer {
    public:
-    virtual ~ValueProducer() {}
+    virtual ~ValueProducer() = default;
     virtual T Produce() = 0;
   };
 
@@ -699,8 +699,8 @@ class ActionInterface {
   typedef typename internal::Function::Result Result;
   typedef typename internal::Function::ArgumentTuple ArgumentTuple;
 
-  ActionInterface() {}
-  virtual ~ActionInterface() {}
+  ActionInterface() = default;
+  virtual ~ActionInterface() = default;
 
   // Performs the action.  This method is not const, as in general an
   // action can have side effects and be stateful.  For example, a
@@ -749,7 +749,7 @@ class Action {
 
   // Constructs a null Action.  Needed for storing Action objects in
   // STL containers.
-  Action() {}
+  Action() = default;
 
   // Construct an Action from a specified callable.
   // This cannot take std::function directly, because then Action would not be
diff --git a/googlemock/include/gmock/gmock-cardinalities.h b/googlemock/include/gmock/gmock-cardinalities.h
index b6ab648e..533e604f 100644
--- a/googlemock/include/gmock/gmock-cardinalities.h
+++ b/googlemock/include/gmock/gmock-cardinalities.h
@@ -65,7 +65,7 @@ namespace testing {
 // The implementation of a cardinality.
 class CardinalityInterface {
  public:
-  virtual ~CardinalityInterface() {}
+  virtual ~CardinalityInterface() = default;
 
   // Conservative estimate on the lower/upper bound of the number of
   // calls allowed.
@@ -92,7 +92,7 @@ class GTEST_API_ Cardinality {
  public:
   // Constructs a null cardinality.  Needed for storing Cardinality
   // objects in STL containers.
-  Cardinality() {}
+  Cardinality() = default;
 
   // Constructs a Cardinality from its implementation.
   explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {}
diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h
index 2a33acb1..78ca15d0 100644
--- a/googlemock/include/gmock/gmock-spec-builders.h
+++ b/googlemock/include/gmock/gmock-spec-builders.h
@@ -566,7 +566,7 @@ class ExpectationSet {
   typedef Expectation::Set::value_type value_type;
 
   // Constructs an empty set.
-  ExpectationSet() {}
+  ExpectationSet() = default;
 
   // This single-argument ctor must not be explicit, in order to support the
   //   ExpectationSet es = EXPECT_CALL(...);
@@ -1446,7 +1446,7 @@ class FunctionMocker final : public UntypedFunctionMockerBase {
   using ArgumentTuple = std::tuple;
   using ArgumentMatcherTuple = std::tuple...>;
 
-  FunctionMocker() {}
+  FunctionMocker() = default;
 
   // There is no generally useful and implementable semantics of
   // copying a mock object, so copying a mock is usually a user error.
diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h
index d3444386..ead6d7c8 100644
--- a/googlemock/include/gmock/internal/gmock-internal-utils.h
+++ b/googlemock/include/gmock/internal/gmock-internal-utils.h
@@ -224,7 +224,7 @@ class FailureReporterInterface {
   // The type of a failure (either non-fatal or fatal).
   enum FailureType { kNonfatal, kFatal };
 
-  virtual ~FailureReporterInterface() {}
+  virtual ~FailureReporterInterface() = default;
 
   // Reports a failure that occurred at the given source file location.
   virtual void ReportFailure(FailureType type, const char* file, int line,
diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc
index df0660b1..de894716 100644
--- a/googlemock/src/gmock-spec-builders.cc
+++ b/googlemock/src/gmock-spec-builders.cc
@@ -96,7 +96,7 @@ ExpectationBase::ExpectationBase(const char* a_file, int a_line,
       action_count_checked_(false) {}
 
 // Destructs an ExpectationBase object.
-ExpectationBase::~ExpectationBase() {}
+ExpectationBase::~ExpectationBase() = default;
 
 // Explicitly specifies the cardinality of this expectation.  Used by
 // the subclasses to implement the .Times() clause.
@@ -309,7 +309,7 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) {
 UntypedFunctionMockerBase::UntypedFunctionMockerBase()
     : mock_obj_(nullptr), name_("") {}
 
-UntypedFunctionMockerBase::~UntypedFunctionMockerBase() {}
+UntypedFunctionMockerBase::~UntypedFunctionMockerBase() = default;
 
 // Sets the mock object this mock method belongs to, and registers
 // this information in the global mock registry.  Will be called
@@ -746,13 +746,13 @@ void Mock::ClearDefaultActionsLocked(void* mock_obj)
   // needed by VerifyAndClearExpectationsLocked().
 }
 
-Expectation::Expectation() {}
+Expectation::Expectation() = default;
 
 Expectation::Expectation(
     const std::shared_ptr& an_expectation_base)
     : expectation_base_(an_expectation_base) {}
 
-Expectation::~Expectation() {}
+Expectation::~Expectation() = default;
 
 // Adds an expectation to a sequence.
 void Sequence::AddExpectation(const Expectation& expectation) const {
diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc
index f2305e52..f569e834 100644
--- a/googlemock/test/gmock-actions_test.cc
+++ b/googlemock/test/gmock-actions_test.cc
@@ -985,7 +985,7 @@ TEST(ReturnRoundRobinTest, WorksForVector) {
 
 class MockClass {
  public:
-  MockClass() {}
+  MockClass() = default;
 
   MOCK_METHOD1(IntFunc, int(bool flag));  // NOLINT
   MOCK_METHOD0(Foo, MyNonDefaultConstructible());
diff --git a/googlemock/test/gmock-cardinalities_test.cc b/googlemock/test/gmock-cardinalities_test.cc
index 77196d7a..ad49752e 100644
--- a/googlemock/test/gmock-cardinalities_test.cc
+++ b/googlemock/test/gmock-cardinalities_test.cc
@@ -52,7 +52,7 @@ using testing::MakeCardinality;
 
 class MockFoo {
  public:
-  MockFoo() {}
+  MockFoo() = default;
   MOCK_METHOD0(Bar, int());  // NOLINT
 
  private:
diff --git a/googlemock/test/gmock-function-mocker_test.cc b/googlemock/test/gmock-function-mocker_test.cc
index 4db498d8..f7b31ae3 100644
--- a/googlemock/test/gmock-function-mocker_test.cc
+++ b/googlemock/test/gmock-function-mocker_test.cc
@@ -70,7 +70,7 @@ using testing::TypedEq;
 template 
 class TemplatedCopyable {
  public:
-  TemplatedCopyable() {}
+  TemplatedCopyable() = default;
 
   template 
   TemplatedCopyable(const U& other) {}  // NOLINT
@@ -78,7 +78,7 @@ class TemplatedCopyable {
 
 class FooInterface {
  public:
-  virtual ~FooInterface() {}
+  virtual ~FooInterface() = default;
 
   virtual void VoidReturning(int x) = 0;
 
@@ -137,7 +137,7 @@ class FooInterface {
 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4373)
 class MockFoo : public FooInterface {
  public:
-  MockFoo() {}
+  MockFoo() = default;
 
   // Makes sure that a mock function parameter can be named.
   MOCK_METHOD(void, VoidReturning, (int n));  // NOLINT
@@ -208,7 +208,7 @@ class MockFoo : public FooInterface {
 
 class LegacyMockFoo : public FooInterface {
  public:
-  LegacyMockFoo() {}
+  LegacyMockFoo() = default;
 
   // Makes sure that a mock function parameter can be named.
   MOCK_METHOD1(VoidReturning, void(int n));  // NOLINT
@@ -487,7 +487,7 @@ TEST(FunctionMockerTest, RefQualified) {
 
 class MockB {
  public:
-  MockB() {}
+  MockB() = default;
 
   MOCK_METHOD(void, DoB, ());
 
@@ -498,7 +498,7 @@ class MockB {
 
 class LegacyMockB {
  public:
-  LegacyMockB() {}
+  LegacyMockB() = default;
 
   MOCK_METHOD0(DoB, void());
 
@@ -534,7 +534,7 @@ TYPED_TEST(ExpectCallTest, UnmentionedFunctionCanBeCalledAnyNumberOfTimes) {
 template 
 class StackInterface {
  public:
-  virtual ~StackInterface() {}
+  virtual ~StackInterface() = default;
 
   // Template parameter appears in function parameter.
   virtual void Push(const T& value) = 0;
@@ -547,7 +547,7 @@ class StackInterface {
 template 
 class MockStack : public StackInterface {
  public:
-  MockStack() {}
+  MockStack() = default;
 
   MOCK_METHOD(void, Push, (const T& elem), ());
   MOCK_METHOD(void, Pop, (), (final));
@@ -566,7 +566,7 @@ class MockStack : public StackInterface {
 template 
 class LegacyMockStack : public StackInterface {
  public:
-  LegacyMockStack() {}
+  LegacyMockStack() = default;
 
   MOCK_METHOD1_T(Push, void(const T& elem));
   MOCK_METHOD0_T(Pop, void());
@@ -711,7 +711,7 @@ TYPED_TEST(TemplateMockTestWithCallType, Works) {
 
 class MockOverloadedOnArgNumber {
  public:
-  MockOverloadedOnArgNumber() {}
+  MockOverloadedOnArgNumber() = default;
 
   MY_MOCK_METHODS1_;
 
@@ -723,7 +723,7 @@ class MockOverloadedOnArgNumber {
 
 class LegacyMockOverloadedOnArgNumber {
  public:
-  LegacyMockOverloadedOnArgNumber() {}
+  LegacyMockOverloadedOnArgNumber() = default;
 
   LEGACY_MY_MOCK_METHODS1_;
 
@@ -758,7 +758,7 @@ TYPED_TEST(OverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
 
 class MockOverloadedOnConstness {
  public:
-  MockOverloadedOnConstness() {}
+  MockOverloadedOnConstness() = default;
 
   MY_MOCK_METHODS2_;
 
diff --git a/googlemock/test/gmock-matchers-arithmetic_test.cc b/googlemock/test/gmock-matchers-arithmetic_test.cc
index 062e2ab3..f1769628 100644
--- a/googlemock/test/gmock-matchers-arithmetic_test.cc
+++ b/googlemock/test/gmock-matchers-arithmetic_test.cc
@@ -955,7 +955,7 @@ TEST(AllArgsTest, WorksForNonTuple) {
 
 class AllArgsHelper {
  public:
-  AllArgsHelper() {}
+  AllArgsHelper() = default;
 
   MOCK_METHOD2(Helper, int(char x, int y));
 
@@ -976,7 +976,7 @@ TEST(AllArgsTest, WorksInWithClause) {
 
 class OptionalMatchersHelper {
  public:
-  OptionalMatchersHelper() {}
+  OptionalMatchersHelper() = default;
 
   MOCK_METHOD0(NoArgs, int());
 
diff --git a/googlemock/test/gmock-matchers-comparisons_test.cc b/googlemock/test/gmock-matchers-comparisons_test.cc
index cf85eb56..b2ce99e1 100644
--- a/googlemock/test/gmock-matchers-comparisons_test.cc
+++ b/googlemock/test/gmock-matchers-comparisons_test.cc
@@ -589,8 +589,8 @@ TEST(MatcherCastTest, ValueIsNotCopied) {
 
 class Base {
  public:
-  virtual ~Base() {}
-  Base() {}
+  virtual ~Base() = default;
+  Base() = default;
 
  private:
   Base(const Base&) = delete;
diff --git a/googlemock/test/gmock-matchers-containers_test.cc b/googlemock/test/gmock-matchers-containers_test.cc
index 654a011a..38fd9a5d 100644
--- a/googlemock/test/gmock-matchers-containers_test.cc
+++ b/googlemock/test/gmock-matchers-containers_test.cc
@@ -2788,7 +2788,7 @@ TEST(ElementsAreTest, WorksWithNativeArrayPassedByReference) {
 
 class NativeArrayPassedAsPointerAndSize {
  public:
-  NativeArrayPassedAsPointerAndSize() {}
+  NativeArrayPassedAsPointerAndSize() = default;
 
   MOCK_METHOD(void, Helper, (int* array, int size));
 
diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc
index 08254e1a..95f09690 100644
--- a/googlemock/test/gmock-nice-strict_test.cc
+++ b/googlemock/test/gmock-nice-strict_test.cc
@@ -40,7 +40,7 @@
 // clash with ::testing::Mock.
 class Mock {
  public:
-  Mock() {}
+  Mock() = default;
 
   MOCK_METHOD0(DoThis, void());
 
@@ -78,7 +78,7 @@ class CallsMockMethodInDestructor {
 
 class Foo {
  public:
-  virtual ~Foo() {}
+  virtual ~Foo() = default;
 
   virtual void DoThis() = 0;
   virtual int DoThat(bool flag) = 0;
@@ -86,7 +86,7 @@ class Foo {
 
 class MockFoo : public Foo {
  public:
-  MockFoo() {}
+  MockFoo() = default;
   void Delete() { delete this; }
 
   MOCK_METHOD0(DoThis, void());
@@ -109,7 +109,7 @@ class MockBar {
            (a10 ? 'T' : 'F');
   }
 
-  virtual ~MockBar() {}
+  virtual ~MockBar() = default;
 
   const std::string& str() const { return str_; }
 
diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc
index d53196b3..7ba591a1 100644
--- a/googlemock/test/gmock-spec-builders_test.cc
+++ b/googlemock/test/gmock-spec-builders_test.cc
@@ -98,7 +98,7 @@ class NonDefaultConstructible {
 
 class MockA {
  public:
-  MockA() {}
+  MockA() = default;
 
   MOCK_METHOD1(DoA, void(int n));
   MOCK_METHOD1(ReturnResult, Result(int n));
@@ -113,7 +113,7 @@ class MockA {
 
 class MockB {
  public:
-  MockB() {}
+  MockB() = default;
 
   MOCK_CONST_METHOD0(DoB, int());  // NOLINT
   MOCK_METHOD1(DoB, int(int n));   // NOLINT
@@ -125,7 +125,7 @@ class MockB {
 
 class ReferenceHoldingMock {
  public:
-  ReferenceHoldingMock() {}
+  ReferenceHoldingMock() = default;
 
   MOCK_METHOD1(AcceptReference, void(std::shared_ptr*));
 
@@ -143,12 +143,12 @@ class ReferenceHoldingMock {
 
 class CC {
  public:
-  virtual ~CC() {}
+  virtual ~CC() = default;
   virtual int Method() = 0;
 };
 class MockCC : public CC {
  public:
-  MockCC() {}
+  MockCC() = default;
 
   MOCK_METHOD0(Method, int());
 
@@ -1881,7 +1881,7 @@ struct Unprintable {
 
 class MockC {
  public:
-  MockC() {}
+  MockC() = default;
 
   MOCK_METHOD6(VoidMethod, void(bool cond, int n, std::string s, void* p,
                                 const Printable& x, Unprintable y));
@@ -2121,7 +2121,7 @@ void PrintTo(PrintMeNot /* dummy */, ::std::ostream* /* os */) {
 
 class LogTestHelper {
  public:
-  LogTestHelper() {}
+  LogTestHelper() = default;
 
   MOCK_METHOD1(Foo, PrintMeNot(PrintMeNot));
 
diff --git a/googlemock/test/gmock_leak_test_.cc b/googlemock/test/gmock_leak_test_.cc
index fa645916..a6bb3392 100644
--- a/googlemock/test/gmock_leak_test_.cc
+++ b/googlemock/test/gmock_leak_test_.cc
@@ -40,13 +40,13 @@ using ::testing::Return;
 
 class FooInterface {
  public:
-  virtual ~FooInterface() {}
+  virtual ~FooInterface() = default;
   virtual void DoThis() = 0;
 };
 
 class MockFoo : public FooInterface {
  public:
-  MockFoo() {}
+  MockFoo() = default;
 
   MOCK_METHOD0(DoThis, void());
 
diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h
index 8d2abb1a..db11c2d2 100644
--- a/googlemock/test/gmock_link_test.h
+++ b/googlemock/test/gmock_link_test.h
@@ -194,7 +194,7 @@ using testing::MatchesRegex;
 
 class Interface {
  public:
-  virtual ~Interface() {}
+  virtual ~Interface() = default;
   virtual void VoidFromString(char* str) = 0;
   virtual char* StringFromString(char* str) = 0;
   virtual int IntFromString(char* str) = 0;
@@ -208,7 +208,7 @@ class Interface {
 
 class Mock : public Interface {
  public:
-  Mock() {}
+  Mock() = default;
 
   MOCK_METHOD1(VoidFromString, void(char* str));
   MOCK_METHOD1(StringFromString, char*(char* str));
diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc
index ca5a646f..04a6e8b4 100644
--- a/googlemock/test/gmock_output_test_.cc
+++ b/googlemock/test/gmock_output_test_.cc
@@ -53,7 +53,7 @@ using testing::Value;
 
 class MockFoo {
  public:
-  MockFoo() {}
+  MockFoo() = default;
 
   MOCK_METHOD3(Bar, char(const std::string& s, int i, double x));
   MOCK_METHOD2(Bar2, bool(int x, int y));
diff --git a/googletest/include/gtest/gtest-matchers.h b/googletest/include/gtest/gtest-matchers.h
index d73d8341..eae210e9 100644
--- a/googletest/include/gtest/gtest-matchers.h
+++ b/googletest/include/gtest/gtest-matchers.h
@@ -107,13 +107,13 @@ class MatchResultListener {
   MatchResultListener& operator=(const MatchResultListener&) = delete;
 };
 
-inline MatchResultListener::~MatchResultListener() {}
+inline MatchResultListener::~MatchResultListener() = default;
 
 // An instance of a subclass of this knows how to describe itself as a
 // matcher.
 class GTEST_API_ MatcherDescriberInterface {
  public:
-  virtual ~MatcherDescriberInterface() {}
+  virtual ~MatcherDescriberInterface() = default;
 
   // Describes this matcher to an ostream.  The function should print
   // a verb phrase that describes the property a value matching this
@@ -494,7 +494,7 @@ template <>
 class GTEST_API_ Matcher
     : public internal::MatcherBase {
  public:
-  Matcher() {}
+  Matcher() = default;
 
   explicit Matcher(const MatcherInterface* impl)
       : internal::MatcherBase(impl) {}
@@ -516,7 +516,7 @@ template <>
 class GTEST_API_ Matcher
     : public internal::MatcherBase {
  public:
-  Matcher() {}
+  Matcher() = default;
 
   explicit Matcher(const MatcherInterface* impl)
       : internal::MatcherBase(impl) {}
@@ -544,7 +544,7 @@ template <>
 class GTEST_API_ Matcher
     : public internal::MatcherBase {
  public:
-  Matcher() {}
+  Matcher() = default;
 
   explicit Matcher(const MatcherInterface* impl)
       : internal::MatcherBase(impl) {}
@@ -570,7 +570,7 @@ template <>
 class GTEST_API_ Matcher
     : public internal::MatcherBase {
  public:
-  Matcher() {}
+  Matcher() = default;
 
   explicit Matcher(const MatcherInterface* impl)
       : internal::MatcherBase(impl) {}
diff --git a/googletest/include/gtest/gtest-test-part.h b/googletest/include/gtest/gtest-test-part.h
index 8290b4d6..41c8a9a0 100644
--- a/googletest/include/gtest/gtest-test-part.h
+++ b/googletest/include/gtest/gtest-test-part.h
@@ -133,7 +133,7 @@ std::ostream& operator<<(std::ostream& os, const TestPartResult& result);
 // virtual.
 class GTEST_API_ TestPartResultArray {
  public:
-  TestPartResultArray() {}
+  TestPartResultArray() = default;
 
   // Appends the given TestPartResult to the array.
   void Append(const TestPartResult& result);
@@ -154,7 +154,7 @@ class GTEST_API_ TestPartResultArray {
 // This interface knows how to report a test part result.
 class GTEST_API_ TestPartResultReporterInterface {
  public:
-  virtual ~TestPartResultReporterInterface() {}
+  virtual ~TestPartResultReporterInterface() = default;
 
   virtual void ReportTestPartResult(const TestPartResult& result) = 0;
 };
diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h
index e5438268..84125034 100644
--- a/googletest/include/gtest/gtest.h
+++ b/googletest/include/gtest/gtest.h
@@ -894,7 +894,7 @@ class GTEST_API_ TestSuite {
 class Environment {
  public:
   // The d'tor is virtual as we need to subclass Environment.
-  virtual ~Environment() {}
+  virtual ~Environment() = default;
 
   // Override this to define how to set up the environment.
   virtual void SetUp() {}
@@ -925,7 +925,7 @@ class GTEST_API_ AssertionException
 // the order the corresponding events are fired.
 class TestEventListener {
  public:
-  virtual ~TestEventListener() {}
+  virtual ~TestEventListener() = default;
 
   // Fired before any test activity starts.
   virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
@@ -1671,7 +1671,7 @@ template 
 class WithParamInterface {
  public:
   typedef T ParamType;
-  virtual ~WithParamInterface() {}
+  virtual ~WithParamInterface() = default;
 
   // The current parameter value. Is also available in the test fixture's
   // constructor.
diff --git a/googletest/include/gtest/internal/gtest-death-test-internal.h b/googletest/include/gtest/internal/gtest-death-test-internal.h
index 522eed85..8e9c988b 100644
--- a/googletest/include/gtest/internal/gtest-death-test-internal.h
+++ b/googletest/include/gtest/internal/gtest-death-test-internal.h
@@ -88,7 +88,7 @@ class GTEST_API_ DeathTest {
   static bool Create(const char* statement, Matcher matcher,
                      const char* file, int line, DeathTest** test);
   DeathTest();
-  virtual ~DeathTest() {}
+  virtual ~DeathTest() = default;
 
   // A helper class that aborts a death test when it's deleted.
   class ReturnSentinel {
@@ -153,7 +153,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_()  //  4251
 // Factory interface for death tests.  May be mocked out for testing.
 class DeathTestFactory {
  public:
-  virtual ~DeathTestFactory() {}
+  virtual ~DeathTestFactory() = default;
   virtual bool Create(const char* statement,
                       Matcher matcher, const char* file,
                       int line, DeathTest** test) = 0;
diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h
index ae2ca95e..317894e7 100644
--- a/googletest/include/gtest/internal/gtest-internal.h
+++ b/googletest/include/gtest/internal/gtest-internal.h
@@ -435,7 +435,7 @@ GTEST_API_ TypeId GetTestTypeId();
 // of a Test object.
 class TestFactoryBase {
  public:
-  virtual ~TestFactoryBase() {}
+  virtual ~TestFactoryBase() = default;
 
   // Creates a test instance to run. The instance is both created and destroyed
   // within TestInfoImpl::Run()
diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h
index 50435f50..6a81c37f 100644
--- a/googletest/include/gtest/internal/gtest-param-util.h
+++ b/googletest/include/gtest/internal/gtest-param-util.h
@@ -97,7 +97,7 @@ class ParamGenerator;
 template 
 class ParamIteratorInterface {
  public:
-  virtual ~ParamIteratorInterface() {}
+  virtual ~ParamIteratorInterface() = default;
   // A pointer to the base generator instance.
   // Used only for the purposes of iterator comparison
   // to make sure that two iterators belong to the same generator.
@@ -171,7 +171,7 @@ class ParamGeneratorInterface {
  public:
   typedef T ParamType;
 
-  virtual ~ParamGeneratorInterface() {}
+  virtual ~ParamGeneratorInterface() = default;
 
   // Generator interface definition
   virtual ParamIteratorInterface* Begin() const = 0;
@@ -215,7 +215,7 @@ class RangeGenerator : public ParamGeneratorInterface {
         end_(end),
         step_(step),
         end_index_(CalculateEndIndex(begin, end, step)) {}
-  ~RangeGenerator() override {}
+  ~RangeGenerator() override = default;
 
   ParamIteratorInterface* Begin() const override {
     return new Iterator(this, begin_, 0, step_);
@@ -230,7 +230,7 @@ class RangeGenerator : public ParamGeneratorInterface {
     Iterator(const ParamGeneratorInterface* base, T value, int index,
              IncrementT step)
         : base_(base), value_(value), index_(index), step_(step) {}
-    ~Iterator() override {}
+    ~Iterator() override = default;
 
     const ParamGeneratorInterface* BaseGenerator() const override {
       return base_;
@@ -299,7 +299,7 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface {
   template 
   ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)
       : container_(begin, end) {}
-  ~ValuesInIteratorRangeGenerator() override {}
+  ~ValuesInIteratorRangeGenerator() override = default;
 
   ParamIteratorInterface* Begin() const override {
     return new Iterator(this, container_.begin());
@@ -316,7 +316,7 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface {
     Iterator(const ParamGeneratorInterface* base,
              typename ContainerType::const_iterator iterator)
         : base_(base), iterator_(iterator) {}
-    ~Iterator() override {}
+    ~Iterator() override = default;
 
     const ParamGeneratorInterface* BaseGenerator() const override {
       return base_;
@@ -420,7 +420,7 @@ class ParameterizedTestFactory : public TestFactoryBase {
 template 
 class TestMetaFactoryBase {
  public:
-  virtual ~TestMetaFactoryBase() {}
+  virtual ~TestMetaFactoryBase() = default;
 
   virtual TestFactoryBase* CreateTestFactory(ParamType parameter) = 0;
 };
@@ -439,7 +439,7 @@ class TestMetaFactory
  public:
   using ParamType = typename TestSuite::ParamType;
 
-  TestMetaFactory() {}
+  TestMetaFactory() = default;
 
   TestFactoryBase* CreateTestFactory(ParamType parameter) override {
     return new ParameterizedTestFactory(parameter);
@@ -462,7 +462,7 @@ class TestMetaFactory
 // and calls RegisterTests() on each of them when asked.
 class ParameterizedTestSuiteInfoBase {
  public:
-  virtual ~ParameterizedTestSuiteInfoBase() {}
+  virtual ~ParameterizedTestSuiteInfoBase() = default;
 
   // Base part of test suite name for display purposes.
   virtual const std::string& GetTestSuiteName() const = 0;
@@ -691,7 +691,7 @@ using ParameterizedTestCaseInfo = ParameterizedTestSuiteInfo;
 // ParameterizedTestSuiteInfo descriptors.
 class ParameterizedTestSuiteRegistry {
  public:
-  ParameterizedTestSuiteRegistry() {}
+  ParameterizedTestSuiteRegistry() = default;
   ~ParameterizedTestSuiteRegistry() {
     for (auto& test_suite_info : test_suite_infos_) {
       delete test_suite_info;
@@ -825,7 +825,7 @@ class CartesianProductGenerator
 
   CartesianProductGenerator(const std::tuple...>& g)
       : generators_(g) {}
-  ~CartesianProductGenerator() override {}
+  ~CartesianProductGenerator() override = default;
 
   ParamIteratorInterface* Begin() const override {
     return new Iterator(this, generators_, false);
@@ -850,7 +850,7 @@ class CartesianProductGenerator
           current_(is_end ? end_ : begin_) {
       ComputeCurrentValue();
     }
-    ~IteratorImpl() override {}
+    ~IteratorImpl() override = default;
 
     const ParamGeneratorInterface* BaseGenerator() const override {
       return base_;
@@ -969,7 +969,7 @@ class ParamGeneratorConverter : public ParamGeneratorInterface {
         : base_(base), it_(it), end_(end) {
       if (it_ != end_) value_ = std::make_shared(static_cast(*it_));
     }
-    ~Iterator() override {}
+    ~Iterator() override = default;
 
     const ParamGeneratorInterface* BaseGenerator() const override {
       return base_;
diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h
index 656a2618..c6bc2d76 100644
--- a/googletest/include/gtest/internal/gtest-port.h
+++ b/googletest/include/gtest/internal/gtest-port.h
@@ -1328,7 +1328,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_()  // 4251
 // problem.
 class ThreadWithParamBase {
  public:
-  virtual ~ThreadWithParamBase() {}
+  virtual ~ThreadWithParamBase() = default;
   virtual void Run() = 0;
 };
 
@@ -1790,7 +1790,7 @@ typedef GTestMutexLock MutexLock;
 // ThreadLocalValueHolderBase.
 class GTEST_API_ ThreadLocalValueHolderBase {
  public:
-  virtual ~ThreadLocalValueHolderBase() {}
+  virtual ~ThreadLocalValueHolderBase() = default;
 };
 
 // Called by pthread to delete thread-local data stored by
@@ -1862,8 +1862,8 @@ class GTEST_API_ ThreadLocal {
 
   class ValueHolderFactory {
    public:
-    ValueHolderFactory() {}
-    virtual ~ValueHolderFactory() {}
+    ValueHolderFactory() = default;
+    virtual ~ValueHolderFactory() = default;
     virtual ValueHolder* MakeNewHolder() const = 0;
 
    private:
@@ -1873,7 +1873,7 @@ class GTEST_API_ ThreadLocal {
 
   class DefaultValueHolderFactory : public ValueHolderFactory {
    public:
-    DefaultValueHolderFactory() {}
+    DefaultValueHolderFactory() = default;
     ValueHolder* MakeNewHolder() const override { return new ValueHolder(); }
 
    private:
diff --git a/googletest/samples/prime_tables.h b/googletest/samples/prime_tables.h
index 08ad9493..14c016ad 100644
--- a/googletest/samples/prime_tables.h
+++ b/googletest/samples/prime_tables.h
@@ -39,7 +39,7 @@
 // The prime table interface.
 class PrimeTable {
  public:
-  virtual ~PrimeTable() {}
+  virtual ~PrimeTable() = default;
 
   // Returns true if and only if n is a prime number.
   virtual bool IsPrime(int n) const = 0;
diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h
index 16841b55..00849717 100644
--- a/googletest/src/gtest-internal-inl.h
+++ b/googletest/src/gtest-internal-inl.h
@@ -407,8 +407,8 @@ GTEST_API_ FilePath GetCurrentExecutableName();
 // The role interface for getting the OS stack trace as a string.
 class OsStackTraceGetterInterface {
  public:
-  OsStackTraceGetterInterface() {}
-  virtual ~OsStackTraceGetterInterface() {}
+  OsStackTraceGetterInterface() = default;
+  virtual ~OsStackTraceGetterInterface() = default;
 
   // Returns the current OS stack trace as an std::string.  Parameters:
   //
@@ -436,7 +436,7 @@ class OsStackTraceGetterInterface {
 // A working implementation of the OsStackTraceGetterInterface interface.
 class OsStackTraceGetter : public OsStackTraceGetterInterface {
  public:
-  OsStackTraceGetter() {}
+  OsStackTraceGetter() = default;
 
   std::string CurrentStackTrace(int max_depth, int skip_count) override;
   void UponLeavingGTest() override;
@@ -1064,7 +1064,7 @@ class StreamingListener : public EmptyTestEventListener {
   // Abstract base class for writing strings to a socket.
   class AbstractSocketWriter {
    public:
-    virtual ~AbstractSocketWriter() {}
+    virtual ~AbstractSocketWriter() = default;
 
     // Sends a string to the socket.
     virtual void Send(const std::string& message) = 0;
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 01c0220b..9fdca40e 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -2241,7 +2241,7 @@ TestResult::TestResult()
     : death_test_count_(0), start_timestamp_(0), elapsed_time_(0) {}
 
 // D'tor.
-TestResult::~TestResult() {}
+TestResult::~TestResult() = default;
 
 // Returns the i-th test part result among all the results. i can
 // range from 0 to total_part_count() - 1. If i is not in that range,
@@ -2450,7 +2450,7 @@ Test::Test() : gtest_flag_saver_(new GTEST_FLAG_SAVER_) {}
 // The d'tor restores the states of all flags.  The actual work is
 // done by the d'tor of the gtest_flag_saver_ field, and thus not
 // visible here.
-Test::~Test() {}
+Test::~Test() = default;
 
 // Sets up the test fixture.
 //
@@ -3362,7 +3362,7 @@ static void PrintFullTestCommentIfPresent(const TestInfo& test_info) {
 // Class PrettyUnitTestResultPrinter is copyable.
 class PrettyUnitTestResultPrinter : public TestEventListener {
  public:
-  PrettyUnitTestResultPrinter() {}
+  PrettyUnitTestResultPrinter() = default;
   static void PrintTestName(const char* test_suite, const char* test) {
     printf("%s.%s", test_suite, test);
   }
@@ -3670,7 +3670,7 @@ void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
 // Class BriefUnitTestResultPrinter is copyable.
 class BriefUnitTestResultPrinter : public TestEventListener {
  public:
-  BriefUnitTestResultPrinter() {}
+  BriefUnitTestResultPrinter() = default;
   static void PrintTestName(const char* test_suite, const char* test) {
     printf("%s.%s", test_suite, test);
   }
diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc
index 94bb8e38..32a2a7b4 100644
--- a/googletest/test/googletest-port-test.cc
+++ b/googletest/test/googletest-port-test.cc
@@ -97,7 +97,7 @@ class Base {
   explicit Base(int n) : member_(n) {}
   Base(const Base&) = default;
   Base& operator=(const Base&) = default;
-  virtual ~Base() {}
+  virtual ~Base() = default;
   int member() { return member_; }
 
  private:
@@ -982,7 +982,7 @@ TEST(ThreadLocalTest, SingleParamConstructorInitializesToParam) {
 class NoDefaultConstructor {
  public:
   explicit NoDefaultConstructor(const char*) {}
-  NoDefaultConstructor(const NoDefaultConstructor&) {}
+  NoDefaultConstructor(const NoDefaultConstructor&) = default;
 };
 
 TEST(ThreadLocalTest, ValueDefaultContructorIsNotRequiredForParamVersion) {
diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc
index e667e8f0..f44f29a5 100644
--- a/googletest/test/googletest-printers-test.cc
+++ b/googletest/test/googletest-printers-test.cc
@@ -108,7 +108,7 @@ class UnprintableTemplateInGlobal {
 // A user-defined streamable type in the global namespace.
 class StreamableInGlobal {
  public:
-  virtual ~StreamableInGlobal() {}
+  virtual ~StreamableInGlobal() = default;
 };
 
 inline void operator<<(::std::ostream& os, const StreamableInGlobal& /* x */) {
@@ -216,7 +216,7 @@ class PathLike {
   using value_type = char;
   using const_iterator = iterator;
 
-  PathLike() {}
+  PathLike() = default;
 
   iterator begin() const { return iterator(); }
   iterator end() const { return iterator(); }
@@ -749,7 +749,7 @@ AssertionResult HasPrefix(const StringType& str, const StringType& prefix) {
 
 struct Foo {
  public:
-  virtual ~Foo() {}
+  virtual ~Foo() = default;
   int MyMethod(char x) { return x + 1; }
   virtual char MyVirtualMethod(int /* n */) { return 'a'; }
 
diff --git a/googletest/test/gtest_repeat_test.cc b/googletest/test/gtest_repeat_test.cc
index 73fb8dc9..f67b7886 100644
--- a/googletest/test/gtest_repeat_test.cc
+++ b/googletest/test/gtest_repeat_test.cc
@@ -61,7 +61,7 @@ int g_environment_tear_down_count = 0;
 
 class MyEnvironment : public testing::Environment {
  public:
-  MyEnvironment() {}
+  MyEnvironment() = default;
   void SetUp() override { g_environment_set_up_count++; }
   void TearDown() override { g_environment_tear_down_count++; }
 };
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc
index 57041f05..1fde827e 100644
--- a/googletest/test/gtest_unittest.cc
+++ b/googletest/test/gtest_unittest.cc
@@ -4951,7 +4951,7 @@ TEST(ComparisonAssertionTest, AcceptsUnprintableArgs) {
 // both in a TEST and in a TEST_F.
 class Foo {
  public:
-  Foo() {}
+  Foo() = default;
 
  private:
   int Bar() const { return 1; }

From 51eeae5a5520166a385ce457b410d6309ac20968 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Patryk=20Gawro=C5=84ski?= 
Date: Tue, 25 Apr 2023 01:45:26 +0200
Subject: [PATCH 71/75] gmock: fix issue #4222

Rename 'Result' struct to 'NonMoveableStruct' in
gmock-spec-builders_test.cc in ExpectCallTest.NonMoveableType test
---
 googlemock/test/gmock-spec-builders_test.cc | 26 ++++++++++-----------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc
index 7ba591a1..d07cb5cb 100644
--- a/googlemock/test/gmock-spec-builders_test.cc
+++ b/googlemock/test/gmock-spec-builders_test.cc
@@ -811,32 +811,32 @@ TEST(ExpectCallTest, InfersCardinality1WhenThereIsWillRepeatedly) {
 // from a prvalue returned from a function.
 TEST(ExpectCallTest, NonMoveableType) {
   // Define a non-moveable result type.
-  struct Result {
-    explicit Result(int x_in) : x(x_in) {}
-    Result(Result&&) = delete;
+  struct NonMoveableStruct {
+    explicit NonMoveableStruct(int x_in) : x(x_in) {}
+    NonMoveableStruct(NonMoveableStruct&&) = delete;
 
     int x;
   };
 
-  static_assert(!std::is_move_constructible_v);
-  static_assert(!std::is_copy_constructible_v);
+  static_assert(!std::is_move_constructible_v);
+  static_assert(!std::is_copy_constructible_v);
 
-  static_assert(!std::is_move_assignable_v);
-  static_assert(!std::is_copy_assignable_v);
+  static_assert(!std::is_move_assignable_v);
+  static_assert(!std::is_copy_assignable_v);
 
   // We should be able to use a callable that returns that result as both a
   // OnceAction and an Action, whether the callable ignores arguments or not.
-  const auto return_17 = [] { return Result(17); };
+  const auto return_17 = [] { return NonMoveableStruct(17); };
 
-  static_cast(OnceAction{return_17});
-  static_cast(Action{return_17});
+  static_cast(OnceAction{return_17});
+  static_cast(Action{return_17});
 
-  static_cast(OnceAction{return_17});
-  static_cast(Action{return_17});
+  static_cast(OnceAction{return_17});
+  static_cast(Action{return_17});
 
   // It should be possible to return the result end to end through an
   // EXPECT_CALL statement, with both WillOnce and WillRepeatedly.
-  MockFunction mock;
+  MockFunction mock;
   EXPECT_CALL(mock, Call)   //
       .WillOnce(return_17)  //
       .WillRepeatedly(return_17);

From 97408cae552bde8609aabfa7c3647a52fb21f8c9 Mon Sep 17 00:00:00 2001
From: Vertexwahn 
Date: Tue, 25 Apr 2023 20:20:01 +0200
Subject: [PATCH 72/75] Fix spelling

---
 googletest/src/gtest-death-test.cc          | 2 +-
 googletest/src/gtest-internal-inl.h         | 2 +-
 googletest/test/googletest-filepath-test.cc | 2 +-
 googletest/test/gtest_xml_test_utils.py     | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc
index 55b95782..c3b7820e 100644
--- a/googletest/src/gtest-death-test.cc
+++ b/googletest/src/gtest-death-test.cc
@@ -1029,7 +1029,7 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
   // Note: The test component must have `fuchsia.process.Launcher` declared
   // in its manifest. (Fuchsia integration tests require creating a
   // "Fuchsia Test Component" which contains a "Fuchsia Component Manifest")
-  // Launching processes is a privileged operation in Fuschia, and the
+  // Launching processes is a privileged operation in Fuchsia, and the
   // declaration indicates that the ability is required for the component.
   std::unique_ptr argv = CreateArgvFromArgs(args);
   status = fdio_spawn_etc(child_job, FDIO_SPAWN_CLONE_ALL, argv[0], argv.get(),
diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h
index 00849717..5ba557fe 100644
--- a/googletest/src/gtest-internal-inl.h
+++ b/googletest/src/gtest-internal-inl.h
@@ -93,7 +93,7 @@ GTEST_API_ TimeInMillis GetTimeInMillis();
 GTEST_API_ bool ShouldUseColor(bool stdout_is_tty);
 
 // Formats the given time in milliseconds as seconds. If the input is an exact N
-// seconds, the output has a trailing decimal point (e.g., "N." intead of "N").
+// seconds, the output has a trailing decimal point (e.g., "N." instead of "N").
 GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms);
 
 // Converts the given time in milliseconds to a date string in the ISO 8601
diff --git a/googletest/test/googletest-filepath-test.cc b/googletest/test/googletest-filepath-test.cc
index 0a33d714..3e9c79f0 100644
--- a/googletest/test/googletest-filepath-test.cc
+++ b/googletest/test/googletest-filepath-test.cc
@@ -515,7 +515,7 @@ class DirectoryCreationTest : public Test {
   }
 
   // Strings representing a directory and a file, with identical paths
-  // except for the trailing separator character that distinquishes
+  // except for the trailing separator character that distinguishes
   // a directory named 'test' from a file named 'test'. Example names:
   FilePath testdata_path_;  // "/tmp/directory_creation/test/"
   FilePath testdata_file_;  // "/tmp/directory_creation/test"
diff --git a/googletest/test/gtest_xml_test_utils.py b/googletest/test/gtest_xml_test_utils.py
index 8fcb6933..74e0f4a0 100755
--- a/googletest/test/gtest_xml_test_utils.py
+++ b/googletest/test/gtest_xml_test_utils.py
@@ -218,7 +218,7 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
       )
     if element.tagName in ('testsuites', 'testsuite', 'testcase'):
       time = element.getAttributeNode('time')
-      # The value for exact N seconds has a traling decimal point (e.g., "10."
+      # The value for exact N seconds has a trailing decimal point (e.g., "10."
       # instead of "10")
       time.value = re.sub(r'^\d+\.(\d+)?$', '*', time.value)
       type_param = element.getAttributeNode('type_param')

From dea0484e4d3b6a2c50055c24c5617cd662a50c5f Mon Sep 17 00:00:00 2001
From: Abseil Team 
Date: Wed, 26 Apr 2023 07:13:23 -0700
Subject: [PATCH 73/75] Use Abseil Flag public API for flag parsing.

This change brings InitGoogleTest semantic in accordance with the official documentation: only GoogleTest flags are removed from argc/argv. The rest of the flags remains in place. We do nothing special for flags with unrecognized gunit_/gtest_ prefix and we do not report them.

PiperOrigin-RevId: 527257221
Change-Id: Ibb29a1bda1a44251a4ee579c0fb5bbdfd9965c21
---
 googletest/src/gtest.cc            | 69 +++++++++++++++++++++++-------
 googletest/test/gtest_help_test.py | 11 -----
 googletest/test/gtest_unittest.cc  |  9 ++++
 googletest_deps.bzl                |  8 ++--
 4 files changed, 67 insertions(+), 30 deletions(-)

diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 9fdca40e..fb7512c1 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -44,6 +44,7 @@
 #include   // NOLINT
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -140,6 +141,7 @@
 #endif
 
 #ifdef GTEST_HAS_ABSL
+#include "absl/container/flat_hash_set.h"
 #include "absl/debugging/failure_signal_handler.h"
 #include "absl/debugging/stacktrace.h"
 #include "absl/debugging/symbolize.h"
@@ -147,6 +149,8 @@
 #include "absl/flags/usage.h"
 #include "absl/strings/str_cat.h"
 #include "absl/strings/str_replace.h"
+#include "absl/strings/string_view.h"
+#include "absl/strings/strip.h"
 #endif  // GTEST_HAS_ABSL
 
 // Checks builtin compiler feature |x| while avoiding an extra layer of #ifdefs
@@ -6686,25 +6690,60 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) {
 }
 
 // Parses the command line for Google Test flags, without initializing
-// other parts of Google Test.
+// other parts of Google Test. This function updates argc and argv by removing
+// flags that are known to GoogleTest (including other user flags defined using
+// ABSL_FLAG if GoogleTest is built with GTEST_USE_ABSL). Other arguments
+// 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
-  if (*argc > 0) {
-    // absl::ParseCommandLine() requires *argc > 0.
-    auto positional_args = absl::flags_internal::ParseCommandLineImpl(
-        *argc, argv, absl::flags_internal::UsageFlagsAction::kHandleUsage,
-        absl::flags_internal::OnUndefinedFlag::kReportUndefined);
-    // Any command-line positional arguments not part of any command-line flag
-    // (or arguments to a flag) are copied back out to argv, with the program
-    // invocation name at position 0, and argc is resized. This includes
-    // positional arguments after the flag-terminating delimiter '--'.
-    // See https://abseil.io/docs/cpp/guides/flags.
-    std::copy(positional_args.begin(), positional_args.end(), argv);
-    if (static_cast(positional_args.size()) < *argc) {
-      argv[positional_args.size()] = nullptr;
-      *argc = static_cast(positional_args.size());
+  if (*argc <= 0) return;
+
+  std::vector positional_args;
+  std::vector unrecognized_flags;
+  absl::ParseAbseilFlagsOnly(*argc, argv, positional_args, unrecognized_flags);
+  absl::flat_hash_set unrecognized;
+  for (const auto& flag : unrecognized_flags) {
+    unrecognized.insert(flag.flag_name);
+  }
+  absl::flat_hash_set positional;
+  for (const auto& arg : positional_args) {
+    positional.insert(arg);
+  }
+
+  int out_pos = 1;
+  int in_pos = 1;
+  for (; in_pos < *argc; ++in_pos) {
+    char* arg = argv[in_pos];
+    absl::string_view arg_str(arg);
+    if (absl::ConsumePrefix(&arg_str, "--")) {
+      // Flag-like argument. If the flag was unrecognized, keep it.
+      // If it was a GoogleTest flag, remove it.
+      if (unrecognized.contains(arg_str)) {
+        argv[out_pos++] = argv[in_pos];
+        continue;
+      }
+    }
+
+    if (arg_str.empty()) {
+      ++in_pos;
+      break;  // '--' indicates that the rest of the arguments are positional
+    }
+
+    // Probably a positional argument. If it is in fact positional, keep it.
+    // If it was a value for the flag argument, remove it.
+    if (positional.contains(arg)) {
+      argv[out_pos++] = arg;
     }
   }
+
+  // The rest are positional args for sure.
+  while (in_pos < *argc) {
+    argv[out_pos++] = argv[in_pos++];
+  }
+
+  *argc = out_pos;
+  argv[out_pos] = nullptr;
 #else
   ParseGoogleTestFlagsOnlyImpl(argc, argv);
 #endif
diff --git a/googletest/test/gtest_help_test.py b/googletest/test/gtest_help_test.py
index 9261b87a..85a0c33c 100755
--- a/googletest/test/gtest_help_test.py
+++ b/googletest/test/gtest_help_test.py
@@ -54,7 +54,6 @@ PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_')
 FLAG_PREFIX = '--gtest_'
 DEATH_TEST_STYLE_FLAG = FLAG_PREFIX + 'death_test_style'
 STREAM_RESULT_TO_FLAG = FLAG_PREFIX + 'stream_result_to'
-UNKNOWN_GTEST_PREFIXED_FLAG = FLAG_PREFIX + 'unknown_flag_for_testing'
 LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests'
 INTERNAL_FLAG_FOR_TESTING = FLAG_PREFIX + 'internal_flag_for_testing'
 
@@ -177,16 +176,6 @@ class GTestHelpTest(gtest_test_utils.TestCase):
   def testPrintsHelpWithFullFlag(self):
     self.TestHelpFlag('--help')
 
-  def testPrintsHelpWithUnrecognizedGoogleTestFlag(self):
-    # The behavior is slightly different when Abseil flags is
-    # used. Abseil flags rejects all unknown flags, while the builtin
-    # GTest flags implementation interprets an unknown flag with a
-    # '--gtest_' prefix as a request for help.
-    if HAS_ABSL_FLAGS:
-      self.TestUnknownFlagWithAbseil(UNKNOWN_GTEST_PREFIXED_FLAG)
-    else:
-      self.TestHelpFlag(UNKNOWN_GTEST_PREFIXED_FLAG)
-
   def testRunsTestsWithoutHelpFlag(self):
     """Verifies correct behavior when no help flag is specified.
 
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc
index 1fde827e..9b4b8333 100644
--- a/googletest/test/gtest_unittest.cc
+++ b/googletest/test/gtest_unittest.cc
@@ -6220,6 +6220,15 @@ TEST_F(ParseFlagsTest, AbseilPositionalFlags) {
 }
 #endif
 
+TEST_F(ParseFlagsTest, UnrecognizedFlags) {
+  const char* argv[] = {"foo.exe", "--gtest_filter=abcd", "--other_flag",
+                        nullptr};
+
+  const char* argv2[] = {"foo.exe", "--other_flag", nullptr};
+
+  GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter("abcd"), false);
+}
+
 #ifdef GTEST_OS_WINDOWS
 // Tests parsing wide strings.
 TEST_F(ParseFlagsTest, WideStrings) {
diff --git a/googletest_deps.bzl b/googletest_deps.bzl
index 7fe80961..65e56abb 100644
--- a/googletest_deps.bzl
+++ b/googletest_deps.bzl
@@ -15,8 +15,8 @@ def googletest_deps():
 
     if not native.existing_rule("com_google_absl"):
         http_archive(
-            name = "com_google_absl",  # 2023-02-27T15:50:25Z
-            sha256 = "baf8e734ac3ce213a889ce7c248b981ee1730e2093e32808e0f0a910dc985f76",
-            strip_prefix = "abseil-cpp-0c1114c4fb83c844c7fd74708338cca1d3d9b0dc",
-            urls = ["https://github.com/abseil/abseil-cpp/archive/0c1114c4fb83c844c7fd74708338cca1d3d9b0dc.zip"],
+            name = "com_google_absl",  # 2023-04-06T14:42:25Z
+            sha256 = "a50452f02402262f9a61a8eedda60f76dda6b9538d36b34b55bce9f74a4d5ef8",
+            strip_prefix = "abseil-cpp-e73b9139ee9b853a4bd7812531442c138da09084",
+            urls = ["https://github.com/abseil/abseil-cpp/archive/e73b9139ee9b853a4bd7812531442c138da09084.zip"],
         )

From 0bdaac5a1401fffac6b64581efc639734aded793 Mon Sep 17 00:00:00 2001
From: Tom Hughes 
Date: Thu, 27 Apr 2023 18:17:19 -0700
Subject: [PATCH 74/75] Add qualifier to avoid argument dependent lookup

PiperOrigin-RevId: 527740306
Change-Id: I61308cc232c346d5ff8b0548d4c552a59633fffc
---
 googlemock/test/gmock-more-actions_test.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc
index ec7aea61..9980f3bc 100644
--- a/googlemock/test/gmock-more-actions_test.cc
+++ b/googlemock/test/gmock-more-actions_test.cc
@@ -677,7 +677,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithIteratorArgument) {
   Action a = SetArrayArgument<1>(letters.begin(), letters.end());
 
   std::string s;
-  a.Perform(std::make_tuple(true, back_inserter(s)));
+  a.Perform(std::make_tuple(true, std::back_inserter(s)));
   EXPECT_EQ(letters, s);
 }
 

From 797b0ad2a3a45608ecf5c67e6e289d377a3521ca Mon Sep 17 00:00:00 2001
From: Dino Radakovic 
Date: Fri, 28 Apr 2023 10:15:31 -0700
Subject: [PATCH 75/75] Use GTEST_INTERNAL_CPLUSPLUS_LANG instead of
 __cplusplus

Some versions of MSVC provide incorrect values for the latter and rely on _MSVC_LANG instead.
Fixes #4226.

PiperOrigin-RevId: 527919195
Change-Id: Ifcca4612074f5ebc5337094426866a187f79f90a
---
 googlemock/test/gmock-actions_test.cc          |  4 +++-
 googlemock/test/gmock-spec-builders_test.cc    |  3 ++-
 googletest/include/gtest/internal/gtest-port.h | 17 +++++++++--------
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc
index f569e834..da1675c5 100644
--- a/googlemock/test/gmock-actions_test.cc
+++ b/googlemock/test/gmock-actions_test.cc
@@ -48,6 +48,7 @@
 #include "gmock/internal/gmock-port.h"
 #include "gtest/gtest-spi.h"
 #include "gtest/gtest.h"
+#include "gtest/internal/gtest-port.h"
 
 // Silence C4100 (unreferenced formal parameter) and C4503 (decorated name
 // length exceeded) for MSVC.
@@ -221,7 +222,8 @@ TEST(TypeTraits, IsInvocableRV) {
   // In C++17 and above, where it's guaranteed that functions can return
   // non-moveable objects, everything should work fine for non-moveable rsult
   // types too.
-#if defined(__cplusplus) && __cplusplus >= 201703L
+#if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
+    GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
   {
     struct NonMoveable {
       NonMoveable() = default;
diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc
index d07cb5cb..221de2d2 100644
--- a/googlemock/test/gmock-spec-builders_test.cc
+++ b/googlemock/test/gmock-spec-builders_test.cc
@@ -804,7 +804,8 @@ TEST(ExpectCallTest, InfersCardinality1WhenThereIsWillRepeatedly) {
       "to be called at least once");
 }
 
-#if defined(__cplusplus) && __cplusplus >= 201703L
+#if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
+    GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
 
 // It should be possible to return a non-moveable type from a mock action in
 // C++17 and above, where it's guaranteed that such a type can be initialized
diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h
index c6bc2d76..d71110c0 100644
--- a/googletest/include/gtest/internal/gtest-port.h
+++ b/googletest/include/gtest/internal/gtest-port.h
@@ -2398,7 +2398,7 @@ using Any = ::absl::any;
 }  // namespace testing
 #else
 #ifdef __has_include
-#if __has_include() && __cplusplus >= 201703L && \
+#if __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L && \
     (!defined(_MSC_VER) || GTEST_HAS_RTTI)
 // Otherwise for C++17 and higher use std::any for UniversalPrinter<>
 // specializations.
@@ -2411,7 +2411,7 @@ using Any = ::std::any;
 }  // namespace testing
 // The case where absl is configured NOT to alias std::any is not
 // supported.
-#endif  // __has_include() && __cplusplus >= 201703L
+#endif  // __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
 #endif  // __has_include
 #endif  // GTEST_HAS_ABSL
 
@@ -2433,7 +2433,7 @@ inline ::absl::nullopt_t Nullopt() { return ::absl::nullopt; }
 }  // namespace testing
 #else
 #ifdef __has_include
-#if __has_include() && __cplusplus >= 201703L
+#if __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
 // Otherwise for C++17 and higher use std::optional for UniversalPrinter<>
 // specializations.
 #define GTEST_INTERNAL_HAS_OPTIONAL 1
@@ -2447,7 +2447,7 @@ inline ::std::nullopt_t Nullopt() { return ::std::nullopt; }
 }  // namespace testing
 // The case where absl is configured NOT to alias std::optional is not
 // supported.
-#endif  // __has_include() && __cplusplus >= 201703L
+#endif  // __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
 #endif  // __has_include
 #endif  // GTEST_HAS_ABSL
 
@@ -2467,7 +2467,7 @@ using StringView = ::absl::string_view;
 }  // namespace testing
 #else
 #ifdef __has_include
-#if __has_include() && __cplusplus >= 201703L
+#if __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
 // Otherwise for C++17 and higher use std::string_view for Matcher<>
 // specializations.
 #define GTEST_INTERNAL_HAS_STRING_VIEW 1
@@ -2479,7 +2479,8 @@ using StringView = ::std::string_view;
 }  // namespace testing
 // The case where absl is configured NOT to alias std::string_view is not
 // supported.
-#endif  // __has_include() && __cplusplus >= 201703L
+#endif  // __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >=
+        // 201703L
 #endif  // __has_include
 #endif  // GTEST_HAS_ABSL
 
@@ -2500,7 +2501,7 @@ using Variant = ::absl::variant;
 }  // namespace testing
 #else
 #ifdef __has_include
-#if __has_include() && __cplusplus >= 201703L
+#if __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
 // Otherwise for C++17 and higher use std::variant for UniversalPrinter<>
 // specializations.
 #define GTEST_INTERNAL_HAS_VARIANT 1
@@ -2512,7 +2513,7 @@ using Variant = ::std::variant;
 }  // namespace internal
 }  // namespace testing
 // The case where absl is configured NOT to alias std::variant is not supported.
-#endif  // __has_include() && __cplusplus >= 201703L
+#endif  // __has_include() && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
 #endif  // __has_include
 #endif  // GTEST_HAS_ABSL