From 83cb0b3394dea0e8f70ae216d128ccefc09731f6 Mon Sep 17 00:00:00 2001 From: shikamu Date: Tue, 18 Sep 2018 12:58:14 +0200 Subject: [PATCH] --suppress on line 0 (#1354) Fixed --suppress on line 0 --- lib/errorlogger.cpp | 2 +- lib/suppressions.cpp | 10 +++++----- lib/suppressions.h | 2 +- test/testerrorlogger.cpp | 6 +++--- test/testsuppressions.cpp | 8 ++++++++ 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index f9ff4f4a2..f57caa20e 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -611,7 +611,7 @@ std::string ErrorLogger::ErrorMessage::FileLocation::stringify() const { std::ostringstream oss; oss << '[' << Path::toNativeSeparators(mFileName); - if (line != 0) + if (line != Suppressions::Suppression::NO_LINE) oss << ':' << line; oss << ']'; return oss.str(); diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 589bef9b3..b57f97a51 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -144,10 +144,10 @@ std::string Suppressions::addSuppressionLine(const std::string &line) std::istringstream istr1(suppression.fileName.substr(pos+1)); istr1 >> suppression.lineNumber; } catch (...) { - suppression.lineNumber = 0; + suppression.lineNumber = Suppressions::Suppression::NO_LINE; } - if (suppression.lineNumber > 0) { + if (suppression.lineNumber > Suppressions::Suppression::NO_LINE) { suppression.fileName.erase(pos); } } @@ -233,7 +233,7 @@ bool Suppressions::Suppression::isSuppressed(const Suppressions::ErrorMessage &e return false; if (!fileName.empty() && !matchglob(fileName, errmsg.getFileName())) return false; - if (lineNumber > 0 && lineNumber != errmsg.lineNumber) + if (lineNumber > NO_LINE && lineNumber != errmsg.lineNumber) return false; if (!symbolName.empty()) { for (std::string::size_type pos = 0; pos < errmsg.symbolNames.size();) { @@ -269,7 +269,7 @@ std::string Suppressions::Suppression::getText() const ret = errorId; if (!fileName.empty()) ret += " fileName=" + fileName; - if (lineNumber > 0) + if (lineNumber > NO_LINE) ret += " lineNumber=" + MathLib::toString(lineNumber); if (!symbolName.empty()) ret += " symbolName=" + symbolName; @@ -312,7 +312,7 @@ void Suppressions::dump(std::ostream & out) out << " errorId=\"" << ErrorLogger::toxml(suppression.errorId) << '"'; if (!suppression.fileName.empty()) out << " fileName=\"" << ErrorLogger::toxml(suppression.fileName) << '"'; - if (suppression.lineNumber > 0) + if (suppression.lineNumber > Suppression::NO_LINE) out << " lineNumber=\"" << suppression.lineNumber << '"'; if (!suppression.symbolName.empty()) out << " symbolName=\"" << ErrorLogger::toxml(suppression.symbolName) << '\"'; diff --git a/lib/suppressions.h b/lib/suppressions.h index 623d1ed5b..f21832f8c 100644 --- a/lib/suppressions.h +++ b/lib/suppressions.h @@ -98,7 +98,7 @@ public: std::string symbolName; bool matched; - static const int NO_LINE = 0; + enum { NO_LINE = -1 }; }; /** diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index 32342351a..8dba23d78 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -301,7 +301,7 @@ private: errout.str(""); suppressions.clear(); suppressions.emplace_back("abc", "a.c", 10U); - suppressions.emplace_back("unmatchedSuppression", "*", 0U); + suppressions.emplace_back("unmatchedSuppression", "*", Suppressions::Suppression::NO_LINE); reportUnmatchedSuppressions(suppressions); ASSERT_EQUALS("", errout.str()); @@ -309,7 +309,7 @@ private: errout.str(""); suppressions.clear(); suppressions.emplace_back("abc", "a.c", 10U); - suppressions.emplace_back("unmatchedSuppression", "a.c", 0U); + suppressions.emplace_back("unmatchedSuppression", "a.c", Suppressions::Suppression::NO_LINE); reportUnmatchedSuppressions(suppressions); ASSERT_EQUALS("", errout.str()); @@ -325,7 +325,7 @@ private: errout.str(""); suppressions.clear(); suppressions.emplace_back("abc", "a.c", 10U); - suppressions.emplace_back("unmatchedSuppression", "b.c", 0U); + suppressions.emplace_back("unmatchedSuppression", "b.c", Suppressions::Suppression::NO_LINE); reportUnmatchedSuppressions(suppressions); ASSERT_EQUALS("[a.c:10]: (information) Unmatched suppression: abc\n", errout.str()); diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index 0280acf2f..7e9623c03 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -22,6 +22,7 @@ #include "suppressions.h" #include "testsuite.h" #include "threadexecutor.h" +#include "path.h" #include #include @@ -46,6 +47,7 @@ private: TEST_CASE(suppressionsSettings); TEST_CASE(suppressionsMultiFile); TEST_CASE(suppressionsPathSeparator); + TEST_CASE(suppressionsLine0); TEST_CASE(inlinesuppress); TEST_CASE(inlinesuppress_symbolname); @@ -403,6 +405,12 @@ private: ASSERT_EQUALS(true, s2.isSuppressed(errorMessage("abc", "include/1.h", 142))); } + void suppressionsLine0() { + Suppressions suppressions; + suppressions.addSuppressionLine("syntaxError:*:0"); + ASSERT_EQUALS(true, suppressions.isSuppressed(errorMessage("syntaxError", "test.cpp", 0))); + } + void inlinesuppress() { Suppressions::Suppression s; std::string msg;