Skip to content

Commit 55cd437

Browse files
committed
Moved UT validation to getErrorMessages UT
1 parent e83d024 commit 55cd437

2 files changed

Lines changed: 7 additions & 79 deletions

File tree

lib/cppcheck.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,9 +1686,6 @@ void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfCo
16861686
msg << " of " << numberOfConfigurations << " configurations. Use --force to check all configurations.\n";
16871687
else if (file.empty())
16881688
msg << " configurations. Use --force to check all configurations. For more details, use --enable=information.\n";
1689-
else
1690-
msg << " configurations.\n";
1691-
16921689
msg << "The checking of the file will be interrupted because there are too many "
16931690
"#ifdef configurations. Checking of all #ifdef configurations can be forced "
16941691
"by --force command line option or from GUI preferences. However that may "

test/testcppcheck.cpp

Lines changed: 7 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class TestCppcheck : public TestFixture {
7979
TEST_CASE(isPremiumCodingStandardId);
8080
TEST_CASE(getDumpFileContentsRawTokens);
8181
TEST_CASE(getDumpFileContentsLibrary);
82-
TEST_CASE(tooManyConfigsError);
8382
TEST_CASE(checkPlistOutput);
8483
TEST_CASE(premiumResultsCache);
8584
TEST_CASE(toomanyconfigs);
@@ -90,6 +89,13 @@ class TestCppcheck : public TestFixture {
9089
ErrorLogger2 errorLogger;
9190
CppCheck::getErrorMessages(errorLogger);
9291
ASSERT(!errorLogger.ids.empty());
92+
ASSERT(!errorLogger.errmsgs.empty());
93+
94+
const auto it = std::next(errorLogger.errmsgs.cbegin());
95+
const std::string shortMsg = it->toString(false, templateFormat, "");
96+
const std::string debugMsg = it->toString(true, templateFormat, "");
97+
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]");
98+
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]");
9399

94100
// Check if there are duplicate error ids in errorLogger.id
95101
std::string duplicate;
@@ -524,81 +530,6 @@ class TestCppcheck : public TestFixture {
524530
}
525531
}
526532

527-
void tooManyConfigsError() const {
528-
Suppressions supprs;
529-
ErrorLogger2 errorLogger;
530-
531-
{
532-
const Settings s;
533-
CppCheck cppcheck(s, supprs, errorLogger, false, {});
534-
cppcheck.tooManyConfigsError("file", 0);
535-
ASSERT_EQUALS(0, errorLogger.errmsgs.size());
536-
}
537-
538-
{
539-
const auto s = dinit(Settings, $.severity.enable (Severity::information));
540-
CppCheck cppcheck(s, supprs, errorLogger, false, {});
541-
cppcheck.tooManyConfigsError("", 0);
542-
ASSERT_EQUALS(0, errorLogger.errmsgs.size());
543-
}
544-
545-
const std::string forceFlagInstruction {"The checking of the file will be interrupted because there are too many "
546-
"#ifdef configurations. Checking of all #ifdef configurations can be forced "
547-
"by --force command line option or from GUI preferences. However that may "
548-
"increase the checking time."};
549-
550-
{
551-
const auto s = dinit(Settings, $.templateFormat = templateFormat, $.severity.enable (Severity::information));
552-
CppCheck cppcheck(s, supprs, errorLogger, false, {});
553-
554-
const int numberOfConfigurations = s.maxConfigs+1;
555-
cppcheck.tooManyConfigsError("file", numberOfConfigurations);
556-
557-
ASSERT_EQUALS(1, errorLogger.errmsgs.size());
558-
auto it = errorLogger.errmsgs.cbegin();
559-
const std::string shortMsg = it->toString(false, templateFormat, "");
560-
const std::string debugMsg = it->toString(true, templateFormat, "");
561-
562-
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]");
563-
ASSERT_EQUALS(debugMsg, "file:0:0: information: " + forceFlagInstruction + " [toomanyconfigs]");
564-
errorLogger.errmsgs.clear();
565-
}
566-
567-
{
568-
const auto s = dinit(Settings, $.templateFormat = templateFormat);
569-
CppCheck cppcheck(s, supprs, errorLogger, false, {});
570-
cppcheck.mTooManyConfigs = true;
571-
572-
cppcheck.tooManyConfigsError("", 0);
573-
574-
ASSERT_EQUALS(1, errorLogger.errmsgs.size());
575-
auto it = errorLogger.errmsgs.cbegin();
576-
const std::string shortMsg = it->toString(false, templateFormat, "");
577-
const std::string debugMsg = it->toString(true, templateFormat, "");
578-
579-
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]");
580-
ASSERT_EQUALS(debugMsg, "nofile:0:0: information: " + forceFlagInstruction + " For more details, use --enable=information. [toomanyconfigs]");
581-
errorLogger.errmsgs.clear();
582-
}
583-
584-
{
585-
const auto s = dinit(Settings, $.templateFormat = templateFormat, $.severity.enable (Severity::information));
586-
CppCheck cppcheck(s, supprs, errorLogger, false, {});
587-
cppcheck.mTooManyConfigs = true;
588-
589-
cppcheck.tooManyConfigsError("file", 0);
590-
591-
ASSERT_EQUALS(1, errorLogger.errmsgs.size());
592-
auto it = errorLogger.errmsgs.cbegin();
593-
const std::string shortMsg = it->toString(false, templateFormat, "");
594-
const std::string debugMsg = it->toString(true, templateFormat, "");
595-
596-
ASSERT_EQUALS(shortMsg, "file:0:0: information: Too many #ifdef configurations - cppcheck only checks " + std::to_string(s.maxConfigs) + " configurations. [toomanyconfigs]");
597-
ASSERT_EQUALS(debugMsg, "file:0:0: information: " + forceFlagInstruction + " [toomanyconfigs]");
598-
errorLogger.errmsgs.clear();
599-
}
600-
}
601-
602533
void checkPlistOutput() const {
603534
Suppressions supprs;
604535
ErrorLogger2 errorLogger;

0 commit comments

Comments
 (0)