Skip to content

Commit c89574c

Browse files
authored
Fix 12463: dumpfile: what library are used (#6569)
1 parent 5d3b528 commit c89574c

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

lib/cppcheck.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,14 @@ static bool reportClangErrors(std::istream &is, const std::function<void(const E
413413
return false;
414414
}
415415

416+
std::string CppCheck::getLibraryDumpData() const {
417+
std::string out;
418+
for (const std::string &s : mSettings.libraries) {
419+
out += " <library lib=\"" + s + "\"/>\n";
420+
}
421+
return out;
422+
}
423+
416424
unsigned int CppCheck::checkClang(const FileWithDetails &file)
417425
{
418426
if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mUnusedFunctionsCheck)
@@ -520,6 +528,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
520528
fdump << " <c version=\"" << mSettings.standards.getC() << "\"/>\n";
521529
fdump << " <cpp version=\"" << mSettings.standards.getCPP() << "\"/>\n";
522530
fdump << " </standards>\n";
531+
fdump << getLibraryDumpData();
523532
tokenizer.dump(fdump);
524533
fdump << "</dump>\n";
525534
fdump << "</dumps>\n";
@@ -902,6 +911,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
902911
fdump << " <c version=\"" << mSettings.standards.getC() << "\"/>" << std::endl;
903912
fdump << " <cpp version=\"" << mSettings.standards.getCPP() << "\"/>" << std::endl;
904913
fdump << " </standards>" << std::endl;
914+
fdump << getLibraryDumpData();
905915
preprocessor.dump(fdump);
906916
tokenizer.dump(fdump);
907917
fdump << "</dump>" << std::endl;

lib/cppcheck.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
162162
*/
163163
std::string getDumpFileContentsRawTokens(const std::vector<std::string>& files, const simplecpp::TokenList& tokens1) const;
164164

165+
std::string getLibraryDumpData() const;
166+
165167
private:
166168
#ifdef HAVE_RULES
167169
/** Are there "simple" rules */

test/testcppcheck.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class TestCppcheck : public TestFixture {
5959
TEST_CASE(unique_errors);
6060
TEST_CASE(isPremiumCodingStandardId);
6161
TEST_CASE(getDumpFileContentsRawTokens);
62+
TEST_CASE(getDumpFileContentsLibrary);
6263
}
6364

6465
void getErrorMessages() const {
@@ -222,6 +223,18 @@ class TestCppcheck : public TestFixture {
222223
ASSERT_EQUALS(expected, cppcheck.getDumpFileContentsRawTokens(files, tokens1));
223224
}
224225

226+
void getDumpFileContentsLibrary() const {
227+
ErrorLogger2 errorLogger;
228+
CppCheck cppcheck(errorLogger, false, {});
229+
cppcheck.settings().libraries.emplace_back("std.cfg");
230+
std::vector<std::string> files{ "/some/path/test.cpp" };
231+
const std::string expected1 = " <library lib=\"std.cfg\"/>\n";
232+
ASSERT_EQUALS(expected1, cppcheck.getLibraryDumpData());
233+
cppcheck.settings().libraries.emplace_back("posix.cfg");
234+
const std::string expected2 = " <library lib=\"std.cfg\"/>\n <library lib=\"posix.cfg\"/>\n";
235+
ASSERT_EQUALS(expected2, cppcheck.getLibraryDumpData());
236+
}
237+
225238
// TODO: test suppressions
226239
// TODO: test all with FS
227240
};

0 commit comments

Comments
 (0)