[cmake-developers] [RFCv2] ctest: color test summary output

Steve Dougherty sdougherty at barracuda.com
Tue Jul 1 16:01:48 EDT 2014


When I glance at ctest output, even if all tests passed, my eye catches
"failed" before noticing the other things, which gives me a start.

To make this less likely to happen this colors the test summary green
if all tests succeeded and red if not.

Although I have attempted to edit the test regular expressions so that
they still pass, I'm missing something about matching escape codes,
and a third of them fail. From LastTest.log:

    Start 1: RunCMake
1/1 MemCheck #1: RunCMake .........................   Passed    0.00 sec
ESC[32;1m
100% tests passed, 0 tests failed out of 1
ESC[0m
Total Test time (real) =   0.00 sec
-- Processing memory checking output:
Memory checking results:
<end of output>
Test time =   0.11 sec
----------------------------------------------------------
Test Fail Reason:
Required regular expression not found.Regex=[
1/1 MemCheck #1: RunCMake \.+   Passed +[0-9]+\.[0-9]+ sec
\\033\[32;1m
100% tests passed, 0 tests failed out of 1
.*
-- Processing memory checking output:( )
Memory checking results:
((BullseyeCoverage|==)[^
]*
)*$
]
---
 Source/CTest/cmCTestTestHandler.cxx    | 13 +++++++++++++
 Tests/CTestTestMemcheck/CMakeLists.txt |  4 ++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index f21d166..b256be0 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -583,10 +583,23 @@ int cmCTestTestHandler::ProcessHandler()
       percent = 99;
       }
 
+    if ( failed.size() )
+      {
+        // Bold red foreground
+        cmCTestLog(this->CTest, HANDLER_OUTPUT, "\033[31;1m");
+      }
+    else
+      {
+        // Bold green foreground
+        cmCTestLog(this->CTest, HANDLER_OUTPUT, "\033[32;1m");
+      }
     cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
                << static_cast<int>(percent + .5) << "% tests passed, "
                << failed.size() << " tests failed out of "
                << total << std::endl);
+    // Reset formatting to default
+    cmCTestLog(this->CTest, HANDLER_OUTPUT, "\033[0m");
+
     if(this->CTest->GetLabelSummary())
       {
       this->PrintLabelSummary();
diff --git a/Tests/CTestTestMemcheck/CMakeLists.txt b/Tests/CTestTestMemcheck/CMakeLists.txt
index 8984463..c35e1f7 100644
--- a/Tests/CTestTestMemcheck/CMakeLists.txt
+++ b/Tests/CTestTestMemcheck/CMakeLists.txt
@@ -54,7 +54,7 @@ set(other_tool_output "((${guard_malloc_output}BullseyeCoverage|==)[^\n]*\n)*")
 
 string(REPLACE "\r\n" "\n" ctest_and_tool_outputs "
 1/1 MemCheck #1: RunCMake \\.+   Passed +[0-9]+\\.[0-9]+ sec
-${guard_malloc_lines}
+${guard_malloc_lines}\\\\033\\[32;1m
 100% tests passed, 0 tests failed out of 1
 .*
 -- Processing memory checking output:( )
@@ -177,7 +177,7 @@ set_tests_properties(CTestTestMemcheckDummyValgrindIgnoreMemcheck
     PASS_REGULAR_EXPRESSION "\n2/2 Test #2: RunCMakeAgain .*${ctest_and_tool_outputs}$")
 
 set_tests_properties(CTestTestMemcheckDummyBC PROPERTIES
-    PASS_REGULAR_EXPRESSION "\n1/1 MemCheck #1: RunCMake \\.+   Passed +[0-9]+.[0-9]+ sec\n\n100% tests passed, 0 tests failed out of 1\n(.*\n)?Error parsing XML in stream at line 1: no element found\n")
+    PASS_REGULAR_EXPRESSION "\n1/1 MemCheck #1: RunCMake \\.+   Passed +[0-9]+.[0-9]+ sec\n\\\\033\\[32;1m\n100% tests passed, 0 tests failed out of 1\n(.*\n)?Error parsing XML in stream at line 1: no element found\n")
 
 set_tests_properties(CTestTestMemcheckDummyValgrindInvalidSupFile PROPERTIES
     PASS_REGULAR_EXPRESSION "\nCannot find memory checker suppression file: ${CTEST_ESCAPED_REALPATH_CMAKE_CURRENT_BINARY_DIR}/does-not-exist\n")
-- 
2.0.1


===========================================================



DISCLAIMER:
This e-mail and any attachments to it contain confidential and proprietary material of Barracuda, its affiliates or agents, and is solely for the use of the intended recipient. Any review, use, disclosure, distribution or copying of this transmittal is prohibited except by or on behalf of the intended recipient. If you have received this transmittal in error, please notify the sender and destroy this e-mail and any attachments and all copies, whether electronic or printed.



More information about the cmake-developers mailing list