From eeed606ddea244efbb4081fccb3886e69cb17a6c Mon Sep 17 00:00:00 2001 From: Goncalo Mao-Cheia Date: Wed, 29 Oct 2025 00:31:16 +0000 Subject: [PATCH 1/3] Update tooManyConfigsError error message to prevent duplication in error message --- lib/cppcheck.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 9c411a8b0af..10e2f3738bf 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1684,7 +1684,7 @@ void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfCo 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()) + else 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 " From e83d024475e523984aa136d331522c326c917a7a Mon Sep 17 00:00:00 2001 From: Goncalo Mao-Cheia Date: Thu, 6 Nov 2025 00:51:20 +0000 Subject: [PATCH 2/3] Add UT for tooManyConfigsError function --- lib/cppcheck.cpp | 3 ++ test/testcppcheck.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 10e2f3738bf..d0d5b6c02ca 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1686,6 +1686,9 @@ void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfCo msg << " of " << numberOfConfigurations << " configurations. Use --force to check all configurations.\n"; else if (file.empty()) msg << " configurations. Use --force to check all configurations. For more details, use --enable=information.\n"; + else + msg << " configurations.\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 " diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index 8535bbfe47c..72e8386a323 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -79,6 +79,7 @@ class TestCppcheck : public TestFixture { TEST_CASE(isPremiumCodingStandardId); TEST_CASE(getDumpFileContentsRawTokens); TEST_CASE(getDumpFileContentsLibrary); + TEST_CASE(tooManyConfigsError); TEST_CASE(checkPlistOutput); TEST_CASE(premiumResultsCache); TEST_CASE(toomanyconfigs); @@ -523,6 +524,81 @@ class TestCppcheck : public TestFixture { } } + void tooManyConfigsError() const { + Suppressions supprs; + ErrorLogger2 errorLogger; + + { + const Settings s; + CppCheck cppcheck(s, supprs, errorLogger, false, {}); + cppcheck.tooManyConfigsError("file", 0); + ASSERT_EQUALS(0, errorLogger.errmsgs.size()); + } + + { + const auto s = dinit(Settings, $.severity.enable (Severity::information)); + CppCheck cppcheck(s, supprs, errorLogger, false, {}); + cppcheck.tooManyConfigsError("", 0); + ASSERT_EQUALS(0, errorLogger.errmsgs.size()); + } + + const std::string forceFlagInstruction {"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."}; + + { + const auto s = dinit(Settings, $.templateFormat = templateFormat, $.severity.enable (Severity::information)); + CppCheck cppcheck(s, supprs, errorLogger, false, {}); + + const int numberOfConfigurations = s.maxConfigs+1; + cppcheck.tooManyConfigsError("file", numberOfConfigurations); + + ASSERT_EQUALS(1, errorLogger.errmsgs.size()); + auto it = errorLogger.errmsgs.cbegin(); + const std::string shortMsg = it->toString(false, templateFormat, ""); + const std::string debugMsg = it->toString(true, templateFormat, ""); + + ASSERT_EQUALS(shortMsg, "file:0:0: information: Too many #ifdef configurations - cppcheck only checks " + std::to_string(s.maxConfigs) + " of " + std::to_string(numberOfConfigurations) + " configurations. Use --force to check all configurations. [toomanyconfigs]"); + ASSERT_EQUALS(debugMsg, "file:0:0: information: " + forceFlagInstruction + " [toomanyconfigs]"); + errorLogger.errmsgs.clear(); + } + + { + const auto s = dinit(Settings, $.templateFormat = templateFormat); + CppCheck cppcheck(s, supprs, errorLogger, false, {}); + cppcheck.mTooManyConfigs = true; + + cppcheck.tooManyConfigsError("", 0); + + ASSERT_EQUALS(1, errorLogger.errmsgs.size()); + auto it = errorLogger.errmsgs.cbegin(); + const std::string shortMsg = it->toString(false, templateFormat, ""); + const std::string debugMsg = it->toString(true, templateFormat, ""); + + ASSERT_EQUALS(shortMsg, "nofile:0:0: information: Too many #ifdef configurations - cppcheck only checks " + std::to_string(s.maxConfigs) + " configurations. Use --force to check all configurations. For more details, use --enable=information. [toomanyconfigs]"); + ASSERT_EQUALS(debugMsg, "nofile:0:0: information: " + forceFlagInstruction + " For more details, use --enable=information. [toomanyconfigs]"); + errorLogger.errmsgs.clear(); + } + + { + const auto s = dinit(Settings, $.templateFormat = templateFormat, $.severity.enable (Severity::information)); + CppCheck cppcheck(s, supprs, errorLogger, false, {}); + cppcheck.mTooManyConfigs = true; + + cppcheck.tooManyConfigsError("file", 0); + + ASSERT_EQUALS(1, errorLogger.errmsgs.size()); + auto it = errorLogger.errmsgs.cbegin(); + const std::string shortMsg = it->toString(false, templateFormat, ""); + const std::string debugMsg = it->toString(true, templateFormat, ""); + + ASSERT_EQUALS(shortMsg, "file:0:0: information: Too many #ifdef configurations - cppcheck only checks " + std::to_string(s.maxConfigs) + " configurations. [toomanyconfigs]"); + ASSERT_EQUALS(debugMsg, "file:0:0: information: " + forceFlagInstruction + " [toomanyconfigs]"); + errorLogger.errmsgs.clear(); + } + } + void checkPlistOutput() const { Suppressions supprs; ErrorLogger2 errorLogger; From 55cd437d46b26478eaba48db2539b474860b9d90 Mon Sep 17 00:00:00 2001 From: Goncalo Mao-Cheia Date: Thu, 6 Nov 2025 20:47:12 +0000 Subject: [PATCH 3/3] Moved UT validation to getErrorMessages UT --- lib/cppcheck.cpp | 3 -- test/testcppcheck.cpp | 83 ++++--------------------------------------- 2 files changed, 7 insertions(+), 79 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index d0d5b6c02ca..10e2f3738bf 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1686,9 +1686,6 @@ void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfCo msg << " of " << numberOfConfigurations << " configurations. Use --force to check all configurations.\n"; else if (file.empty()) msg << " configurations. Use --force to check all configurations. For more details, use --enable=information.\n"; - else - msg << " configurations.\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 " diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index 72e8386a323..a9ef10e79a7 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -79,7 +79,6 @@ class TestCppcheck : public TestFixture { TEST_CASE(isPremiumCodingStandardId); TEST_CASE(getDumpFileContentsRawTokens); TEST_CASE(getDumpFileContentsLibrary); - TEST_CASE(tooManyConfigsError); TEST_CASE(checkPlistOutput); TEST_CASE(premiumResultsCache); TEST_CASE(toomanyconfigs); @@ -90,6 +89,13 @@ class TestCppcheck : public TestFixture { ErrorLogger2 errorLogger; CppCheck::getErrorMessages(errorLogger); ASSERT(!errorLogger.ids.empty()); + ASSERT(!errorLogger.errmsgs.empty()); + + const auto it = std::next(errorLogger.errmsgs.cbegin()); + const std::string shortMsg = it->toString(false, templateFormat, ""); + const std::string debugMsg = it->toString(true, templateFormat, ""); + ASSERT_EQUALS(shortMsg, "nofile:0:0: information: Too many #ifdef configurations - cppcheck only checks 12 configurations. Use --force to check all configurations. For more details, use --enable=information. [toomanyconfigs]"); + ASSERT_EQUALS(debugMsg, "nofile:0:0: information: 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. For more details, use --enable=information. [toomanyconfigs]"); // Check if there are duplicate error ids in errorLogger.id std::string duplicate; @@ -524,81 +530,6 @@ class TestCppcheck : public TestFixture { } } - void tooManyConfigsError() const { - Suppressions supprs; - ErrorLogger2 errorLogger; - - { - const Settings s; - CppCheck cppcheck(s, supprs, errorLogger, false, {}); - cppcheck.tooManyConfigsError("file", 0); - ASSERT_EQUALS(0, errorLogger.errmsgs.size()); - } - - { - const auto s = dinit(Settings, $.severity.enable (Severity::information)); - CppCheck cppcheck(s, supprs, errorLogger, false, {}); - cppcheck.tooManyConfigsError("", 0); - ASSERT_EQUALS(0, errorLogger.errmsgs.size()); - } - - const std::string forceFlagInstruction {"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."}; - - { - const auto s = dinit(Settings, $.templateFormat = templateFormat, $.severity.enable (Severity::information)); - CppCheck cppcheck(s, supprs, errorLogger, false, {}); - - const int numberOfConfigurations = s.maxConfigs+1; - cppcheck.tooManyConfigsError("file", numberOfConfigurations); - - ASSERT_EQUALS(1, errorLogger.errmsgs.size()); - auto it = errorLogger.errmsgs.cbegin(); - const std::string shortMsg = it->toString(false, templateFormat, ""); - const std::string debugMsg = it->toString(true, templateFormat, ""); - - ASSERT_EQUALS(shortMsg, "file:0:0: information: Too many #ifdef configurations - cppcheck only checks " + std::to_string(s.maxConfigs) + " of " + std::to_string(numberOfConfigurations) + " configurations. Use --force to check all configurations. [toomanyconfigs]"); - ASSERT_EQUALS(debugMsg, "file:0:0: information: " + forceFlagInstruction + " [toomanyconfigs]"); - errorLogger.errmsgs.clear(); - } - - { - const auto s = dinit(Settings, $.templateFormat = templateFormat); - CppCheck cppcheck(s, supprs, errorLogger, false, {}); - cppcheck.mTooManyConfigs = true; - - cppcheck.tooManyConfigsError("", 0); - - ASSERT_EQUALS(1, errorLogger.errmsgs.size()); - auto it = errorLogger.errmsgs.cbegin(); - const std::string shortMsg = it->toString(false, templateFormat, ""); - const std::string debugMsg = it->toString(true, templateFormat, ""); - - ASSERT_EQUALS(shortMsg, "nofile:0:0: information: Too many #ifdef configurations - cppcheck only checks " + std::to_string(s.maxConfigs) + " configurations. Use --force to check all configurations. For more details, use --enable=information. [toomanyconfigs]"); - ASSERT_EQUALS(debugMsg, "nofile:0:0: information: " + forceFlagInstruction + " For more details, use --enable=information. [toomanyconfigs]"); - errorLogger.errmsgs.clear(); - } - - { - const auto s = dinit(Settings, $.templateFormat = templateFormat, $.severity.enable (Severity::information)); - CppCheck cppcheck(s, supprs, errorLogger, false, {}); - cppcheck.mTooManyConfigs = true; - - cppcheck.tooManyConfigsError("file", 0); - - ASSERT_EQUALS(1, errorLogger.errmsgs.size()); - auto it = errorLogger.errmsgs.cbegin(); - const std::string shortMsg = it->toString(false, templateFormat, ""); - const std::string debugMsg = it->toString(true, templateFormat, ""); - - ASSERT_EQUALS(shortMsg, "file:0:0: information: Too many #ifdef configurations - cppcheck only checks " + std::to_string(s.maxConfigs) + " configurations. [toomanyconfigs]"); - ASSERT_EQUALS(debugMsg, "file:0:0: information: " + forceFlagInstruction + " [toomanyconfigs]"); - errorLogger.errmsgs.clear(); - } - } - void checkPlistOutput() const { Suppressions supprs; ErrorLogger2 errorLogger;