aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormisterg <misterg@google.com>2019-01-03 16:32:01 -0500
committerGennadiy Civil <misterg@google.com>2019-01-03 16:40:27 -0500
commit827515f8a092050901d4eb9fdc1ddbb972f38442 (patch)
tree8654380eab99fc4511cbd6892943dea4ef752f63
parent3a460a26b7a91abf87af7f31b93d29f930e25c82 (diff)
downloadgoogletest-827515f8a092050901d4eb9fdc1ddbb972f38442.tar.gz
Googletest export
Fixes #1261 PiperOrigin-RevId: 227740670
-rw-r--r--googletest/include/gtest/gtest_pred_impl.h74
-rw-r--r--googletest/test/gtest_pred_impl_unittest.cc2
-rw-r--r--googletest/test/gtest_unittest.cc10
3 files changed, 48 insertions, 38 deletions
diff --git a/googletest/include/gtest/gtest_pred_impl.h b/googletest/include/gtest/gtest_pred_impl.h
index 0c1105cb..d514255c 100644
--- a/googletest/include/gtest/gtest_pred_impl.h
+++ b/googletest/include/gtest/gtest_pred_impl.h
@@ -27,11 +27,10 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// This file is AUTOMATICALLY GENERATED on 01/02/2018 by command
+// This file is AUTOMATICALLY GENERATED on 01/02/2019 by command
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
//
// Implements a family of generic predicate assertion macros.
-
// GOOGLETEST_CM0001 DO NOT DELETE
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
@@ -67,6 +66,8 @@ namespace testing {
// We also define the EXPECT_* variations.
//
// For now we only support predicates whose arity is at most 5.
+// Please email googletestframework@googlegroups.com if you need
+// support for higher arities.
// GTEST_ASSERT_ is the basic statement to which all of the assertions
// in this file reduce. Don't use this in your code.
@@ -89,9 +90,10 @@ AssertionResult AssertPred1Helper(const char* pred_text,
const T1& v1) {
if (pred(v1)) return AssertionSuccess();
- return AssertionFailure() << pred_text << "("
- << e1 << ") evaluates to false, where"
- << "\n" << e1 << " evaluates to " << v1;
+ return AssertionFailure()
+ << pred_text << "(" << e1 << ") evaluates to false, where"
+ << "\n"
+ << e1 << " evaluates to " << ::testing::PrintToString(v1);
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
@@ -133,11 +135,12 @@ AssertionResult AssertPred2Helper(const char* pred_text,
const T2& v2) {
if (pred(v1, v2)) return AssertionSuccess();
- return AssertionFailure() << pred_text << "("
- << e1 << ", "
- << e2 << ") evaluates to false, where"
- << "\n" << e1 << " evaluates to " << v1
- << "\n" << e2 << " evaluates to " << v2;
+ return AssertionFailure()
+ << pred_text << "(" << e1 << ", " << e2
+ << ") evaluates to false, where"
+ << "\n"
+ << e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
+ << e2 << " evaluates to " << ::testing::PrintToString(v2);
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
@@ -184,13 +187,13 @@ AssertionResult AssertPred3Helper(const char* pred_text,
const T3& v3) {
if (pred(v1, v2, v3)) return AssertionSuccess();
- return AssertionFailure() << pred_text << "("
- << e1 << ", "
- << e2 << ", "
- << e3 << ") evaluates to false, where"
- << "\n" << e1 << " evaluates to " << v1
- << "\n" << e2 << " evaluates to " << v2
- << "\n" << e3 << " evaluates to " << v3;
+ return AssertionFailure()
+ << pred_text << "(" << e1 << ", " << e2 << ", " << e3
+ << ") evaluates to false, where"
+ << "\n"
+ << e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
+ << e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
+ << e3 << " evaluates to " << ::testing::PrintToString(v3);
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
@@ -242,15 +245,14 @@ AssertionResult AssertPred4Helper(const char* pred_text,
const T4& v4) {
if (pred(v1, v2, v3, v4)) return AssertionSuccess();
- return AssertionFailure() << pred_text << "("
- << e1 << ", "
- << e2 << ", "
- << e3 << ", "
- << e4 << ") evaluates to false, where"
- << "\n" << e1 << " evaluates to " << v1
- << "\n" << e2 << " evaluates to " << v2
- << "\n" << e3 << " evaluates to " << v3
- << "\n" << e4 << " evaluates to " << v4;
+ return AssertionFailure()
+ << pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", " << e4
+ << ") evaluates to false, where"
+ << "\n"
+ << e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
+ << e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
+ << e3 << " evaluates to " << ::testing::PrintToString(v3) << "\n"
+ << e4 << " evaluates to " << ::testing::PrintToString(v4);
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
@@ -307,17 +309,15 @@ AssertionResult AssertPred5Helper(const char* pred_text,
const T5& v5) {
if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
- return AssertionFailure() << pred_text << "("
- << e1 << ", "
- << e2 << ", "
- << e3 << ", "
- << e4 << ", "
- << e5 << ") evaluates to false, where"
- << "\n" << e1 << " evaluates to " << v1
- << "\n" << e2 << " evaluates to " << v2
- << "\n" << e3 << " evaluates to " << v3
- << "\n" << e4 << " evaluates to " << v4
- << "\n" << e5 << " evaluates to " << v5;
+ return AssertionFailure()
+ << pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", " << e4
+ << ", " << e5 << ") evaluates to false, where"
+ << "\n"
+ << e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
+ << e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
+ << e3 << " evaluates to " << ::testing::PrintToString(v3) << "\n"
+ << e4 << " evaluates to " << ::testing::PrintToString(v4) << "\n"
+ << e5 << " evaluates to " << ::testing::PrintToString(v5);
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
diff --git a/googletest/test/gtest_pred_impl_unittest.cc b/googletest/test/gtest_pred_impl_unittest.cc
index 2019a30c..049ef983 100644
--- a/googletest/test/gtest_pred_impl_unittest.cc
+++ b/googletest/test/gtest_pred_impl_unittest.cc
@@ -27,7 +27,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// This file is AUTOMATICALLY GENERATED on 01/02/2018 by command
+// This file is AUTOMATICALLY GENERATED on 01/02/2019 by command
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
// Regression test for gtest_pred_impl.h
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc
index 6c7d5519..5e0e43a4 100644
--- a/googletest/test/gtest_unittest.cc
+++ b/googletest/test/gtest_unittest.cc
@@ -2357,6 +2357,16 @@ TEST(PredTest, SingleEvaluationOnFailure) {
EXPECT_EQ(1, n4) << "Argument 4 is not evaluated exactly once.";
}
+// Test predicate assertions for sets
+TEST(PredTest, ExpectPredEvalFailure) {
+ std::set<int> set_a = {2, 1, 3, 4, 5};
+ std::set<int> set_b = {0, 4, 8};
+ const auto compare_sets = [] (std::set<int>, std::set<int>) { return false; };
+ EXPECT_NONFATAL_FAILURE(
+ EXPECT_PRED2(compare_sets, set_a, set_b),
+ "compare_sets(set_a, set_b) evaluates to false, where\nset_a evaluates "
+ "to { 1, 2, 3, 4, 5 }\nset_b evaluates to { 0, 4, 8 }");
+}
// Some helper functions for testing using overloaded/template
// functions with ASSERT_PREDn and EXPECT_PREDn.