From 88b3dcb125db2c3ae64b69d74a9f58b3425012d0 Mon Sep 17 00:00:00 2001 From: Roni Choudhury Date: Sat, 24 May 2014 11:42:08 -0400 Subject: [PATCH 1/2] CTest: Improve Python coverage.py source file search algorithm If the coverage.py source file is not found in the source directory, the build directory is first searched before raising an error. This is necessary because it is a valid workflow to build a Python package from source, then install this package to a virtualenv that lives in the build directory. Tests will run against this deployed package and therefore the covered source files will be found in a subdirectory of the build directory, and not anywhere in the source directory. --- Source/CTest/cmParsePythonCoverage.cxx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Source/CTest/cmParsePythonCoverage.cxx b/Source/CTest/cmParsePythonCoverage.cxx index 2578bb876..68a6817af 100644 --- a/Source/CTest/cmParsePythonCoverage.cxx +++ b/Source/CTest/cmParsePythonCoverage.cxx @@ -33,19 +33,25 @@ protected: << atts[tagCount+1] << std::endl); this->CurFileName = this->Coverage.SourceDir + "/" + atts[tagCount+1]; - FileLinesType& curFileLines = - this->Coverage.TotalCoverage[this->CurFileName]; cmsys::ifstream fin(this->CurFileName.c_str()); if(!fin) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Python Coverage: Error opening " << this->CurFileName - << std::endl); - this->Coverage.Error++; - break; + 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)) { From deee7c42a2df8156ad81c371d0f1007286018f0f Mon Sep 17 00:00:00 2001 From: Zach Mullen Date: Tue, 27 May 2014 15:44:46 -0400 Subject: [PATCH 2/2] CTest: Fix Python coverage.py off-by-one error in results The cobertura format uses line numbers indexed starting at 1, and CTest uses a vector indexed starting at 0 to store them. --- Source/CTest/cmParsePythonCoverage.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/CTest/cmParsePythonCoverage.cxx b/Source/CTest/cmParsePythonCoverage.cxx index 68a6817af..817b8dca3 100644 --- a/Source/CTest/cmParsePythonCoverage.cxx +++ b/Source/CTest/cmParsePythonCoverage.cxx @@ -79,11 +79,11 @@ protected: curNumber = atoi(atts[tagCount+1]); } - if(curHits > -1 && curNumber > -1) + if(curHits > -1 && curNumber > 0) { FileLinesType& curFileLines = this->Coverage.TotalCoverage[this->CurFileName]; - curFileLines[curNumber] = curHits; + curFileLines[curNumber-1] = curHits; break; } ++tagCount;