Skip to content

Commit e83d024

Browse files
committed
Add UT for tooManyConfigsError function
1 parent eeed606 commit e83d024

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

lib/cppcheck.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,9 @@ 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+
16891692
msg << "The checking of the file will be interrupted because there are too many "
16901693
"#ifdef configurations. Checking of all #ifdef configurations can be forced "
16911694
"by --force command line option or from GUI preferences. However that may "

test/testcppcheck.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class TestCppcheck : public TestFixture {
7979
TEST_CASE(isPremiumCodingStandardId);
8080
TEST_CASE(getDumpFileContentsRawTokens);
8181
TEST_CASE(getDumpFileContentsLibrary);
82+
TEST_CASE(tooManyConfigsError);
8283
TEST_CASE(checkPlistOutput);
8384
TEST_CASE(premiumResultsCache);
8485
TEST_CASE(toomanyconfigs);
@@ -523,6 +524,81 @@ class TestCppcheck : public TestFixture {
523524
}
524525
}
525526

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+
526602
void checkPlistOutput() const {
527603
Suppressions supprs;
528604
ErrorLogger2 errorLogger;

0 commit comments

Comments
 (0)