Skip to content

Commit 0e649a9

Browse files
committed
Add test
1 parent 05f0334 commit 0e649a9

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

test/testcppcheck.cpp

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

8687
void getErrorMessages() const {
@@ -568,7 +569,7 @@ class TestCppcheck : public TestFixture {
568569
// this is the "simple" format
569570
const auto s = dinit(Settings,
570571
$.templateFormat = templateFormat, // TODO: remove when we only longer rely on toString() in unique message handling
571-
$.severity.enable (Severity::information);
572+
$.severity.enable (Severity::information);
572573
$.maxConfigs = 2);
573574
Suppressions supprs;
574575
ErrorLogger2 errorLogger;
@@ -584,6 +585,33 @@ class TestCppcheck : public TestFixture {
584585
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, ""));
585586
}
586587

588+
void purgedConfiguration() const
589+
{
590+
ScopedFile test_file("test.cpp",
591+
"#ifdef X\n"
592+
"#endif\n"
593+
"int main() {}\n");
594+
595+
// this is the "simple" format
596+
const auto s = dinit(Settings,
597+
$.templateFormat = templateFormat, // TODO: remove when we only longer rely on toString() in unique message handling
598+
$.severity.enable (Severity::information);
599+
$.debugwarnings = true);
600+
Suppressions supprs;
601+
ErrorLogger2 errorLogger;
602+
CppCheck cppcheck(s, supprs, errorLogger, false, {});
603+
ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(test_file.path(), Path::identify(test_file.path(), false), 0)));
604+
// TODO: how to properly disable these warnings?
605+
errorLogger.errmsgs.erase(std::remove_if(errorLogger.errmsgs.begin(), errorLogger.errmsgs.end(), [](const ErrorMessage& msg) {
606+
return msg.id == "logChecker";
607+
}), errorLogger.errmsgs.end());
608+
// the internal errorlist is cleared after each check() call
609+
ASSERT_EQUALS(1, errorLogger.errmsgs.size());
610+
auto it = errorLogger.errmsgs.cbegin();
611+
ASSERT_EQUALS("test.cpp:0:0: information: The configuration 'X' was not checked because its code equals another one. [purgedConfiguration]",
612+
it->toString(false, templateFormat, ""));
613+
}
614+
587615
// TODO: test suppressions
588616
// TODO: test all with FS
589617
};

0 commit comments

Comments
 (0)