Skip to content

Commit c0a066d

Browse files
authored
fixed #13859 - added test for toomanyconfigs (#7898)
1 parent ef902a8 commit c0a066d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/testcppcheck.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class TestCppcheck : public TestFixture {
8181
TEST_CASE(getDumpFileContentsRawTokens);
8282
TEST_CASE(getDumpFileContentsLibrary);
8383
TEST_CASE(premiumResultsCache);
84+
TEST_CASE(toomanyconfigs);
8485
}
8586

8687
void getErrorMessages() const {
@@ -556,6 +557,35 @@ class TestCppcheck : public TestFixture {
556557
ASSERT(hash1 != hash2);
557558
}
558559

560+
void toomanyconfigs() const
561+
{
562+
ScopedFile test_file_a("a.c",
563+
"#if DEF_1\n"
564+
"#endif\n"
565+
"#if DEF_2\n"
566+
"#endif\n"
567+
"#if DEF_3\n"
568+
"#endif");
569+
570+
// this is the "simple" format
571+
const auto s = dinit(Settings,
572+
$.templateFormat = templateFormat, // TODO: remove when we only longer rely on toString() in unique message handling
573+
$.severity.enable (Severity::information);
574+
$.maxConfigs = 2);
575+
Suppressions supprs;
576+
ErrorLogger2 errorLogger;
577+
CppCheck cppcheck(s, supprs, errorLogger, false, {});
578+
ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(test_file_a.path(), Path::identify(test_file_a.path(), false), 0)));
579+
// TODO: how to properly disable these warnings?
580+
errorLogger.errmsgs.erase(std::remove_if(errorLogger.errmsgs.begin(), errorLogger.errmsgs.end(), [](const ErrorMessage& msg) {
581+
return msg.id == "logChecker";
582+
}), errorLogger.errmsgs.end());
583+
// the internal errorlist is cleared after each check() call
584+
ASSERT_EQUALS(1, errorLogger.errmsgs.size());
585+
const auto it = errorLogger.errmsgs.cbegin();
586+
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, ""));
587+
}
588+
559589
// TODO: test suppressions
560590
// TODO: test all with FS
561591
};

0 commit comments

Comments
 (0)