summaryrefslogtreecommitdiffstats
path: root/Source/CTest/cmCTestBuildAndTestHandler.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/CTest/cmCTestBuildAndTestHandler.cxx')
-rw-r--r--Source/CTest/cmCTestBuildAndTestHandler.cxx60
1 files changed, 32 insertions, 28 deletions
diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx
index 0fac136..627832c 100644
--- a/Source/CTest/cmCTestBuildAndTestHandler.cxx
+++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx
@@ -156,34 +156,36 @@ void CMakeProgressCallback(const char*msg, float , void * s)
}
//----------------------------------------------------------------------
-void CMakeStdoutCallback(const char* m, int len, void* s)
+void CMakeOutputCallback(const char* m, size_t len, void* s)
{
std::string* out = (std::string*)s;
out->append(m, len);
}
-struct cmSetupOutputCaptureCleanup
+
+//----------------------------------------------------------------------
+class cmCTestBuildAndTestCaptureRAII
{
- ~cmSetupOutputCaptureCleanup()
- {
- cmSystemTools::SetErrorCallback(0, 0);
+ cmake& CM;
+public:
+ cmCTestBuildAndTestCaptureRAII(cmake& cm, std::string& s): CM(cm)
+ {
+ cmSystemTools::SetMessageCallback(CMakeMessageCallback, &s);
+ cmSystemTools::SetStdoutCallback(CMakeOutputCallback, &s);
+ cmSystemTools::SetStderrCallback(CMakeOutputCallback, &s);
+ this->CM.SetProgressCallback(CMakeProgressCallback, &s);
+ }
+ ~cmCTestBuildAndTestCaptureRAII()
+ {
+ this->CM.SetProgressCallback(0, 0);
+ cmSystemTools::SetStderrCallback(0, 0);
cmSystemTools::SetStdoutCallback(0, 0);
- }
+ cmSystemTools::SetMessageCallback(0, 0);
+ }
};
//----------------------------------------------------------------------
int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
{
- unsigned int k;
- std::string cmakeOutString;
- cmSystemTools::SetErrorCallback(CMakeMessageCallback, &cmakeOutString);
- cmSystemTools::SetStdoutCallback(CMakeStdoutCallback, &cmakeOutString);
- // make sure SetStdoutCallback and SetErrorCallback are set to null
- // after this function exits so that they do not point at a destroyed
- // string cmakeOutString
- cmSetupOutputCaptureCleanup cleanup;
- static_cast<void>(cleanup);
- cmOStringStream out;
-
// if the generator and make program are not specified then it is an error
if (!this->BuildGenerator.size())
{
@@ -197,6 +199,12 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
return 1;
}
+ cmake cm;
+ std::string cmakeOutString;
+ cmCTestBuildAndTestCaptureRAII captureRAII(cm, cmakeOutString);
+ static_cast<void>(captureRAII);
+ cmOStringStream out;
+
if ( this->CTest->GetConfigType().size() == 0 &&
this->ConfigSample.size())
{
@@ -233,19 +241,15 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
}
cmSystemTools::ChangeDirectory(this->BinaryDir.c_str());
- // should we cmake?
- cmake cm;
- cm.SetProgressCallback(CMakeProgressCallback, &cmakeOutString);
-
if(this->BuildNoCMake)
{
// Make the generator available for the Build call below.
cm.SetGlobalGenerator(cm.CreateGlobalGenerator(
- this->BuildGenerator.c_str()));
+ this->BuildGenerator));
cm.SetGeneratorToolset(this->BuildGeneratorToolset);
// Load the cache to make CMAKE_MAKE_PROGRAM available.
- cm.GetCacheManager()->LoadCache(this->BinaryDir.c_str());
+ cm.GetCacheManager()->LoadCache(this->BinaryDir);
}
else
{
@@ -295,9 +299,9 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
config = "Debug";
}
int retVal = cm.GetGlobalGenerator()->Build(
- this->SourceDir.c_str(), this->BinaryDir.c_str(),
- this->BuildProject.c_str(), tarIt->c_str(),
- &output, this->BuildMakeProgram.c_str(),
+ this->SourceDir, this->BinaryDir,
+ this->BuildProject, *tarIt,
+ output, this->BuildMakeProgram,
config,
!this->BuildNoClean,
false, remainingTime);
@@ -369,7 +373,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
std::vector<const char*> testCommand;
testCommand.push_back(fullPath.c_str());
- for(k=0; k < this->TestCommandArgs.size(); ++k)
+ for(size_t k=0; k < this->TestCommandArgs.size(); ++k)
{
testCommand.push_back(this->TestCommandArgs[k].c_str());
}
@@ -383,7 +387,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
cmSystemTools::ChangeDirectory(this->BuildRunDir.c_str());
}
out << "Running test command: \"" << fullPath << "\"";
- for(k=0; k < this->TestCommandArgs.size(); ++k)
+ for(size_t k=0; k < this->TestCommandArgs.size(); ++k)
{
out << " \"" << this->TestCommandArgs[k] << "\"";
}