Skip to content

Commit 01693ba

Browse files
authored
Fix #13983 (cli: clarify output when --file-filter value does not match) (danmar#7675)
1 parent 1bed43d commit 01693ba

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

cli/cmdlineparser.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
213213
return matchglobs(mSettings.fileFilters, fs.filename());
214214
});
215215
if (fileSettings.empty()) {
216-
mLogger.printError("could not find any files matching the filter.");
216+
for (const std::string& f: mSettings.fileFilters)
217+
mLogger.printError("could not find any files matching the filter:" + f);
217218
return false;
218219
}
219220
}
@@ -285,7 +286,8 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
285286
if (!mSettings.fileFilters.empty()) {
286287
files = filterFiles(mSettings.fileFilters, filesResolved);
287288
if (files.empty()) {
288-
mLogger.printError("could not find any files matching the filter.");
289+
for (const std::string& f: mSettings.fileFilters)
290+
mLogger.printError("could not find any files matching the filter:" + f);
289291
return false;
290292
}
291293
}

test/cli/more-projects_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def test_project_file_filter_no_match(tmpdir):
389389

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

395395
assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)

test/cli/other_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ def test_file_filter_no_match(tmpdir):
988988

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

994994
assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)

test/testcmdlineparser.cpp

Lines changed: 11 additions & 0 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(fileFilterNoMatch);
211212
TEST_CASE(fileList);
212213
TEST_CASE(fileListNoFile);
213214
TEST_CASE(fileListStdin);
@@ -1226,6 +1227,16 @@ class TestCmdlineParser : public TestFixture {
12261227
ASSERT_EQUALS("file2.cpp", settings->fileFilters[1]);
12271228
}
12281229

1230+
void fileFilterNoMatch() {
1231+
REDIRECT;
1232+
RedirectInput input("notexist1.c\nnotexist2.cpp\n");
1233+
const char * const argv[] = {"cppcheck", "--file-filter=-", "."};
1234+
ASSERT(!fillSettingsFromArgs(argv));
1235+
ASSERT_EQUALS("cppcheck: error: could not find any files matching the filter:notexist1.c\n"
1236+
"cppcheck: error: could not find any files matching the filter:notexist2.cpp\n",
1237+
logger->str());
1238+
}
1239+
12291240
void fileList() {
12301241
REDIRECT;
12311242
ScopedFile file("files.txt",

0 commit comments

Comments
 (0)