xml results: added a command line switch for generating simple results.xml file

This commit is contained in:
Daniel Marjamäki 2009-01-28 17:12:43 +00:00
parent 12b6cf8c70
commit 0ca38cc9fe
3 changed files with 26 additions and 0 deletions

View File

@ -95,6 +95,10 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
else if (strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "--force") == 0)
_settings._force = true;
// Write results in results.xml
else if (strcmp(argv[i], "--xml-results") == 0)
_settings._xmlResults = true;
// Print help
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
{
@ -272,6 +276,24 @@ unsigned int CppCheck::check()
_checkFunctionUsage.check();
}
// xml results..
if (_settings._xmlResults)
{
std::ofstream fxml("results.xml");
fxml << "<cppcheckResults>\n"
<< " <test result=\"" << (_errorList.empty() ? "OK" : "ERROR") << "\"/>\n"
<< " <name>cppcheck</name>\n";
if (_errorList.size())
{
fxml << " <message>\n";
for (std::list<std::string>::const_iterator it = _errorList.begin(); it != _errorList.end(); ++it)
fxml << *it << "\n";
fxml << " </message>\n";
}
fxml << " </test>\n"
<< "</cppcheckResults>\n";
}
unsigned int result = _errorList.size();
_errorList.clear();
return result;

View File

@ -27,6 +27,7 @@ Settings::Settings()
_errorsOnly = false;
_verbose = false;
_force = false;
_xmlResults = false;
}
Settings::~Settings()

View File

@ -39,6 +39,9 @@ public:
/** Force checking t he files with "too many" configurations. */
bool _force;
/** write results in xml file results.xml */
bool _xmlResults;
};
#endif // SETTINGS_H