summaryrefslogtreecommitdiffstats
path: root/Source/CTest/cmParseBlanketJSCoverage.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/CTest/cmParseBlanketJSCoverage.cxx')
-rw-r--r--Source/CTest/cmParseBlanketJSCoverage.cxx132
1 files changed, 58 insertions, 74 deletions
diff --git a/Source/CTest/cmParseBlanketJSCoverage.cxx b/Source/CTest/cmParseBlanketJSCoverage.cxx
index 1f1db3e..1e42847 100644
--- a/Source/CTest/cmParseBlanketJSCoverage.cxx
+++ b/Source/CTest/cmParseBlanketJSCoverage.cxx
@@ -18,76 +18,65 @@
#include <stdio.h>
#include <stdlib.h>
-
class cmParseBlanketJSCoverage::JSONParser
- {
+{
public:
- typedef cmCTestCoverageHandlerContainer::
- SingleFileCoverageVector FileLinesType;
+ typedef cmCTestCoverageHandlerContainer::SingleFileCoverageVector
+ FileLinesType;
JSONParser(cmCTestCoverageHandlerContainer& cont)
- : Coverage(cont)
- {
- }
+ : Coverage(cont)
+ {
+ }
- virtual ~JSONParser()
- {
- }
+ virtual ~JSONParser() {}
std::string getValue(std::string line, int type)
- {
+ {
size_t begIndex;
size_t endIndex;
endIndex = line.rfind(',');
begIndex = line.find_first_of(':');
- if(type == 0)
- {
+ if (type == 0) {
// A unique substring to remove the extra characters
// around the files name in the JSON (extra " and ,)
std::string foundFileName =
- line.substr(begIndex+3,endIndex-(begIndex+4));
+ line.substr(begIndex + 3, endIndex - (begIndex + 4));
return foundFileName;
- }
- else
- {
- return line.substr(begIndex,line.npos);
- }
+ } else {
+ return line.substr(begIndex, line.npos);
}
+ }
bool ParseFile(std::string file)
- {
+ {
FileLinesType localCoverageVector;
std::string filename;
bool foundFile = false;
- bool inSource = false;
+ bool inSource = false;
std::string covResult;
std::string line;
cmsys::ifstream in(file.c_str());
- if(!in)
- {
+ if (!in) {
return false;
- }
- while( cmSystemTools::GetLineFromStream(in, line))
- {
- if(line.find("filename") != line.npos)
- {
- if(foundFile)
- {
+ }
+ while (cmSystemTools::GetLineFromStream(in, line)) {
+ if (line.find("filename") != line.npos) {
+ if (foundFile) {
/*
* Upon finding a second file name, generate a
* vector within the total coverage to capture the
* information in the local vector
*/
FileLinesType& CoverageVector =
- this->Coverage.TotalCoverage[filename];
+ this->Coverage.TotalCoverage[filename];
CoverageVector = localCoverageVector;
localCoverageVector.clear();
- }
- foundFile= true;
- inSource = false;
- filename = getValue(line,0).c_str();
}
- else if((line.find("coverage") != line.npos) && foundFile && inSource )
- {
+ foundFile = true;
+ inSource = false;
+ filename = getValue(line, 0).c_str();
+ } else if ((line.find("coverage") != line.npos) && foundFile &&
+ inSource) {
/*
* two types of "coverage" in the JSON structure
*
@@ -97,68 +86,63 @@ public:
* FoundFile and foundSource ensure that
* only the value of the line coverage is captured
*/
- std::string result = getValue(line,1);
- result = result.substr(2,result.npos);
- if(result == "\"\"")
- {
+ std::string result = getValue(line, 1);
+ result = result.substr(2, result.npos);
+ if (result == "\"\"") {
// Empty quotation marks indicate that the
// line is not executable
localCoverageVector.push_back(-1);
- }
- else
- {
+ } else {
// Else, it contains the number of time executed
localCoverageVector.push_back(atoi(result.c_str()));
- }
- }
- else if(line.find("source") != line.npos)
- {
- inSource=true;
}
+ } else if (line.find("source") != line.npos) {
+ inSource = true;
}
+ }
// On exit, capture end of last file covered.
- FileLinesType& CoverageVector =
- this->Coverage.TotalCoverage[filename];
+ FileLinesType& CoverageVector = this->Coverage.TotalCoverage[filename];
CoverageVector = localCoverageVector;
localCoverageVector.clear();
return true;
- }
+ }
+
private:
cmCTestCoverageHandlerContainer& Coverage;
};
cmParseBlanketJSCoverage::cmParseBlanketJSCoverage(
- cmCTestCoverageHandlerContainer& cont, cmCTest* ctest)
- :Coverage(cont), CTest(ctest)
- {
- }
+ cmCTestCoverageHandlerContainer& cont, cmCTest* ctest)
+ : Coverage(cont)
+ , CTest(ctest)
+{
+}
bool cmParseBlanketJSCoverage::LoadCoverageData(std::vector<std::string> files)
- {
- size_t i=0;
+{
+ size_t i = 0;
std::string path;
- cmCTestOptionalLog(this->CTest,HANDLER_VERBOSE_OUTPUT,
- "Found " << files.size() <<" Files" << std::endl, this->Coverage.Quiet);
- for(i=0;i<files.size();i++)
- {
- cmCTestOptionalLog(this->CTest,HANDLER_VERBOSE_OUTPUT,
- "Reading JSON File " << files[i] << std::endl, this->Coverage.Quiet);
+ cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Found " << files.size() << " Files" << std::endl,
+ this->Coverage.Quiet);
+ for (i = 0; i < files.size(); i++) {
+ cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Reading JSON File " << files[i] << std::endl,
+ this->Coverage.Quiet);
- if(!this->ReadJSONFile(files[i]))
- {
+ if (!this->ReadJSONFile(files[i])) {
return false;
- }
}
- return true;
}
+ return true;
+}
bool cmParseBlanketJSCoverage::ReadJSONFile(std::string file)
- {
- cmParseBlanketJSCoverage::JSONParser parser
- (this->Coverage);
- cmCTestOptionalLog(this->CTest,HANDLER_VERBOSE_OUTPUT,
- "Parsing " << file << std::endl, this->Coverage.Quiet);
+{
+ cmParseBlanketJSCoverage::JSONParser parser(this->Coverage);
+ cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Parsing " << file << std::endl, this->Coverage.Quiet);
parser.ParseFile(file);
return true;
- }
+}