Преглед на файлове

cmCTestRunTest: Buffer test result output before printing

Michael Wegner преди 7 години
родител
ревизия
6a285bb737
променени са 1 файла, в които са добавени 29 реда и са изтрити 28 реда
  1. 29 28
      Source/CTest/cmCTestRunTest.cxx

+ 29 - 28
Source/CTest/cmCTestRunTest.cxx

@@ -181,6 +181,7 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
       }
       }
     }
     }
   }
   }
+  std::ostringstream outputStream;
   if (res == cmProcess::State::Exited) {
   if (res == cmProcess::State::Exited) {
     bool success = !forceFail &&
     bool success = !forceFail &&
       (retVal == 0 ||
       (retVal == 0 ||
@@ -196,36 +197,36 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
     } else if ((success && !this->TestProperties->WillFail) ||
     } else if ((success && !this->TestProperties->WillFail) ||
                (!success && this->TestProperties->WillFail)) {
                (!success && this->TestProperties->WillFail)) {
       this->TestResult.Status = cmCTestTestHandler::COMPLETED;
       this->TestResult.Status = cmCTestTestHandler::COMPLETED;
-      cmCTestLog(this->CTest, HANDLER_OUTPUT, "   Passed  ");
+      outputStream << "   Passed  ";
     } else {
     } else {
       this->TestResult.Status = cmCTestTestHandler::FAILED;
       this->TestResult.Status = cmCTestTestHandler::FAILED;
-      cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Failed  " << reason);
+      outputStream << "***Failed  " << reason;
       outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
       outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
     }
     }
   } else if (res == cmProcess::State::Expired) {
   } else if (res == cmProcess::State::Expired) {
-    cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Timeout ");
+    outputStream << "***Timeout ";
     this->TestResult.Status = cmCTestTestHandler::TIMEOUT;
     this->TestResult.Status = cmCTestTestHandler::TIMEOUT;
     outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
     outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
   } else if (res == cmProcess::State::Exception) {
   } else if (res == cmProcess::State::Exception) {
     outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
     outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
-    cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Exception: ");
+    outputStream << "***Exception: ";
     this->TestResult.ExceptionStatus =
     this->TestResult.ExceptionStatus =
       this->TestProcess->GetExitExceptionString();
       this->TestProcess->GetExitExceptionString();
     switch (this->TestProcess->GetExitException()) {
     switch (this->TestProcess->GetExitException()) {
       case cmProcess::Exception::Fault:
       case cmProcess::Exception::Fault:
-        cmCTestLog(this->CTest, HANDLER_OUTPUT, "SegFault");
+        outputStream << "SegFault";
         this->TestResult.Status = cmCTestTestHandler::SEGFAULT;
         this->TestResult.Status = cmCTestTestHandler::SEGFAULT;
         break;
         break;
       case cmProcess::Exception::Illegal:
       case cmProcess::Exception::Illegal:
-        cmCTestLog(this->CTest, HANDLER_OUTPUT, "Illegal");
+        outputStream << "Illegal";
         this->TestResult.Status = cmCTestTestHandler::ILLEGAL;
         this->TestResult.Status = cmCTestTestHandler::ILLEGAL;
         break;
         break;
       case cmProcess::Exception::Interrupt:
       case cmProcess::Exception::Interrupt:
-        cmCTestLog(this->CTest, HANDLER_OUTPUT, "Interrupt");
+        outputStream << "Interrupt";
         this->TestResult.Status = cmCTestTestHandler::INTERRUPT;
         this->TestResult.Status = cmCTestTestHandler::INTERRUPT;
         break;
         break;
       case cmProcess::Exception::Numerical:
       case cmProcess::Exception::Numerical:
-        cmCTestLog(this->CTest, HANDLER_OUTPUT, "Numerical");
+        outputStream << "Numerical";
         this->TestResult.Status = cmCTestTestHandler::NUMERICAL;
         this->TestResult.Status = cmCTestTestHandler::NUMERICAL;
         break;
         break;
       default:
       default:
@@ -234,16 +235,18 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
         this->TestResult.Status = cmCTestTestHandler::OTHER_FAULT;
         this->TestResult.Status = cmCTestTestHandler::OTHER_FAULT;
     }
     }
   } else if ("Disabled" == this->TestResult.CompletionStatus) {
   } else if ("Disabled" == this->TestResult.CompletionStatus) {
-    cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Not Run (Disabled) ");
+    outputStream << "***Not Run (Disabled) ";
   } else // cmProcess::State::Error
   } else // cmProcess::State::Error
   {
   {
-    cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Not Run ");
+    outputStream << "***Not Run ";
   }
   }
 
 
   passed = this->TestResult.Status == cmCTestTestHandler::COMPLETED;
   passed = this->TestResult.Status == cmCTestTestHandler::COMPLETED;
   char buf[1024];
   char buf[1024];
   sprintf(buf, "%6.2f sec", this->TestProcess->GetTotalTime().count());
   sprintf(buf, "%6.2f sec", this->TestProcess->GetTotalTime().count());
-  cmCTestLog(this->CTest, HANDLER_OUTPUT, buf << "\n");
+  outputStream << buf << "\n";
+
+  cmCTestLog(this->CTest, HANDLER_OUTPUT, outputStream.str());
 
 
   if (outputTestErrorsToConsole) {
   if (outputTestErrorsToConsole) {
     cmCTestLog(this->CTest, HANDLER_OUTPUT, this->ProcessOutput << std::endl);
     cmCTestLog(this->CTest, HANDLER_OUTPUT, this->ProcessOutput << std::endl);
@@ -689,6 +692,8 @@ bool cmCTestRunTest::ForkProcess(cmDuration testTimeOut, bool explicitTimeout,
 
 
 void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total)
 void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total)
 {
 {
+  std::ostringstream outputStream;
+
   // if this is the last or only run of this test
   // if this is the last or only run of this test
   // then print out completed / total
   // then print out completed / total
   // Only issue is if a test fails and we are running until fail
   // Only issue is if a test fails and we are running until fail
@@ -696,37 +701,32 @@ void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total)
   // got for run until pass.  Trick is when this is called we don't
   // got for run until pass.  Trick is when this is called we don't
   // yet know if we are passing or failing.
   // yet know if we are passing or failing.
   if (this->NumberOfRunsLeft == 1) {
   if (this->NumberOfRunsLeft == 1) {
-    cmCTestLog(this->CTest, HANDLER_OUTPUT,
-               std::setw(getNumWidth(total)) << completed << "/");
-    cmCTestLog(this->CTest, HANDLER_OUTPUT,
-               std::setw(getNumWidth(total)) << total << " ");
+    outputStream << std::setw(getNumWidth(total)) << completed << "/";
+    outputStream << std::setw(getNumWidth(total)) << total << " ";
   }
   }
   // if this is one of several runs of a test just print blank space
   // if this is one of several runs of a test just print blank space
   // to keep things neat
   // to keep things neat
   else {
   else {
-    cmCTestLog(this->CTest, HANDLER_OUTPUT,
-               std::setw(getNumWidth(total)) << " "
-                                             << " ");
-    cmCTestLog(this->CTest, HANDLER_OUTPUT,
-               std::setw(getNumWidth(total)) << " "
-                                             << " ");
+    outputStream << std::setw(getNumWidth(total)) << "  ";
+    outputStream << std::setw(getNumWidth(total)) << "  ";
   }
   }
 
 
   if (this->TestHandler->MemCheck) {
   if (this->TestHandler->MemCheck) {
-    cmCTestLog(this->CTest, HANDLER_OUTPUT, "MemCheck");
+    outputStream << "MemCheck";
   } else {
   } else {
-    cmCTestLog(this->CTest, HANDLER_OUTPUT, "Test");
+    outputStream << "Test";
   }
   }
 
 
   std::ostringstream indexStr;
   std::ostringstream indexStr;
   indexStr << " #" << this->Index << ":";
   indexStr << " #" << this->Index << ":";
-  cmCTestLog(this->CTest, HANDLER_OUTPUT,
-             std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex()))
-               << indexStr.str());
-  cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
+  outputStream << std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex()))
+               << indexStr.str();
+  outputStream << " ";
+
   const int maxTestNameWidth = this->CTest->GetMaxTestNameWidth();
   const int maxTestNameWidth = this->CTest->GetMaxTestNameWidth();
   std::string outname = this->TestProperties->Name + " ";
   std::string outname = this->TestProperties->Name + " ";
   outname.resize(maxTestNameWidth + 4, '.');
   outname.resize(maxTestNameWidth + 4, '.');
+  outputStream << outname;
 
 
   *this->TestHandler->LogFile << this->TestProperties->Index << "/"
   *this->TestHandler->LogFile << this->TestProperties->Index << "/"
                               << this->TestHandler->TotalNumberOfTests
                               << this->TestHandler->TotalNumberOfTests
@@ -754,7 +754,8 @@ void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total)
   *this->TestHandler->LogFile << this->ProcessOutput << "<end of output>"
   *this->TestHandler->LogFile << this->ProcessOutput << "<end of output>"
                               << std::endl;
                               << std::endl;
 
 
-  cmCTestLog(this->CTest, HANDLER_OUTPUT, outname.c_str());
+  cmCTestLog(this->CTest, HANDLER_OUTPUT, outputStream.str());
+
   cmCTestLog(this->CTest, DEBUG,
   cmCTestLog(this->CTest, DEBUG,
              "Testing " << this->TestProperties->Name << " ... ");
              "Testing " << this->TestProperties->Name << " ... ");
 }
 }