From 5b367d32e19c3f5f2ebea45d67195f531dd48b17 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 | 10 ++++++++++ lib/cppcheck.h | 2 ++ test/testcppcheck.cpp | 13 +++++++++++++ 3 files changed, 25 insertions(+) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 45fbb89678d3..48bccbdc3a0b 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"; @@ -896,6 +905,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..373f3d7731e1 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 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 };