Merge topic 'improve_cobertura'

ab74553d ctest_coverage: Fix parsing of absolute paths in Cobertura files
This commit is contained in:
Brad King 2015-01-12 09:39:38 -05:00 committed by CMake Topic Stage
commit 212bf1f82a
1 changed files with 39 additions and 9 deletions

View File

@ -12,9 +12,11 @@ public:
XMLParser(cmCTest* ctest, cmCTestCoverageHandlerContainer& cont) XMLParser(cmCTest* ctest, cmCTestCoverageHandlerContainer& cont)
: CTest(ctest), Coverage(cont) : CTest(ctest), Coverage(cont)
{ {
this->InSources = false; this->InSources = false;
this->InSource = false; this->InSource = false;
this->SkipThisClass = false;
this->FilePaths.push_back(this->Coverage.SourceDir); this->FilePaths.push_back(this->Coverage.SourceDir);
this->FilePaths.push_back(this->Coverage.BinaryDir);
this->CurFileName = ""; this->CurFileName = "";
} }
@ -35,6 +37,10 @@ protected:
{ {
this->InSources=false; this->InSources=false;
} }
else if(name == "class")
{
this->SkipThisClass = false;
}
} }
virtual void CharacterDataHandler(const char* data, int length) virtual void CharacterDataHandler(const char* data, int length)
@ -72,15 +78,33 @@ protected:
<< atts[tagCount+1]<< std::endl); << atts[tagCount+1]<< std::endl);
std::string filename = atts[tagCount+1]; std::string filename = atts[tagCount+1];
this->CurFileName = ""; this->CurFileName = "";
// Check if this is an absolute path that falls within our
// source or binary directories.
for(size_t i=0;i < FilePaths.size();i++) for(size_t i=0;i < FilePaths.size();i++)
{ {
finalpath = FilePaths[i] + "/" + filename; if (filename.find(FilePaths[i]) == 0)
if(cmSystemTools::FileExists(finalpath.c_str()))
{ {
this->CurFileName = finalpath; this->CurFileName = filename;
break; break;
} }
} }
if (this->CurFileName == "")
{
// Check if this is a path that is relative to our source or
// binary directories.
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()); cmsys::ifstream fin(this->CurFileName.c_str());
if(this->CurFileName == "" || !fin ) if(this->CurFileName == "" || !fin )
{ {
@ -89,10 +113,11 @@ protected:
fin.open(this->CurFileName.c_str()); fin.open(this->CurFileName.c_str());
if (!fin) if (!fin)
{ {
cmCTestLog(this->CTest, ERROR_MESSAGE, cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Python Coverage: Error opening " << this->CurFileName "Skipping system file " << filename <<
<< std::endl); std::endl);
this->Coverage.Error++;
this->SkipThisClass = true;
break; break;
} }
} }
@ -117,6 +142,10 @@ protected:
int curHits = -1; int curHits = -1;
while(true) while(true)
{ {
if(this->SkipThisClass)
{
break;
}
if(strcmp(atts[tagCount], "hits") == 0) if(strcmp(atts[tagCount], "hits") == 0)
{ {
curHits = atoi(atts[tagCount+1]); curHits = atoi(atts[tagCount+1]);
@ -144,6 +173,7 @@ private:
bool InSources; bool InSources;
bool InSource; bool InSource;
bool SkipThisClass;
std::vector<std::string> FilePaths; std::vector<std::string> FilePaths;
typedef cmCTestCoverageHandlerContainer::SingleFileCoverageVector typedef cmCTestCoverageHandlerContainer::SingleFileCoverageVector
FileLinesType; FileLinesType;