From a2822d30899f3fc2ad96abfdf5de0d0ce4166139 Mon Sep 17 00:00:00 2001 From: Joseph Snyder Date: Tue, 3 Jun 2014 18:30:46 +0000 Subject: CTest: Rename coverage implementation for "Python" to "Cobertura" The coverage.py tool writes out an XML that conforms to the Cobertura Coverage tool standard. Rename the cmParsePythonCoverage files to instead be cmParseCoberturaCoverage. --- Source/CMakeLists.txt | 2 +- Source/CTest/cmCTestCoverageHandler.cxx | 12 +-- Source/CTest/cmCTestCoverageHandler.h | 2 +- Source/CTest/cmParseCoberturaCoverage.cxx | 119 ++++++++++++++++++++++++++++++ Source/CTest/cmParseCoberturaCoverage.h | 48 ++++++++++++ Source/CTest/cmParsePythonCoverage.cxx | 119 ------------------------------ Source/CTest/cmParsePythonCoverage.h | 48 ------------ 7 files changed, 175 insertions(+), 175 deletions(-) create mode 100644 Source/CTest/cmParseCoberturaCoverage.cxx create mode 100644 Source/CTest/cmParseCoberturaCoverage.h delete mode 100644 Source/CTest/cmParsePythonCoverage.cxx delete mode 100644 Source/CTest/cmParsePythonCoverage.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 8ecf83c..fe6cc1b 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -519,7 +519,7 @@ set(CTEST_SRCS cmCTest.cxx CTest/cmParseCacheCoverage.cxx CTest/cmParseGTMCoverage.cxx CTest/cmParsePHPCoverage.cxx - CTest/cmParsePythonCoverage.cxx + CTest/cmParseCoberturaCoverage.cxx CTest/cmCTestEmptyBinaryDirectoryCommand.cxx CTest/cmCTestGenericHandler.cxx CTest/cmCTestHandlerCommand.cxx diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index cb6e56e..da27c8c 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -11,7 +11,7 @@ ============================================================================*/ #include "cmCTestCoverageHandler.h" #include "cmParsePHPCoverage.h" -#include "cmParsePythonCoverage.h" +#include "cmParseCoberturaCoverage.h" #include "cmParseGTMCoverage.h" #include "cmParseCacheCoverage.h" #include "cmCTest.h" @@ -401,7 +401,7 @@ int cmCTestCoverageHandler::ProcessHandler() { return error; } - file_count += this->HandlePythonCoverage(&cont); + file_count += this->HandleCoberturaCoverage(&cont); error = cont.Error; if ( file_count < 0 ) { @@ -779,10 +779,10 @@ int cmCTestCoverageHandler::HandlePHPCoverage( } //---------------------------------------------------------------------- -int cmCTestCoverageHandler::HandlePythonCoverage( +int cmCTestCoverageHandler::HandleCoberturaCoverage( cmCTestCoverageHandlerContainer* cont) { - cmParsePythonCoverage cov(*cont, this->CTest); + cmParseCoberturaCoverage cov(*cont, this->CTest); // Assume the coverage.xml is in the source directory std::string coverageXMLFile = this->CTest->GetBinaryDir() + "/coverage.xml"; @@ -790,14 +790,14 @@ int cmCTestCoverageHandler::HandlePythonCoverage( if(cmSystemTools::FileExists(coverageXMLFile.c_str())) { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Parsing coverage.py XML file: " << coverageXMLFile + "Parsing Cobertura XML file: " << coverageXMLFile << std::endl); cov.ReadCoverageXML(coverageXMLFile.c_str()); } else { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Cannot find coverage.py XML file: " << coverageXMLFile + "Cannot find Cobertura XML file: " << coverageXMLFile << std::endl); } return static_cast(cont->TotalCoverage.size()); diff --git a/Source/CTest/cmCTestCoverageHandler.h b/Source/CTest/cmCTestCoverageHandler.h index 0a0fe81..38a3353 100644 --- a/Source/CTest/cmCTestCoverageHandler.h +++ b/Source/CTest/cmCTestCoverageHandler.h @@ -76,7 +76,7 @@ private: int HandlePHPCoverage(cmCTestCoverageHandlerContainer* cont); //! Handle coverage for Python with coverage.py - int HandlePythonCoverage(cmCTestCoverageHandlerContainer* cont); + int HandleCoberturaCoverage(cmCTestCoverageHandlerContainer* cont); //! Handle coverage for mumps int HandleMumpsCoverage(cmCTestCoverageHandlerContainer* cont); diff --git a/Source/CTest/cmParseCoberturaCoverage.cxx b/Source/CTest/cmParseCoberturaCoverage.cxx new file mode 100644 index 0000000..0f5daba --- /dev/null +++ b/Source/CTest/cmParseCoberturaCoverage.cxx @@ -0,0 +1,119 @@ +#include "cmStandardIncludes.h" +#include "cmSystemTools.h" +#include "cmXMLParser.h" +#include "cmParseCoberturaCoverage.h" +#include +#include + +//---------------------------------------------------------------------------- +class cmParseCoberturaCoverage::XMLParser: public cmXMLParser +{ +public: + XMLParser(cmCTest* ctest, cmCTestCoverageHandlerContainer& cont) + : CTest(ctest), Coverage(cont) + { + } + + virtual ~XMLParser() + { + } + +protected: + + virtual void StartElement(const std::string& name, const char** atts) + { + if(name == "class") + { + int tagCount = 0; + while(true) + { + if(strcmp(atts[tagCount], "filename") == 0) + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Reading file: " + << atts[tagCount+1] << std::endl); + this->CurFileName = this->Coverage.SourceDir + "/" + + atts[tagCount+1]; + cmsys::ifstream fin(this->CurFileName.c_str()); + if(!fin) + { + this->CurFileName = this->Coverage.BinaryDir + "/" + + atts[tagCount+1]; + fin.open(this->CurFileName.c_str()); + if (!fin) + { + cmCTestLog(this->CTest, ERROR_MESSAGE, + "Python Coverage: Error opening " << this->CurFileName + << std::endl); + this->Coverage.Error++; + break; + } + } + + std::string line; + FileLinesType& curFileLines = + this->Coverage.TotalCoverage[this->CurFileName]; + curFileLines.push_back(-1); + while(cmSystemTools::GetLineFromStream(fin, line)) + { + curFileLines.push_back(-1); + } + + break; + } + ++tagCount; + } + } + else if(name == "line") + { + int tagCount = 0; + int curNumber = -1; + int curHits = -1; + while(true) + { + if(strcmp(atts[tagCount], "hits") == 0) + { + curHits = atoi(atts[tagCount+1]); + } + else if(strcmp(atts[tagCount], "number") == 0) + { + curNumber = atoi(atts[tagCount+1]); + } + + if(curHits > -1 && curNumber > 0) + { + FileLinesType& curFileLines = + this->Coverage.TotalCoverage[this->CurFileName]; + curFileLines[curNumber-1] = curHits; + break; + } + ++tagCount; + } + } + } + + virtual void EndElement(const std::string&) {} + +private: + + typedef cmCTestCoverageHandlerContainer::SingleFileCoverageVector + FileLinesType; + cmCTest* CTest; + cmCTestCoverageHandlerContainer& Coverage; + std::string CurFileName; + +}; + + +cmParseCoberturaCoverage::cmParseCoberturaCoverage( + cmCTestCoverageHandlerContainer& cont, + cmCTest* ctest) + :Coverage(cont), CTest(ctest) +{ +} + +bool cmParseCoberturaCoverage::ReadCoverageXML(const char* xmlFile) +{ + cmParseCoberturaCoverage::XMLParser parser(this->CTest, this->Coverage); + parser.ParseFile(xmlFile); + return true; +} diff --git a/Source/CTest/cmParseCoberturaCoverage.h b/Source/CTest/cmParseCoberturaCoverage.h new file mode 100644 index 0000000..4204b10 --- /dev/null +++ b/Source/CTest/cmParseCoberturaCoverage.h @@ -0,0 +1,48 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2009 Kitware, Inc. + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#ifndef cmParseCoberturaCoverage_h +#define cmParseCoberturaCoverage_h + +#include "cmStandardIncludes.h" +#include "cmCTestCoverageHandler.h" + +/** \class cmParsePythonCoverage + * \brief Parse coverage.py Python coverage information + * + * This class is used to parse the output of the coverage.py tool that + * is currently maintained by Ned Batchelder. That tool has a command + * that produces xml output in the format typically output by the common + * Java-based Cobertura coverage application. This helper class parses + * that XML file to fill the coverage-handler container. + */ +class cmParseCoberturaCoverage +{ +public: + + //! Create the coverage parser by passing in the coverage handler + //! container and the cmCTest object + cmParseCoberturaCoverage(cmCTestCoverageHandlerContainer& cont, + cmCTest* ctest); + + //! Read the XML produced by running `coverage xml` + bool ReadCoverageXML(const char* xmlFile); + +private: + + class XMLParser; + cmCTestCoverageHandlerContainer& Coverage; + cmCTest* CTest; + std::string CurFileName; +}; + +#endif diff --git a/Source/CTest/cmParsePythonCoverage.cxx b/Source/CTest/cmParsePythonCoverage.cxx deleted file mode 100644 index 817b8dc..0000000 --- a/Source/CTest/cmParsePythonCoverage.cxx +++ /dev/null @@ -1,119 +0,0 @@ -#include "cmStandardIncludes.h" -#include "cmSystemTools.h" -#include "cmXMLParser.h" -#include "cmParsePythonCoverage.h" -#include -#include - -//---------------------------------------------------------------------------- -class cmParsePythonCoverage::XMLParser: public cmXMLParser -{ -public: - XMLParser(cmCTest* ctest, cmCTestCoverageHandlerContainer& cont) - : CTest(ctest), Coverage(cont) - { - } - - virtual ~XMLParser() - { - } - -protected: - - virtual void StartElement(const std::string& name, const char** atts) - { - if(name == "class") - { - int tagCount = 0; - while(true) - { - if(strcmp(atts[tagCount], "filename") == 0) - { - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Reading file: " - << atts[tagCount+1] << std::endl); - this->CurFileName = this->Coverage.SourceDir + "/" + - atts[tagCount+1]; - cmsys::ifstream fin(this->CurFileName.c_str()); - if(!fin) - { - this->CurFileName = this->Coverage.BinaryDir + "/" + - atts[tagCount+1]; - fin.open(this->CurFileName.c_str()); - if (!fin) - { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Python Coverage: Error opening " << this->CurFileName - << std::endl); - this->Coverage.Error++; - break; - } - } - - std::string line; - FileLinesType& curFileLines = - this->Coverage.TotalCoverage[this->CurFileName]; - curFileLines.push_back(-1); - while(cmSystemTools::GetLineFromStream(fin, line)) - { - curFileLines.push_back(-1); - } - - break; - } - ++tagCount; - } - } - else if(name == "line") - { - int tagCount = 0; - int curNumber = -1; - int curHits = -1; - while(true) - { - if(strcmp(atts[tagCount], "hits") == 0) - { - curHits = atoi(atts[tagCount+1]); - } - else if(strcmp(atts[tagCount], "number") == 0) - { - curNumber = atoi(atts[tagCount+1]); - } - - if(curHits > -1 && curNumber > 0) - { - FileLinesType& curFileLines = - this->Coverage.TotalCoverage[this->CurFileName]; - curFileLines[curNumber-1] = curHits; - break; - } - ++tagCount; - } - } - } - - virtual void EndElement(const std::string&) {} - -private: - - typedef cmCTestCoverageHandlerContainer::SingleFileCoverageVector - FileLinesType; - cmCTest* CTest; - cmCTestCoverageHandlerContainer& Coverage; - std::string CurFileName; - -}; - - -cmParsePythonCoverage::cmParsePythonCoverage( - cmCTestCoverageHandlerContainer& cont, - cmCTest* ctest) - :Coverage(cont), CTest(ctest) -{ -} - -bool cmParsePythonCoverage::ReadCoverageXML(const char* xmlFile) -{ - cmParsePythonCoverage::XMLParser parser(this->CTest, this->Coverage); - parser.ParseFile(xmlFile); - return true; -} diff --git a/Source/CTest/cmParsePythonCoverage.h b/Source/CTest/cmParsePythonCoverage.h deleted file mode 100644 index 668c7f9..0000000 --- a/Source/CTest/cmParsePythonCoverage.h +++ /dev/null @@ -1,48 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2000-2009 Kitware, Inc. - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - -#ifndef cmParsePythonCoverage_h -#define cmParsePythonCoverage_h - -#include "cmStandardIncludes.h" -#include "cmCTestCoverageHandler.h" - -/** \class cmParsePythonCoverage - * \brief Parse coverage.py Python coverage information - * - * This class is used to parse the output of the coverage.py tool that - * is currently maintained by Ned Batchelder. That tool has a command - * that produces xml output in the format typically output by the common - * Java-based Cobertura coverage application. This helper class parses - * that XML file to fill the coverage-handler container. - */ -class cmParsePythonCoverage -{ -public: - - //! Create the coverage parser by passing in the coverage handler - //! container and the cmCTest object - cmParsePythonCoverage(cmCTestCoverageHandlerContainer& cont, - cmCTest* ctest); - - //! Read the XML produced by running `coverage xml` - bool ReadCoverageXML(const char* xmlFile); - -private: - - class XMLParser; - cmCTestCoverageHandlerContainer& Coverage; - cmCTest* CTest; - std::string CurFileName; -}; - -#endif -- cgit v0.12