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: 1 addition & 1 deletion lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ static simplecpp::TokenList createTokenList(const std::string& filename, std::ve
static std::size_t calculateHash(const Preprocessor& preprocessor, const simplecpp::TokenList& tokens, const Settings& settings, const Suppressions& supprs)
{
std::ostringstream toolinfo;
toolinfo << CPPCHECK_VERSION_STRING;
toolinfo << (settings.cppcheckCfgProductName.empty() ? CPPCHECK_VERSION_STRING : settings.cppcheckCfgProductName);
toolinfo << (settings.severity.isEnabled(Severity::warning) ? 'w' : ' ');
toolinfo << (settings.severity.isEnabled(Severity::style) ? 's' : ' ');
toolinfo << (settings.severity.isEnabled(Severity::performance) ? 'p' : ' ');
Expand Down
44 changes: 44 additions & 0 deletions test/cli/premium_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# python -m pytest premium_test.py

import os
import re
import shutil
import sys
import time
Expand Down Expand Up @@ -53,3 +54,46 @@ def test_misra_c_builtin_style_checks(tmpdir):
assert exitcode == 0
assert 'id="unusedVariable"' in stderr
assert 'id="checkersReport"' not in stderr


def test_build_dir_hash_cppcheck_product(tmpdir):
# 13644 - cppcheck build dir hashes should depend on the cppcheck version
# so that files are rescanned when cppcheck is switched

test_file = os.path.join(tmpdir, 'test.cpp')
with open(test_file, 'wt') as f:
f.write(';')

build_dir = tmpdir.mkdir('b')
args = [f'--cppcheck-build-dir={build_dir}', test_file]

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

def _get_hash(s:str):
i = s.find(' hash="')
if i <= -1:
return ''
i += 7
return s[i:s.find('"', i)]

with open(build_dir.join('test.a1'), 'rt') as f:
f1 = f.read()
hash1 = _get_hash(f1)
assert re.match(r'^[0-9a-f]{6,}$', hash1), f1

premium_exe = __copy_cppcheck_premium(tmpdir)
exitcode, stdout, stderr = cppcheck(args, cppcheck_exe=premium_exe)
assert 'error' not in stdout
assert stderr == ''
assert exitcode == 0

with open(build_dir.join('test.a1'), 'rt') as f:
f2 = f.read()
hash2 = _get_hash(f2)
assert re.match(r'^[0-9a-f]{6,}$', hash2), f2

assert hash1 != hash2

Loading