Skip to content

Commit 78a38ed

Browse files
authored
Fix #15110: Support extra comments for suppression files (#8942)
1 parent e5f9f00 commit 78a38ed

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

‎lib/suppressions.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ SuppressionList::Suppression SuppressionList::parseLine(std::string line)
255255
// Strip any end of line comments
256256
std::string::size_type endpos = std::min(line.find('#'), line.find("//"));
257257
if (endpos != std::string::npos) {
258+
const std::string::size_type offset = line[endpos] == '#' ? 1 : 2;
259+
suppression.extraComment = trim(line.substr(endpos + offset));
258260
while (endpos > 0 && std::isspace(line[endpos-1])) {
259261
endpos--;
260262
}

‎test/testsuppressions.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,38 +1124,45 @@ class TestSuppressions : public TestFixture {
11241124
SuppressionList suppressions1;
11251125
ASSERT_EQUALS("", suppressions1.parseFile(file1));
11261126
ASSERT_EQUALS(true, suppressions1.isSuppressed(errorMessage("abc", "test.cpp", 123)));
1127+
ASSERT_EQUALS("", suppressions1.getSuppressions().cbegin()->extraComment);
11271128

11281129
std::istringstream file2("// comment\n"
11291130
"abc");
11301131
SuppressionList suppressions2;
11311132
ASSERT_EQUALS("", suppressions2.parseFile(file2));
11321133
ASSERT_EQUALS(true, suppressions2.isSuppressed(errorMessage("abc", "test.cpp", 123)));
1134+
ASSERT_EQUALS("", suppressions2.getSuppressions().cbegin()->extraComment);
11331135

11341136
std::istringstream file3("abc // comment");
11351137
SuppressionList suppressions3;
11361138
ASSERT_EQUALS("", suppressions3.parseFile(file3));
11371139
ASSERT_EQUALS(true, suppressions3.isSuppressed(errorMessage("abc", "test.cpp", 123)));
1140+
ASSERT_EQUALS("comment", suppressions3.getSuppressions().cbegin()->extraComment);
11381141

11391142
std::istringstream file4("abc\t\t # comment");
11401143
SuppressionList suppressions4;
11411144
ASSERT_EQUALS("", suppressions4.parseFile(file4));
11421145
ASSERT_EQUALS(true, suppressions4.isSuppressed(errorMessage("abc", "test.cpp", 123)));
1146+
ASSERT_EQUALS("comment", suppressions4.getSuppressions().cbegin()->extraComment);
11431147

11441148
std::istringstream file5("abc:test.cpp\t\t # comment");
11451149
SuppressionList suppressions5;
11461150
ASSERT_EQUALS("", suppressions5.parseFile(file5));
11471151
ASSERT_EQUALS(true, suppressions5.isSuppressed(errorMessage("abc", "test.cpp", 123)));
1152+
ASSERT_EQUALS("comment", suppressions5.getSuppressions().cbegin()->extraComment);
11481153

11491154
std::istringstream file6("abc:test.cpp:123\t\t # comment with . inside");
11501155
SuppressionList suppressions6;
11511156
ASSERT_EQUALS("", suppressions6.parseFile(file6));
11521157
ASSERT_EQUALS(true, suppressions6.isSuppressed(errorMessage("abc", "test.cpp", 123)));
1158+
ASSERT_EQUALS("comment with . inside", suppressions6.getSuppressions().cbegin()->extraComment);
11531159

11541160
std::istringstream file7(" // comment\n" // #11450
11551161
"abc");
11561162
SuppressionList suppressions7;
11571163
ASSERT_EQUALS("", suppressions7.parseFile(file7));
11581164
ASSERT_EQUALS(true, suppressions7.isSuppressed(errorMessage("abc", "test.cpp", 123)));
1165+
ASSERT_EQUALS("", suppressions7.getSuppressions().cbegin()->extraComment);
11591166
}
11601167

11611168
void inlinesuppress() const {

0 commit comments

Comments
 (0)