From fab35920ad7e709847a94175337b8674bea0f9ae Mon Sep 17 00:00:00 2001 From: misterg Date: Mon, 8 Oct 2018 10:30:02 -0400 Subject: [PATCH 1/4] Remove non-variadic pre C++11 AllOf PiperOrigin-RevId: 216183352 --- .../include/gmock/gmock-generated-matchers.h | 170 ------------------ .../gmock/gmock-generated-matchers.h.pump | 50 ------ googlemock/include/gmock/gmock-matchers.h | 9 +- googlemock/test/gmock-matchers_test.cc | 95 ++++------ 4 files changed, 38 insertions(+), 286 deletions(-) diff --git a/googlemock/include/gmock/gmock-generated-matchers.h b/googlemock/include/gmock/gmock-generated-matchers.h index 16093bf8..61fe66ad 100644 --- a/googlemock/include/gmock/gmock-generated-matchers.h +++ b/googlemock/include/gmock/gmock-generated-matchers.h @@ -297,94 +297,6 @@ class ArgsMatcher { GTEST_DISALLOW_ASSIGN_(ArgsMatcher); }; -// A set of metafunctions for computing the result type of AllOf. -// AllOf(m1, ..., mN) returns -// AllOfResultN::type. - -// Although AllOf isn't defined for one argument, AllOfResult1 is defined -// to simplify the implementation. -template -struct AllOfResult1 { - typedef M1 type; -}; - -template -struct AllOfResult2 { - typedef BothOfMatcher< - typename AllOfResult1::type, - typename AllOfResult1::type - > type; -}; - -template -struct AllOfResult3 { - typedef BothOfMatcher< - typename AllOfResult1::type, - typename AllOfResult2::type - > type; -}; - -template -struct AllOfResult4 { - typedef BothOfMatcher< - typename AllOfResult2::type, - typename AllOfResult2::type - > type; -}; - -template -struct AllOfResult5 { - typedef BothOfMatcher< - typename AllOfResult2::type, - typename AllOfResult3::type - > type; -}; - -template -struct AllOfResult6 { - typedef BothOfMatcher< - typename AllOfResult3::type, - typename AllOfResult3::type - > type; -}; - -template -struct AllOfResult7 { - typedef BothOfMatcher< - typename AllOfResult3::type, - typename AllOfResult4::type - > type; -}; - -template -struct AllOfResult8 { - typedef BothOfMatcher< - typename AllOfResult4::type, - typename AllOfResult4::type - > type; -}; - -template -struct AllOfResult9 { - typedef BothOfMatcher< - typename AllOfResult4::type, - typename AllOfResult5::type - > type; -}; - -template -struct AllOfResult10 { - typedef BothOfMatcher< - typename AllOfResult5::type, - typename AllOfResult5::type - > type; -}; - // A set of metafunctions for computing the result type of AnyOf. // AnyOf(m1, ..., mN) returns // AnyOfResultN::type. @@ -553,88 +465,6 @@ Args(const InnerMatcher& matcher) { k9, k10>(matcher); } -// AllOf(m1, m2, ..., mk) matches any value that matches all of the given -// sub-matchers. AllOf is called fully qualified to prevent ADL from firing. - -template -inline typename internal::AllOfResult2::type -AllOf(M1 m1, M2 m2) { - return typename internal::AllOfResult2::type( - m1, - m2); -} - -template -inline typename internal::AllOfResult3::type -AllOf(M1 m1, M2 m2, M3 m3) { - return typename internal::AllOfResult3::type( - m1, - ::testing::AllOf(m2, m3)); -} - -template -inline typename internal::AllOfResult4::type -AllOf(M1 m1, M2 m2, M3 m3, M4 m4) { - return typename internal::AllOfResult4::type( - ::testing::AllOf(m1, m2), - ::testing::AllOf(m3, m4)); -} - -template -inline typename internal::AllOfResult5::type -AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) { - return typename internal::AllOfResult5::type( - ::testing::AllOf(m1, m2), - ::testing::AllOf(m3, m4, m5)); -} - -template -inline typename internal::AllOfResult6::type -AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) { - return typename internal::AllOfResult6::type( - ::testing::AllOf(m1, m2, m3), - ::testing::AllOf(m4, m5, m6)); -} - -template -inline typename internal::AllOfResult7::type -AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) { - return typename internal::AllOfResult7::type( - ::testing::AllOf(m1, m2, m3), - ::testing::AllOf(m4, m5, m6, m7)); -} - -template -inline typename internal::AllOfResult8::type -AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) { - return typename internal::AllOfResult8::type( - ::testing::AllOf(m1, m2, m3, m4), - ::testing::AllOf(m5, m6, m7, m8)); -} - -template -inline typename internal::AllOfResult9::type -AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) { - return typename internal::AllOfResult9::type( - ::testing::AllOf(m1, m2, m3, m4), - ::testing::AllOf(m5, m6, m7, m8, m9)); -} - -template -inline typename internal::AllOfResult10::type -AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { - return typename internal::AllOfResult10::type( - ::testing::AllOf(m1, m2, m3, m4, m5), - ::testing::AllOf(m6, m7, m8, m9, m10)); -} // AnyOf(m1, m2, ..., mk) matches any value that matches any of the given // sub-matchers. AnyOf is called fully qualified to prevent ADL from firing. diff --git a/googlemock/include/gmock/gmock-generated-matchers.h.pump b/googlemock/include/gmock/gmock-generated-matchers.h.pump index e1f2f838..ad02ea7f 100644 --- a/googlemock/include/gmock/gmock-generated-matchers.h.pump +++ b/googlemock/include/gmock/gmock-generated-matchers.h.pump @@ -187,36 +187,6 @@ class ArgsMatcher { GTEST_DISALLOW_ASSIGN_(ArgsMatcher); }; -// A set of metafunctions for computing the result type of AllOf. -// AllOf(m1, ..., mN) returns -// AllOfResultN::type. - -// Although AllOf isn't defined for one argument, AllOfResult1 is defined -// to simplify the implementation. -template -struct AllOfResult1 { - typedef M1 type; -}; - -$range i 1..n - -$range i 2..n -$for i [[ -$range j 2..i -$var m = i/2 -$range k 1..m -$range t m+1..i - -template -struct AllOfResult$i { - typedef BothOfMatcher< - typename AllOfResult$m<$for k, [[M$k]]>::type, - typename AllOfResult$(i-m)<$for t, [[M$t]]>::type - > type; -}; - -]] - // A set of metafunctions for computing the result type of AnyOf. // AnyOf(m1, ..., mN) returns // AnyOfResultN::type. @@ -263,26 +233,6 @@ Args(const InnerMatcher& matcher) { } -]] - -// AllOf(m1, m2, ..., mk) matches any value that matches all of the given -// sub-matchers. AllOf is called fully qualified to prevent ADL from firing. - -$range i 2..n -$for i [[ -$range j 1..i -$var m = i/2 -$range k 1..m -$range t m+1..i - -template <$for j, [[typename M$j]]> -inline typename internal::AllOfResult$i<$for j, [[M$j]]>::type -AllOf($for j, [[M$j m$j]]) { - return typename internal::AllOfResult$i<$for j, [[M$j]]>::type( - $if m == 1 [[m1]] $else [[::testing::AllOf($for k, [[m$k]])]], - $if m+1 == i [[m$i]] $else [[::testing::AllOf($for t, [[m$t]])]]); -} - ]] // AnyOf(m1, m2, ..., mk) matches any value that matches any of the given diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 0f7745ea..9772f15b 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -1772,7 +1772,6 @@ class AllOfMatcherImpl GTEST_DISALLOW_ASSIGN_(AllOfMatcherImpl); }; -#if GTEST_LANG_CXX11 // VariadicMatcher is used for the variadic implementation of // AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...). // CombiningMatcher is used to recursively combine the provided matchers @@ -1816,8 +1815,6 @@ class VariadicMatcher { template using AllOfMatcher = VariadicMatcher; -#endif // GTEST_LANG_CXX11 - // Used for implementing the AllOf(m_1, ..., m_n) matcher, which // matches a value that matches all of the matchers m_1, ..., and m_n. template @@ -5185,9 +5182,7 @@ UnorderedElementsAre(const Args&... matchers) { make_tuple(matchers...)); } -#if GTEST_LANG_CXX11 -// Define variadic matcher versions. They are overloaded in -// gmock-generated-matchers.h for the cases supported by pre C++11 compilers. +// Define variadic matcher versions. template internal::AllOfMatcher::type...> AllOf( const Args&... matchers) { @@ -5202,8 +5197,6 @@ internal::AnyOfMatcher::type...> AnyOf( matchers...); } -#endif // GTEST_LANG_CXX11 - // AllArgs(m) is a synonym of m. This is useful in // // EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq())); diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index ceff5b08..c38be994 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2555,27 +2555,6 @@ TEST(AllOfTest, MatchesWhenAllMatch) { Ne(9), Ne(10))); } -#if GTEST_LANG_CXX11 -// Tests the variadic version of the AllOfMatcher. -TEST(AllOfTest, VariadicMatchesWhenAllMatch) { - // Make sure AllOf is defined in the right namespace and does not depend on - // ADL. - ::testing::AllOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); - Matcher m = AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), - Ne(9), Ne(10), Ne(11)); - EXPECT_THAT(Describe(m), EndsWith("and (isn't equal to 11)")); - AllOfMatches(11, m); - AllOfMatches(50, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), - Ne(9), Ne(10), Ne(11), Ne(12), Ne(13), Ne(14), Ne(15), - Ne(16), Ne(17), Ne(18), Ne(19), Ne(20), Ne(21), Ne(22), - Ne(23), Ne(24), Ne(25), Ne(26), Ne(27), Ne(28), Ne(29), - Ne(30), Ne(31), Ne(32), Ne(33), Ne(34), Ne(35), Ne(36), - Ne(37), Ne(38), Ne(39), Ne(40), Ne(41), Ne(42), Ne(43), - Ne(44), Ne(45), Ne(46), Ne(47), Ne(48), Ne(49), - Ne(50))); -} - -#endif // GTEST_LANG_CXX11 // Tests that AllOf(m1, ..., mn) describes itself properly. TEST(AllOfTest, CanDescribeSelf) { @@ -2584,59 +2563,59 @@ TEST(AllOfTest, CanDescribeSelf) { EXPECT_EQ("(is <= 2) and (is >= 1)", Describe(m)); m = AllOf(Gt(0), Ne(1), Ne(2)); - EXPECT_EQ("(is > 0) and " - "((isn't equal to 1) and " - "(isn't equal to 2))", - Describe(m)); - + std::string expected_descr1 = + "(is > 0) and (isn't equal to 1) and (isn't equal to 2)"; + EXPECT_EQ(expected_descr1, Describe(m)); m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3)); - EXPECT_EQ("((is > 0) and " - "(isn't equal to 1)) and " - "((isn't equal to 2) and " - "(isn't equal to 3))", - Describe(m)); - + std::string expected_descr2 = + "(is > 0) and (isn't equal to 1) and (isn't equal to 2) and (isn't equal " + "to 3)"; + EXPECT_EQ(expected_descr2, Describe(m)); m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7)); - EXPECT_EQ("((is >= 0) and " - "(is < 10)) and " - "((isn't equal to 3) and " - "((isn't equal to 5) and " - "(isn't equal to 7)))", - Describe(m)); + std::string expected_descr3 = + "(is >= 0) and (is < 10) and (isn't equal to 3) and (isn't equal to 5) " + "and (isn't equal to 7)"; + EXPECT_EQ(expected_descr3, Describe(m)); } // Tests that AllOf(m1, ..., mn) describes its negation properly. TEST(AllOfTest, CanDescribeNegation) { Matcher m; m = AllOf(Le(2), Ge(1)); - EXPECT_EQ("(isn't <= 2) or " - "(isn't >= 1)", - DescribeNegation(m)); + std::string expected_descr4 = "(isn't <= 2) or (isn't >= 1)"; + EXPECT_EQ(expected_descr4, DescribeNegation(m)); m = AllOf(Gt(0), Ne(1), Ne(2)); - EXPECT_EQ("(isn't > 0) or " - "((is equal to 1) or " - "(is equal to 2))", - DescribeNegation(m)); - + std::string expected_descr5 = + "(isn't > 0) or (is equal to 1) or (is equal to 2)"; + EXPECT_EQ(expected_descr5, DescribeNegation(m)); m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3)); - EXPECT_EQ("((isn't > 0) or " - "(is equal to 1)) or " - "((is equal to 2) or " - "(is equal to 3))", - DescribeNegation(m)); - + std::string expected_descr6 = + "(isn't > 0) or (is equal to 1) or (is equal to 2) or (is equal to 3)"; + EXPECT_EQ(expected_descr6, DescribeNegation(m)); m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7)); - EXPECT_EQ("((isn't >= 0) or " - "(isn't < 10)) or " - "((is equal to 3) or " - "((is equal to 5) or " - "(is equal to 7)))", - DescribeNegation(m)); + std::string expected_desr7 = + "(isn't >= 0) or (isn't < 10) or (is equal to 3) or (is equal to 5) or " + "(is equal to 7)"; + EXPECT_EQ(expected_desr7, DescribeNegation(m)); + + m = AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9), + Ne(10), Ne(11)); + AllOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); + EXPECT_THAT(Describe(m), EndsWith("and (isn't equal to 11)")); + AllOfMatches(11, m); + AllOfMatches( + 50, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9), + Ne(10), Ne(11), Ne(12), Ne(13), Ne(14), Ne(15), Ne(16), Ne(17), + Ne(18), Ne(19), Ne(20), Ne(21), Ne(22), Ne(23), Ne(24), Ne(25), + Ne(26), Ne(27), Ne(28), Ne(29), Ne(30), Ne(31), Ne(32), Ne(33), + Ne(34), Ne(35), Ne(36), Ne(37), Ne(38), Ne(39), Ne(40), Ne(41), + Ne(42), Ne(43), Ne(44), Ne(45), Ne(46), Ne(47), Ne(48), Ne(49), + Ne(50))); } // Tests that monomorphic matchers are safely cast by the AllOf matcher. From 27c86f29417e53a622a2902baab2d1d82dafc5f9 Mon Sep 17 00:00:00 2001 From: misterg Date: Mon, 8 Oct 2018 10:42:22 -0400 Subject: [PATCH 2/4] always define define GTEST_LANG_CXX11 1 PiperOrigin-RevId: 216184859 --- googletest/include/gtest/internal/gtest-port.h | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 899fa5bc..ad56d079 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -343,18 +343,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() #endif -#ifndef GTEST_LANG_CXX11 -// gcc and clang define __GXX_EXPERIMENTAL_CXX0X__ when -// -std={c,gnu}++{0x,11} is passed. The C++11 standard specifies a -// value for __cplusplus, and recent versions of clang, gcc, and -// probably other compilers set that too in C++11 mode. -# if __GXX_EXPERIMENTAL_CXX0X__ || __cplusplus >= 201103L || _MSC_VER >= 1900 -// Compiling in at least C++11 mode. -# define GTEST_LANG_CXX11 1 -# else -# define GTEST_LANG_CXX11 0 -# endif -#endif +#define GTEST_LANG_CXX11 1 // Distinct from C++11 language support, some environments don't provide // proper C++11 library support. Notably, it's possible to build in From 4ac07de8de545c8e907d3de273228de814f9c999 Mon Sep 17 00:00:00 2001 From: misterg Date: Mon, 8 Oct 2018 11:56:57 -0400 Subject: [PATCH 3/4] Fixing AllOfMatches test, where it properly belongs PiperOrigin-RevId: 216193701 --- googlemock/test/gmock-matchers_test.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index c38be994..6d432340 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2553,6 +2553,14 @@ TEST(AllOfTest, MatchesWhenAllMatch) { Ne(8), Ne(9))); AllOfMatches(10, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9), Ne(10))); + AllOfMatches( + 50, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9), + Ne(10), Ne(11), Ne(12), Ne(13), Ne(14), Ne(15), Ne(16), Ne(17), + Ne(18), Ne(19), Ne(20), Ne(21), Ne(22), Ne(23), Ne(24), Ne(25), + Ne(26), Ne(27), Ne(28), Ne(29), Ne(30), Ne(31), Ne(32), Ne(33), + Ne(34), Ne(35), Ne(36), Ne(37), Ne(38), Ne(39), Ne(40), Ne(41), + Ne(42), Ne(43), Ne(44), Ne(45), Ne(46), Ne(47), Ne(48), Ne(49), + Ne(50))); } @@ -2608,14 +2616,6 @@ TEST(AllOfTest, CanDescribeNegation) { AllOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); EXPECT_THAT(Describe(m), EndsWith("and (isn't equal to 11)")); AllOfMatches(11, m); - AllOfMatches( - 50, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9), - Ne(10), Ne(11), Ne(12), Ne(13), Ne(14), Ne(15), Ne(16), Ne(17), - Ne(18), Ne(19), Ne(20), Ne(21), Ne(22), Ne(23), Ne(24), Ne(25), - Ne(26), Ne(27), Ne(28), Ne(29), Ne(30), Ne(31), Ne(32), Ne(33), - Ne(34), Ne(35), Ne(36), Ne(37), Ne(38), Ne(39), Ne(40), Ne(41), - Ne(42), Ne(43), Ne(44), Ne(45), Ne(46), Ne(47), Ne(48), Ne(49), - Ne(50))); } // Tests that monomorphic matchers are safely cast by the AllOf matcher. From a31d6f9057f65b86eee45bf0fc9eeab91a097f58 Mon Sep 17 00:00:00 2001 From: Eisoku Kuroiwa Date: Mon, 8 Oct 2018 16:59:24 -0400 Subject: [PATCH 4/4] Merge c1170881039e859738c62b02a918116fc6d346bc into 27c86f29417e53a622a2902baab2d1d82dafc5f9 Closes #1888 PiperOrigin-RevId: 216244924 --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d7732116..572dac00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 2.8.8) +add_definitions(-std=c++11) if (POLICY CMP0048) cmake_policy(SET CMP0048 NEW)