From 7e1ba9d0757885626b1ed9a26a0b014d6755429b Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Sun, 18 Jan 2009 13:03:32 -0500 Subject: BUG: add output on failure to ctest #8255 --- Source/cmCTest.cxx | 26 ++++++++++++++++++++++++++ Source/cmCTest.h | 5 +++++ Source/ctest.cxx | 3 +++ 3 files changed, 34 insertions(+) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 4116d35..1853996 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -258,6 +258,11 @@ cmCTest::cmCTest() this->OutputLogFileLastTag = -1; this->SuppressUpdatingCTestConfiguration = false; this->DartVersion = 1; + this->OutputTestOutputOnTestFailure = false; + if(cmSystemTools::GetEnv("CTEST_OUTPUT_ON_FAILURE")) + { + this->OutputTestOutputOnTestFailure = true; + } this->InitStreams(); this->Parts[PartStart].SetName("Start"); @@ -1233,9 +1238,17 @@ int cmCTest::RunTest(std::vector argv, if(result == cmsysProcess_State_Exited) { *retVal = cmsysProcess_GetExitValue(cp); + if(*retVal != 0 && this->OutputTestOutputOnTestFailure) + { + OutputTestErrors(tempOutput); + } } else if(result == cmsysProcess_State_Exception) { + if(this->OutputTestOutputOnTestFailure) + { + OutputTestErrors(tempOutput); + } *retVal = cmsysProcess_GetExitException(cp); std::string outerr = "\n*** Exception executing: "; outerr += cmsysProcess_GetExceptionString(cp); @@ -1767,6 +1780,10 @@ void cmCTest::HandleCommandLineArguments(size_t &i, this->ExtraVerbose = true; this->Verbose = true; } + if(this->CheckArgument(arg, "--output-on-failure")) + { + this->OutputTestOutputOnTestFailure = true; + } if(this->CheckArgument(arg, "-N", "--show-only")) { @@ -2746,3 +2763,12 @@ double cmCTest::GetRemainingTimeAllowed() return ch->GetRemainingTimeAllowed(); } + +//---------------------------------------------------------------------- +void cmCTest::OutputTestErrors(std::vector 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); +} + diff --git a/Source/cmCTest.h b/Source/cmCTest.h index d822fec..b949378 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -467,6 +467,9 @@ private: bool CheckArgument(const std::string& arg, const char* varg1, const char* varg2 = 0); + //! Output errors from a test + void OutputTestErrors(std::vector const &process_output); + bool SuppressUpdatingCTestConfiguration; bool Debug; @@ -482,6 +485,8 @@ private: cmGeneratedFileStream* OutputLogFile; int OutputLogFileLastTag; + + bool OutputTestOutputOnTestFailure; }; class cmCTestLogWrite diff --git a/Source/ctest.cxx b/Source/ctest.cxx index 9401574..7f4987e 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -65,6 +65,9 @@ static const char * cmDocumentationOptions[][3] = {"--debug", "Displaying more verbose internals of CTest.", "This feature will result in large number of output that is mostly " "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.", "This option will suppress all the output. The output log file will " "still be generated if the --output-log is specified. Options such " -- cgit v0.12