diff --git a/cli/filelister.cpp b/cli/filelister.cpp index 684ed10c328..676d0448a51 100644 --- a/cli/filelister.cpp +++ b/cli/filelister.cpp @@ -128,7 +128,9 @@ static std::string addFiles2(std::list&files, const std::string } else { // Directory if (recursive) { - if (!ignored.match(fname)) { + // 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(fname + '/')) { std::list filesSorted; std::string err = addFiles2(filesSorted, fname, extra, recursive, ignored); @@ -240,7 +242,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..e0a431a4430 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, cwd=str(tmp_path)) \ No newline at end of file diff --git a/test/cli/testutils.py b/test/cli/testutils.py index 00b9483d08e..f352af49f15 100644 --- a/test/cli/testutils.py +++ b/test/cli/testutils.py @@ -236,8 +236,8 @@ def cppcheck(*args, **kwargs): return return_code, stdout, stderr -def assert_cppcheck(args, ec_exp=None, out_exp=None, err_exp=None, env=None): - exitcode, stdout, stderr = cppcheck(args, env) +def assert_cppcheck(args, ec_exp=None, out_exp=None, err_exp=None, env=None, cwd=None): + exitcode, stdout, stderr = cppcheck(args, env=env, cwd=cwd) if ec_exp is not None: assert exitcode == ec_exp, stdout if out_exp is not None: