From 8cacf1f22a208d7798b487bd8e1f85b8eeba77d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 17 Nov 2025 21:29:44 +0100 Subject: [PATCH 01/13] Experimental fix for #13825 (toomanyconfigs lacks file information) --- cli/cppcheckexecutor.cpp | 4 ---- lib/cppcheck.cpp | 19 +++---------------- lib/cppcheck.h | 3 --- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index ef5b0469add..58659739d79 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -432,10 +432,6 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup returnValue = settings.exitCode; } - if (!settings.checkConfiguration) { - cppcheck.tooManyConfigsError("",0U); - } - stdLogger.writeCheckersReport(supprs); if (settings.outputFormat == Settings::OutputFormat::xml) { diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index da761030ec7..3c687bd7ccc 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1060,13 +1060,8 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str } #endif - if (!mSettings.force && configurations.size() > mSettings.maxConfigs) { - if (mSettings.severity.isEnabled(Severity::information)) { - tooManyConfigsError(Path::toNativeSeparators(file.spath()),configurations.size()); - } else { - mTooManyConfigs = true; - } - } + if (!mSettings.force && configurations.size() > mSettings.maxConfigs) + tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size()); FilesDeleter filesDeleter; @@ -1630,12 +1625,7 @@ void CppCheck::executeAddonsWholeProgram(const std::list &files void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfConfigurations) { - if (!mSettings.severity.isEnabled(Severity::information) && !mTooManyConfigs) - return; - - mTooManyConfigs = false; - - if (mSettings.severity.isEnabled(Severity::information) && file.empty()) + if (!mSettings.severity.isEnabled(Severity::information)) return; std::list loclist; @@ -1669,8 +1659,6 @@ void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfCo void CppCheck::purgedConfigurationMessage(const std::string &file, const std::string& configuration) { - mTooManyConfigs = false; - if (mSettings.severity.isEnabled(Severity::information) && file.empty()) return; @@ -1699,7 +1687,6 @@ void CppCheck::getErrorMessages(ErrorLogger &errorlogger) CppCheck cppcheck(settings, supprs, errorlogger, true, nullptr); cppcheck.purgedConfigurationMessage("",""); - cppcheck.mTooManyConfigs = true; cppcheck.tooManyConfigsError("",0U); // TODO: add functions to get remaining error messages diff --git a/lib/cppcheck.h b/lib/cppcheck.h index c139df08ce1..ad1ca8cbeb3 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -249,9 +249,6 @@ class CPPCHECKLIB CppCheck { bool mUseGlobalSuppressions; - /** Are there too many configs? */ - bool mTooManyConfigs{}; - /** File info used for whole program analysis */ std::list mFileInfo; From 707d1663ee916aafd249aeaa15aa6337bac8e53d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 17 Nov 2025 21:33:17 +0100 Subject: [PATCH 02/13] tweak --- lib/cppcheck.cpp | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 3c687bd7ccc..d04b8e8ef14 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1060,7 +1060,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str } #endif - if (!mSettings.force && configurations.size() > mSettings.maxConfigs) + if (!mSettings.force && mSettings.isEnabled(Severity::information) && configurations.size() > mSettings.maxConfigs) tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size()); FilesDeleter filesDeleter; @@ -1625,27 +1625,14 @@ void CppCheck::executeAddonsWholeProgram(const std::list &files void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfConfigurations) { - if (!mSettings.severity.isEnabled(Severity::information)) - return; - std::list loclist; if (!file.empty()) { loclist.emplace_back(file, 0, 0); } std::ostringstream msg; - msg << "Too many #ifdef configurations - cppcheck only checks " << mSettings.maxConfigs; - if (numberOfConfigurations > mSettings.maxConfigs) - msg << " of " << numberOfConfigurations << " configurations. Use --force to check all configurations.\n"; - if (file.empty()) - msg << " configurations. Use --force to check all configurations. For more details, use --enable=information.\n"; - msg << "The checking of the file will be interrupted because there are too many " - "#ifdef configurations. Checking of all #ifdef configurations can be forced " - "by --force command line option or from GUI preferences. However that may " - "increase the checking time."; - if (file.empty()) - msg << " For more details, use --enable=information."; - + msg << "Too many #ifdef configurations - cppcheck only checks " << mSettings.maxConfigs + << " of " << numberOfConfigurations << " configurations. Use --force to check all configurations."; ErrorMessage errmsg(std::move(loclist), "", From 39cd696fb3341fb915c0675c971cf2e35807c40b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 17 Nov 2025 21:34:04 +0100 Subject: [PATCH 03/13] runformat --- lib/cppcheck.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index d04b8e8ef14..2e23f717e3d 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1631,7 +1631,7 @@ void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfCo } std::ostringstream msg; - msg << "Too many #ifdef configurations - cppcheck only checks " << mSettings.maxConfigs + msg << "Too many #ifdef configurations - cppcheck only checks " << mSettings.maxConfigs << " of " << numberOfConfigurations << " configurations. Use --force to check all configurations."; ErrorMessage errmsg(std::move(loclist), From b3dda6affe5dbe11d6f0bee1bfead5cd4d78157a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 17 Nov 2025 21:39:42 +0100 Subject: [PATCH 04/13] fix --- lib/cppcheck.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 2e23f717e3d..6231011547f 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1060,7 +1060,8 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str } #endif - if (!mSettings.force && mSettings.isEnabled(Severity::information) && configurations.size() > mSettings.maxConfigs) + if (!mSettings.force && configurations.size() > mSettings.maxConfigs && + mSettings.severity.isEnabled(Severity::information)) tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size()); FilesDeleter filesDeleter; From 41b6f938733ea93e7f6507803a34c1ce95e4e297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 18 Nov 2025 09:30:19 +0100 Subject: [PATCH 05/13] test --- lib/cppcheck.cpp | 7 ++++++- test/cli/other_test.py | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 6231011547f..ac0af6f8222 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1041,6 +1041,9 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str for (const std::string &config : configurations) (void)preprocessor.getcode(config, files, false); + if (configurations.size() > mSettings.maxConfigs) + tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size()); + if (analyzerInformation) mLogger->setAnalyzerInfo(nullptr); return 0; @@ -1060,7 +1063,9 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str } #endif - if (!mSettings.force && configurations.size() > mSettings.maxConfigs && + if (!mSettings.force && + configurations.size() > mSettings.maxConfigs && + mSettings.maxConfigs == 12 && // <- do not warn if maxConfigs has been changed mSettings.severity.isEnabled(Severity::information)) tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size()); diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 81bef0bbf1e..e2f579a56d3 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3947,4 +3947,26 @@ def test_simplecpp_syntax_error(tmp_path): # TODO: lacks column information '{}:1:0: error: No header in #include [syntaxError]'.format(test_file), '{}:1:0: error: No header in #include [syntaxError]'.format(test_file) +def test_max_configs(tmp_path): + test_file = tmp_path / 'test.cpp' + with open(test_file, "w") as f: + for i in range(1,20): + dir = 'if' if i == 1 else 'elif' + f.write(f'#{dir} defined(X{i})\nx = {i};\n') + f.write('#endif\n') + + # default max configs is set to 12 + _, stdout, stderr = cppcheck(['-v', '--enable=information', '--template=daca2', str(test_file)]) + assert stderr.splitlines() == [ + '{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 12 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file) + ] + + # set explicit max configs => do not warn + _, _, stderr = cppcheck(['--enable=information', '--template=daca2', '--max-configs=6', str(test_file)]) + assert stderr.splitlines() == [] + + # when using --check-configs, warn + _, _, stderr = cppcheck(['--check-config', '--template=daca2', '--max-configs=6', str(test_file)]) + assert stderr.splitlines() == [ + '{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 6 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file) ] From 49fed2d77151e30b1dc6e6d4e188cac452175a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 18 Nov 2025 10:17:36 +0100 Subject: [PATCH 06/13] refactor --- lib/cppcheck.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index ac0af6f8222..b17c0be4c8f 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1063,12 +1063,6 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str } #endif - if (!mSettings.force && - configurations.size() > mSettings.maxConfigs && - mSettings.maxConfigs == 12 && // <- do not warn if maxConfigs has been changed - mSettings.severity.isEnabled(Severity::information)) - tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size()); - FilesDeleter filesDeleter; // write dump file xml prolog @@ -1093,8 +1087,13 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str // Check only a few configurations (default 12), after that bail out, unless --force // was used. - if (!mSettings.force && ++checkCount > mSettings.maxConfigs) + if (!mSettings.force && ++checkCount > mSettings.maxConfigs) { + // if maxConfigs has default value then report information message that configurations are skipped + if (mSettings.maxConfigs == 12 && mSettings.severity.isEnabled(Severity::information)) + tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size()); + break; + } std::string currentConfig; From 4ed0b8d7023c635c14a653f628c9de6c033782c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 18 Nov 2025 10:20:29 +0100 Subject: [PATCH 07/13] newlines --- test/cli/other_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index e2f579a56d3..f1e7021e19d 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3947,6 +3947,8 @@ def test_simplecpp_syntax_error(tmp_path): # TODO: lacks column information '{}:1:0: error: No header in #include [syntaxError]'.format(test_file), '{}:1:0: error: No header in #include [syntaxError]'.format(test_file) + + def test_max_configs(tmp_path): test_file = tmp_path / 'test.cpp' with open(test_file, "w") as f: From 3943e9e7fecac45b7aa88a5eb62c2ca2a75ef39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 18 Nov 2025 10:29:15 +0100 Subject: [PATCH 08/13] improve testing --- test/cli/other_test.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index f1e7021e19d..e7e94fc7c3d 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3947,7 +3947,7 @@ def test_simplecpp_syntax_error(tmp_path): # TODO: lacks column information '{}:1:0: error: No header in #include [syntaxError]'.format(test_file), '{}:1:0: error: No header in #include [syntaxError]'.format(test_file) - + ] def test_max_configs(tmp_path): test_file = tmp_path / 'test.cpp' @@ -3957,18 +3957,25 @@ def test_max_configs(tmp_path): f.write(f'#{dir} defined(X{i})\nx = {i};\n') f.write('#endif\n') - # default max configs is set to 12 - _, stdout, stderr = cppcheck(['-v', '--enable=information', '--template=daca2', str(test_file)]) + args = ['--enable=information', '--template=daca2', str(test_file)] + + # default max configs is set to 12, warn if code contains more configurations than that + _, stdout, stderr = cppcheck(args) assert stderr.splitlines() == [ '{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 12 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file) ] # set explicit max configs => do not warn - _, _, stderr = cppcheck(['--enable=information', '--template=daca2', '--max-configs=6', str(test_file)]) + # configurations are likely skipped by intention + _, _, stderr = cppcheck(['--max-configs=6'] + args) assert stderr.splitlines() == [] - # when using --check-configs, warn - _, _, stderr = cppcheck(['--check-config', '--template=daca2', '--max-configs=6', str(test_file)]) + # when using --check-configs, warn if code contains more than max configs + _, _, stderr = cppcheck(['--check-config', '--max-configs=6'] + args) assert stderr.splitlines() == [ '{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 6 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file) ] + + # when using --check-configs, do not warn if code contains less than max configs + _, _, stderr = cppcheck(['--check-config', '--max-configs=60'] + args) + assert stderr.splitlines() == [] From 88efa98311f17d1ca6ae665fd087b7fa5a7a4c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 18 Nov 2025 12:57:21 +0100 Subject: [PATCH 09/13] remove toomanyconfigs, tested in other_test.py --- test/testcppcheck.cpp | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index 8535bbfe47c..ac292a1a057 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -81,7 +81,6 @@ class TestCppcheck : public TestFixture { TEST_CASE(getDumpFileContentsLibrary); TEST_CASE(checkPlistOutput); TEST_CASE(premiumResultsCache); - TEST_CASE(toomanyconfigs); TEST_CASE(purgedConfiguration); } @@ -594,35 +593,6 @@ class TestCppcheck : public TestFixture { ASSERT(hash1 != hash2); } - void toomanyconfigs() const - { - ScopedFile test_file_a("a.c", - "#if DEF_1\n" - "#endif\n" - "#if DEF_2\n" - "#endif\n" - "#if DEF_3\n" - "#endif"); - - // this is the "simple" format - const auto s = dinit(Settings, - $.templateFormat = templateFormat, // TODO: remove when we only longer rely on toString() in unique message handling - $.severity.enable (Severity::information); - $.maxConfigs = 2); - Suppressions supprs; - ErrorLogger2 errorLogger; - CppCheck cppcheck(s, supprs, errorLogger, false, {}); - ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(test_file_a.path(), Path::identify(test_file_a.path(), false), 0))); - // TODO: how to properly disable these warnings? - errorLogger.errmsgs.erase(std::remove_if(errorLogger.errmsgs.begin(), errorLogger.errmsgs.end(), [](const ErrorMessage& msg) { - return msg.id == "logChecker"; - }), errorLogger.errmsgs.end()); - // the internal errorlist is cleared after each check() call - ASSERT_EQUALS(1, errorLogger.errmsgs.size()); - const auto it = errorLogger.errmsgs.cbegin(); - ASSERT_EQUALS("a.c:0:0: information: Too many #ifdef configurations - cppcheck only checks 2 of 4 configurations. Use --force to check all configurations. [toomanyconfigs]", it->toString(false, templateFormat, "")); - } - void purgedConfiguration() const { ScopedFile test_file("test.cpp", From e5da14c4769b37ed9dc4ef022239dec41b4afec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 18 Nov 2025 13:10:53 +0100 Subject: [PATCH 10/13] pylint --- test/cli/other_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index e7e94fc7c3d..f456488e722 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3960,7 +3960,7 @@ def test_max_configs(tmp_path): args = ['--enable=information', '--template=daca2', str(test_file)] # default max configs is set to 12, warn if code contains more configurations than that - _, stdout, stderr = cppcheck(args) + _, _, stderr = cppcheck(args) assert stderr.splitlines() == [ '{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 12 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file) ] From 120c3930eaf75c4bd86aee3a6587412248b58847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 19 Nov 2025 08:22:19 +0100 Subject: [PATCH 11/13] comment why information message should be skipped when --max-configs is used --- lib/cppcheck.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index b17c0be4c8f..208ee183f84 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1088,8 +1088,13 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str // Check only a few configurations (default 12), after that bail out, unless --force // was used. if (!mSettings.force && ++checkCount > mSettings.maxConfigs) { - // if maxConfigs has default value then report information message that configurations are skipped - if (mSettings.maxConfigs == 12 && mSettings.severity.isEnabled(Severity::information)) + // If maxConfigs has default value then report information message that configurations are skipped. + // If maxConfigs does not have default value then the user is explicitly skipping configurations so + // the information message is not reported, the whole purpose of setting i.e. --max-configs=1 is to + // skip configurations. When --check-config is used then tooManyConfigs will be reported even if the + // value is non-default. + const Settings defaultSettings; + if (mSettings.maxConfigs == defaultSettings.maxConfigs && mSettings.severity.isEnabled(Severity::information)) tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size()); break; From b86270322eff426737a2975d14847b87ef4914b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 19 Nov 2025 15:38:43 +0100 Subject: [PATCH 12/13] test --- lib/cppcheck.cpp | 3 +++ test/cli/other_test.py | 48 ++++++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 208ee183f84..10ec031b180 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -857,6 +857,9 @@ std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const std: toolinfo << (mSettings.severity.isEnabled(Severity::portability) ? 'p' : ' '); toolinfo << (mSettings.severity.isEnabled(Severity::information) ? 'i' : ' '); toolinfo << mSettings.userDefines; + toolinfo << (mSettings.checkConfiguration ? 'c' : ' '); // --check-config + toolinfo << (mSettings.force ? 'f' : ' '); + toolinfo << mSettings.maxConfigs; toolinfo << std::to_string(static_cast(mSettings.checkLevel)); for (const auto &a : mSettings.addonInfos) { toolinfo << a.name; diff --git a/test/cli/other_test.py b/test/cli/other_test.py index f456488e722..c12b5ef4ce3 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3949,33 +3949,39 @@ def test_simplecpp_syntax_error(tmp_path): '{}:1:0: error: No header in #include [syntaxError]'.format(test_file) ] -def test_max_configs(tmp_path): + +@pytest.mark.parametrize('max_configs,number_of_configs,check_config,expected_warn', [ + # max configs = default, max configs < number of configs => warn + (12, 20, False, True), + (12, 20, True, True), + + # max configs != default, max configs < number of configs => warn if --check-config + (6, 20, False, False), + (6, 20, True, True), + + # max configs >= number of configs => no warning + (20, 20, False, False), + (20, 20, False, False) +]) +def test_max_configs(tmp_path, max_configs, number_of_configs, check_config, expected_warn): test_file = tmp_path / 'test.cpp' with open(test_file, "w") as f: - for i in range(1,20): + for i in range(1,number_of_configs): dir = 'if' if i == 1 else 'elif' f.write(f'#{dir} defined(X{i})\nx = {i};\n') f.write('#endif\n') - args = ['--enable=information', '--template=daca2', str(test_file)] + args = [f'--max-configs={max_configs}', '--enable=information', '--template=daca2', str(test_file)] + + if check_config: + args = ['--check-config'] + args # default max configs is set to 12, warn if code contains more configurations than that _, _, stderr = cppcheck(args) - assert stderr.splitlines() == [ - '{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 12 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file) - ] - - # set explicit max configs => do not warn - # configurations are likely skipped by intention - _, _, stderr = cppcheck(['--max-configs=6'] + args) - assert stderr.splitlines() == [] - - # when using --check-configs, warn if code contains more than max configs - _, _, stderr = cppcheck(['--check-config', '--max-configs=6'] + args) - assert stderr.splitlines() == [ - '{}:0:0: information: Too many #ifdef configurations - cppcheck only checks 6 of 20 configurations. Use --force to check all configurations. [toomanyconfigs]'.format(test_file) - ] - - # when using --check-configs, do not warn if code contains less than max configs - _, _, stderr = cppcheck(['--check-config', '--max-configs=60'] + args) - assert stderr.splitlines() == [] + if not expected_warn: + assert stderr.splitlines() == [] + else: + assert stderr.splitlines() == [ + '{}:0:0: information: Too many #ifdef configurations - cppcheck only checks {} of {} configurations. Use --force to check all configurations. [toomanyconfigs]' + .format(test_file, max_configs, number_of_configs) + ] From ecb1cf2cd078be32aca488475718a14d712d74d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 19 Nov 2025 19:51:30 +0100 Subject: [PATCH 13/13] daca2->simple --- test/cli/other_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index c12b5ef4ce3..26a6fa35e56 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3971,7 +3971,7 @@ def test_max_configs(tmp_path, max_configs, number_of_configs, check_config, exp f.write(f'#{dir} defined(X{i})\nx = {i};\n') f.write('#endif\n') - args = [f'--max-configs={max_configs}', '--enable=information', '--template=daca2', str(test_file)] + args = [f'--max-configs={max_configs}', '--enable=information', '--template=simple', str(test_file)] if check_config: args = ['--check-config'] + args