Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,15 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
}
}

else if (std::strncmp(argv[i], "--exitcode-suppress=", 20) == 0) {
const std::string suppression = argv[i]+20;
const std::string errmsg(mSuppressions.nofail.addSuppressionLine(suppression));
if (!errmsg.empty()) {
mLogger.printError(errmsg);
return Result::Fail;
}
}

// Filter errors
else if (std::strncmp(argv[i], "--exitcode-suppressions=", 24) == 0) {
// exitcode-suppressions=filename.txt
Expand Down Expand Up @@ -1795,6 +1804,9 @@ void CmdLineParser::printHelp() const
" provided. Note that your operating system can modify\n"
" this value, e.g. '256' can become '0'.\n"
" --errorlist Print a list of all the error messages in XML format.\n"
" --exitcode-suppress=<spec>\n"
" Used to specify an error ID which should not result in\n"
" a non-zero exitcode."
" --exitcode-suppressions=<file>\n"
" Used when certain messages should be displayed but\n"
" should not cause a non-zero exitcode.\n"
Expand Down
11 changes: 11 additions & 0 deletions man/cppcheck.1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
<arg choice="opt">
<option>--errorlist</option>
</arg>
<arg choice="opt">
<option>--exitcode-suppress=&lt;spec&gt;</option>
</arg>
<arg choice="opt">
<option>--exitcode-suppressions=&lt;file&gt;</option>
</arg>
Expand Down Expand Up @@ -343,6 +346,14 @@ Example: '-UDEBUG'</para>
<para>Print a list of all possible error messages in XML format.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--exitcode-suppress=&lt;spec&gt;</option>
</term>
<listitem>
<para>Used to specify an error ID which should not result in a non-zero exitcode.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--exitcode-suppressions=&lt;file&gt;</option>
Expand Down
1 change: 1 addition & 0 deletions releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ Infrastructure & dependencies:
-

Other:
- Added CLI option `--exitcode-suppress` to specify an error ID which should not result in a non-zero exitcode.
-
33 changes: 33 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(suppressSingleFile);
TEST_CASE(suppressTwo);
TEST_CASE(suppressTwoSeparate);
TEST_CASE(exitcodeSuppressSingle);
TEST_CASE(exitcodeSuppressSingleFile);
TEST_CASE(exitcodeSuppressTwo);
TEST_CASE(exitcodeSuppressTwoSeparate);
TEST_CASE(templates);
TEST_CASE(templatesGcc);
TEST_CASE(templatesVs);
Expand Down Expand Up @@ -1985,6 +1989,35 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS(true, supprs->nomsg.isSuppressed(errorMessage("noConstructor", "file.cpp", 1U)));
}

void exitcodeSuppressSingle() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--exitcode-suppress=uninitvar", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
ASSERT_EQUALS(true, supprs->nofail.isSuppressed(errorMessage("uninitvar", "file.cpp", 1)));
}

void exitcodeSuppressSingleFile() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--exitcode-suppress=uninitvar:file.cpp", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
ASSERT_EQUALS(true, supprs->nofail.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U)));
}

void exitcodeSuppressTwo() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--exitcode-suppress=uninitvar,noConstructor", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Fail, parseFromArgs(argv));
ASSERT_EQUALS("cppcheck: error: Failed to add suppression. Invalid id \"uninitvar,noConstructor\"\n", logger->str());
}

void exitcodeSuppressTwoSeparate() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--exitcode-suppress=uninitvar", "--exitcode-suppress=noConstructor", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
ASSERT_EQUALS(true, supprs->nofail.isSuppressed(errorMessage("uninitvar", "file.cpp", 1U)));
ASSERT_EQUALS(true, supprs->nofail.isSuppressed(errorMessage("noConstructor", "file.cpp", 1U)));
}

void templates() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--template={file}:{line},{severity},{id},{message}", "--template-location={file}:{line}:{column} {info}", "file.cpp"};
Expand Down
Loading