From c6ed8680096293a994476660b746e7db14bc7d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 4 Dec 2008 19:31:30 +0000 Subject: [PATCH] testsuite: show diffing strings better when they are not equal --- testsuite.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/testsuite.cpp b/testsuite.cpp index b37532c78..06e096b59 100644 --- a/testsuite.cpp +++ b/testsuite.cpp @@ -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; } }