$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r58338 - in trunk/boost/test: detail impl utils
From: gennadiy.rozental_at_[hidden]
Date: 2009-12-13 04:24:48
Author: rogeeff
Date: 2009-12-13 04:24:47 EST (Sun, 13 Dec 2009)
New Revision: 58338
URL: http://svn.boost.org/trac/boost/changeset/58338
Log:
added support for the colored output
Added:
   trunk/boost/test/utils/setcolor.hpp   (contents, props changed)
Text files modified: 
   trunk/boost/test/detail/global_typedef.hpp       |     7 +++++++                                 
   trunk/boost/test/detail/unit_test_parameters.hpp |     1 +                                       
   trunk/boost/test/impl/compiler_log_formatter.ipp |    31 +++++++++++++++++++++++++++++--         
   trunk/boost/test/impl/plain_report_formatter.ipp |     6 ++++++                                  
   trunk/boost/test/impl/progress_monitor.ipp       |     9 +++++++++                               
   trunk/boost/test/impl/unit_test_parameters.ipp   |    13 +++++++++++++                           
   6 files changed, 65 insertions(+), 2 deletions(-)
Modified: trunk/boost/test/detail/global_typedef.hpp
==============================================================================
--- trunk/boost/test/detail/global_typedef.hpp	(original)
+++ trunk/boost/test/detail/global_typedef.hpp	2009-12-13 04:24:47 EST (Sun, 13 Dec 2009)
@@ -20,6 +20,13 @@
 #define BOOST_TEST_STRINGIZE( s ) BOOST_TEST_L( BOOST_STRINGIZE( s ) )
 #define BOOST_TEST_EMPTY_STRING   BOOST_TEST_L( "" )
 
+#define BOOST_TEST_SCOPE_SETCOLOR( os, attr, color )            \
+    scope_setcolor const& sc = runtime_config::color_output()   \
+           ? scope_setcolor( os, attr, color )                  \
+           : scope_setcolor();                                  \
+    ut_detail::ignore_unused_variable_warning( sc )             \
+/**/
+
 #include <boost/test/detail/suppress_warnings.hpp>
 
 //____________________________________________________________________________//
Modified: trunk/boost/test/detail/unit_test_parameters.hpp
==============================================================================
--- trunk/boost/test/detail/unit_test_parameters.hpp	(original)
+++ trunk/boost/test/detail/unit_test_parameters.hpp	2009-12-13 04:24:47 EST (Sun, 13 Dec 2009)
@@ -46,6 +46,7 @@
 BOOST_TEST_DECL bool                     show_build_info();
 BOOST_TEST_DECL bool                     show_progress();
 BOOST_TEST_DECL bool                     catch_sys_errors();
+BOOST_TEST_DECL bool                     color_output();
 BOOST_TEST_DECL bool                     auto_start_dbg();
 BOOST_TEST_DECL bool                     use_alt_stack();
 BOOST_TEST_DECL bool                     detect_fp_exceptions();
Modified: trunk/boost/test/impl/compiler_log_formatter.ipp
==============================================================================
--- trunk/boost/test/impl/compiler_log_formatter.ipp	(original)
+++ trunk/boost/test/impl/compiler_log_formatter.ipp	2009-12-13 04:24:47 EST (Sun, 13 Dec 2009)
@@ -21,6 +21,8 @@
 #include <boost/test/framework.hpp>
 #include <boost/test/utils/basic_cstring/io.hpp>
 #include <boost/test/utils/lazy_ostream.hpp>
+#include <boost/test/utils/setcolor.hpp>
+#include <boost/test/detail/unit_test_parameters.hpp>
 
 // Boost
 #include <boost/version.hpp>
@@ -90,6 +92,8 @@
 void
 compiler_log_formatter::test_unit_start( std::ostream& output, test_unit const& tu )
 {
+    BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BRIGHT, term_color::BLUE );
+
     output << "Entering test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
 }
 
@@ -98,6 +102,8 @@
 void
 compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, unsigned long elapsed )
 {
+    BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BRIGHT, term_color::BLUE );
+
     output << "Leaving test " << tu.p_type_name << " \"" << tu.p_name << "\"";
 
     if( elapsed > 0 ) {
@@ -116,6 +122,8 @@
 void
 compiler_log_formatter::test_unit_skipped( std::ostream& output, test_unit const& tu )
 {
+    BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BRIGHT, term_color::YELLOW );
+
     output  << "Test " << tu.p_type_name << " \"" << tu.p_name << "\"" << "is skipped" << std::endl;
 }
     
@@ -127,13 +135,19 @@
     execution_exception::location const& loc = ex.where();
     print_prefix( output, loc.m_file_name, loc.m_line_num );
 
-    output << "fatal error in \"" << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function ) << "\": ";
+    {
+        BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BLINK, term_color::RED );
 
-    output << ex.what();
+        output << "fatal error in \"" << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function ) << "\": "
+               << ex.what();
+    }
 
     if( !checkpoint_data.m_file_name.is_empty() ) {
         output << '\n';
         print_prefix( output, checkpoint_data.m_file_name, checkpoint_data.m_line_num );
+
+        BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BRIGHT, term_color::CYAN );
+
         output << "last checkpoint";
         if( !checkpoint_data.m_message.empty() )
             output << ": " << checkpoint_data.m_message;
@@ -150,20 +164,30 @@
     switch( let ) {
         case BOOST_UTL_ET_INFO:
             print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
+            if( runtime_config::color_output() )
+                output << setcolor( term_attr::BRIGHT, term_color::GREEN );
             output << "info: ";
             break;
         case BOOST_UTL_ET_MESSAGE:
+            if( runtime_config::color_output() )
+                output << setcolor( term_attr::BRIGHT, term_color::CYAN );
             break;
         case BOOST_UTL_ET_WARNING:
             print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
+            if( runtime_config::color_output() )
+                output << setcolor( term_attr::BRIGHT, term_color::YELLOW );
             output << "warning in \"" << test_phase_identifier() << "\": ";
             break;
         case BOOST_UTL_ET_ERROR:
             print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
+            if( runtime_config::color_output() )
+                output << setcolor( term_attr::BRIGHT, term_color::RED );
             output << "error in \"" << test_phase_identifier() << "\": ";
             break;
         case BOOST_UTL_ET_FATAL_ERROR:
             print_prefix( output, entry_data.m_file_name, entry_data.m_line_num );
+            if( runtime_config::color_output() )
+                output << setcolor( term_attr::BLINK, term_color::RED );
             output << "fatal error in \"" << test_phase_identifier() << "\": ";
             break;
     }
@@ -190,9 +214,12 @@
 void
 compiler_log_formatter::log_entry_finish( std::ostream& output )
 {
+    if( runtime_config::color_output() )
+        output << setcolor();
     output << std::endl;
 }
 
+
 //____________________________________________________________________________//
 
 void
Modified: trunk/boost/test/impl/plain_report_formatter.ipp
==============================================================================
--- trunk/boost/test/impl/plain_report_formatter.ipp	(original)
+++ trunk/boost/test/impl/plain_report_formatter.ipp	2009-12-13 04:24:47 EST (Sun, 13 Dec 2009)
@@ -22,6 +22,8 @@
 #include <boost/test/unit_test_suite_impl.hpp>
 
 #include <boost/test/utils/basic_cstring/io.hpp>
+#include <boost/test/utils/setcolor.hpp>
+#include <boost/test/detail/unit_test_parameters.hpp>
 
 // STL
 #include <iomanip>
@@ -157,10 +159,14 @@
     test_results const& tr = results_collector.results( tu.p_id );
     
     if( tr.passed() ) {
+        BOOST_TEST_SCOPE_SETCOLOR( ostr, term_attr::BRIGHT, term_color::GREEN );
+
         ostr << "*** No errors detected\n";
         return;
     }
         
+    BOOST_TEST_SCOPE_SETCOLOR( ostr, term_attr::BRIGHT, term_color::RED );
+        
     if( tr.p_skipped ) {
         ostr << "*** Test " << tu.p_type_name << " skipped due to " 
              << (tu.check_dependencies() ? "test aborting\n" : "failed dependancy\n" );
Modified: trunk/boost/test/impl/progress_monitor.ipp
==============================================================================
--- trunk/boost/test/impl/progress_monitor.ipp	(original)
+++ trunk/boost/test/impl/progress_monitor.ipp	2009-12-13 04:24:47 EST (Sun, 13 Dec 2009)
@@ -20,6 +20,7 @@
 #include <boost/test/unit_test_suite_impl.hpp>
 
 #include <boost/test/detail/unit_test_parameters.hpp>
+#include <boost/test/utils/setcolor.hpp>
 
 // Boost
 #include <boost/progress.hpp>
@@ -58,6 +59,8 @@
 void
 progress_monitor_t::test_start( counter_t test_cases_amount )
 {
+    BOOST_TEST_SCOPE_SETCOLOR( *s_pm_impl().m_stream, term_attr::BRIGHT, term_color::MAGENTA );
+
     s_pm_impl().m_progress_display.reset( new progress_display( test_cases_amount, *s_pm_impl().m_stream ) );
 }
 
@@ -66,6 +69,8 @@
 void
 progress_monitor_t::test_aborted()
 {
+    BOOST_TEST_SCOPE_SETCOLOR( *s_pm_impl().m_stream, term_attr::BRIGHT, term_color::MAGENTA );
+
     (*s_pm_impl().m_progress_display) += s_pm_impl().m_progress_display->count();
 }
 
@@ -74,6 +79,8 @@
 void
 progress_monitor_t::test_unit_finish( test_unit const& tu, unsigned long )
 {
+    BOOST_TEST_SCOPE_SETCOLOR( *s_pm_impl().m_stream, term_attr::BRIGHT, term_color::MAGENTA );
+
     if( tu.p_type == tut_case )
         ++(*s_pm_impl().m_progress_display);
 }
@@ -83,6 +90,8 @@
 void
 progress_monitor_t::test_unit_skipped( test_unit const& tu )
 {
+    BOOST_TEST_SCOPE_SETCOLOR( *s_pm_impl().m_stream, term_attr::BRIGHT, term_color::MAGENTA );
+
     test_case_counter tcc;
     traverse_test_tree( tu, tcc );
     
Modified: trunk/boost/test/impl/unit_test_parameters.ipp
==============================================================================
--- trunk/boost/test/impl/unit_test_parameters.ipp	(original)
+++ trunk/boost/test/impl/unit_test_parameters.ipp	2009-12-13 04:24:47 EST (Sun, 13 Dec 2009)
@@ -158,6 +158,7 @@
 std::string BREAK_EXEC_PATH   = "break_exec_path";
 std::string BUILD_INFO        = "build_info";
 std::string CATCH_SYS_ERRORS  = "catch_system_errors";
+std::string COLOR_OUTPUT      = "color_output";
 std::string DETECT_FP_EXCEPT  = "detect_fp_exceptions";
 std::string DETECT_MEM_LEAKS  = "detect_memory_leaks";
 std::string LOG_FORMAT        = "log_format";
@@ -179,6 +180,7 @@
     BREAK_EXEC_PATH   , "BOOST_TEST_BREAK_EXEC_PATH",
     BUILD_INFO        , "BOOST_TEST_BUILD_INFO",
     CATCH_SYS_ERRORS  , "BOOST_TEST_CATCH_SYSTEM_ERRORS",
+    COLOR_OUTPUT      , "BOOST_TEST_COLOR_OUTPUT",
     DETECT_FP_EXCEPT  , "BOOST_TEST_DETECT_FP_EXCEPTIONS",
     DETECT_MEM_LEAKS  , "BOOST_TEST_DETECT_MEMORY_LEAK",
     LOG_FORMAT        , "BOOST_TEST_LOG_FORMAT",
@@ -261,6 +263,9 @@
           << cla::dual_name_parameter<bool>( CATCH_SYS_ERRORS + "|s" )
             - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
                cla::description = "Allows to switch between catching and ignoring system errors (signals)")
+          << cla::dual_name_parameter<bool>( COLOR_OUTPUT + "|x" )
+            - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
+               cla::description = "Allows to switch between catching and ignoring system errors (signals)")
           << cla::named_parameter<bool>( DETECT_FP_EXCEPT )
             - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional,
                cla::description = "Allows to switch between catching and ignoring floating point exceptions")
@@ -423,6 +428,14 @@
 //____________________________________________________________________________//
 
 bool
+color_output()
+{
+    return retrieve_parameter( COLOR_OUTPUT, s_cla_parser, false );
+}
+
+//____________________________________________________________________________//
+
+bool
 auto_start_dbg()
 {
     // !! set debugger as an option
Added: trunk/boost/test/utils/setcolor.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/test/utils/setcolor.hpp	2009-12-13 04:24:47 EST (Sun, 13 Dec 2009)
@@ -0,0 +1,121 @@
+//  (C) Copyright Gennadiy Rozental 2009.
+//  Distributed under the Boost Software License, Version 1.0.
+//  (See accompanying file LICENSE_1_0.txt or copy at 
+//  http://www.boost.org/LICENSE_1_0.txt)
+
+//  See http://www.boost.org/libs/test for the library home page.
+//
+//  File        : $RCSfile$
+//
+//  Version     : $Revision$
+//
+//  Description : contains definition for setcolor iostream manipulator
+// ***************************************************************************
+
+#ifndef BOOST_TEST_SETCOLOR_HPP_121009GER
+#define BOOST_TEST_SETCOLOR_HPP_121009GER
+
+// Boost.Test
+#include <boost/test/detail/config.hpp>
+
+// STL
+#include <iostream>
+#include <cstdio>
+
+#include <boost/test/detail/suppress_warnings.hpp>
+
+//____________________________________________________________________________//
+
+namespace boost {
+
+namespace unit_test {
+
+// ************************************************************************** //
+// **************                    term_attr                 ************** //
+// ************************************************************************** //
+
+struct term_attr { enum _ { 
+    NORMAL    = 0,
+    BRIGHT    = 1,
+    DIM       = 2,
+    UNDERLINE = 4,
+    BLINK     = 5,
+    REVERSE   = 7,
+    CROSSOUT  = 9 
+}; };
+
+// ************************************************************************** //
+// **************                   term_color                 ************** //
+// ************************************************************************** //
+
+struct term_color { enum _ { 
+    BLACK    = 0,
+    RED      = 1,
+    GREEN    = 2,
+    YELLOW   = 3,
+    BLUE     = 4,
+    MAGENTA  = 5,
+    CYAN     = 6,
+    WHITE    = 7,
+    ORIGINAL = 9
+}; };
+
+// ************************************************************************** //
+// **************                    setcolor                  ************** //
+// ************************************************************************** //
+
+class setcolor {
+public:
+    // Constructor
+    explicit    setcolor( term_attr::_  attr = term_attr::NORMAL, 
+                          term_color::_ fg   = term_color::ORIGINAL, 
+                          term_color::_ bg   = term_color::ORIGINAL )
+    {
+        m_command_size = std::sprintf( m_control_command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40 );
+    }
+
+    friend std::ostream&
+    operator<<( std::ostream& os, setcolor const& sc )
+    {
+        return os.write( sc.m_control_command, sc.m_command_size );
+    }
+
+private:
+    // Data members
+    char        m_control_command[13];
+    size_t      m_command_size;
+};
+
+// ************************************************************************** //
+// **************                 scope_setcolor               ************** //
+// ************************************************************************** //
+
+struct scope_setcolor {
+    scope_setcolor() : m_os( 0 ) {}
+    explicit    scope_setcolor( std::ostream& os,
+                                term_attr::_  attr = term_attr::NORMAL, 
+                                term_color::_ fg   = term_color::ORIGINAL, 
+                                term_color::_ bg   = term_color::ORIGINAL )
+    : m_os( &os )
+    {
+        os << setcolor( attr, fg, bg );
+    }
+    ~scope_setcolor()
+    {
+        if( m_os )
+	    *m_os << setcolor();
+    }
+private:
+    // Data members
+    std::ostream* m_os;
+};
+
+} // namespace unit_test
+
+} // namespace boost
+
+//____________________________________________________________________________//
+
+#include <boost/test/detail/enable_warnings.hpp>
+
+#endif // BOOST_TEST_SETCOLOR_HPP_121009GER