diff options
author | Brad King <brad.king@kitware.com> | 2009-01-05 19:14:10 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-01-05 19:14:10 (GMT) |
commit | 2703d51b8f382f3d20abe409b116eb0afd5051ff (patch) | |
tree | b3207fe2d42965e0900756eac3a0194ceae4170f | |
parent | 86aeefc7c97cd65d952513963400d28e6eb32808 (diff) | |
download | CMake-2703d51b8f382f3d20abe409b116eb0afd5051ff.zip CMake-2703d51b8f382f3d20abe409b116eb0afd5051ff.tar.gz CMake-2703d51b8f382f3d20abe409b116eb0afd5051ff.tar.bz2 |
BUG: Capture cout and cerr from internal ctest
When CTest detects that a test is running its own executable it
optimizes the test by using an internal instance of cmCTest instead of
creating a new process. However, the internal instance was using cout
and cerr directly. This redirects the output to a string stream to
avoid direct display of the internal test's output.
-rw-r--r-- | Source/cmCTest.cxx | 52 | ||||
-rw-r--r-- | Source/cmCTest.h | 8 |
2 files changed, 42 insertions, 18 deletions
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 78b11cf..15f1178 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -258,6 +258,7 @@ cmCTest::cmCTest() this->OutputLogFileLastTag = -1; this->SuppressUpdatingCTestConfiguration = false; this->DartVersion = 1; + this->InitStreams(); int cc; for ( cc=0; cc < cmCTest::LAST_TEST; cc ++ ) @@ -1136,6 +1137,11 @@ int cmCTest::RunTest(std::vector<const char*> argv, cmCTest inst; inst.ConfigType = this->ConfigType; inst.TimeOut = timeout; + + // Capture output of the child ctest. + cmOStringStream oss; + inst.SetStreams(&oss, &oss); + std::vector<std::string> args; for(unsigned int i =0; i < argv.size(); ++i) { @@ -1166,6 +1172,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, } *retVal = inst.Run(args, output); + *output += oss.str(); if ( log ) { *log << output->c_str(); @@ -2602,6 +2609,13 @@ static const char* cmCTestStringLogType[] = (stream) << std::endl << file << ":" << line << " "; \ } +void cmCTest::InitStreams() +{ + // By default we write output to the process output streams. + this->StreamOut = &std::cout; + this->StreamErr = &std::cerr; +} + void cmCTest::Log(int logType, const char* file, int line, const char* msg) { if ( !msg || !*msg ) @@ -2640,47 +2654,49 @@ void cmCTest::Log(int logType, const char* file, int line, const char* msg) } if ( !this->Quiet ) { + std::ostream& out = *this->StreamOut; + std::ostream& err = *this->StreamErr; switch ( logType ) { case DEBUG: if ( this->Debug ) { - cmCTestLogOutputFileLine(std::cout); - std::cout << msg; - std::cout.flush(); + cmCTestLogOutputFileLine(out); + out << msg; + out.flush(); } break; case OUTPUT: case HANDLER_OUTPUT: if ( this->Debug || this->Verbose ) { - cmCTestLogOutputFileLine(std::cout); - std::cout << msg; - std::cout.flush(); + cmCTestLogOutputFileLine(out); + out << msg; + out.flush(); } break; case HANDLER_VERBOSE_OUTPUT: if ( this->Debug || this->ExtraVerbose ) { - cmCTestLogOutputFileLine(std::cout); - std::cout << msg; - std::cout.flush(); + cmCTestLogOutputFileLine(out); + out << msg; + out.flush(); } break; case WARNING: - cmCTestLogOutputFileLine(std::cerr); - std::cerr << msg; - std::cerr.flush(); + cmCTestLogOutputFileLine(err); + err << msg; + err.flush(); break; case ERROR_MESSAGE: - cmCTestLogOutputFileLine(std::cerr); - std::cerr << msg; - std::cerr.flush(); + cmCTestLogOutputFileLine(err); + err << msg; + err.flush(); cmSystemTools::SetErrorOccured(); break; default: - cmCTestLogOutputFileLine(std::cout); - std::cout << msg; - std::cout.flush(); + cmCTestLogOutputFileLine(out); + out << msg; + out.flush(); } } } diff --git a/Source/cmCTest.h b/Source/cmCTest.h index a9bdb62..10a7d5b 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -331,6 +331,10 @@ public: bool GetVerbose() { return this->Verbose;} bool GetExtraVerbose() { return this->ExtraVerbose;} + + /** Direct process output to given streams. */ + void SetStreams(std::ostream* out, std::ostream* err) + { this->StreamOut = out; this->StreamErr = err; } private: std::string ConfigType; bool Verbose; @@ -402,6 +406,10 @@ private: bool CompressXMLFiles; + void InitStreams(); + std::ostream* StreamOut; + std::ostream* StreamErr; + void BlockTestErrorDiagnostics(); |