diff options
author | Brad King <brad.king@kitware.com> | 2014-06-05 14:55:29 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2014-06-05 14:55:29 (GMT) |
commit | 994f4b71fcc5f4487862bd610eab7114a616d643 (patch) | |
tree | 9279d53e05aa47df526433f0d15d845fb9ebb50a /Source | |
parent | 5d360f23fa5616004ffa813914336e5810d1f42b (diff) | |
parent | 50daf239b001ddda61449044e75bb98651e99d21 (diff) | |
download | CMake-994f4b71fcc5f4487862bd610eab7114a616d643.zip CMake-994f4b71fcc5f4487862bd610eab7114a616d643.tar.gz CMake-994f4b71fcc5f4487862bd610eab7114a616d643.tar.bz2 |
Merge topic 'expand_cobertura_coverage'
50daf239 CTest: Generalize Cobertura coverage format handling
a2822d30 CTest: Rename coverage implementation for "Python" to "Cobertura"
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Source/CTest/cmCTestCoverageHandler.cxx | 12 | ||||
-rw-r--r-- | Source/CTest/cmCTestCoverageHandler.h | 2 | ||||
-rw-r--r-- | Source/CTest/cmParseCoberturaCoverage.cxx (renamed from Source/CTest/cmParsePythonCoverage.cxx) | 77 | ||||
-rw-r--r-- | Source/CTest/cmParseCoberturaCoverage.h (renamed from Source/CTest/cmParsePythonCoverage.h) | 11 |
5 files changed, 78 insertions, 26 deletions
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<int>(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/cmParsePythonCoverage.cxx b/Source/CTest/cmParseCoberturaCoverage.cxx index 817b8dc..6b98056 100644 --- a/Source/CTest/cmParsePythonCoverage.cxx +++ b/Source/CTest/cmParseCoberturaCoverage.cxx @@ -1,17 +1,21 @@ #include "cmStandardIncludes.h" #include "cmSystemTools.h" #include "cmXMLParser.h" -#include "cmParsePythonCoverage.h" +#include "cmParseCoberturaCoverage.h" #include <cmsys/Directory.hxx> #include <cmsys/FStream.hxx> //---------------------------------------------------------------------------- -class cmParsePythonCoverage::XMLParser: public cmXMLParser +class cmParseCoberturaCoverage::XMLParser: public cmXMLParser { public: XMLParser(cmCTest* ctest, cmCTestCoverageHandlerContainer& cont) : CTest(ctest), Coverage(cont) { + this->InSources = false; + this->InSource = false; + this->FilePaths.push_back(this->Coverage.SourceDir); + this->CurFileName = ""; } virtual ~XMLParser() @@ -20,9 +24,44 @@ public: protected: + + virtual void EndElement(const std::string& name) + { + if(name == "source") + { + this->InSource=false; + } + else if (name == "sources") + { + this->InSources=false; + } + } + + virtual void CharacterDataHandler(const char* data, int length) + { + std::string tmp; + tmp.insert(0,data,length); + if (this->InSources && this->InSource) + { + this->FilePaths.push_back(tmp); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Adding Source: " + << tmp << std::endl); + } + } + virtual void StartElement(const std::string& name, const char** atts) { - if(name == "class") + std::string FoundSource; + std::string finalpath = ""; + if(name == "source") + { + this->InSource = true; + } + else if(name == "sources") + { + this->InSources = true; + } + else if(name == "class") { int tagCount = 0; while(true) @@ -30,11 +69,19 @@ protected: 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]; + << atts[tagCount+1]<< std::endl); + std::string filename = atts[tagCount+1]; + for(size_t i=0;i < FilePaths.size();i++) + { + finalpath = FilePaths[i] + "/" + filename; + if(cmSystemTools::FileExists(finalpath.c_str())) + { + this->CurFileName = finalpath; + break; + } + } cmsys::ifstream fin(this->CurFileName.c_str()); - if(!fin) + if(this->CurFileName == "" || !fin ) { this->CurFileName = this->Coverage.BinaryDir + "/" + atts[tagCount+1]; @@ -48,7 +95,6 @@ protected: break; } } - std::string line; FileLinesType& curFileLines = this->Coverage.TotalCoverage[this->CurFileName]; @@ -83,7 +129,9 @@ protected: { FileLinesType& curFileLines = this->Coverage.TotalCoverage[this->CurFileName]; - curFileLines[curNumber-1] = curHits; + { + curFileLines[curNumber-1] = curHits; + } break; } ++tagCount; @@ -91,10 +139,11 @@ protected: } } - virtual void EndElement(const std::string&) {} - private: + bool InSources; + bool InSource; + std::vector<std::string> FilePaths; typedef cmCTestCoverageHandlerContainer::SingleFileCoverageVector FileLinesType; cmCTest* CTest; @@ -104,16 +153,16 @@ private: }; -cmParsePythonCoverage::cmParsePythonCoverage( +cmParseCoberturaCoverage::cmParseCoberturaCoverage( cmCTestCoverageHandlerContainer& cont, cmCTest* ctest) :Coverage(cont), CTest(ctest) { } -bool cmParsePythonCoverage::ReadCoverageXML(const char* xmlFile) +bool cmParseCoberturaCoverage::ReadCoverageXML(const char* xmlFile) { - cmParsePythonCoverage::XMLParser parser(this->CTest, this->Coverage); + cmParseCoberturaCoverage::XMLParser parser(this->CTest, this->Coverage); parser.ParseFile(xmlFile); return true; } diff --git a/Source/CTest/cmParsePythonCoverage.h b/Source/CTest/cmParseCoberturaCoverage.h index 668c7f9..ff5954d 100644 --- a/Source/CTest/cmParsePythonCoverage.h +++ b/Source/CTest/cmParseCoberturaCoverage.h @@ -10,8 +10,8 @@ See the License for more information. ============================================================================*/ -#ifndef cmParsePythonCoverage_h -#define cmParsePythonCoverage_h +#ifndef cmParseCoberturaCoverage_h +#define cmParseCoberturaCoverage_h #include "cmStandardIncludes.h" #include "cmCTestCoverageHandler.h" @@ -25,15 +25,18 @@ * Java-based Cobertura coverage application. This helper class parses * that XML file to fill the coverage-handler container. */ -class cmParsePythonCoverage +class cmParseCoberturaCoverage { public: //! Create the coverage parser by passing in the coverage handler //! container and the cmCTest object - cmParsePythonCoverage(cmCTestCoverageHandlerContainer& cont, + cmParseCoberturaCoverage(cmCTestCoverageHandlerContainer& cont, cmCTest* ctest); + bool inSources; + bool inSource; + std::vector<std::string> filepaths; //! Read the XML produced by running `coverage xml` bool ReadCoverageXML(const char* xmlFile); |