Skip to content

Commit 41b6f93

Browse files
committed
test
1 parent b3dda6a commit 41b6f93

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

lib/cppcheck.cpp

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

1044+
if (configurations.size() > mSettings.maxConfigs)
1045+
tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size());
1046+
10441047
if (analyzerInformation)
10451048
mLogger->setAnalyzerInfo(nullptr);
10461049
return 0;
@@ -1060,7 +1063,9 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
10601063
}
10611064
#endif
10621065

1063-
if (!mSettings.force && configurations.size() > mSettings.maxConfigs &&
1066+
if (!mSettings.force &&
1067+
configurations.size() > mSettings.maxConfigs &&
1068+
mSettings.maxConfigs == 12 && // <- do not warn if maxConfigs has been changed
10641069
mSettings.severity.isEnabled(Severity::information))
10651070
tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size());
10661071

test/cli/other_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3947,4 +3947,26 @@ def test_simplecpp_syntax_error(tmp_path):
39473947
# TODO: lacks column information
39483948
'{}:1:0: error: No header in #include [syntaxError]'.format(test_file),
39493949
'{}:1:0: error: No header in #include [syntaxError]'.format(test_file)
3950+
def test_max_configs(tmp_path):
3951+
test_file = tmp_path / 'test.cpp'
3952+
with open(test_file, "w") as f:
3953+
for i in range(1,20):
3954+
dir = 'if' if i == 1 else 'elif'
3955+
f.write(f'#{dir} defined(X{i})\nx = {i};\n')
3956+
f.write('#endif\n')
3957+
3958+
# default max configs is set to 12
3959+
_, stdout, stderr = cppcheck(['-v', '--enable=information', '--template=daca2', str(test_file)])
3960+
assert stderr.splitlines() == [
3961+
'{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 12 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file)
3962+
]
3963+
3964+
# set explicit max configs => do not warn
3965+
_, _, stderr = cppcheck(['--enable=information', '--template=daca2', '--max-configs=6', str(test_file)])
3966+
assert stderr.splitlines() == []
3967+
3968+
# when using --check-configs, warn
3969+
_, _, stderr = cppcheck(['--check-config', '--template=daca2', '--max-configs=6', str(test_file)])
3970+
assert stderr.splitlines() == [
3971+
'{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 6 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file)
39503972
]

0 commit comments

Comments
 (0)