Merge branch 'cmdline-suppress'

This commit is contained in:
Greg Hewgill 2011-02-23 21:34:09 +13:00
commit b26777c962
4 changed files with 57 additions and 8 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;
@ -661,11 +673,12 @@ void CmdLineParser::PrintHelp()
" --rule-file=<file> Use given rule file. For more information, see: \n"
" https://sourceforge.net/projects/cppcheck/files/Articles/\n"
" -s, --style Deprecated, use --enable=style\n"
" --suppressions-list=<file>\n"
" Suppress warnings listed in the file. Filename and line\n"
" are optional in the suppression file. The format of the\n"
" single line in the suppression file is:\n"
" --suppress=<spec> Suppress a specific warning. The format of <spec> is:\n"
" [error id]:[filename]:[line]\n"
" The [filename] and [line] are optional.\n"
" --suppressions-list=<file>\n"
" Suppress warnings listed in the file. Each suppression\n"
" is in the same format as <spec> above.\n"
" --template '<text>' Format the error messages. E.g.\n"
" '{file}:{line},{severity},{id},{message}' or\n"
" '{file}({line}):({severity}) {message}'\n"

View File

@ -120,6 +120,7 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
<arg choice="opt"><option>--rule=&lt;rule&gt;</option></arg>
<arg choice="opt"><option>--rule-file=&lt;file&gt;</option></arg>
<arg choice="opt"><option>--style</option></arg>
<arg choice="opt"><option>--suppress=&lt;spec&gt;</option></arg>
<arg choice="opt"><option>--suppressions-list=&lt;file&gt;</option></arg>
<arg choice="opt"><option>--template '&lt;text&gt;'</option></arg>
<arg choice="opt"><option>--verbose</option></arg>
@ -303,12 +304,19 @@ Directory name is matched to all parts of the path.</para>
<para>Deprecated, use --enable=style</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--suppress=&lt;spec&gt;</option></term>
<listitem>
<para>Suppress a specific warning. The format of &lt;spec&gt; is: [error id]:[filename]:[line].
The [filename] and [line] are optional.
[filename] may contain the wildcard characters * or ?.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--suppressions-list=&lt;file&gt;</option></term>
<listitem>
<para>Suppress warnings listed in the file. Filename and line are optional. The format of the single line in file is: [error id]:[filename]:[line].
You can use --template or --xml to see the error id.
The filename may contain the wildcard characters * or ?.</para>
<para>Suppress warnings listed in the file.
Each suppression is in the format of &lt;spec&gt; above.</para>
</listitem>
</varlistentry>
<varlistentry>

View File

@ -374,7 +374,8 @@ gui/test.cpp,16,error,mismatchAllocDealloc,Mismatching allocation and deallocati
<title>Suppressions</title>
<para>If you want to filter out certain errors you can suppress these.
First you need to create a suppressions file. The format is:</para>
The <literal>--suppress=</literal> command line option is used to specify
suppressions on the command line. The format is one of:</para>
<programlisting>[error id]:[filename]:[line]
[error id]:[filename2]
@ -389,6 +390,11 @@ gui/test.cpp,16,error,mismatchAllocDealloc,Mismatching allocation and deallocati
* or ?, which match any sequence of characters or any single character
respectively.</para>
<programlisting>cppcheck --suppress=memleak:file1.cpp src/</programlisting>
<para>If you have more than a couple of suppressions, create a suppressions
file with one line per suppression as above.</para>
<para>Here is an example:</para>
<programlisting>memleak:file1.cpp

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;