From 9b307cf8e082a3d472e9606a2af84f3a27e62a04 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 27 Mar 2014 16:06:30 +0100 Subject: [PATCH] Improved readability of testsuite output when ASSERT_EQUALS_MSG fails. Fixed another true positive in checkbufferoverrun.cpp AStyle --- lib/checkbufferoverrun.cpp | 2 +- test/testsuite.cpp | 10 ++++++---- test/testtokenize.cpp | 17 ++++++++--------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index b12a4d21e..8387b3486 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1423,7 +1423,7 @@ bool CheckBufferOverrun::isArrayOfStruct(const Token* tok, int &position) void CheckBufferOverrun::checkReadlinkBufferUsage(const Token* ftok, const Token *scope_begin, const unsigned int varid, const MathLib::bigint total_size) { - const std::string funcname = ftok->str(); + const std::string& funcname = ftok->str(); const Token* bufParam = ftok->tokAt(2)->nextArgument(); if (funcname == "readlinkat") diff --git a/test/testsuite.cpp b/test/testsuite.cpp index 72f6199d1..4840730c0 100644 --- a/test/testsuite.cpp +++ b/test/testsuite.cpp @@ -135,15 +135,17 @@ void TestFixture::assertEquals(const char *filename, unsigned int linenr, const << writestr(actual, true) << '.' << std::endl; + if (!msg.empty()) + errmsg << msg << std::endl; } else { errmsg << "Assertion failed in " << filename << " at line " << linenr << std::endl << "Expected:" << std::endl << writestr(expected) << std::endl << "Actual:" << std::endl - << writestr(actual) << std::endl << "_____" << std::endl; - } - if (!msg.empty()) { - errmsg << msg << std::endl; + << writestr(actual) << std::endl; + if (!msg.empty()) + errmsg << "Hint:" << std::endl << msg << std::endl; + errmsg << "_____" << std::endl; } } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 48859b5c9..2a4196cf8 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -891,15 +891,14 @@ private: " )\n" "}"; - try { - tokenizeAndStringify(code); - assertThrowFail(__FILE__, __LINE__); - } - catch (InternalError& e) { - ASSERT_EQUALS("Analysis failed. If the code is valid then please report this failure.", e.errorMessage); - ASSERT_EQUALS("cppcheckError", e.id); - ASSERT_EQUALS(5, e.token->linenr()); - } + try { + tokenizeAndStringify(code); + assertThrowFail(__FILE__, __LINE__); + } catch (InternalError& e) { + ASSERT_EQUALS("Analysis failed. If the code is valid then please report this failure.", e.errorMessage); + ASSERT_EQUALS("cppcheckError", e.id); + ASSERT_EQUALS(5, e.token->linenr()); + } } void wrong_syntax4() { // #3618