diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 63d85b1de3b..80c79f7d32d 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -413,6 +413,14 @@ static bool reportClangErrors(std::istream &is, const std::function\n"; + } + return out; +} + unsigned int CppCheck::checkClang(const FileWithDetails &file) { if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mUnusedFunctionsCheck) @@ -520,6 +528,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file) fdump << " \n"; fdump << " \n"; fdump << " \n"; + fdump << getLibraryDumpData(); tokenizer.dump(fdump); fdump << "\n"; fdump << "\n"; @@ -902,6 +911,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string fdump << " " << std::endl; fdump << " " << std::endl; fdump << " " << std::endl; + fdump << getLibraryDumpData(); preprocessor.dump(fdump); tokenizer.dump(fdump); fdump << "" << std::endl; diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 50281bee8e2..373f3d7731e 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -162,6 +162,8 @@ class CPPCHECKLIB CppCheck : ErrorLogger { */ std::string getDumpFileContentsRawTokens(const std::vector& files, const simplecpp::TokenList& tokens1) const; + std::string getLibraryDumpData() const; + private: #ifdef HAVE_RULES /** Are there "simple" rules */ diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index 5663bb7b3b5..58ae75b8ede 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -59,6 +59,7 @@ class TestCppcheck : public TestFixture { TEST_CASE(unique_errors); TEST_CASE(isPremiumCodingStandardId); TEST_CASE(getDumpFileContentsRawTokens); + TEST_CASE(getDumpFileContentsLibrary); } void getErrorMessages() const { @@ -222,6 +223,18 @@ class TestCppcheck : public TestFixture { ASSERT_EQUALS(expected, cppcheck.getDumpFileContentsRawTokens(files, tokens1)); } + void getDumpFileContentsLibrary() const { + ErrorLogger2 errorLogger; + CppCheck cppcheck(errorLogger, false, {}); + cppcheck.settings().libraries.emplace_back("std.cfg"); + std::vector files{ "/some/path/test.cpp" }; + const std::string expected1 = " \n"; + ASSERT_EQUALS(expected1, cppcheck.getLibraryDumpData()); + cppcheck.settings().libraries.emplace_back("posix.cfg"); + const std::string expected2 = " \n \n"; + ASSERT_EQUALS(expected2, cppcheck.getLibraryDumpData()); + } + // TODO: test suppressions // TODO: test all with FS };