Imrove --xml-version option parsing.

Allow --xml-version parsing to recognize also version 1 and print
errors about invalid values.
This commit is contained in:
Kimmo Varis 2011-02-02 14:04:50 +02:00
parent 1118b132b9
commit 1da88de932
2 changed files with 32 additions and 3 deletions

View File

@ -210,11 +210,28 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
else if (strcmp(argv[i], "--xml") == 0)
_settings->_xml = true;
// Write results in xml2 format
else if (strcmp(argv[i], "--xml-version=2") == 0)
// Define the XML file version (and enable XML output)
else if (strncmp(argv[i], "--xml-version=", 14) == 0)
{
std::string numberString(argv[i]);
numberString = numberString.substr(14);
std::istringstream iss(numberString);
if (!(iss >> _settings->_xml_version))
{
PrintMessage("cppcheck: argument to '--xml-version' is not a number");
return false;
}
if (_settings->_xml_version < 0 || _settings->_xml_version > 2)
{
// We only have xml versions 1 and 2
PrintMessage("cppcheck: --xml-version can only be 1 or 2.");
return false;
}
// Enable also XML if version is set
_settings->_xml = true;
_settings->_xml_version = 2;
}
// Only print something when there are errors

View File

@ -81,6 +81,7 @@ private:
TEST_CASE(templatesGcc);
TEST_CASE(templatesVs);
TEST_CASE(xml);
TEST_CASE(xmlver1);
TEST_CASE(xmlver2);
TEST_CASE(xmlver2both);
TEST_CASE(xmlver2both2);
@ -587,6 +588,17 @@ private:
ASSERT_EQUALS(1, settings._xml_version);
}
void xmlver1()
{
REDIRECT;
const char *argv[] = {"cppcheck", "--xml-version=1", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings._xml);
ASSERT_EQUALS(1, settings._xml_version);
}
void xmlver2()
{
REDIRECT;