#12263: Constant Error 'missingInclude' (#5769)

Small adjustment of the log of the error.

- printed only when there was `--enabled=information` and no mentioning
of `missingInclude`
This commit is contained in:
olabetskyi 2023-12-16 19:38:30 +02:00 committed by GitHub
parent 3329e2f633
commit 7191ed92b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 3 deletions

View File

@ -376,6 +376,8 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
ImportProject project;
int8_t logMissingInclude{0};
for (int i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
// User define
@ -551,6 +553,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
mLogger.printError(errmsg);
return Result::Fail;
}
if (std::string(argv[i] + 10).find("missingInclude") != std::string::npos) {
--logMissingInclude;
}
}
// dump cppcheck data
@ -570,9 +575,12 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
mSettings.addEnabled("performance");
mSettings.addEnabled("portability");
}
if (enable_arg.find("information") != std::string::npos) {
if (enable_arg.find("information") != std::string::npos && logMissingInclude == 0) {
++logMissingInclude;
mSettings.addEnabled("missingInclude");
mLogger.printMessage("'--enable=information' will no longer implicitly enable 'missingInclude' starting with 2.16. Please enable it explicitly if you require it.");
}
if (enable_arg.find("missingInclude") != std::string::npos) {
--logMissingInclude;
}
}
@ -1234,6 +1242,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
}
}
if (logMissingInclude == 1)
mLogger.printMessage("'--enable=information' will no longer implicitly enable 'missingInclude' starting with 2.16. Please enable it explicitly if you require it.");
if (!loadCppcheckCfg())
return Result::Fail;

View File

@ -172,6 +172,9 @@ private:
TEST_CASE(enabledInformation);
TEST_CASE(enabledUnusedFunction);
TEST_CASE(enabledMissingInclude);
TEST_CASE(disabledMissingIncludeWithInformation);
TEST_CASE(enabledMissingIncludeWithInformation);
TEST_CASE(enabledMissingIncludeWithInformationReverseOrder);
#ifdef CHECK_INTERNAL
TEST_CASE(enabledInternal);
#endif
@ -839,6 +842,33 @@ private:
ASSERT(settings->checks.isEnabled(Checks::missingInclude));
}
void disabledMissingIncludeWithInformation() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--disable=missingInclude", "--enable=information", "file.cpp"};
ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv));
ASSERT(settings->severity.isEnabled(Severity::information));
ASSERT(!settings->checks.isEnabled(Checks::missingInclude));
ASSERT_EQUALS("", logger->str());
}
void enabledMissingIncludeWithInformation() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--enable=information", "--enable=missingInclude", "file.cpp"};
ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv));
ASSERT(settings->severity.isEnabled(Severity::information));
ASSERT(settings->checks.isEnabled(Checks::missingInclude));
ASSERT_EQUALS("", logger->str());
}
void enabledMissingIncludeWithInformationReverseOrder() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--enable=missingInclude", "--enable=information", "file.cpp"};
ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv));
ASSERT(settings->severity.isEnabled(Severity::information));
ASSERT(settings->checks.isEnabled(Checks::missingInclude));
ASSERT_EQUALS("", logger->str());
}
#ifdef CHECK_INTERNAL
void enabledInternal() {
REDIRECT;
@ -940,7 +970,7 @@ private:
ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv));
ASSERT(settings->severity.isEnabled(Severity::information));
ASSERT(!settings->checks.isEnabled(Checks::missingInclude));
ASSERT_EQUALS("cppcheck: '--enable=information' will no longer implicitly enable 'missingInclude' starting with 2.16. Please enable it explicitly if you require it.\n", logger->str());
ASSERT_EQUALS("", logger->str());
}
void disableInformationPartial2() {