From e98bd7b9ccfdd68dc22e227535b3e3915bd76c15 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 | 8 ++++++++ lib/cppcheck.h | 5 +++++ lib/settings.h | 11 +++++++++++ test/testcppcheck.cpp | 10 ++++++++++ 4 files changed, 34 insertions(+) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 45fbb89678d3..e6f5562ebdc9 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -520,6 +520,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file) fdump << " \n"; fdump << " \n"; fdump << " \n"; + fdump << " \n"; tokenizer.dump(fdump); fdump << "\n"; fdump << "\n"; @@ -896,6 +897,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string fdump << " " << std::endl; fdump << " " << std::endl; fdump << " " << std::endl; + fdump << " \n"; preprocessor.dump(fdump); tokenizer.dump(fdump); fdump << "" << std::endl; @@ -1925,3 +1927,9 @@ std::string CppCheck::getDumpFileContentsRawTokens(const std::vector"; + return dumpProlog; +} diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 50281bee8e26..91530b830093 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -162,6 +162,11 @@ class CPPCHECKLIB CppCheck : ErrorLogger { */ std::string getDumpFileContentsRawTokens(const std::vector& files, const simplecpp::TokenList& tokens1) const; + /** + * @brief Get dumpfile contents, this is only public for testing purposes + */ + std::string getDumpFileContentsLib(void); + private: #ifdef HAVE_RULES /** Are there "simple" rules */ diff --git a/lib/settings.h b/lib/settings.h index 7fa2918a15f4..eeb8862cb66f 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -471,6 +471,17 @@ class CPPCHECKLIB WARN_UNUSED Settings { return std::find(libraries.cbegin(), libraries.cend(), lib) != libraries.cend(); } + /** Return List of all libs specified */ + const std::string getLib(void) const { + std::string libs; + for (const std::string& l : libraries) { + libs += l + " "; + } + if (!libs.empty()) + libs.pop_back(); + return libs; + } + /** @brief Request termination of checking */ static void terminate(bool t = true) { Settings::mTerminated = t; diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index 5663bb7b3b55..d0aef03828b2 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(getDumpFileContentsLib); } void getErrorMessages() const { @@ -222,6 +223,15 @@ class TestCppcheck : public TestFixture { ASSERT_EQUALS(expected, cppcheck.getDumpFileContentsRawTokens(files, tokens1)); } + void getDumpFileContentsLib() const { + ErrorLogger2 errorLogger; + CppCheck cppcheck(errorLogger, false, {}); + cppcheck.settings().libraries.emplace_back("std.cfg"); + std::vector files{ "/some/path/test.cpp" }; + const std::string expected = " "; + ASSERT_EQUALS(expected, cppcheck.getDumpFileContentsLib()); + } + // TODO: test suppressions // TODO: test all with FS };