Add support for comments at end of suppression in suppression files (#2736)

This commit is contained in:
eivindt 2020-08-20 21:49:07 +02:00 committed by GitHub
parent a332062385
commit 27e40af06c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 3 deletions

View File

@ -169,8 +169,20 @@ std::vector<Suppressions::Suppression> Suppressions::parseMultiSuppressComment(c
std::string Suppressions::addSuppressionLine(const std::string &line)
{
std::istringstream lineStream(line);
std::istringstream lineStream;
Suppressions::Suppression suppression;
// Strip any end of line comments
std::string::size_type endpos = std::min(line.find("#"), line.find("//"));
if (endpos != std::string::npos) {
while (endpos > 0 && std::isspace(line[endpos-1])) {
endpos--;
}
lineStream.str(line.substr(0, endpos));
} else {
lineStream.str(line);
}
if (std::getline(lineStream, suppression.errorId, ':')) {
if (std::getline(lineStream, suppression.fileName)) {
// If there is not a dot after the last colon in "file" then

View File

@ -391,10 +391,10 @@ You can create a suppressions file. Example:
memleak:src/file1.cpp
exceptNew:src/file1.cpp
// suppress all uninitvar errors in all files
uninitvar
uninitvar // suppress all uninitvar errors in all files
Note that you may add empty lines and comments in the suppressions file.
Comments must start with `#` or `//` and be at the start of the line, or after the suppression line.
You can use the suppressions file like this:

View File

@ -493,6 +493,26 @@ private:
Suppressions suppressions2;
suppressions2.parseFile(file2);
ASSERT_EQUALS(true, suppressions2.isSuppressed(errorMessage("abc", "test.cpp", 123)));
std::istringstream file3("abc // comment");
Suppressions suppressions3;
suppressions3.parseFile(file3);
ASSERT_EQUALS(true, suppressions3.isSuppressed(errorMessage("abc", "test.cpp", 123)));
std::istringstream file4("abc\t\t # comment");
Suppressions suppressions4;
suppressions4.parseFile(file4);
ASSERT_EQUALS(true, suppressions4.isSuppressed(errorMessage("abc", "test.cpp", 123)));
std::istringstream file5("abc:test.cpp\t\t # comment");
Suppressions suppressions5;
suppressions5.parseFile(file5);
ASSERT_EQUALS(true, suppressions5.isSuppressed(errorMessage("abc", "test.cpp", 123)));
std::istringstream file6("abc:test.cpp:123\t\t # comment with . inside");
Suppressions suppressions6;
suppressions6.parseFile(file6);
ASSERT_EQUALS(true, suppressions6.isSuppressed(errorMessage("abc", "test.cpp", 123)));
}
void inlinesuppress() {