diff --git a/cli/filelister.cpp b/cli/filelister.cpp index 684ed10c328..567ac3d784b 100644 --- a/cli/filelister.cpp +++ b/cli/filelister.cpp @@ -240,7 +240,9 @@ static std::string addFiles2(std::list &files, #endif if (path_is_directory) { if (recursive) { - if (!ignored.match(new_path)) { + // append a slash if it is a directory since that is what we are doing for mIgnoredPaths directory entries. + // otherwise we would ignore all its contents individually instead as a whole. + if (!ignored.match(new_path + '/')) { std::string err = addFiles2(files, new_path, extra, recursive, ignored, debug); if (!err.empty()) { return err; diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 58313336f29..c37861f0435 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3140,4 +3140,29 @@ def test_debug_valueflow_xml(tmp_path): # #13606 assert 'floatvalue' in value_elem[1].attrib assert value_elem[1].attrib['floatvalue'] == '1e-07' assert 'floatvalue' in value_elem[2].attrib - assert value_elem[2].attrib['floatvalue'] == '1e-07' \ No newline at end of file + assert value_elem[2].attrib['floatvalue'] == '1e-07' + + +def test_dir_ignore(tmp_path): + test_file = tmp_path / 'test.cpp' + with open(test_file, 'wt'): + pass + + lib_dir = tmp_path / 'lib' + os.mkdir(lib_dir) + lib_test_file = lib_dir / 'test.cpp' + with open(lib_test_file, 'wt'): + pass + + args = [ + '-ilib', + '--debug-ignore', + str(tmp_path) + ] + # make sure the whole directory is being ignored instead of each of its contents individually + out_lines = [ + 'ignored path: {}'.format(lib_dir), + 'Checking {} ...'.format(test_file) + ] + + assert_cppcheck(args, ec_exp=0, err_exp=[], out_exp=out_lines) \ No newline at end of file