Ticket #7410: boost_test_test_unit_file_and_line.diff
File boost_test_test_unit_file_and_line.diff, 22.3 KB (added by , 10 years ago) |
---|
-
libs/test/test/test_tools_test.cpp
100 100 \ 101 101 BOOST_AUTO_TEST_CASE( name ) \ 102 102 { \ 103 test_case* impl = make_test_case( &name ## _impl, #name ); \ 103 test_case* impl = make_test_case( &name ## _impl, \ 104 #name, \ 105 __FILE__, \ 106 __LINE__ ); \ 104 107 \ 105 108 unit_test_log.set_stream( ots() ); \ 106 109 unit_test_log.set_threshold_level( log_nothing ); \ -
libs/test/test/test_tree_management_test.cpp
108 108 109 109 BOOST_CHECK_THROW( &framework::get( tc1->p_id, tut_suite ), framework::internal_error ); 110 110 111 test_case* tc2 = make_test_case( &empty, "my test case" );111 test_case* tc2 = make_test_case( &empty, "my test case", "test_file_name", 1 ); 112 112 BOOST_CHECK_EQUAL( tc2->p_name, const_string( "my test case" ) ); 113 BOOST_CHECK_EQUAL( tc2->p_file_name, const_string( "test_file_name" ) ); 114 BOOST_CHECK_EQUAL( tc2->p_line_num, 1 ); 113 115 } 114 116 115 117 //____________________________________________________________________________// … … 139 141 { 140 142 test_suite* ts1 = BOOST_TEST_SUITE( "TestSuite" ); 141 143 142 test_case* tc1 = make_test_case( &empty, "empty1" );144 std::size_t line_num = 1; 143 145 146 test_case* tc1 = make_test_case( &empty, "empty1", "file_name", line_num ); 147 144 148 ts1->add( tc1, 1, 10U ); 145 149 BOOST_CHECK_EQUAL( ts1->size(), 1U ); 146 150 … … 148 152 BOOST_CHECK_EQUAL( tc1->p_timeout, 10U ); 149 153 BOOST_CHECK_EQUAL( ts1->p_expected_failures, 1U ); 150 154 151 test_case* tc2 = make_test_case( &empty, "empty2" );155 test_case* tc2 = make_test_case( &empty, "empty2", "file_name", line_num ); 152 156 153 157 ts1->add( tc2, 2U ); 154 158 BOOST_CHECK_EQUAL( ts1->size(), 2U ); -
boost/test/tree/auto_registration.hpp
38 38 struct BOOST_TEST_DECL auto_test_unit_registrar { 39 39 // Constructors 40 40 auto_test_unit_registrar( test_case* tc, decorator::collector* decorators, counter_t exp_fail = 0 ); 41 explicit auto_test_unit_registrar( const_string ts_name, decorator::collector* decorators );41 explicit auto_test_unit_registrar( const_string ts_name, const_string ts_file, std::size_t ts_line, decorator::collector* decorators ); 42 42 explicit auto_test_unit_registrar( test_unit_generator const& tc_gen, decorator::collector* decorators ); 43 43 explicit auto_test_unit_registrar( int ); 44 44 -
boost/test/tree/test_case_template.hpp
64 64 65 65 template<typename Generator,typename TestCaseTemplate> 66 66 struct generate_test_case_4_type { 67 explicit generate_test_case_4_type( const_string tc_name, Generator& G )67 explicit generate_test_case_4_type( const_string tc_name, const_string tc_file, std::size_t tc_line, Generator& G ) 68 68 : m_test_case_name( tc_name ) 69 , m_test_case_file( tc_file ) 70 , m_test_case_line( tc_line ) 69 71 , m_holder( G ) 70 72 {} 71 73 … … 80 82 full_name += " const"; 81 83 full_name += '>'; 82 84 83 m_holder.m_test_cases.push_back( new test_case( full_name, test_case_template_invoker<TestCaseTemplate,TestType>() ) ); 85 m_holder.m_test_cases.push_back( new test_case( full_name, 86 m_test_case_file, 87 m_test_case_line, 88 test_case_template_invoker<TestCaseTemplate,TestType>() ) ); 84 89 } 85 90 86 91 private: 87 92 // Data members 88 93 const_string m_test_case_name; 94 const_string m_test_case_file; 95 std::size_t m_test_case_line; 89 96 Generator& m_holder; 90 97 }; 91 98 … … 97 104 class template_test_case_gen : public test_unit_generator { 98 105 public: 99 106 // Constructor 100 template_test_case_gen( const_string tc_name )107 template_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line ) 101 108 { 102 109 typedef generate_test_case_4_type<template_test_case_gen<TestCaseTemplate,TestTypesList>,TestCaseTemplate> single_test_gen; 103 110 104 mpl::for_each<TestTypesList,mpl::make_identity<mpl::_> >( single_test_gen( tc_name, *this ) );111 mpl::for_each<TestTypesList,mpl::make_identity<mpl::_> >( single_test_gen( tc_name, tc_file, tc_line, *this ) ); 105 112 } 106 113 107 114 virtual test_unit* next() const -
boost/test/tree/test_unit.hpp
49 49 typedef std::list<test_unit_fixture_ptr> fixture_list; 50 50 51 51 // Constructor 52 test_unit( const_string tu_name, test_unit_type t );52 test_unit( const_string tu_name, const_string tc_file, std::size_t tc_line, test_unit_type t ); 53 53 54 54 // dependencies management 55 55 void depends_on( test_unit* tu ); … … 70 70 71 71 readonly_property<test_unit_type> p_type; // type for this test unit 72 72 readonly_property<const_string> p_type_name; // "case"/"suite" 73 readonly_property<const_string> p_file_name; 74 readonly_property<std::size_t> p_line_num; 73 75 id_t p_id; // unique id for this test unit 74 76 parent_id_t p_parent_id; // parent test suite id 75 77 id_list_t p_dependencies; // list of test units this one depends on … … 112 114 enum { type = tut_case }; 113 115 114 116 // Constructor 115 test_case( const_string tc_name, boost::function<void ()> const& test_func );117 test_case( const_string tc_name, const_string tc_file, std::size_t tc_line, boost::function<void ()> const& test_func ); 116 118 117 119 // Public property 118 120 typedef BOOST_READONLY_PROPERTY(boost::function<void ()>,(test_case)) test_func; … … 133 135 enum { type = tut_suite }; 134 136 135 137 // Constructor 136 explicit test_suite( const_string ts_name );138 explicit test_suite( const_string ts_name, const_string ts_file, std::size_t ts_line ); 137 139 138 140 // test unit list management 139 141 void add( test_unit* tu, counter_t expected_failures = 0, unsigned timeout = 0 ); … … 160 162 161 163 class BOOST_TEST_DECL master_test_suite_t : public test_suite { 162 164 public: 163 master_test_suite_t() : test_suite( "Master Test Suite" )165 master_test_suite_t() : test_suite( "Master Test Suite", "", 0 ) 164 166 , argc( 0 ) 165 167 , argv( 0 ) 166 168 {} … … 200 202 // ************************************************************************** // 201 203 202 204 inline test_case* 203 make_test_case( boost::function<void ()> const& test_func, const_string tc_name )205 make_test_case( boost::function<void ()> const& test_func, const_string tc_name, const_string tc_file, std::size_t tc_line ) 204 206 { 205 return new test_case( ut_detail::normalize_test_case_name( tc_name ), t est_func );207 return new test_case( ut_detail::normalize_test_case_name( tc_name ), tc_name, tc_line, test_func ); 206 208 } 207 209 208 210 //____________________________________________________________________________// … … 211 213 inline test_case* 212 214 make_test_case( void (UserTestCase::* test_method )(), 213 215 const_string tc_name, 216 const_string tc_file, 217 std::size_t tc_line, 214 218 boost::shared_ptr<InstanceType> user_test_case ) 215 219 { 216 220 return new test_case( ut_detail::normalize_test_case_name( tc_name ), 221 tc_file, 222 tc_line, 217 223 ut_detail::user_tc_method_invoker<InstanceType,UserTestCase>( user_test_case, test_method ) ); 218 224 } 219 225 -
boost/test/impl/xml_log_formatter.ipp
80 80 void 81 81 xml_log_formatter::test_unit_start( std::ostream& ostr, test_unit const& tu ) 82 82 { 83 ostr << "<" << tu_type_name( tu ) << " name" << attr_value() << tu.p_name.get() << ">"; 83 ostr << "<" << tu_type_name( tu ) << " name" << attr_value() << tu.p_name.get(); 84 85 if( !tu.p_file_name.get().empty() ) 86 { 87 ostr << BOOST_TEST_L( " file" ) << attr_value() << tu.p_file_name 88 << BOOST_TEST_L( " line" ) << attr_value() << tu.p_line_num; 89 } 90 ostr << ">"; 84 91 } 85 92 86 93 //____________________________________________________________________________// -
boost/test/impl/test_tree.ipp
54 54 // ************** test_unit ************** // 55 55 // ************************************************************************** // 56 56 57 test_unit::test_unit( const_string name, test_unit_type t )57 test_unit::test_unit( const_string name, const_string file_name, std::size_t line_num, test_unit_type t ) 58 58 : p_type( t ) 59 59 , p_type_name( t == tut_case ? "case" : "suite" ) 60 , p_file_name( file_name ) 61 , p_line_num( line_num ) 60 62 , p_id( INV_TEST_UNIT_ID ) 61 63 , p_name( std::string( name.begin(), name.size() ) ) 62 64 , p_enabled( true ) … … 126 128 // ************** test_case ************** // 127 129 // ************************************************************************** // 128 130 129 test_case::test_case( const_string name, boost::function<void ()> const& test_func )130 : test_unit( name, static_cast<test_unit_type>(type) )131 test_case::test_case( const_string name, const_string file_name, std::size_t line_num, boost::function<void ()> const& test_func ) 132 : test_unit( name, file_name, line_num, static_cast<test_unit_type>(type) ) 131 133 , p_test_func( test_func ) 132 134 { 133 135 framework::register_test_unit( this ); … … 141 143 142 144 //____________________________________________________________________________// 143 145 144 test_suite::test_suite( const_string name )145 : test_unit( name, static_cast<test_unit_type>(type) )146 test_suite::test_suite( const_string name, const_string file_name, std::size_t line_num ) 147 : test_unit( name, file_name, line_num, static_cast<test_unit_type>(type) ) 146 148 { 147 149 framework::register_test_unit( this ); 148 150 } … … 292 294 293 295 //____________________________________________________________________________// 294 296 295 auto_test_unit_registrar::auto_test_unit_registrar( const_string ts_name, decorator::collector* decorators )297 auto_test_unit_registrar::auto_test_unit_registrar( const_string ts_name, const_string ts_file, std::size_t ts_line, decorator::collector* decorators ) 296 298 { 297 299 test_unit_id id = curr_ts_store().back()->get( ts_name ); 298 300 … … 303 305 BOOST_ASSERT( ts->p_parent_id == curr_ts_store().back()->p_id ); 304 306 } 305 307 else { 306 ts = new test_suite( ts_name );308 ts = new test_suite( ts_name, ts_file, ts_line ); 307 309 curr_ts_store().back()->add( ts ); 308 310 } 309 311 -
boost/test/impl/compiler_log_formatter.ipp
93 93 { 94 94 BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BRIGHT, term_color::BLUE ); 95 95 96 print_prefix( output, tu.p_file_name, tu.p_line_num ); 96 97 output << "Entering test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl; 97 98 } 98 99 … … 230 231 //____________________________________________________________________________// 231 232 232 233 void 233 compiler_log_formatter::print_prefix( std::ostream& output, const_string file , std::size_t line)234 compiler_log_formatter::print_prefix( std::ostream& output, const_string file_name, std::size_t line_num ) 234 235 { 236 if( !file_name.empty() ) 237 { 235 238 #ifdef __APPLE_CC__ 236 // Xcode-compatible logging format, idea by Richard Dingwall at237 // <http://richarddingwall.name/2008/06/01/using-the-boost-unit-test-framework-with-xcode-3/>.238 output << file << ':' << line<< ": ";239 // Xcode-compatible logging format, idea by Richard Dingwall at 240 // <http://richarddingwall.name/2008/06/01/using-the-boost-unit-test-framework-with-xcode-3/>. 241 output << file_name << ':' << line_num << ": "; 239 242 #else 240 output << file << '(' << line<< "): ";243 output << file_name << '(' << line_num << "): "; 241 244 #endif 245 } 242 246 } 243 247 244 248 //____________________________________________________________________________// -
boost/test/unit_test_suite.hpp
27 27 // ************** Non-auto (explicit) test case interface ************** // 28 28 // ************************************************************************** // 29 29 30 #define BOOST_TEST_CASE( test_function ) \ 31 boost::unit_test::make_test_case( boost::function<void ()>(test_function), BOOST_TEST_STRINGIZE( test_function ) ) 32 #define BOOST_CLASS_TEST_CASE( test_function, tc_instance ) \ 33 boost::unit_test::make_test_case((test_function), BOOST_TEST_STRINGIZE( test_function ), tc_instance ) 30 #define BOOST_TEST_CASE( test_function ) \ 31 boost::unit_test::make_test_case( boost::function<void ()>(test_function), \ 32 BOOST_TEST_STRINGIZE( test_function ), \ 33 __FILE__, __LINE__ ) 34 #define BOOST_CLASS_TEST_CASE( test_function, tc_instance ) \ 35 boost::unit_test::make_test_case( (test_function), \ 36 BOOST_TEST_STRINGIZE( test_function ), \ 37 __FILE__, __LINE__, tc_instance ) 34 38 35 39 // ************************************************************************** // 36 40 // ************** BOOST_TEST_SUITE ************** // 37 41 // ************************************************************************** // 38 42 39 43 #define BOOST_TEST_SUITE( testsuite_name ) \ 40 ( new boost::unit_test::test_suite( testsuite_name ) )44 ( new boost::unit_test::test_suite( testsuite_name, __FILE__, __LINE__ ) ) 41 45 42 46 // ************************************************************************** // 43 47 // ************** BOOST_AUTO_TEST_SUITE ************** // … … 47 51 namespace suite_name { \ 48 52 BOOST_AUTO_TU_REGISTRAR( suite_name )( \ 49 53 BOOST_STRINGIZE( suite_name ), \ 54 __FILE__, __LINE__, \ 50 55 boost::unit_test::decorator::collector::instance() ); \ 51 56 /**/ 52 57 … … 97 102 \ 98 103 BOOST_AUTO_TU_REGISTRAR( test_name )( \ 99 104 boost::unit_test::make_test_case( \ 100 &BOOST_AUTO_TC_INVOKER( test_name ), #test_name ), \ 105 &BOOST_AUTO_TC_INVOKER( test_name ), \ 106 #test_name, __FILE__, __LINE__ ), \ 101 107 boost::unit_test::decorator::collector::instance() ); \ 102 108 \ 103 109 void test_name::test_method() \ … … 135 141 BOOST_AUTO_TU_REGISTRAR( test_name )( \ 136 142 boost::unit_test::ut_detail::template_test_case_gen< \ 137 143 BOOST_AUTO_TC_INVOKER( test_name ),TL >( \ 138 BOOST_STRINGIZE( test_name ) ),\144 BOOST_STRINGIZE( test_name ), __FILE__, __LINE__ ), \ 139 145 boost::unit_test::decorator::collector::instance() ); \ 140 146 \ 141 147 template<typename type_name> \ … … 155 161 156 162 #define BOOST_TEST_CASE_TEMPLATE( name, typelist ) \ 157 163 boost::unit_test::ut_detail::template_test_case_gen<name,typelist >(\ 158 BOOST_TEST_STRINGIZE( name ) )\164 BOOST_TEST_STRINGIZE( name ), __FILE__, __LINE__ ) \ 159 165 /**/ 160 166 161 167 // ************************************************************************** // -
boost/test/parameterized_test.hpp
32 32 #define BOOST_PARAM_TEST_CASE( function, begin, end ) \ 33 33 boost::unit_test::make_test_case( function, \ 34 34 BOOST_TEST_STRINGIZE( function ), \ 35 __FILE__, __LINE__, \ 35 36 (begin), (end) ) \ 36 37 /**/ 37 38 38 39 #define BOOST_PARAM_CLASS_TEST_CASE( function, tc_instance, begin, end ) \ 39 40 boost::unit_test::make_test_case( function, \ 40 41 BOOST_TEST_STRINGIZE( function ), \ 42 __FILE__, __LINE__, \ 41 43 (tc_instance), \ 42 44 (begin), (end) ) \ 43 45 /**/ … … 56 58 public: 57 59 param_test_case_generator( boost::function<void (ParamType)> const& test_func, 58 60 const_string tc_name, 61 const_string tc_file, 62 std::size_t tc_line, 59 63 ParamIter par_begin, 60 64 ParamIter par_end ) 61 65 : m_test_func( test_func ) 62 66 , m_tc_name( ut_detail::normalize_test_case_name( tc_name ) ) 67 , m_tc_file( tc_file ) 68 , m_tc_line( tc_line ) 63 69 , m_par_begin( par_begin ) 64 70 , m_par_end( par_end ) 65 71 {} … … 69 75 if( m_par_begin == m_par_end ) 70 76 return (test_unit*)0; 71 77 72 test_unit* res = new test_case( m_tc_name, boost::bind( m_test_func, *m_par_begin ) );78 test_unit* res = new test_case( m_tc_name, m_tc_file, m_tc_line, boost::bind( m_test_func, *m_par_begin ) ); 73 79 74 80 ++m_par_begin; 75 81 … … 80 86 // Data members 81 87 boost::function<void (ParamType)> m_test_func; 82 88 std::string m_tc_name; 89 const_string m_tc_file; 90 std::size_t m_tc_line; 83 91 mutable ParamIter m_par_begin; 84 92 ParamIter m_par_end; 85 93 }; … … 109 117 inline ut_detail::param_test_case_generator<ParamType,ParamIter> 110 118 make_test_case( boost::function<void (ParamType)> const& test_func, 111 119 const_string tc_name, 120 const_string tc_file, 121 std::size_t tc_line, 112 122 ParamIter par_begin, 113 123 ParamIter par_end ) 114 124 { 115 return ut_detail::param_test_case_generator<ParamType,ParamIter>( test_func, tc_name, par_begin, par_end );125 return ut_detail::param_test_case_generator<ParamType,ParamIter>( test_func, tc_name, tc_file, tc_line, par_begin, par_end ); 116 126 } 117 127 118 128 //____________________________________________________________________________// … … 122 132 BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type,ParamIter> 123 133 make_test_case( void (*test_func)( ParamType ), 124 134 const_string tc_name, 135 const_string tc_file, 136 std::size_t tc_line, 125 137 ParamIter par_begin, 126 138 ParamIter par_end ) 127 139 { 128 140 typedef BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type param_value_type; 129 return ut_detail::param_test_case_generator<param_value_type,ParamIter>( test_func, tc_name, par_begin, par_end );141 return ut_detail::param_test_case_generator<param_value_type,ParamIter>( test_func, tc_name, tc_file, tc_line, par_begin, par_end ); 130 142 } 131 143 132 144 //____________________________________________________________________________// … … 136 148 BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type,ParamIter> 137 149 make_test_case( void (UserTestCase::*test_method )( ParamType ), 138 150 const_string tc_name, 151 const_string tc_file, 152 std::size_t tc_line, 139 153 boost::shared_ptr<UserTestCase> const& user_test_case, 140 154 ParamIter par_begin, 141 155 ParamIter par_end ) … … 144 158 return ut_detail::param_test_case_generator<param_value_type,ParamIter>( 145 159 ut_detail::user_param_tc_method_invoker<UserTestCase,ParamType>( user_test_case, test_method ), 146 160 tc_name, 161 tc_file, 162 tc_line, 147 163 par_begin, 148 164 par_end ); 149 165 }