summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-09-27 22:09:42 (GMT)
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-09-27 22:09:42 (GMT)
commit2d1835b086e69570e4c3e0ad6197da509bd0a957 (patch)
tree1732afebaad166ad92ad2f0a12ed3327b891e626
parentb5d3a17805fe0ed2ccde463412ae1fd206c4df21 (diff)
downloadgoogletest-2d1835b086e69570e4c3e0ad6197da509bd0a957.zip
googletest-2d1835b086e69570e4c3e0ad6197da509bd0a957.tar.gz
googletest-2d1835b086e69570e4c3e0ad6197da509bd0a957.tar.bz2
Removes uses of deprecated AssertionFailure() API (by Vlad Losev).
-rw-r--r--include/gtest/gtest.h5
-rw-r--r--include/gtest/gtest_pred_impl.h82
-rwxr-xr-xscripts/gen_gtest_pred_impl.py13
-rw-r--r--src/gtest.cc70
-rw-r--r--test/gtest_pred_impl_unittest.cc27
5 files changed, 82 insertions, 115 deletions
diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h
index 71eccac..c725e4c 100644
--- a/include/gtest/gtest.h
+++ b/include/gtest/gtest.h
@@ -1385,11 +1385,10 @@ AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
if (val1 op val2) {\
return AssertionSuccess();\
} else {\
- Message msg;\
- msg << "Expected: (" << expr1 << ") " #op " (" << expr2\
+ return AssertionFailure() \
+ << "Expected: (" << expr1 << ") " #op " (" << expr2\
<< "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
<< " vs " << FormatForComparisonFailureMessage(val2, val1);\
- return AssertionFailure(msg);\
}\
}\
GTEST_API_ AssertionResult CmpHelper##op_name(\
diff --git a/include/gtest/gtest_pred_impl.h b/include/gtest/gtest_pred_impl.h
index e1e2f8c..d33f5d5 100644
--- a/include/gtest/gtest_pred_impl.h
+++ b/include/gtest/gtest_pred_impl.h
@@ -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 10/02/2008 by command
+// This file is AUTOMATICALLY GENERATED on 09/24/2010 by command
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
//
// Implements a family of generic predicate assertion macros.
@@ -90,11 +90,9 @@ AssertionResult AssertPred1Helper(const char* pred_text,
const T1& v1) {
if (pred(v1)) return AssertionSuccess();
- Message msg;
- msg << pred_text << "("
- << e1 << ") evaluates to false, where"
- << "\n" << e1 << " evaluates to " << v1;
- return AssertionFailure(msg);
+ return AssertionFailure() << pred_text << "("
+ << e1 << ") evaluates to false, where"
+ << "\n" << e1 << " evaluates to " << v1;
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
@@ -136,13 +134,11 @@ AssertionResult AssertPred2Helper(const char* pred_text,
const T2& v2) {
if (pred(v1, v2)) return AssertionSuccess();
- Message msg;
- msg << pred_text << "("
- << e1 << ", "
- << e2 << ") evaluates to false, where"
- << "\n" << e1 << " evaluates to " << v1
- << "\n" << e2 << " evaluates to " << v2;
- return AssertionFailure(msg);
+ return AssertionFailure() << pred_text << "("
+ << e1 << ", "
+ << e2 << ") evaluates to false, where"
+ << "\n" << e1 << " evaluates to " << v1
+ << "\n" << e2 << " evaluates to " << v2;
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
@@ -189,15 +185,13 @@ AssertionResult AssertPred3Helper(const char* pred_text,
const T3& v3) {
if (pred(v1, v2, v3)) return AssertionSuccess();
- Message msg;
- msg << 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(msg);
+ 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;
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
@@ -249,17 +243,15 @@ AssertionResult AssertPred4Helper(const char* pred_text,
const T4& v4) {
if (pred(v1, v2, v3, v4)) return AssertionSuccess();
- Message msg;
- msg << 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(msg);
+ 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;
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
@@ -316,19 +308,17 @@ AssertionResult AssertPred5Helper(const char* pred_text,
const T5& v5) {
if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
- Message msg;
- msg << 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(msg);
+ 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;
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
diff --git a/scripts/gen_gtest_pred_impl.py b/scripts/gen_gtest_pred_impl.py
index 39bb6cf..d35b4f0 100755
--- a/scripts/gen_gtest_pred_impl.py
+++ b/scripts/gen_gtest_pred_impl.py
@@ -238,21 +238,19 @@ AssertionResult AssertPred%(n)sHelper(const char* pred_text""" % DEFS
impl += """) {
if (pred(%(vs)s)) return AssertionSuccess();
- Message msg;
""" % DEFS
- impl += ' msg << pred_text << "("'
+ impl += ' return AssertionFailure() << pred_text << "("'
impl += Iter(n, """
- << e%s""", sep=' << ", "')
+ << e%s""", sep=' << ", "')
impl += ' << ") evaluates to false, where"'
impl += Iter(n, """
- << "\\n" << e%s << " evaluates to " << v%s""")
+ << "\\n" << e%s << " evaluates to " << v%s""")
impl += """;
- return AssertionFailure(msg);
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT%(n)s.
@@ -478,15 +476,14 @@ testing::AssertionResult PredFormatFunction%(n)s(""" % DEFS
if (PredFunction%(n)s(%(vs)s))
return testing::AssertionSuccess();
- testing::Message msg;
- msg << """ % DEFS
+ return testing::AssertionFailure()
+ << """ % DEFS
tests += Iter(n, 'e%s', sep=' << " + " << ')
tests += """
<< " is expected to be positive, but evaluates to "
<< %(v_sum)s << ".";
- return testing::AssertionFailure(msg);
}
""" % DEFS
diff --git a/src/gtest.cc b/src/gtest.cc
index 3b2238f..0d41e46 100644
--- a/src/gtest.cc
+++ b/src/gtest.cc
@@ -618,23 +618,21 @@ AssertionResult HasOneFailure(const char* /* results_expr */,
for (int i = 0; i < results.size(); i++) {
msg << "\n" << results.GetTestPartResult(i);
}
- return AssertionFailure(msg);
+ return AssertionFailure() << msg;
}
const TestPartResult& r = results.GetTestPartResult(0);
if (r.type() != type) {
- msg << "Expected: " << expected << "\n"
- << " Actual:\n"
- << r;
- return AssertionFailure(msg);
+ return AssertionFailure() << "Expected: " << expected << "\n"
+ << " Actual:\n"
+ << r;
}
if (strstr(r.message(), substr.c_str()) == NULL) {
- msg << "Expected: " << expected << " containing \""
- << substr << "\"\n"
- << " Actual:\n"
- << r;
- return AssertionFailure(msg);
+ return AssertionFailure() << "Expected: " << expected << " containing \""
+ << substr << "\"\n"
+ << " Actual:\n"
+ << r;
}
return AssertionSuccess();
@@ -1011,7 +1009,7 @@ AssertionResult EqFailure(const char* expected_expression,
msg << "\nWhich is: " << expected_value;
}
- return AssertionFailure(msg);
+ return AssertionFailure() << msg;
}
// Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
@@ -1041,13 +1039,12 @@ AssertionResult DoubleNearPredFormat(const char* expr1,
// TODO(wan): do not print the value of an expression if it's
// already a literal.
- Message msg;
- msg << "The difference between " << expr1 << " and " << expr2
+ return AssertionFailure()
+ << "The difference between " << expr1 << " and " << expr2
<< " is " << diff << ", which exceeds " << abs_error_expr << ", where\n"
<< expr1 << " evaluates to " << val1 << ",\n"
<< expr2 << " evaluates to " << val2 << ", and\n"
<< abs_error_expr << " evaluates to " << abs_error << ".";
- return AssertionFailure(msg);
}
@@ -1080,12 +1077,10 @@ AssertionResult FloatingPointLE(const char* expr1,
val2_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
<< val2;
- Message msg;
- msg << "Expected: (" << expr1 << ") <= (" << expr2 << ")\n"
+ return AssertionFailure()
+ << "Expected: (" << expr1 << ") <= (" << expr2 << ")\n"
<< " Actual: " << StringStreamToString(&val1_ss) << " vs "
<< StringStreamToString(&val2_ss);
-
- return AssertionFailure(msg);
}
} // namespace internal
@@ -1132,11 +1127,10 @@ AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
if (val1 op val2) {\
return AssertionSuccess();\
} else {\
- Message msg;\
- msg << "Expected: (" << expr1 << ") " #op " (" << expr2\
+ return AssertionFailure() \
+ << "Expected: (" << expr1 << ") " #op " (" << expr2\
<< "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
<< " vs " << FormatForComparisonFailureMessage(val2, val1);\
- return AssertionFailure(msg);\
}\
}
@@ -1198,11 +1192,9 @@ AssertionResult CmpHelperSTRNE(const char* s1_expression,
if (!String::CStringEquals(s1, s2)) {
return AssertionSuccess();
} else {
- Message msg;
- msg << "Expected: (" << s1_expression << ") != ("
- << s2_expression << "), actual: \""
- << s1 << "\" vs \"" << s2 << "\"";
- return AssertionFailure(msg);
+ return AssertionFailure() << "Expected: (" << s1_expression << ") != ("
+ << s2_expression << "), actual: \""
+ << s1 << "\" vs \"" << s2 << "\"";
}
}
@@ -1214,11 +1206,10 @@ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
if (!String::CaseInsensitiveCStringEquals(s1, s2)) {
return AssertionSuccess();
} else {
- Message msg;
- msg << "Expected: (" << s1_expression << ") != ("
+ return AssertionFailure()
+ << "Expected: (" << s1_expression << ") != ("
<< s2_expression << ") (ignoring case), actual: \""
<< s1 << "\" vs \"" << s2 << "\"";
- return AssertionFailure(msg);
}
}
@@ -1267,13 +1258,12 @@ AssertionResult IsSubstringImpl(
const bool is_wide_string = sizeof(needle[0]) > 1;
const char* const begin_string_quote = is_wide_string ? "L\"" : "\"";
- return AssertionFailure(
- Message()
+ return AssertionFailure()
<< "Value of: " << needle_expr << "\n"
<< " Actual: " << begin_string_quote << needle << "\"\n"
<< "Expected: " << (expected_to_be_substring ? "" : "not ")
<< "a substring of " << haystack_expr << "\n"
- << "Which is: " << begin_string_quote << haystack << "\"");
+ << "Which is: " << begin_string_quote << haystack << "\"";
}
} // namespace
@@ -1369,11 +1359,9 @@ AssertionResult HRESULTFailureHelper(const char* expr,
#endif // GTEST_OS_WINDOWS_MOBILE
const String error_hex(String::Format("0x%08X ", hr));
- Message msg;
- msg << "Expected: " << expr << " " << expected << ".\n"
+ return ::testing::AssertionFailure()
+ << "Expected: " << expr << " " << expected << ".\n"
<< " Actual: " << error_hex << error_text << "\n";
-
- return ::testing::AssertionFailure(msg);
}
} // namespace
@@ -1584,12 +1572,10 @@ AssertionResult CmpHelperSTRNE(const char* s1_expression,
return AssertionSuccess();
}
- Message msg;
- msg << "Expected: (" << s1_expression << ") != ("
- << s2_expression << "), actual: "
- << String::ShowWideCStringQuoted(s1)
- << " vs " << String::ShowWideCStringQuoted(s2);
- return AssertionFailure(msg);
+ return AssertionFailure() << "Expected: (" << s1_expression << ") != ("
+ << s2_expression << "), actual: "
+ << String::ShowWideCStringQuoted(s1)
+ << " vs " << String::ShowWideCStringQuoted(s2);
}
// Compares two C strings, ignoring case. Returns true iff they have
diff --git a/test/gtest_pred_impl_unittest.cc b/test/gtest_pred_impl_unittest.cc
index 66c75d1..35dc9bc 100644
--- a/test/gtest_pred_impl_unittest.cc
+++ b/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 10/02/2008 by command
+// This file is AUTOMATICALLY GENERATED on 09/24/2010 by command
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
// Regression test for gtest_pred_impl.h
@@ -103,11 +103,10 @@ testing::AssertionResult PredFormatFunction1(const char* e1,
if (PredFunction1(v1))
return testing::AssertionSuccess();
- testing::Message msg;
- msg << e1
+ return testing::AssertionFailure()
+ << e1
<< " is expected to be positive, but evaluates to "
<< v1 << ".";
- return testing::AssertionFailure(msg);
}
// A unary predicate-formatter functor.
@@ -494,11 +493,10 @@ testing::AssertionResult PredFormatFunction2(const char* e1,
if (PredFunction2(v1, v2))
return testing::AssertionSuccess();
- testing::Message msg;
- msg << e1 << " + " << e2
+ return testing::AssertionFailure()
+ << e1 << " + " << e2
<< " is expected to be positive, but evaluates to "
<< v1 + v2 << ".";
- return testing::AssertionFailure(msg);
}
// A binary predicate-formatter functor.
@@ -927,11 +925,10 @@ testing::AssertionResult PredFormatFunction3(const char* e1,
if (PredFunction3(v1, v2, v3))
return testing::AssertionSuccess();
- testing::Message msg;
- msg << e1 << " + " << e2 << " + " << e3
+ return testing::AssertionFailure()
+ << e1 << " + " << e2 << " + " << e3
<< " is expected to be positive, but evaluates to "
<< v1 + v2 + v3 << ".";
- return testing::AssertionFailure(msg);
}
// A ternary predicate-formatter functor.
@@ -1402,11 +1399,10 @@ testing::AssertionResult PredFormatFunction4(const char* e1,
if (PredFunction4(v1, v2, v3, v4))
return testing::AssertionSuccess();
- testing::Message msg;
- msg << e1 << " + " << e2 << " + " << e3 << " + " << e4
+ return testing::AssertionFailure()
+ << e1 << " + " << e2 << " + " << e3 << " + " << e4
<< " is expected to be positive, but evaluates to "
<< v1 + v2 + v3 + v4 << ".";
- return testing::AssertionFailure(msg);
}
// A 4-ary predicate-formatter functor.
@@ -1919,11 +1915,10 @@ testing::AssertionResult PredFormatFunction5(const char* e1,
if (PredFunction5(v1, v2, v3, v4, v5))
return testing::AssertionSuccess();
- testing::Message msg;
- msg << e1 << " + " << e2 << " + " << e3 << " + " << e4 << " + " << e5
+ return testing::AssertionFailure()
+ << e1 << " + " << e2 << " + " << e3 << " + " << e4 << " + " << e5
<< " is expected to be positive, but evaluates to "
<< v1 + v2 + v3 + v4 + v5 << ".";
- return testing::AssertionFailure(msg);
}
// A 5-ary predicate-formatter functor.