Skip to content

Commit 87cd909

Browse files
committed
test
1 parent baea61f commit 87cd909

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

lib/cppcheck.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,9 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10601060
for (const std::string &config : configurations)
10611061
(void)preprocessor.getcode(config, files, false);
10621062

1063+
if (configurations.size() > mSettings.maxConfigs)
1064+
tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size());
1065+
10631066
if (analyzerInformation)
10641067
mLogger->setAnalyzerInfo(nullptr);
10651068
return 0;
@@ -1079,7 +1082,9 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10791082
}
10801083
#endif
10811084

1082-
if (!mSettings.force && configurations.size() > mSettings.maxConfigs &&
1085+
if (!mSettings.force &&
1086+
configurations.size() > mSettings.maxConfigs &&
1087+
mSettings.maxConfigs == 12 && // <- do not warn if maxConfigs has been changed
10831088
mSettings.severity.isEnabled(Severity::information))
10841089
tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size());
10851090

test/cli/other_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,3 +3847,28 @@ def test_unmatched_file(tmp_path): # #14248 / #14249
38473847
f'{lib_file}:-1:0: information: Unmatched suppression: error6 [unmatchedSuppression]'
38483848
]
38493849
assert ret == 0, stdout
3850+
3851+
3852+
def test_max_configs(tmp_path):
3853+
test_file = tmp_path / 'test.cpp'
3854+
with open(test_file, "w") as f:
3855+
for i in range(1,20):
3856+
dir = 'if' if i == 1 else 'elif'
3857+
f.write(f'#{dir} defined(X{i})\nx = {i};\n')
3858+
f.write('#endif\n')
3859+
3860+
# default max configs is set to 12
3861+
_, stdout, stderr = cppcheck(['-v', '--enable=information', '--template=daca2', str(test_file)])
3862+
assert stderr.splitlines() == [
3863+
'{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 12 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file)
3864+
]
3865+
3866+
# set explicit max configs => do not warn
3867+
_, _, stderr = cppcheck(['--enable=information', '--template=daca2', '--max-configs=6', str(test_file)])
3868+
assert stderr.splitlines() == []
3869+
3870+
# when using --check-configs, warn
3871+
_, _, stderr = cppcheck(['--check-config', '--template=daca2', '--max-configs=6', str(test_file)])
3872+
assert stderr.splitlines() == [
3873+
'{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 6 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file)
3874+
]

0 commit comments

Comments
 (0)