Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,14 @@ static bool reportClangErrors(std::istream &is, const std::function<void(const E
return false;
}

std::string CppCheck::getLibraryDumpData() const {
std::string out;
for (const std::string &s : mSettings.libraries) {
out += " <library lib=\"" + s + "\"/>\n";
}
return out;
}

unsigned int CppCheck::checkClang(const FileWithDetails &file)
{
if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mUnusedFunctionsCheck)
Expand Down Expand Up @@ -520,6 +528,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 << getLibraryDumpData();
tokenizer.dump(fdump);
fdump << "</dump>\n";
fdump << "</dumps>\n";
Expand Down Expand Up @@ -902,6 +911,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 << getLibraryDumpData();
preprocessor.dump(fdump);
tokenizer.dump(fdump);
fdump << "</dump>" << std::endl;
Expand Down
2 changes: 2 additions & 0 deletions lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
*/
std::string getDumpFileContentsRawTokens(const std::vector<std::string>& files, const simplecpp::TokenList& tokens1) const;

std::string getLibraryDumpData() const;

private:
#ifdef HAVE_RULES
/** Are there "simple" rules */
Expand Down
13 changes: 13 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,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<std::string> files{ "/some/path/test.cpp" };
const std::string expected1 = " <library lib=\"std.cfg\"/>\n";
ASSERT_EQUALS(expected1, cppcheck.getLibraryDumpData());
cppcheck.settings().libraries.emplace_back("posix.cfg");
const std::string expected2 = " <library lib=\"std.cfg\"/>\n <library lib=\"posix.cfg\"/>\n";
ASSERT_EQUALS(expected2, cppcheck.getLibraryDumpData());
}

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