summaryrefslogtreecommitdiff
path: root/boost/test/unit_test_log.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/test/unit_test_log.hpp')
-rw-r--r--boost/test/unit_test_log.hpp103
1 files changed, 102 insertions, 1 deletions
diff --git a/boost/test/unit_test_log.hpp b/boost/test/unit_test_log.hpp
index 4126953d02..ba998b0ca4 100644
--- a/boost/test/unit_test_log.hpp
+++ b/boost/test/unit_test_log.hpp
@@ -85,6 +85,30 @@ private:
// ************** unit_test_log ************** //
// ************************************************************************** //
+/// @brief Manages the sets of loggers, their streams and log levels
+///
+/// The Boost.Test framework allows for having several formatters/loggers at the same time, each of which
+/// having their own log level and output stream.
+///
+/// This class serves the purpose of
+/// - exposing an interface to the test framework (as a boost::unit_test::test_observer)
+/// - exposing an interface to the testing tools
+/// - managing several loggers
+///
+/// @note Accesses to the functions exposed by this class are made through the singleton
+/// @c boost::unit_test::unit_test_log.
+///
+/// Users/developers willing to implement their own formatter need to:
+/// - implement a boost::unit_test::unit_test_log_formatter that will output the desired format
+/// - register the formatter during a eg. global fixture using the method @c set_formatter (though the framework singleton).
+///
+/// @warning this observer has a higher priority than the @ref boost::unit_test::results_collector_t. This means
+/// that the various @ref boost::unit_test::test_results associated to each test unit may not be available at the time
+/// the @c test_unit_start, @c test_unit_finish ... are called.
+///
+/// @see
+/// - boost::unit_test::test_observer
+/// - boost::unit_test::unit_test_log_formatter
class BOOST_TEST_DECL unit_test_log_t : public test_observer, public singleton<unit_test_log_t> {
public:
// test_observer interface implementation
@@ -95,17 +119,83 @@ public:
virtual void test_unit_start( test_unit const& );
virtual void test_unit_finish( test_unit const&, unsigned long elapsed );
virtual void test_unit_skipped( test_unit const&, const_string );
+ virtual void test_unit_aborted( test_unit const& );
virtual void exception_caught( execution_exception const& ex );
virtual int priority() { return 1; }
// log configuration methods
+ //! Sets the stream for all loggers
+ //!
+ //! This will override the log sink/stream of all loggers, whether enabled or not.
void set_stream( std::ostream& );
+
+ //! Sets the stream for specific logger
+ //!
+ //! @note Has no effect if the specified format is not found
+ //! @par Since Boost 1.62
+ void set_stream( output_format, std::ostream& );
+
+ //! Sets the threshold level for all loggers/formatters.
+ //!
+ //! This will override the log level of all loggers, whether enabled or not.
void set_threshold_level( log_level );
+
+ //! Sets the threshold/log level of a specific format
+ //!
+ //! @note Has no effect if the specified format is not found
+ //! @par Since Boost 1.62
+ void set_threshold_level( output_format, log_level );
+
+ //! Add a format to the set of loggers
+ //!
+ //! Adding a logger means that the specified logger is enabled. The log level is managed by the formatter itself
+ //! and specifies what events are forwarded to the underlying formatter.
+ //! @par Since Boost 1.62
+ void add_format( output_format );
+
+ //! Sets the format of the logger
+ //!
+ //! This will become the only active format of the logs.
void set_format( output_format );
+
+ //! Returns the logger instance for a specific format.
+ //!
+ //! @returns the logger/formatter instance, or @c (unit_test_log_formatter*)0 if the format is not found.
+ //! @par Since Boost 1.62
+ unit_test_log_formatter* get_formatter( output_format );
+
+ //! Sets the logger instance
+ //!
+ //! The specified logger becomes the unique active one. The custom log formatter has the
+ //! format @c OF_CUSTOM_LOGGER. If such a format exists already, its formatter gets replaced by the one
+ //! given in argument.
+ //!
+ //! The log level and output stream of the new formatter are taken from the currently active logger. In case
+ //! several loggers are active, the order of priority is CUSTOM, HRF, XML, and JUNIT.
+ //! If (unit_test_log_formatter*)0 is given as argument, the custom logger (if any) is removed.
+ //!
+ //! @note The ownership of the pointer is transfered to the Boost.Test framework. This call is equivalent to
+ //! - a call to @c add_formatter
+ //! - a call to @c set_format(OF_CUSTOM_LOGGER)
+ //! - a configuration of the newly added logger with a previously configured stream and log level.
void set_formatter( unit_test_log_formatter* );
+ //! Adds a custom log formatter to the set of formatters
+ //!
+ //! The specified logger is added with the format @c OF_CUSTOM_LOGGER, such that it can
+ //! be futher selected or its stream/log level can be specified.
+ //! If there is already a custom logger (with @c OF_CUSTOM_LOGGER), then
+ //! the existing one gets replaced by the one given in argument.
+ //! The provided logger is added with an enabled state.
+ //! If (unit_test_log_formatter*)0 is given as argument, the custom logger (if any) is removed and
+ //! no other action is performed.
+ //!
+ //! @note The ownership of the pointer is transfered to the Boost.Test framework.
+ //! @par Since Boost 1.62
+ void add_formatter( unit_test_log_formatter* the_formatter );
+
// test progress logging
void set_checkpoint( const_string file, std::size_t line_num, const_string msg = const_string() );
@@ -120,7 +210,7 @@ public:
private:
// Implementation helpers
- bool log_entry_start();
+ bool log_entry_start(output_format log_format);
void log_entry_context( log_level l );
void clear_entry_context();
@@ -142,6 +232,17 @@ BOOST_TEST_SINGLETON_INST( unit_test_log )
// ************** Unit test log interface helpers ************** //
// ************************************************************************** //
+// messages sent by the framework
+#define BOOST_TEST_FRAMEWORK_MESSAGE( M ) \
+ (::boost::unit_test::unit_test_log \
+ << ::boost::unit_test::log::begin( \
+ "boost.test framework", \
+ __LINE__ )) \
+ ( ::boost::unit_test::log_messages ) \
+ << BOOST_TEST_LAZY_MSG( M ) \
+/**/
+
+
#define BOOST_TEST_MESSAGE( M ) \
BOOST_TEST_LOG_ENTRY( ::boost::unit_test::log_messages ) \
<< BOOST_TEST_LAZY_MSG( M ) \