diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 03841fb3814..503d3f7ff32 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -471,13 +471,21 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a else if (std::strcmp(argv[i], "--check-config") == 0) mSettings.checkConfiguration = true; - // Check code exhaustively - else if (std::strcmp(argv[i], "--check-level=exhaustive") == 0) - mSettings.setCheckLevel(Settings::CheckLevel::exhaustive); + // Check level + else if (std::strncmp(argv[i], "--check-level=", 14) == 0) { + Settings::CheckLevel level = Settings::CheckLevel::normal; + const std::string level_s(argv[i] + 14); + if (level_s == "normal") + level = Settings::CheckLevel::normal; + else if (level_s == "exhaustive") + level = Settings::CheckLevel::exhaustive; + else { + mLogger.printError("unknown '--check-level' value '" + level_s + "'."); + return Result::Fail; + } - // Check code with normal analysis - else if (std::strcmp(argv[i], "--check-level=normal") == 0) - mSettings.setCheckLevel(Settings::CheckLevel::normal); + mSettings.setCheckLevel(level); + } // Check library definitions else if (std::strcmp(argv[i], "--check-library") == 0) { diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index a92047363fa..1756f635f93 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -386,6 +386,7 @@ class TestCmdlineParser : public TestFixture { TEST_CASE(checkLevelDefault); TEST_CASE(checkLevelNormal); TEST_CASE(checkLevelExhaustive); + TEST_CASE(checkLevelUnknown); TEST_CASE(ignorepaths1); TEST_CASE(ignorepaths2); @@ -2595,6 +2596,13 @@ class TestCmdlineParser : public TestFixture { ASSERT_EQUALS(256, settings->performanceValueFlowMaxSubFunctionArgs); } + void checkLevelUnknown() { + REDIRECT; + const char * const argv[] = {"cppcheck", "--check-level=default", "file.cpp"}; + ASSERT_EQUALS_ENUM(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS("cppcheck: error: unknown '--check-level' value 'default'.\n", logger->str()); + } + void ignorepaths1() { REDIRECT; const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};