BUG: add output on failure to ctest #8255

This commit is contained in:
Bill Hoffman 2009-01-18 13:03:32 -05:00
parent e4048118de
commit 7e1ba9d075
3 changed files with 34 additions and 0 deletions

View File

@ -258,6 +258,11 @@ cmCTest::cmCTest()
this->OutputLogFileLastTag = -1; this->OutputLogFileLastTag = -1;
this->SuppressUpdatingCTestConfiguration = false; this->SuppressUpdatingCTestConfiguration = false;
this->DartVersion = 1; this->DartVersion = 1;
this->OutputTestOutputOnTestFailure = false;
if(cmSystemTools::GetEnv("CTEST_OUTPUT_ON_FAILURE"))
{
this->OutputTestOutputOnTestFailure = true;
}
this->InitStreams(); this->InitStreams();
this->Parts[PartStart].SetName("Start"); this->Parts[PartStart].SetName("Start");
@ -1233,9 +1238,17 @@ int cmCTest::RunTest(std::vector<const char*> argv,
if(result == cmsysProcess_State_Exited) if(result == cmsysProcess_State_Exited)
{ {
*retVal = cmsysProcess_GetExitValue(cp); *retVal = cmsysProcess_GetExitValue(cp);
if(*retVal != 0 && this->OutputTestOutputOnTestFailure)
{
OutputTestErrors(tempOutput);
}
} }
else if(result == cmsysProcess_State_Exception) else if(result == cmsysProcess_State_Exception)
{ {
if(this->OutputTestOutputOnTestFailure)
{
OutputTestErrors(tempOutput);
}
*retVal = cmsysProcess_GetExitException(cp); *retVal = cmsysProcess_GetExitException(cp);
std::string outerr = "\n*** Exception executing: "; std::string outerr = "\n*** Exception executing: ";
outerr += cmsysProcess_GetExceptionString(cp); outerr += cmsysProcess_GetExceptionString(cp);
@ -1767,6 +1780,10 @@ void cmCTest::HandleCommandLineArguments(size_t &i,
this->ExtraVerbose = true; this->ExtraVerbose = true;
this->Verbose = true; this->Verbose = true;
} }
if(this->CheckArgument(arg, "--output-on-failure"))
{
this->OutputTestOutputOnTestFailure = true;
}
if(this->CheckArgument(arg, "-N", "--show-only")) if(this->CheckArgument(arg, "-N", "--show-only"))
{ {
@ -2746,3 +2763,12 @@ double cmCTest::GetRemainingTimeAllowed()
return ch->GetRemainingTimeAllowed(); return ch->GetRemainingTimeAllowed();
} }
//----------------------------------------------------------------------
void cmCTest::OutputTestErrors(std::vector<char> const &process_output)
{
std::string test_outputs("\n*** Test Failed:\n");
test_outputs.append(&*process_output.begin(), process_output.size());
cmCTestLog(this, HANDLER_OUTPUT, test_outputs << std::endl << std::flush);
}

View File

@ -467,6 +467,9 @@ private:
bool CheckArgument(const std::string& arg, const char* varg1, bool CheckArgument(const std::string& arg, const char* varg1,
const char* varg2 = 0); const char* varg2 = 0);
//! Output errors from a test
void OutputTestErrors(std::vector<char> const &process_output);
bool SuppressUpdatingCTestConfiguration; bool SuppressUpdatingCTestConfiguration;
bool Debug; bool Debug;
@ -482,6 +485,8 @@ private:
cmGeneratedFileStream* OutputLogFile; cmGeneratedFileStream* OutputLogFile;
int OutputLogFileLastTag; int OutputLogFileLastTag;
bool OutputTestOutputOnTestFailure;
}; };
class cmCTestLogWrite class cmCTestLogWrite

View File

@ -65,6 +65,9 @@ static const char * cmDocumentationOptions[][3] =
{"--debug", "Displaying more verbose internals of CTest.", {"--debug", "Displaying more verbose internals of CTest.",
"This feature will result in large number of output that is mostly " "This feature will result in large number of output that is mostly "
"useful for debugging dashboard problems."}, "useful for debugging dashboard problems."},
{"--output-on-failure", "Output anything outputted by the test program "
"if the test should fail. This option can also be enabled by setting "
"the environment variable CTEST_OUTPUT_ON_FAILURE"},
{"-Q,--quiet", "Make ctest quiet.", {"-Q,--quiet", "Make ctest quiet.",
"This option will suppress all the output. The output log file will " "This option will suppress all the output. The output log file will "
"still be generated if the --output-log is specified. Options such " "still be generated if the --output-log is specified. Options such "