diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2012-06-07 20:34:34 +0000 |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2012-06-07 20:34:34 +0000 |
commit | a88c9a88e49e90ec414175543b2b7ff2f70866a7 (patch) | |
tree | 617807532cbbd68ce8e684a570791231b1b9cd92 /src/gtest.cc | |
parent | a3b859162dd7a4a1798cf8753a03098f2cbdb62e (diff) | |
download | googletest-a88c9a88e49e90ec414175543b2b7ff2f70866a7.tar.gz googletest-a88c9a88e49e90ec414175543b2b7ff2f70866a7.tar.bz2 googletest-a88c9a88e49e90ec414175543b2b7ff2f70866a7.zip |
Improves gtest's failure messages. In particulars, char pointers and
char arrays are not escapped properly.
Diffstat (limited to 'src/gtest.cc')
-rw-r--r-- | src/gtest.cc | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/src/gtest.cc b/src/gtest.cc index 78f113e2..35e1dbdf 100644 --- a/src/gtest.cc +++ b/src/gtest.cc @@ -818,17 +818,6 @@ TimeInMillis GetTimeInMillis() { // class String -// Returns the input enclosed in double quotes if it's not NULL; -// otherwise returns "(null)". For example, "\"Hello\"" is returned -// for input "Hello". -// -// This is useful for printing a C string in the syntax of a literal. -// -// Known issue: escape sequences are not handled yet. -String String::ShowCStringQuoted(const char* c_str) { - return c_str ? String::Format("\"%s\"", c_str) : String("(null)"); -} - // Copies at most length characters from str into a newly-allocated // piece of memory of size length+1. The memory is allocated with new[]. // A terminating null byte is written to the memory, and a pointer to it @@ -1169,8 +1158,8 @@ AssertionResult CmpHelperSTREQ(const char* expected_expression, return EqFailure(expected_expression, actual_expression, - String::ShowCStringQuoted(expected), - String::ShowCStringQuoted(actual), + PrintToString(expected), + PrintToString(actual), false); } @@ -1185,8 +1174,8 @@ AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression, return EqFailure(expected_expression, actual_expression, - String::ShowCStringQuoted(expected), - String::ShowCStringQuoted(actual), + PrintToString(expected), + PrintToString(actual), true); } @@ -1534,15 +1523,6 @@ String String::ShowWideCString(const wchar_t * wide_c_str) { return String(internal::WideStringToUtf8(wide_c_str, -1).c_str()); } -// Similar to ShowWideCString(), except that this function encloses -// the converted string in double quotes. -String String::ShowWideCStringQuoted(const wchar_t* wide_c_str) { - if (wide_c_str == NULL) return String("(null)"); - - return String::Format("L\"%s\"", - String::ShowWideCString(wide_c_str).c_str()); -} - // Compares two wide C strings. Returns true iff they have the same // content. // @@ -1568,8 +1548,8 @@ AssertionResult CmpHelperSTREQ(const char* expected_expression, return EqFailure(expected_expression, actual_expression, - String::ShowWideCStringQuoted(expected), - String::ShowWideCStringQuoted(actual), + PrintToString(expected), + PrintToString(actual), false); } @@ -1584,8 +1564,8 @@ AssertionResult CmpHelperSTRNE(const char* s1_expression, return AssertionFailure() << "Expected: (" << s1_expression << ") != (" << s2_expression << "), actual: " - << String::ShowWideCStringQuoted(s1) - << " vs " << String::ShowWideCStringQuoted(s2); + << PrintToString(s1) + << " vs " << PrintToString(s2); } // Compares two C strings, ignoring case. Returns true iff they have |