From 88b3dcb125db2c3ae64b69d74a9f58b3425012d0 Mon Sep 17 00:00:00 2001 From: Roni Choudhury Date: Sat, 24 May 2014 11:42:08 -0400 Subject: [PATCH] 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)) {