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 4, 2024
1 parent a6cc9b2 commit fd092bc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
9 changes: 9 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;
}
const 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,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 @@ -896,6 +904,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;

const std::string getLibraryDumpData();

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

0 comments on commit fd092bc

Please sign in to comment.