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
2 changes: 2 additions & 0 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ static std::size_t calculateHash(const Preprocessor& preprocessor, const simplec
toolinfo << (settings.severity.isEnabled(Severity::portability) ? 'p' : ' ');
toolinfo << (settings.severity.isEnabled(Severity::information) ? 'i' : ' ');
toolinfo << settings.userDefines;
toolinfo << std::to_string(static_cast<std::uint8_t>(settings.checkLevel));
// TODO: do we need to add more options?
settings.supprs.nomsg.dump(toolinfo);
return preprocessor.calculateHash(tokens, toolinfo.str());
}
Expand Down
47 changes: 47 additions & 0 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import json

from testutils import cppcheck, assert_cppcheck, cppcheck_ex
from xml.etree import ElementTree


def __remove_std_lookup_log(l : list, exepath):
Expand Down Expand Up @@ -2269,3 +2270,49 @@ def test_dumpfile_platform(tmpdir):
break
assert ' wchar_t_bit="' in platform
assert ' size_t_bit="' in platform


def test_builddir_hash_check_level(tmp_path): # #13376
test_file = tmp_path / 'test.c'
Comment thread
danmar marked this conversation as resolved.
with open(test_file, 'wt') as f:
f.write("""
void f(bool b)
{
for (int i = 0; i < 2; ++i)
{
if (i == 0) {}
if (b) continue;
}
}
""")

build_dir = tmp_path / 'b1'
os.mkdir(build_dir)

args = [
'--enable=warning', # to execute the code which generates the normalCheckLevelMaxBranches message
'--enable=information', # to show the normalCheckLevelMaxBranches message
'--cppcheck-build-dir={}'.format(build_dir),
'--template=simple',
str(test_file)
]

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0, stdout
assert stderr == '{}:0:0: information: Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches. [normalCheckLevelMaxBranches]\n'.format(test_file)

cache_file = (build_dir / 'test.a1')

root = ElementTree.fromstring(cache_file.read_text())
hash_1 = root.get('hash')

args += ['--check-level=exhaustive']

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0, stdout
assert stderr == ''

root = ElementTree.fromstring(cache_file.read_text())
hash_2 = root.get('hash')

assert hash_1 != hash_2