diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index aa9f14a4c..4d71ac51f 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -318,7 +318,25 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string void ErrorLogger::reportUnmatchedSuppressions(const std::list &unmatched) { + // Report unmatched suppressions for (std::list::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::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 callStack; callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(i->file, i->line)); reportErr(ErrorLogger::ErrorMessage(callStack, Severity::information, "Unmatched suppression: " + i->id, "unmatchedSuppression", false)); diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index 4e120d6ac..88dc0d292 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -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; + + // 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)