summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorJoseph Snyder <joe.snyder@kitware.com>2014-05-29 17:47:31 (GMT)
committerJoseph Snyder <joe.snyder@kitware.com>2014-06-04 14:26:19 (GMT)
commit50daf239b001ddda61449044e75bb98651e99d21 (patch)
treece47d4d773037e2515149de475c7edeee6baff17 /Source
parenta2822d30899f3fc2ad96abfdf5de0d0ce4166139 (diff)
downloadCMake-50daf239b001ddda61449044e75bb98651e99d21.zip
CMake-50daf239b001ddda61449044e75bb98651e99d21.tar.gz
CMake-50daf239b001ddda61449044e75bb98651e99d21.tar.bz2
CTest: Generalize Cobertura coverage format handling
Add support for Cobertura coverage files written by Java. Add a test which uses the report from a Java run of Cobertura to calculate coverage. In the documentation of CTEST_COVERAGE_COMMAND, give a sample .sh file to merge the Cobertura .ser files and generate the XML report from the merged file.
Diffstat (limited to 'Source')
-rw-r--r--Source/CTest/cmParseCoberturaCoverage.cxx67
-rw-r--r--Source/CTest/cmParseCoberturaCoverage.h3
2 files changed, 61 insertions, 9 deletions
diff --git a/Source/CTest/cmParseCoberturaCoverage.cxx b/Source/CTest/cmParseCoberturaCoverage.cxx
index 0f5daba..6b98056 100644
--- a/Source/CTest/cmParseCoberturaCoverage.cxx
+++ b/Source/CTest/cmParseCoberturaCoverage.cxx
@@ -12,6 +12,10 @@ 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;
diff --git a/Source/CTest/cmParseCoberturaCoverage.h b/Source/CTest/cmParseCoberturaCoverage.h
index 4204b10..ff5954d 100644
--- a/Source/CTest/cmParseCoberturaCoverage.h
+++ b/Source/CTest/cmParseCoberturaCoverage.h
@@ -34,6 +34,9 @@ public:
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);