Fixed #3442 (unmatchedSuppression can't be suppressed)
This commit is contained in:
parent
2e18842681
commit
6018bb4636
|
@ -318,7 +318,25 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
|
|||
|
||||
void ErrorLogger::reportUnmatchedSuppressions(const std::list<Suppressions::SuppressionEntry> &unmatched)
|
||||
{
|
||||
// Report unmatched suppressions
|
||||
for (std::list<Suppressions::SuppressionEntry>::const_iterator i = unmatched.begin(); i != unmatched.end(); ++i) {
|
||||
// don't report "unmatchedSuppression" as unmatched
|
||||
if (i->id == "unmatchedSuppression")
|
||||
continue;
|
||||
|
||||
// check if this unmatched suppression is suppressed
|
||||
bool suppressed = false;
|
||||
for (std::list<Suppressions::SuppressionEntry>::const_iterator i2 = unmatched.begin(); i2 != unmatched.end(); ++i2) {
|
||||
if (i2->id == "unmatchedSuppression") {
|
||||
if ((i2->file == "*" || i2->file == i->file) &&
|
||||
(i2->line == 0 || i2->line == i->line))
|
||||
suppressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (suppressed)
|
||||
continue;
|
||||
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
|
||||
callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(i->file, i->line));
|
||||
reportErr(ErrorLogger::ErrorMessage(callStack, Severity::information, "Unmatched suppression: " + i->id, "unmatchedSuppression", false));
|
||||
|
|
|
@ -50,6 +50,8 @@ private:
|
|||
|
||||
// Serialize / Deserialize inconclusive message
|
||||
TEST_CASE(SerializeInconclusiveMessage);
|
||||
|
||||
TEST_CASE(suppressUnmatchedSuppressions);
|
||||
}
|
||||
|
||||
void FileLocationDefaults() {
|
||||
|
@ -315,5 +317,56 @@ private:
|
|||
ASSERT_EQUALS("Programming error", msg2.shortMessage());
|
||||
ASSERT_EQUALS("Programming error", msg2.verboseMessage());
|
||||
}
|
||||
|
||||
void suppressUnmatchedSuppressions() {
|
||||
std::list<Suppressions::SuppressionEntry> suppressions;
|
||||
|
||||
// No unmatched suppression
|
||||
errout.str("");
|
||||
suppressions.clear();
|
||||
reportUnmatchedSuppressions(suppressions);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// suppress all unmatchedSuppression
|
||||
errout.str("");
|
||||
suppressions.clear();
|
||||
suppressions.push_back(Suppressions::SuppressionEntry("abc", "a.c", 10U));
|
||||
suppressions.push_back(Suppressions::SuppressionEntry("unmatchedSuppression", "*", 0U));
|
||||
reportUnmatchedSuppressions(suppressions);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// suppress all unmatchedSuppression in a.c
|
||||
errout.str("");
|
||||
suppressions.clear();
|
||||
suppressions.push_back(Suppressions::SuppressionEntry("abc", "a.c", 10U));
|
||||
suppressions.push_back(Suppressions::SuppressionEntry("unmatchedSuppression", "a.c", 0U));
|
||||
reportUnmatchedSuppressions(suppressions);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// suppress unmatchedSuppression in a.c at line 10
|
||||
errout.str("");
|
||||
suppressions.clear();
|
||||
suppressions.push_back(Suppressions::SuppressionEntry("abc", "a.c", 10U));
|
||||
suppressions.push_back(Suppressions::SuppressionEntry("unmatchedSuppression", "a.c", 10U));
|
||||
reportUnmatchedSuppressions(suppressions);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// don't suppress unmatchedSuppression when file is mismatching
|
||||
errout.str("");
|
||||
suppressions.clear();
|
||||
suppressions.push_back(Suppressions::SuppressionEntry("abc", "a.c", 10U));
|
||||
suppressions.push_back(Suppressions::SuppressionEntry("unmatchedSuppression", "b.c", 0U));
|
||||
reportUnmatchedSuppressions(suppressions);
|
||||
ASSERT_EQUALS("[a.c:10]: (information) Unmatched suppression: abc\n", errout.str());
|
||||
|
||||
// don't suppress unmatchedSuppression when line is mismatching
|
||||
errout.str("");
|
||||
suppressions.clear();
|
||||
suppressions.push_back(Suppressions::SuppressionEntry("abc", "a.c", 10U));
|
||||
suppressions.push_back(Suppressions::SuppressionEntry("unmatchedSuppression", "a.c", 1U));
|
||||
reportUnmatchedSuppressions(suppressions);
|
||||
ASSERT_EQUALS("[a.c:10]: (information) Unmatched suppression: abc\n", errout.str());
|
||||
}
|
||||
|
||||
};
|
||||
REGISTER_TEST(TestErrorLogger)
|
||||
|
|
Loading…
Reference in New Issue