add --suppress= command line option

This commit is contained in:
Greg Hewgill 2011-02-16 22:26:40 +13:00
parent d20987c3da
commit 22210e0255
2 changed files with 34 additions and 0 deletions

View File

@ -197,6 +197,18 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
}
}
else if (strncmp(argv[i], "--suppress=", 11) == 0)
{
std::string suppression = argv[i];
suppression = suppression.substr(11);
const std::string errmsg(_settings->nomsg.addSuppressionLine(suppression));
if (!errmsg.empty())
{
PrintMessage(errmsg);
return false;
}
}
// Enables inline suppressions.
else if (strcmp(argv[i], "--inline-suppr") == 0)
_settings->_inlineSuppressions = true;

View File

@ -77,6 +77,8 @@ private:
TEST_CASE(suppressionsOld); // TODO: Create and test real suppression file
TEST_CASE(suppressions)
TEST_CASE(suppressionsNoFile)
TEST_CASE(suppressionSingle)
TEST_CASE(suppressionSingleFile)
TEST_CASE(templates);
TEST_CASE(templatesGcc);
TEST_CASE(templatesVs);
@ -554,6 +556,26 @@ private:
ASSERT(!parser.ParseFromArgs(3, argv));
}
void suppressionSingle()
{
REDIRECT;
const char *argv[] = {"cppcheck", "--suppress=uninitvar", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U));
}
void suppressionSingleFile()
{
REDIRECT;
const char *argv[] = {"cppcheck", "--suppress=uninitvar:file.cpp", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT_EQUALS(true, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U));
}
void templates()
{
REDIRECT;