Merge branch 'unmatched-suppressions'
This commit is contained in:
commit
e2581da30c
|
@ -197,7 +197,7 @@ unsigned int CppCheck::check()
|
|||
_errorLogger.reportOut("Bailing out from checking " + fixedpath + ": " + e.what());
|
||||
}
|
||||
|
||||
reportUnmatchedSuppressions(_settings.nomsg.getUnmatchedLocalSuppressions());
|
||||
reportUnmatchedSuppressions(_settings.nomsg.getUnmatchedLocalSuppressions(fname));
|
||||
|
||||
_errorLogger.reportStatus(c + 1, (unsigned int)_filenames.size());
|
||||
}
|
||||
|
|
|
@ -312,12 +312,13 @@ bool Settings::Suppressions::isSuppressedLocal(const std::string &errorId, const
|
|||
return _suppressions[errorId].isSuppressedLocal(file, line);
|
||||
}
|
||||
|
||||
std::list<Settings::Suppressions::SuppressionEntry> Settings::Suppressions::getUnmatchedLocalSuppressions() const
|
||||
std::list<Settings::Suppressions::SuppressionEntry> Settings::Suppressions::getUnmatchedLocalSuppressions(const std::string &file) const
|
||||
{
|
||||
std::list<SuppressionEntry> r;
|
||||
for (std::map<std::string, FileMatcher>::const_iterator i = _suppressions.begin(); i != _suppressions.end(); ++i)
|
||||
{
|
||||
for (std::map<std::string, std::map<unsigned int, bool> >::const_iterator f = i->second._files.begin(); f != i->second._files.end(); ++f)
|
||||
std::map<std::string, std::map<unsigned int, bool> >::const_iterator f = i->second._files.find(file);
|
||||
if (f != i->second._files.end())
|
||||
{
|
||||
for (std::map<unsigned int, bool>::const_iterator l = f->second.begin(); l != f->second.end(); ++l)
|
||||
{
|
||||
|
|
|
@ -239,7 +239,7 @@ public:
|
|||
* @brief Returns list of unmatched local (per-file) suppressions.
|
||||
* @return list of unmatched suppressions
|
||||
*/
|
||||
std::list<SuppressionEntry> getUnmatchedLocalSuppressions() const;
|
||||
std::list<SuppressionEntry> getUnmatchedLocalSuppressions(const std::string &file) const;
|
||||
|
||||
/**
|
||||
* @brief Returns list of unmatched global (glob pattern) suppressions.
|
||||
|
|
|
@ -36,6 +36,7 @@ private:
|
|||
void run()
|
||||
{
|
||||
TEST_CASE(suppressionsSettings);
|
||||
TEST_CASE(suppressionsMultiFile);
|
||||
}
|
||||
|
||||
// Check the suppression
|
||||
|
@ -84,6 +85,26 @@ private:
|
|||
reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions());
|
||||
}
|
||||
|
||||
// Check the suppression for multiple files
|
||||
void checkSuppression(const char *names[], const char *codes[], const std::string &suppression = "")
|
||||
{
|
||||
// Clear the error log
|
||||
errout.str("");
|
||||
|
||||
Settings settings;
|
||||
settings._inlineSuppressions = true;
|
||||
if (!suppression.empty())
|
||||
settings.nomsg.addSuppressionLine(suppression);
|
||||
|
||||
CppCheck cppCheck(*this, true);
|
||||
cppCheck.settings(settings);
|
||||
for (int i = 0; names[i] != NULL; ++i)
|
||||
cppCheck.addFile(names[i], codes[i]);
|
||||
cppCheck.check();
|
||||
|
||||
reportUnmatchedSuppressions(cppCheck.settings().nomsg.getUnmatchedGlobalSuppressions());
|
||||
}
|
||||
|
||||
void runChecks(void (TestSuppressions::*check)(const char[], const std::string &))
|
||||
{
|
||||
// check to make sure the appropriate error is present
|
||||
|
@ -167,6 +188,23 @@ private:
|
|||
runChecks(&TestSuppressions::checkSuppressionThreads);
|
||||
}
|
||||
|
||||
void suppressionsMultiFile()
|
||||
{
|
||||
const char *names[] = {"abc.cpp", "xyz.cpp", NULL};
|
||||
const char *codes[] = {
|
||||
"void f() {\n"
|
||||
"}\n",
|
||||
"void f() {\n"
|
||||
" int a;\n"
|
||||
" a++;\n"
|
||||
"}\n",
|
||||
};
|
||||
|
||||
// suppress uninitvar for this file and line
|
||||
checkSuppression(names, codes, "uninitvar:xyz.cpp:3");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestSuppressions)
|
||||
|
|
Loading…
Reference in New Issue