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 b888d8b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,13 @@ static bool reportClangErrors(std::istream &is, const std::function<void(const E
}
return false;
}
std::string CppCheck::getLibraryDumpData() {
std::string out;
for (const std::string s : mSettings.libraries) {
out += " <library lib=\"" + s + "\"/>\n";
}
return out;
}

unsigned int CppCheck::checkClang(const FileWithDetails &file)
{
Expand Down Expand Up @@ -520,6 +527,9 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
fdump << " <c version=\"" << mSettings.standards.getC() << "\"/>\n";
fdump << " <cpp version=\"" << mSettings.standards.getCPP() << "\"/>\n";
fdump << " </standards>\n";
const std::string libs = getLibraryDumpData();
if (!libs.empty())
fdump << libs;
tokenizer.dump(fdump);
fdump << "</dump>\n";
fdump << "</dumps>\n";
Expand Down Expand Up @@ -896,6 +906,9 @@ 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;
const std::string libs = getLibraryDumpData();
if (!libs.empty())
fdump << libs;
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();

private:
#ifdef HAVE_RULES
/** Are there "simple" rules */
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\"/>\n";
ASSERT_EQUALS(expected, cppcheck.getLibraryDumpData());
}

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

0 comments on commit b888d8b

Please sign in to comment.