From fd092bc68cc13423fbba834807b23804a25896ef Mon Sep 17 00:00:00 2001 From: swasti16 Date: Wed, 3 Jul 2024 16:55:10 +0530 Subject: [PATCH] Fix 12463: dumpfile: what library are used --- lib/cppcheck.cpp | 9 +++++++++ lib/cppcheck.h | 2 ++ test/testcppcheck.cpp | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 45fbb89678d3..66d845a5da32 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -412,6 +412,13 @@ static bool reportClangErrors(std::istream &is, const std::function\n"; + } + return out; +} unsigned int CppCheck::checkClang(const FileWithDetails &file) { @@ -520,6 +527,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file) fdump << " \n"; fdump << " \n"; fdump << " \n"; + fdump << getLibraryDumpData(); tokenizer.dump(fdump); fdump << "\n"; fdump << "\n"; @@ -896,6 +904,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 50281bee8e26..5de9898d5438 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; + const std::string getLibraryDumpData(); + private: #ifdef HAVE_RULES /** Are there "simple" rules */ diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index 5663bb7b3b55..58ae75b8ede8 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 };