testsuite: show diffing strings better when they are not equal

This commit is contained in:
Daniel Marjamäki 2008-12-04 19:31:30 +00:00
parent e9a533fb32
commit c6ed868009
1 changed files with 22 additions and 2 deletions

View File

@ -76,6 +76,26 @@ bool TestFixture::runTest(const char testname[])
std::cout << classname << "::" << testname << "\n";
return true;
}
static std::string writestr( const std::string &str )
{
std::ostringstream ostr;
ostr << "\"";
for (unsigned int i = 0; i < str.length(); ++i)
{
char ch = str[i];
if ( ch == '\n' )
ostr << "\\n";
else if ( ch == '\t' )
ostr << "\\t";
else if ( ch == '\"' )
ostr << "\\\"";
else
ostr << std::string(1, ch);
}
ostr << "\"";
return ostr.str();
}
void TestFixture::assertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual)
{
@ -83,9 +103,9 @@ void TestFixture::assertEquals(const char *filename, int linenr, const std::stri
{
errmsg << "Assertion failed in " << filename << " at line " << linenr << std::endl
<< "Expected:" << std::endl
<< expected << std::endl
<< writestr(expected) << std::endl
<< "Actual:" << std::endl
<< actual << std::endl;
<< writestr(actual) << std::endl;
}
}