diff --git a/deps/googletest/include/gtest/gtest-assertion-result.h b/deps/googletest/include/gtest/gtest-assertion-result.h index 7a5e223fa211..a72ac939102e 100644 --- a/deps/googletest/include/gtest/gtest-assertion-result.h +++ b/deps/googletest/include/gtest/gtest-assertion-result.h @@ -158,13 +158,18 @@ class GTEST_API_ [[nodiscard]] AssertionResult { // The second parameter prevents this overload from being considered if // the argument is implicitly convertible to AssertionResult. In that case // we want AssertionResult's copy constructor to be used. - template - explicit AssertionResult( - const T& success, - std::enable_if_t>* - /*enabler*/ - = nullptr) - : success_(success) {} + template && + !std::is_trivially_constructible_v, + int> = 0> + explicit AssertionResult(T&& success) : success_(std::forward(success)) {} + + // Similar to the mutable overload, but for cases where mutability is + // unnecessary or problematic (e.g., bitfields). + template , + int> = 0> + explicit AssertionResult(const T& success) : success_(success) {} #if defined(_MSC_VER) && (_MSC_VER < 1910 || _MSC_VER >= 1920) GTEST_DISABLE_MSC_WARNINGS_POP_() @@ -226,6 +231,24 @@ class GTEST_API_ [[nodiscard]] AssertionResult { std::unique_ptr< ::std::string> message_; }; +namespace internal { + +// A pair containing the result that an assertion is evaluating, and the +// expected result (true, false). +// +// Contains a conversion operator that indicates whether the two match. +struct AssertionResultExpectation { + testing::AssertionResult assertion_result; + bool expected_result; + + explicit operator bool() const { + bool converted(assertion_result); + return converted == expected_result; + } +}; + +} // namespace internal + // Makes a successful assertion result. GTEST_API_ AssertionResult AssertionSuccess(); diff --git a/deps/googletest/include/gtest/gtest-printers.h b/deps/googletest/include/gtest/gtest-printers.h index a13815733eff..fc0913ff0094 100644 --- a/deps/googletest/include/gtest/gtest-printers.h +++ b/deps/googletest/include/gtest/gtest-printers.h @@ -945,13 +945,13 @@ template class [[nodiscard]] UniversalPrinter> { public: static void Print(const std::optional& value, ::std::ostream* os) { - *os << '('; if (!value) { - *os << "nullopt"; + UniversalPrint(std::nullopt, os); } else { + *os << '('; UniversalPrint(*value, os); + *os << ')'; } - *os << ')'; } }; @@ -961,27 +961,38 @@ class [[nodiscard]] UniversalPrinter { static void Print(std::nullopt_t, ::std::ostream* os) { *os << "(nullopt)"; } }; +struct UniversalPrinterVisitor { + template + void operator()(const T& arg) const { + *os << "'" << GetTypeName() << "(index = " << index << ")' with value "; + UniversalPrint(arg, os); + } + ::std::ostream* os; + std::size_t index; +}; + // Printer for std::variant template class [[nodiscard]] UniversalPrinter> { public: static void Print(const std::variant& value, ::std::ostream* os) { - *os << '('; - std::visit(Visitor{os, value.index()}, value); - *os << ')'; + if (value.valueless_by_exception()) { + *os << "(valueless)"; + } else { + *os << '('; + std::visit(UniversalPrinterVisitor{os, value.index()}, value); + *os << ')'; + } } +}; - private: - struct Visitor { - template - void operator()(const U& u) const { - *os << "'" << GetTypeName() << "(index = " << index - << ")' with value "; - UniversalPrint(u, os); - } - ::std::ostream* os; - std::size_t index; - }; +// Printer for std::monostate +template <> +class [[nodiscard]] UniversalPrinter { + public: + static void Print(std::monostate, ::std::ostream* os) { + *os << "(monostate)"; + } }; // UniversalPrintArray(begin, len, os) prints an array of 'len' diff --git a/deps/googletest/include/gtest/gtest.h b/deps/googletest/include/gtest/gtest.h index a7193379b9ff..089b10e9f7a9 100644 --- a/deps/googletest/include/gtest/gtest.h +++ b/deps/googletest/include/gtest/gtest.h @@ -1818,14 +1818,13 @@ class [[nodiscard]] TestWithParam : public Test, #define GTEST_EXPECT_TRUE(condition) \ GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \ GTEST_NONFATAL_FAILURE_) -#define GTEST_EXPECT_FALSE(condition) \ - GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ +#define GTEST_EXPECT_FALSE(condition) \ + GTEST_TEST_BOOLEAN_(condition, #condition, true, false, \ GTEST_NONFATAL_FAILURE_) #define GTEST_ASSERT_TRUE(condition) \ GTEST_TEST_BOOLEAN_(condition, #condition, false, true, GTEST_FATAL_FAILURE_) -#define GTEST_ASSERT_FALSE(condition) \ - GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ - GTEST_FATAL_FAILURE_) +#define GTEST_ASSERT_FALSE(condition) \ + GTEST_TEST_BOOLEAN_(condition, #condition, true, false, GTEST_FATAL_FAILURE_) // Define these macros to 1 to omit the definition of the corresponding // EXPECT or ASSERT, which clashes with some users' own code. diff --git a/deps/googletest/include/gtest/internal/gtest-internal.h b/deps/googletest/include/gtest/internal/gtest-internal.h index 8f66d1b35641..2b048c5dc098 100644 --- a/deps/googletest/include/gtest/internal/gtest-internal.h +++ b/deps/googletest/include/gtest/internal/gtest-internal.h @@ -1453,12 +1453,12 @@ class [[nodiscard]] NeverThrown { // representation of expression as it was passed into the EXPECT_TRUE. #define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (const ::testing::AssertionResult gtest_ar_ = \ - ::testing::AssertionResult(expression)) \ + if (::testing::internal::AssertionResultExpectation gtest_are_ = { \ + ::testing::AssertionResult(expression), expected}) \ ; \ else \ fail(::testing::internal::GetBoolAssertionFailureMessage( \ - gtest_ar_, text, #actual, #expected)) + gtest_are_.assertion_result, text, #actual, #expected)) #define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ diff --git a/deps/googletest/include/gtest/internal/gtest-port.h b/deps/googletest/include/gtest/internal/gtest-port.h index 8b32daeced23..31654b09c1dc 100644 --- a/deps/googletest/include/gtest/internal/gtest-port.h +++ b/deps/googletest/include/gtest/internal/gtest-port.h @@ -363,18 +363,24 @@ #define GTEST_DISABLE_MSC_WARNINGS_POP_() #endif -// Clang on Windows does not understand MSVC's pragma warning. -// We need clang-specific way to disable function deprecation warning. -#ifdef __clang__ -#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \ +// Pragmas to disable function deprecation warnings. +#if defined(__clang__) +#define GTEST_DISABLE_DEPRECATED_PUSH_() \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \ _Pragma("clang diagnostic ignored \"-Wdeprecated-implementations\"") -#define GTEST_DISABLE_MSC_DEPRECATED_POP_() _Pragma("clang diagnostic pop") +#define GTEST_DISABLE_DEPRECATED_POP_() _Pragma("clang diagnostic pop") +#elif defined(__GNUC__) +#define GTEST_DISABLE_DEPRECATED_PUSH_() \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#define GTEST_DISABLE_DEPRECATED_POP_() _Pragma("GCC diagnostic pop") +#elif defined(_MSC_VER) +#define GTEST_DISABLE_DEPRECATED_PUSH_() GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) +#define GTEST_DISABLE_DEPRECATED_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_() #else -#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \ - GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) -#define GTEST_DISABLE_MSC_DEPRECATED_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_() +#define GTEST_DISABLE_DEPRECATED_PUSH_() +#define GTEST_DISABLE_DEPRECATED_POP_() #endif // Brings in definitions for functions used in the testing::internal::posix @@ -2119,7 +2125,7 @@ inline int IsATTY(int fd) { // Functions deprecated by MSVC 8.0. -GTEST_DISABLE_MSC_DEPRECATED_PUSH_() +GTEST_DISABLE_DEPRECATED_PUSH_() // ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and // StrError() aren't needed on Windows CE at this time and thus not @@ -2181,7 +2187,7 @@ inline const char* GetEnv(const char* name) { #endif } -GTEST_DISABLE_MSC_DEPRECATED_POP_() +GTEST_DISABLE_DEPRECATED_POP_() #ifdef GTEST_OS_WINDOWS_MOBILE // Windows CE has no C library. The abort() function is used in @@ -2302,22 +2308,29 @@ using TimeInMillis = int64_t; // Represents time in milliseconds. // Macros for defining flags. #define GTEST_DEFINE_bool_(name, default_val, doc) \ + GTEST_DECLARE_bool_(name); \ namespace testing { \ GTEST_API_ bool GTEST_FLAG(name) = (default_val); \ } \ static_assert(true, "no-op to require trailing semicolon") #define GTEST_DEFINE_int32_(name, default_val, doc) \ + GTEST_DECLARE_int32_(name); \ namespace testing { \ GTEST_API_ std::int32_t GTEST_FLAG(name) = (default_val); \ } \ static_assert(true, "no-op to require trailing semicolon") #define GTEST_DEFINE_string_(name, default_val, doc) \ + GTEST_DECLARE_string_(name); \ namespace testing { \ GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val); \ } \ static_assert(true, "no-op to require trailing semicolon") // Macros for declaring flags. +// +// We also need to declare the flag in the public namespace to avoid triggering +// -Wmissing-variable-declarations warnings, as reported here: +// https://github.com/google/googletest/issues/4897 #define GTEST_DECLARE_bool_(name) \ namespace testing { \ GTEST_API_ extern bool GTEST_FLAG(name); \ diff --git a/deps/googletest/src/gtest-internal-inl.h b/deps/googletest/src/gtest-internal-inl.h index 2ebfcd39ef56..4bebca1bc656 100644 --- a/deps/googletest/src/gtest-internal-inl.h +++ b/deps/googletest/src/gtest-internal-inl.h @@ -587,7 +587,7 @@ class GTEST_API_ UnitTestImpl { // total_test_suite_count() - 1. If i is not in that range, returns NULL. const TestSuite* GetTestSuite(int i) const { const int index = GetElementOr(test_suite_indices_, i, -1); - return index < 0 ? nullptr : test_suites_[static_cast(i)]; + return index < 0 ? nullptr : test_suites_[static_cast(index)]; } // Legacy API is deprecated but still available @@ -1106,7 +1106,7 @@ class StreamingListener : public EmptyTestEventListener { GTEST_CHECK_(sockfd_ != -1) << "Send() can be called only when there is a connection."; - const auto len = static_cast(message.length()); + const size_t len = message.length(); if (write(sockfd_, message.c_str(), len) != static_cast(len)) { GTEST_LOG_(WARNING) << "stream_result_to: failed to stream to " << host_name_ << ":" << port_num_; diff --git a/deps/googletest/src/gtest-port.cc b/deps/googletest/src/gtest-port.cc index d34a693e4500..433586f3b711 100644 --- a/deps/googletest/src/gtest-port.cc +++ b/deps/googletest/src/gtest-port.cc @@ -1069,7 +1069,7 @@ GTestLog::~GTestLog() { // Disable Microsoft deprecation warnings for POSIX functions called from // this class (creat, dup, dup2, and close) -GTEST_DISABLE_MSC_DEPRECATED_PUSH_() +GTEST_DISABLE_DEPRECATED_PUSH_() namespace { @@ -1095,10 +1095,12 @@ class CapturedStream { 0, // Generate unique file name. temp_file_path); GTEST_CHECK_(success != 0) - << "Unable to create a temporary file in " << temp_dir_path; + << "Failed to create temporary file in " << temp_dir_path + << " with error " << ::GetLastError(); const int captured_fd = creat(temp_file_path, _S_IREAD | _S_IWRITE); GTEST_CHECK_(captured_fd != -1) - << "Unable to open temporary file " << temp_file_path; + << "Failed to open temporary file " << temp_file_path << " with error " + << ::GetLastError(); filename_ = temp_file_path; #else // There's no guarantee that a test has write access to the current @@ -1200,7 +1202,7 @@ class CapturedStream { CapturedStream& operator=(const CapturedStream&) = delete; }; -GTEST_DISABLE_MSC_DEPRECATED_POP_() +GTEST_DISABLE_DEPRECATED_POP_() static CapturedStream* g_captured_stderr = nullptr; static CapturedStream* g_captured_stdout = nullptr; diff --git a/deps/googletest/src/gtest.cc b/deps/googletest/src/gtest.cc index b38f551e036f..307ecc6f0b9c 100644 --- a/deps/googletest/src/gtest.cc +++ b/deps/googletest/src/gtest.cc @@ -1209,7 +1209,7 @@ int UnitTestImpl::test_to_run_count() const { // trace but Bar() and CurrentOsStackTraceExceptTop() won't. std::string UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) { return os_stack_trace_getter()->CurrentStackTrace( - static_cast(GTEST_FLAG_GET(stack_trace_depth)), skip_count + 1 + GTEST_FLAG_GET(stack_trace_depth), skip_count + 1 // Skips the user-specified number of frames plus this function // itself. ); // NOLINT @@ -2700,7 +2700,7 @@ Result HandleSehExceptionsInMethodIfSupported(T* object, Result (T::*method)(), } // Runs the given method and catches and reports C++ and/or SEH-style -// exceptions, if they are supported; returns the 0-value for type +// exceptions, if they are supported; returns the default-value for type // Result in case of an SEH exception. template Result HandleExceptionsInMethodIfSupported(T* object, Result (T::*method)(), @@ -2748,7 +2748,7 @@ Result HandleExceptionsInMethodIfSupported(T* object, Result (T::*method)(), TestPartResult::kFatalFailure, FormatCxxExceptionMessage(nullptr, location)); } - return static_cast(0); + return Result(); #else return HandleSehExceptionsInMethodIfSupported(object, method, location); #endif // GTEST_HAS_EXCEPTIONS @@ -4239,8 +4239,7 @@ void XmlUnitTestResultPrinter::OutputXmlCDataSection(::std::ostream* stream, for (;;) { const char* const next_segment = strstr(segment, "]]>"); if (next_segment != nullptr) { - stream->write(segment, - static_cast(next_segment - segment)); + stream->write(segment, next_segment - segment); *stream << "]]>]]>"); } else { @@ -5172,9 +5171,12 @@ class ScopedPrematureExitFile { // create the file with a single "0" character in it. I/O // errors are ignored as there's nothing better we can do and we // don't want to fail the test because of this. - FILE* pfile = posix::FOpen(premature_exit_filepath_.c_str(), "w"); - fwrite("0", 1, 1, pfile); - fclose(pfile); + if (FILE* pfile = posix::FOpen(premature_exit_filepath_.c_str(), "w")) { + fwrite("0", 1, 1, pfile); + fclose(pfile); + } else { + premature_exit_filepath_.clear(); + } } } @@ -5192,7 +5194,7 @@ class ScopedPrematureExitFile { } private: - const std::string premature_exit_filepath_; + std::string premature_exit_filepath_; ScopedPrematureExitFile(const ScopedPrematureExitFile&) = delete; ScopedPrematureExitFile& operator=(const ScopedPrematureExitFile&) = delete;