Index: cmCTest.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCTest.cxx,v
retrieving revision 1.341
diff -u -r1.341 cmCTest.cxx
--- cmCTest.cxx	26 Nov 2008 19:38:40 -0000	1.341
+++ cmCTest.cxx	8 Dec 2008 02:59:20 -0000
@@ -258,6 +258,11 @@
   this->OutputLogFileLastTag   = -1;
   this->SuppressUpdatingCTestConfiguration = false;
   this->DartVersion            = 1;
+  this->OutputTestOutputOnTestFailure = false;
+  if(getenv("CTEST_OUTPUT_ON_FAILURE"))
+    {
+    this->OutputTestOutputOnTestFailure = true;
+    }
 
   int cc;
   for ( cc=0; cc < cmCTest::LAST_TEST; cc ++ )
@@ -1233,9 +1238,17 @@
   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);
@@ -1728,6 +1741,10 @@
     this->ExtraVerbose = true;
     this->Verbose = true;
     }
+  if(this->CheckArgument(arg, "--output-on-failure"))
+    {
+    this->OutputTestOutputOnTestFailure = true;
+    }
   
   if(this->CheckArgument(arg, "-N", "--show-only"))
     {
@@ -2698,3 +2715,12 @@
 
   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);
+}
+
Index: cmCTest.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCTest.h,v
retrieving revision 1.104
diff -u -r1.104 cmCTest.h
--- cmCTest.h	28 Nov 2008 15:50:20 -0000	1.104
+++ cmCTest.h	8 Dec 2008 02:59:20 -0000
@@ -431,6 +431,9 @@
   bool CheckArgument(const std::string& arg, const char* varg1,
     const char* varg2 = 0);
 
+  //! Output errors from a test
+  void OutputTestErrors(std::vector<char> const &process_output);
+
   bool                      SuppressUpdatingCTestConfiguration;
 
   bool Debug;
@@ -446,6 +449,8 @@
 
   cmGeneratedFileStream* OutputLogFile;
   int OutputLogFileLastTag;
+
+  bool OutputTestOutputOnTestFailure;
 };
 
 class cmCTestLogWrite
Index: ctest.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/ctest.cxx,v
retrieving revision 1.103
diff -u -r1.103 ctest.cxx
--- ctest.cxx	22 Sep 2008 18:04:12 -0000	1.103
+++ ctest.cxx	8 Dec 2008 02:59:20 -0000
@@ -65,6 +65,9 @@
   {"--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 "
