Merge branch 'cmdline-suppress'
This commit is contained in:
commit
b26777c962
|
@ -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"
|
||||
|
|
|
@ -120,6 +120,7 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
|
|||
<arg choice="opt"><option>--rule=<rule></option></arg>
|
||||
<arg choice="opt"><option>--rule-file=<file></option></arg>
|
||||
<arg choice="opt"><option>--style</option></arg>
|
||||
<arg choice="opt"><option>--suppress=<spec></option></arg>
|
||||
<arg choice="opt"><option>--suppressions-list=<file></option></arg>
|
||||
<arg choice="opt"><option>--template '<text>'</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=<spec></option></term>
|
||||
<listitem>
|
||||
<para>Suppress a specific warning. The format of <spec> 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=<file></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 <spec> above.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue