Skip to content
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
6 changes: 4 additions & 2 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
return matchglobs(mSettings.fileFilters, fs.filename());
});
if (fileSettings.empty()) {
mLogger.printError("could not find any files matching the filter.");
for (const std::string& f: mSettings.fileFilters)
mLogger.printError("could not find any files matching the filter:" + f);
return false;
}
}
Expand Down Expand Up @@ -285,7 +286,8 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
if (!mSettings.fileFilters.empty()) {
files = filterFiles(mSettings.fileFilters, filesResolved);
if (files.empty()) {
mLogger.printError("could not find any files matching the filter.");
for (const std::string& f: mSettings.fileFilters)
mLogger.printError("could not find any files matching the filter:" + f);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/cli/more-projects_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def test_project_file_filter_no_match(tmpdir):

args = ['--file-filter=*.c', '--project={}'.format(project_file)]
out_lines = [
'cppcheck: error: could not find any files matching the filter.'
'cppcheck: error: could not find any files matching the filter:*.c'
]

assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)
Expand Down
2 changes: 1 addition & 1 deletion test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ def test_file_filter_no_match(tmpdir):

args = ['--file-filter=*.c', test_file]
out_lines = [
'cppcheck: error: could not find any files matching the filter.'
'cppcheck: error: could not find any files matching the filter:*.c'
]

assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)
Expand Down
11 changes: 11 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(fileFilterFileWithDetailsSimplifiedPath);
TEST_CASE(fileFilterFileWithDetailsCase);
TEST_CASE(fileFilterStdin);
TEST_CASE(fileFilterNoMatch);
TEST_CASE(fileList);
TEST_CASE(fileListNoFile);
TEST_CASE(fileListStdin);
Expand Down Expand Up @@ -1226,6 +1227,16 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS("file2.cpp", settings->fileFilters[1]);
}

void fileFilterNoMatch() {
REDIRECT;
RedirectInput input("notexist1.c\nnotexist2.cpp\n");
const char * const argv[] = {"cppcheck", "--file-filter=-", "."};
ASSERT(!fillSettingsFromArgs(argv));
ASSERT_EQUALS("cppcheck: error: could not find any files matching the filter:notexist1.c\n"
"cppcheck: error: could not find any files matching the filter:notexist2.cpp\n",
logger->str());
}

void fileList() {
REDIRECT;
ScopedFile file("files.txt",
Expand Down