Bug 1951370 - Update googletest to 24a9e940d481f992ba852599c78bb2217362847b r=ahal

Differential Revision: https://phabricator.services.mozilla.com/D240141
This commit is contained in:
Updatebot
2025-03-04 16:13:11 +00:00
parent 9a5c71e06a
commit 688eb05226
21 changed files with 300 additions and 231 deletions

View File

@@ -83,6 +83,10 @@ cc_library(
) )
# Google Test including Google Mock # Google Test including Google Mock
# For an actual test, use `gtest` and also `gtest_main` if you depend on gtest's
# main(). For a library, use `gtest_for_library` instead if the library can be
# testonly.
cc_library( cc_library(
name = "gtest", name = "gtest",
srcs = glob( srcs = glob(
@@ -167,6 +171,16 @@ cc_library(
}), }),
) )
# `gtest`, but testonly. See guidance on `gtest` for when to use this.
alias(
name = "gtest_for_library",
actual = ":gtest",
testonly = True,
)
# Implements main() for tests using gtest. Prefer to depend on `gtest` as well
# to ensure compliance with the layering_check Bazel feature where only the
# direct hdrs values are available.
cc_library( cc_library(
name = "gtest_main", name = "gtest_main",
srcs = ["googlemock/src/gmock_main.cc"], srcs = ["googlemock/src/gmock_main.cc"],

View File

@@ -1,10 +1,10 @@
# Note: CMake support is community-based. The maintainers do not use CMake # Note: CMake support is community-based. The maintainers do not use CMake
# internally. # internally.
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.16)
project(googletest-distribution) project(googletest-distribution)
set(GOOGLETEST_VERSION 1.15.2) set(GOOGLETEST_VERSION 1.16.0)
if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)

View File

@@ -41,7 +41,7 @@ module(
bazel_dep( bazel_dep(
name = "abseil-cpp", name = "abseil-cpp",
version = "20240116.2", version = "20250127.0",
) )
bazel_dep( bazel_dep(
name = "platforms", name = "platforms",
@@ -54,7 +54,7 @@ bazel_dep(
bazel_dep( bazel_dep(
name = "rules_python", name = "rules_python",
version = "0.34.0", version = "1.1.0",
dev_dependency = True, dev_dependency = True,
) )

View File

@@ -9,7 +9,7 @@ GoogleTest now follows the
We recommend We recommend
[updating to the latest commit in the `main` branch as often as possible](https://github.com/abseil/abseil-cpp/blob/master/FAQ.md#what-is-live-at-head-and-how-do-i-do-it). [updating to the latest commit in the `main` branch as often as possible](https://github.com/abseil/abseil-cpp/blob/master/FAQ.md#what-is-live-at-head-and-how-do-i-do-it).
We do publish occasional semantic versions, tagged with We do publish occasional semantic versions, tagged with
`v${major}.${minor}.${patch}` (e.g. `v1.15.2`). `v${major}.${minor}.${patch}` (e.g. `v1.16.0`).
#### Documentation Updates #### Documentation Updates
@@ -17,12 +17,15 @@ Our documentation is now live on GitHub Pages at
https://google.github.io/googletest/. We recommend browsing the documentation on https://google.github.io/googletest/. We recommend browsing the documentation on
GitHub Pages rather than directly in the repository. GitHub Pages rather than directly in the repository.
#### Release 1.15.2 #### Release 1.16.0
[Release 1.15.2](https://github.com/google/googletest/releases/tag/v1.15.2) is [Release 1.16.0](https://github.com/google/googletest/releases/tag/v1.16.0) is
now available. now available.
The 1.15.x branch requires at least C++14. The 1.16.x branch requires at least C++14.
The 1.16.x branch will be the last to support C++14. Future development will
[require at least C++17](https://opensource.google/documentation/policies/cplusplus-support#c_language_standard).
#### Continuous Integration #### Continuous Integration

View File

@@ -36,13 +36,12 @@ googletest_deps()
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive( http_archive(
name = "rules_python", name = "rules_python",
sha256 = "d71d2c67e0bce986e1c5a7731b4693226867c45bfe0b7c5e0067228a536fc580", sha256 = "9c6e26911a79fbf510a8f06d8eedb40f412023cf7fa6d1461def27116bff022c",
strip_prefix = "rules_python-0.29.0", strip_prefix = "rules_python-1.1.0",
urls = ["https://github.com/bazelbuild/rules_python/releases/download/0.29.0/rules_python-0.29.0.tar.gz"], url = "https://github.com/bazelbuild/rules_python/releases/download/1.1.0/rules_python-1.1.0.tar.gz",
) )
# https://github.com/bazelbuild/rules_python/releases/tag/1.1.0
# https://github.com/bazelbuild/rules_python/releases/tag/0.29.0
load("@rules_python//python:repositories.bzl", "py_repositories") load("@rules_python//python:repositories.bzl", "py_repositories")
py_repositories() py_repositories()

View File

@@ -1720,6 +1720,16 @@ struct SaveArgAction {
} }
}; };
template <size_t k, typename Ptr>
struct SaveArgByMoveAction {
Ptr pointer;
template <typename... Args>
void operator()(Args&&... args) const {
*pointer = std::move(std::get<k>(std::tie(args...)));
}
};
template <size_t k, typename Ptr> template <size_t k, typename Ptr>
struct SaveArgPointeeAction { struct SaveArgPointeeAction {
Ptr pointer; Ptr pointer;
@@ -2070,6 +2080,13 @@ internal::SaveArgAction<k, Ptr> SaveArg(Ptr pointer) {
return {pointer}; return {pointer};
} }
// Action SaveArgByMove<k>(pointer) moves the k-th (0-based) argument of the
// mock function into *pointer.
template <size_t k, typename Ptr>
internal::SaveArgByMoveAction<k, Ptr> SaveArgByMove(Ptr pointer) {
return {pointer};
}
// Action SaveArgPointee<k>(pointer) saves the value pointed to // Action SaveArgPointee<k>(pointer) saves the value pointed to
// by the k-th (0-based) argument of the mock function to *pointer. // by the k-th (0-based) argument of the mock function to *pointer.
template <size_t k, typename Ptr> template <size_t k, typename Ptr>
@@ -2213,9 +2230,9 @@ template <typename F, typename Impl>
} }
#define GMOCK_INTERNAL_ARG_UNUSED(i, data, el) \ #define GMOCK_INTERNAL_ARG_UNUSED(i, data, el) \
, GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED const arg##i##_type& arg##i , [[maybe_unused]] const arg##i##_type& arg##i
#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_ \ #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_ \
GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED const args_type& args GMOCK_PP_REPEAT( \ [[maybe_unused]] const args_type& args GMOCK_PP_REPEAT( \
GMOCK_INTERNAL_ARG_UNUSED, , 10) GMOCK_INTERNAL_ARG_UNUSED, , 10)
#define GMOCK_INTERNAL_ARG(i, data, el) , const arg##i##_type& arg##i #define GMOCK_INTERNAL_ARG(i, data, el) , const arg##i##_type& arg##i
@@ -2280,8 +2297,8 @@ template <typename F, typename Impl>
std::shared_ptr<const gmock_Impl> impl_; \ std::shared_ptr<const gmock_Impl> impl_; \
}; \ }; \
template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \ template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \
inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name( \ [[nodiscard]] inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name( \
GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) GTEST_MUST_USE_RESULT_; \ GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)); \
template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \ template <GMOCK_ACTION_TYPENAME_PARAMS_(params)> \
inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name( \ inline full_name<GMOCK_ACTION_TYPE_PARAMS_(params)> name( \
GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) { \ GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) { \
@@ -2316,7 +2333,7 @@ template <typename F, typename Impl>
return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \ return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \
}; \ }; \
}; \ }; \
inline name##Action name() GTEST_MUST_USE_RESULT_; \ [[nodiscard]] inline name##Action name(); \
inline name##Action name() { return name##Action(); } \ inline name##Action name() { return name##Action(); } \
template <typename function_type, typename return_type, typename args_type, \ template <typename function_type, typename return_type, typename args_type, \
GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \

View File

@@ -3305,6 +3305,13 @@ auto UnpackStructImpl(const T& u, std::make_index_sequence<20>, char) {
const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t] = u; const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t] = u;
return std::tie(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, t);
} }
template <typename T>
auto UnpackStructImpl(const T& in, std::make_index_sequence<21>, char) {
const auto& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u] =
in;
return std::tie(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t,
u);
}
#endif // defined(__cpp_structured_bindings) #endif // defined(__cpp_structured_bindings)
template <size_t I, typename T> template <size_t I, typename T>
@@ -4453,6 +4460,10 @@ inline PolymorphicMatcher<internal::FieldMatcher<Class, FieldType>> Field(
// matches 'matcher'. For example, // matches 'matcher'. For example,
// Property(&Foo::str, StartsWith("hi")) // Property(&Foo::str, StartsWith("hi"))
// matches a Foo object x if and only if x.str() starts with "hi". // matches a Foo object x if and only if x.str() starts with "hi".
//
// Warning: Don't use `Property()` against member functions that you do not
// own, because taking addresses of functions is fragile and generally not part
// of the contract of the function.
template <typename Class, typename PropertyType, typename PropertyMatcher> template <typename Class, typename PropertyType, typename PropertyMatcher>
inline PolymorphicMatcher<internal::PropertyMatcher< inline PolymorphicMatcher<internal::PropertyMatcher<
Class, PropertyType, PropertyType (Class::*)() const>> Class, PropertyType, PropertyType (Class::*)() const>>
@@ -5551,8 +5562,7 @@ PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> ThrowsMessage(
template <typename arg_type> \ template <typename arg_type> \
bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain( \ bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain( \
const arg_type& arg, \ const arg_type& arg, \
GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED ::testing::MatchResultListener* \ [[maybe_unused]] ::testing::MatchResultListener* result_listener) const
result_listener) const
#define MATCHER_P(name, p0, description) \ #define MATCHER_P(name, p0, description) \
GMOCK_INTERNAL_MATCHER(name, name##MatcherP, description, (#p0), (p0)) GMOCK_INTERNAL_MATCHER(name, name##MatcherP, description, (#p0), (p0))
@@ -5637,8 +5647,8 @@ PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> ThrowsMessage(
bool full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>:: \ bool full_name<GMOCK_INTERNAL_MATCHER_TYPE_PARAMS(args)>:: \
gmock_Impl<arg_type>::MatchAndExplain( \ gmock_Impl<arg_type>::MatchAndExplain( \
const arg_type& arg, \ const arg_type& arg, \
GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED ::testing:: \ [[maybe_unused]] ::testing::MatchResultListener* result_listener) \
MatchResultListener* result_listener) const const
#define GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAMS(args) \ #define GMOCK_INTERNAL_MATCHER_TEMPLATE_PARAMS(args) \
GMOCK_PP_TAIL( \ GMOCK_PP_TAIL( \

View File

@@ -521,9 +521,8 @@
GMOCK_INTERNAL_DECL_##value_params) \ GMOCK_INTERNAL_DECL_##value_params) \
GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \ GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \
= default; \ = default; \
, \ , : impl_(std::make_shared<gmock_Impl>( \
: impl_(std::make_shared<gmock_Impl>( \ GMOCK_INTERNAL_LIST_##value_params)){}) \
GMOCK_INTERNAL_LIST_##value_params)){}) \
GMOCK_ACTION_CLASS_(name, value_params)(const GMOCK_ACTION_CLASS_( \ GMOCK_ACTION_CLASS_(name, value_params)(const GMOCK_ACTION_CLASS_( \
name, value_params) &) noexcept GMOCK_INTERNAL_DEFN_COPY_ \ name, value_params) &) noexcept GMOCK_INTERNAL_DEFN_COPY_ \
##value_params \ ##value_params \
@@ -551,10 +550,10 @@
}; \ }; \
template <GMOCK_INTERNAL_DECL_##template_params \ template <GMOCK_INTERNAL_DECL_##template_params \
GMOCK_INTERNAL_DECL_TYPE_##value_params> \ GMOCK_INTERNAL_DECL_TYPE_##value_params> \
GMOCK_ACTION_CLASS_( \ [[nodiscard]] GMOCK_ACTION_CLASS_( \
name, value_params)<GMOCK_INTERNAL_LIST_##template_params \ name, value_params)<GMOCK_INTERNAL_LIST_##template_params \
GMOCK_INTERNAL_LIST_TYPE_##value_params> \ GMOCK_INTERNAL_LIST_TYPE_##value_params> \
name(GMOCK_INTERNAL_DECL_##value_params) GTEST_MUST_USE_RESULT_; \ name(GMOCK_INTERNAL_DECL_##value_params); \
template <GMOCK_INTERNAL_DECL_##template_params \ template <GMOCK_INTERNAL_DECL_##template_params \
GMOCK_INTERNAL_DECL_TYPE_##value_params> \ GMOCK_INTERNAL_DECL_TYPE_##value_params> \
inline GMOCK_ACTION_CLASS_( \ inline GMOCK_ACTION_CLASS_( \

View File

@@ -467,11 +467,6 @@ struct Function<R(Args...)> {
using MakeResultIgnoredValue = IgnoredValue(Args...); using MakeResultIgnoredValue = IgnoredValue(Args...);
}; };
#ifdef GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL
template <typename R, typename... Args>
constexpr size_t Function<R(Args...)>::ArgumentCount;
#endif
// Workaround for MSVC error C2039: 'type': is not a member of 'std' // Workaround for MSVC error C2039: 'type': is not a member of 'std'
// when std::tuple_element is used. // when std::tuple_element is used.
// See: https://github.com/google/googletest/issues/3931 // See: https://github.com/google/googletest/issues/3931

View File

@@ -25,7 +25,7 @@ When building GoogleTest as a standalone project, the typical workflow starts
with with
``` ```
git clone https://github.com/google/googletest.git -b v1.15.2 git clone https://github.com/google/googletest.git -b v1.16.0
cd googletest # Main directory of the cloned repository. cd googletest # Main directory of the cloned repository.
mkdir build # Create a directory to hold the build output. mkdir build # Create a directory to hold the build output.
cd build cd build

View File

@@ -195,7 +195,7 @@ function(cxx_library_with_type name type cxx_flags)
target_link_libraries(${name} PUBLIC Threads::Threads) target_link_libraries(${name} PUBLIC Threads::Threads)
endif() endif()
target_compile_features(${name} PUBLIC cxx_std_14) target_compile_features(${name} PUBLIC cxx_std_17)
endfunction() endfunction()
######################################################################## ########################################################################

View File

@@ -129,6 +129,13 @@ namespace testing {
// //
// Expected: Foo() is even // Expected: Foo() is even
// Actual: it's 5 // Actual: it's 5
//
// Returned AssertionResult objects may not be ignored.
// Note: Disabled for SWIG as it doesn't parse attributes correctly.
#if !defined(SWIG)
class [[nodiscard]] AssertionResult;
#endif // !SWIG
class GTEST_API_ AssertionResult { class GTEST_API_ AssertionResult {
public: public:

View File

@@ -469,7 +469,7 @@ internal::ParamConverterGenerator<T> ConvertGenerator(
::testing::internal::CodeLocation(__FILE__, __LINE__)); \ ::testing::internal::CodeLocation(__FILE__, __LINE__)); \
return 0; \ return 0; \
} \ } \
GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static int gtest_registering_dummy_; \ [[maybe_unused]] static int gtest_registering_dummy_; \
}; \ }; \
int GTEST_TEST_CLASS_NAME_(test_suite_name, \ int GTEST_TEST_CLASS_NAME_(test_suite_name, \
test_name)::gtest_registering_dummy_ = \ test_name)::gtest_registering_dummy_ = \
@@ -493,39 +493,38 @@ internal::ParamConverterGenerator<T> ConvertGenerator(
#define GTEST_GET_FIRST_(first, ...) first #define GTEST_GET_FIRST_(first, ...) first
#define GTEST_GET_SECOND_(first, second, ...) second #define GTEST_GET_SECOND_(first, second, ...) second
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, ...) \ #define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, ...) \
static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \ static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \
gtest_##prefix##test_suite_name##_EvalGenerator_() { \ gtest_##prefix##test_suite_name##_EvalGenerator_() { \
return GTEST_EXPAND_(GTEST_GET_FIRST_(__VA_ARGS__, DUMMY_PARAM_)); \ return GTEST_EXPAND_(GTEST_GET_FIRST_(__VA_ARGS__, DUMMY_PARAM_)); \
} \ } \
static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \ static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \
const ::testing::TestParamInfo<test_suite_name::ParamType>& info) { \ const ::testing::TestParamInfo<test_suite_name::ParamType>& info) { \
if (::testing::internal::AlwaysFalse()) { \ if (::testing::internal::AlwaysFalse()) { \
::testing::internal::TestNotEmpty(GTEST_EXPAND_(GTEST_GET_SECOND_( \ ::testing::internal::TestNotEmpty(GTEST_EXPAND_(GTEST_GET_SECOND_( \
__VA_ARGS__, \ __VA_ARGS__, \
::testing::internal::DefaultParamName<test_suite_name::ParamType>, \ ::testing::internal::DefaultParamName<test_suite_name::ParamType>, \
DUMMY_PARAM_))); \ DUMMY_PARAM_))); \
auto t = std::make_tuple(__VA_ARGS__); \ auto t = std::make_tuple(__VA_ARGS__); \
static_assert(std::tuple_size<decltype(t)>::value <= 2, \ static_assert(std::tuple_size<decltype(t)>::value <= 2, \
"Too Many Args!"); \ "Too Many Args!"); \
} \ } \
return ((GTEST_EXPAND_(GTEST_GET_SECOND_( \ return ((GTEST_EXPAND_(GTEST_GET_SECOND_( \
__VA_ARGS__, \ __VA_ARGS__, \
::testing::internal::DefaultParamName<test_suite_name::ParamType>, \ ::testing::internal::DefaultParamName<test_suite_name::ParamType>, \
DUMMY_PARAM_))))(info); \ DUMMY_PARAM_))))(info); \
} \ } \
GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static int \ [[maybe_unused]] static int gtest_##prefix##test_suite_name##_dummy_ = \
gtest_##prefix##test_suite_name##_dummy_ = \ ::testing::UnitTest::GetInstance() \
::testing::UnitTest::GetInstance() \ ->parameterized_test_registry() \
->parameterized_test_registry() \ .GetTestSuitePatternHolder<test_suite_name>( \
.GetTestSuitePatternHolder<test_suite_name>( \ GTEST_STRINGIFY_(test_suite_name), \
GTEST_STRINGIFY_(test_suite_name), \ ::testing::internal::CodeLocation(__FILE__, __LINE__)) \
::testing::internal::CodeLocation(__FILE__, __LINE__)) \ ->AddTestSuiteInstantiation( \
->AddTestSuiteInstantiation( \ GTEST_STRINGIFY_(prefix), \
GTEST_STRINGIFY_(prefix), \ &gtest_##prefix##test_suite_name##_EvalGenerator_, \
&gtest_##prefix##test_suite_name##_EvalGenerator_, \ &gtest_##prefix##test_suite_name##_EvalGenerateName_, __FILE__, \
&gtest_##prefix##test_suite_name##_EvalGenerateName_, \ __LINE__)
__FILE__, __LINE__)
// Allow Marking a Parameterized test class as not needing to be instantiated. // Allow Marking a Parameterized test class as not needing to be instantiated.
#define GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(T) \ #define GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(T) \

View File

@@ -194,34 +194,33 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \ typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
GTEST_NAME_GENERATOR_(CaseName) GTEST_NAME_GENERATOR_(CaseName)
#define TYPED_TEST(CaseName, TestName) \ #define TYPED_TEST(CaseName, TestName) \
static_assert(sizeof(GTEST_STRINGIFY_(TestName)) > 1, \ static_assert(sizeof(GTEST_STRINGIFY_(TestName)) > 1, \
"test-name must not be empty"); \ "test-name must not be empty"); \
template <typename gtest_TypeParam_> \ template <typename gtest_TypeParam_> \
class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \ class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \
: public CaseName<gtest_TypeParam_> { \ : public CaseName<gtest_TypeParam_> { \
private: \ private: \
typedef CaseName<gtest_TypeParam_> TestFixture; \ typedef CaseName<gtest_TypeParam_> TestFixture; \
typedef gtest_TypeParam_ TypeParam; \ typedef gtest_TypeParam_ TypeParam; \
void TestBody() override; \ void TestBody() override; \
}; \ }; \
GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static bool \ [[maybe_unused]] static bool gtest_##CaseName##_##TestName##_registered_ = \
gtest_##CaseName##_##TestName##_registered_ = \ ::testing::internal::TypeParameterizedTest< \
::testing::internal::TypeParameterizedTest< \ CaseName, \
CaseName, \ ::testing::internal::TemplateSel<GTEST_TEST_CLASS_NAME_(CaseName, \
::testing::internal::TemplateSel<GTEST_TEST_CLASS_NAME_( \ TestName)>, \
CaseName, TestName)>, \ GTEST_TYPE_PARAMS_( \
GTEST_TYPE_PARAMS_( \ CaseName)>::Register("", \
CaseName)>::Register("", \ ::testing::internal::CodeLocation( \
::testing::internal::CodeLocation( \ __FILE__, __LINE__), \
__FILE__, __LINE__), \ GTEST_STRINGIFY_(CaseName), \
GTEST_STRINGIFY_(CaseName), \ GTEST_STRINGIFY_(TestName), 0, \
GTEST_STRINGIFY_(TestName), 0, \ ::testing::internal::GenerateNames< \
::testing::internal::GenerateNames< \ GTEST_NAME_GENERATOR_(CaseName), \
GTEST_NAME_GENERATOR_(CaseName), \ GTEST_TYPE_PARAMS_(CaseName)>()); \
GTEST_TYPE_PARAMS_(CaseName)>()); \ template <typename gtest_TypeParam_> \
template <typename gtest_TypeParam_> \ void GTEST_TEST_CLASS_NAME_(CaseName, \
void GTEST_TEST_CLASS_NAME_(CaseName, \
TestName)<gtest_TypeParam_>::TestBody() TestName)<gtest_TypeParam_>::TestBody()
// Legacy API is deprecated but still available // Legacy API is deprecated but still available
@@ -268,23 +267,22 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
TYPED_TEST_SUITE_P TYPED_TEST_SUITE_P
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
#define TYPED_TEST_P(SuiteName, TestName) \ #define TYPED_TEST_P(SuiteName, TestName) \
namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \ namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
template <typename gtest_TypeParam_> \ template <typename gtest_TypeParam_> \
class TestName : public SuiteName<gtest_TypeParam_> { \ class TestName : public SuiteName<gtest_TypeParam_> { \
private: \ private: \
typedef SuiteName<gtest_TypeParam_> TestFixture; \ typedef SuiteName<gtest_TypeParam_> TestFixture; \
typedef gtest_TypeParam_ TypeParam; \ typedef gtest_TypeParam_ TypeParam; \
void TestBody() override; \ void TestBody() override; \
}; \ }; \
GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static bool \ [[maybe_unused]] static bool gtest_##TestName##_defined_ = \
gtest_##TestName##_defined_ = \ GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).AddTestName( \
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).AddTestName( \ __FILE__, __LINE__, GTEST_STRINGIFY_(SuiteName), \
__FILE__, __LINE__, GTEST_STRINGIFY_(SuiteName), \ GTEST_STRINGIFY_(TestName)); \
GTEST_STRINGIFY_(TestName)); \ } \
} \ template <typename gtest_TypeParam_> \
template <typename gtest_TypeParam_> \ void GTEST_SUITE_NAMESPACE_( \
void GTEST_SUITE_NAMESPACE_( \
SuiteName)::TestName<gtest_TypeParam_>::TestBody() SuiteName)::TestName<gtest_TypeParam_>::TestBody()
// Note: this won't work correctly if the trailing arguments are macros. // Note: this won't work correctly if the trailing arguments are macros.
@@ -292,8 +290,8 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \ namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
typedef ::testing::internal::Templates<__VA_ARGS__> gtest_AllTests_; \ typedef ::testing::internal::Templates<__VA_ARGS__> gtest_AllTests_; \
} \ } \
GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static const char* const \ [[maybe_unused]] static const char* const GTEST_REGISTERED_TEST_NAMES_( \
GTEST_REGISTERED_TEST_NAMES_(SuiteName) = \ SuiteName) = \
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).VerifyRegisteredTestNames( \ GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).VerifyRegisteredTestNames( \
GTEST_STRINGIFY_(SuiteName), __FILE__, __LINE__, #__VA_ARGS__) GTEST_STRINGIFY_(SuiteName), __FILE__, __LINE__, #__VA_ARGS__)
@@ -305,24 +303,22 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
REGISTER_TYPED_TEST_SUITE_P REGISTER_TYPED_TEST_SUITE_P
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
#define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types, ...) \ #define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types, ...) \
static_assert(sizeof(GTEST_STRINGIFY_(Prefix)) > 1, \ static_assert(sizeof(GTEST_STRINGIFY_(Prefix)) > 1, \
"test-suit-prefix must not be empty"); \ "test-suit-prefix must not be empty"); \
GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static bool \ [[maybe_unused]] static bool gtest_##Prefix##_##SuiteName = \
gtest_##Prefix##_##SuiteName = \ ::testing::internal::TypeParameterizedTestSuite< \
::testing::internal::TypeParameterizedTestSuite< \ SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \
SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \ ::testing::internal::GenerateTypeList<Types>::type>:: \
::testing::internal::GenerateTypeList<Types>::type>:: \ Register(GTEST_STRINGIFY_(Prefix), \
Register( \ ::testing::internal::CodeLocation(__FILE__, __LINE__), \
GTEST_STRINGIFY_(Prefix), \ &GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName), \
::testing::internal::CodeLocation(__FILE__, __LINE__), \ GTEST_STRINGIFY_(SuiteName), \
&GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName), \ GTEST_REGISTERED_TEST_NAMES_(SuiteName), \
GTEST_STRINGIFY_(SuiteName), \ ::testing::internal::GenerateNames< \
GTEST_REGISTERED_TEST_NAMES_(SuiteName), \ ::testing::internal::NameGeneratorSelector< \
::testing::internal::GenerateNames< \ __VA_ARGS__>::type, \
::testing::internal::NameGeneratorSelector< \ ::testing::internal::GenerateTypeList<Types>::type>())
__VA_ARGS__>::type, \
::testing::internal::GenerateTypeList<Types>::type>())
// Legacy API is deprecated but still available // Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_

View File

@@ -73,8 +73,6 @@
#include "gtest/internal/gtest-internal.h" #include "gtest/internal/gtest-internal.h"
#include "gtest/internal/gtest-string.h" #include "gtest/internal/gtest-string.h"
#include "mozilla/Attributes.h"
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
/* class A needs to have dll-interface to be used by clients of class B */) /* class A needs to have dll-interface to be used by clients of class B */)
@@ -327,7 +325,7 @@ class GTEST_API_ Test {
// //
// DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM. // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
// Instead, use the TEST or TEST_F macro. // Instead, use the TEST or TEST_F macro.
MOZ_CAN_RUN_SCRIPT virtual void TestBody() = 0; virtual void TestBody() = 0;
// Sets up, executes, and tears down the test. // Sets up, executes, and tears down the test.
void Run(); void Run();
@@ -1125,7 +1123,7 @@ class GTEST_API_ UnitTest {
// This method can only be called from the main thread. // This method can only be called from the main thread.
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
int Run() GTEST_MUST_USE_RESULT_; [[nodiscard]] int Run();
// Returns the working directory when the first TEST() or TEST_F() // Returns the working directory when the first TEST() or TEST_F()
// was executed. The UnitTest object owns the string. // was executed. The UnitTest object owns the string.
@@ -2331,7 +2329,7 @@ TestInfo* RegisterTest(const char* test_suite_name, const char* test_name,
// //
// This function was formerly a macro; thus, it is in the global // This function was formerly a macro; thus, it is in the global
// namespace and has an all-caps name. // namespace and has an all-caps name.
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_; [[nodiscard]] int RUN_ALL_TESTS();
inline int RUN_ALL_TESTS() { return ::testing::UnitTest::GetInstance()->Run(); } inline int RUN_ALL_TESTS() { return ::testing::UnitTest::GetInstance()->Run(); }

View File

@@ -894,11 +894,6 @@ class HasDebugStringAndShortDebugString {
HasDebugStringType::value && HasShortDebugStringType::value; HasDebugStringType::value && HasShortDebugStringType::value;
}; };
#ifdef GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL
template <typename T>
constexpr bool HasDebugStringAndShortDebugString<T>::value;
#endif
// When the compiler sees expression IsContainerTest<C>(0), if C is an // When the compiler sees expression IsContainerTest<C>(0), if C is an
// STL-style container class, the first overload of IsContainerTest // STL-style container class, the first overload of IsContainerTest
// will be viable (since both C::iterator* and C::const_iterator* are // will be viable (since both C::iterator* and C::const_iterator* are
@@ -1241,30 +1236,40 @@ class FlatTuple
// Utility functions to be called with static_assert to induce deprecation // Utility functions to be called with static_assert to induce deprecation
// warnings. // warnings.
GTEST_INTERNAL_DEPRECATED( [[deprecated(
"INSTANTIATE_TEST_CASE_P is deprecated, please use " "INSTANTIATE_TEST_CASE_P is deprecated, please use "
"INSTANTIATE_TEST_SUITE_P") "INSTANTIATE_TEST_SUITE_P")]]
constexpr bool InstantiateTestCase_P_IsDeprecated() { return true; } constexpr bool InstantiateTestCase_P_IsDeprecated() {
return true;
}
GTEST_INTERNAL_DEPRECATED( [[deprecated(
"TYPED_TEST_CASE_P is deprecated, please use " "TYPED_TEST_CASE_P is deprecated, please use "
"TYPED_TEST_SUITE_P") "TYPED_TEST_SUITE_P")]]
constexpr bool TypedTestCase_P_IsDeprecated() { return true; } constexpr bool TypedTestCase_P_IsDeprecated() {
return true;
}
GTEST_INTERNAL_DEPRECATED( [[deprecated(
"TYPED_TEST_CASE is deprecated, please use " "TYPED_TEST_CASE is deprecated, please use "
"TYPED_TEST_SUITE") "TYPED_TEST_SUITE")]]
constexpr bool TypedTestCaseIsDeprecated() { return true; } constexpr bool TypedTestCaseIsDeprecated() {
return true;
}
GTEST_INTERNAL_DEPRECATED( [[deprecated(
"REGISTER_TYPED_TEST_CASE_P is deprecated, please use " "REGISTER_TYPED_TEST_CASE_P is deprecated, please use "
"REGISTER_TYPED_TEST_SUITE_P") "REGISTER_TYPED_TEST_SUITE_P")]]
constexpr bool RegisterTypedTestCase_P_IsDeprecated() { return true; } constexpr bool RegisterTypedTestCase_P_IsDeprecated() {
return true;
}
GTEST_INTERNAL_DEPRECATED( [[deprecated(
"INSTANTIATE_TYPED_TEST_CASE_P is deprecated, please use " "INSTANTIATE_TYPED_TEST_CASE_P is deprecated, please use "
"INSTANTIATE_TYPED_TEST_SUITE_P") "INSTANTIATE_TYPED_TEST_SUITE_P")]]
constexpr bool InstantiateTypedTestCase_P_IsDeprecated() { return true; } constexpr bool InstantiateTypedTestCase_P_IsDeprecated() {
return true;
}
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
@@ -1501,8 +1506,7 @@ class NeverThrown {
\ \
private: \ private: \
void TestBody() override; \ void TestBody() override; \
GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static ::testing::TestInfo* const \ [[maybe_unused]] static ::testing::TestInfo* const test_info_; \
test_info_; \
}; \ }; \
\ \
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_suite_name, \ ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_suite_name, \

View File

@@ -194,7 +194,6 @@
// //
// Macros for basic C++ coding: // Macros for basic C++ coding:
// GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning. // GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
// GTEST_MUST_USE_RESULT_ - declares that a function's result must be used.
// GTEST_INTENTIONAL_CONST_COND_PUSH_ - start code section where MSVC C4127 is // GTEST_INTENTIONAL_CONST_COND_PUSH_ - start code section where MSVC C4127 is
// suppressed (constant conditional). // suppressed (constant conditional).
// GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127 // GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127
@@ -260,11 +259,6 @@
// BoolFromGTestEnv() - parses a bool environment variable. // BoolFromGTestEnv() - parses a bool environment variable.
// Int32FromGTestEnv() - parses an int32_t environment variable. // Int32FromGTestEnv() - parses an int32_t environment variable.
// StringFromGTestEnv() - parses a string environment variable. // StringFromGTestEnv() - parses a string environment variable.
//
// Deprecation warnings:
// GTEST_INTERNAL_DEPRECATED(message) - attribute marking a function as
// deprecated; calling a marked function
// should generate a compiler warning
// The definition of GTEST_INTERNAL_CPLUSPLUS_LANG comes first because it can // The definition of GTEST_INTERNAL_CPLUSPLUS_LANG comes first because it can
// potentially be used as an #include guard. // potentially be used as an #include guard.
@@ -275,8 +269,8 @@
#endif #endif
#if !defined(GTEST_INTERNAL_CPLUSPLUS_LANG) || \ #if !defined(GTEST_INTERNAL_CPLUSPLUS_LANG) || \
GTEST_INTERNAL_CPLUSPLUS_LANG < 201402L GTEST_INTERNAL_CPLUSPLUS_LANG < 201703L
#error C++ versions less than C++14 are not supported. #error C++ versions less than C++17 are not supported.
#endif #endif
// MSVC >= 19.11 (VS 2017 Update 3) supports __has_include. // MSVC >= 19.11 (VS 2017 Update 3) supports __has_include.
@@ -772,25 +766,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#define GTEST_HAVE_FEATURE_(x) 0 #define GTEST_HAVE_FEATURE_(x) 0
#endif #endif
// Use this annotation after a variable or parameter declaration to tell the
// compiler the variable/parameter may be used.
// Example:
//
// GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED int foo = bar();
//
// This can be removed once we only support only C++17 or newer and
// [[maybe_unused]] is available on all supported platforms.
#if GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE(maybe_unused)
#define GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED [[maybe_unused]]
#elif GTEST_HAVE_ATTRIBUTE_(unused)
// This is inferior to [[maybe_unused]] as it can produce a
// -Wused-but-marked-unused warning on optionally used symbols, but it is all we
// have.
#define GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED __attribute__((__unused__))
#else
#define GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED
#endif
// Use this annotation before a function that takes a printf format string. // Use this annotation before a function that takes a printf format string.
#if GTEST_HAVE_ATTRIBUTE_(format) && defined(__MINGW_PRINTF_FORMAT) #if GTEST_HAVE_ATTRIBUTE_(format) && defined(__MINGW_PRINTF_FORMAT)
// MinGW has two different printf implementations. Ensure the format macro // MinGW has two different printf implementations. Ensure the format macro
@@ -805,17 +780,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) #define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check)
#endif #endif
// Tell the compiler to warn about unused return values for functions declared
// with this macro. The macro should be used on function declarations
// following the argument list:
//
// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
#if GTEST_HAVE_ATTRIBUTE_(warn_unused_result)
#define GTEST_MUST_USE_RESULT_ __attribute__((warn_unused_result))
#else
#define GTEST_MUST_USE_RESULT_
#endif
// MS C++ compiler emits warning when a conditional expression is compile time // 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 // constant. In some contexts this warning is false positive and needs to be
// suppressed. Use the following two macros in such cases: // suppressed. Use the following two macros in such cases:
@@ -2367,26 +2331,6 @@ const char* StringFromGTestEnv(const char* flag, const char* default_val);
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
#if !defined(GTEST_INTERNAL_DEPRECATED)
// Internal Macro to mark an API deprecated, for googletest usage only
// Usage: class GTEST_INTERNAL_DEPRECATED(message) MyClass or
// GTEST_INTERNAL_DEPRECATED(message) <return_type> myFunction(); Every usage of
// a deprecated entity will trigger a warning when compiled with
// `-Wdeprecated-declarations` option (clang, gcc, any __GNUC__ compiler).
// For msvc /W3 option will need to be used
// Note that for 'other' compilers this macro evaluates to nothing to prevent
// compilations errors.
#if defined(_MSC_VER)
#define GTEST_INTERNAL_DEPRECATED(message) __declspec(deprecated(message))
#elif defined(__GNUC__)
#define GTEST_INTERNAL_DEPRECATED(message) __attribute__((deprecated(message)))
#else
#define GTEST_INTERNAL_DEPRECATED(message)
#endif
#endif // !defined(GTEST_INTERNAL_DEPRECATED)
#ifdef GTEST_HAS_ABSL #ifdef GTEST_HAS_ABSL
// Always use absl::any for UniversalPrinter<> specializations if googletest // Always use absl::any for UniversalPrinter<> specializations if googletest
// is built with absl support. // is built with absl support.
@@ -2527,12 +2471,6 @@ using Variant = ::std::variant<T...>;
#define GTEST_INTERNAL_HAS_VARIANT 0 #define GTEST_INTERNAL_HAS_VARIANT 0
#endif #endif
#if (defined(__cpp_constexpr) && !defined(__cpp_inline_variables)) || \
(defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
GTEST_INTERNAL_CPLUSPLUS_LANG < 201703L)
#define GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL 1
#endif
#if (defined(__cpp_lib_three_way_comparison) || \ #if (defined(__cpp_lib_three_way_comparison) || \
(GTEST_INTERNAL_HAS_INCLUDE(<compare>) && \ (GTEST_INTERNAL_HAS_INCLUDE(<compare>) && \
GTEST_INTERNAL_CPLUSPLUS_LANG >= 201907L)) GTEST_INTERNAL_CPLUSPLUS_LANG >= 201907L))

View File

@@ -826,6 +826,10 @@ class GTEST_API_ UnitTestImpl {
bool catch_exceptions() const { return catch_exceptions_; } bool catch_exceptions() const { return catch_exceptions_; }
private: private:
// Returns true if a warning should be issued if no tests match the test
// filter flag.
bool ShouldWarnIfNoTestsMatchFilter() const;
struct CompareTestSuitesByPointer { struct CompareTestSuitesByPointer {
bool operator()(const TestSuite* lhs, const TestSuite* rhs) const { bool operator()(const TestSuite* lhs, const TestSuite* rhs) const {
return lhs->name_ < rhs->name_; return lhs->name_ < rhs->name_;

View File

@@ -192,12 +192,17 @@ static const char kDefaultOutputFormat[] = "xml";
// The default output file. // The default output file.
static const char kDefaultOutputFile[] = "test_detail"; static const char kDefaultOutputFile[] = "test_detail";
// These environment variables are set by Bazel.
// https://bazel.build/reference/test-encyclopedia#initial-conditions
//
// The environment variable name for the test shard index. // The environment variable name for the test shard index.
static const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; static const char kTestShardIndex[] = "GTEST_SHARD_INDEX";
// The environment variable name for the total number of test shards. // The environment variable name for the total number of test shards.
static const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; static const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS";
// The environment variable name for the test shard status file. // The environment variable name for the test shard status file.
static const char kTestShardStatusFile[] = "GTEST_SHARD_STATUS_FILE"; static const char kTestShardStatusFile[] = "GTEST_SHARD_STATUS_FILE";
// The environment variable name for the test output warnings file.
static const char kTestWarningsOutputFile[] = "TEST_WARNINGS_OUTPUT_FILE";
namespace internal { namespace internal {
@@ -258,6 +263,12 @@ GTEST_DEFINE_bool_(
testing::GetDefaultFailFast()), testing::GetDefaultFailFast()),
"True if and only if a test failure should stop further test execution."); "True if and only if a test failure should stop further test execution.");
GTEST_DEFINE_bool_(
fail_if_no_test_linked,
testing::internal::BoolFromGTestEnv("fail_if_no_test_linked", false),
"True if and only if the test should fail if no test case (including "
"disabled test cases) is linked.");
GTEST_DEFINE_bool_( GTEST_DEFINE_bool_(
also_run_disabled_tests, also_run_disabled_tests,
testing::internal::BoolFromGTestEnv("also_run_disabled_tests", false), testing::internal::BoolFromGTestEnv("also_run_disabled_tests", false),
@@ -5869,6 +5880,23 @@ TestSuite* UnitTestImpl::GetTestSuite(
static void SetUpEnvironment(Environment* env) { env->SetUp(); } static void SetUpEnvironment(Environment* env) { env->SetUp(); }
static void TearDownEnvironment(Environment* env) { env->TearDown(); } static void TearDownEnvironment(Environment* env) { env->TearDown(); }
// If the environment variable TEST_WARNINGS_OUTPUT_FILE was provided, appends
// `str` to the file, creating the file if necessary.
#if GTEST_HAS_FILE_SYSTEM
static void AppendToTestWarningsOutputFile(const std::string& str) {
const char* const filename = posix::GetEnv(kTestWarningsOutputFile);
if (filename == nullptr) {
return;
}
auto* const file = posix::FOpen(filename, "a");
if (file == nullptr) {
return;
}
GTEST_CHECK_(fwrite(str.data(), 1, str.size(), file) == str.size());
GTEST_CHECK_(posix::FClose(file) == 0);
}
#endif // GTEST_HAS_FILE_SYSTEM
// Runs all tests in this UnitTest object, prints the result, and // Runs all tests in this UnitTest object, prints the result, and
// returns true if all tests are successful. If any exception is // returns true if all tests are successful. If any exception is
// thrown during a test, the test is considered to be failed, but the // thrown during a test, the test is considered to be failed, but the
@@ -5890,6 +5918,28 @@ bool UnitTestImpl::RunAllTests() {
// user didn't call InitGoogleTest. // user didn't call InitGoogleTest.
PostFlagParsingInit(); PostFlagParsingInit();
// Handle the case where the program has no tests linked.
// Sometimes this is a programmer mistake, but sometimes it is intended.
if (total_test_count() == 0) {
constexpr char kNoTestLinkedMessage[] =
"This test program does NOT link in any test case.";
constexpr char kNoTestLinkedFatal[] =
"This is INVALID. Please make sure to link in at least one test case.";
constexpr char kNoTestLinkedWarning[] =
"Please make sure this is intended.";
const bool fail_if_no_test_linked = GTEST_FLAG_GET(fail_if_no_test_linked);
ColoredPrintf(
GTestColor::kRed, "%s %s\n", kNoTestLinkedMessage,
fail_if_no_test_linked ? kNoTestLinkedFatal : kNoTestLinkedWarning);
if (fail_if_no_test_linked) {
return false;
}
#if GTEST_HAS_FILE_SYSTEM
AppendToTestWarningsOutputFile(std::string(kNoTestLinkedMessage) + ' ' +
kNoTestLinkedWarning + '\n');
#endif // GTEST_HAS_FILE_SYSTEM
}
#if GTEST_HAS_FILE_SYSTEM #if GTEST_HAS_FILE_SYSTEM
// Even if sharding is not on, test runners may want to use the // 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 // GTEST_SHARD_STATUS_FILE to query whether the test supports the sharding
@@ -6063,6 +6113,17 @@ bool UnitTestImpl::RunAllTests() {
environments_.clear(); environments_.clear();
} }
// Try to warn the user if no tests matched the test filter.
if (ShouldWarnIfNoTestsMatchFilter()) {
const std::string filter_warning =
std::string("filter \"") + GTEST_FLAG_GET(filter) +
"\" did not match any test; no tests were run\n";
ColoredPrintf(GTestColor::kRed, "WARNING: %s", filter_warning.c_str());
#if GTEST_HAS_FILE_SYSTEM
AppendToTestWarningsOutputFile(filter_warning);
#endif // GTEST_HAS_FILE_SYSTEM
}
if (!gtest_is_initialized_before_run_all_tests) { if (!gtest_is_initialized_before_run_all_tests) {
ColoredPrintf( ColoredPrintf(
GTestColor::kRed, GTestColor::kRed,
@@ -6231,6 +6292,30 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
return num_selected_tests; return num_selected_tests;
} }
// Returns true if a warning should be issued if no tests match the test filter
// flag. We can't simply count the number of tests that ran because, for
// instance, test sharding and death tests might mean no tests are expected to
// run in this process, but will run in another process.
bool UnitTestImpl::ShouldWarnIfNoTestsMatchFilter() const {
if (total_test_count() == 0) {
// No tests were linked in to program.
// This case is handled by a different warning.
return false;
}
const PositiveAndNegativeUnitTestFilter gtest_flag_filter(
GTEST_FLAG_GET(filter));
for (auto* test_suite : test_suites_) {
const std::string& test_suite_name = test_suite->name_;
for (TestInfo* test_info : test_suite->test_info_list()) {
const std::string& test_name = test_info->name_;
if (gtest_flag_filter.MatchesTest(test_suite_name, test_name)) {
return false;
}
}
}
return true;
}
// Prints the given C-string on a single line by replacing all '\n' // Prints the given C-string on a single line by replacing all '\n'
// characters with string "\\n". If the output takes more than // characters with string "\\n". If the output takes more than
// max_length characters, only prints the first max_length characters // max_length characters, only prints the first max_length characters
@@ -6677,6 +6762,7 @@ static bool ParseGoogleTestFlag(const char* const arg) {
GTEST_INTERNAL_PARSE_FLAG(death_test_style); GTEST_INTERNAL_PARSE_FLAG(death_test_style);
GTEST_INTERNAL_PARSE_FLAG(death_test_use_fork); GTEST_INTERNAL_PARSE_FLAG(death_test_use_fork);
GTEST_INTERNAL_PARSE_FLAG(fail_fast); GTEST_INTERNAL_PARSE_FLAG(fail_fast);
GTEST_INTERNAL_PARSE_FLAG(fail_if_no_test_linked);
GTEST_INTERNAL_PARSE_FLAG(filter); GTEST_INTERNAL_PARSE_FLAG(filter);
GTEST_INTERNAL_PARSE_FLAG(internal_run_death_test); GTEST_INTERNAL_PARSE_FLAG(internal_run_death_test);
GTEST_INTERNAL_PARSE_FLAG(list_tests); GTEST_INTERNAL_PARSE_FLAG(list_tests);

View File

@@ -17,9 +17,9 @@ def googletest_deps():
if not native.existing_rule("abseil-cpp"): if not native.existing_rule("abseil-cpp"):
http_archive( http_archive(
name = "abseil-cpp", name = "abseil-cpp",
sha256 = "733726b8c3a6d39a4120d7e45ea8b41a434cdacde401cba500f14236c49b39dc", sha256 = "16242f394245627e508ec6bb296b433c90f8d914f73b9c026fddb905e27276e8",
strip_prefix = "abseil-cpp-20240116.2", strip_prefix = "abseil-cpp-20250127.0",
urls = ["https://github.com/abseil/abseil-cpp/releases/download/20240116.2/abseil-cpp-20240116.2.tar.gz"], urls = ["https://github.com/abseil/abseil-cpp/releases/download/20250127.0/abseil-cpp-20250127.0.tar.gz"],
) )
if not native.existing_rule("fuchsia_sdk"): if not native.existing_rule("fuchsia_sdk"):

View File

@@ -10,9 +10,9 @@ origin:
url: https://google.github.io/googletest/ url: https://google.github.io/googletest/
release: e235eb34c6c4fed790ccdad4b16394301360dcd4 (2025-01-31T18:23:04Z). release: 24a9e940d481f992ba852599c78bb2217362847b (2025-02-28T19:36:13Z).
revision: e235eb34c6c4fed790ccdad4b16394301360dcd4 revision: 24a9e940d481f992ba852599c78bb2217362847b
license: BSD-3-Clause license: BSD-3-Clause
license-file: LICENSE license-file: LICENSE