Skip to content

Commit c2ee0d2

Browse files
committed
review
1 parent 20a6ff0 commit c2ee0d2

File tree

2 files changed

+26
-48
lines changed

2 files changed

+26
-48
lines changed

cli/cmdlineparser.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,10 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
382382
bool def = false;
383383
bool maxconfigs = false;
384384
bool debug = false;
385+
bool inputAsFilter = false; // set by: --file-filter=+
385386

386387
ImportProject::Type projectType = ImportProject::Type::NONE;
387388
ImportProject project;
388-
bool projectSettings = false;
389389
std::string vsConfig;
390390

391391
std::string platform;
@@ -769,6 +769,8 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
769769
mLogger.printError("Failed: --file-filter=-");
770770
return Result::Fail;
771771
}
772+
} else if (std::strcmp(filter, "+") == 0) {
773+
inputAsFilter = true;
772774
} else {
773775
mSettings.fileFilters.emplace_back(filter);
774776
}
@@ -1133,18 +1135,16 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
11331135
}
11341136
}
11351137

1136-
// --project, --project-settings
1137-
else if (std::strncmp(argv[i], "--project=", 10) == 0 || std::strncmp(argv[i], "--project-settings=", 19) == 0) {
1138+
// --project
1139+
else if (std::strncmp(argv[i], "--project=", 10) == 0) {
11381140
if (projectType != ImportProject::Type::NONE)
11391141
{
11401142
mLogger.printError("multiple --project options are not supported.");
11411143
return Result::Fail;
11421144
}
11431145

1144-
projectSettings = (std::strncmp(argv[i], "--project-settings=", 19) == 0);
1145-
11461146
mSettings.checkAllConfigurations = false; // Can be overridden with --max-configs or --force
1147-
std::string projectFile = std::strchr(argv[i], '=') + 1;
1147+
std::string projectFile = argv[i]+10;
11481148
projectType = project.import(projectFile, &mSettings, &mSuppressions, isCppcheckPremium());
11491149
if (projectType == ImportProject::Type::CPPCHECK_GUI) {
11501150
for (const std::string &lib : project.guiProject.libraries)
@@ -1585,7 +1585,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
15851585
//mLogger.printMessage("whole program analysis requires --cppcheck-build-dir to be active with -j.");
15861586
}
15871587

1588-
if (projectSettings) {
1588+
if (inputAsFilter) {
15891589
mSettings.fileFilters.insert(mSettings.fileFilters.end(), mPathNames.cbegin(), mPathNames.cend());
15901590
mPathNames.clear();
15911591
}
@@ -1785,10 +1785,12 @@ void CmdLineParser::printHelp() const
17851785
" --exitcode-suppressions=<file>\n"
17861786
" Used when certain messages should be displayed but\n"
17871787
" should not cause a non-zero exitcode.\n"
1788-
" --file-filter=<str> Analyze only those files matching the given filter str\n"
1789-
" Can be used multiple times\n"
1788+
" --file-filter=<str> Analyze only those files matching the given filter str.\n"
1789+
" Can be used multiple times. When str is '-', the file\n"
1790+
" filter will be read from standard input. When str is '+',\n"
1791+
" all path arguments are treated as file filters.\n"
17901792
" Example: --file-filter=*bar.cpp analyzes only files\n"
1791-
" that end with bar.cpp.\n"
1793+
" that end with bar.cpp.\n"
17921794
" --file-list=<file> Specify the files to check in a text file. Add one\n"
17931795
" filename per line. When file is '-,' the file list will\n"
17941796
" be read from standard input.\n"
@@ -1926,16 +1928,6 @@ void CmdLineParser::printHelp() const
19261928
" or Visual Studio Project (*.vcxproj) you can limit\n"
19271929
" the configuration cppcheck should check.\n"
19281930
" For example: '--project-configuration=Release|Win32'\n"
1929-
" --project-settings=<file>\n"
1930-
" IDE option: Import settings from project file. Preprocessor\n"
1931-
" settings, suppressions, coding standards, etc. are imported.\n"
1932-
" Unlike --project the files to analyse is not imported with this\n"
1933-
" option.\n"
1934-
" These two commands are effectively the same:\n"
1935-
" cppcheck --project=foo --file-filter=src/test.c\n"
1936-
" cppcheck --project-settings=foo src/test.c\n"
1937-
" Both commands will load the project foo and then analyse only the\n"
1938-
" file src/test.c\n"
19391931
" -q, --quiet Do not show progress reports.\n"
19401932
" Note that this option is not mutually exclusive with --verbose.\n"
19411933
" -rp=<paths>, --relative-paths=<paths>\n"

test/testcmdlineparser.cpp

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ class TestCmdlineParser : public TestFixture {
208208
TEST_CASE(fileFilterFileWithDetailsSimplifiedPath);
209209
TEST_CASE(fileFilterFileWithDetailsCase);
210210
TEST_CASE(fileFilterStdin);
211+
TEST_CASE(fileFilterPlus);
211212
TEST_CASE(fileFilterNoMatch);
212213
TEST_CASE(fileList);
213214
TEST_CASE(fileListNoFile);
@@ -376,8 +377,6 @@ class TestCmdlineParser : public TestFixture {
376377
TEST_CASE(projectEmpty);
377378
TEST_CASE(projectMissing);
378379
TEST_CASE(projectNoPaths);
379-
TEST_CASE(projectSettingsBeforeSource);
380-
TEST_CASE(projectSettingsAfterSource);
381380
TEST_CASE(addon);
382381
TEST_CASE(addonMissing);
383382
#ifdef HAVE_RULES
@@ -1235,6 +1234,19 @@ class TestCmdlineParser : public TestFixture {
12351234
ASSERT_EQUALS("file2.cpp", settings->fileFilters[1]);
12361235
}
12371236

1237+
void fileFilterPlus() {
1238+
REDIRECT;
1239+
ScopedFile file("project.cppcheck",
1240+
"<project>\n"
1241+
"<paths>\n"
1242+
"<dir name=\"src\"/>\n"
1243+
"</paths>\n"
1244+
"</project>");
1245+
const char * const argv[] = {"cppcheck", "--project=project.cppcheck", "--file-filter=+", "src/file.cpp"};
1246+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
1247+
ASSERT_EQUALS("src/file.cpp", settings->fileFilters.front());
1248+
}
1249+
12381250
void fileFilterNoMatch() {
12391251
REDIRECT;
12401252
RedirectInput input("notexist1.c\nnotexist2.cpp\n");
@@ -2504,32 +2516,6 @@ class TestCmdlineParser : public TestFixture {
25042516
ASSERT_EQUALS("cppcheck: error: no C or C++ source files found.\n", logger->str());
25052517
}
25062518

2507-
void projectSettingsBeforeSource() {
2508-
REDIRECT;
2509-
ScopedFile file("project.cppcheck",
2510-
"<project>\n"
2511-
"<paths>\n"
2512-
"<dir name=\"src\"/>\n"
2513-
"</paths>\n"
2514-
"</project>");
2515-
const char * const argv[] = {"cppcheck", "--project-settings=project.cppcheck", "src/file.cpp"};
2516-
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
2517-
ASSERT_EQUALS("src/file.cpp", settings->fileFilters.front());
2518-
}
2519-
2520-
void projectSettingsAfterSource() {
2521-
REDIRECT;
2522-
ScopedFile file("project.cppcheck",
2523-
"<project>\n"
2524-
"<paths>\n"
2525-
"<dir name=\"src\"/>\n"
2526-
"</paths>\n"
2527-
"</project>");
2528-
const char * const argv[] = {"cppcheck", "src/file.cpp", "--project-settings=project.cppcheck"};
2529-
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
2530-
ASSERT_EQUALS("src/file.cpp", settings->fileFilters.front());
2531-
}
2532-
25332519
void addon() {
25342520
REDIRECT;
25352521
const char * const argv[] = {"cppcheck", "--addon=misra", "file.cpp"};

0 commit comments

Comments
 (0)