--suppress on line 0 (#1354)

Fixed --suppress on line 0
This commit is contained in:
shikamu 2018-09-18 12:58:14 +02:00 committed by PKEuS
parent b16eb32df6
commit 83cb0b3394
5 changed files with 18 additions and 10 deletions

View File

@ -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();

View File

@ -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) << '\"';

View File

@ -98,7 +98,7 @@ public:
std::string symbolName;
bool matched;
static const int NO_LINE = 0;
enum { NO_LINE = -1 };
};
/**

View File

@ -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());

View File

@ -22,6 +22,7 @@
#include "suppressions.h"
#include "testsuite.h"
#include "threadexecutor.h"
#include "path.h"
#include <cstddef>
#include <list>
@ -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;