diff --git a/cli/cppcheckexecutor.h b/cli/cppcheckexecutor.h index 5ef743ef20d..a063a795241 100644 --- a/cli/cppcheckexecutor.h +++ b/cli/cppcheckexecutor.h @@ -39,8 +39,6 @@ struct Suppressions; */ class CppCheckExecutor { public: - friend class TestSuppressions; - /** * Constructor */ @@ -61,17 +59,16 @@ class CppCheckExecutor { */ int check(int argc, const char* const argv[]); -private: +protected: /** * Execute a shell command and read the output from it. Returns exitcode of the executed command,. */ static int executeCommand(std::string exe, std::vector args, std::string redirect, std::string &output_); -protected: - static bool reportUnmatchedSuppressions(const Settings &settings, const SuppressionList& suppressions, const std::list &files, const std::list& fileSettings, ErrorLogger& errorLogger); +private: /** * Wrapper around check_internal * - installs optional platform dependent signal handling diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index 58ee72f28b3..61bb0f9cc1a 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -46,6 +46,11 @@ class TestSuppressions : public TestFixture { private: + class CppCheckExecutorTest final : public CppCheckExecutor + { + friend class TestSuppressions; + }; + const std::string templateFormat{"{callstack}: ({severity}) {inconclusive:inconclusive: }{message}"}; void run() override { @@ -289,7 +294,7 @@ class TestSuppressions : public TestFixture { SingleExecutor executor(cppCheck, filelist, fileSettings, settings, supprs, *this, nullptr); unsigned int exitCode = executor.check(); - const bool err = CppCheckExecutor::reportUnmatchedSuppressions(settings, supprs.nomsg, filelist, fileSettings, *this); + const bool err = CppCheckExecutorTest::reportUnmatchedSuppressions(settings, supprs.nomsg, filelist, fileSettings, *this); if (err && exitCode == 0) exitCode = 1; @@ -335,10 +340,10 @@ class TestSuppressions : public TestFixture { if (useFS) filelist.clear(); - ThreadExecutor executor(filelist, fileSettings, settings, supprs, *this, nullptr, CppCheckExecutor::executeCommand); + ThreadExecutor executor(filelist, fileSettings, settings, supprs, *this, nullptr, CppCheckExecutorTest::executeCommand); unsigned int exitCode = executor.check(); - const bool err = CppCheckExecutor::reportUnmatchedSuppressions(settings, supprs.nomsg, filelist, fileSettings, *this); + const bool err = CppCheckExecutorTest::reportUnmatchedSuppressions(settings, supprs.nomsg, filelist, fileSettings, *this); if (err && exitCode == 0) exitCode = 1; @@ -385,10 +390,10 @@ class TestSuppressions : public TestFixture { if (useFS) filelist.clear(); - ProcessExecutor executor(filelist, fileSettings, settings, supprs, *this, nullptr, CppCheckExecutor::executeCommand); + ProcessExecutor executor(filelist, fileSettings, settings, supprs, *this, nullptr, CppCheckExecutorTest::executeCommand); unsigned int exitCode = executor.check(); - const bool err = CppCheckExecutor::reportUnmatchedSuppressions(settings, supprs.nomsg, filelist, fileSettings, *this); + const bool err = CppCheckExecutorTest::reportUnmatchedSuppressions(settings, supprs.nomsg, filelist, fileSettings, *this); if (err && exitCode == 0) exitCode = 1; @@ -1534,7 +1539,7 @@ class TestSuppressions : public TestFixture { // No unmatched suppression { SuppressionList suppressions; - ASSERT_EQUALS(false, CppCheckExecutor::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this)); + ASSERT_EQUALS(false, CppCheckExecutorTest::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this)); ASSERT_EQUALS("", errout_str()); } @@ -1543,7 +1548,7 @@ class TestSuppressions : public TestFixture { SuppressionList suppressions; addCheckedSuppression(suppressions, {"abc", "a.c", 10U}); addCheckedSuppression(suppressions, {"unmatchedSuppression", "*", SuppressionList::Suppression::NO_LINE}); - ASSERT_EQUALS(false, CppCheckExecutor::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this)); + ASSERT_EQUALS(false, CppCheckExecutorTest::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this)); ASSERT_EQUALS("", errout_str()); } @@ -1552,7 +1557,7 @@ class TestSuppressions : public TestFixture { SuppressionList suppressions; addCheckedSuppression(suppressions, {"abc", "a.c", 10U}); addCheckedSuppression(suppressions, {"unmatchedSuppression", "", SuppressionList::Suppression::NO_LINE}); - ASSERT_EQUALS(false, CppCheckExecutor::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this)); + ASSERT_EQUALS(false, CppCheckExecutorTest::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this)); ASSERT_EQUALS("", errout_str()); } @@ -1561,7 +1566,7 @@ class TestSuppressions : public TestFixture { SuppressionList suppressions; addCheckedSuppression(suppressions, {"abc", "a.c", 10U}); addCheckedSuppression(suppressions, {"unmatchedSuppression", "a.c", SuppressionList::Suppression::NO_LINE}); - ASSERT_EQUALS(false, CppCheckExecutor::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this)); + ASSERT_EQUALS(false, CppCheckExecutorTest::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this)); ASSERT_EQUALS("", errout_str()); } @@ -1570,7 +1575,7 @@ class TestSuppressions : public TestFixture { SuppressionList suppressions; addCheckedSuppression(suppressions, {"abc", "a.c", 10U}); addCheckedSuppression(suppressions, {"unmatchedSuppression", "a.c", 10U}); - ASSERT_EQUALS(false, CppCheckExecutor::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this)); + ASSERT_EQUALS(false, CppCheckExecutorTest::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this)); ASSERT_EQUALS("", errout_str()); } @@ -1579,7 +1584,7 @@ class TestSuppressions : public TestFixture { SuppressionList suppressions; addCheckedSuppression(suppressions, {"abc", "a.c", 10U}); addCheckedSuppression(suppressions, {"unmatchedSuppression", "b.c", SuppressionList::Suppression::NO_LINE}); - ASSERT_EQUALS(true, CppCheckExecutor::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this)); + ASSERT_EQUALS(true, CppCheckExecutorTest::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this)); ASSERT_EQUALS("[a.c:10:0]: (information) Unmatched suppression: abc [unmatchedSuppression]\n", errout_str()); } @@ -1588,7 +1593,7 @@ class TestSuppressions : public TestFixture { SuppressionList suppressions; addCheckedSuppression(suppressions, {"abc", "a.c", 10U}); addCheckedSuppression(suppressions, {"unmatchedSuppression", "a.c", 1U}); - ASSERT_EQUALS(true, CppCheckExecutor::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this)); + ASSERT_EQUALS(true, CppCheckExecutorTest::reportUnmatchedSuppressions(settingsDefault, suppressions, files, fs, *this)); ASSERT_EQUALS("[a.c:10:0]: (information) Unmatched suppression: abc [unmatchedSuppression]\n", errout_str()); } }