Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: add --premium option for license file #6858

Merged
merged 3 commits into from
Oct 4, 2024
Merged
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
13 changes: 10 additions & 3 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,8 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
}

// Special Cppcheck Premium options
else if (std::strncmp(argv[i], "--premium=", 10) == 0 && isCppcheckPremium()) {
else if ((std::strncmp(argv[i], "--premium=", 10) == 0 || std::strncmp(argv[i], "--premium-", 10) == 0) && isCppcheckPremium()) {
// valid options --premium=..
const std::set<std::string> valid{
"autosar",
"cert-c-2016",
Expand All @@ -984,6 +985,11 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
"misra-cpp-2023",
"bughunting",
"safety"};
// valid options --premium-..=
const std::set<std::string> valid2{
"cert-c-int-precision",
"license-file"
};

if (std::strcmp(argv[i], "--premium=safety-off") == 0) {
mSettings.safety = false;
Expand All @@ -994,8 +1000,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
if (!mSettings.premiumArgs.empty())
mSettings.premiumArgs += " ";
const std::string p(argv[i] + 10);
if (!valid.count(p) && !startsWith(p, "cert-c-int-precision=")) {
mLogger.printError("invalid --premium option '" + p + "'.");
const std::string p2(p.find('=') != std::string::npos ? p.substr(0, p.find('=')) : "");
if (!valid.count(p) && !valid2.count(p2)) {
mLogger.printError("invalid --premium option '" + (p2.empty() ? p : p2) + "'.");
return Result::Fail;
}
mSettings.premiumArgs += "--" + p;
Expand Down
18 changes: 18 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(premiumOptions3);
TEST_CASE(premiumOptions4);
TEST_CASE(premiumOptions5);
TEST_CASE(premiumOptionsCertCIntPrecision);
TEST_CASE(premiumOptionsLicenseFile);
TEST_CASE(premiumOptionsInvalid1);
TEST_CASE(premiumOptionsInvalid2);
TEST_CASE(premiumSafety);
Expand Down Expand Up @@ -1290,6 +1292,22 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS(false, settings->severity.isEnabled(Severity::warning));
}

void premiumOptionsCertCIntPrecision() {
REDIRECT;
asPremium();
const char * const argv[] = {"cppcheck", "--premium-cert-c-int-precision=12", "file.c"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv));
ASSERT_EQUALS("--cert-c-int-precision=12", settings->premiumArgs);
}

void premiumOptionsLicenseFile() {
REDIRECT;
asPremium();
const char * const argv[] = {"cppcheck", "--premium-license-file=file.lic", "file.c"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv));
ASSERT_EQUALS("--license-file=file.lic", settings->premiumArgs);
}

void premiumOptionsInvalid1() {
REDIRECT;
asPremium();
Expand Down
Loading