Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74958 - in trunk/boost/test: . impl
From: gennadiy.rozental_at_[hidden]
Date: 2011-10-16 01:12:02


Author: rogeeff
Date: 2011-10-16 01:12:00 EDT (Sun, 16 Oct 2011)
New Revision: 74958
URL: http://svn.boost.org/trac/boost/changeset/74958

Log:
Introduces notion of framework shutdown
Fixes #5582
Text files modified:
   trunk/boost/test/framework.hpp | 3
   trunk/boost/test/impl/framework.ipp | 298 +++++++++++++++++++++++++++------------
   trunk/boost/test/impl/unit_test_main.ipp | 20 +
   3 files changed, 223 insertions(+), 98 deletions(-)

Modified: trunk/boost/test/framework.hpp
==============================================================================
--- trunk/boost/test/framework.hpp (original)
+++ trunk/boost/test/framework.hpp 2011-10-16 01:12:00 EDT (Sun, 16 Oct 2011)
@@ -50,6 +50,9 @@
 BOOST_TEST_DECL void init( init_unit_test_func init_func, int argc, char* argv[] );
 BOOST_TEST_DECL bool is_initialized();
 
+// shutdown
+BOOST_TEST_DECL void shutdown();
+
 // mutation access methods
 BOOST_TEST_DECL void register_test_unit( test_case* tc );
 BOOST_TEST_DECL void register_test_unit( test_suite* ts );

Modified: trunk/boost/test/impl/framework.ipp
==============================================================================
--- trunk/boost/test/impl/framework.ipp (original)
+++ trunk/boost/test/impl/framework.ipp 2011-10-16 01:12:00 EDT (Sun, 16 Oct 2011)
@@ -423,6 +423,108 @@
 
 namespace framework {
 
+// ************************************************************************** //
+// ************** apply_filters ************** //
+// ************************************************************************** //
+
+namespace impl {
+void
+apply_filters( test_unit_id tu_id )
+{
+ if( runtime_config::test_to_run().empty() ) {
+ // enable all test units for this run
+ ut_detail::change_status enabler( true );
+ traverse_test_tree( tu_id, enabler, true );
+ }
+ else {
+ // 10. First disable all test units. We'll re-enable only those that pass the filters
+ ut_detail::change_status disabler( false );
+ traverse_test_tree( tu_id, disabler, true );
+
+ // 20. collect tu to enable based on filters
+ ut_detail::tu_enable_list tu_to_enable;
+
+ BOOST_TEST_FOREACH( std::string const&, filter, runtime_config::test_to_run() ) {
+ if( filter.empty() )
+ continue;
+
+ if( filter[0] == '@' ) {
+ ut_detail::label_filter lf( tu_to_enable, const_string(filter).trim_left(1) );
+ traverse_test_tree( tu_id, lf, true );
+ }
+ else {
+ ut_detail::name_filter nf( tu_to_enable, filter );
+ traverse_test_tree( tu_id, nf, true );
+ }
+ }
+
+ // 30. enable all tu collected along with their parents, dependencies and children where necessary
+ while( !tu_to_enable.empty() ) {
+ std::pair<test_unit_id,bool> data = tu_to_enable.front();
+ test_unit const& tu = framework::get( data.first, tut_any );
+
+ tu_to_enable.pop_front();
+
+ if( tu.p_enabled )
+ continue;
+
+ // 31. enable tu
+ tu.p_enabled.value = true;
+
+ // 32. master test suite - we are done
+ if( tu.p_id == tu_id )
+ continue;
+
+ // 33. add parent to the list (without children)
+ if( !framework::get( tu.p_parent_id, tut_any ).p_enabled )
+ tu_to_enable.push_back( std::make_pair( tu.p_parent_id, false ) );
+
+ // 34. add dependencies to the list (with children)
+ BOOST_TEST_FOREACH( test_unit_id, dep_id, tu.p_dependencies.get() ) {
+ test_unit const& dep = framework::get( dep_id, tut_any );
+
+ if( !dep.p_enabled ) {
+ BOOST_TEST_MESSAGE( "Including test " << dep.p_type_name << ' ' << dep.p_name <<
+ " as a dependacy of test " << tu.p_type_name << ' ' << tu.p_name );
+
+ tu_to_enable.push_back( std::make_pair( dep_id, true ) );
+ }
+ }
+
+ // 35. add all children to the list recursively
+ if( data.second && tu.p_type == tut_suite ) {
+ class collect_disabled : public test_tree_visitor {
+ public:
+ explicit collect_disabled( ut_detail::tu_enable_list& tu_to_enable ) : m_tu_to_enable( tu_to_enable ) {}
+
+ private:
+ // test_tree_visitor interface
+ virtual bool visit( test_unit const& tu )
+ {
+ if( !tu.p_enabled )
+ m_tu_to_enable.push_back( std::make_pair( tu.p_id, false ) );
+
+ return true;
+ }
+
+ // Data members
+ ut_detail::tu_enable_list& m_tu_to_enable;
+ } V( tu_to_enable );
+
+ traverse_test_tree( tu.p_id, V, true );
+ }
+ }
+ }
+}
+
+//____________________________________________________________________________//
+
+} // namespace impl
+
+// ************************************************************************** //
+// ************** framework::init ************** //
+// ************************************************************************** //
+
 void
 init( init_unit_test_func init_func, int argc, char* argv[] )
 {
@@ -524,108 +626,54 @@
 
 //____________________________________________________________________________//
 
-namespace impl {
-void
-apply_filters( test_unit_id tu_id )
-{
- if( runtime_config::test_to_run().empty() ) {
- // enable all test units for this run
- ut_detail::change_status enabler( true );
- traverse_test_tree( tu_id, enabler, true );
- }
- else {
- // 10. First disable all test units. We'll re-enable only those that pass the filters
- ut_detail::change_status disabler( false );
- traverse_test_tree( tu_id, disabler, true );
-
- // 20. collect tu to enable based on filters
- ut_detail::tu_enable_list tu_to_enable;
-
- BOOST_TEST_FOREACH( std::string const&, filter, runtime_config::test_to_run() ) {
- if( filter.empty() )
- continue;
-
- if( filter[0] == '@' ) {
- ut_detail::label_filter lf( tu_to_enable, const_string(filter).trim_left(1) );
- traverse_test_tree( tu_id, lf, true );
- }
- else {
- ut_detail::name_filter nf( tu_to_enable, filter );
- traverse_test_tree( tu_id, nf, true );
- }
- }
-
- // 30. enable all tu collected along with their parents, dependencies and children where necessary
- while( !tu_to_enable.empty() ) {
- std::pair<test_unit_id,bool> data = tu_to_enable.front();
- test_unit const& tu = framework::get( data.first, tut_any );
-
- tu_to_enable.pop_front();
-
- if( tu.p_enabled )
- continue;
-
- // 31. enable tu
- tu.p_enabled.value = true;
-
- // 32. master test suite - we are done
- if( tu.p_id == tu_id )
- continue;
-
- // 33. add parent to the list (without children)
- if( !framework::get( tu.p_parent_id, tut_any ).p_enabled )
- tu_to_enable.push_back( std::make_pair( tu.p_parent_id, false ) );
-
- // 34. add dependencies to the list (with children)
- BOOST_TEST_FOREACH( test_unit_id, dep_id, tu.p_dependencies.get() ) {
- test_unit const& dep = framework::get( dep_id, tut_any );
-
- if( !dep.p_enabled ) {
- BOOST_TEST_MESSAGE( "Including test " << dep.p_type_name << ' ' << dep.p_name <<
- " as a dependacy of test " << tu.p_type_name << ' ' << tu.p_name );
-
- tu_to_enable.push_back( std::make_pair( dep_id, true ) );
- }
- }
-
- // 35. add all children to the list recursively
- if( data.second && tu.p_type == tut_suite ) {
- class collect_disabled : public test_tree_visitor {
- public:
- explicit collect_disabled( ut_detail::tu_enable_list& tu_to_enable ) : m_tu_to_enable( tu_to_enable ) {}
-
- private:
- // test_tree_visitor interface
- virtual bool visit( test_unit const& tu )
- {
- if( !tu.p_enabled )
- m_tu_to_enable.push_back( std::make_pair( tu.p_id, false ) );
+// ************************************************************************** //
+// ************** is_initialized ************** //
+// ************************************************************************** //
 
- return true;
- }
-
- // Data members
- ut_detail::tu_enable_list& m_tu_to_enable;
- } V( tu_to_enable );
-
- traverse_test_tree( tu.p_id, V, true );
- }
- }
- }
+bool
+is_initialized()
+{
+ return s_frk_impl().m_is_initialized;
 }
 
 //____________________________________________________________________________//
 
-} // namespace impl
+// ************************************************************************** //
+// ************** framework::shutdown ************** //
+// ************************************************************************** //
 
-bool
-is_initialized()
+void
+shutdown()
 {
- return s_frk_impl().m_is_initialized;
+ // eliminating some fake memory leak reports. See for more details:
+ // http://connect.microsoft.com/VisualStudio/feedback/details/106937/memory-leaks-reported-by-debug-crt-inside-typeinfo-name
+
+# if BOOST_WORKAROUND(BOOST_MSVC, <= 1600 ) && !defined(_DLL) && defined(_DEBUG)
+# if BOOST_WORKAROUND(BOOST_MSVC, < 1600 )
+#define _Next next
+#define _MemPtr memPtr
+#endif
+ __type_info_node* pNode = __type_info_root_node._Next;
+ __type_info_node* tmpNode = &__type_info_root_node;
+
+ for( ; pNode!=NULL; pNode = tmpNode ) {
+ tmpNode = pNode->_Next;
+ delete pNode->_MemPtr;
+ delete pNode;
+ }
+# if BOOST_WORKAROUND(BOOST_MSVC, < 1600 )
+#undef _Next
+#undef _MemPtr
+#endif
+# endif
 }
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** register_test_unit ************** //
+// ************************************************************************** //
+
 void
 register_test_unit( test_case* tc )
 {
@@ -645,6 +693,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** register_test_unit ************** //
+// ************************************************************************** //
+
 void
 register_test_unit( test_suite* ts )
 {
@@ -663,6 +715,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** deregister_test_unit ************** //
+// ************************************************************************** //
+
 void
 deregister_test_unit( test_unit* tu )
 {
@@ -671,6 +727,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** clear ************** //
+// ************************************************************************** //
+
 void
 clear()
 {
@@ -679,6 +739,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** register_observer ************** //
+// ************************************************************************** //
+
 void
 register_observer( test_observer& to )
 {
@@ -687,6 +751,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** deregister_observer ************** //
+// ************************************************************************** //
+
 void
 deregister_observer( test_observer& to )
 {
@@ -695,6 +763,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** reset_observer ************** //
+// ************************************************************************** //
+
 void
 reset_observers()
 {
@@ -703,6 +775,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** add_context ************** //
+// ************************************************************************** //
+
 int
 add_context( ::boost::unit_test::lazy_ostream const& context_descr, bool sticky )
 {
@@ -717,6 +793,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** clear_context ************** //
+// ************************************************************************** //
+
 struct frame_with_id {
     explicit frame_with_id( int id ) : m_id( id ) {}
 
@@ -747,6 +827,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** get_context ************** //
+// ************************************************************************** //
+
 context_generator
 get_context()
 {
@@ -755,6 +839,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** context_generator ************** //
+// ************************************************************************** //
+
 bool
 context_generator::is_empty() const
 {
@@ -771,6 +859,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** master_test_suite ************** //
+// ************************************************************************** //
+
 master_test_suite_t&
 master_test_suite()
 {
@@ -782,6 +874,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** current_test_case ************** //
+// ************************************************************************** //
+
 test_case const&
 current_test_case()
 {
@@ -790,6 +886,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** framework::get ************** //
+// ************************************************************************** //
+
 test_unit&
 get( test_unit_id id, test_unit_type t )
 {
@@ -803,6 +903,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** framework::run ************** //
+// ************************************************************************** //
+
 void
 run( test_unit_id id, bool continue_test )
 {
@@ -871,6 +975,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** assertion_result ************** //
+// ************************************************************************** //
+
 void
 assertion_result( bool passed )
 {
@@ -880,6 +988,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** exception_caught ************** //
+// ************************************************************************** //
+
 void
 exception_caught( execution_exception const& ex )
 {
@@ -889,6 +1001,10 @@
 
 //____________________________________________________________________________//
 
+// ************************************************************************** //
+// ************** test_unit_aborted ************** //
+// ************************************************************************** //
+
 void
 test_unit_aborted( test_unit const& tu )
 {

Modified: trunk/boost/test/impl/unit_test_main.ipp
==============================================================================
--- trunk/boost/test/impl/unit_test_main.ipp (original)
+++ trunk/boost/test/impl/unit_test_main.ipp 2011-10-16 01:12:00 EDT (Sun, 16 Oct 2011)
@@ -81,6 +81,8 @@
 int BOOST_TEST_DECL
 unit_test_main( init_unit_test_func init_func, int argc, char* argv[] )
 {
+ int result_code = 0;
+
     try {
         framework::init( init_func, argc, argv );
 
@@ -103,28 +105,32 @@
         
         results_reporter::make_report();
 
- return runtime_config::no_result_code()
- ? boost::exit_success
- : results_collector.results( framework::master_test_suite().p_id ).result_code();
+ result_code = runtime_config::no_result_code()
+ ? boost::exit_success
+ : results_collector.results( framework::master_test_suite().p_id ).result_code();
     }
     catch( framework::nothing_to_test const& ) {
- return boost::exit_success;
+ result_code = boost::exit_success;
     }
     catch( framework::internal_error const& ex ) {
         results_reporter::get_stream() << "Boost.Test framework internal error: " << ex.what() << std::endl;
         
- return boost::exit_exception_failure;
+ result_code = boost::exit_exception_failure;
     }
     catch( framework::setup_error const& ex ) {
         results_reporter::get_stream() << "Test setup error: " << ex.what() << std::endl;
         
- return boost::exit_exception_failure;
+ result_code = boost::exit_exception_failure;
     }
     catch( ... ) {
         results_reporter::get_stream() << "Boost.Test framework internal error: unknown reason" << std::endl;
         
- return boost::exit_exception_failure;
+ result_code = boost::exit_exception_failure;
     }
+
+ framework::shutdown();
+
+ return result_code;
 }
 
 } // namespace unit_test


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk