Merge topic 'ctest-merge-test-output'

721b7e3e CTest: Capture test stdout/stderr through one pipe (#15600)
This commit is contained in:
Brad King 2015-06-04 09:13:25 -04:00 committed by CMake Topic Stage
commit 94070b8dfa
6 changed files with 37 additions and 22 deletions

View File

@ -57,8 +57,7 @@ bool cmCTestRunTest::CheckOutput()
// Process has terminated and all output read. // Process has terminated and all output read.
return false; return false;
} }
else if(p == cmsysProcess_Pipe_STDOUT || else if(p == cmsysProcess_Pipe_STDOUT)
p == cmsysProcess_Pipe_STDERR)
{ {
// Store this line of output. // Store this line of output.
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,

View File

@ -62,6 +62,7 @@ bool cmProcess::StartProcess()
this->WorkingDirectory.c_str()); this->WorkingDirectory.c_str());
} }
cmsysProcess_SetTimeout(this->Process, this->Timeout); cmsysProcess_SetTimeout(this->Process, this->Timeout);
cmsysProcess_SetOption(this->Process, cmsysProcess_Option_MergeOutput, 1);
cmsysProcess_Execute(this->Process); cmsysProcess_Execute(this->Process);
return (cmsysProcess_GetState(this->Process) return (cmsysProcess_GetState(this->Process)
== cmsysProcess_State_Executing); == cmsysProcess_State_Executing);
@ -124,14 +125,10 @@ int cmProcess::GetNextOutputLine(std::string& line, double timeout)
for(;;) for(;;)
{ {
// Look for lines already buffered. // Look for lines already buffered.
if(this->StdOut.GetLine(line)) if(this->Output.GetLine(line))
{ {
return cmsysProcess_Pipe_STDOUT; return cmsysProcess_Pipe_STDOUT;
} }
else if(this->StdErr.GetLine(line))
{
return cmsysProcess_Pipe_STDERR;
}
// Check for more data from the process. // Check for more data from the process.
char* data; char* data;
@ -143,11 +140,7 @@ int cmProcess::GetNextOutputLine(std::string& line, double timeout)
} }
else if(p == cmsysProcess_Pipe_STDOUT) else if(p == cmsysProcess_Pipe_STDOUT)
{ {
this->StdOut.insert(this->StdOut.end(), data, data+length); this->Output.insert(this->Output.end(), data, data+length);
}
else if(p == cmsysProcess_Pipe_STDERR)
{
this->StdErr.insert(this->StdErr.end(), data, data+length);
} }
else // p == cmsysProcess_Pipe_None else // p == cmsysProcess_Pipe_None
{ {
@ -157,14 +150,10 @@ int cmProcess::GetNextOutputLine(std::string& line, double timeout)
} }
// Look for partial last lines. // Look for partial last lines.
if(this->StdOut.GetLast(line)) if(this->Output.GetLast(line))
{ {
return cmsysProcess_Pipe_STDOUT; return cmsysProcess_Pipe_STDOUT;
} }
else if(this->StdErr.GetLast(line))
{
return cmsysProcess_Pipe_STDERR;
}
// No more data. Wait for process exit. // No more data. Wait for process exit.
if(!cmsysProcess_WaitForExit(this->Process, &timeout)) if(!cmsysProcess_WaitForExit(this->Process, &timeout))

View File

@ -48,8 +48,7 @@ public:
* Read one line of output but block for no more than timeout. * Read one line of output but block for no more than timeout.
* Returns: * Returns:
* cmsysProcess_Pipe_None = Process terminated and all output read * cmsysProcess_Pipe_None = Process terminated and all output read
* cmsysProcess_Pipe_STDOUT = Line came from stdout * cmsysProcess_Pipe_STDOUT = Line came from stdout or stderr
* cmsysProcess_Pipe_STDOUT = Line came from stderr
* cmsysProcess_Pipe_Timeout = Timeout expired while waiting * cmsysProcess_Pipe_Timeout = Timeout expired while waiting
*/ */
int GetNextOutputLine(std::string& line, double timeout); int GetNextOutputLine(std::string& line, double timeout);
@ -68,13 +67,11 @@ private:
bool GetLine(std::string& line); bool GetLine(std::string& line);
bool GetLast(std::string& line); bool GetLast(std::string& line);
}; };
Buffer StdErr; Buffer Output;
Buffer StdOut;
std::string Command; std::string Command;
std::string WorkingDirectory; std::string WorkingDirectory;
std::vector<std::string> Arguments; std::vector<std::string> Arguments;
std::vector<const char*> ProcessArgs; std::vector<const char*> ProcessArgs;
std::string Output;
int Id; int Id;
int ExitValue; int ExitValue;
}; };

View File

@ -0,0 +1,13 @@
Test timeout computed to be: [^
]+
1: -- Output on stdout
1: Output on stderr
1: -- Output on stdout
1: Output on stderr
1: -- Output on stdout
1: Output on stderr
1: -- Output on stdout
1: Output on stderr
1: -- Output on stdout
1: Output on stderr
1/1 Test #1: MergeOutput

View File

@ -0,0 +1,4 @@
foreach(i RANGE 1 5)
message(STATUS "Output on stdout")
message("Output on stderr")
endforeach()

View File

@ -39,3 +39,16 @@ subdirs()
run_cmake_command(BadCTestTestfile ${CMAKE_CTEST_COMMAND}) run_cmake_command(BadCTestTestfile ${CMAKE_CTEST_COMMAND})
endfunction() endfunction()
run_BadCTestTestfile() run_BadCTestTestfile()
function(run_MergeOutput)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/MergeOutput)
set(RunCMake_TEST_NO_CLEAN 1)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
file(WRITE "${RunCMake_TEST_BINARY_DIR}/CTestTestfile.cmake" "
add_test(MergeOutput \"${CMAKE_COMMAND}\" -P \"${RunCMake_SOURCE_DIR}/MergeOutput.cmake\")
")
run_cmake_command(MergeOutput ${CMAKE_CTEST_COMMAND} -V)
endfunction()
run_MergeOutput()