xml2: added <errors> element

This commit is contained in:
Daniel Marjamäki 2011-02-02 18:46:07 +01:00
parent 26b21a5ae0
commit 9a383388be
4 changed files with 9 additions and 8 deletions

View File

@ -55,7 +55,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
errorlist = true;
std::cout << ErrorLogger::ErrorMessage::getXMLHeader(_settings._xml_version);
cppcheck->getErrorMessages();
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
std::cout << ErrorLogger::ErrorMessage::getXMLFooter(_settings._xml_version) << std::endl;
}
if (parser.ExitAfterPrinting())
@ -141,7 +141,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
if (_settings._xml)
{
reportErr(ErrorLogger::ErrorMessage::getXMLFooter());
reportErr(ErrorLogger::ErrorMessage::getXMLFooter(_settings._xml_version));
}
if (returnValue)

View File

@ -162,15 +162,16 @@ std::string ErrorLogger::ErrorMessage::getXMLHeader(int xml_version)
else
{
ostr << "<results version=\"" << xml_version << "\">\n";
ostr << " <cppcheck version=\"" << CppCheck::version() << "\"/>";
ostr << " <cppcheck version=\"" << CppCheck::version() << "\"/>\n";
ostr << " <errors>";
}
return ostr.str();
}
std::string ErrorLogger::ErrorMessage::getXMLFooter()
std::string ErrorLogger::ErrorMessage::getXMLFooter(int xml_version)
{
return "</results>";
return (xml_version<=1) ? "</results>" : " </errors>\n</results>";
}
static std::string stringToXml(std::string s)

View File

@ -137,7 +137,7 @@ public:
std::string toXML(bool verbose, int ver) const;
static std::string getXMLHeader(int xml_version);
static std::string getXMLFooter();
static std::string getXMLFooter(int xml_version);
/**
* Format the error message into a string.

View File

@ -124,7 +124,7 @@ private:
locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId");
ASSERT_EQUALS("<?xml version=\"1.0\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter());
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
ASSERT_EQUALS("<error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Programming error.\"/>", msg.toXML(false,1));
}
@ -137,7 +137,7 @@ private:
locs.push_back(loc);
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId");
ASSERT_EQUALS("<?xml version=\"1.0\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter());
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
ASSERT_EQUALS("<error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Verbose error\"/>", msg.toXML(true,1));
}
};