[Cmake-commits] [cmake-commits] king committed cmCTest.cxx 1.342 1.343 cmCTest.h 1.104 1.105

cmake-commits at cmake.org cmake-commits at cmake.org
Mon Jan 5 14:14:13 EST 2009


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv16606/Source

Modified Files:
	cmCTest.cxx cmCTest.h 
Log Message:
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.


Index: cmCTest.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCTest.h,v
retrieving revision 1.104
retrieving revision 1.105
diff -C 2 -d -r1.104 -r1.105
*** cmCTest.h	28 Nov 2008 15:50:20 -0000	1.104
--- cmCTest.h	5 Jan 2009 19:14:10 -0000	1.105
***************
*** 332,335 ****
--- 332,339 ----
    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;
***************
*** 403,406 ****
--- 407,414 ----
    bool                     CompressXMLFiles;
  
+   void InitStreams();
+   std::ostream* StreamOut;
+   std::ostream* StreamErr;
+ 
    void BlockTestErrorDiagnostics();
  

Index: cmCTest.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCTest.cxx,v
retrieving revision 1.342
retrieving revision 1.343
diff -C 2 -d -r1.342 -r1.343
*** cmCTest.cxx	18 Dec 2008 17:27:54 -0000	1.342
--- cmCTest.cxx	5 Jan 2009 19:14:10 -0000	1.343
***************
*** 259,262 ****
--- 259,263 ----
    this->SuppressUpdatingCTestConfiguration = false;
    this->DartVersion            = 1;
+   this->InitStreams();
  
    int cc;
***************
*** 1137,1140 ****
--- 1138,1146 ----
      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)
***************
*** 1167,1170 ****
--- 1173,1177 ----
  
      *retVal = inst.Run(args, output);
+     *output += oss.str();
      if ( log )
        {
***************
*** 2603,2606 ****
--- 2610,2620 ----
      }
  
+ 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)
  {
***************
*** 2641,2644 ****
--- 2655,2660 ----
    if ( !this->Quiet )
      {
+     std::ostream& out = *this->StreamOut;
+     std::ostream& err = *this->StreamErr;
      switch ( logType )
        {
***************
*** 2646,2652 ****
        if ( this->Debug )
          {
!         cmCTestLogOutputFileLine(std::cout);
!         std::cout << msg;
!         std::cout.flush();
          }
        break;
--- 2662,2668 ----
        if ( this->Debug )
          {
!         cmCTestLogOutputFileLine(out);
!         out << msg;
!         out.flush();
          }
        break;
***************
*** 2654,2660 ****
        if ( this->Debug || this->Verbose )
          {
!         cmCTestLogOutputFileLine(std::cout);
!         std::cout << msg;
!         std::cout.flush();
          }
        break;
--- 2670,2676 ----
        if ( this->Debug || this->Verbose )
          {
!         cmCTestLogOutputFileLine(out);
!         out << msg;
!         out.flush();
          }
        break;
***************
*** 2662,2685 ****
        if ( this->Debug || this->ExtraVerbose )
          {
!         cmCTestLogOutputFileLine(std::cout);
!         std::cout << msg;
!         std::cout.flush();
          }
        break;
      case WARNING:
!       cmCTestLogOutputFileLine(std::cerr);
!       std::cerr << msg;
!       std::cerr.flush();
        break;
      case ERROR_MESSAGE:
!       cmCTestLogOutputFileLine(std::cerr);
!       std::cerr << msg;
!       std::cerr.flush();
        cmSystemTools::SetErrorOccured();
        break;
      default:
!       cmCTestLogOutputFileLine(std::cout);
!       std::cout << msg;
!       std::cout.flush();
        }
      }
--- 2678,2701 ----
        if ( this->Debug || this->ExtraVerbose )
          {
!         cmCTestLogOutputFileLine(out);
!         out << msg;
!         out.flush();
          }
        break;
      case WARNING:
!       cmCTestLogOutputFileLine(err);
!       err << msg;
!       err.flush();
        break;
      case ERROR_MESSAGE:
!       cmCTestLogOutputFileLine(err);
!       err << msg;
!       err.flush();
        cmSystemTools::SetErrorOccured();
        break;
      default:
!       cmCTestLogOutputFileLine(out);
!       out << msg;
!       out.flush();
        }
      }



More information about the Cmake-commits mailing list