1 // (C) Copyright Gennadiy Rozental 2001.
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.
10 // Version : $Revision$
12 // Description : implements framework API - main driver for the test
13 // ***************************************************************************
15 #ifndef BOOST_TEST_FRAMEWORK_IPP_021005GER
16 #define BOOST_TEST_FRAMEWORK_IPP_021005GER
19 #include <boost/test/framework.hpp>
20 #include <boost/test/execution_monitor.hpp>
21 #include <boost/test/debug.hpp>
22 #include <boost/test/unit_test_parameters.hpp>
24 #include <boost/test/unit_test_log.hpp>
25 #include <boost/test/unit_test_log_formatter.hpp>
26 #include <boost/test/unit_test_monitor.hpp>
27 #include <boost/test/results_collector.hpp>
28 #include <boost/test/progress_monitor.hpp>
29 #include <boost/test/results_reporter.hpp>
30 #include <boost/test/test_framework_init_observer.hpp>
32 #include <boost/test/tree/observer.hpp>
33 #include <boost/test/tree/test_unit.hpp>
34 #include <boost/test/tree/visitor.hpp>
35 #include <boost/test/tree/traverse.hpp>
36 #include <boost/test/tree/test_case_counter.hpp>
38 #if BOOST_TEST_SUPPORT_TOKEN_ITERATOR
39 #include <boost/test/utils/iterator/token_iterator.hpp>
42 #include <boost/test/utils/foreach.hpp>
43 #include <boost/test/utils/basic_cstring/io.hpp>
44 #include <boost/test/utils/basic_cstring/compare.hpp>
46 #include <boost/test/detail/global_typedef.hpp>
47 #include <boost/test/detail/throw_exception.hpp>
50 #include <boost/timer.hpp>
51 #include <boost/bind.hpp>
60 #ifdef BOOST_NO_CXX98_RANDOM_SHUFFLE
64 #ifdef BOOST_NO_STDC_NAMESPACE
65 namespace std { using ::time; using ::srand; }
68 #include <boost/test/detail/suppress_warnings.hpp>
70 //____________________________________________________________________________//
78 // ************************************************************************** //
79 // ************** order detection helpers ************** //
80 // ************************************************************************** //
83 order_info() : depth(-1) {}
86 std::vector<test_unit_id> dependant_siblings;
89 typedef std::set<test_unit_id> tu_id_set;
90 typedef std::map<test_unit_id,order_info> order_info_per_tu; // !! ?? unordered map
92 //____________________________________________________________________________//
95 get_tu_parent( test_unit_id tu_id )
97 return framework::get( tu_id, TUT_ANY ).p_parent_id;
100 //____________________________________________________________________________//
103 tu_depth( test_unit_id tu_id, test_unit_id master_tu_id, order_info_per_tu& tuoi )
105 if( tu_id == master_tu_id )
108 order_info& info = tuoi[tu_id];
110 if( info.depth == -1 )
111 info.depth = tu_depth( get_tu_parent( tu_id ), master_tu_id, tuoi ) + 1;
116 //____________________________________________________________________________//
119 collect_dependant_siblings( test_unit_id from, test_unit_id to, test_unit_id master_tu_id, order_info_per_tu& tuoi )
121 int from_depth = tu_depth( from, master_tu_id, tuoi );
122 int to_depth = tu_depth( to, master_tu_id, tuoi );
124 while(from_depth > to_depth) {
125 from = get_tu_parent( from );
129 while(from_depth < to_depth) {
130 to = get_tu_parent( to );
135 test_unit_id from_parent = get_tu_parent( from );
136 test_unit_id to_parent = get_tu_parent( to );
137 if( from_parent == to_parent )
143 tuoi[from].dependant_siblings.push_back( to );
146 //____________________________________________________________________________//
149 assign_sibling_rank( test_unit_id tu_id, order_info_per_tu& tuoi )
151 test_unit& tu = framework::get( tu_id, TUT_ANY );
153 BOOST_TEST_SETUP_ASSERT( tu.p_sibling_rank != (std::numeric_limits<counter_t>::max)(),
154 "Cyclic dependency detected involving test unit \"" + tu.full_name() + "\"" );
156 if( tu.p_sibling_rank != 0 )
157 return tu.p_sibling_rank;
159 order_info const& info = tuoi[tu_id];
161 // indicate in progress
162 tu.p_sibling_rank.value = (std::numeric_limits<counter_t>::max)();
164 counter_t new_rank = 1;
165 BOOST_TEST_FOREACH( test_unit_id, sibling_id, info.dependant_siblings )
166 new_rank = (std::max)(new_rank, assign_sibling_rank( sibling_id, tuoi ) + 1);
168 return tu.p_sibling_rank.value = new_rank;
171 //____________________________________________________________________________//
173 // ************************************************************************** //
174 // ************** test_init call wrapper ************** //
175 // ************************************************************************** //
178 invoke_init_func( init_unit_test_func init_func )
180 #ifdef BOOST_TEST_ALTERNATIVE_INIT_API
181 BOOST_TEST_I_ASSRT( (*init_func)(), std::runtime_error( "test module initialization failed" ) );
183 test_suite* manual_test_units = (*init_func)( framework::master_test_suite().argc, framework::master_test_suite().argv );
185 if( manual_test_units )
186 framework::master_test_suite().add( manual_test_units );
190 // ************************************************************************** //
191 // ************** name_filter ************** //
192 // ************************************************************************** //
194 class name_filter : public test_tree_visitor {
196 component( const_string name ) // has to be implicit
200 else if( first_char( name ) == '*' && last_char( name ) == '*' ) {
202 m_name = name.substr( 1, name.size()-1 );
204 else if( first_char( name ) == '*' ) {
205 m_kind = SFK_TRAILING;
206 m_name = name.substr( 1 );
208 else if( last_char( name ) == '*' ) {
209 m_kind = SFK_LEADING;
210 m_name = name.substr( 0, name.size()-1 );
218 bool pass( test_unit const& tu ) const
220 const_string name( tu.p_name );
227 return name.substr( 0, m_name.size() ) == m_name;
229 return name.size() >= m_name.size() && name.substr( name.size() - m_name.size() ) == m_name;
231 return name.find( m_name ) != const_string::npos;
233 return m_name == tu.p_name.get();
236 enum kind { SFK_ALL, SFK_LEADING, SFK_TRAILING, SFK_SUBSTR, SFK_MATCH };
244 name_filter( test_unit_id_list& targ_list, const_string filter_expr ) : m_targ_list( targ_list ), m_depth( 0 )
246 #ifdef BOOST_TEST_SUPPORT_TOKEN_ITERATOR
247 utils::string_token_iterator tit( filter_expr, (utils::dropped_delimeters = "/",
248 utils::kept_delimeters = utils::dt_none) );
250 while( tit != utils::string_token_iterator() ) {
251 m_components.push_back(
252 std::vector<component>( utils::string_token_iterator( *tit, (utils::dropped_delimeters = ",",
253 utils::kept_delimeters = utils::dt_none) ),
254 utils::string_token_iterator() ) );
262 bool filter_unit( test_unit const& tu )
264 // skip master test suite
268 // corresponding name filters are at level m_depth-1
269 std::vector<component> const& filters = m_components[m_depth-1];
272 using namespace boost::placeholders;
273 return std::find_if( filters.begin(), filters.end(), bind( &component::pass, _1, boost::ref(tu) ) ) != filters.end();
276 // test_tree_visitor interface
277 virtual void visit( test_case const& tc )
279 // make sure we only accept test cases if we match last component of the filter
280 if( m_depth == m_components.size() && filter_unit( tc ) )
281 m_targ_list.push_back( tc.p_id ); // found a test case
283 virtual bool test_suite_start( test_suite const& ts )
285 if( !filter_unit( ts ) )
288 if( m_depth < m_components.size() ) {
293 m_targ_list.push_back( ts.p_id ); // found a test suite
297 virtual void test_suite_finish( test_suite const& /*ts*/ )
303 typedef std::vector<std::vector<component> > components_per_level;
305 components_per_level m_components;
306 test_unit_id_list& m_targ_list;
310 // ************************************************************************** //
311 // ************** label_filter ************** //
312 // ************************************************************************** //
314 class label_filter : public test_tree_visitor {
316 label_filter( test_unit_id_list& targ_list, const_string label )
317 : m_targ_list( targ_list )
322 // test_tree_visitor interface
323 virtual bool visit( test_unit const& tu )
325 if( tu.has_label( m_label ) ) {
326 // found a test unit; add it to list of tu to enable with children and stop recursion in case of suites
327 m_targ_list.push_back( tu.p_id );
335 test_unit_id_list& m_targ_list;
336 const_string m_label;
339 // ************************************************************************** //
340 // ************** set_run_status ************** //
341 // ************************************************************************** //
343 class set_run_status : public test_tree_visitor {
345 explicit set_run_status( test_unit::run_status rs, test_unit_id_list* dep_collector = 0 )
347 , m_dep_collector( dep_collector )
350 // test_tree_visitor interface
351 virtual bool visit( test_unit const& tu )
353 const_cast<test_unit&>(tu).p_run_status.value = m_new_status == test_unit::RS_INVALID ? tu.p_default_status : m_new_status;
354 if( m_dep_collector ) {
355 BOOST_TEST_FOREACH( test_unit_id, dep_id, tu.p_dependencies.get() ) {
356 test_unit const& dep = framework::get( dep_id, TUT_ANY );
358 if( dep.p_run_status == tu.p_run_status )
361 BOOST_TEST_FRAMEWORK_MESSAGE( "Including test " << dep.p_type_name << ' ' << dep.full_name() <<
362 " as a dependency of test " << tu.p_type_name << ' ' << tu.full_name() );
364 m_dep_collector->push_back( dep_id );
372 test_unit::run_status m_new_status;
373 test_unit_id_list* m_dep_collector;
376 // ************************************************************************** //
377 // ************** parse_filters ************** //
378 // ************************************************************************** //
381 add_filtered_test_units( test_unit_id master_tu_id, const_string filter, test_unit_id_list& targ )
383 // Choose between two kinds of filters
384 if( filter[0] == '@' ) {
385 filter.trim_left( 1 );
386 label_filter lf( targ, filter );
387 traverse_test_tree( master_tu_id, lf, true );
390 name_filter nf( targ, filter );
391 traverse_test_tree( master_tu_id, nf, true );
395 //____________________________________________________________________________//
398 parse_filters( test_unit_id master_tu_id, test_unit_id_list& tu_to_enable, test_unit_id_list& tu_to_disable )
400 // 10. collect tu to enable and disable based on filters
401 bool had_selector_filter = false;
403 std::vector<std::string> const& filters = runtime_config::get<std::vector<std::string> >( runtime_config::btrt_run_filters );
405 BOOST_TEST_FOREACH( const_string, filter, filters ) {
406 BOOST_TEST_SETUP_ASSERT( !filter.is_empty(), "Invalid filter specification" );
408 // each --run_test command may also be separated by a ':' (environment variable)
409 utils::string_token_iterator t_filter_it( filter, (utils::dropped_delimeters = ":",
410 utils::kept_delimeters = utils::dt_none) );
412 while( t_filter_it != utils::string_token_iterator() ) {
413 const_string filter_token = *t_filter_it;
415 enum { SELECTOR, ENABLER, DISABLER } filter_type = SELECTOR;
417 // 11. Deduce filter type
418 if( filter_token[0] == '!' || filter_token[0] == '+' ) {
419 filter_type = filter_token[0] == '+' ? ENABLER : DISABLER;
420 filter_token.trim_left( 1 );
421 BOOST_TEST_SETUP_ASSERT( !filter_token.is_empty(), "Invalid filter specification" );
424 had_selector_filter |= filter_type == SELECTOR;
426 // 12. Add test units to corresponding list
427 switch( filter_type ) {
429 case ENABLER: add_filtered_test_units( master_tu_id, filter_token, tu_to_enable ); break;
430 case DISABLER: add_filtered_test_units( master_tu_id, filter_token, tu_to_disable ); break;
437 return had_selector_filter;
440 //____________________________________________________________________________//
442 #ifdef BOOST_NO_CXX98_RANDOM_SHUFFLE
444 // a poor man's implementation of random_shuffle
445 template< class RandomIt, class RandomFunc >
446 void random_shuffle( RandomIt first, RandomIt last, RandomFunc &r )
448 typedef typename std::iterator_traits<RandomIt>::difference_type difference_type;
449 difference_type n = last - first;
450 for (difference_type i = n-1; i > 0; --i) {
451 difference_type j = r(i+1);
454 swap(first[i], first[j]);
462 // A simple handle for registering the global fixtures to the master test suite
463 // without deleting an existing static object (the global fixture itself) when the program
464 // terminates (shared_ptr).
465 class global_fixture_handle : public test_unit_fixture {
467 global_fixture_handle(test_unit_fixture* fixture) : m_global_fixture(fixture) {}
468 ~global_fixture_handle() {}
470 virtual void setup() {
471 m_global_fixture->setup();
473 virtual void teardown() {
474 m_global_fixture->teardown();
478 test_unit_fixture* m_global_fixture;
484 // ************************************************************************** //
485 // ************** framework::state ************** //
486 // ************************************************************************** //
488 unsigned const TIMEOUT_EXCEEDED = static_cast<unsigned>( -1 );
493 : m_master_test_suite( 0 )
494 , m_curr_test_unit( INV_TEST_UNIT_ID )
495 , m_next_test_case_id( MIN_TEST_CASE_ID )
496 , m_next_test_suite_id( MIN_TEST_SUITE_ID )
497 , m_test_in_progress( false )
500 , m_report_sink( std::cerr )
504 ~state() { clear(); }
508 while( !m_test_units.empty() ) {
509 test_unit_store::value_type const& tu = *m_test_units.begin();
510 test_unit const* tu_ptr = tu.second;
512 // the delete will erase this element from map
513 if( ut_detail::test_id_2_unit_type( tu.second->p_id ) == TUT_SUITE )
514 delete static_cast<test_suite const*>(tu_ptr);
516 delete static_cast<test_case const*>(tu_ptr);
520 void set_tu_id( test_unit& tu, test_unit_id id ) { tu.p_id.value = id; }
522 //////////////////////////////////////////////////////////////////
524 // Validates the dependency graph and deduces the sibling dependency rank for each child
525 void deduce_siblings_order( test_unit_id tu_id, test_unit_id master_tu_id, impl::order_info_per_tu& tuoi )
527 test_unit& tu = framework::get( tu_id, TUT_ANY );
529 // collect all sibling dependancy from tu own list
530 BOOST_TEST_FOREACH( test_unit_id, dep_id, tu.p_dependencies.get() )
531 collect_dependant_siblings( tu_id, dep_id, master_tu_id, tuoi );
533 if( tu.p_type != TUT_SUITE )
536 test_suite& ts = static_cast<test_suite&>(tu);
538 // recursive call to children first
539 BOOST_TEST_FOREACH( test_unit_id, chld_id, ts.m_children )
540 deduce_siblings_order( chld_id, master_tu_id, tuoi );
542 ts.m_ranked_children.clear();
543 BOOST_TEST_FOREACH( test_unit_id, chld_id, ts.m_children ) {
544 counter_t rank = assign_sibling_rank( chld_id, tuoi );
545 ts.m_ranked_children.insert( std::make_pair( rank, chld_id ) );
549 //////////////////////////////////////////////////////////////////
551 // Finalize default run status:
552 // 1) inherit run status from parent where applicable
553 // 2) if any of test units in test suite enabled enable it as well
554 bool finalize_default_run_status( test_unit_id tu_id, test_unit::run_status parent_status )
556 test_unit& tu = framework::get( tu_id, TUT_ANY );
558 if( tu.p_default_status == test_suite::RS_INHERIT )
559 tu.p_default_status.value = parent_status;
561 // go through list of children
562 if( tu.p_type == TUT_SUITE ) {
563 bool has_enabled_child = false;
564 BOOST_TEST_FOREACH( test_unit_id, chld_id, static_cast<test_suite const&>(tu).m_children )
565 has_enabled_child |= finalize_default_run_status( chld_id, tu.p_default_status );
567 tu.p_default_status.value = has_enabled_child ? test_suite::RS_ENABLED : test_suite::RS_DISABLED;
570 return tu.p_default_status == test_suite::RS_ENABLED;
573 //////////////////////////////////////////////////////////////////
575 bool finalize_run_status( test_unit_id tu_id )
577 test_unit& tu = framework::get( tu_id, TUT_ANY );
579 // go through list of children
580 if( tu.p_type == TUT_SUITE ) {
581 bool has_enabled_child = false;
582 BOOST_TEST_FOREACH( test_unit_id, chld_id, static_cast<test_suite const&>(tu).m_children)
583 has_enabled_child |= finalize_run_status( chld_id );
585 tu.p_run_status.value = has_enabled_child ? test_suite::RS_ENABLED : test_suite::RS_DISABLED;
588 return tu.is_enabled();
591 //////////////////////////////////////////////////////////////////
593 void deduce_run_status( test_unit_id master_tu_id )
595 using namespace framework::impl;
596 test_unit_id_list tu_to_enable;
597 test_unit_id_list tu_to_disable;
599 // 10. If there are any filters supplied, figure out lists of test units to enable/disable
600 bool had_selector_filter = !runtime_config::get<std::vector<std::string> >( runtime_config::btrt_run_filters ).empty() &&
601 parse_filters( master_tu_id, tu_to_enable, tu_to_disable );
603 // 20. Set the stage: either use default run status or disable all test units
604 set_run_status initial_setter( had_selector_filter ? test_unit::RS_DISABLED : test_unit::RS_INVALID );
605 traverse_test_tree( master_tu_id, initial_setter, true );
607 // 30. Apply all selectors and enablers.
608 while( !tu_to_enable.empty() ) {
609 test_unit& tu = framework::get( tu_to_enable.back(), TUT_ANY );
611 tu_to_enable.pop_back();
613 // 35. Ignore test units which are already enabled
614 if( tu.is_enabled() )
617 // set new status and add all dependencies into tu_to_enable
618 set_run_status enabler( test_unit::RS_ENABLED, &tu_to_enable );
619 traverse_test_tree( tu.p_id, enabler, true );
621 // Add the dependencies of the parent suites, see trac #13149
622 test_unit_id parent_id = tu.p_parent_id;
623 while( parent_id != INV_TEST_UNIT_ID
624 && parent_id != master_tu_id )
626 // we do not use the traverse_test_tree as otherwise it would enable the sibblings and subtree
627 // of the test case we want to enable (we need to enable the parent suites and their dependencies only)
628 // the parent_id needs to be enabled in order to be properly parsed by finalize_run_status, the visit
630 test_unit& tu_parent = framework::get( parent_id, TUT_ANY );
631 enabler.visit( tu_parent );
632 parent_id = tu_parent.p_parent_id;
636 // 40. Apply all disablers
637 while( !tu_to_disable.empty() ) {
638 test_unit const& tu = framework::get( tu_to_disable.back(), TUT_ANY );
640 tu_to_disable.pop_back();
642 // 35. Ignore test units which already disabled
643 if( !tu.is_enabled() )
646 set_run_status disabler( test_unit::RS_DISABLED );
647 traverse_test_tree( tu.p_id, disabler, true );
650 // 50. Make sure parents of enabled test units are also enabled
651 finalize_run_status( master_tu_id );
654 //////////////////////////////////////////////////////////////////
656 typedef unit_test_monitor_t::error_level execution_result;
658 // Random generator using the std::rand function (seeded prior to the call)
659 struct random_generator_helper {
660 size_t operator()(size_t i) const {
661 return std::rand() % i;
665 // Executes the test tree with the root at specified test unit
666 execution_result execute_test_tree( test_unit_id tu_id,
667 unsigned timeout = 0,
668 random_generator_helper const * const p_random_generator = 0)
670 test_unit const& tu = framework::get( tu_id, TUT_ANY );
672 execution_result result = unit_test_monitor_t::test_ok;
674 if( !tu.is_enabled() )
677 // 10. Check preconditions, including zero time left for execution and
678 // successful execution of all dependencies
679 if( timeout == TIMEOUT_EXCEEDED ) {
680 // notify all observers about skipped test unit
681 BOOST_TEST_FOREACH( test_observer*, to, m_observers )
682 to->test_unit_skipped( tu, "timeout for the test unit is exceeded" );
684 return unit_test_monitor_t::os_timeout;
686 else if( timeout == 0 || timeout > tu.p_timeout ) // deduce timeout for this test unit
687 timeout = tu.p_timeout;
689 test_tools::assertion_result const precondition_res = tu.check_preconditions();
690 if( !precondition_res ) {
691 // notify all observers about skipped test unit
692 BOOST_TEST_FOREACH( test_observer*, to, m_observers )
693 to->test_unit_skipped( tu, precondition_res.message() );
695 return unit_test_monitor_t::precondition_failure;
698 // 20. Notify all observers about the start of the test unit
699 BOOST_TEST_FOREACH( test_observer*, to, m_observers )
700 to->test_unit_start( tu );
702 // 30. Execute setup fixtures if any; any failure here leads to test unit abortion
703 BOOST_TEST_FOREACH( test_unit_fixture_ptr, F, tu.p_fixtures.get() ) {
704 ut_detail::test_unit_id_restore restore_current_test_unit(m_curr_test_unit, tu.p_id);
705 result = unit_test_monitor.execute_and_translate( boost::bind( &test_unit_fixture::setup, F ) );
706 if( result != unit_test_monitor_t::test_ok )
708 test_results const& test_rslt = unit_test::results_collector.results( m_curr_test_unit );
709 if( test_rslt.aborted() ) {
710 result = unit_test_monitor_t::precondition_failure;
715 // This is the time we are going to spend executing the test unit
716 unsigned long elapsed = 0;
718 if( result == unit_test_monitor_t::test_ok ) {
719 // 40. We are going to time the execution
720 boost::timer tu_timer;
722 // we pass the random generator
723 const random_generator_helper& rand_gen = p_random_generator ? *p_random_generator : random_generator_helper();
725 if( tu.p_type == TUT_SUITE ) {
726 test_suite const& ts = static_cast<test_suite const&>( tu );
728 if( runtime_config::get<unsigned>( runtime_config::btrt_random_seed ) == 0 ) {
729 typedef std::pair<counter_t,test_unit_id> value_type;
731 BOOST_TEST_FOREACH( value_type, chld, ts.m_ranked_children ) {
732 unsigned chld_timeout = child_timeout( timeout, tu_timer.elapsed() );
734 result = (std::min)( result, execute_test_tree( chld.second, chld_timeout, &rand_gen ) );
736 if( unit_test_monitor.is_critical_error( result ) )
741 // Go through ranges of children with the same dependency rank and shuffle them
742 // independently. Execute each subtree in this order
743 test_unit_id_list children_with_the_same_rank;
745 typedef test_suite::children_per_rank::const_iterator it_type;
746 it_type it = ts.m_ranked_children.begin();
747 while( it != ts.m_ranked_children.end() ) {
748 children_with_the_same_rank.clear();
750 std::pair<it_type,it_type> range = ts.m_ranked_children.equal_range( it->first );
752 while( it != range.second ) {
753 children_with_the_same_rank.push_back( it->second );
757 #ifdef BOOST_NO_CXX98_RANDOM_SHUFFLE
758 impl::random_shuffle( children_with_the_same_rank.begin(), children_with_the_same_rank.end(), rand_gen );
760 std::random_shuffle( children_with_the_same_rank.begin(), children_with_the_same_rank.end(), rand_gen );
763 BOOST_TEST_FOREACH( test_unit_id, chld, children_with_the_same_rank ) {
764 unsigned chld_timeout = child_timeout( timeout, tu_timer.elapsed() );
766 result = (std::min)( result, execute_test_tree( chld, chld_timeout, &rand_gen ) );
768 if( unit_test_monitor.is_critical_error( result ) )
774 elapsed = static_cast<unsigned long>( tu_timer.elapsed() * 1e6 );
777 test_case const& tc = static_cast<test_case const&>( tu );
782 // setup current test case
783 ut_detail::test_unit_id_restore restore_current_test_unit(m_curr_test_unit, tc.p_id);
785 // execute the test case body
786 result = unit_test_monitor.execute_and_translate( tc.p_test_func, timeout );
787 elapsed = static_cast<unsigned long>( tu_timer.elapsed() * 1e6 );
789 // cleanup leftover context
792 // restore state (scope exit) and abort if necessary
796 // if run error is critical skip teardown, who knows what the state of the program at this point
797 if( !unit_test_monitor.is_critical_error( result ) ) {
798 // execute teardown fixtures if any in reverse order
799 BOOST_TEST_REVERSE_FOREACH( test_unit_fixture_ptr, F, tu.p_fixtures.get() ) {
800 ut_detail::test_unit_id_restore restore_current_test_unit(m_curr_test_unit, tu.p_id);
801 result = (std::min)( result, unit_test_monitor.execute_and_translate( boost::bind( &test_unit_fixture::teardown, F ), 0 ) );
803 if( unit_test_monitor.is_critical_error( result ) )
808 // notify all observers about abortion
809 if( unit_test_monitor.is_critical_error( result ) ) {
810 BOOST_TEST_FOREACH( test_observer*, to, m_observers )
814 // notify all observers about completion
815 BOOST_TEST_REVERSE_FOREACH( test_observer*, to, m_observers )
816 to->test_unit_finish( tu, elapsed );
821 //////////////////////////////////////////////////////////////////
823 unsigned child_timeout( unsigned tu_timeout, double elapsed )
825 if( tu_timeout == 0U )
828 unsigned elpsed_sec = static_cast<unsigned>(elapsed); // rounding to number of whole seconds
830 return tu_timeout > elpsed_sec ? tu_timeout - elpsed_sec : TIMEOUT_EXCEEDED;
833 struct priority_order {
834 bool operator()( test_observer* lhs, test_observer* rhs ) const
836 return (lhs->priority() < rhs->priority()) || ((lhs->priority() == rhs->priority()) && (lhs < rhs));
841 typedef std::map<test_unit_id,test_unit*> test_unit_store;
842 typedef std::set<test_observer*,priority_order> observer_store;
843 struct context_frame {
844 context_frame( std::string const& d, int id, bool sticky )
847 , is_sticky( sticky )
854 typedef std::vector<context_frame> context_data;
856 master_test_suite_t* m_master_test_suite;
857 std::vector<test_suite*> m_auto_test_suites;
859 test_unit_id m_curr_test_unit;
860 test_unit_store m_test_units;
862 test_unit_id m_next_test_case_id;
863 test_unit_id m_next_test_suite_id;
865 bool m_test_in_progress;
867 observer_store m_observers;
868 context_data m_context;
871 std::set<test_unit_fixture*> m_global_fixtures;
873 boost::execution_monitor m_aux_em;
875 std::map<output_format, runtime_config::stream_holder> m_log_sinks;
876 runtime_config::stream_holder m_report_sink;
879 //____________________________________________________________________________//
884 #if defined(__CYGWIN__)
885 framework::state& s_frk_state() { static framework::state* the_inst = 0; if(!the_inst) the_inst = new framework::state; return *the_inst; }
887 framework::state& s_frk_state() { static framework::state the_inst; return the_inst; }
893 setup_for_execution( test_unit const& tu )
895 s_frk_state().deduce_run_status( tu.p_id );
898 struct sum_to_first_only {
899 sum_to_first_only() : is_first(true) {}
900 template <class T, class U>
901 T operator()(T const& l_, U const& r_) {
904 return l_ + r_.first;
906 return l_ + ", " + r_.first;
913 shutdown_loggers_and_reports()
915 s_frk_state().m_log_sinks.clear();
916 s_frk_state().m_report_sink.setup( "stderr" );
925 #ifdef BOOST_TEST_SUPPORT_TOKEN_ITERATOR
926 bool has_combined_logger = runtime_config::has( runtime_config::btrt_combined_logger )
927 && !runtime_config::get< std::vector<std::string> >( runtime_config::btrt_combined_logger ).empty();
929 bool has_combined_logger = false;
932 if( !has_combined_logger ) {
933 unit_test_log.set_threshold_level( runtime_config::get<log_level>( runtime_config::btrt_log_level ) );
934 const output_format format = runtime_config::get<output_format>( runtime_config::btrt_log_format );
935 unit_test_log.set_format( format );
937 runtime_config::stream_holder& stream_logger = s_frk_state().m_log_sinks[format];
938 if( runtime_config::has( runtime_config::btrt_log_sink ) ) {
939 // we remove all streams in this case, so we do not specify the format
940 boost::function< void () > log_cleaner = boost::bind( &unit_test_log_t::set_stream,
942 boost::ref(std::cout)
944 stream_logger.setup( runtime_config::get<std::string>( runtime_config::btrt_log_sink ),
947 unit_test_log.set_stream( stream_logger.ref() );
952 const std::vector<std::string>& v_output_format = runtime_config::get< std::vector<std::string> >( runtime_config::btrt_combined_logger ) ;
954 static const std::pair<const char*, log_level> all_log_levels[] = {
955 std::make_pair( "all" , log_successful_tests ),
956 std::make_pair( "success" , log_successful_tests ),
957 std::make_pair( "test_suite" , log_test_units ),
958 std::make_pair( "unit_scope" , log_test_units ),
959 std::make_pair( "message" , log_messages ),
960 std::make_pair( "warning" , log_warnings ),
961 std::make_pair( "error" , log_all_errors ),
962 std::make_pair( "cpp_exception" , log_cpp_exception_errors ),
963 std::make_pair( "system_error" , log_system_errors ),
964 std::make_pair( "fatal_error" , log_fatal_errors ),
965 std::make_pair( "nothing" , log_nothing )
968 static const std::pair<const char*, output_format> all_formats[] = {
969 std::make_pair( "HRF" , OF_CLF ),
970 std::make_pair( "CLF" , OF_CLF ),
971 std::make_pair( "XML" , OF_XML ),
972 std::make_pair( "JUNIT", OF_JUNIT )
976 bool is_first = true;
978 BOOST_TEST_FOREACH( const_string, current_multi_config, v_output_format ) {
980 #ifdef BOOST_TEST_SUPPORT_TOKEN_ITERATOR
982 // ':' may be used for file names: C:/tmp/mylogsink.xml
983 // we merge the tokens that start with / or \ with the previous one.
984 std::vector<std::string> v_processed_tokens;
987 utils::string_token_iterator current_config( current_multi_config, (utils::dropped_delimeters = ":",
988 utils::kept_delimeters = utils::dt_none) );
990 for( ; current_config != utils::string_token_iterator() ; ++current_config) {
991 std::string str_copy(current_config->begin(), current_config->end());
992 if( ( str_copy[0] == '\\' || str_copy[0] == '/' )
993 && v_processed_tokens.size() > 0) {
994 v_processed_tokens.back() += ":" + str_copy; // ':' has been eaten up
997 v_processed_tokens.push_back(str_copy);
1002 BOOST_TEST_FOREACH( std::string const&, current_config, v_processed_tokens ) {
1004 utils::string_token_iterator current_format_specs( current_config, (utils::keep_empty_tokens,
1005 utils::dropped_delimeters = ",",
1006 utils::kept_delimeters = utils::dt_none) );
1008 output_format format = OF_INVALID ; // default
1009 if( current_format_specs != utils::string_token_iterator() &&
1010 current_format_specs->size() ) {
1012 for(size_t elem=0; elem < sizeof(all_formats)/sizeof(all_formats[0]); elem++) {
1013 if(const_string(all_formats[elem].first) == *current_format_specs) {
1014 format = all_formats[elem].second;
1020 BOOST_TEST_I_ASSRT( format != OF_INVALID,
1021 boost::runtime::access_to_missing_argument()
1022 << "Unable to determine the logger type from '"
1024 << "'. Possible choices are: "
1025 << std::accumulate(all_formats,
1026 all_formats + sizeof(all_formats)/sizeof(all_formats[0]),
1028 sum_to_first_only())
1031 // activates this format
1033 unit_test_log.set_format( format );
1036 unit_test_log.add_format( format );
1040 unit_test_log_formatter * const formatter = unit_test_log.get_formatter(format);
1041 BOOST_TEST_SETUP_ASSERT( formatter, "Logger setup error" );
1043 log_level formatter_log_level = invalid_log_level;
1044 ++current_format_specs ;
1045 if( !current_format_specs->size() ) {
1046 formatter_log_level = formatter->get_log_level(); // default log level given by the formatter
1048 else if( current_format_specs != utils::string_token_iterator() ) {
1050 for(size_t elem=0; elem < sizeof(all_log_levels)/sizeof(all_log_levels[0]); elem++) {
1051 if(const_string(all_log_levels[elem].first) == *current_format_specs) {
1052 formatter_log_level = all_log_levels[elem].second;
1058 BOOST_TEST_I_ASSRT( formatter_log_level != invalid_log_level,
1059 boost::runtime::access_to_missing_argument()
1060 << "Unable to determine the log level from '"
1062 << "'. Possible choices are: "
1063 << std::accumulate(all_log_levels,
1064 all_log_levels + sizeof(all_log_levels)/sizeof(all_log_levels[0]),
1066 sum_to_first_only())
1069 unit_test_log.set_threshold_level( format, formatter_log_level );
1071 runtime_config::stream_holder& stream_logger = s_frk_state().m_log_sinks[format];
1072 boost::function< void () > log_cleaner = boost::bind( &unit_test_log_t::set_stream,
1075 boost::ref(std::cout) );
1076 if( ++current_format_specs != utils::string_token_iterator() &&
1077 current_format_specs->size() ) {
1078 stream_logger.setup( *current_format_specs,
1082 stream_logger.setup( formatter->get_default_stream_description(),
1085 unit_test_log.set_stream( format, stream_logger.ref() );
1088 } // for each logger
1090 } // if/else new logger API
1091 } // BOOST_TEST_I_TRY
1092 BOOST_TEST_I_CATCH( boost::runtime::init_error, ex ) {
1093 BOOST_TEST_SETUP_ASSERT( false, ex.msg );
1095 BOOST_TEST_I_CATCH( boost::runtime::input_error, ex ) {
1096 std::cerr << ex.msg << "\n\n";
1098 BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_exception_failure ) );
1104 //____________________________________________________________________________//
1108 //____________________________________________________________________________//
1110 // ************************************************************************** //
1111 // ************** framework::init ************** //
1112 // ************************************************************************** //
1115 init( init_unit_test_func init_func, int argc, char* argv[] )
1117 using namespace impl;
1119 // 10. Set up runtime parameters
1120 runtime_config::init( argc, argv );
1122 // 20. Set the desired log level, format and sink
1123 impl::setup_loggers();
1125 // 30. Set the desired report level, format and sink
1126 results_reporter::set_level( runtime_config::get<report_level>( runtime_config::btrt_report_level ) );
1127 results_reporter::set_format( runtime_config::get<output_format>( runtime_config::btrt_report_format ) );
1129 if( runtime_config::has( runtime_config::btrt_report_sink ) ) {
1130 boost::function< void () > report_cleaner = boost::bind( &results_reporter::set_stream,
1131 boost::ref(std::cerr)
1133 s_frk_state().m_report_sink.setup( runtime_config::get<std::string>( runtime_config::btrt_report_sink ),
1137 results_reporter::set_stream( s_frk_state().m_report_sink.ref() );
1139 // 40. Register default test observers
1140 register_observer( results_collector );
1141 register_observer( unit_test_log );
1142 register_observer( framework_init_observer );
1144 if( runtime_config::get<bool>( runtime_config::btrt_show_progress ) ) {
1145 progress_monitor.set_stream( std::cout ); // defaults to stdout
1146 register_observer( progress_monitor );
1149 // 50. Set up memory leak detection
1150 unsigned long detect_mem_leak = runtime_config::get<unsigned long>( runtime_config::btrt_detect_mem_leaks );
1151 if( detect_mem_leak > 0 ) {
1152 debug::detect_memory_leaks( true, runtime_config::get<std::string>( runtime_config::btrt_report_mem_leaks ) );
1153 debug::break_memory_alloc( (long)detect_mem_leak );
1156 // 60. Initialize master unit test suite
1157 master_test_suite().argc = argc;
1158 master_test_suite().argv = argv;
1160 // 70. Invoke test module initialization routine
1162 s_frk_state().m_aux_em.vexecute( boost::bind( &impl::invoke_init_func, init_func ) );
1164 BOOST_TEST_I_CATCH( execution_exception, ex ) {
1165 BOOST_TEST_SETUP_ASSERT( false, ex.what() );
1169 //____________________________________________________________________________//
1172 finalize_setup_phase( test_unit_id master_tu_id )
1174 if( master_tu_id == INV_TEST_UNIT_ID )
1175 master_tu_id = master_test_suite().p_id;
1177 // 10. Apply all decorators to the auto test units
1178 class apply_decorators : public test_tree_visitor {
1180 // test_tree_visitor interface
1181 virtual bool visit( test_unit const& tu )
1183 BOOST_TEST_FOREACH( decorator::base_ptr, d, tu.p_decorators.get() )
1184 d->apply( const_cast<test_unit&>(tu) );
1189 traverse_test_tree( master_tu_id, ad, true );
1191 // 20. Finalize setup phase
1192 impl::order_info_per_tu tuoi;
1193 impl::s_frk_state().deduce_siblings_order( master_tu_id, master_tu_id, tuoi );
1194 impl::s_frk_state().finalize_default_run_status( master_tu_id, test_unit::RS_INVALID );
1197 // ************************************************************************** //
1198 // ************** test_in_progress ************** //
1199 // ************************************************************************** //
1204 return impl::s_frk_state().m_test_in_progress;
1207 //____________________________________________________________________________//
1209 // ************************************************************************** //
1210 // ************** framework::shutdown ************** //
1211 // ************************************************************************** //
1216 impl::shutdown_loggers_and_reports();
1217 // eliminating some fake memory leak reports. See for more details:
1218 // http://connect.microsoft.com/VisualStudio/feedback/details/106937/memory-leaks-reported-by-debug-crt-inside-typeinfo-name
1220 # if BOOST_WORKAROUND(BOOST_MSVC, <= 1600 ) && !defined(_DLL) && defined(_DEBUG)
1221 # if BOOST_WORKAROUND(BOOST_MSVC, < 1600 )
1223 #define _MemPtr memPtr
1225 __type_info_node* pNode = __type_info_root_node._Next;
1226 __type_info_node* tmpNode = &__type_info_root_node;
1228 for( ; pNode!=NULL; pNode = tmpNode ) {
1229 tmpNode = pNode->_Next;
1230 delete pNode->_MemPtr;
1233 # if BOOST_WORKAROUND(BOOST_MSVC, < 1600 )
1240 //____________________________________________________________________________//
1242 // ************************************************************************** //
1243 // ************** register_test_unit ************** //
1244 // ************************************************************************** //
1247 register_test_unit( test_case* tc )
1249 BOOST_TEST_SETUP_ASSERT( tc->p_id == INV_TEST_UNIT_ID, BOOST_TEST_L( "test case already registered" ) );
1251 test_unit_id new_id = impl::s_frk_state().m_next_test_case_id;
1253 BOOST_TEST_SETUP_ASSERT( new_id != MAX_TEST_CASE_ID, BOOST_TEST_L( "too many test cases" ) );
1255 typedef state::test_unit_store::value_type map_value_type;
1257 impl::s_frk_state().m_test_units.insert( map_value_type( new_id, tc ) );
1258 impl::s_frk_state().m_next_test_case_id++;
1260 impl::s_frk_state().set_tu_id( *tc, new_id );
1263 //____________________________________________________________________________//
1265 // ************************************************************************** //
1266 // ************** register_test_unit ************** //
1267 // ************************************************************************** //
1270 register_test_unit( test_suite* ts )
1272 BOOST_TEST_SETUP_ASSERT( ts->p_id == INV_TEST_UNIT_ID, BOOST_TEST_L( "test suite already registered" ) );
1274 test_unit_id new_id = impl::s_frk_state().m_next_test_suite_id;
1276 BOOST_TEST_SETUP_ASSERT( new_id != MAX_TEST_SUITE_ID, BOOST_TEST_L( "too many test suites" ) );
1278 typedef state::test_unit_store::value_type map_value_type;
1280 impl::s_frk_state().m_test_units.insert( map_value_type( new_id, ts ) );
1281 impl::s_frk_state().m_next_test_suite_id++;
1283 impl::s_frk_state().set_tu_id( *ts, new_id );
1286 //____________________________________________________________________________//
1288 // ************************************************************************** //
1289 // ************** deregister_test_unit ************** //
1290 // ************************************************************************** //
1293 deregister_test_unit( test_unit* tu )
1295 impl::s_frk_state().m_test_units.erase( tu->p_id );
1298 //____________________________________________________________________________//
1300 // ************************************************************************** //
1301 // ************** clear ************** //
1302 // ************************************************************************** //
1307 impl::s_frk_state().clear();
1310 //____________________________________________________________________________//
1312 // ************************************************************************** //
1313 // ************** register_observer ************** //
1314 // ************************************************************************** //
1317 register_observer( test_observer& to )
1319 impl::s_frk_state().m_observers.insert( &to );
1322 //____________________________________________________________________________//
1324 // ************************************************************************** //
1325 // ************** deregister_observer ************** //
1326 // ************************************************************************** //
1329 deregister_observer( test_observer& to )
1331 impl::s_frk_state().m_observers.erase( &to );
1334 //____________________________________________________________________________//
1336 // ************************************************************************** //
1337 // ************** register_global_fixture ************** //
1338 // ************************************************************************** //
1341 register_global_fixture( test_unit_fixture& tuf )
1343 impl::s_frk_state().m_global_fixtures.insert( &tuf );
1346 //____________________________________________________________________________//
1348 // ************************************************************************** //
1349 // ************** deregister_global_fixture ************** //
1350 // ************************************************************************** //
1353 deregister_global_fixture( test_unit_fixture &tuf )
1355 impl::s_frk_state().m_global_fixtures.erase( &tuf );
1358 //____________________________________________________________________________//
1360 // ************************************************************************** //
1361 // ************** add_context ************** //
1362 // ************************************************************************** //
1365 add_context( ::boost::unit_test::lazy_ostream const& context_descr, bool sticky )
1367 std::stringstream buffer;
1368 context_descr( buffer );
1369 int res_idx = impl::s_frk_state().m_context_idx++;
1371 impl::s_frk_state().m_context.push_back( state::context_frame( buffer.str(), res_idx, sticky ) );
1376 //____________________________________________________________________________//
1378 // ************************************************************************** //
1379 // ************** clear_context ************** //
1380 // ************************************************************************** //
1382 struct frame_with_id {
1383 explicit frame_with_id( int id ) : m_id( id ) {}
1385 bool operator()( state::context_frame const& f )
1387 return f.frame_id == m_id;
1392 //____________________________________________________________________________//
1395 clear_context( int frame_id )
1397 if( frame_id == -1 ) { // clear all non sticky frames
1398 for( int i=static_cast<int>(impl::s_frk_state().m_context.size())-1; i>=0; i-- )
1399 if( !impl::s_frk_state().m_context[i].is_sticky )
1400 impl::s_frk_state().m_context.erase( impl::s_frk_state().m_context.begin()+i );
1403 else { // clear specific frame
1404 state::context_data::iterator it =
1405 std::find_if( impl::s_frk_state().m_context.begin(), impl::s_frk_state().m_context.end(), frame_with_id( frame_id ) );
1407 if( it != impl::s_frk_state().m_context.end() ) // really an internal error if this is not true
1408 impl::s_frk_state().m_context.erase( it );
1412 //____________________________________________________________________________//
1414 // ************************************************************************** //
1415 // ************** get_context ************** //
1416 // ************************************************************************** //
1421 return context_generator();
1424 //____________________________________________________________________________//
1426 // ************************************************************************** //
1427 // ************** context_generator ************** //
1428 // ************************************************************************** //
1431 context_generator::is_empty() const
1433 return impl::s_frk_state().m_context.empty();
1436 //____________________________________________________________________________//
1439 context_generator::next() const
1441 return m_curr_frame < impl::s_frk_state().m_context.size() ? impl::s_frk_state().m_context[m_curr_frame++].descr : const_string();
1444 //____________________________________________________________________________//
1446 // ************************************************************************** //
1447 // ************** master_test_suite ************** //
1448 // ************************************************************************** //
1450 master_test_suite_t&
1453 if( !impl::s_frk_state().m_master_test_suite )
1454 impl::s_frk_state().m_master_test_suite = new master_test_suite_t;
1456 return *impl::s_frk_state().m_master_test_suite;
1459 //____________________________________________________________________________//
1461 // ************************************************************************** //
1462 // ************** current_auto_test_suite ************** //
1463 // ************************************************************************** //
1466 current_auto_test_suite( test_suite* ts, bool push_or_pop )
1468 if( impl::s_frk_state().m_auto_test_suites.empty() )
1469 impl::s_frk_state().m_auto_test_suites.push_back( &framework::master_test_suite() );
1472 impl::s_frk_state().m_auto_test_suites.pop_back();
1474 impl::s_frk_state().m_auto_test_suites.push_back( ts );
1476 return *impl::s_frk_state().m_auto_test_suites.back();
1479 //____________________________________________________________________________//
1481 // ************************************************************************** //
1482 // ************** current_test_case ************** //
1483 // ************************************************************************** //
1488 return get<test_case>( impl::s_frk_state().m_curr_test_unit );
1495 return *impl::s_frk_state().m_test_units[impl::s_frk_state().m_curr_test_unit];
1498 //____________________________________________________________________________//
1501 current_test_case_id()
1503 return impl::s_frk_state().m_curr_test_unit;
1506 //____________________________________________________________________________//
1508 // ************************************************************************** //
1509 // ************** framework::get ************** //
1510 // ************************************************************************** //
1513 get( test_unit_id id, test_unit_type t )
1515 test_unit* res = impl::s_frk_state().m_test_units[id];
1517 BOOST_TEST_I_ASSRT( (res->p_type & t) != 0, internal_error( "Invalid test unit type" ) );
1522 //____________________________________________________________________________//
1524 // ************************************************************************** //
1525 // ************** framework::run ************** //
1526 // ************************************************************************** //
1528 template <class Cont>
1529 struct swap_on_delete {
1530 swap_on_delete(Cont& c1, Cont& c2) : m_c1(c1), m_c2(c2){}
1540 run( test_unit_id id, bool continue_test )
1542 if( id == INV_TEST_UNIT_ID )
1543 id = master_test_suite().p_id;
1545 // Figure out run status for execution phase
1546 impl::s_frk_state().deduce_run_status( id );
1548 test_case_counter tcc;
1549 traverse_test_tree( id, tcc );
1551 BOOST_TEST_SETUP_ASSERT( tcc.p_count != 0 , runtime_config::get<std::vector<std::string> >( runtime_config::btrt_run_filters ).empty()
1552 ? BOOST_TEST_L( "test tree is empty" )
1553 : BOOST_TEST_L( "no test cases matching filter or all test cases were disabled" ) );
1555 bool was_in_progress = framework::test_in_progress();
1556 bool call_start_finish = !continue_test || !was_in_progress;
1557 bool init_ok = true;
1558 const_string setup_error;
1560 if( call_start_finish ) {
1561 // indicates the framework that no test is in progress now if observers need to be notified
1562 impl::s_frk_state().m_test_in_progress = false;
1563 // unit_test::framework_init_observer will get cleared first
1564 BOOST_TEST_FOREACH( test_observer*, to, impl::s_frk_state().m_observers ) {
1566 ut_detail::test_unit_id_restore restore_current_test_unit(impl::s_frk_state().m_curr_test_unit, id);
1567 unit_test_monitor_t::error_level result = unit_test_monitor.execute_and_translate( boost::bind( &test_observer::test_start, to, tcc.p_count ) );
1569 if( result != unit_test_monitor_t::test_ok ) {
1573 if( unit_test::framework_init_observer.has_failed() ) {
1579 BOOST_TEST_I_CATCH( execution_exception, ex ) {
1581 // log only the first error
1583 setup_error = ex.what();
1585 // break; // we should continue otherwise loggers may have improper structure (XML start missing for instance)
1592 // attaching the global fixtures to the main entry point
1593 test_unit& entry_test_unit = framework::get( id, TUT_ANY );
1594 std::vector<test_unit_fixture_ptr> v_saved_fixture(entry_test_unit.p_fixtures.value.begin(),
1595 entry_test_unit.p_fixtures.value.end());
1597 BOOST_TEST_FOREACH( test_unit_fixture*, tuf, impl::s_frk_state().m_global_fixtures ) {
1598 entry_test_unit.p_fixtures.value.insert( entry_test_unit.p_fixtures.value.begin(),
1599 test_unit_fixture_ptr(new impl::global_fixture_handle(tuf)) );
1602 swap_on_delete< std::vector<test_unit_fixture_ptr> > raii_fixture(v_saved_fixture, entry_test_unit.p_fixtures.value);
1604 // now work in progress
1605 impl::s_frk_state().m_test_in_progress = true;
1606 unsigned seed = runtime_config::get<unsigned>( runtime_config::btrt_random_seed );
1611 seed = static_cast<unsigned>( std::rand() ^ std::time( 0 ) ); // better init using std::rand() ^ ...
1614 BOOST_TEST_FRAMEWORK_MESSAGE( "Test cases order is shuffled using seed: " << seed );
1618 // executing the test tree
1619 impl::s_frk_state().execute_test_tree( id );
1621 // removing previously added global fixtures: dtor raii_fixture
1624 impl::s_frk_state().m_test_in_progress = false;
1626 results_reporter::make_report( INV_REPORT_LEVEL, id );
1628 unit_test::framework_init_observer.clear();
1629 if( call_start_finish ) {
1630 // indicates the framework that no test is in progress anymore if observers need to be notified
1631 // and this is a teardown, so assertions should not raise any exception otherwise an exception
1632 // might be raised in a dtor of a global fixture
1633 impl::s_frk_state().m_test_in_progress = false;
1634 BOOST_TEST_REVERSE_FOREACH( test_observer*, to, impl::s_frk_state().m_observers ) {
1635 ut_detail::test_unit_id_restore restore_current_test_unit(impl::s_frk_state().m_curr_test_unit, id);
1640 impl::s_frk_state().m_test_in_progress = was_in_progress;
1642 // propagates the init/teardown error if any
1643 BOOST_TEST_SETUP_ASSERT( init_ok && !unit_test::framework_init_observer.has_failed(), setup_error );
1646 //____________________________________________________________________________//
1649 run( test_unit const* tu, bool continue_test )
1651 run( tu->p_id, continue_test );
1654 //____________________________________________________________________________//
1656 // ************************************************************************** //
1657 // ************** assertion_result ************** //
1658 // ************************************************************************** //
1661 assertion_result( unit_test::assertion_result ar )
1663 BOOST_TEST_FOREACH( test_observer*, to, impl::s_frk_state().m_observers )
1664 to->assertion_result( ar );
1667 //____________________________________________________________________________//
1669 // ************************************************************************** //
1670 // ************** exception_caught ************** //
1671 // ************************************************************************** //
1674 exception_caught( execution_exception const& ex )
1676 BOOST_TEST_FOREACH( test_observer*, to, impl::s_frk_state().m_observers )
1677 to->exception_caught( ex );
1680 //____________________________________________________________________________//
1682 // ************************************************************************** //
1683 // ************** test_unit_aborted ************** //
1684 // ************************************************************************** //
1687 test_unit_aborted( test_unit const& tu )
1689 BOOST_TEST_FOREACH( test_observer*, to, impl::s_frk_state().m_observers )
1690 to->test_unit_aborted( tu );
1693 // ************************************************************************** //
1694 // ************** test_aborted ************** //
1695 // ************************************************************************** //
1700 BOOST_TEST_FOREACH( test_observer*, to, impl::s_frk_state().m_observers )
1701 to->test_aborted( );
1705 //____________________________________________________________________________//
1707 } // namespace framework
1708 } // namespace unit_test
1709 } // namespace boost
1711 #include <boost/test/detail/enable_warnings.hpp>
1713 #endif // BOOST_TEST_FRAMEWORK_IPP_021005GER