1 // (C) Copyright 2016 Raffi Enficiaud.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
9 ///@brief Contains the definition of the Junit log formatter (OF_JUNIT)
10 // ***************************************************************************
12 #ifndef BOOST_TEST_JUNIT_LOG_FORMATTER__
13 #define BOOST_TEST_JUNIT_LOG_FORMATTER__
16 #include <boost/test/detail/global_typedef.hpp>
17 #include <boost/test/unit_test_log_formatter.hpp>
18 #include <boost/test/tree/test_unit.hpp>
20 //#include <boost/test/results_collector.hpp>
23 #include <cstddef> // std::size_t
27 #include <boost/test/detail/suppress_warnings.hpp>
29 //____________________________________________________________________________//
36 namespace junit_impl {
38 // helper for the JUnit logger
39 struct junit_log_helper
41 struct assertion_entry {
49 assertion_entry() : sealed(false)
52 std::string logentry_message;
53 std::string logentry_type; // the one that will get expanded in the final junit (failure, error)
54 std::string output; // additional information/message generated by the assertion
56 log_entry_t log_entry; // the type associated to the assertion (or error)
58 bool sealed; // indicates if the entry can accept additional information
61 std::string system_out; // sysout: additional information
62 std::string system_err; // syserr: additional information
64 // list of failure, errors and messages (assertions message and the full log)
65 std::vector< assertion_entry > assertion_entries;
70 // ************************************************************************** //
71 // ************** junit_log_formatter ************** //
72 // ************************************************************************** //
74 /// JUnit logger class
75 class junit_log_formatter : public unit_test_log_formatter {
78 junit_log_formatter() : m_display_build_info(false)
80 this->m_log_level = log_successful_tests;
83 // Formatter interface
84 void log_start( std::ostream&, counter_t test_cases_amount );
85 void log_finish( std::ostream& );
86 void log_build_info( std::ostream& );
88 void test_unit_start( std::ostream&, test_unit const& tu );
89 void test_unit_finish( std::ostream&, test_unit const& tu, unsigned long elapsed );
90 void test_unit_skipped( std::ostream&, test_unit const& tu, const_string reason );
91 void test_unit_aborted( std::ostream& os, test_unit const& tu );
93 void log_exception_start( std::ostream&, log_checkpoint_data const&, execution_exception const& ex );
94 void log_exception_finish( std::ostream& );
96 void log_entry_start( std::ostream&, log_entry_data const&, log_entry_types let );
98 using unit_test_log_formatter::log_entry_value; // bring base class functions into overload set
99 void log_entry_value( std::ostream&, const_string value );
100 void log_entry_finish( std::ostream& );
102 void entry_context_start( std::ostream&, log_level );
103 void log_entry_context( std::ostream&, const_string );
104 void entry_context_finish( std::ostream& );
106 //! Discards changes in the log level
107 virtual void set_log_level(log_level )
111 //! Instead of a regular stream, returns a file name corresponding to
112 //! the current master test suite. If the file already exists, adds an index
114 virtual std::string get_default_stream_description() const;
118 typedef std::map<test_unit_id, junit_impl::junit_log_helper> map_trace_t;
119 map_trace_t map_tests;
121 std::list<test_unit_id> list_path_to_root;
122 test_unit_id root_id;
123 bool m_display_build_info;
124 bool m_is_last_assertion_or_error; // true if failure, false if error
126 friend class junit_result_helper;
129 } // namespace output
130 } // namespace unit_test
133 #include <boost/test/detail/enable_warnings.hpp>
135 #endif // BOOST_TEST_JUNIT_LOG_FORMATTER__