diff options
author | thegeorg <thegeorg@yandex-team.com> | 2023-06-07 20:50:34 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2023-06-07 20:50:34 +0300 |
commit | 07219c4ed034bb8dff31ae035ceba5a6da9b29b0 (patch) | |
tree | 3b6db9529551ccea4ac93ceab4fbabbc09816c8c | |
parent | 029d9d97f20c0311ee78c82a8044849ed79cd03f (diff) | |
download | ydb-07219c4ed034bb8dff31ae035ceba5a6da9b29b0.tar.gz |
Update contrib/restricted/googletest to 1.13.0
30 files changed, 804 insertions, 292 deletions
diff --git a/contrib/restricted/googletest/googlemock/include/gmock/gmock-actions.h b/contrib/restricted/googletest/googlemock/include/gmock/gmock-actions.h index c785ad8abba..aad07d51cc1 100644 --- a/contrib/restricted/googletest/googlemock/include/gmock/gmock-actions.h +++ b/contrib/restricted/googletest/googlemock/include/gmock/gmock-actions.h @@ -122,7 +122,7 @@ // MORE INFORMATION: // // To learn more about using these macros, please search for 'ACTION' on -// https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md +// https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md // IWYU pragma: private, include "gmock/gmock.h" // IWYU pragma: friend gmock/.* @@ -1428,8 +1428,10 @@ struct WithArgsAction { // MSVC complains about the I parameter pack not being // expanded (error C3520) despite it being expanded in the // type alias. - OnceAction<R(typename std::tuple_element< - I, std::tuple<Args...>>::type...)>>::value, + // TupleElement is also an MSVC workaround. + // See its definition for details. + OnceAction<R(internal::TupleElement< + I, std::tuple<Args...>>...)>>::value, int>::type = 0> operator OnceAction<R(Args...)>() && { // NOLINT struct OA { @@ -1453,8 +1455,10 @@ struct WithArgsAction { // MSVC complains about the I parameter pack not being // expanded (error C3520) despite it being expanded in the // type alias. - Action<R(typename std::tuple_element< - I, std::tuple<Args...>>::type...)>>::value, + // TupleElement is also an MSVC workaround. + // See its definition for details. + Action<R(internal::TupleElement< + I, std::tuple<Args...>>...)>>::value, int>::type = 0> operator Action<R(Args...)>() const { // NOLINT Action<InnerSignature<R, Args...>> converted(inner_action); diff --git a/contrib/restricted/googletest/googlemock/include/gmock/gmock-function-mocker.h b/contrib/restricted/googletest/googlemock/include/gmock/gmock-function-mocker.h index f565d980c56..73065493b38 100644 --- a/contrib/restricted/googletest/googlemock/include/gmock/gmock-function-mocker.h +++ b/contrib/restricted/googletest/googlemock/include/gmock/gmock-function-mocker.h @@ -34,8 +34,8 @@ // IWYU pragma: private, include "gmock/gmock.h" // IWYU pragma: friend gmock/.* -#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT -#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT +#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_ +#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_ #include <type_traits> // IWYU pragma: keep #include <utility> // IWYU pragma: keep @@ -108,8 +108,11 @@ constexpr bool ValidateSpec(const char (&spec)[N]) { using internal::FunctionMocker; } // namespace testing -#define MOCK_METHOD(...) \ - GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__) +#define MOCK_METHOD(...) \ + GMOCK_INTERNAL_WARNING_PUSH() \ + GMOCK_INTERNAL_WARNING_CLANG(ignored, "-Wunused-member-function") \ + GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__) \ + GMOCK_INTERNAL_WARNING_POP() #define GMOCK_INTERNAL_MOCK_METHOD_ARG_1(...) \ GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) @@ -511,4 +514,4 @@ using internal::FunctionMocker; #define GMOCK_MOCKER_(arity, constness, Method) \ GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) -#endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ +#endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_ diff --git a/contrib/restricted/googletest/googlemock/include/gmock/gmock-matchers.h b/contrib/restricted/googletest/googlemock/include/gmock/gmock-matchers.h index 6282901145a..9e634f7f1c4 100644 --- a/contrib/restricted/googletest/googlemock/include/gmock/gmock-matchers.h +++ b/contrib/restricted/googletest/googlemock/include/gmock/gmock-matchers.h @@ -240,7 +240,7 @@ // // To learn more about using these macros, please search for 'MATCHER' // on -// https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md +// https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md // // This file also implements some commonly used argument matchers. More // matchers can be defined by the user implementing the @@ -258,6 +258,7 @@ #include <algorithm> #include <cmath> #include <initializer_list> +#include <ios> #include <iterator> #include <limits> #include <memory> @@ -2309,11 +2310,11 @@ class SizeIsMatcher { : size_matcher_(MatcherCast<SizeType>(size_matcher)) {} void DescribeTo(::std::ostream* os) const override { - *os << "size "; + *os << "has a size that "; size_matcher_.DescribeTo(os); } void DescribeNegationTo(::std::ostream* os) const override { - *os << "size "; + *os << "has a size that "; size_matcher_.DescribeNegationTo(os); } @@ -3235,6 +3236,21 @@ auto UnpackStructImpl(const T& t, MakeIndexSequence<16>, char) { const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p] = t; return std::tie(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p); } +template <typename T> +auto UnpackStructImpl(const T& t, MakeIndexSequence<17>, char) { + const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q] = t; + return std::tie(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q); +} +template <typename T> +auto UnpackStructImpl(const T& t, MakeIndexSequence<18>, char) { + const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r] = t; + return std::tie(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r); +} +template <typename T> +auto UnpackStructImpl(const T& t, MakeIndexSequence<19>, char) { + const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s] = t; + return std::tie(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s); +} #endif // defined(__cpp_structured_bindings) template <size_t I, typename T> @@ -3301,8 +3317,8 @@ class FieldsAreMatcherImpl<Struct, IndexSequence<I...>> std::vector<StringMatchResultListener> inner_listener(sizeof...(I)); VariadicExpand( - {failed_pos == ~size_t{} && !std::get<I>(matchers_).MatchAndExplain( - std::get<I>(tuple), &inner_listener[I]) + {failed_pos == ~size_t{}&& !std::get<I>(matchers_).MatchAndExplain( + std::get<I>(tuple), &inner_listener[I]) ? failed_pos = I : 0 ...}); if (failed_pos != ~size_t{}) { @@ -3629,23 +3645,6 @@ class UnorderedElementsAreMatcherImpl AnalyzeElements(stl_container.begin(), stl_container.end(), &element_printouts, listener); - if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) { - return true; - } - - if (match_flags() == UnorderedMatcherRequire::ExactMatch) { - if (matrix.LhsSize() != matrix.RhsSize()) { - // The element count doesn't match. If the container is empty, - // there's no need to explain anything as Google Mock already - // prints the empty container. Otherwise we just need to show - // how many elements there actually are. - if (matrix.LhsSize() != 0 && listener->IsInterested()) { - *listener << "which has " << Elements(matrix.LhsSize()); - } - return false; - } - } - return VerifyMatchMatrix(element_printouts, matrix, listener) && FindPairing(matrix, listener); } @@ -4100,7 +4099,12 @@ class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> { const char* sep = ""; // Workaround spurious C4189 on MSVC<=15.7 when k is empty. (void)sep; - const char* dummy[] = {"", (*os << sep << "#" << k, sep = ", ")...}; + // The static_cast to void is needed to silence Clang's -Wcomma warning. + // This pattern looks suspiciously like we may have mismatched parentheses + // and may have been trying to use the first operation of the comma operator + // as a member of the array, so Clang warns that we may have made a mistake. + const char* dummy[] = { + "", (static_cast<void>(*os << sep << "#" << k), sep = ", ")...}; (void)dummy; *os << ") "; } @@ -5467,7 +5471,13 @@ PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> ThrowsMessage( } \ }; \ }; \ - GTEST_ATTRIBUTE_UNUSED_ inline name##Matcher name() { return {}; } \ + inline name##Matcher GMOCK_INTERNAL_WARNING_PUSH() \ + GMOCK_INTERNAL_WARNING_CLANG(ignored, "-Wunused-function") \ + GMOCK_INTERNAL_WARNING_CLANG(ignored, "-Wunused-member-function") \ + name \ + GMOCK_INTERNAL_WARNING_POP()() { \ + return {}; \ + } \ template <typename arg_type> \ bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain( \ const arg_type& arg, \ diff --git a/contrib/restricted/googletest/googlemock/include/gmock/gmock-more-matchers.h b/contrib/restricted/googletest/googlemock/include/gmock/gmock-more-matchers.h index 47aaf98461e..d9a92107380 100644 --- a/contrib/restricted/googletest/googlemock/include/gmock/gmock-more-matchers.h +++ b/contrib/restricted/googletest/googlemock/include/gmock/gmock-more-matchers.h @@ -40,6 +40,9 @@ #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_ #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_ +#include <ostream> +#include <string> + #include "gmock/gmock-matchers.h" namespace testing { @@ -56,14 +59,42 @@ namespace testing { #endif #endif -// Defines a matcher that matches an empty container. The container must -// support both size() and empty(), which all STL-like containers provide. -MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { - if (arg.empty()) { - return true; +namespace internal { + +// Implements the polymorphic IsEmpty matcher, which +// can be used as a Matcher<T> as long as T is either a container that defines +// empty() and size() (e.g. std::vector or std::string), or a C-style string. +class IsEmptyMatcher { + public: + // Matches anything that defines empty() and size(). + template <typename MatcheeContainerType> + bool MatchAndExplain(const MatcheeContainerType& c, + MatchResultListener* listener) const { + if (c.empty()) { + return true; + } + *listener << "whose size is " << c.size(); + return false; + } + + // Matches C-style strings. + bool MatchAndExplain(const char* s, MatchResultListener* listener) const { + return MatchAndExplain(std::string(s), listener); } - *result_listener << "whose size is " << arg.size(); - return false; + + // Describes what this matcher matches. + void DescribeTo(std::ostream* os) const { *os << "is empty"; } + + void DescribeNegationTo(std::ostream* os) const { *os << "isn't empty"; } +}; + +} // namespace internal + +// Creates a polymorphic matcher that matches an empty container or C-style +// string. The container must support both size() and empty(), which all +// STL-like containers provide. +inline PolymorphicMatcher<internal::IsEmptyMatcher> IsEmpty() { + return MakePolymorphicMatcher(internal::IsEmptyMatcher()); } // Define a matcher that matches a value that evaluates in boolean diff --git a/contrib/restricted/googletest/googlemock/include/gmock/gmock-spec-builders.h b/contrib/restricted/googletest/googlemock/include/gmock/gmock-spec-builders.h index 45cc605183c..4e498d8f54f 100644 --- a/contrib/restricted/googletest/googlemock/include/gmock/gmock-spec-builders.h +++ b/contrib/restricted/googletest/googlemock/include/gmock/gmock-spec-builders.h @@ -65,6 +65,7 @@ #include <functional> #include <map> #include <memory> +#include <ostream> #include <set> #include <sstream> #include <string> @@ -656,7 +657,7 @@ class GTEST_API_ InSequence { InSequence(const InSequence&) = delete; InSequence& operator=(const InSequence&) = delete; -} GTEST_ATTRIBUTE_UNUSED_; +}; namespace internal { @@ -706,6 +707,12 @@ class GTEST_API_ ExpectationBase { // describes it to the ostream. virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0; + // Do not rely on this for correctness. + // This is only for making human-readable test output easier to understand. + void UntypedDescription(std::string description) { + description_ = std::move(description); + } + protected: friend class ::testing::Expectation; friend class UntypedFunctionMockerBase; @@ -772,6 +779,10 @@ class GTEST_API_ ExpectationBase { retired_ = true; } + // Returns a human-readable description of this expectation. + // Do not rely on this for correctness. It is only for human readability. + const std::string& GetDescription() const { return description_; } + // Returns true if and only if this expectation is satisfied. bool IsSatisfied() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { g_gmock_mutex.AssertHeld(); @@ -831,6 +842,7 @@ class GTEST_API_ ExpectationBase { const char* file_; // The file that contains the expectation. int line_; // The line number of the expectation. const std::string source_text_; // The EXPECT_CALL(...) source text. + std::string description_; // User-readable name for the expectation. // True if and only if the cardinality is specified explicitly. bool cardinality_specified_; Cardinality cardinality_; // The cardinality of the expectation. @@ -909,6 +921,13 @@ class TypedExpectation<R(Args...)> : public ExpectationBase { return *this; } + // Do not rely on this for correctness. + // This is only for making human-readable test output easier to understand. + TypedExpectation& Description(std::string name) { + ExpectationBase::UntypedDescription(std::move(name)); + return *this; + } + // Implements the .Times() clause. TypedExpectation& Times(const Cardinality& a_cardinality) { ExpectationBase::UntypedTimes(a_cardinality); @@ -1199,10 +1218,15 @@ class TypedExpectation<R(Args...)> : public ExpectationBase { ::std::ostream* why) GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { g_gmock_mutex.AssertHeld(); + const ::std::string& expectation_description = GetDescription(); if (IsSaturated()) { // We have an excessive call. IncrementCallCount(); - *what << "Mock function called more times than expected - "; + *what << "Mock function "; + if (!expectation_description.empty()) { + *what << "\"" << expectation_description << "\" "; + } + *what << "called more times than expected - "; mocker->DescribeDefaultActionTo(args, what); DescribeCallCountTo(why); @@ -1217,7 +1241,11 @@ class TypedExpectation<R(Args...)> : public ExpectationBase { } // Must be done after IncrementCount()! - *what << "Mock function call matches " << source_text() << "...\n"; + *what << "Mock function "; + if (!expectation_description.empty()) { + *what << "\"" << expectation_description << "\" "; + } + *what << "call matches " << source_text() << "...\n"; return &(GetCurrentAction(mocker, args)); } diff --git a/contrib/restricted/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h b/contrib/restricted/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h index b1343fdc82d..36ab8e26a8a 100644 --- a/contrib/restricted/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/contrib/restricted/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -95,6 +95,24 @@ inline Element* GetRawPointer(Element* p) { return p; } +// Default definitions for all compilers. +// NOTE: If you implement support for other compilers, make sure to avoid +// unexpected overlaps. +// (e.g., Clang also processes #pragma GCC, and clang-cl also handles _MSC_VER.) +#define GMOCK_INTERNAL_WARNING_PUSH() +#define GMOCK_INTERNAL_WARNING_CLANG(Level, Name) +#define GMOCK_INTERNAL_WARNING_POP() + +#if defined(__clang__) +#undef GMOCK_INTERNAL_WARNING_PUSH +#define GMOCK_INTERNAL_WARNING_PUSH() _Pragma("clang diagnostic push") +#undef GMOCK_INTERNAL_WARNING_CLANG +#define GMOCK_INTERNAL_WARNING_CLANG(Level, Warning) \ + _Pragma(GMOCK_PP_INTERNAL_STRINGIZE(clang diagnostic Level Warning)) +#undef GMOCK_INTERNAL_WARNING_POP +#define GMOCK_INTERNAL_WARNING_POP() _Pragma("clang diagnostic pop") +#endif + // MSVC treats wchar_t as a native type usually, but treats it as the // same as unsigned short when the compiler option /Zc:wchar_t- is // specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t @@ -290,13 +308,6 @@ class WithoutMatchers { // Internal use only: access the singleton instance of WithoutMatchers. GTEST_API_ WithoutMatchers GetWithoutMatchers(); -// Disable MSVC warnings for infinite recursion, since in this case the -// recursion is unreachable. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4717) -#endif - // Invalid<T>() is usable as an expression of type T, but will terminate // the program with an assertion failure if actually run. This is useful // when a value of type T is needed for compilation, but the statement @@ -314,10 +325,6 @@ inline T Invalid() { #endif } -#ifdef _MSC_VER -#pragma warning(pop) -#endif - // Given a raw type (i.e. having no top-level reference or const // modifier) RawContainer that's either an STL-style container or a // native array, class StlContainerView<RawContainer> has the @@ -464,6 +471,13 @@ struct Function<R(Args...)> { template <typename R, typename... Args> constexpr size_t Function<R(Args...)>::ArgumentCount; +// Workaround for MSVC error C2039: 'type': is not a member of 'std' +// when std::tuple_element is used. +// See: https://github.com/google/googletest/issues/3931 +// Can be replaced with std::tuple_element_t in C++14. +template <size_t I, typename T> +using TupleElement = typename std::tuple_element<I, T>::type; + bool Base64Unescape(const std::string& encoded, std::string* decoded); #ifdef _MSC_VER diff --git a/contrib/restricted/googletest/googlemock/src/gmock-internal-utils.cc b/contrib/restricted/googletest/googlemock/src/gmock-internal-utils.cc index 0a74841f35b..7bfff02a33c 100644 --- a/contrib/restricted/googletest/googlemock/src/gmock-internal-utils.cc +++ b/contrib/restricted/googletest/googlemock/src/gmock-internal-utils.cc @@ -181,7 +181,7 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message, } std::cout << "Stack trace:\n" << ::testing::internal::GetCurrentOsStackTraceExceptTop( - ::testing::UnitTest::GetInstance(), actual_to_skip); + actual_to_skip); } std::cout << ::std::flush; } @@ -199,9 +199,10 @@ GTEST_API_ void IllegalDoDefault(const char* file, int line) { } constexpr char UnBase64Impl(char c, const char* const base64, char carry) { - return *base64 == 0 ? static_cast<char>(65) - : *base64 == c ? carry - : UnBase64Impl(c, base64 + 1, carry + 1); + return *base64 == 0 ? static_cast<char>(65) + : *base64 == c + ? carry + : UnBase64Impl(c, base64 + 1, static_cast<char>(carry + 1)); } template <size_t... I> diff --git a/contrib/restricted/googletest/googlemock/src/gmock-matchers.cc b/contrib/restricted/googletest/googlemock/src/gmock-matchers.cc index a8d04a6da0c..5810b6aa391 100644 --- a/contrib/restricted/googletest/googlemock/src/gmock-matchers.cc +++ b/contrib/restricted/googletest/googlemock/src/gmock-matchers.cc @@ -370,6 +370,23 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl( bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix( const ::std::vector<std::string>& element_printouts, const MatchMatrix& matrix, MatchResultListener* listener) const { + if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) { + return true; + } + + if (match_flags() == UnorderedMatcherRequire::ExactMatch) { + if (matrix.LhsSize() != matrix.RhsSize()) { + // The element count doesn't match. If the container is empty, + // there's no need to explain anything as Google Mock already + // prints the empty container. Otherwise we just need to show + // how many elements there actually are. + if (matrix.LhsSize() != 0 && listener->IsInterested()) { + *listener << "which has " << Elements(matrix.LhsSize()); + } + return false; + } + } + bool result = true; ::std::vector<char> element_matched(matrix.LhsSize(), 0); ::std::vector<char> matcher_matched(matrix.RhsSize(), 0); diff --git a/contrib/restricted/googletest/googlemock/src/gmock-spec-builders.cc b/contrib/restricted/googletest/googlemock/src/gmock-spec-builders.cc index 658ad3fa229..7cc3bcc28db 100644 --- a/contrib/restricted/googletest/googlemock/src/gmock-spec-builders.cc +++ b/contrib/restricted/googletest/googlemock/src/gmock-spec-builders.cc @@ -51,6 +51,9 @@ #if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC #include <unistd.h> // NOLINT #endif +#if GTEST_OS_QURT +#error #include <qurt_event.h> +#endif // Silence C4800 (C4800: 'int *const ': forcing value // to bool 'true' or 'false') for MSVC 15 @@ -295,7 +298,7 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) { "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/master/docs/" + "https://github.com/google/googletest/blob/main/docs/" "gmock_cook_book.md#" "knowing-when-to-expect for details.\n", stack_frames_to_skip); @@ -406,8 +409,15 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked() } else if (!untyped_expectation->IsSatisfied()) { expectations_met = false; ::std::stringstream ss; - ss << "Actual function call count doesn't match " - << untyped_expectation->source_text() << "...\n"; + + const ::std::string& expectation_name = + untyped_expectation->GetDescription(); + ss << "Actual function "; + if (!expectation_name.empty()) { + ss << "\"" << expectation_name << "\" "; + } + ss << "call count doesn't match " << untyped_expectation->source_text() + << "...\n"; // No need to show the source file location of the expectation // in the description, as the Expect() call that follows already // takes care of it. @@ -435,7 +445,7 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked() return expectations_met; } -CallReaction intToCallReaction(int mock_behavior) { +static CallReaction intToCallReaction(int mock_behavior) { if (mock_behavior >= kAllow && mock_behavior <= kFail) { return static_cast<internal::CallReaction>(mock_behavior); } @@ -519,8 +529,12 @@ 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 + qurt_exception_raise_fatal(); +#else _exit(1); // We cannot call exit() as it is not reentrant and // may already have been called. +#endif } } diff --git a/contrib/restricted/googletest/googletest/README.md b/contrib/restricted/googletest/googletest/README.md index d26b309ed0d..9bdbcec04c9 100644 --- a/contrib/restricted/googletest/googletest/README.md +++ b/contrib/restricted/googletest/googletest/README.md @@ -9,7 +9,7 @@ depends on which build system you use, and is usually straightforward. ### Build with CMake GoogleTest comes with a CMake build script -([CMakeLists.txt](https://github.com/google/googletest/blob/master/CMakeLists.txt)) +([CMakeLists.txt](https://github.com/google/googletest/blob/main/CMakeLists.txt)) that can be used on a wide range of platforms ("C" stands for cross-platform.). If you don't have CMake installed already, you can download it for free from <http://www.cmake.org/>. @@ -25,7 +25,7 @@ When building GoogleTest as a standalone project, the typical workflow starts with ``` -git clone https://github.com/google/googletest.git -b release-1.11.0 +git clone https://github.com/google/googletest.git -b release-1.12.1 cd googletest # Main directory of the cloned repository. mkdir build # Create a directory to hold the build output. cd build @@ -94,7 +94,7 @@ include(FetchContent) FetchContent_Declare( googletest # Specify the commit you depend on and update it regularly. - URL https://github.com/google/googletest/archive/e2239ee6043f73722e7aa812a459f54a28552929.zip + URL https://github.com/google/googletest/archive/5376968f6948923e2411081fd9372e71a59d8e77.zip ) # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) @@ -140,7 +140,7 @@ command line. Generally, these macros are named like `GTEST_XYZ` and you define them to either 1 or 0 to enable or disable a certain feature. We list the most frequently used macros below. For a complete list, see file -[include/gtest/internal/gtest-port.h](https://github.com/google/googletest/blob/master/googletest/include/gtest/internal/gtest-port.h). +[include/gtest/internal/gtest-port.h](https://github.com/google/googletest/blob/main/googletest/include/gtest/internal/gtest-port.h). ### Multi-threaded Tests @@ -186,9 +186,9 @@ to the compiler flags. Note: while the above steps aren't technically necessary today when using some compilers (e.g. GCC), they may become necessary in the future, if we decide to improve the speed of loading the library (see -<http://gcc.gnu.org/wiki/Visibility> for details). Therefore you are recommended -to always add the above flags when using GoogleTest as a shared library. -Otherwise a future release of GoogleTest may break your build script. +<https://gcc.gnu.org/wiki/Visibility> for details). Therefore you are +recommended to always add the above flags when using GoogleTest as a shared +library. Otherwise a future release of GoogleTest may break your build script. ### Avoiding Macro Name Clashes diff --git a/contrib/restricted/googletest/googletest/include/gtest/gtest-matchers.h b/contrib/restricted/googletest/googletest/include/gtest/gtest-matchers.h index 29fae035553..e440b284de2 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/gtest-matchers.h +++ b/contrib/restricted/googletest/googletest/include/gtest/gtest-matchers.h @@ -844,7 +844,7 @@ class MatchesRegexMatcher { template <class MatcheeStringType> bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { - const std::string& s2(s); + const std::string s2(s); return full_match_ ? RE::FullMatch(s2, *regex_) : RE::PartialMatch(s2, *regex_); } diff --git a/contrib/restricted/googletest/googletest/include/gtest/gtest-message.h b/contrib/restricted/googletest/googletest/include/gtest/gtest-message.h index 6c8bf900094..4d4b152b1d8 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/gtest-message.h +++ b/contrib/restricted/googletest/googletest/include/gtest/gtest-message.h @@ -50,7 +50,9 @@ #include <limits> #include <memory> +#include <ostream> #include <sstream> +#include <string> #include "gtest/internal/gtest-port.h" diff --git a/contrib/restricted/googletest/googletest/include/gtest/gtest-param-test.h b/contrib/restricted/googletest/googletest/include/gtest/gtest-param-test.h index b55119ac62f..1adb9a72520 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/gtest-param-test.h +++ b/contrib/restricted/googletest/googletest/include/gtest/gtest-param-test.h @@ -407,9 +407,49 @@ internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) { return internal::CartesianProductHolder<Generator...>(g...); } +// ConvertGenerator() wraps a parameter generator in order to cast each produced +// value through a known type before supplying it to the test suite +// +// Synopsis: +// ConvertGenerator<T>(gen) +// - returns a generator producing the same elements as generated by gen, but +// each element is static_cast to type T before being returned +// +// It is useful when using the Combine() function to get the generated +// parameters in a custom type instead of std::tuple +// +// Example: +// +// This will instantiate tests in test suite AnimalTest each one with +// the parameter values tuple("cat", BLACK), tuple("cat", WHITE), +// tuple("dog", BLACK), and tuple("dog", WHITE): +// +// enum Color { BLACK, GRAY, WHITE }; +// struct ParamType { +// using TupleT = std::tuple<const char*, Color>; +// std::string animal; +// Color color; +// ParamType(TupleT t) : animal(std::get<0>(t)), color(std::get<1>(t)) {} +// }; +// class AnimalTest +// : public testing::TestWithParam<ParamType> {...}; +// +// TEST_P(AnimalTest, AnimalLooksNice) {...} +// +// INSTANTIATE_TEST_SUITE_P(AnimalVariations, AnimalTest, +// ConvertGenerator<ParamType::TupleT>( +// Combine(Values("cat", "dog"), +// Values(BLACK, WHITE)))); +// +template <typename T> +internal::ParamConverterGenerator<T> ConvertGenerator( + internal::ParamGenerator<T> gen) { + return internal::ParamConverterGenerator<T>(gen); +} + #define TEST_P(test_suite_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - : public test_suite_name { \ + : public test_suite_name, private ::testing::internal::GTestNonCopyable {\ public: \ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \ void TestBody() override; \ @@ -429,11 +469,6 @@ internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) { return 0; \ } \ static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \ - GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - (const GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) &) = delete; \ - GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) & operator=( \ - const GTEST_TEST_CLASS_NAME_(test_suite_name, \ - test_name) &) = delete; /* NOLINT */ \ }; \ int GTEST_TEST_CLASS_NAME_(test_suite_name, \ test_name)::gtest_registering_dummy_ = \ diff --git a/contrib/restricted/googletest/googletest/include/gtest/gtest-printers.h b/contrib/restricted/googletest/googletest/include/gtest/gtest-printers.h index 87a124b9174..e1196721c0b 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/gtest-printers.h +++ b/contrib/restricted/googletest/googletest/include/gtest/gtest-printers.h @@ -108,6 +108,7 @@ #include <string> #include <tuple> #include <type_traits> +#include <typeinfo> #include <utility> #include <vector> @@ -393,7 +394,7 @@ GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char32_t); GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string); GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string); -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char8_t, ::std::u8string); GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char8_t, ::std::u8string); #endif @@ -493,6 +494,81 @@ GTEST_API_ void PrintTo(__uint128_t v, ::std::ostream* os); GTEST_API_ void PrintTo(__int128_t v, ::std::ostream* os); #endif // __SIZEOF_INT128__ +// The default resolution used to print floating-point values uses only +// 6 digits, which can be confusing if a test compares two values whose +// difference lies in the 7th digit. So we'd like to print out numbers +// in full precision. +// However if the value is something simple like 1.1, full will print a +// long string like 1.100000001 due to floating-point numbers not using +// a base of 10. This routiune returns an appropriate resolution for a +// given floating-point number, that is, 6 if it will be accurate, or a +// max_digits10 value (full precision) if it won't, for values between +// 0.0001 and one million. +// It does this by computing what those digits would be (by multiplying +// by an appropriate power of 10), then dividing by that power again to +// see if gets the original value back. +// A similar algorithm applies for values larger than one million; note +// that for those values, we must divide to get a six-digit number, and +// then multiply to possibly get the original value again. +template <typename FloatType> +int AppropriateResolution(FloatType val) { + int full = std::numeric_limits<FloatType>::max_digits10; + if (val < 0) val = -val; + + if (val < 1000000) { + FloatType mulfor6 = 1e10; + if (val >= 100000.0) { // 100,000 to 999,999 + mulfor6 = 1.0; + } else if (val >= 10000.0) { + mulfor6 = 1e1; + } else if (val >= 1000.0) { + mulfor6 = 1e2; + } else if (val >= 100.0) { + mulfor6 = 1e3; + } else if (val >= 10.0) { + mulfor6 = 1e4; + } else if (val >= 1.0) { + mulfor6 = 1e5; + } else if (val >= 0.1) { + mulfor6 = 1e6; + } else if (val >= 0.01) { + mulfor6 = 1e7; + } else if (val >= 0.001) { + mulfor6 = 1e8; + } else if (val >= 0.0001) { + mulfor6 = 1e9; + } + if (static_cast<int32_t>(val * mulfor6 + 0.5) / mulfor6 == val) return 6; + } else if (val < 1e10) { + FloatType divfor6 = 1.0; + if (val >= 1e9) { // 1,000,000,000 to 9,999,999,999 + divfor6 = 10000; + } else if (val >= 1e8) { // 100,000,000 to 999,999,999 + divfor6 = 1000; + } else if (val >= 1e7) { // 10,000,000 to 99,999,999 + divfor6 = 100; + } else if (val >= 1e6) { // 1,000,000 to 9,999,999 + divfor6 = 10; + } + if (static_cast<int32_t>(val / divfor6 + 0.5) * divfor6 == val) return 6; + } + return full; +} + +inline void PrintTo(float f, ::std::ostream* os) { + auto old_precision = os->precision(); + os->precision(AppropriateResolution(f)); + *os << f; + os->precision(old_precision); +} + +inline void PrintTo(double d, ::std::ostream* os) { + auto old_precision = os->precision(); + os->precision(AppropriateResolution(d)); + *os << d; + os->precision(old_precision); +} + // Overloads for C strings. GTEST_API_ void PrintTo(const char* s, ::std::ostream* os); inline void PrintTo(char* s, ::std::ostream* os) { @@ -565,7 +641,7 @@ inline void PrintTo(const ::std::string& s, ::std::ostream* os) { } // Overloads for ::std::u8string -#ifdef __cpp_char8_t +#ifdef __cpp_lib_char8_t GTEST_API_ void PrintU8StringTo(const ::std::u8string& s, ::std::ostream* os); inline void PrintTo(const ::std::u8string& s, ::std::ostream* os) { PrintU8StringTo(s, os); @@ -900,6 +976,13 @@ class UniversalTersePrinter<T&> { UniversalPrint(value, os); } }; +template <typename T> +class UniversalTersePrinter<std::reference_wrapper<T>> { + public: + static void Print(std::reference_wrapper<T> value, ::std::ostream* os) { + UniversalTersePrinter<T>::Print(value.get(), os); + } +}; template <typename T, size_t N> class UniversalTersePrinter<T[N]> { public: diff --git a/contrib/restricted/googletest/googletest/include/gtest/gtest-spi.h b/contrib/restricted/googletest/googletest/include/gtest/gtest-spi.h index bec8c4810bb..c0613b69595 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/gtest-spi.h +++ b/contrib/restricted/googletest/googletest/include/gtest/gtest-spi.h @@ -33,6 +33,8 @@ #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_SPI_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_SPI_H_ +#include <string> + #include "gtest/gtest.h" GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ diff --git a/contrib/restricted/googletest/googletest/include/gtest/gtest-test-part.h b/contrib/restricted/googletest/googletest/include/gtest/gtest-test-part.h index 09cc8c34f04..8290b4d653d 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/gtest-test-part.h +++ b/contrib/restricted/googletest/googletest/include/gtest/gtest-test-part.h @@ -35,6 +35,8 @@ #define GOOGLETEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ #include <iosfwd> +#include <ostream> +#include <string> #include <vector> #include "gtest/internal/gtest-internal.h" diff --git a/contrib/restricted/googletest/googletest/include/gtest/gtest.h b/contrib/restricted/googletest/googletest/include/gtest/gtest.h index d19a587a18c..3e452a503f8 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/gtest.h +++ b/contrib/restricted/googletest/googletest/include/gtest/gtest.h @@ -50,9 +50,14 @@ #define GOOGLETEST_INCLUDE_GTEST_GTEST_H_ #include <cstddef> +#include <cstdint> +#include <iomanip> #include <limits> #include <memory> #include <ostream> +#include <set> +#include <sstream> +#include <string> #include <type_traits> #include <vector> @@ -190,6 +195,17 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string& message); std::set<std::string>* GetIgnoredParameterizedTestSuites(); +// A base class that prevents subclasses from being copyable. +// We do this instead of using '= delete' so as to avoid triggering warnings +// inside user code regarding any of our declarations. +class GTestNonCopyable { + public: + GTestNonCopyable() = default; + GTestNonCopyable(const GTestNonCopyable &) = delete; + GTestNonCopyable &operator=(const GTestNonCopyable &) = delete; + ~GTestNonCopyable() = default; +}; + } // namespace internal // The friend relationship of some of these classes is cyclic. @@ -285,7 +301,7 @@ class GTEST_API_ Test { // SetUp/TearDown method of Environment objects registered with Google // Test) will be output as attributes of the <testsuites> element. static void RecordProperty(const std::string& key, const std::string& value); - static void RecordProperty(const std::string& key, int value); + static void RecordProperty(const std::string& key, int64_t value); protected: // Creates a Test object. @@ -1625,7 +1641,7 @@ class GTEST_API_ AssertHelper { // the GetParam() method. // // Use it with one of the parameter generator defining functions, like Range(), -// Values(), ValuesIn(), Bool(), and Combine(). +// Values(), ValuesIn(), Bool(), Combine(), and ConvertGenerator<T>(). // // class FooTest : public ::testing::TestWithParam<int> { // protected: @@ -1723,9 +1739,9 @@ class TestWithParam : public Test, public WithParamInterface<T> {}; #define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed") // Like GTEST_FAIL(), but at the given source file location. -#define GTEST_FAIL_AT(file, line) \ - GTEST_MESSAGE_AT_(file, line, "Failed", \ - ::testing::TestPartResult::kFatalFailure) +#define GTEST_FAIL_AT(file, line) \ + return GTEST_MESSAGE_AT_(file, line, "Failed", \ + ::testing::TestPartResult::kFatalFailure) // Define this macro to 1 to omit the definition of FAIL(), which is a // generic name and clashes with some other libraries. @@ -2063,9 +2079,7 @@ class GTEST_API_ ScopedTrace { ScopedTrace(const ScopedTrace&) = delete; ScopedTrace& operator=(const ScopedTrace&) = delete; -} GTEST_ATTRIBUTE_UNUSED_; // A ScopedTrace object does its job in its - // c'tor and d'tor. Therefore it doesn't - // need to be used otherwise. +}; // Causes a trace (including the source file path, the current line // number, and the given message) to be included in every test failure @@ -2189,10 +2203,17 @@ constexpr bool StaticAssertTypeEq() noexcept { #define TEST_F(test_fixture, test_name) GTEST_TEST_F(test_fixture, test_name) #endif -// Returns a path to temporary directory. -// Tries to determine an appropriate directory for the platform. +// Returns a path to a temporary directory, which should be writable. It is +// implementation-dependent whether or not the path is terminated by the +// directory-separator character. GTEST_API_ std::string TempDir(); +// Returns a path to a directory that contains ancillary data files that might +// be used by tests. It is implementation dependent whether or not the path is +// terminated by the directory-separator character. The directory and the files +// in it should be considered read-only. +GTEST_API_ std::string SrcDir(); + #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-death-test-internal.h b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-death-test-internal.h index c6e2ce07ed9..08fa2294cf0 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-death-test-internal.h +++ b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-death-test-internal.h @@ -42,6 +42,7 @@ #include <stdio.h> #include <memory> +#include <string> #include "gtest/gtest-matchers.h" #include "gtest/internal/gtest-internal.h" @@ -99,7 +100,7 @@ class GTEST_API_ DeathTest { DeathTest* const test_; ReturnSentinel(const ReturnSentinel&) = delete; ReturnSentinel& operator=(const ReturnSentinel&) = delete; - } GTEST_ATTRIBUTE_UNUSED_; + }; // An enumeration of possible roles that may be taken when a death // test is encountered. EXECUTE means that the death test logic should diff --git a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-filepath.h b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-filepath.h index a2a60a962b8..5189c81dabf 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-filepath.h +++ b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-filepath.h @@ -42,11 +42,16 @@ #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ +#include <string> + +#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-string.h" GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ /* class A needs to have dll-interface to be used by clients of class B */) +#if GTEST_HAS_FILE_SYSTEM + namespace testing { namespace internal { @@ -199,6 +204,16 @@ class GTEST_API_ FilePath { // separators. Returns NULL if no path separator was found. const char* FindLastPathSeparator() const; + // Returns the length of the path root, including the directory separator at + // the end of the prefix. Returns zero by definition if the path is relative. + // Examples: + // - [Windows] "..\Sibling" => 0 + // - [Windows] "\Windows" => 1 + // - [Windows] "C:/Windows\Notepad.exe" => 3 + // - [Windows] "\\Host\Share\C$/Windows" => 13 + // - [UNIX] "/bin" => 1 + size_t CalculateRootLength() const; + std::string pathname_; }; // class FilePath @@ -207,4 +222,6 @@ class GTEST_API_ FilePath { GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 +#endif // GTEST_HAS_FILE_SYSTEM + #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ diff --git a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-internal.h b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-internal.h index 34cb2b4e6f2..ab7d4f16d80 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-internal.h +++ b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-internal.h @@ -57,12 +57,14 @@ #include <string.h> #include <cstdint> +#include <functional> #include <iomanip> #include <limits> #include <map> #include <set> #include <string> #include <type_traits> +#include <utility> #include <vector> #include "gtest/gtest-message.h" @@ -461,7 +463,7 @@ class TestFactoryBase { TestFactoryBase& operator=(const TestFactoryBase&) = delete; }; -// This class provides implementation of TeastFactoryBase interface. +// This class provides implementation of TestFactoryBase interface. // It is used in TEST and TEST_F macros. template <class TestClass> class TestFactoryImpl : public TestFactoryBase { @@ -631,7 +633,7 @@ class GTEST_API_ TypedTestSuitePState { const char* registered_tests); private: - typedef ::std::map<std::string, CodeLocation> RegisteredTestsMap; + typedef ::std::map<std::string, CodeLocation, std::less<>> RegisteredTestsMap; bool registered_; RegisteredTestsMap registered_tests_; @@ -829,8 +831,7 @@ class TypeParameterizedTestSuite<Fixture, internal::None, Types> { // For example, if Foo() calls Bar(), which in turn calls // GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. -GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, - int skip_count); +GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(int skip_count); // Helpers for suppressing warnings on unreachable code or constant // condition. diff --git a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-param-util.h b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-param-util.h index e7af2f904a4..7092d10e677 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-param-util.h +++ b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-param-util.h @@ -40,8 +40,11 @@ #include <cassert> #include <iterator> +#include <map> #include <memory> +#include <ostream> #include <set> +#include <string> #include <tuple> #include <type_traits> #include <utility> @@ -950,6 +953,78 @@ class CartesianProductHolder { std::tuple<Gen...> generators_; }; +template <typename From, typename To> +class ParamGeneratorConverter : public ParamGeneratorInterface<To> { + public: + ParamGeneratorConverter(ParamGenerator<From> gen) // NOLINT + : generator_(std::move(gen)) {} + + ParamIteratorInterface<To>* Begin() const override { + return new Iterator(this, generator_.begin(), generator_.end()); + } + ParamIteratorInterface<To>* End() const override { + return new Iterator(this, generator_.end(), generator_.end()); + } + + private: + class Iterator : public ParamIteratorInterface<To> { + public: + Iterator(const ParamGeneratorInterface<To>* base, ParamIterator<From> it, + ParamIterator<From> end) + : base_(base), it_(it), end_(end) { + if (it_ != end_) value_ = std::make_shared<To>(static_cast<To>(*it_)); + } + ~Iterator() override {} + + const ParamGeneratorInterface<To>* BaseGenerator() const override { + return base_; + } + void Advance() override { + ++it_; + if (it_ != end_) value_ = std::make_shared<To>(static_cast<To>(*it_)); + } + ParamIteratorInterface<To>* Clone() const override { + return new Iterator(*this); + } + const To* Current() const override { return value_.get(); } + bool Equals(const ParamIteratorInterface<To>& other) const override { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const ParamIterator<From> other_it = + CheckedDowncastToActualType<const Iterator>(&other)->it_; + return it_ == other_it; + } + + private: + Iterator(const Iterator& other) = default; + + const ParamGeneratorInterface<To>* const base_; + ParamIterator<From> it_; + ParamIterator<From> end_; + std::shared_ptr<To> value_; + }; // class ParamGeneratorConverter::Iterator + + ParamGenerator<From> generator_; +}; // class ParamGeneratorConverter + +template <class Gen> +class ParamConverterGenerator { + public: + ParamConverterGenerator(ParamGenerator<Gen> g) // NOLINT + : generator_(std::move(g)) {} + + template <typename T> + operator ParamGenerator<T>() const { // NOLINT + return ParamGenerator<T>(new ParamGeneratorConverter<Gen, T>(generator_)); + } + + private: + ParamGenerator<Gen> generator_; +}; + } // namespace internal } // namespace testing diff --git a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-port-arch.h b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-port-arch.h index f025db76ad3..04064606f5d 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-port-arch.h +++ b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-port-arch.h @@ -111,6 +111,8 @@ #define GTEST_OS_ESP32 1 #elif defined(__XTENSA__) #define GTEST_OS_XTENSA 1 +#elif defined(__hexagon__) +#define GTEST_OS_QURT 1 #endif // __CYGWIN__ #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ diff --git a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-port.h b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-port.h index e09d7744ad5..88b73b7ddc0 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-port.h +++ b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-port.h @@ -83,6 +83,8 @@ // GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that // std::wstring does/doesn't work (Google Test can // be used where std::wstring is unavailable). +// GTEST_HAS_FILE_SYSTEM - Define it to 1/0 to indicate whether or not a +// file system is/isn't available. // GTEST_HAS_SEH - Define it to 1/0 to indicate whether the // compiler supports Microsoft's "Structured // Exception Handling". @@ -255,6 +257,19 @@ // deprecated; calling a marked function // should generate a compiler warning +// The definition of GTEST_INTERNAL_CPLUSPLUS_LANG comes first because it can +// potentially be used as an #include guard. +#if defined(_MSVC_LANG) +#define GTEST_INTERNAL_CPLUSPLUS_LANG _MSVC_LANG +#elif defined(__cplusplus) +#define GTEST_INTERNAL_CPLUSPLUS_LANG __cplusplus +#endif + +#if !defined(GTEST_INTERNAL_CPLUSPLUS_LANG) || \ + GTEST_INTERNAL_CPLUSPLUS_LANG < 201402L +#error C++ versions less than C++14 are not supported. +#endif + #include <ctype.h> // for isspace, etc #include <stddef.h> // for ptrdiff_t #include <stdio.h> @@ -268,6 +283,7 @@ #include <limits> #include <locale> #include <memory> +#include <ostream> #include <string> // #include <mutex> // Guarded by GTEST_IS_THREADSAFE below #include <tuple> @@ -385,7 +401,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // On Android, <regex.h> 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) +#define GTEST_HAS_POSIX_RE \ + !(GTEST_OS_WINDOWS || GTEST_OS_XTENSA || GTEST_OS_QURT) #endif #endif @@ -460,10 +477,16 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // 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_HAIKU || GTEST_OS_ESP32 || GTEST_OS_ESP8266 || \ + GTEST_OS_XTENSA || GTEST_OS_QURT)) #endif // GTEST_HAS_STD_WSTRING +#ifndef GTEST_HAS_FILE_SYSTEM +// Most platforms support a file system. +#define GTEST_HAS_FILE_SYSTEM 1 +#endif // GTEST_HAS_FILE_SYSTEM + // Determines whether RTTI is available. #ifndef GTEST_HAS_RTTI // The user didn't tell us whether RTTI is enabled, so we need to @@ -581,9 +604,11 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // output correctness and to implement death tests. #ifndef GTEST_HAS_STREAM_REDIRECTION // By default, we assume that stream redirection is supported on all -// platforms except known mobile ones. -#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ - GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA +// 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 #define GTEST_HAS_STREAM_REDIRECTION 0 #else #define GTEST_HAS_STREAM_REDIRECTION 1 @@ -599,7 +624,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \ GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_HAIKU || \ GTEST_OS_GNU_HURD) +// Death tests require a file system to work properly. +#if GTEST_HAS_FILE_SYSTEM #define GTEST_HAS_DEATH_TEST 1 +#endif // GTEST_HAS_FILE_SYSTEM #endif // Determines whether to support type-driven tests. @@ -642,41 +670,53 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; default: // NOLINT #endif -// Use this annotation at the end of a struct/class definition to -// prevent the compiler from optimizing away instances that are never -// used. This is useful when all interesting logic happens inside the -// c'tor and / or d'tor. Example: +// GTEST_HAVE_ATTRIBUTE_ // -// struct Foo { -// Foo() { ... } -// } GTEST_ATTRIBUTE_UNUSED_; +// A function-like feature checking macro that is a wrapper around +// `__has_attribute`, which is defined by GCC 5+ and Clang and evaluates to a +// nonzero constant integer if the attribute is supported or 0 if not. // -// Also use it after a variable or parameter declaration to tell the -// compiler the variable/parameter does not have to be used. -#if defined(__GNUC__) && !defined(COMPILER_ICC) -#define GTEST_ATTRIBUTE_UNUSED_ __attribute__((unused)) -#elif defined(__clang__) -#if __has_attribute(unused) -#define GTEST_ATTRIBUTE_UNUSED_ __attribute__((unused)) +// It evaluates to zero if `__has_attribute` is not defined by the compiler. +// +// GCC: https://gcc.gnu.org/gcc-5/changes.html +// Clang: https://clang.llvm.org/docs/LanguageExtensions.html +#ifdef __has_attribute +#define GTEST_HAVE_ATTRIBUTE_(x) __has_attribute(x) +#else +#define GTEST_HAVE_ATTRIBUTE_(x) 0 #endif + +// GTEST_HAVE_FEATURE_ +// +// A function-like feature checking macro that is a wrapper around +// `__has_feature`. +#ifdef __has_feature +#define GTEST_HAVE_FEATURE_(x) __has_feature(x) +#else +#define GTEST_HAVE_FEATURE_(x) 0 #endif -#ifndef GTEST_ATTRIBUTE_UNUSED_ + +// Use this annotation after a variable or parameter declaration to tell the +// compiler the variable/parameter does not have to be used. +// Example: +// +// GTEST_ATTRIBUTE_UNUSED_ int foo = bar(); +#if GTEST_HAVE_ATTRIBUTE_(unused) +#define GTEST_ATTRIBUTE_UNUSED_ __attribute__((unused)) +#else #define GTEST_ATTRIBUTE_UNUSED_ #endif // Use this annotation before a function that takes a printf format string. -#if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC) -#if defined(__MINGW_PRINTF_FORMAT) +#if GTEST_HAVE_ATTRIBUTE_(format) && defined(__MINGW_PRINTF_FORMAT) // MinGW has two different printf implementations. Ensure the format macro // matches the selected implementation. See // https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/. #define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ - __attribute__(( \ - __format__(__MINGW_PRINTF_FORMAT, string_index, first_to_check))) -#else -#define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ - __attribute__((__format__(__printf__, string_index, first_to_check))) -#endif + __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, first_to_check))) +#elif GTEST_HAVE_ATTRIBUTE_(format) +#define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ + __attribute__((format(printf, string_index, first_to_check))) #else #define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) #endif @@ -686,11 +726,11 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // following the argument list: // // Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_; -#if defined(__GNUC__) && !defined(COMPILER_ICC) +#if GTEST_HAVE_ATTRIBUTE_(warn_unused_result) #define GTEST_MUST_USE_RESULT_ __attribute__((warn_unused_result)) #else #define GTEST_MUST_USE_RESULT_ -#endif // __GNUC__ && !COMPILER_ICC +#endif // MS C++ compiler emits warning when a conditional expression is compile time // constant. In some contexts this warning is false positive and needs to be @@ -746,7 +786,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #elif GTEST_CREATE_SHARED_LIBRARY #define GTEST_API_ __declspec(dllexport) #endif -#elif __GNUC__ >= 4 || defined(__clang__) +#elif GTEST_HAVE_ATTRIBUTE_(visibility) #define GTEST_API_ __attribute__((visibility("default"))) #endif // _MSC_VER @@ -760,20 +800,17 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #define GTEST_DEFAULT_DEATH_TEST_STYLE "fast" #endif // GTEST_DEFAULT_DEATH_TEST_STYLE -#ifdef __GNUC__ +#if GTEST_HAVE_ATTRIBUTE_(noinline) // Ask the compiler to never inline a given function. #define GTEST_NO_INLINE_ __attribute__((noinline)) #else #define GTEST_NO_INLINE_ #endif -#if defined(__clang__) -// Nested ifs to avoid triggering MSVC warning. -#if __has_attribute(disable_tail_calls) +#if GTEST_HAVE_ATTRIBUTE_(disable_tail_calls) // Ask the compiler not to perform tail call optimization inside // the marked function. #define GTEST_NO_TAIL_CALL_ __attribute__((disable_tail_calls)) -#endif #elif __GNUC__ #define GTEST_NO_TAIL_CALL_ \ __attribute__((optimize("no-optimize-sibling-calls"))) @@ -792,50 +829,35 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // A function level attribute to disable checking for use of uninitialized // memory when built with MemorySanitizer. -#if defined(__clang__) -#if __has_feature(memory_sanitizer) +#if GTEST_HAVE_ATTRIBUTE_(no_sanitize_memory) #define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ __attribute__((no_sanitize_memory)) #else #define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ -#endif // __has_feature(memory_sanitizer) -#else -#define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ -#endif // __clang__ +#endif // A function level attribute to disable AddressSanitizer instrumentation. -#if defined(__clang__) -#if __has_feature(address_sanitizer) +#if GTEST_HAVE_ATTRIBUTE_(no_sanitize_address) #define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \ __attribute__((no_sanitize_address)) #else #define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ -#endif // __has_feature(address_sanitizer) -#else -#define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ -#endif // __clang__ +#endif // A function level attribute to disable HWAddressSanitizer instrumentation. -#if defined(__clang__) -#if __has_feature(hwaddress_sanitizer) +#if GTEST_HAVE_FEATURE_(hwaddress_sanitizer) && \ + GTEST_HAVE_ATTRIBUTE_(no_sanitize) #define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ \ __attribute__((no_sanitize("hwaddress"))) #else #define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ -#endif // __has_feature(hwaddress_sanitizer) -#else -#define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ -#endif // __clang__ +#endif // A function level attribute to disable ThreadSanitizer instrumentation. -#if defined(__clang__) -#if __has_feature(thread_sanitizer) -#define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ __attribute__((no_sanitize_thread)) -#else -#define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ -#endif // __has_feature(thread_sanitizer) +#if GTEST_HAVE_ATTRIBUTE_(no_sanitize_thread) +#define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ __attribute((no_sanitize_thread)) #else #define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ -#endif // __clang__ +#endif namespace testing { @@ -1713,7 +1735,7 @@ typedef GTestMutexLock MutexLock; // C-linkage. Therefore it cannot be templatized to access // ThreadLocal<T>. Hence the need for class // ThreadLocalValueHolderBase. -class ThreadLocalValueHolderBase { +class GTEST_API_ ThreadLocalValueHolderBase { public: virtual ~ThreadLocalValueHolderBase() {} }; @@ -1959,12 +1981,55 @@ inline std::string StripTrailingSpaces(std::string str) { namespace posix { -// Functions with a different name on Windows. - +// File system porting. +#if GTEST_HAS_FILE_SYSTEM #if GTEST_OS_WINDOWS typedef struct _stat StatStruct; +#if GTEST_OS_WINDOWS_MOBILE +inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); } +// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this +// time and thus not defined there. +#else +inline int FileNo(FILE* file) { return _fileno(file); } +inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); } +inline int RmDir(const char* dir) { return _rmdir(dir); } +inline bool IsDir(const StatStruct& st) { return (_S_IFDIR & st.st_mode) != 0; } +#endif // GTEST_OS_WINDOWS_MOBILE + +#elif GTEST_OS_ESP8266 +typedef struct stat StatStruct; + +inline int FileNo(FILE* file) { return fileno(file); } +inline int Stat(const char* path, StatStruct* buf) { + // stat function not implemented on ESP8266 + return 0; +} +inline int RmDir(const char* dir) { return rmdir(dir); } +inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } + +#else + +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 +// QuRT doesn't support any directory functions, including rmdir +inline int RmDir(const char*) { return 0; } +#else +inline int RmDir(const char* dir) { return rmdir(dir); } +#endif +inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } + +#endif // GTEST_OS_WINDOWS +#endif // GTEST_HAS_FILE_SYSTEM + +// Other functions with a different name on Windows. + +#if GTEST_OS_WINDOWS + #ifdef __BORLANDC__ inline int DoIsATTY(int fd) { return isatty(fd); } inline int StrCaseCmp(const char* s1, const char* s2) { @@ -1984,46 +2049,21 @@ inline int StrCaseCmp(const char* s1, const char* s2) { inline char* StrDup(const char* src) { return _strdup(src); } #endif // __BORLANDC__ -#if GTEST_OS_WINDOWS_MOBILE -inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); } -// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this -// time and thus not defined there. -#else -inline int FileNo(FILE* file) { return _fileno(file); } -inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); } -inline int RmDir(const char* dir) { return _rmdir(dir); } -inline bool IsDir(const StatStruct& st) { return (_S_IFDIR & st.st_mode) != 0; } -#endif // GTEST_OS_WINDOWS_MOBILE - #elif GTEST_OS_ESP8266 -typedef struct stat StatStruct; -inline int FileNo(FILE* file) { return fileno(file); } inline int DoIsATTY(int fd) { return isatty(fd); } -inline int Stat(const char* path, StatStruct* buf) { - // stat function not implemented on ESP8266 - return 0; -} inline int StrCaseCmp(const char* s1, const char* s2) { return strcasecmp(s1, s2); } inline char* StrDup(const char* src) { return strdup(src); } -inline int RmDir(const char* dir) { return rmdir(dir); } -inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } #else -typedef struct stat StatStruct; - -inline int FileNo(FILE* file) { return fileno(file); } inline int DoIsATTY(int fd) { return isatty(fd); } -inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); } inline int StrCaseCmp(const char* s1, const char* s2) { return strcasecmp(s1, s2); } inline char* StrDup(const char* src) { return strdup(src); } -inline int RmDir(const char* dir) { return rmdir(dir); } -inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } #endif // GTEST_OS_WINDOWS @@ -2045,9 +2085,10 @@ GTEST_DISABLE_MSC_DEPRECATED_PUSH_() // ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and // StrError() aren't needed on Windows CE at this time and thus not // defined there. - -#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \ - !GTEST_OS_WINDOWS_RT && !GTEST_OS_ESP8266 && !GTEST_OS_XTENSA +#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 inline int ChDir(const char* dir) { return chdir(dir); } #endif inline FILE* FOpen(const char* path, const char* mode) { @@ -2061,14 +2102,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 +#if !GTEST_OS_WINDOWS_MOBILE && !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 +#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT inline int FClose(FILE* fp) { return fclose(fp); } -#if !GTEST_OS_WINDOWS_MOBILE +#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT inline int Read(int fd, void* buf, unsigned int count) { return static_cast<int>(read(fd, buf, count)); } @@ -2076,11 +2117,17 @@ inline int Write(int fd, const void* buf, unsigned int count) { return static_cast<int>(write(fd, buf, count)); } 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 inline const char* StrError(int errnum) { return strerror(errnum); } -#endif +#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 +#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ + GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA || \ + GTEST_OS_QURT // We are on an embedded platform, which has no environment variables. static_cast<void>(name); // To prevent 'unused argument' warning. return nullptr; @@ -2112,7 +2159,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 _MSC_VER && !GTEST_OS_WINDOWS_MOBILE +#if defined(_MSC_VER) && !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/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-string.h b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-string.h index fcf9c04beba..6460480b545 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-string.h +++ b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-string.h @@ -51,6 +51,7 @@ #include <string.h> #include <cstdint> +#include <sstream> #include <string> #include "gtest/internal/gtest-port.h" diff --git a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-type-util.h b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-type-util.h index bf992175af7..ccf3ca54771 100644 --- a/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-type-util.h +++ b/contrib/restricted/googletest/googletest/include/gtest/internal/gtest-type-util.h @@ -37,6 +37,10 @@ #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ +#include <string> +#include <type_traits> +#include <typeinfo> + #include "gtest/internal/gtest-port.h" // #ifdef __GNUC__ is too general here. It is possible to use gcc without using diff --git a/contrib/restricted/googletest/googletest/src/gtest-death-test.cc b/contrib/restricted/googletest/googletest/src/gtest-death-test.cc index 8d2767d4f0c..7bd5781a7cb 100644 --- a/contrib/restricted/googletest/googletest/src/gtest-death-test.cc +++ b/contrib/restricted/googletest/googletest/src/gtest-death-test.cc @@ -249,7 +249,7 @@ static std::string DeathTestThreadWarning(size_t thread_count) { msg << "detected " << thread_count << " threads."; } msg << " See " - "https://github.com/google/googletest/blob/master/docs/" + "https://github.com/google/googletest/blob/main/docs/" "advanced.md#death-tests-and-threads" << " for more explanation and suggested solutions, especially if" << " this is the last message you see before your test times out."; @@ -284,7 +284,7 @@ enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW }; // message is propagated back to the parent process. Otherwise, the // message is simply printed to stderr. In either case, the program // then exits with status 1. -static void DeathTestAbort(const std::string& message) { +[[noreturn]] static void DeathTestAbort(const std::string& message) { // On a POSIX system, this function may be called from a threadsafe-style // death test child process, which operates on a very small stack. Use // the heap for any additional non-minuscule memory requirements. diff --git a/contrib/restricted/googletest/googletest/src/gtest-filepath.cc b/contrib/restricted/googletest/googletest/src/gtest-filepath.cc index f6ee90cdb7c..9d79ea49d8a 100644 --- a/contrib/restricted/googletest/googletest/src/gtest-filepath.cc +++ b/contrib/restricted/googletest/googletest/src/gtest-filepath.cc @@ -57,6 +57,8 @@ #define GTEST_PATH_MAX_ _POSIX_PATH_MAX #endif // GTEST_OS_WINDOWS +#if GTEST_HAS_FILE_SYSTEM + namespace testing { namespace internal { @@ -96,7 +98,7 @@ static bool IsPathSeparator(char c) { 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_XTENSA || GTEST_OS_QURT // These platforms do not have a current directory, so we just return // something reasonable. return FilePath(kCurrentDirectoryString); @@ -145,6 +147,45 @@ const char* FilePath::FindLastPathSeparator() const { return last_sep; } +size_t FilePath::CalculateRootLength() const { + const auto &path = pathname_; + auto s = path.begin(); + auto end = path.end(); +#if 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:" + s += 2; + if (s != end) { + ++s; + } + } else if (end - s >= 3 && IsPathSeparator(*s) && IsPathSeparator(*(s + 1)) + && !IsPathSeparator(*(s + 2))) { + // Move past the "\\" prefix in a UNC path like "\\Server\Share\Folder" + s += 2; + // Skip 2 components and their following separators ("Server\" and "Share\") + for (int i = 0; i < 2; ++i) { + while (s != end) { + bool stop = IsPathSeparator(*s); + ++s; + if (stop) { + break; + } + } + } + } else if (s != end && IsPathSeparator(*s)) { + // A drive-rooted path like "\Windows" + ++s; + } +#else + if (s != end && IsPathSeparator(*s)) { + ++s; + } +#endif + return static_cast<size_t>(s - path.begin()); +} + // Returns a copy of the FilePath with the directory part removed. // Example: FilePath("path/to/file").RemoveDirectoryName() returns // FilePath("file"). If there is no directory part ("just_a_file"), it returns @@ -246,26 +287,16 @@ bool FilePath::DirectoryExists() const { } // Returns true if pathname describes a root directory. (Windows has one -// root directory per disk drive.) +// root directory per disk drive. UNC share roots are also included.) bool FilePath::IsRootDirectory() const { -#if GTEST_OS_WINDOWS - return pathname_.length() == 3 && IsAbsolutePath(); -#else - return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]); -#endif + size_t root_length = CalculateRootLength(); + return root_length > 0 && root_length == pathname_.size() && + IsPathSeparator(pathname_[root_length - 1]); } // Returns true if pathname describes an absolute path. bool FilePath::IsAbsolutePath() const { - const char* const name = pathname_.c_str(); -#if GTEST_OS_WINDOWS - return pathname_.length() >= 3 && - ((name[0] >= 'a' && name[0] <= 'z') || - (name[0] >= 'A' && name[0] <= 'Z')) && - name[1] == ':' && IsPathSeparator(name[2]); -#else - return IsPathSeparator(name[0]); -#endif + return CalculateRootLength() > 0; } // Returns a pathname for a file that does not currently exist. The pathname @@ -323,7 +354,7 @@ bool FilePath::CreateFolder() const { delete[] unicode; #elif GTEST_OS_WINDOWS int result = _mkdir(pathname_.c_str()); -#elif GTEST_OS_ESP8266 || GTEST_OS_XTENSA +#elif GTEST_OS_ESP8266 || GTEST_OS_XTENSA || GTEST_OS_QURT // do nothing int result = 0; #else @@ -347,17 +378,27 @@ FilePath FilePath::RemoveTrailingPathSeparator() const { // Removes any redundant separators that might be in the pathname. // For example, "bar///foo" becomes "bar/foo". Does not eliminate other // redundancies that might be in a pathname involving "." or "..". +// Note that "\\Host\Share" does not contain a redundancy on Windows! void FilePath::Normalize() { auto out = pathname_.begin(); - for (const char character : pathname_) { + auto i = pathname_.cbegin(); +#if GTEST_OS_WINDOWS + // UNC paths are treated specially + if (pathname_.end() - i >= 3 && IsPathSeparator(*i) && + IsPathSeparator(*(i + 1)) && !IsPathSeparator(*(i + 2))) { + *(out++) = kPathSeparator; + *(out++) = kPathSeparator; + } +#endif + while (i != pathname_.end()) { + const char character = *i; if (!IsPathSeparator(character)) { *(out++) = character; } else if (out == pathname_.begin() || *std::prev(out) != kPathSeparator) { *(out++) = kPathSeparator; - } else { - continue; } + ++i; } pathname_.erase(out, pathname_.end()); @@ -365,3 +406,5 @@ void FilePath::Normalize() { } // namespace internal } // namespace testing + +#endif // GTEST_HAS_FILE_SYSTEM diff --git a/contrib/restricted/googletest/googletest/src/gtest-internal-inl.h b/contrib/restricted/googletest/googletest/src/gtest-internal-inl.h index 0b9e929c689..2c9db4f2078 100644 --- a/contrib/restricted/googletest/googletest/src/gtest-internal-inl.h +++ b/contrib/restricted/googletest/googletest/src/gtest-internal-inl.h @@ -44,6 +44,7 @@ #include <algorithm> #include <cstdint> #include <memory> +#include <set> #include <string> #include <vector> @@ -212,7 +213,7 @@ class GTestFlagSaver { int32_t stack_trace_depth_; std::string stream_result_to_; bool throw_on_failure_; -} GTEST_ATTRIBUTE_UNUSED_; +}; // Converts a Unicode code point to a narrow string in UTF-8 encoding. // code_point parameter is of type UInt32 because wchar_t may not be @@ -396,9 +397,11 @@ class GTEST_API_ UnitTestOptions { static bool MatchesFilter(const std::string& name, const char* filter); }; +#if GTEST_HAS_FILE_SYSTEM // Returns the current application's name, removing directory path if that // is present. Used by UnitTestOptions::GetOutputFile. GTEST_API_ FilePath GetCurrentExecutableName(); +#endif // GTEST_HAS_FILE_SYSTEM // The role interface for getting the OS stack trace as a string. class OsStackTraceGetterInterface { @@ -507,9 +510,9 @@ class GTEST_API_ UnitTestImpl { virtual ~UnitTestImpl(); // There are two different ways to register your own TestPartResultReporter. - // You can register your own repoter to listen either only for test results + // You can register your own reporter to listen either only for test results // from the current thread or for results from all threads. - // By default, each per-thread test result repoter just passes a new + // By default, each per-thread test result reporter just passes a new // TestPartResult to the global test result reporter, which registers the // test part result for the currently running test. @@ -840,9 +843,11 @@ class GTEST_API_ UnitTestImpl { // The UnitTest object that owns this implementation object. UnitTest* const parent_; +#if GTEST_HAS_FILE_SYSTEM // The working directory when the first TEST() or TEST_F() was // executed. internal::FilePath original_working_dir_; +#endif // GTEST_HAS_FILE_SYSTEM // The default test part result reporters. DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_; @@ -850,7 +855,7 @@ class GTEST_API_ UnitTestImpl { default_per_thread_test_part_result_reporter_; // Points to (but doesn't own) the global test part result reporter. - TestPartResultReporterInterface* global_test_part_result_repoter_; + TestPartResultReporterInterface* global_test_part_result_reporter_; // Protects read and write access to global_test_part_result_reporter_. internal::Mutex global_test_part_result_reporter_mutex_; diff --git a/contrib/restricted/googletest/googletest/src/gtest-printers.cc b/contrib/restricted/googletest/googletest/src/gtest-printers.cc index f3976d230da..d475ad36f5e 100644 --- a/contrib/restricted/googletest/googletest/src/gtest-printers.cc +++ b/contrib/restricted/googletest/googletest/src/gtest-printers.cc @@ -315,7 +315,7 @@ void PrintTo(__uint128_t v, ::std::ostream* os) { low = low / 10 + high_mod * 1844674407370955161 + carry / 10; char digit = static_cast<char>(carry % 10); - *--p = '0' + digit; + *--p = static_cast<char>('0' + digit); } *os << p; } diff --git a/contrib/restricted/googletest/googletest/src/gtest.cc b/contrib/restricted/googletest/googletest/src/gtest.cc index 7fd062fc0f1..98d7c03bfce 100644 --- a/contrib/restricted/googletest/googletest/src/gtest.cc +++ b/contrib/restricted/googletest/googletest/src/gtest.cc @@ -58,6 +58,7 @@ #include "gtest/gtest-assertion-result.h" #include "gtest/gtest-spi.h" #include "gtest/internal/custom/gtest.h" +#include "gtest/internal/gtest-port.h" #if GTEST_OS_LINUX @@ -143,6 +144,14 @@ #error #include "absl/strings/str_replace.h" #endif // GTEST_HAS_ABSL +// Checks builtin compiler feature |x| while avoiding an extra layer of #ifdefs +// at the callsite. +#if defined(__has_builtin) +#define GTEST_HAS_BUILTIN(x) __has_builtin(x) +#else +#define GTEST_HAS_BUILTIN(x) 0 +#endif // defined(__has_builtin) + namespace testing { using internal::CountIf; @@ -186,6 +195,7 @@ const char kStackTraceMarker[] = "\nStack trace:\n"; // is specified on the command line. bool g_help_flag = false; +#if GTEST_HAS_FILE_SYSTEM // Utility function to Open File for Writing static FILE* OpenFileForWriting(const std::string& output_file) { FILE* fileout = nullptr; @@ -200,6 +210,7 @@ static FILE* OpenFileForWriting(const std::string& output_file) { } return fileout; } +#endif // GTEST_HAS_FILE_SYSTEM } // namespace internal @@ -372,6 +383,8 @@ GTEST_DEFINE_string_( namespace testing { namespace internal { +const uint32_t Random::kMaxRange; + // Generates a random number from [0, range), using a Linear // Congruential Generator (LCG). Crashes if 'range' is 0 or greater // than kMaxRange. @@ -610,6 +623,7 @@ static ::std::vector<std::string> g_argvs; #endif // defined(GTEST_CUSTOM_GET_ARGVS_) } +#if GTEST_HAS_FILE_SYSTEM // Returns the current application's name, removing directory path if that // is present. FilePath GetCurrentExecutableName() { @@ -623,6 +637,7 @@ FilePath GetCurrentExecutableName() { return result.RemoveDirectoryName(); } +#endif // GTEST_HAS_FILE_SYSTEM // Functions for processing the gtest_output flag. @@ -637,6 +652,7 @@ std::string UnitTestOptions::GetOutputFormat() { static_cast<size_t>(colon - gtest_output_flag)); } +#if GTEST_HAS_FILE_SYSTEM // Returns the name of the requested output file, or the default if none // was explicitly specified. std::string UnitTestOptions::GetAbsolutePathToOutputFile() { @@ -667,6 +683,7 @@ std::string UnitTestOptions::GetAbsolutePathToOutputFile() { GetOutputFormat().c_str())); return result.string(); } +#endif // GTEST_HAS_FILE_SYSTEM // Returns true if and only if the wildcard pattern matches the string. Each // pattern consists of regular characters, single-character wildcards (?), and @@ -1008,14 +1025,14 @@ void DefaultPerThreadTestPartResultReporter::ReportTestPartResult( TestPartResultReporterInterface* UnitTestImpl::GetGlobalTestPartResultReporter() { internal::MutexLock lock(&global_test_part_result_reporter_mutex_); - return global_test_part_result_repoter_; + return global_test_part_result_reporter_; } // Sets the global test part result reporter. void UnitTestImpl::SetGlobalTestPartResultReporter( TestPartResultReporterInterface* reporter) { internal::MutexLock lock(&global_test_part_result_reporter_mutex_); - global_test_part_result_repoter_ = reporter; + global_test_part_result_reporter_ = reporter; } // Returns the test part result reporter for the current thread. @@ -1113,17 +1130,24 @@ std::string UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) { // A helper class for measuring elapsed times. class Timer { public: - Timer() : start_(std::chrono::steady_clock::now()) {} + Timer() : start_(clock::now()) {} // Return time elapsed in milliseconds since the timer was created. TimeInMillis Elapsed() { return std::chrono::duration_cast<std::chrono::milliseconds>( - std::chrono::steady_clock::now() - start_) + clock::now() - start_) .count(); } private: - std::chrono::steady_clock::time_point start_; + // Fall back to the system_clock when building with newlib on a system + // without a monotonic clock. +#if defined(_NEWLIB_VERSION) && !defined(CLOCK_MONOTONIC) + using clock = std::chrono::system_clock; +#else + using clock = std::chrono::steady_clock; +#endif + clock::time_point start_; }; // Returns a timestamp as milliseconds since the epoch. Note this time may jump @@ -2434,12 +2458,10 @@ void Test::TearDown() {} void Test::RecordProperty(const std::string& key, const std::string& value) { UnitTest::GetInstance()->RecordProperty(key, value); } - -// Allows user supplied key value pairs to be recorded for later output. -void Test::RecordProperty(const std::string& key, int value) { - Message value_message; - value_message << value; - RecordProperty(key, value_message.GetString().c_str()); +// We do not define a customary serialization except for integers, +// but other values could be logged in this way. +void Test::RecordProperty(const std::string& key, int64_t value) { + RecordProperty(key, (Message() << value).GetString()); } namespace internal { @@ -2711,7 +2733,8 @@ TestInfo::TestInfo(const std::string& a_test_suite_name, internal::TypeId fixture_class_id, internal::TestFactoryBase* factory) : test_suite_name_(a_test_suite_name), - name_(a_name), + // begin()/end() is MSVC 17.3.3 ASAN crash workaround (GitHub issue #3997) + name_(a_name.begin(), a_name.end()), type_param_(a_type_param ? new std::string(a_type_param) : nullptr), value_param_(a_value_param ? new std::string(a_value_param) : nullptr), location_(a_code_location), @@ -2775,37 +2798,6 @@ void ReportInvalidTestSuiteType(const char* test_suite_name, code_location.line) << " " << errors.GetString(); } -} // namespace internal - -namespace { - -// A predicate that checks the test name of a TestInfo against a known -// value. -// -// This is used for implementation of the TestSuite class only. We put -// it in the anonymous namespace to prevent polluting the outer -// namespace. -// -// TestNameIs is copyable. -class TestNameIs { - public: - // Constructor. - // - // TestNameIs has NO default constructor. - explicit TestNameIs(const char* name) : name_(name) {} - - // Returns true if and only if the test name of test_info matches name_. - bool operator()(const TestInfo* test_info) const { - return test_info && test_info->name() == name_; - } - - private: - std::string name_; -}; - -} // namespace - -namespace internal { // This method expands all parameterized tests registered with macros TEST_P // and INSTANTIATE_TEST_SUITE_P into regular tests and registers those. @@ -3244,17 +3236,15 @@ bool ShouldUseColor(bool stdout_is_tty) { // On non-Windows platforms, we rely on the TERM variable. const char* const term = posix::GetEnv("TERM"); const bool term_supports_color = - String::CStringEquals(term, "xterm") || - String::CStringEquals(term, "xterm-color") || - String::CStringEquals(term, "xterm-256color") || - String::CStringEquals(term, "screen") || - String::CStringEquals(term, "screen-256color") || - String::CStringEquals(term, "tmux") || - String::CStringEquals(term, "tmux-256color") || - String::CStringEquals(term, "rxvt-unicode") || - String::CStringEquals(term, "rxvt-unicode-256color") || - String::CStringEquals(term, "linux") || - String::CStringEquals(term, "cygwin"); + term != nullptr && (String::CStringEquals(term, "xterm") || + String::CStringEquals(term, "xterm-color") || + String::CStringEquals(term, "xterm-kitty") || + String::CStringEquals(term, "screen") || + String::CStringEquals(term, "tmux") || + String::CStringEquals(term, "rxvt-unicode") || + String::CStringEquals(term, "linux") || + String::CStringEquals(term, "cygwin") || + String::EndsWithCaseInsensitive(term, "-256color")); return stdout_is_tty && term_supports_color; #endif // GTEST_OS_WINDOWS } @@ -3279,7 +3269,12 @@ static void ColoredPrintf(GTestColor color, const char* fmt, ...) { va_start(args, fmt); static const bool in_color_mode = +#if GTEST_HAS_FILE_SYSTEM ShouldUseColor(posix::IsATTY(posix::FileNo(stdout)) != 0); +#else + false; +#endif // GTEST_HAS_FILE_SYSTEM + const bool use_color = in_color_mode && (color != GTestColor::kDefault); if (!use_color) { @@ -3884,6 +3879,7 @@ void TestEventRepeater::OnTestIterationEnd(const UnitTest& unit_test, // End TestEventRepeater +#if GTEST_HAS_FILE_SYSTEM // This class generates an XML output file. class XmlUnitTestResultPrinter : public EmptyTestEventListener { public: @@ -4431,7 +4427,9 @@ void XmlUnitTestResultPrinter::OutputXmlTestProperties( } // End XmlUnitTestResultPrinter +#endif // GTEST_HAS_FILE_SYSTEM +#if GTEST_HAS_FILE_SYSTEM // This class generates an JSON output file. class JsonUnitTestResultPrinter : public EmptyTestEventListener { public: @@ -4821,6 +4819,9 @@ void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream, // If there was a test failure outside of one of the test suites (like in a // test environment) include that in the output. if (unit_test.ad_hoc_test_result().Failed()) { + if (comma) { + *stream << ",\n"; + } OutputJsonTestSuiteForTestResult(stream, unit_test.ad_hoc_test_result()); } @@ -4869,6 +4870,7 @@ std::string JsonUnitTestResultPrinter::TestPropertiesAsJson( } // End JsonUnitTestResultPrinter +#endif // GTEST_HAS_FILE_SYSTEM #if GTEST_CAN_STREAM_RESULTS_ @@ -4886,7 +4888,8 @@ std::string StreamingListener::UrlEncode(const char* str) { case '=': case '&': case '\n': - result.append("%" + String::FormatByte(static_cast<unsigned char>(ch))); + result.push_back('%'); + result.append(String::FormatByte(static_cast<unsigned char>(ch))); break; default: result.push_back(ch); @@ -5007,6 +5010,7 @@ void OsStackTraceGetter::UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_) { #endif // GTEST_HAS_ABSL } +#if 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 { @@ -5026,7 +5030,7 @@ class ScopedPrematureExitFile { } ~ScopedPrematureExitFile() { -#if !defined GTEST_OS_ESP8266 +#if !GTEST_OS_ESP8266 if (!premature_exit_filepath_.empty()) { int retval = remove(premature_exit_filepath_.c_str()); if (retval) { @@ -5044,6 +5048,7 @@ class ScopedPrematureExitFile { ScopedPrematureExitFile(const ScopedPrematureExitFile&) = delete; ScopedPrematureExitFile& operator=(const ScopedPrematureExitFile&) = delete; }; +#endif // GTEST_HAS_DEATH_TEST } // namespace internal @@ -5331,6 +5336,10 @@ void UnitTest::AddTestPartResult(TestPartResult::Type result_type, (defined(__x86_64__) || defined(__i386__))) // with clang/gcc we can achieve the same effect on x86 by invoking int3 asm("int3"); +#elif GTEST_HAS_BUILTIN(__builtin_trap) + __builtin_trap(); +#elif defined(SIGTRAP) + raise(SIGTRAP); #else // Dereference nullptr through a volatile pointer to prevent the compiler // from removing. We use this rather than abort() or __builtin_trap() for @@ -5365,6 +5374,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 const bool in_death_test_child_process = GTEST_FLAG_GET(internal_run_death_test).length() > 0; @@ -5393,6 +5403,7 @@ int UnitTest::Run() { in_death_test_child_process ? nullptr : internal::posix::GetEnv("TEST_PREMATURE_EXIT_FILE")); +#endif // GTEST_HAS_DEATH_TEST // Captures the value of GTEST_FLAG(catch_exceptions). This value will be // used for the duration of the program. @@ -5448,11 +5459,13 @@ int UnitTest::Run() { : 1; } +#if GTEST_HAS_FILE_SYSTEM // Returns the working directory when the first TEST() or TEST_F() was // executed. const char* UnitTest::original_working_dir() const { return impl_->original_working_dir_.c_str(); } +#endif // GTEST_HAS_FILE_SYSTEM // Returns the TestSuite object for the test that's currently running, // or NULL if no test is running. @@ -5516,7 +5529,7 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent) GTEST_DISABLE_MSC_WARNINGS_PUSH_(4355 /* using this in initializer */) default_global_test_part_result_reporter_(this), default_per_thread_test_part_result_reporter_(this), - GTEST_DISABLE_MSC_WARNINGS_POP_() global_test_part_result_repoter_( + GTEST_DISABLE_MSC_WARNINGS_POP_() global_test_part_result_reporter_( &default_global_test_part_result_reporter_), per_thread_test_part_result_reporter_( &default_per_thread_test_part_result_reporter_), @@ -5585,6 +5598,7 @@ void UnitTestImpl::SuppressTestEventsIfInSubprocess() { // UnitTestOptions. Must not be called before InitGoogleTest. void UnitTestImpl::ConfigureXmlOutput() { const std::string& output_format = UnitTestOptions::GetOutputFormat(); +#if GTEST_HAS_FILE_SYSTEM if (output_format == "xml") { listeners()->SetDefaultXmlGenerator(new XmlUnitTestResultPrinter( UnitTestOptions::GetAbsolutePathToOutputFile().c_str())); @@ -5595,6 +5609,10 @@ void UnitTestImpl::ConfigureXmlOutput() { GTEST_LOG_(WARNING) << "WARNING: unrecognized output format \"" << output_format << "\" ignored."; } +#else + GTEST_LOG_(ERROR) << "ERROR: alternative output formats require " + << "GTEST_HAS_FILE_SYSTEM to be enabled"; +#endif // GTEST_HAS_FILE_SYSTEM } #if GTEST_CAN_STREAM_RESULTS_ @@ -5757,10 +5775,12 @@ bool UnitTestImpl::RunAllTests() { // user didn't call InitGoogleTest. PostFlagParsingInit(); +#if GTEST_HAS_FILE_SYSTEM // Even if sharding is not on, test runners may want to use the // GTEST_SHARD_STATUS_FILE to query whether the test supports the sharding // protocol. internal::WriteToShardStatusFileIfNeeded(); +#endif // GTEST_HAS_FILE_SYSTEM // True if and only if we are in a subprocess for running a thread-safe-style // death test. @@ -5940,6 +5960,7 @@ bool UnitTestImpl::RunAllTests() { return !failed; } +#if GTEST_HAS_FILE_SYSTEM // Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file // if the variable is present. If a file already exists at this location, this // function will write over it. If the variable is present, but the file cannot @@ -5959,6 +5980,7 @@ void WriteToShardStatusFileIfNeeded() { fclose(file); } } +#endif // GTEST_HAS_FILE_SYSTEM // Checks whether sharding is enabled by examining the relevant // environment variable values. If the variables are present, @@ -6037,7 +6059,7 @@ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) { // each TestSuite and TestInfo object. // If shard_tests == true, further filters tests based on sharding // variables in the environment - see -// https://github.com/google/googletest/blob/master/googletest/docs/advanced.md +// https://github.com/google/googletest/blob/main/docs/advanced.md // . Returns the number of tests that should run. int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) { const int32_t total_shards = shard_tests == HONOR_SHARDING_PROTOCOL @@ -6150,6 +6172,7 @@ void UnitTestImpl::ListTestsMatchingFilter() { } } fflush(stdout); + #if GTEST_HAS_FILE_SYSTEM const std::string& output_format = UnitTestOptions::GetOutputFormat(); if (output_format == "xml" || output_format == "json") { FILE* fileout = OpenFileForWriting( @@ -6167,6 +6190,7 @@ void UnitTestImpl::ListTestsMatchingFilter() { fprintf(fileout, "%s", StringStreamToString(&stream).c_str()); fclose(fileout); } +#endif // GTEST_HAS_FILE_SYSTEM } // Sets the OS stack trace getter. @@ -6245,7 +6269,7 @@ void UnitTestImpl::UnshuffleTests() { // GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. GTEST_NO_INLINE_ GTEST_NO_TAIL_CALL_ std::string -GetCurrentOsStackTraceExceptTop(UnitTest* /*unit_test*/, int skip_count) { +GetCurrentOsStackTraceExceptTop(int skip_count) { // We pass skip_count + 1 to skip this wrapper function in addition // to what the user really wants to skip. return GetUnitTestImpl()->CurrentOsStackTraceExceptTop(skip_count + 1); @@ -6555,7 +6579,7 @@ static bool ParseGoogleTestFlag(const char* const arg) { return false; } -#if GTEST_USE_OWN_FLAGFILE_FLAG_ +#if GTEST_USE_OWN_FLAGFILE_FLAG_ && GTEST_HAS_FILE_SYSTEM static void LoadFlagsFromFile(const std::string& path) { FILE* flagfile = posix::FOpen(path.c_str(), "r"); if (!flagfile) { @@ -6571,7 +6595,7 @@ static void LoadFlagsFromFile(const std::string& path) { if (!ParseGoogleTestFlag(lines[i].c_str())) g_help_flag = true; } } -#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ +#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ && GTEST_HAS_FILE_SYSTEM // Parses the command line for Google Test flags, without initializing // other parts of Google Test. The type parameter CharType can be @@ -6588,12 +6612,12 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) { bool remove_flag = false; if (ParseGoogleTestFlag(arg)) { remove_flag = true; -#if GTEST_USE_OWN_FLAGFILE_FLAG_ +#if GTEST_USE_OWN_FLAGFILE_FLAG_ && GTEST_HAS_FILE_SYSTEM } else if (ParseFlag(arg, "flagfile", &flagfile_value)) { GTEST_FLAG_SET(flagfile, flagfile_value); LoadFlagsFromFile(flagfile_value); remove_flag = true; -#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ +#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ && GTEST_HAS_FILE_SYSTEM } else if (arg_string == "--help" || HasGoogleTestFlagPrefix(arg)) { // Both help flag and unrecognized Google Test flags (excluding // internal ones) trigger help display. @@ -6741,12 +6765,13 @@ void InitGoogleTest() { #endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) } -#if !defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_) -// Return value of first environment variable that is set and contains -// a non-empty string. If there are none, return the "fallback" string. -// Since we like the temporary directory to have a directory separator suffix, -// add it if not provided in the environment variable value. -static std::string GetTempDirFromEnv( +#if !defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_) || \ + !defined(GTEST_CUSTOM_SRCDIR_FUNCTION_) +// Returns the value of the first environment variable that is set and contains +// a non-empty string. If there are none, returns the "fallback" string. Adds +// the director-separator character as a suffix if not provided in the +// environment variable value. +static std::string GetDirFromEnv( std::initializer_list<const char*> environment_variables, const char* fallback, char separator) { for (const char* variable_name : environment_variables) { @@ -6766,11 +6791,35 @@ std::string TempDir() { #if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_) return GTEST_CUSTOM_TEMPDIR_FUNCTION_(); #elif GTEST_OS_WINDOWS || GTEST_OS_WINDOWS_MOBILE - return GetTempDirFromEnv({"TEST_TMPDIR", "TEMP"}, "\\temp\\", '\\'); + return GetDirFromEnv({"TEST_TMPDIR", "TEMP"}, "\\temp\\", '\\'); +#elif GTEST_OS_LINUX_ANDROID + return GetDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/data/local/tmp/", '/'); +#else + return GetDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/tmp/", '/'); +#endif +} + +#if !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() { + internal::FilePath argv_0(internal::GetArgvs()[0]); + return argv_0.RemoveFileName().string(); +} +#endif + +std::string SrcDir() { +#if defined(GTEST_CUSTOM_SRCDIR_FUNCTION_) + return GTEST_CUSTOM_SRCDIR_FUNCTION_(); +#elif GTEST_OS_WINDOWS || GTEST_OS_WINDOWS_MOBILE + return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(), + '\\'); #elif GTEST_OS_LINUX_ANDROID - return GetTempDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/data/local/tmp/", '/'); + return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(), + '/'); #else - return GetTempDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/tmp/", '/'); + return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(), + '/'); #endif } |