diff options
26 files changed, 345 insertions, 167 deletions
@@ -9,8 +9,8 @@ #### Release 1.10.x -[Release 1.10.x](https://github.com/google/googletest/releases/tag/v1.10.x) is -now available. +[Release 1.10.x](https://github.com/google/googletest/releases/tag/release-1.10.0) +is now available. #### Coming Soon @@ -102,6 +102,9 @@ runs tests from your binary in parallel to provide significant speed-up. is a VS Code extension allowing to view Google Tests in a tree view, and run/debug your tests. +[Cornichon](https://pypi.org/project/cornichon/) is a small Gherkin DSL parser +that generates stub code for Google Test. + ## Requirements Google Test is designed to have fairly minimal requirements to build and use diff --git a/googlemock/docs/cheat_sheet.md b/googlemock/docs/cheat_sheet.md index 850963af..3236e6a9 100644 --- a/googlemock/docs/cheat_sheet.md +++ b/googlemock/docs/cheat_sheet.md @@ -287,6 +287,7 @@ is not changed afterwards, or the meaning of your matcher will be changed. | `FloatEq(a_float)` | `argument` is a `float` value approximately equal to `a_float`, treating two NaNs as unequal. | | `NanSensitiveDoubleEq(a_double)` | `argument` is a `double` value approximately equal to `a_double`, treating two NaNs as equal. | | `NanSensitiveFloatEq(a_float)` | `argument` is a `float` value approximately equal to `a_float`, treating two NaNs as equal. | +| `IsNan()` | `argument` is any floating-point type with a NaN value. | <!-- mdformat on --> The above matchers use ULP-based comparison (the same as used in googletest). @@ -325,9 +326,9 @@ The `argument` can be either a C string or a C++ string object: `ContainsRegex()` and `MatchesRegex()` take ownership of the `RE` object. They use the regular expression syntax defined -[here](../../googletest/docs/advanced.md#regular-expression-syntax). -`StrCaseEq()`, `StrCaseNe()`, `StrEq()`, and `StrNe()` work for wide strings as -well. +[here](../../googletest/docs/advanced.md#regular-expression-syntax). All of +these matchers, except `ContainsRegex()` and `MatchesRegex()` work for wide +strings as well. #### Container Matchers diff --git a/googlemock/include/gmock/gmock-function-mocker.h b/googlemock/include/gmock/gmock-function-mocker.h index cc1535c8..684db139 100644 --- a/googlemock/include/gmock/gmock-function-mocker.h +++ b/googlemock/include/gmock/gmock-function-mocker.h @@ -39,6 +39,13 @@ #include "gmock/gmock-generated-function-mockers.h" // NOLINT #include "gmock/internal/gmock-pp.h" +namespace testing { +namespace internal { +template <typename T> +using identity_t = T; +} // namespace internal +} // namespace testing + #define MOCK_METHOD(...) \ GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__) @@ -207,10 +214,24 @@ #define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype -#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \ - GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), GMOCK_PP_REMOVE_PARENS, \ - GMOCK_PP_IDENTITY) \ - (_Ret)(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args)) +// Note: The use of `identity_t` here allows _Ret to represent return types that +// would normally need to be specified in a different way. For example, a method +// returning a function pointer must be written as +// +// fn_ptr_return_t (*method(method_args_t...))(fn_ptr_args_t...) +// +// But we only support placing the return type at the beginning. To handle this, +// we wrap all calls in identity_t, so that a declaration will be expanded to +// +// identity_t<fn_ptr_return_t (*)(fn_ptr_args_t...)> method(method_args_t...) +// +// This allows us to work around the syntactic oddities of function/method +// types. +#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \ + ::testing::internal::identity_t<GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), \ + GMOCK_PP_REMOVE_PARENS, \ + GMOCK_PP_IDENTITY)(_Ret)>( \ + GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args)) #define GMOCK_INTERNAL_GET_TYPE(_i, _, _elem) \ GMOCK_PP_COMMA_IF(_i) \ diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h index 981af78f..cee96dae 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h +++ b/googlemock/include/gmock/gmock-generated-actions.h @@ -663,7 +663,7 @@ class ActionHelper { typedef typename ::testing::internal::Function<F>::ArgumentTuple\ args_type;\ explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\ - virtual return_type Perform(const args_type& args) {\ + return_type Perform(const args_type& args) override {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ }\ @@ -726,7 +726,7 @@ class ActionHelper { typedef typename ::testing::internal::Function<F>::ArgumentTuple\ args_type;\ gmock_Impl() {}\ - virtual return_type Perform(const args_type& args) {\ + return_type Perform(const args_type& args) override {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ }\ @@ -776,7 +776,7 @@ class ActionHelper { args_type;\ explicit gmock_Impl(p0##_type gmock_p0) : \ p0(::std::forward<p0##_type>(gmock_p0)) {}\ - virtual return_type Perform(const args_type& args) {\ + return_type Perform(const args_type& args) override {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ }\ @@ -832,7 +832,7 @@ class ActionHelper { gmock_Impl(p0##_type gmock_p0, \ p1##_type gmock_p1) : p0(::std::forward<p0##_type>(gmock_p0)), \ p1(::std::forward<p1##_type>(gmock_p1)) {}\ - virtual return_type Perform(const args_type& args) {\ + return_type Perform(const args_type& args) override {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ }\ @@ -893,7 +893,7 @@ class ActionHelper { p2##_type gmock_p2) : p0(::std::forward<p0##_type>(gmock_p0)), \ p1(::std::forward<p1##_type>(gmock_p1)), \ p2(::std::forward<p2##_type>(gmock_p2)) {}\ - virtual return_type Perform(const args_type& args) {\ + return_type Perform(const args_type& args) override {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ }\ @@ -961,7 +961,7 @@ class ActionHelper { p1(::std::forward<p1##_type>(gmock_p1)), \ p2(::std::forward<p2##_type>(gmock_p2)), \ p3(::std::forward<p3##_type>(gmock_p3)) {}\ - virtual return_type Perform(const args_type& args) {\ + return_type Perform(const args_type& args) override {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ }\ @@ -1038,7 +1038,7 @@ class ActionHelper { p2(::std::forward<p2##_type>(gmock_p2)), \ p3(::std::forward<p3##_type>(gmock_p3)), \ p4(::std::forward<p4##_type>(gmock_p4)) {}\ - virtual return_type Perform(const args_type& args) {\ + return_type Perform(const args_type& args) override {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ }\ @@ -1119,7 +1119,7 @@ class ActionHelper { p3(::std::forward<p3##_type>(gmock_p3)), \ p4(::std::forward<p4##_type>(gmock_p4)), \ p5(::std::forward<p5##_type>(gmock_p5)) {}\ - virtual return_type Perform(const args_type& args) {\ + return_type Perform(const args_type& args) override {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ }\ @@ -1206,7 +1206,7 @@ class ActionHelper { p4(::std::forward<p4##_type>(gmock_p4)), \ p5(::std::forward<p5##_type>(gmock_p5)), \ p6(::std::forward<p6##_type>(gmock_p6)) {}\ - virtual return_type Perform(const args_type& args) {\ + return_type Perform(const args_type& args) override {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ }\ @@ -1302,7 +1302,7 @@ class ActionHelper { p5(::std::forward<p5##_type>(gmock_p5)), \ p6(::std::forward<p6##_type>(gmock_p6)), \ p7(::std::forward<p7##_type>(gmock_p7)) {}\ - virtual return_type Perform(const args_type& args) {\ + return_type Perform(const args_type& args) override {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ }\ @@ -1404,7 +1404,7 @@ class ActionHelper { p6(::std::forward<p6##_type>(gmock_p6)), \ p7(::std::forward<p7##_type>(gmock_p7)), \ p8(::std::forward<p8##_type>(gmock_p8)) {}\ - virtual return_type Perform(const args_type& args) {\ + return_type Perform(const args_type& args) override {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ }\ @@ -1513,7 +1513,7 @@ class ActionHelper { p7(::std::forward<p7##_type>(gmock_p7)), \ p8(::std::forward<p8##_type>(gmock_p8)), \ p9(::std::forward<p9##_type>(gmock_p9)) {}\ - virtual return_type Perform(const args_type& args) {\ + return_type Perform(const args_type& args) override {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ }\ diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump index 209603c5..283abcdc 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h.pump +++ b/googlemock/include/gmock/gmock-generated-actions.h.pump @@ -395,7 +395,7 @@ $range k 0..n-1 typedef typename ::testing::internal::Function<F>::ArgumentTuple\ args_type;\ explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\ - virtual return_type Perform(const args_type& args) {\ + return_type Perform(const args_type& args) override {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ }\ @@ -482,7 +482,7 @@ $var macro_name = [[$if i==0 [[ACTION]] $elif i==1 [[ACTION_P]] typedef typename ::testing::internal::Function<F>::ArgumentTuple\ args_type;\ [[$if i==1 [[explicit ]]]]gmock_Impl($ctor_param_list)$inits {}\ - virtual return_type Perform(const args_type& args) {\ + return_type Perform(const args_type& args) override {\ return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\ Perform(this, args);\ }\ diff --git a/googlemock/include/gmock/gmock-generated-matchers.h b/googlemock/include/gmock/gmock-generated-matchers.h index 690a57f1..61892380 100644 --- a/googlemock/include/gmock/gmock-generated-matchers.h +++ b/googlemock/include/gmock/gmock-generated-matchers.h @@ -269,13 +269,13 @@ public:\ gmock_Impl()\ {}\ - virtual bool MatchAndExplain(\ + bool MatchAndExplain(\ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ - ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ + ::testing::MatchResultListener* result_listener) const override;\ + void DescribeTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(false);\ }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + void DescribeNegationTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(true);\ }\ private:\ @@ -318,13 +318,13 @@ public:\ explicit gmock_Impl(p0##_type gmock_p0)\ : p0(::std::move(gmock_p0)) {}\ - virtual bool MatchAndExplain(\ + bool MatchAndExplain(\ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ - ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ + ::testing::MatchResultListener* result_listener) const override;\ + void DescribeTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(false);\ }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + void DescribeNegationTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(true);\ }\ p0##_type const p0;\ @@ -371,13 +371,13 @@ public:\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\ : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)) {}\ - virtual bool MatchAndExplain(\ + bool MatchAndExplain(\ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ - ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ + ::testing::MatchResultListener* result_listener) const override;\ + void DescribeTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(false);\ }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + void DescribeNegationTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(true);\ }\ p0##_type const p0;\ @@ -431,13 +431,13 @@ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\ : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \ p2(::std::move(gmock_p2)) {}\ - virtual bool MatchAndExplain(\ + bool MatchAndExplain(\ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ - ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ + ::testing::MatchResultListener* result_listener) const override;\ + void DescribeTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(false);\ }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + void DescribeNegationTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(true);\ }\ p0##_type const p0;\ @@ -495,13 +495,13 @@ p3##_type gmock_p3)\ : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \ p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)) {}\ - virtual bool MatchAndExplain(\ + bool MatchAndExplain(\ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ - ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ + ::testing::MatchResultListener* result_listener) const override;\ + void DescribeTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(false);\ }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + void DescribeNegationTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(true);\ }\ p0##_type const p0;\ @@ -568,13 +568,13 @@ : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \ p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \ p4(::std::move(gmock_p4)) {}\ - virtual bool MatchAndExplain(\ + bool MatchAndExplain(\ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ - ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ + ::testing::MatchResultListener* result_listener) const override;\ + void DescribeTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(false);\ }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + void DescribeNegationTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(true);\ }\ p0##_type const p0;\ @@ -644,13 +644,13 @@ : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \ p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \ p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)) {}\ - virtual bool MatchAndExplain(\ + bool MatchAndExplain(\ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ - ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ + ::testing::MatchResultListener* result_listener) const override;\ + void DescribeTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(false);\ }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + void DescribeNegationTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(true);\ }\ p0##_type const p0;\ @@ -726,13 +726,13 @@ p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \ p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \ p6(::std::move(gmock_p6)) {}\ - virtual bool MatchAndExplain(\ + bool MatchAndExplain(\ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ - ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ + ::testing::MatchResultListener* result_listener) const override;\ + void DescribeTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(false);\ }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + void DescribeNegationTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(true);\ }\ p0##_type const p0;\ @@ -814,13 +814,13 @@ p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \ p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \ p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)) {}\ - virtual bool MatchAndExplain(\ + bool MatchAndExplain(\ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ - ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ + ::testing::MatchResultListener* result_listener) const override;\ + void DescribeTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(false);\ }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + void DescribeNegationTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(true);\ }\ p0##_type const p0;\ @@ -909,13 +909,13 @@ p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \ p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)), \ p8(::std::move(gmock_p8)) {}\ - virtual bool MatchAndExplain(\ + bool MatchAndExplain(\ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ - ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ + ::testing::MatchResultListener* result_listener) const override;\ + void DescribeTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(false);\ }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + void DescribeNegationTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(true);\ }\ p0##_type const p0;\ @@ -1009,13 +1009,13 @@ p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \ p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)), \ p8(::std::move(gmock_p8)), p9(::std::move(gmock_p9)) {}\ - virtual bool MatchAndExplain(\ + bool MatchAndExplain(\ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ - ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ + ::testing::MatchResultListener* result_listener) const override;\ + void DescribeTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(false);\ }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + void DescribeNegationTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(true);\ }\ p0##_type const p0;\ diff --git a/googlemock/include/gmock/gmock-generated-matchers.h.pump b/googlemock/include/gmock/gmock-generated-matchers.h.pump index ae90917c..69d2ae41 100644 --- a/googlemock/include/gmock/gmock-generated-matchers.h.pump +++ b/googlemock/include/gmock/gmock-generated-matchers.h.pump @@ -302,13 +302,13 @@ $var param_field_decls2 = [[$for j public:\ [[$if i==1 [[explicit ]]]]gmock_Impl($impl_ctor_param_list)\ $impl_inits {}\ - virtual bool MatchAndExplain(\ + bool MatchAndExplain(\ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ - ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ + ::testing::MatchResultListener* result_listener) const override;\ + void DescribeTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(false);\ }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + void DescribeNegationTo(::std::ostream* gmock_os) const override {\ *gmock_os << FormatDescription(true);\ }\$param_field_decls private:\ diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 4428ec14..be446aad 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -42,8 +42,8 @@ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ -#include <math.h> #include <algorithm> +#include <cmath> #include <initializer_list> #include <iterator> #include <limits> @@ -54,6 +54,7 @@ #include <type_traits> #include <utility> #include <vector> + #include "gmock/internal/gmock-internal-utils.h" #include "gmock/internal/gmock-port.h" #include "gtest/gtest.h" @@ -1349,6 +1350,22 @@ MakePredicateFormatterFromMatcher(M matcher) { return PredicateFormatterFromMatcher<M>(std::move(matcher)); } +// Implements the polymorphic IsNan() matcher, which matches any floating type +// value that is Nan. +class IsNanMatcher { + public: + template <typename FloatType> + bool MatchAndExplain(const FloatType& f, + MatchResultListener* /* listener */) const { + return (::std::isnan)(f); + } + + void DescribeTo(::std::ostream* os) const { *os << "is NaN"; } + void DescribeNegationTo(::std::ostream* os) const { + *os << "isn't NaN"; + } +}; + // Implements the polymorphic floating point equality matcher, which matches // two float values using ULP-based approximation or, optionally, a // user-specified epsilon. The template is meant to be instantiated with @@ -1409,7 +1426,7 @@ class FloatingEqMatcher { } const FloatType diff = value - expected_; - if (fabs(diff) <= max_abs_error_) { + if (::std::fabs(diff) <= max_abs_error_) { return true; } @@ -3626,6 +3643,11 @@ inline internal::RefMatcher<T&> Ref(T& x) { // NOLINT return internal::RefMatcher<T&>(x); } +// Creates a polymorphic matcher that matches any NaN floating point. +inline PolymorphicMatcher<internal::IsNanMatcher> IsNan() { + return MakePolymorphicMatcher(internal::IsNanMatcher()); +} + // Creates a matcher that matches any double argument approximately // equal to rhs, where two NANs are considered unequal. inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) { diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index d012e710..584afa98 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -490,8 +490,7 @@ struct Function<R(Args...)> { using Result = R; static constexpr size_t ArgumentCount = sizeof...(Args); template <size_t I> - using Arg = ElemFromList<I, typename MakeIndexSequence<sizeof...(Args)>::type, - Args...>; + using Arg = ElemFromList<I, Args...>; using ArgumentTuple = std::tuple<Args...>; using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>; using MakeResultVoid = void(Args...); diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index f9d34345..81ea9894 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -36,14 +36,17 @@ #include "gmock/gmock-spec-builders.h" #include <stdlib.h> + #include <iostream> // NOLINT #include <map> #include <memory> #include <set> #include <string> #include <vector> + #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "gtest/internal/gtest-port.h" #if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC # include <unistd.h> // NOLINT @@ -70,7 +73,8 @@ GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity, const char* file, int line, const std::string& message) { ::std::ostringstream s; - s << file << ":" << line << ": " << message << ::std::endl; + s << internal::FormatFileLocation(file, line) << " " << message + << ::std::endl; Log(severity, s.str(), 0); } diff --git a/googlemock/test/gmock-function-mocker_test.cc b/googlemock/test/gmock-function-mocker_test.cc index fbc5d5b2..55be70a8 100644 --- a/googlemock/test/gmock-function-mocker_test.cc +++ b/googlemock/test/gmock-function-mocker_test.cc @@ -101,6 +101,10 @@ class FooInterface { virtual int TypeWithComma(const std::map<int, std::string>& a_map) = 0; virtual int TypeWithTemplatedCopyCtor(const TemplatedCopyable<int>&) = 0; + virtual int (*ReturnsFunctionPointer1(int))(bool) = 0; + using fn_ptr = int (*)(bool); + virtual fn_ptr ReturnsFunctionPointer2(int) = 0; + #if GTEST_OS_WINDOWS STDMETHOD_(int, CTNullary)() = 0; STDMETHOD_(bool, CTUnary)(int x) = 0; @@ -159,6 +163,9 @@ class MockFoo : public FooInterface { MOCK_METHOD(int, TypeWithTemplatedCopyCtor, (const TemplatedCopyable<int>&)); // NOLINT + MOCK_METHOD(int (*)(bool), ReturnsFunctionPointer1, (int), ()); + MOCK_METHOD(fn_ptr, ReturnsFunctionPointer2, (int), ()); + #if GTEST_OS_WINDOWS MOCK_METHOD(int, CTNullary, (), (Calltype(STDMETHODCALLTYPE))); MOCK_METHOD(bool, CTUnary, (int), (Calltype(STDMETHODCALLTYPE))); diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 03735267..b9eb894d 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2054,6 +2054,114 @@ TEST(PairMatchBaseTest, WorksWithMoveOnly) { EXPECT_TRUE(matcher.Matches(pointers)); } +// Tests that IsNan() matches a NaN, with float. +TEST(IsNan, FloatMatchesNan) { + float quiet_nan = std::numeric_limits<float>::quiet_NaN(); + float other_nan = std::nanf("1"); + float real_value = 1.0f; + + Matcher<float> m = IsNan(); + EXPECT_TRUE(m.Matches(quiet_nan)); + EXPECT_TRUE(m.Matches(other_nan)); + EXPECT_FALSE(m.Matches(real_value)); + + Matcher<float&> m_ref = IsNan(); + EXPECT_TRUE(m_ref.Matches(quiet_nan)); + EXPECT_TRUE(m_ref.Matches(other_nan)); + EXPECT_FALSE(m_ref.Matches(real_value)); + + Matcher<const float&> m_cref = IsNan(); + EXPECT_TRUE(m_cref.Matches(quiet_nan)); + EXPECT_TRUE(m_cref.Matches(other_nan)); + EXPECT_FALSE(m_cref.Matches(real_value)); +} + +// Tests that IsNan() matches a NaN, with double. +TEST(IsNan, DoubleMatchesNan) { + double quiet_nan = std::numeric_limits<double>::quiet_NaN(); + double other_nan = std::nan("1"); + double real_value = 1.0; + + Matcher<double> m = IsNan(); + EXPECT_TRUE(m.Matches(quiet_nan)); + EXPECT_TRUE(m.Matches(other_nan)); + EXPECT_FALSE(m.Matches(real_value)); + + Matcher<double&> m_ref = IsNan(); + EXPECT_TRUE(m_ref.Matches(quiet_nan)); + EXPECT_TRUE(m_ref.Matches(other_nan)); + EXPECT_FALSE(m_ref.Matches(real_value)); + + Matcher<const double&> m_cref = IsNan(); + EXPECT_TRUE(m_cref.Matches(quiet_nan)); + EXPECT_TRUE(m_cref.Matches(other_nan)); + EXPECT_FALSE(m_cref.Matches(real_value)); +} + +// Tests that IsNan() matches a NaN, with long double. +TEST(IsNan, LongDoubleMatchesNan) { + long double quiet_nan = std::numeric_limits<long double>::quiet_NaN(); + long double other_nan = std::nan("1"); + long double real_value = 1.0; + + Matcher<long double> m = IsNan(); + EXPECT_TRUE(m.Matches(quiet_nan)); + EXPECT_TRUE(m.Matches(other_nan)); + EXPECT_FALSE(m.Matches(real_value)); + + Matcher<long double&> m_ref = IsNan(); + EXPECT_TRUE(m_ref.Matches(quiet_nan)); + EXPECT_TRUE(m_ref.Matches(other_nan)); + EXPECT_FALSE(m_ref.Matches(real_value)); + + Matcher<const long double&> m_cref = IsNan(); + EXPECT_TRUE(m_cref.Matches(quiet_nan)); + EXPECT_TRUE(m_cref.Matches(other_nan)); + EXPECT_FALSE(m_cref.Matches(real_value)); +} + +// Tests that IsNan() works with Not. +TEST(IsNan, NotMatchesNan) { + Matcher<float> mf = Not(IsNan()); + EXPECT_FALSE(mf.Matches(std::numeric_limits<float>::quiet_NaN())); + EXPECT_FALSE(mf.Matches(std::nanf("1"))); + EXPECT_TRUE(mf.Matches(1.0)); + + Matcher<double> md = Not(IsNan()); + EXPECT_FALSE(md.Matches(std::numeric_limits<double>::quiet_NaN())); + EXPECT_FALSE(md.Matches(std::nan("1"))); + EXPECT_TRUE(md.Matches(1.0)); + + Matcher<long double> mld = Not(IsNan()); + EXPECT_FALSE(mld.Matches(std::numeric_limits<long double>::quiet_NaN())); + EXPECT_FALSE(mld.Matches(std::nanl("1"))); + EXPECT_TRUE(mld.Matches(1.0)); +} + +// Tests that IsNan() can describe itself. +TEST(IsNan, CanDescribeSelf) { + Matcher<float> mf = IsNan(); + EXPECT_EQ("is NaN", Describe(mf)); + + Matcher<double> md = IsNan(); + EXPECT_EQ("is NaN", Describe(md)); + + Matcher<long double> mld = IsNan(); + EXPECT_EQ("is NaN", Describe(mld)); +} + +// Tests that IsNan() can describe itself with Not. +TEST(IsNan, CanDescribeSelfWithNot) { + Matcher<float> mf = Not(IsNan()); + EXPECT_EQ("isn't NaN", Describe(mf)); + + Matcher<double> md = Not(IsNan()); + EXPECT_EQ("isn't NaN", Describe(md)); + + Matcher<long double> mld = Not(IsNan()); + EXPECT_EQ("isn't NaN", Describe(mld)); +} + // Tests that FloatEq() matches a 2-tuple where // FloatEq(first field) matches the second field. TEST(FloatEq2Test, MatchesEqualArguments) { diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 7bf5a8ad..791a2476 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -69,8 +69,8 @@ using testing::AtMost; using testing::Between; using testing::Cardinality; using testing::CardinalityInterface; -using testing::ContainsRegex; using testing::Const; +using testing::ContainsRegex; using testing::DoAll; using testing::DoDefault; using testing::Eq; diff --git a/googletest/include/gtest/gtest-message.h b/googletest/include/gtest/gtest-message.h index 4a80e11e..21899232 100644 --- a/googletest/include/gtest/gtest-message.h +++ b/googletest/include/gtest/gtest-message.h @@ -49,6 +49,7 @@ #include <limits> #include <memory> +#include <sstream> #include "gtest/internal/gtest-port.h" diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index e1135e99..f61e3c5d 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -58,7 +58,9 @@ class FooTest : public ::testing::TestWithParam<const char*> { // Then, use the TEST_P macro to define as many parameterized tests // for this fixture as you want. The _P suffix is for "parameterized" -// or "pattern", whichever you prefer to think. +// or "pattern", whichever you prefer to think. The arguments to the +// TEST_P macro are the test_suite_name and test_case (both which must be +// non-empty) that will form the test name. TEST_P(FooTest, DoesBlah) { // Inside a test, access the test parameter with the GetParam() method @@ -101,10 +103,10 @@ INSTANTIATE_TEST_SUITE_P(InstantiationName, // To distinguish different instances of the pattern, (yes, you // can instantiate it more than once) the first argument to the -// INSTANTIATE_TEST_SUITE_P macro is a prefix that will be added to the -// actual test suite name. Remember to pick unique prefixes for different -// instantiations. The tests from the instantiation above will have -// these names: +// INSTANTIATE_TEST_SUITE_P macro is a prefix (which must be non-empty) that +// will be added to the actual test suite name. Remember to pick unique prefixes +// for different instantiations. The tests from the instantiation above will +// have these names: // // * InstantiationName/FooTest.DoesBlah/0 for "meeny" // * InstantiationName/FooTest.DoesBlah/1 for "miny" @@ -412,6 +414,10 @@ internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) { } #define TEST_P(test_suite_name, test_name) \ + static_assert(sizeof(GTEST_STRINGIFY_(test_suite_name)) > 1, \ + "test_suite_name must not be empty"); \ + static_assert(sizeof(GTEST_STRINGIFY_(test_name)) > 1, \ + "test_name must not be empty"); \ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ : public test_suite_name { \ public: \ @@ -423,7 +429,7 @@ internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) { ::testing::UnitTest::GetInstance() \ ->parameterized_test_registry() \ .GetTestSuitePatternHolder<test_suite_name>( \ - #test_suite_name, \ + GTEST_STRINGIFY_(test_suite_name), \ ::testing::internal::CodeLocation(__FILE__, __LINE__)) \ ->AddTestPattern( \ GTEST_STRINGIFY_(test_suite_name), GTEST_STRINGIFY_(test_name), \ @@ -458,6 +464,10 @@ internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) { #define GTEST_GET_SECOND_(first, second, ...) second #define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, ...) \ + static_assert(sizeof(GTEST_STRINGIFY_(test_suite_name)) > 1, \ + "test_suite_name must not be empty"); \ + static_assert(sizeof(GTEST_STRINGIFY_(prefix)) > 1, \ + "prefix must not be empty"); \ static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \ gtest_##prefix##test_suite_name##_EvalGenerator_() { \ return GTEST_EXPAND_(GTEST_GET_FIRST_(__VA_ARGS__, DUMMY_PARAM_)); \ @@ -483,10 +493,11 @@ internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) { ::testing::UnitTest::GetInstance() \ ->parameterized_test_registry() \ .GetTestSuitePatternHolder<test_suite_name>( \ - #test_suite_name, \ + GTEST_STRINGIFY_(test_suite_name), \ ::testing::internal::CodeLocation(__FILE__, __LINE__)) \ ->AddTestSuiteInstantiation( \ - #prefix, >est_##prefix##test_suite_name##_EvalGenerator_, \ + GTEST_STRINGIFY_(prefix), \ + >est_##prefix##test_suite_name##_EvalGenerator_, \ >est_##prefix##test_suite_name##_EvalGenerateName_, \ __FILE__, __LINE__) diff --git a/googletest/include/gtest/gtest-typed-test.h b/googletest/include/gtest/gtest-typed-test.h index 095ce058..6b7c9c8a 100644 --- a/googletest/include/gtest/gtest-typed-test.h +++ b/googletest/include/gtest/gtest-typed-test.h @@ -201,7 +201,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); private: \ typedef CaseName<gtest_TypeParam_> TestFixture; \ typedef gtest_TypeParam_ TypeParam; \ - virtual void TestBody(); \ + void TestBody() override; \ }; \ static bool gtest_##CaseName##_##TestName##_registered_ \ GTEST_ATTRIBUTE_UNUSED_ = \ @@ -276,7 +276,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes); private: \ typedef SuiteName<gtest_TypeParam_> TestFixture; \ typedef gtest_TypeParam_ TypeParam; \ - virtual void TestBody(); \ + void TestBody() override; \ }; \ static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \ GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).AddTestName( \ diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 76ce13ae..ebfe3c9d 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -1124,25 +1124,29 @@ struct MakeIndexSequence template <> struct MakeIndexSequence<0> : IndexSequence<> {}; -// FIXME: This implementation of ElemFromList is O(1) in instantiation depth, -// but it is O(N^2) in total instantiations. Not sure if this is the best -// tradeoff, as it will make it somewhat slow to compile. -template <typename T, size_t, size_t> -struct ElemFromListImpl {}; - -template <typename T, size_t I> -struct ElemFromListImpl<T, I, I> { - using type = T; +template <size_t> +struct Ignore { + Ignore(...); // NOLINT }; -// Get the Nth element from T... -// It uses O(1) instantiation depth. -template <size_t N, typename I, typename... T> -struct ElemFromList; +template <typename> +struct ElemFromListImpl; +template <size_t... I> +struct ElemFromListImpl<IndexSequence<I...>> { + // We make Ignore a template to solve a problem with MSVC. + // A non-template Ignore would work fine with `decltype(Ignore(I))...`, but + // MSVC doesn't understand how to deal with that pack expansion. + // Use `0 * I` to have a single instantiation of Ignore. + template <typename R> + static R Apply(Ignore<0 * I>..., R (*)(), ...); +}; -template <size_t N, size_t... I, typename... T> -struct ElemFromList<N, IndexSequence<I...>, T...> - : ElemFromListImpl<T, N, I>... {}; +template <size_t N, typename... T> +struct ElemFromList { + using type = + decltype(ElemFromListImpl<typename MakeIndexSequence<N>::type>::Apply( + static_cast<T (*)()>(nullptr)...)); +}; template <typename... T> class FlatTuple; @@ -1152,9 +1156,7 @@ struct FlatTupleElemBase; template <typename... T, size_t I> struct FlatTupleElemBase<FlatTuple<T...>, I> { - using value_type = - typename ElemFromList<I, typename MakeIndexSequence<sizeof...(T)>::type, - T...>::type; + using value_type = typename ElemFromList<I, T...>::type; FlatTupleElemBase() = default; explicit FlatTupleElemBase(value_type t) : value(std::move(t)) {} value_type value; @@ -1192,12 +1194,12 @@ class FlatTuple explicit FlatTuple(T... t) : FlatTuple::FlatTupleBase(std::move(t)...) {} template <size_t I> - const typename ElemFromList<I, Indices, T...>::type& Get() const { + const typename ElemFromList<I, T...>::type& Get() const { return static_cast<const FlatTupleElemBase<FlatTuple, I>*>(this)->value; } template <size_t I> - typename ElemFromList<I, Indices, T...>::type& Get() { + typename ElemFromList<I, T...>::type& Get() { return static_cast<FlatTupleElemBase<FlatTuple, I>*>(this)->value; } }; diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h index 97533993..e900b3ff 100644 --- a/googletest/include/gtest/internal/gtest-param-util.h +++ b/googletest/include/gtest/internal/gtest-param-util.h @@ -565,10 +565,7 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { test_param_names.insert(param_name); - if (!test_info->test_base_name.empty()) { - test_name_stream << test_info->test_base_name << "/"; - } - test_name_stream << param_name; + test_name_stream << test_info->test_base_name << "/" << param_name; MakeAndRegisterTestInfo( test_suite_name.c_str(), test_name_stream.GetString().c_str(), nullptr, // No type parameter. diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 3c9f7251..c4b1aabe 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -248,7 +248,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <memory> #include <type_traits> #ifndef _WIN32_WCE @@ -261,16 +260,14 @@ # include <TargetConditionals.h> #endif -#include <algorithm> // NOLINT -#include <iostream> // NOLINT -#include <sstream> // NOLINT -#include <string> // NOLINT +#include <iostream> // NOLINT +#include <memory> +#include <string> // NOLINT #include <tuple> -#include <utility> #include <vector> // NOLINT -#include "gtest/internal/gtest-port-arch.h" #include "gtest/internal/custom/gtest-port.h" +#include "gtest/internal/gtest-port-arch.h" #if !defined(GTEST_DEV_EMAIL_) # define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com" @@ -441,15 +438,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # endif // defined(_MSC_VER) || defined(__BORLANDC__) #endif // GTEST_HAS_EXCEPTIONS -#if !defined(GTEST_HAS_STD_STRING) -// Even though we don't use this macro any longer, we keep it in case -// some clients still depend on it. -# define GTEST_HAS_STD_STRING 1 -#elif !GTEST_HAS_STD_STRING -// The user told us that ::std::string isn't available. -# error "::std::string isn't available." -#endif // !defined(GTEST_HAS_STD_STRING) - #ifndef GTEST_HAS_STD_WSTRING // The user didn't tell us whether ::std::wstring is available, so we need // to figure it out. @@ -1599,7 +1587,7 @@ class ThreadLocal : public ThreadLocalBase { class DefaultValueHolderFactory : public ValueHolderFactory { public: DefaultValueHolderFactory() {} - virtual ValueHolder* MakeNewHolder() const { return new ValueHolder(); } + ValueHolder* MakeNewHolder() const override { return new ValueHolder(); } private: GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory); @@ -1608,7 +1596,7 @@ class ThreadLocal : public ThreadLocalBase { class InstanceValueHolderFactory : public ValueHolderFactory { public: explicit InstanceValueHolderFactory(const T& value) : value_(value) {} - virtual ValueHolder* MakeNewHolder() const { + ValueHolder* MakeNewHolder() const override { return new ValueHolder(value_); } @@ -2013,10 +2001,6 @@ inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } GTEST_DISABLE_MSC_DEPRECATED_PUSH_() -inline const char* StrNCpy(char* dest, const char* src, size_t n) { - return strncpy(dest, src, n); -} - // ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and // StrError() aren't needed on Windows CE at this time and thus not // defined there. diff --git a/googletest/src/gtest-test-part.cc b/googletest/src/gtest-test-part.cc index 178317a6..a938683c 100644 --- a/googletest/src/gtest-test-part.cc +++ b/googletest/src/gtest-test-part.cc @@ -31,6 +31,8 @@ // The Google C++ Testing and Mocking Framework (Google Test) #include "gtest/gtest-test-part.h" + +#include "gtest/internal/gtest-port.h" #include "src/gtest-internal-inl.h" namespace testing { @@ -46,7 +48,9 @@ std::string TestPartResult::ExtractSummary(const char* message) { // Prints a TestPartResult object. std::ostream& operator<<(std::ostream& os, const TestPartResult& result) { - return os << result.file_name() << ":" << result.line_number() << ": " + return os << internal::FormatFileLocation(result.file_name(), + result.line_number()) + << " " << (result.type() == TestPartResult::kSuccess ? "Success" : result.type() == TestPartResult::kSkip diff --git a/googletest/test/googletest-output-test-golden-lin.txt b/googletest/test/googletest-output-test-golden-lin.txt index 038de921..270b15ae 100644 --- a/googletest/test/googletest-output-test-golden-lin.txt +++ b/googletest/test/googletest-output-test-golden-lin.txt @@ -12,7 +12,7 @@ Expected equality of these values: 3 Stack trace: (omitted) -[0;32m[==========] [mRunning 85 tests from 40 test suites. +[0;32m[==========] [mRunning 84 tests from 39 test suites. [0;32m[----------] [mGlobal test environment set-up. FooEnvironment::SetUp() called. BarEnvironment::SetUp() called. @@ -966,9 +966,6 @@ Expected equality of these values: Stack trace: (omitted) [0;31m[ FAILED ] [mPrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2 -[0;32m[----------] [m1 test from EmptyBasenameParamInst -[0;32m[ RUN ] [mEmptyBasenameParamInst.Passes/0 -[0;32m[ OK ] [mEmptyBasenameParamInst.Passes/0 [0;32m[----------] [m2 tests from PrintingStrings/ParamTest [0;32m[ RUN ] [mPrintingStrings/ParamTest.Success/a [0;32m[ OK ] [mPrintingStrings/ParamTest.Success/a @@ -995,8 +992,8 @@ Failed Expected fatal failure. Stack trace: (omitted) -[0;32m[==========] [m85 tests from 40 test suites ran. -[0;32m[ PASSED ] [m31 tests. +[0;32m[==========] [m84 tests from 39 test suites ran. +[0;32m[ PASSED ] [m30 tests. [0;31m[ FAILED ] [m54 tests, listed below: [0;31m[ FAILED ] [mNonfatalFailureTest.EscapesStringOperands [0;31m[ FAILED ] [mNonfatalFailureTest.DiffForLongStrings diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc index 4f716d84..f724cca9 100644 --- a/googletest/test/googletest-output-test_.cc +++ b/googletest/test/googletest-output-test_.cc @@ -96,14 +96,6 @@ INSTANTIATE_TEST_SUITE_P(PrintingFailingParams, FailingParamTest, testing::Values(2)); -// Tests that an empty value for the test suite basename yields just -// the test name without any prior / -class EmptyBasenameParamInst : public testing::TestWithParam<int> {}; - -TEST_P(EmptyBasenameParamInst, Passes) { EXPECT_EQ(1, GetParam()); } - -INSTANTIATE_TEST_SUITE_P(, EmptyBasenameParamInst, testing::Values(1)); - static const char kGoldenString[] = "\"Line\0 1\"\nLine 2"; TEST(NonfatalFailureTest, EscapesStringOperands) { diff --git a/googletest/test/googletest-param-test-test.cc b/googletest/test/googletest-param-test-test.cc index 6c187dff..2740aaab 100644 --- a/googletest/test/googletest-param-test-test.cc +++ b/googletest/test/googletest-param-test-test.cc @@ -37,6 +37,7 @@ # include <algorithm> # include <iostream> # include <list> +# include <set> # include <sstream> # include <string> # include <vector> @@ -802,7 +803,7 @@ TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) { ::testing::UnitTest::GetInstance()->current_test_info(); EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_suite_name()); - EXPECT_STREQ("FooSomeTestName", test_info->name()); + EXPECT_STREQ("FooSomeTestName/0", test_info->name()); } INSTANTIATE_TEST_SUITE_P(FortyTwo, MacroNamingTest, Values(42)); @@ -819,6 +820,36 @@ TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized), EXPECT_STREQ("FooSomeTestName", test_info->name()); } +TEST(MacroNameing, LookupNames) { + std::set<std::string> know_suite_names, know_test_names; + + auto ins = testing::UnitTest::GetInstance(); + int ts = 0; + while (const testing::TestSuite* suite = ins->GetTestSuite(ts++)) { + know_suite_names.insert(suite->name()); + + int ti = 0; + while (const testing::TestInfo* info = suite->GetTestInfo(ti++)) { + know_test_names.insert(std::string(suite->name()) + "." + info->name()); + } + } + + // Check that the expected form of the test suit name actualy exists. + EXPECT_NE( // + know_suite_names.find("FortyTwo/MacroNamingTest"), + know_suite_names.end()); + EXPECT_NE( + know_suite_names.find("MacroNamingTestNonParametrized"), + know_suite_names.end()); + // Check that the expected form of the test name actualy exists. + EXPECT_NE( // + know_test_names.find("FortyTwo/MacroNamingTest.FooSomeTestName/0"), + know_test_names.end()); + EXPECT_NE( + know_test_names.find("MacroNamingTestNonParametrized.FooSomeTestName"), + know_test_names.end()); +} + // Tests that user supplied custom parameter names are working correctly. // Runs the test with a builtin helper method which uses PrintToString, // as well as a custom function and custom functor to ensure all possible diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index 4bdc9add..58be7d1c 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -219,7 +219,6 @@ using ::testing::PrintToString; using ::testing::internal::FormatForComparisonFailureMessage; using ::testing::internal::ImplicitCast_; using ::testing::internal::NativeArray; -using ::testing::internal::RE; using ::testing::internal::RelationToSourceReference; using ::testing::internal::Strings; using ::testing::internal::UniversalPrint; diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 39749b7b..d17a1554 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -5343,7 +5343,7 @@ TEST_P(CodeLocationForTESTP, Verify) { VERIFY_CODE_LOCATION; } -INSTANTIATE_TEST_SUITE_P(, CodeLocationForTESTP, Values(0)); +INSTANTIATE_TEST_SUITE_P(All, CodeLocationForTESTP, Values(0)); template <typename T> class CodeLocationForTYPEDTEST : public Test { @@ -6170,7 +6170,7 @@ TEST_F(ParseFlagsTest, WideStrings) { #if GTEST_USE_OWN_FLAGFILE_FLAG_ class FlagfileTest : public ParseFlagsTest { public: - virtual void SetUp() { + void SetUp() override { ParseFlagsTest::SetUp(); testdata_path_.Set(internal::FilePath( @@ -6180,7 +6180,7 @@ class FlagfileTest : public ParseFlagsTest { EXPECT_TRUE(testdata_path_.CreateFolder()); } - virtual void TearDown() { + void TearDown() override { testing::internal::posix::RmDir(testdata_path_.c_str()); ParseFlagsTest::TearDown(); } @@ -7353,20 +7353,15 @@ TEST(IndexSequence, MakeIndexSequence) { // ElemFromList TEST(ElemFromList, Basic) { using testing::internal::ElemFromList; - using Idx = testing::internal::MakeIndexSequence<3>::type; - EXPECT_TRUE(( - std::is_same<int, ElemFromList<0, Idx, int, double, char>::type>::value)); EXPECT_TRUE( - (std::is_same<double, - ElemFromList<1, Idx, int, double, char>::type>::value)); + (std::is_same<int, ElemFromList<0, int, double, char>::type>::value)); EXPECT_TRUE( - (std::is_same<char, - ElemFromList<2, Idx, int, double, char>::type>::value)); + (std::is_same<double, ElemFromList<1, int, double, char>::type>::value)); EXPECT_TRUE( - (std::is_same< - char, ElemFromList<7, testing::internal::MakeIndexSequence<12>::type, - int, int, int, int, int, int, int, char, int, int, - int, int>::type>::value)); + (std::is_same<char, ElemFromList<2, int, double, char>::type>::value)); + EXPECT_TRUE(( + std::is_same<char, ElemFromList<7, int, int, int, int, int, int, int, + char, int, int, int, int>::type>::value)); } // FlatTuple diff --git a/library.json b/library.json index 49b9d20b..50bc84ac 100644 --- a/library.json +++ b/library.json @@ -8,7 +8,7 @@ "type": "git", "url": "https://github.com/google/googletest.git" }, - "version": "1.8.1", + "version": "1.10.0", "frameworks": "arduino", "platforms": [ "espressif32" @@ -33,7 +33,7 @@ "googletest/src/gtest-all.cc", "googletest/src/gtest_main.cc", "googletest/test", - "googletest/CMakeLists.txt", + "googletest/CMakeLists.txt" ] }, "build": { |