Skip to content

Commit

Permalink
Fix 12463: dumpfile: what library are used
Browse files Browse the repository at this point in the history
  • Loading branch information
swasti16 committed Jul 3, 2024
1 parent a6cc9b2 commit 77f6647
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
fdump << " <c version=\"" << mSettings.standards.getC() << "\"/>\n";
fdump << " <cpp version=\"" << mSettings.standards.getCPP() << "\"/>\n";
fdump << " </standards>\n";
fdump << " <library lib="<< mSettings.getLib() << "/>\n";
tokenizer.dump(fdump);
fdump << "</dump>\n";
fdump << "</dumps>\n";
Expand Down Expand Up @@ -896,6 +897,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
fdump << " <c version=\"" << mSettings.standards.getC() << "\"/>" << std::endl;
fdump << " <cpp version=\"" << mSettings.standards.getCPP() << "\"/>" << std::endl;
fdump << " </standards>" << std::endl;
fdump << " <library lib=\"" << mSettings.getLib() << "\"/>\n";
preprocessor.dump(fdump);
tokenizer.dump(fdump);
fdump << "</dump>" << std::endl;
Expand Down Expand Up @@ -1925,3 +1927,9 @@ std::string CppCheck::getDumpFileContentsRawTokens(const std::vector<std::string
dumpProlog += " </rawtokens>\n";
return dumpProlog;
}

std::string CppCheck::getDumpFileContentsLib(void) {
std::string dumpProlog;
dumpProlog += " <library lib=\"" + mSettings.getLib() + "\"/>";
return dumpProlog;
}
5 changes: 5 additions & 0 deletions lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
*/
std::string getDumpFileContentsRawTokens(const std::vector<std::string>& files, const simplecpp::TokenList& tokens1) const;

/**
* @brief Get dumpfile <library> contents, this is only public for testing purposes
*/
std::string getDumpFileContentsLib(void);

private:
#ifdef HAVE_RULES
/** Are there "simple" rules */
Expand Down
11 changes: 11 additions & 0 deletions lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions test/testcppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class TestCppcheck : public TestFixture {
TEST_CASE(unique_errors);
TEST_CASE(isPremiumCodingStandardId);
TEST_CASE(getDumpFileContentsRawTokens);
TEST_CASE(getDumpFileContentsLibrary);
}

void getErrorMessages() const {
Expand Down Expand Up @@ -222,6 +223,15 @@ 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<std::string> files{ "/some/path/test.cpp" };
const std::string expected = " <library lib=\"std.cfg\"/>";
ASSERT_EQUALS(expected, cppcheck.getDumpFileContentsLib());
}

// TODO: test suppressions
// TODO: test all with FS
};
Expand Down

0 comments on commit 77f6647

Please sign in to comment.