Skip to content

Commit b862703

Browse files
committed
test
1 parent 120c393 commit b862703

2 files changed

Lines changed: 30 additions & 21 deletions

File tree

lib/cppcheck.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,9 @@ std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const std:
857857
toolinfo << (mSettings.severity.isEnabled(Severity::portability) ? 'p' : ' ');
858858
toolinfo << (mSettings.severity.isEnabled(Severity::information) ? 'i' : ' ');
859859
toolinfo << mSettings.userDefines;
860+
toolinfo << (mSettings.checkConfiguration ? 'c' : ' '); // --check-config
861+
toolinfo << (mSettings.force ? 'f' : ' ');
862+
toolinfo << mSettings.maxConfigs;
860863
toolinfo << std::to_string(static_cast<std::uint8_t>(mSettings.checkLevel));
861864
for (const auto &a : mSettings.addonInfos) {
862865
toolinfo << a.name;

test/cli/other_test.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3949,33 +3949,39 @@ def test_simplecpp_syntax_error(tmp_path):
39493949
'{}:1:0: error: No header in #include [syntaxError]'.format(test_file)
39503950
]
39513951

3952-
def test_max_configs(tmp_path):
3952+
3953+
@pytest.mark.parametrize('max_configs,number_of_configs,check_config,expected_warn', [
3954+
# max configs = default, max configs < number of configs => warn
3955+
(12, 20, False, True),
3956+
(12, 20, True, True),
3957+
3958+
# max configs != default, max configs < number of configs => warn if --check-config
3959+
(6, 20, False, False),
3960+
(6, 20, True, True),
3961+
3962+
# max configs >= number of configs => no warning
3963+
(20, 20, False, False),
3964+
(20, 20, False, False)
3965+
])
3966+
def test_max_configs(tmp_path, max_configs, number_of_configs, check_config, expected_warn):
39533967
test_file = tmp_path / 'test.cpp'
39543968
with open(test_file, "w") as f:
3955-
for i in range(1,20):
3969+
for i in range(1,number_of_configs):
39563970
dir = 'if' if i == 1 else 'elif'
39573971
f.write(f'#{dir} defined(X{i})\nx = {i};\n')
39583972
f.write('#endif\n')
39593973

3960-
args = ['--enable=information', '--template=daca2', str(test_file)]
3974+
args = [f'--max-configs={max_configs}', '--enable=information', '--template=daca2', str(test_file)]
3975+
3976+
if check_config:
3977+
args = ['--check-config'] + args
39613978

39623979
# default max configs is set to 12, warn if code contains more configurations than that
39633980
_, _, stderr = cppcheck(args)
3964-
assert stderr.splitlines() == [
3965-
'{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 12 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file)
3966-
]
3967-
3968-
# set explicit max configs => do not warn
3969-
# configurations are likely skipped by intention
3970-
_, _, stderr = cppcheck(['--max-configs=6'] + args)
3971-
assert stderr.splitlines() == []
3972-
3973-
# when using --check-configs, warn if code contains more than max configs
3974-
_, _, stderr = cppcheck(['--check-config', '--max-configs=6'] + args)
3975-
assert stderr.splitlines() == [
3976-
'{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 6 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file)
3977-
]
3978-
3979-
# when using --check-configs, do not warn if code contains less than max configs
3980-
_, _, stderr = cppcheck(['--check-config', '--max-configs=60'] + args)
3981-
assert stderr.splitlines() == []
3981+
if not expected_warn:
3982+
assert stderr.splitlines() == []
3983+
else:
3984+
assert stderr.splitlines() == [
3985+
'{}:0:0: information: Too many #ifdef configurations - cppcheck only checks {} of {} configurations. Use --force to check all configurations. [toomanyconfigs]'
3986+
.format(test_file, max_configs, number_of_configs)
3987+
]

0 commit comments

Comments
 (0)