diff options
Diffstat (limited to 'Source/CTest')
22 files changed, 707 insertions, 115 deletions
diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx index 41db042..a101e39 100644 --- a/Source/CTest/cmCTestBuildAndTestHandler.cxx +++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx @@ -109,7 +109,7 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring, out << "Error: cmake execution failed\n"; out << cmakeOutString << "\n"; // return to the original directory - cmSystemTools::ChangeDirectory(cwd.c_str()); + cmSystemTools::ChangeDirectory(cwd); if(outstring) { *outstring = out.str(); @@ -128,7 +128,7 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring, out << "Error: cmake execution failed\n"; out << cmakeOutString << "\n"; // return to the original directory - cmSystemTools::ChangeDirectory(cwd.c_str()); + cmSystemTools::ChangeDirectory(cwd); if(outstring) { *outstring = out.str(); @@ -241,11 +241,11 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); out << "Internal cmake changing into directory: " << this->BinaryDir << std::endl; - if (!cmSystemTools::FileIsDirectory(this->BinaryDir.c_str())) + if (!cmSystemTools::FileIsDirectory(this->BinaryDir)) { cmSystemTools::MakeDirectory(this->BinaryDir.c_str()); } - cmSystemTools::ChangeDirectory(this->BinaryDir.c_str()); + cmSystemTools::ChangeDirectory(this->BinaryDir); if(this->BuildNoCMake) { @@ -374,7 +374,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) cmCTestLog(this->CTest, ERROR_MESSAGE, out.str()); } // return to the original directory - cmSystemTools::ChangeDirectory(cwd.c_str()); + cmSystemTools::ChangeDirectory(cwd); return 1; } @@ -391,7 +391,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) if(this->BuildRunDir.size()) { out << "Run test in directory: " << this->BuildRunDir << "\n"; - cmSystemTools::ChangeDirectory(this->BuildRunDir.c_str()); + cmSystemTools::ChangeDirectory(this->BuildRunDir); } out << "Running test command: \"" << fullPath << "\""; for(size_t k=0; k < this->TestCommandArgs.size(); ++k) @@ -453,9 +453,9 @@ int cmCTestBuildAndTestHandler::ProcessCommandLineArguments( // dir must exist before CollapseFullPath is called cmSystemTools::MakeDirectory(this->BinaryDir.c_str()); this->BinaryDir - = cmSystemTools::CollapseFullPath(this->BinaryDir.c_str()); + = cmSystemTools::CollapseFullPath(this->BinaryDir); this->SourceDir - = cmSystemTools::CollapseFullPath(this->SourceDir.c_str()); + = cmSystemTools::CollapseFullPath(this->SourceDir); } else { diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index 2ec1365..d226a6c 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -36,9 +36,6 @@ #include <math.h> #include <float.h> -#if defined(__BORLANDC__) -# pragma warn -8060 /* possibly incorrect assignment */ -#endif static const char* cmCTestErrorMatches[] = { "^[Bb]us [Ee]rror", @@ -610,7 +607,7 @@ void cmCTestBuildHandler::GenerateXMLLaunched(std::ostream& os) int numWarningsAllowed = this->MaxWarnings; // Identify fragments on disk. cmsys::Directory launchDir; - launchDir.Load(this->CTestLaunchDir.c_str()); + launchDir.Load(this->CTestLaunchDir); unsigned long n = launchDir.GetNumberOfFiles(); for(unsigned long i=0; i < n; ++i) { @@ -649,7 +646,7 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(std::ostream& os) std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory"); // make sure the source dir is in the correct case on windows // via a call to collapse full path. - srcdir = cmSystemTools::CollapseFullPath(srcdir.c_str()); + srcdir = cmSystemTools::CollapseFullPath(srcdir); srcdir += "/"; for ( it = ew.begin(); it != ew.end() && (numErrorsAllowed || numWarningsAllowed); it++ ) @@ -695,7 +692,7 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(std::ostream& os) { // make sure it is a full path with the correct case cm->SourceFile = cmSystemTools::CollapseFullPath( - cm->SourceFile.c_str()); + cm->SourceFile); cmSystemTools::ReplaceString( cm->SourceFile, srcdir.c_str(), ""); } @@ -822,7 +819,7 @@ cmCTestBuildHandler::LaunchHelper::LaunchHelper(cmCTestBuildHandler* handler): launchDir += "/Build"; // Clean out any existing launcher fragments. - cmSystemTools::RemoveADirectory(launchDir.c_str()); + cmSystemTools::RemoveADirectory(launchDir); if(this->Handler->UseCTestLaunch) { @@ -831,7 +828,7 @@ cmCTestBuildHandler::LaunchHelper::LaunchHelper(cmCTestBuildHandler* handler): this->WriteLauncherConfig(); std::string launchEnv = "CTEST_LAUNCH_LOGS="; launchEnv += launchDir; - cmSystemTools::PutEnv(launchEnv.c_str()); + cmSystemTools::PutEnv(launchEnv); } } diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index 76f6584..e782886 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -15,6 +15,8 @@ #include "cmParseGTMCoverage.h" #include "cmParseCacheCoverage.h" #include "cmParseJacocoCoverage.h" +#include "cmParseDelphiCoverage.h" +#include "cmParseBlanketJSCoverage.h" #include "cmCTest.h" #include "cmake.h" #include "cmMakefile.h" @@ -164,7 +166,7 @@ void cmCTestCoverageHandler::CleanCoverageLogFiles(std::ostream& log) fi != files.end(); ++fi) { log << "Removing old coverage log: " << *fi << "\n"; - cmSystemTools::RemoveFile(fi->c_str()); + cmSystemTools::RemoveFile(*fi); } } @@ -237,10 +239,10 @@ bool cmCTestCoverageHandler::ShouldIDoCoverage(const char* file, std::string fSrcDir = cmSystemTools::CollapseFullPath(srcDir); std::string fBinDir = cmSystemTools::CollapseFullPath(binDir); std::string fFile = cmSystemTools::CollapseFullPath(file); - bool sourceSubDir = cmSystemTools::IsSubDirectory(fFile.c_str(), - fSrcDir.c_str()); - bool buildSubDir = cmSystemTools::IsSubDirectory(fFile.c_str(), - fBinDir.c_str()); + bool sourceSubDir = cmSystemTools::IsSubDirectory(fFile, + fSrcDir); + bool buildSubDir = cmSystemTools::IsSubDirectory(fFile, + fBinDir); // Always check parent directory of the file. std::string fileDir = cmSystemTools::GetFilenamePath(fFile); std::string checkDir; @@ -423,6 +425,19 @@ int cmCTestCoverageHandler::ProcessHandler() return error; } + file_count += this->HandleBlanketJSCoverage(&cont); + error = cont.Error; + if ( file_count < 0 ) + { + return error; + } + + file_count += this->HandleDelphiCoverage(&cont); + error = cont.Error; + if ( file_count < 0 ) + { + return error; + } std::set<std::string> uncovered = this->FindUncoveredFiles(&cont); if ( file_count == 0 ) @@ -758,8 +773,8 @@ void cmCTestCoverageHandler::PopulateCustomVectors(cmMakefile *mf) //---------------------------------------------------------------------- bool IsFileInDir(const std::string &infile, const std::string &indir) { - std::string file = cmSystemTools::CollapseFullPath(infile.c_str()); - std::string dir = cmSystemTools::CollapseFullPath(indir.c_str()); + std::string file = cmSystemTools::CollapseFullPath(infile); + std::string dir = cmSystemTools::CollapseFullPath(indir); if ( file.size() > dir.size() && @@ -779,7 +794,7 @@ int cmCTestCoverageHandler::HandlePHPCoverage( { cmParsePHPCoverage cov(*cont, this->CTest); std::string coverageDir = this->CTest->GetBinaryDir() + "/xdebugCoverage"; - if(cmSystemTools::FileIsDirectory(coverageDir.c_str())) + if(cmSystemTools::FileIsDirectory(coverageDir)) { cov.ReadPHPCoverageDirectory(coverageDir.c_str()); } @@ -869,7 +884,7 @@ struct cmCTestCoverageHandlerLocale { if(!lc_all.empty()) { - cmSystemTools::PutEnv(("LC_ALL=" + lc_all).c_str()); + cmSystemTools::PutEnv("LC_ALL=" + lc_all); } else { @@ -910,7 +925,68 @@ int cmCTestCoverageHandler::HandleJacocoCoverage( return static_cast<int>(cont->TotalCoverage.size()); } +//---------------------------------------------------------------------- +int cmCTestCoverageHandler::HandleDelphiCoverage( + cmCTestCoverageHandlerContainer* cont) +{ + cmParseDelphiCoverage cov = + cmParseDelphiCoverage(*cont, this->CTest); + cmsys::Glob g; + std::vector<std::string> files; + g.SetRecurse(true); + + + std::string BinDir + = this->CTest->GetBinaryDir(); + std::string coverageFile = BinDir+ "/*.html"; + + g.FindFiles(coverageFile); + files=g.GetFiles(); + if (files.size() > 0) + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + "Found Delphi HTML Files, Performing Coverage" << std::endl); + cov.LoadCoverageData(files); + } + else + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + " Cannot find Delphi coverage files: " << coverageFile + << std::endl); + } + return static_cast<int>(cont->TotalCoverage.size()); +} + +//---------------------------------------------------------------------- +int cmCTestCoverageHandler::HandleBlanketJSCoverage( + cmCTestCoverageHandlerContainer* cont) + { + cmParseBlanketJSCoverage cov = + cmParseBlanketJSCoverage(*cont, this->CTest); + std::string SourceDir + = this->CTest->GetCTestConfiguration("SourceDirectory"); + + //Look for something other than output.json, still JSON extension. + std::string coverageFile = SourceDir+ "/*.json"; + cmsys::Glob g; + std::vector<std::string> files; + g.FindFiles(coverageFile); + files=g.GetFiles(); + if (files.size() > 0) + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + "Found BlanketJS output JSON, Performing Coverage" << std::endl); + cov.LoadCoverageData(files); + } + else + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + " Cannot find BlanketJS coverage files: " << coverageFile + << std::endl); + } + return static_cast<int>(cont->TotalCoverage.size()); + } //---------------------------------------------------------------------- int cmCTestCoverageHandler::HandleGCovCoverage( cmCTestCoverageHandlerContainer* cont) @@ -974,7 +1050,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( std::string tempDir = testingDir + "/CoverageInfo"; std::string currentDirectory = cmSystemTools::GetCurrentWorkingDirectory(); cmSystemTools::MakeDirectory(tempDir.c_str()); - cmSystemTools::ChangeDirectory(tempDir.c_str()); + cmSystemTools::ChangeDirectory(tempDir); int gcovStyle = 0; @@ -1295,7 +1371,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( *cont->OFS << " produced in source dir: " << sourceFile << std::endl; actualSourceFile - = cmSystemTools::CollapseFullPath(sourceFile.c_str()); + = cmSystemTools::CollapseFullPath(sourceFile); } else if ( IsFileInDir(sourceFile, cont->BinaryDir) ) { @@ -1304,7 +1380,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( *cont->OFS << " produced in binary dir: " << sourceFile << std::endl; actualSourceFile - = cmSystemTools::CollapseFullPath(sourceFile.c_str()); + = cmSystemTools::CollapseFullPath(sourceFile); } if ( actualSourceFile.empty() ) @@ -1345,7 +1421,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( } } - cmSystemTools::ChangeDirectory(currentDirectory.c_str()); + cmSystemTools::ChangeDirectory(currentDirectory); return file_count; } @@ -1409,30 +1485,30 @@ int cmCTestCoverageHandler::HandleLCovCoverage( for ( it = files.begin(); it != files.end(); ++ it ) { cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush); - std::string fileDir = cmSystemTools::GetFilenamePath(it->c_str()); - cmSystemTools::ChangeDirectory(fileDir.c_str()); + std::string fileDir = cmSystemTools::GetFilenamePath(*it); + cmSystemTools::ChangeDirectory(fileDir); std::string command = "\"" + lcovCommand + "\" " + lcovExtraFlags + " "; cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Current coverage dir: " - << fileDir.c_str() << std::endl); + << fileDir << std::endl); cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, command.c_str() << std::endl); std::string output = ""; std::string errors = ""; int retVal = 0; - *cont->OFS << "* Run coverage for: " << fileDir.c_str() << std::endl; - *cont->OFS << " Command: " << command.c_str() << std::endl; + *cont->OFS << "* Run coverage for: " << fileDir << std::endl; + *cont->OFS << " Command: " << command << std::endl; int res = this->CTest->RunCommand(command.c_str(), &output, &errors, &retVal, fileDir.c_str(), 0 /*this->TimeOut*/); - *cont->OFS << " Output: " << output.c_str() << std::endl; - *cont->OFS << " Errors: " << errors.c_str() << std::endl; + *cont->OFS << " Output: " << output << std::endl; + *cont->OFS << " Errors: " << errors << std::endl; if ( ! res ) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Problem running coverage on file: " << it->c_str() << std::endl); + "Problem running coverage on file: " << *it << std::endl); cmCTestLog(this->CTest, ERROR_MESSAGE, "Command produced error: " << errors << std::endl); cont->Error ++; @@ -1441,7 +1517,7 @@ int cmCTestCoverageHandler::HandleLCovCoverage( if ( retVal != 0 ) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Coverage command returned: " - << retVal << " while processing: " << it->c_str() << std::endl); + << retVal << " while processing: " << *it << std::endl); cmCTestLog(this->CTest, ERROR_MESSAGE, "Command produced error: " << cont->Error << std::endl); } @@ -1609,7 +1685,7 @@ int cmCTestCoverageHandler::HandleLCovCoverage( } } - cmSystemTools::ChangeDirectory(currentDirectory.c_str()); + cmSystemTools::ChangeDirectory(currentDirectory); return file_count; } @@ -1653,7 +1729,7 @@ void cmCTestCoverageHandler::FindLCovFiles(std::vector<std::string>& files) gl.RecurseThroughSymlinksOff(); std::string prevBinaryDir; cmSystemTools::ChangeDirectory( - this->CTest->GetCTestConfiguration("BuildDirectory").c_str()); + this->CTest->GetCTestConfiguration("BuildDirectory")); // Run profmerge to merge all *.dyn files into dpi files cmSystemTools::RunSingleCommand("profmerge"); @@ -1696,9 +1772,9 @@ int cmCTestCoverageHandler::HandleTracePyCoverage( std::string tempDir = testingDir + "/CoverageInfo"; std::string currentDirectory = cmSystemTools::GetCurrentWorkingDirectory(); cmSystemTools::MakeDirectory(tempDir.c_str()); - cmSystemTools::ChangeDirectory(tempDir.c_str()); + cmSystemTools::ChangeDirectory(tempDir); - cmSystemTools::ChangeDirectory(currentDirectory.c_str()); + cmSystemTools::ChangeDirectory(currentDirectory); std::vector<std::string>::iterator fileIt; int file_count = 0; @@ -1714,7 +1790,7 @@ int cmCTestCoverageHandler::HandleTracePyCoverage( } std::string actualSourceFile - = cmSystemTools::CollapseFullPath(fileName.c_str()); + = cmSystemTools::CollapseFullPath(fileName); cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Check coverage for file: " << actualSourceFile << std::endl); @@ -1802,7 +1878,7 @@ int cmCTestCoverageHandler::HandleTracePyCoverage( } ++ file_count; } - cmSystemTools::ChangeDirectory(currentDirectory.c_str()); + cmSystemTools::ChangeDirectory(currentDirectory); return file_count; } @@ -2132,7 +2208,7 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary( file += "/"; file += sourceFile; } - file = cmSystemTools::CollapseFullPath(file.c_str()); + file = cmSystemTools::CollapseFullPath(file); bool shouldIDoCoverage = this->ShouldIDoCoverage(file.c_str(), cont->SourceDir.c_str(), diff --git a/Source/CTest/cmCTestCoverageHandler.h b/Source/CTest/cmCTestCoverageHandler.h index d0f274c..4aec795 100644 --- a/Source/CTest/cmCTestCoverageHandler.h +++ b/Source/CTest/cmCTestCoverageHandler.h @@ -84,6 +84,12 @@ private: //! Handle coverage for Jacoco int HandleJacocoCoverage(cmCTestCoverageHandlerContainer* cont); + //! Handle coverage for Delphi (Pascal) + int HandleDelphiCoverage(cmCTestCoverageHandlerContainer* cont); + + //! Handle coverage for Jacoco + int HandleBlanketJSCoverage(cmCTestCoverageHandlerContainer* cont); + //! Handle coverage using Bullseye int HandleBullseyeCoverage(cmCTestCoverageHandlerContainer* cont); int RunBullseyeSourceSummary(cmCTestCoverageHandlerContainer* cont); diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index aaa01b2..98bc9d7 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -158,7 +158,7 @@ std::string cmCTestGIT::FindTopDir() { top_dir += "/"; top_dir += cdup; - top_dir = cmSystemTools::CollapseFullPath(top_dir.c_str()); + top_dir = cmSystemTools::CollapseFullPath(top_dir); } return top_dir; } diff --git a/Source/CTest/cmCTestHandlerCommand.cxx b/Source/CTest/cmCTestHandlerCommand.cxx index 0e29160..5b525dd 100644 --- a/Source/CTest/cmCTestHandlerCommand.cxx +++ b/Source/CTest/cmCTestHandlerCommand.cxx @@ -137,7 +137,7 @@ bool cmCTestHandlerCommand } std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory(); cmSystemTools::ChangeDirectory( - this->CTest->GetCTestConfiguration("BuildDirectory").c_str()); + this->CTest->GetCTestConfiguration("BuildDirectory")); int res = handler->ProcessHandler(); if ( this->Values[ct_RETURN_VALUE] && *this->Values[ct_RETURN_VALUE]) { @@ -146,7 +146,7 @@ bool cmCTestHandlerCommand this->Makefile->AddDefinition( this->Values[ct_RETURN_VALUE], str.str().c_str()); } - cmSystemTools::ChangeDirectory(current_dir.c_str()); + cmSystemTools::ChangeDirectory(current_dir); return true; } diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index 10a5199..b65d23b 100644 --- a/Source/CTest/cmCTestLaunch.cxx +++ b/Source/CTest/cmCTestLaunch.cxx @@ -48,8 +48,8 @@ cmCTestLaunch::~cmCTestLaunch() cmsysProcess_Delete(this->Process); if(!this->Passthru) { - cmSystemTools::RemoveFile(this->LogOut.c_str()); - cmSystemTools::RemoveFile(this->LogErr.c_str()); + cmSystemTools::RemoveFile(this->LogOut); + cmSystemTools::RemoveFile(this->LogErr); } } @@ -434,8 +434,8 @@ void cmCTestLaunch::WriteXMLAction(std::ostream& fxml) // If file is in source tree use its relative location. if(cmSystemTools::FileIsFullPath(this->SourceDir.c_str()) && cmSystemTools::FileIsFullPath(source.c_str()) && - cmSystemTools::IsSubDirectory(source.c_str(), - this->SourceDir.c_str())) + cmSystemTools::IsSubDirectory(source, + this->SourceDir)) { source = cmSystemTools::RelativePath(this->SourceDir.c_str(), source.c_str()); diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index 4835010..089e84b 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -1221,10 +1221,10 @@ cmCTestMemCheckHandler::PostProcessBoundsCheckerTest(cmCTestTestResult& res, } } cmSystemTools::Delay(1000); - cmSystemTools::RemoveFile(this->BoundsCheckerDPBDFile.c_str()); + cmSystemTools::RemoveFile(this->BoundsCheckerDPBDFile); cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Remove: " << this->BoundsCheckerDPBDFile << std::endl); - cmSystemTools::RemoveFile(this->BoundsCheckerXMLFile.c_str()); + cmSystemTools::RemoveFile(this->BoundsCheckerXMLFile); cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Remove: " << this->BoundsCheckerXMLFile << std::endl); } @@ -1255,7 +1255,7 @@ cmCTestMemCheckHandler::AppendMemTesterOutput(cmCTestTestResult& res, } if(this->LogWithPID) { - cmSystemTools::RemoveFile(ofile.c_str()); + cmSystemTools::RemoveFile(ofile); cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Remove: "<< ofile <<"\n"); } } diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index 7ba434c..4c89caa 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -123,7 +123,7 @@ void cmCTestMultiProcessHandler::StartTestProcess(int test) testRun->SetTestProperties(this->Properties[test]); std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory(); - cmSystemTools::ChangeDirectory(this->Properties[test]->Directory.c_str()); + cmSystemTools::ChangeDirectory(this->Properties[test]->Directory); // Lock the resources we'll be using this->LockResources(test); @@ -156,7 +156,7 @@ void cmCTestMultiProcessHandler::StartTestProcess(int test) this->Failed->push_back(this->Properties[test]->Name); delete testRun; } - cmSystemTools::ChangeDirectory(current_dir.c_str()); + cmSystemTools::ChangeDirectory(current_dir); } //--------------------------------------------------------- @@ -334,7 +334,7 @@ void cmCTestMultiProcessHandler::UpdateCostData() { if(line == "---") break; std::vector<cmsys::String> parts = - cmSystemTools::SplitString(line.c_str(), ' '); + cmSystemTools::SplitString(line, ' '); //Format: <name> <previous_runs> <avg_cost> if(parts.size() < 3) break; @@ -357,7 +357,7 @@ void cmCTestMultiProcessHandler::UpdateCostData() } } fin.close(); - cmSystemTools::RemoveFile(fname.c_str()); + cmSystemTools::RemoveFile(fname); } // Add all tests not previously listed in the file @@ -393,7 +393,7 @@ void cmCTestMultiProcessHandler::ReadCostData() if(line == "---") break; std::vector<cmsys::String> parts = - cmSystemTools::SplitString(line.c_str(), ' '); + cmSystemTools::SplitString(line, ' '); // Probably an older version of the file, will be fixed next run if(parts.size() < 3) @@ -621,7 +621,7 @@ void cmCTestMultiProcessHandler::MarkFinished() { std::string fname = this->CTest->GetBinaryDir() + "/Testing/Temporary/CTestCheckpoint.txt"; - cmSystemTools::RemoveFile(fname.c_str()); + cmSystemTools::RemoveFile(fname); } //--------------------------------------------------------- @@ -639,7 +639,7 @@ void cmCTestMultiProcessHandler::PrintTestList() //push working dir std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory(); - cmSystemTools::ChangeDirectory(p.Directory.c_str()); + cmSystemTools::ChangeDirectory(p.Directory); cmCTestRunTest testRun(this->TestHandler); testRun.SetIndex(p.Index); @@ -676,7 +676,7 @@ void cmCTestMultiProcessHandler::PrintTestList() cmCTestLog(this->CTest, HANDLER_OUTPUT, " "); cmCTestLog(this->CTest, HANDLER_OUTPUT, p.Name.c_str() << std::endl); //pop working dir - cmSystemTools::ChangeDirectory(current_dir.c_str()); + cmSystemTools::ChangeDirectory(current_dir); } cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl << "Total Tests: " @@ -735,7 +735,7 @@ void cmCTestMultiProcessHandler::CheckResume() } else if(cmSystemTools::FileExists(fname.c_str(), true)) { - cmSystemTools::RemoveFile(fname.c_str()); + cmSystemTools::RemoveFile(fname); } } diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index bdd8c02..9e3c9fc 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -280,12 +280,12 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) // Set the working directory to the tests directory std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory(); - cmSystemTools::ChangeDirectory(this->TestProperties->Directory.c_str()); + cmSystemTools::ChangeDirectory(this->TestProperties->Directory); this->DartProcessing(); // restore working directory - cmSystemTools::ChangeDirectory(oldpath.c_str()); + cmSystemTools::ChangeDirectory(oldpath); // if this is doing MemCheck then all the output needs to be put into diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index f050148..749eb58 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -184,7 +184,7 @@ int cmCTestScriptHandler::ProcessHandler() { // for each script run it res += this->RunConfigurationScript - (cmSystemTools::CollapseFullPath(this->ConfigurationScripts[i].c_str()), + (cmSystemTools::CollapseFullPath(this->ConfigurationScripts[i]), this->ScriptProcessScope[i]); } if ( res ) @@ -482,8 +482,8 @@ int cmCTestScriptHandler::ExtractVariables() = this->Makefile->GetSafeDefinition("CTEST_BINARY_DIRECTORY"); // add in translations for src and bin - cmSystemTools::AddKeepPath(this->SourceDir.c_str()); - cmSystemTools::AddKeepPath(this->BinaryDir.c_str()); + cmSystemTools::AddKeepPath(this->SourceDir); + cmSystemTools::AddKeepPath(this->BinaryDir); this->CTestCmd = this->Makefile->GetSafeDefinition("CTEST_COMMAND"); @@ -743,11 +743,11 @@ int cmCTestScriptHandler::BackupDirectories() // if for some reason those directories exist then first delete them if (cmSystemTools::FileExists(this->BackupSourceDir.c_str())) { - cmSystemTools::RemoveADirectory(this->BackupSourceDir.c_str()); + cmSystemTools::RemoveADirectory(this->BackupSourceDir); } if (cmSystemTools::FileExists(this->BackupBinaryDir.c_str())) { - cmSystemTools::RemoveADirectory(this->BackupBinaryDir.c_str()); + cmSystemTools::RemoveADirectory(this->BackupBinaryDir); } // first rename the src and binary directories @@ -991,8 +991,8 @@ int cmCTestScriptHandler::RunConfigurationDashboard() // if all was succesful, delete the backup dirs to free up disk space if (this->Backup) { - cmSystemTools::RemoveADirectory(this->BackupSourceDir.c_str()); - cmSystemTools::RemoveADirectory(this->BackupBinaryDir.c_str()); + cmSystemTools::RemoveADirectory(this->BackupSourceDir); + cmSystemTools::RemoveADirectory(this->BackupBinaryDir); } return 0; @@ -1033,11 +1033,11 @@ void cmCTestScriptHandler::RestoreBackupDirectories() // if for some reason those directories exist then first delete them if (cmSystemTools::FileExists(this->SourceDir.c_str())) { - cmSystemTools::RemoveADirectory(this->SourceDir.c_str()); + cmSystemTools::RemoveADirectory(this->SourceDir); } if (cmSystemTools::FileExists(this->BinaryDir.c_str())) { - cmSystemTools::RemoveADirectory(this->BinaryDir.c_str()); + cmSystemTools::RemoveADirectory(this->BinaryDir); } // rename the src and binary directories rename(this->BackupSourceDir.c_str(), this->SourceDir.c_str()); @@ -1100,7 +1100,7 @@ bool cmCTestScriptHandler::TryToRemoveBinaryDirectoryOnce( const std::string& directoryPath) { cmsys::Directory directory; - directory.Load(directoryPath.c_str()); + directory.Load(directoryPath); for(unsigned long i = 0; i < directory.GetNumberOfFiles(); ++i) { @@ -1113,26 +1113,26 @@ bool cmCTestScriptHandler::TryToRemoveBinaryDirectoryOnce( std::string fullPath = directoryPath + std::string("/") + path; - bool isDirectory = cmSystemTools::FileIsDirectory(fullPath.c_str()) && - !cmSystemTools::FileIsSymlink(fullPath.c_str()); + bool isDirectory = cmSystemTools::FileIsDirectory(fullPath) && + !cmSystemTools::FileIsSymlink(fullPath); if(isDirectory) { - if(!cmSystemTools::RemoveADirectory(fullPath.c_str())) + if(!cmSystemTools::RemoveADirectory(fullPath)) { return false; } } else { - if(!cmSystemTools::RemoveFile(fullPath.c_str())) + if(!cmSystemTools::RemoveFile(fullPath)) { return false; } } } - return cmSystemTools::RemoveADirectory(directoryPath.c_str()); + return cmSystemTools::RemoveADirectory(directoryPath); } //------------------------------------------------------------------------- diff --git a/Source/CTest/cmCTestStartCommand.cxx b/Source/CTest/cmCTestStartCommand.cxx index da46f4a..1a39a8a 100644 --- a/Source/CTest/cmCTestStartCommand.cxx +++ b/Source/CTest/cmCTestStartCommand.cxx @@ -124,7 +124,7 @@ bool cmCTestStartCommand { return false; } - if(!cmSystemTools::FileIsDirectory(sourceDir.c_str())) + if(!cmSystemTools::FileIsDirectory(sourceDir)) { cmOStringStream e; e << "given source path\n" diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index 06fcb75..6aa1c2b 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -234,9 +234,9 @@ bool cmCTestSubmitHandler::SubmitUsingFTP(const std::string& localprefix, ::curl_global_cleanup(); return false; } - unsigned long filelen = cmSystemTools::FileLength(local_file.c_str()); + unsigned long filelen = cmSystemTools::FileLength(local_file); - ftpfile = cmsys::SystemTools::Fopen(local_file.c_str(), "rb"); + ftpfile = cmsys::SystemTools::Fopen(local_file, "rb"); *this->LogFile << "\tUpload file: " << local_file << " to " << upload_as << std::endl; cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Upload file: " @@ -475,9 +475,9 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix, ::curl_global_cleanup(); return false; } - unsigned long filelen = cmSystemTools::FileLength(local_file.c_str()); + unsigned long filelen = cmSystemTools::FileLength(local_file); - ftpfile = cmsys::SystemTools::Fopen(local_file.c_str(), "rb"); + ftpfile = cmsys::SystemTools::Fopen(local_file, "rb"); cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Upload file: " << local_file << " to " << upload_as << " Size: " << filelen << std::endl); @@ -567,7 +567,7 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix, << count << std::endl); ::fclose(ftpfile); - ftpfile = cmsys::SystemTools::Fopen(local_file.c_str(), "rb"); + ftpfile = cmsys::SystemTools::Fopen(local_file, "rb"); ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile); chunk.clear(); @@ -931,13 +931,13 @@ bool cmCTestSubmitHandler::SubmitUsingCP( cmSystemTools::ConvertToUnixSlashes(lfname); lfname += "/" + *file; std::string rfname = destination + "/" + remoteprefix + *file; - cmSystemTools::CopyFileAlways(lfname.c_str(), rfname.c_str()); + cmSystemTools::CopyFileAlways(lfname, rfname); cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Copy file: " << lfname << " to " << rfname << std::endl); } std::string tagDoneFile = destination + "/" + remoteprefix + "DONE"; - cmSystemTools::Touch(tagDoneFile.c_str(), true); + cmSystemTools::Touch(tagDoneFile, true); if ( problems ) { return false; @@ -1418,20 +1418,20 @@ int cmCTestSubmitHandler::ProcessHandler() // change to the build directory so that we can uses a relative path // on windows since scp dosn't support "c:" a drive in the path oldWorkingDirectory = cmSystemTools::GetCurrentWorkingDirectory(); - cmSystemTools::ChangeDirectory(buildDirectory.c_str()); + cmSystemTools::ChangeDirectory(buildDirectory); if ( !this->SubmitUsingSCP( this->CTest->GetCTestConfiguration("ScpCommand"), "Testing/"+this->CTest->GetCurrentTag(), files, prefix, url) ) { - cmSystemTools::ChangeDirectory(oldWorkingDirectory.c_str()); + cmSystemTools::ChangeDirectory(oldWorkingDirectory); cmCTestLog(this->CTest, ERROR_MESSAGE, " Problems when submitting via SCP" << std::endl); ofs << " Problems when submitting via SCP" << std::endl; return -1; } - cmSystemTools::ChangeDirectory(oldWorkingDirectory.c_str()); + cmSystemTools::ChangeDirectory(oldWorkingDirectory); cmCTestLog(this->CTest, HANDLER_OUTPUT, " Submission successful" << std::endl); ofs << " Submission successful" << std::endl; @@ -1447,7 +1447,7 @@ int cmCTestSubmitHandler::ProcessHandler() // on windows since scp dosn't support "c:" a drive in the path std::string oldWorkingDirectory = cmSystemTools::GetCurrentWorkingDirectory(); - cmSystemTools::ChangeDirectory(buildDirectory.c_str()); + cmSystemTools::ChangeDirectory(buildDirectory); cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Change directory: " << buildDirectory << std::endl); @@ -1457,14 +1457,14 @@ int cmCTestSubmitHandler::ProcessHandler() prefix, location) ) { - cmSystemTools::ChangeDirectory(oldWorkingDirectory.c_str()); + cmSystemTools::ChangeDirectory(oldWorkingDirectory); cmCTestLog(this->CTest, ERROR_MESSAGE, " Problems when submitting via CP" << std::endl); ofs << " Problems when submitting via cp" << std::endl; return -1; } - cmSystemTools::ChangeDirectory(oldWorkingDirectory.c_str()); + cmSystemTools::ChangeDirectory(oldWorkingDirectory); cmCTestLog(this->CTest, HANDLER_OUTPUT, " Submission successful" << std::endl); ofs << " Submission successful" << std::endl; diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index f21d166..f330e58 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -93,12 +93,12 @@ bool cmCTestSubdirCommand fname += *it; } - if ( !cmSystemTools::FileIsDirectory(fname.c_str()) ) + if ( !cmSystemTools::FileIsDirectory(fname) ) { // No subdirectory? So what... continue; } - cmSystemTools::ChangeDirectory(fname.c_str()); + cmSystemTools::ChangeDirectory(fname); const char* testFilename; if( cmSystemTools::FileExists("CTestTestfile.cmake") ) { @@ -120,7 +120,7 @@ bool cmCTestSubdirCommand bool readit = this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(), fname.c_str()); - cmSystemTools::ChangeDirectory(cwd.c_str()); + cmSystemTools::ChangeDirectory(cwd); if(!readit) { std::string m = "Could not find include file: "; @@ -129,7 +129,7 @@ bool cmCTestSubdirCommand return false; } } - cmSystemTools::ChangeDirectory(cwd.c_str()); + cmSystemTools::ChangeDirectory(cwd); return true; } @@ -175,7 +175,7 @@ bool cmCTestAddSubdirectoryCommand } std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); - cmSystemTools::ChangeDirectory(cwd.c_str()); + cmSystemTools::ChangeDirectory(cwd); std::string fname = cwd; fname += "/"; fname += args[1]; @@ -185,7 +185,7 @@ bool cmCTestAddSubdirectoryCommand // No subdirectory? So what... return true; } - cmSystemTools::ChangeDirectory(fname.c_str()); + cmSystemTools::ChangeDirectory(fname); const char* testFilename; if( cmSystemTools::FileExists("CTestTestfile.cmake") ) { @@ -200,7 +200,7 @@ bool cmCTestAddSubdirectoryCommand else { // No CTestTestfile? Who cares... - cmSystemTools::ChangeDirectory(cwd.c_str()); + cmSystemTools::ChangeDirectory(cwd); return true; } fname += "/"; @@ -208,7 +208,7 @@ bool cmCTestAddSubdirectoryCommand bool readit = this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(), fname.c_str()); - cmSystemTools::ChangeDirectory(cwd.c_str()); + cmSystemTools::ChangeDirectory(cwd); if(!readit) { std::string m = "Could not find include file: "; @@ -1498,9 +1498,9 @@ std::string cmCTestTestHandler { // first check without exe extension if(cmSystemTools::FileExists(attempted[ai].c_str()) - && !cmSystemTools::FileIsDirectory(attempted[ai].c_str())) + && !cmSystemTools::FileIsDirectory(attempted[ai])) { - fullPath = cmSystemTools::CollapseFullPath(attempted[ai].c_str()); + fullPath = cmSystemTools::CollapseFullPath(attempted[ai]); resultingConfig = attemptedConfigs[ai]; } // then try with the exe extension @@ -1510,9 +1510,9 @@ std::string cmCTestTestHandler tempPath = attempted[ai]; tempPath += cmSystemTools::GetExecutableExtension(); if(cmSystemTools::FileExists(tempPath.c_str()) - && !cmSystemTools::FileIsDirectory(tempPath.c_str())) + && !cmSystemTools::FileIsDirectory(tempPath)) { - fullPath = cmSystemTools::CollapseFullPath(tempPath.c_str()); + fullPath = cmSystemTools::CollapseFullPath(tempPath); resultingConfig = attemptedConfigs[ai]; } else @@ -1746,7 +1746,7 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed() std::string dirName = this->CTest->GetBinaryDir() + "/Testing/Temporary"; cmsys::Directory directory; - if (directory.Load(dirName.c_str()) == 0) + if (directory.Load(dirName) == 0) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to read the contents of " << dirName << std::endl); @@ -1754,7 +1754,7 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed() } int numFiles = static_cast<int> - (cmsys::Directory::GetNumberOfFilesInDirectory(dirName.c_str())); + (cmsys::Directory::GetNumberOfFilesInDirectory(dirName)); std::string pattern = "LastTestsFailed"; std::string logName = ""; @@ -1777,7 +1777,7 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed() // if multiple matching logs were found we use the most recently // modified one. int res; - cmSystemTools::FileTimeCompare(logName.c_str(), fileName.c_str(), &res); + cmSystemTools::FileTimeCompare(logName, fileName, &res); if (res == -1) { logName = fileName; @@ -1939,7 +1939,7 @@ std::string cmCTestTestHandler::GenerateRegressionImages( cmCTest::CleanString(measurementfile.match(5)); if ( cmSystemTools::FileExists(filename.c_str()) ) { - long len = cmSystemTools::FileLength(filename.c_str()); + long len = cmSystemTools::FileLength(filename); if ( len == 0 ) { std::string k1 = measurementfile.match(1); diff --git a/Source/CTest/cmCTestUpdateHandler.cxx b/Source/CTest/cmCTestUpdateHandler.cxx index 68f5fe1..7206914 100644 --- a/Source/CTest/cmCTestUpdateHandler.cxx +++ b/Source/CTest/cmCTestUpdateHandler.cxx @@ -98,7 +98,7 @@ cmCTestUpdateHandlerLocale::~cmCTestUpdateHandlerLocale() { std::string put = "LC_MESSAGES="; put += saveLCMessages; - cmSystemTools::PutEnv(put.c_str()); + cmSystemTools::PutEnv(put); } else { diff --git a/Source/CTest/cmParseBlanketJSCoverage.cxx b/Source/CTest/cmParseBlanketJSCoverage.cxx new file mode 100644 index 0000000..fc90bc1 --- /dev/null +++ b/Source/CTest/cmParseBlanketJSCoverage.cxx @@ -0,0 +1,166 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2009 Kitware, Inc. + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmStandardIncludes.h" +#include <stdio.h> +#include <stdlib.h> +#include "cmSystemTools.h" +#include "cmParseBlanketJSCoverage.h" +#include <cmsys/Directory.hxx> +#include <cmsys/Glob.hxx> +#include <cmsys/FStream.hxx> + + +class cmParseBlanketJSCoverage::JSONParser + { +public: + typedef cmCTestCoverageHandlerContainer:: + SingleFileCoverageVector FileLinesType; + JSONParser(cmCTestCoverageHandlerContainer& cont) + : Coverage(cont) + { + } + + 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) + { + // 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)); + return foundFileName; + } + else + { + return line.substr(begIndex,line.npos); + } + } + bool ParseFile(std::string file) + { + FileLinesType localCoverageVector; + std::string filename; + bool foundFile = false; + bool inSource = false; + std::string covResult; + std::string line; + + cmsys::ifstream in(file.c_str()); + if(!in) + { + return false; + } + 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]; + CoverageVector = localCoverageVector; + localCoverageVector.clear(); + foundFile=false; + } + 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 + * + * The coverage result over the file or set of files + * and the coverage for each individual line + * + * 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 == "\"\"") + { + // Empty quotation marks indicate that the + // line is not executable + localCoverageVector.push_back(-1); + } + 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; + } + } + + // On exit, capture end of last file covered. + FileLinesType& CoverageVector = + this->Coverage.TotalCoverage[filename]; + CoverageVector = localCoverageVector; + foundFile=false; + localCoverageVector.clear(); + return true; + } +private: + cmCTestCoverageHandlerContainer& Coverage; +}; + +cmParseBlanketJSCoverage::cmParseBlanketJSCoverage( + cmCTestCoverageHandlerContainer& cont, cmCTest* ctest) + :Coverage(cont), CTest(ctest) + { + } + +bool cmParseBlanketJSCoverage::LoadCoverageData(std::vector<std::string> files) + { + size_t i=0; + std::string path; + cmCTestLog(this->CTest,HANDLER_VERBOSE_OUTPUT, + "Found " << files.size() <<" Files" << std::endl); + for(i=0;i<files.size();i++) + { + cmCTestLog(this->CTest,HANDLER_VERBOSE_OUTPUT, + "Reading JSON File " << files[i] << std::endl); + + if(!this->ReadJSONFile(files[i])) + { + return false; + } + } + return true; + } + +bool cmParseBlanketJSCoverage::ReadJSONFile(std::string file) + { + cmParseBlanketJSCoverage::JSONParser parser + (this->Coverage); + cmCTestLog(this->CTest,HANDLER_VERBOSE_OUTPUT, + "Parsing " << file << std::endl); + parser.ParseFile(file); + return true; + } diff --git a/Source/CTest/cmParseBlanketJSCoverage.h b/Source/CTest/cmParseBlanketJSCoverage.h new file mode 100644 index 0000000..fc1d477 --- /dev/null +++ b/Source/CTest/cmParseBlanketJSCoverage.h @@ -0,0 +1,48 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2009 Kitware, Inc. + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#ifndef cmParseBlanketJSCoverage_h +#define cmParseBlanketJSCoverage_h + +#include "cmStandardIncludes.h" +#include "cmCTestCoverageHandler.h" + + +/** \class cmParseBlanketJSCoverage + * \brief Parse BlanketJS coverage information + * + * This class is used to parse BlanketJS(Pascal) coverage information + * generated by the Blanket.js library when used in conjunction with the + * test runner mocha.js, which is used to write out the JSON format. + * + * Blanket.js: + * http://blanketjs.org/ + * + * Mocha.js + * http://visionmedia.github.io/mocha/ + */ +class cmParseBlanketJSCoverage +{ +public: + cmParseBlanketJSCoverage(cmCTestCoverageHandlerContainer& cont, + cmCTest* ctest); + bool LoadCoverageData(std::vector<std::string> files); + // Read the JSON output + bool ReadJSONFile(std::string file); + +protected: + + class JSONParser; + cmCTestCoverageHandlerContainer& Coverage; + cmCTest* CTest; +}; +#endif diff --git a/Source/CTest/cmParseCacheCoverage.cxx b/Source/CTest/cmParseCacheCoverage.cxx index d17f169..97454a8 100644 --- a/Source/CTest/cmParseCacheCoverage.cxx +++ b/Source/CTest/cmParseCacheCoverage.cxx @@ -31,7 +31,7 @@ bool cmParseCacheCoverage::LoadCoverageData(const char* d) { std::string file = dir.GetFile(i); if(file != "." && file != ".." - && !cmSystemTools::FileIsDirectory(file.c_str())) + && !cmSystemTools::FileIsDirectory(file)) { std::string path = d; path += "/"; diff --git a/Source/CTest/cmParseDelphiCoverage.cxx b/Source/CTest/cmParseDelphiCoverage.cxx new file mode 100644 index 0000000..ad71c85 --- /dev/null +++ b/Source/CTest/cmParseDelphiCoverage.cxx @@ -0,0 +1,253 @@ +#include "cmStandardIncludes.h" +#include <stdio.h> +#include <stdlib.h> +#include "cmSystemTools.h" +#include "cmXMLParser.h" +#include "cmParseDelphiCoverage.h" +#include <cmsys/Directory.hxx> +#include <cmsys/Glob.hxx> +#include <cmsys/FStream.hxx> + + +class cmParseDelphiCoverage::HTMLParser +{ +public: + typedef cmCTestCoverageHandlerContainer::SingleFileCoverageVector + FileLinesType; + HTMLParser(cmCTest* ctest, cmCTestCoverageHandlerContainer& cont) + : CTest(ctest), Coverage(cont) + { + } + + virtual ~HTMLParser() + { + } + + bool initializeDelphiFile(const std::string filename, + cmParseDelphiCoverage::HTMLParser::FileLinesType &coverageVector) + { + std::string line; + size_t comPos; + size_t semiPos; + bool blockComFlag= false; + bool lineComFlag= false; + std::vector<std::string> beginSet; + cmsys::ifstream in(filename.c_str()); + if(!in) + { + return false; + } + while(cmSystemTools::GetLineFromStream(in, line)) + { + lineComFlag=false; + // Unique cases found in lines. + size_t beginPos = line.find("begin"); + + //Check that the begin is the first non-space string on the line + if( (beginPos == line.find_first_not_of(' ')) && beginPos != line.npos ) + { + beginSet.push_back("begin"); + coverageVector.push_back(-1); + continue; + } + else if(line.find('{') != line.npos) + { + blockComFlag=true; + } + else if(line.find('}') != line.npos) + { + blockComFlag=false; + coverageVector.push_back(-1); + continue; + } + else if((line.find("end;") != line.npos) + && (beginSet.size() > 0)) + { + beginSet.pop_back(); + coverageVector.push_back(-1); + continue; + } + + // This checks for comments after lines of code, finding the + // comment symbol after the ending semicolon. + comPos = line.find("//"); + if(comPos != line.npos) + { + semiPos= line.find(';'); + if(comPos < semiPos) + { + lineComFlag=true; + } + } + //Based up what was found, add a line to the coverageVector + if((beginSet.size() > 0) && line != "" && !blockComFlag + && !lineComFlag) + { + coverageVector.push_back(0); + } + else + { + coverageVector.push_back(-1); + } + } + return true; + } + bool ParseFile(const char* file) + { + std::string line=file; + std::string lineresult; + std::string lastroutine; + std::string filename; + std::string filelineoffset; + size_t afterLineNum = 0; + size_t lastoffset = 0; + size_t endcovpos = 0; + size_t endnamepos = 0; + size_t pos = 0; + + /* + * This first 'while' section goes through the found HTML + * file name and attempts to capture the source file name + * which is set as part of the HTML file name: the name of + * the file is found in parenthesis '()' + * + * See test HTML file name: UTCovTest(UTCovTest.pas).html. + * + * Find the text inside each pair of parenthesis and check + * to see if it ends in '.pas'. If it can't be found, + * exit the function. + */ + while(true) + { + lastoffset = line.find('(',pos); + if(lastoffset==line.npos) + { + cmCTestLog(this->CTest,HANDLER_VERBOSE_OUTPUT, + endnamepos << "File not found " << lastoffset << std::endl); + return false; + } + endnamepos = line.find(')',lastoffset); + filename = line.substr(lastoffset+1, + (endnamepos-1)-lastoffset); + if(filename.find(".pas") != filename.npos) + { + cmCTestLog(this->CTest,HANDLER_VERBOSE_OUTPUT, + "Coverage found for file: " << filename << std::endl); + break; + } + pos = lastoffset+1; + endnamepos = 0; + lastoffset =0; + } + /* + * Glob through the source directory for the + * file found above + */ + cmsys::Glob gl; + gl.RecurseOn(); + gl.RecurseThroughSymlinksOff(); + std::string glob = Coverage.SourceDir + "*/" + filename; + gl.FindFiles(glob); + std::vector<std::string> const& files = gl.GetFiles(); + if(files.size() == 0) + { + /* + * If that doesn't find any matching files + * return a failure. + */ + cmCTestLog(this->CTest,HANDLER_VERBOSE_OUTPUT, + "Unable to find file matching" << glob << std::endl); + return false; + } + FileLinesType& coverageVector = + this->Coverage.TotalCoverage[files[0]]; + + /* + * Initialize the file to have all code between 'begin' and + * 'end' tags marked as executable + */ + + this->initializeDelphiFile(files[0],coverageVector); + + cmsys::ifstream in(file); + if(!in) + { + return false; + } + + /* + * Now read the HTML file, looking for the lines that have an + * "inline" in it. Then parse out the "class" value of that + * line to determine if the line is executed or not. + * + * Sample HTML line: + * + * <tr class="covered"><td>47</td><td><pre style="display:inline;"> + * CheckEquals(1,2-1);</pre></td></tr> + * + */ + + while( cmSystemTools::GetLineFromStream(in, line)) + { + if(line.find("inline") == line.npos) + { + continue; + } + + lastoffset = line.find("class="); + endcovpos = line.find(">",lastoffset); + lineresult = line.substr(lastoffset+7,(endcovpos-8)-lastoffset); + + if(lineresult == "covered") + { + afterLineNum = line.find('<',endcovpos+5); + filelineoffset= line.substr(endcovpos+5, + afterLineNum-(endcovpos+5)); + coverageVector[atoi(filelineoffset.c_str())-1] = 1; + } + } + return true; + } + + + private: + cmCTest* CTest; + cmCTestCoverageHandlerContainer& Coverage; +}; + +cmParseDelphiCoverage::cmParseDelphiCoverage( + cmCTestCoverageHandlerContainer& cont, cmCTest* ctest) + :Coverage(cont), CTest(ctest) + { + } + +bool cmParseDelphiCoverage::LoadCoverageData( + const std::vector<std::string> files) + { + size_t i; + std::string path; + size_t numf = files.size(); + for (i = 0; i < numf; i++) + { + path = files[i]; + + cmCTestLog(this->CTest,HANDLER_VERBOSE_OUTPUT, + "Reading HTML File " << path << std::endl); + if(cmSystemTools::GetFilenameLastExtension(path) == ".html") + { + if(!this->ReadDelphiHTML(path.c_str())) + { + return false; + } + } + } + return true; + }; + +bool cmParseDelphiCoverage::ReadDelphiHTML(const char* file) + { + cmParseDelphiCoverage::HTMLParser + parser(this->CTest, this->Coverage); + parser.ParseFile(file); + return true; + }; diff --git a/Source/CTest/cmParseDelphiCoverage.h b/Source/CTest/cmParseDelphiCoverage.h new file mode 100644 index 0000000..018340b --- /dev/null +++ b/Source/CTest/cmParseDelphiCoverage.h @@ -0,0 +1,46 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2009 Kitware, Inc. + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#ifndef cmParseDelphiCoverage_h +#define cmParseDelphiCoverage_h + +#include "cmStandardIncludes.h" +#include "cmCTestCoverageHandler.h" + + +/** \class cmParseDelphiCoverage + * \brief Parse Delphi coverage information + * + * This class is used to parse Delphi(Pascal) coverage information + * generated by the Delphi-Code-Coverage tool + * + * https://code.google.com/p/delphi-code-coverage/ + */ + +class cmParseDelphiCoverage + { + public: + cmParseDelphiCoverage(cmCTestCoverageHandlerContainer& cont, + cmCTest* ctest); + bool LoadCoverageData(const std::vector<std::string> files); + bool ReadDelphiHTML(const char* file); + // Read a single HTML file from output + bool ReadHTMLFile(const char* f); + + + protected: + + class HTMLParser; + cmCTestCoverageHandlerContainer& Coverage; + cmCTest* CTest; + }; +#endif diff --git a/Source/CTest/cmParseGTMCoverage.cxx b/Source/CTest/cmParseGTMCoverage.cxx index be10c2e..d77244a 100644 --- a/Source/CTest/cmParseGTMCoverage.cxx +++ b/Source/CTest/cmParseGTMCoverage.cxx @@ -30,7 +30,7 @@ bool cmParseGTMCoverage::LoadCoverageData(const char* d) { std::string file = dir.GetFile(i); if(file != "." && file != ".." - && !cmSystemTools::FileIsDirectory(file.c_str())) + && !cmSystemTools::FileIsDirectory(file)) { std::string path = d; path += "/"; diff --git a/Source/CTest/cmParsePHPCoverage.cxx b/Source/CTest/cmParsePHPCoverage.cxx index 3b7f968..c7f5a68 100644 --- a/Source/CTest/cmParsePHPCoverage.cxx +++ b/Source/CTest/cmParsePHPCoverage.cxx @@ -239,7 +239,7 @@ bool cmParsePHPCoverage::ReadPHPCoverageDirectory(const char* d) { std::string file = dir.GetFile(i); if(file != "." && file != ".." - && !cmSystemTools::FileIsDirectory(file.c_str())) + && !cmSystemTools::FileIsDirectory(file)) { std::string path = d; path += "/"; |