Merge branch 'xml2' of github.com:danmar/cppcheck
This commit is contained in:
commit
1f1df0645b
|
@ -167,6 +167,15 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
else if (strcmp(argv[i], "--xml") == 0)
|
||||
_settings->_xml = true;
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Experimental: Write results in xml2 format
|
||||
else if (strcmp(argv[i], "--xmlver=2") == 0)
|
||||
{
|
||||
_settings->_xml = true;
|
||||
_settings->_xml_version = 2;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Only print something when there are errors
|
||||
else if (strcmp(argv[i], "-q") == 0 || strcmp(argv[i], "--quiet") == 0)
|
||||
_settings->_errorsOnly = true;
|
||||
|
|
|
@ -95,7 +95,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
|
|||
_settings = cppCheck.settings();
|
||||
if (_settings._xml)
|
||||
{
|
||||
reportErr(ErrorLogger::ErrorMessage::getXMLHeader());
|
||||
reportErr(ErrorLogger::ErrorMessage::getXMLHeader(_settings._xml_version));
|
||||
}
|
||||
|
||||
unsigned int returnValue = 0;
|
||||
|
@ -184,7 +184,7 @@ void CppCheckExecutor::reportErr(const ErrorLogger::ErrorMessage &msg)
|
|||
{
|
||||
if (_settings._xml)
|
||||
{
|
||||
reportErr(msg.toXML(_settings._verbose));
|
||||
reportErr(msg.toXML(_settings._verbose, _settings._xml_version));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -110,7 +110,7 @@ public:
|
|||
*/
|
||||
static void reportError(const ErrorLogger::ErrorMessage &errmsg)
|
||||
{
|
||||
std::cout << errmsg.toXML(true) << std::endl;
|
||||
std::cout << errmsg.toXML(true, 1) << std::endl;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
|
@ -363,7 +363,7 @@ void CppCheck::reportStatus(unsigned int /*index*/, unsigned int /*max*/)
|
|||
void CppCheck::getErrorMessages()
|
||||
{
|
||||
// call all "getErrorMessages" in all registered Check classes
|
||||
std::cout << ErrorLogger::ErrorMessage::getXMLHeader();
|
||||
std::cout << ErrorLogger::ErrorMessage::getXMLHeader(1);
|
||||
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
|
||||
{
|
||||
(*it)->getErrorMessages();
|
||||
|
|
|
@ -129,10 +129,14 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string ErrorLogger::ErrorMessage::getXMLHeader()
|
||||
std::string ErrorLogger::ErrorMessage::getXMLHeader(int version)
|
||||
{
|
||||
std::ostringstream strver;
|
||||
if (version > 1)
|
||||
strver << " version=\"" << version << "\"";
|
||||
|
||||
return "<?xml version=\"1.0\"?>\n"
|
||||
"<results>";
|
||||
"<results" + strver.str() + ">";
|
||||
}
|
||||
|
||||
std::string ErrorLogger::ErrorMessage::getXMLFooter()
|
||||
|
@ -161,19 +165,43 @@ static std::string stringToXml(std::string s)
|
|||
return s;
|
||||
}
|
||||
|
||||
std::string ErrorLogger::ErrorMessage::toXML(bool verbose) const
|
||||
std::string ErrorLogger::ErrorMessage::toXML(bool verbose, int version) const
|
||||
{
|
||||
std::ostringstream xml;
|
||||
xml << "<error";
|
||||
if (!_callStack.empty())
|
||||
|
||||
if (version == 1)
|
||||
{
|
||||
xml << " file=\"" << stringToXml(_callStack.back().getfile()) << "\"";
|
||||
xml << " line=\"" << _callStack.back().line << "\"";
|
||||
xml << "<error";
|
||||
if (!_callStack.empty())
|
||||
{
|
||||
xml << " file=\"" << stringToXml(_callStack.back().getfile()) << "\"";
|
||||
xml << " line=\"" << _callStack.back().line << "\"";
|
||||
}
|
||||
xml << " id=\"" << _id << "\"";
|
||||
xml << " severity=\"" << (_severity == Severity::error ? "error" : "style") << "\"";
|
||||
xml << " msg=\"" << stringToXml(verbose ? _verboseMessage : _shortMessage) << "\"";
|
||||
xml << "/>";
|
||||
}
|
||||
xml << " id=\"" << _id << "\"";
|
||||
xml << " severity=\"" << (_severity == Severity::error ? "error" : "style") << "\"";
|
||||
xml << " msg=\"" << stringToXml(verbose ? _verboseMessage : _shortMessage) << "\"";
|
||||
xml << "/>";
|
||||
else if (version == 2)
|
||||
{
|
||||
xml << " <error";
|
||||
xml << " id=\"" << _id << "\"";
|
||||
xml << " severity=\"" << Severity::toString(_severity) << "\"";
|
||||
xml << " msg=\"" << stringToXml(_shortMessage) << "\"";
|
||||
xml << " verbose=\"" << stringToXml(_verboseMessage) << "\"";
|
||||
xml << ">" << std::endl;
|
||||
|
||||
for (std::list<FileLocation>::const_reverse_iterator it = _callStack.rbegin(); it != _callStack.rend(); ++it)
|
||||
{
|
||||
xml << " <location";
|
||||
xml << " file=\"" << stringToXml((*it).getfile()) << "\"";
|
||||
xml << " line=\"" << (*it).line << "\"";
|
||||
xml << "/>" << std::endl;
|
||||
}
|
||||
|
||||
xml << " </error>";
|
||||
}
|
||||
|
||||
return xml.str();
|
||||
}
|
||||
|
||||
|
|
|
@ -124,10 +124,11 @@ public:
|
|||
/**
|
||||
* Format the error message in XML format
|
||||
* @param verbose use verbose message
|
||||
* @param ver xml version
|
||||
*/
|
||||
std::string toXML(bool verbose) const;
|
||||
std::string toXML(bool verbose, int ver) const;
|
||||
|
||||
static std::string getXMLHeader();
|
||||
static std::string getXMLHeader(int ver);
|
||||
static std::string getXMLFooter();
|
||||
|
||||
/**
|
||||
|
|
|
@ -2409,11 +2409,11 @@ void Preprocessor::getErrorMessages(std::ostream &ostr)
|
|||
Severity::style,
|
||||
"Include file: \"\" not found.",
|
||||
"missingInclude");
|
||||
ostr << errmsg.toXML(false) << std::endl;
|
||||
ostr << errmsg.toXML(false, 1) << std::endl;
|
||||
|
||||
const ErrorLogger::ErrorMessage errmsg2(locationList,
|
||||
Severity::error,
|
||||
"#error ...",
|
||||
"preprocessorErrorDirective");
|
||||
ostr << errmsg2.toXML(false) << std::endl;
|
||||
ostr << errmsg2.toXML(false, 1) << std::endl;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ Settings::Settings()
|
|||
_verbose = false;
|
||||
_force = false;
|
||||
_xml = false;
|
||||
_xml_version = 1;
|
||||
_jobs = 1;
|
||||
_exitCode = 0;
|
||||
_showtime = 0; // TODO: use enum
|
||||
|
|
|
@ -87,6 +87,9 @@ public:
|
|||
/** @brief write xml results (--xml) */
|
||||
bool _xml;
|
||||
|
||||
/** @brief xml version (--xmlver=..) */
|
||||
bool _xml_version;
|
||||
|
||||
/** @brief How many processes/threads should do checking at the same
|
||||
time. Default is 1. (-j N) */
|
||||
unsigned int _jobs;
|
||||
|
|
|
@ -389,7 +389,7 @@ private:
|
|||
// Test the errorlogger..
|
||||
ErrorLogger::ErrorMessage errorMessage;
|
||||
errorMessage.setmsg("ab<cd>ef");
|
||||
ASSERT_EQUALS("<error id=\"\" severity=\"style\" msg=\"ab<cd>ef\"/>", errorMessage.toXML(false));
|
||||
ASSERT_EQUALS("<error id=\"\" severity=\"style\" msg=\"ab<cd>ef\"/>", errorMessage.toXML(false,1));
|
||||
}
|
||||
|
||||
|
||||
|
@ -400,7 +400,7 @@ private:
|
|||
loc.setfile("ab/cd/../ef.h");
|
||||
errorMessage._callStack.push_back(loc);
|
||||
const std::string fname(Path::toNativeSeparators("ab/ef.h"));
|
||||
ASSERT_EQUALS("<error file=\"" + fname + "\" line=\"0\" id=\"\" severity=\"style\" msg=\"\"/>", errorMessage.toXML(false));
|
||||
ASSERT_EQUALS("<error file=\"" + fname + "\" line=\"0\" id=\"\" severity=\"style\" msg=\"\"/>", errorMessage.toXML(false,1));
|
||||
ASSERT_EQUALS("[" + fname + ":0]: ", errorMessage.toString(false));
|
||||
}
|
||||
|
||||
|
@ -415,7 +415,7 @@ private:
|
|||
errorMessage._severity = Severity::fromString("error");
|
||||
errorMessage.setmsg("long testMessage");
|
||||
const std::string fname(Path::toNativeSeparators("some/{file}file.cpp"));
|
||||
ASSERT_EQUALS("<error file=\"" + fname + "\" line=\"10\" id=\"testId\" severity=\"error\" msg=\"long testMessage\"/>", errorMessage.toXML(false));
|
||||
ASSERT_EQUALS("<error file=\"" + fname + "\" line=\"10\" id=\"testId\" severity=\"error\" msg=\"long testMessage\"/>", errorMessage.toXML(false,1));
|
||||
ASSERT_EQUALS("[" + fname + ":10]: (error) long testMessage", errorMessage.toString(false));
|
||||
ASSERT_EQUALS("testId-" + fname + ",error.10?{long testMessage}", errorMessage.toString(false, "{id}-{file},{severity}.{line}?{{message}}"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue