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 a9c4821
Show file tree
Hide file tree
Showing 2 changed files with 18 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;
}
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(getDumpFileContentsLib);
}

void getErrorMessages() const {
Expand Down Expand Up @@ -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<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 a9c4821

Please sign in to comment.