Ticket #7410: boost_test_test_unit_file_and_line.diff

File boost_test_test_unit_file_and_line.diff, 22.3 KB (added by Jamie Allsop <ja11sop@…>, 10 years ago)

boost_test_test_unit_file_and_line.diff

  • libs/test/test/test_tools_test.cpp

     
    100100                                                            \
    101101BOOST_AUTO_TEST_CASE( name )                                \
    102102{                                                           \
    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__ );           \
    104107                                                            \
    105108    unit_test_log.set_stream( ots() );                      \
    106109    unit_test_log.set_threshold_level( log_nothing );       \
  • libs/test/test/test_tree_management_test.cpp

     
    108108
    109109    BOOST_CHECK_THROW( &framework::get( tc1->p_id, tut_suite ), framework::internal_error );
    110110
    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 );
    112112    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 );
    113115}
    114116
    115117//____________________________________________________________________________//
     
    139141{
    140142    test_suite* ts1 = BOOST_TEST_SUITE( "TestSuite" );
    141143
    142     test_case* tc1 = make_test_case( &empty, "empty1" );
     144    std::size_t line_num = 1;
    143145
     146    test_case* tc1 = make_test_case( &empty, "empty1", "file_name", line_num );
     147
    144148    ts1->add( tc1, 1, 10U );
    145149    BOOST_CHECK_EQUAL( ts1->size(), 1U );
    146150
     
    148152    BOOST_CHECK_EQUAL( tc1->p_timeout, 10U );
    149153    BOOST_CHECK_EQUAL( ts1->p_expected_failures, 1U );
    150154
    151     test_case* tc2 = make_test_case( &empty, "empty2" );
     155    test_case* tc2 = make_test_case( &empty, "empty2", "file_name", line_num );
    152156
    153157    ts1->add( tc2, 2U );
    154158    BOOST_CHECK_EQUAL( ts1->size(), 2U );
  • boost/test/tree/auto_registration.hpp

     
    3838struct BOOST_TEST_DECL auto_test_unit_registrar {
    3939    // Constructors
    4040                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 );
    4242    explicit    auto_test_unit_registrar( test_unit_generator const& tc_gen, decorator::collector* decorators );
    4343    explicit    auto_test_unit_registrar( int );
    4444
  • boost/test/tree/test_case_template.hpp

     
    6464
    6565template<typename Generator,typename TestCaseTemplate>
    6666struct 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 )
    6868    : m_test_case_name( tc_name )
     69    , m_test_case_file( tc_file )
     70    , m_test_case_line( tc_line )
    6971    , m_holder( G )
    7072    {}
    7173
     
    8082            full_name += " const";
    8183        full_name += '>';
    8284
    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>() ) );
    8489    }
    8590
    8691private:
    8792    // Data members
    8893    const_string    m_test_case_name;
     94    const_string    m_test_case_file;
     95    std::size_t     m_test_case_line;
    8996    Generator&      m_holder;
    9097};
    9198
     
    97104class template_test_case_gen : public test_unit_generator {
    98105public:
    99106    // 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 )
    101108    {
    102109        typedef generate_test_case_4_type<template_test_case_gen<TestCaseTemplate,TestTypesList>,TestCaseTemplate> single_test_gen;
    103110
    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 ) );
    105112    }
    106113
    107114    virtual test_unit* next() const
  • boost/test/tree/test_unit.hpp

     
    4949    typedef std::list<test_unit_fixture_ptr>    fixture_list;
    5050
    5151    // 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 );
    5353
    5454    // dependencies management
    5555    void    depends_on( test_unit* tu );
     
    7070
    7171    readonly_property<test_unit_type>   p_type;                 // type for this test unit
    7272    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;
    7375    id_t                                p_id;                   // unique id for this test unit
    7476    parent_id_t                         p_parent_id;            // parent test suite id
    7577    id_list_t                           p_dependencies;         // list of test units this one depends on
     
    112114    enum { type = tut_case };
    113115
    114116    // 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 );
    116118
    117119    // Public property
    118120    typedef BOOST_READONLY_PROPERTY(boost::function<void ()>,(test_case))  test_func;
     
    133135    enum { type = tut_suite };
    134136
    135137    // 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 );
    137139
    138140    // test unit list management
    139141    void            add( test_unit* tu, counter_t expected_failures = 0, unsigned timeout = 0 );
     
    160162
    161163class BOOST_TEST_DECL master_test_suite_t : public test_suite {
    162164public:
    163     master_test_suite_t() : test_suite( "Master Test Suite" )
     165    master_test_suite_t() : test_suite( "Master Test Suite", "", 0 )
    164166    , argc( 0 )
    165167    , argv( 0 )
    166168    {}
     
    200202// ************************************************************************** //
    201203
    202204inline test_case*
    203 make_test_case( boost::function<void ()> const& test_func, const_string tc_name )
     205make_test_case( boost::function<void ()> const& test_func, const_string tc_name, const_string tc_file, std::size_t tc_line )
    204206{
    205     return new test_case( ut_detail::normalize_test_case_name( tc_name ), test_func );
     207    return new test_case( ut_detail::normalize_test_case_name( tc_name ), tc_name, tc_line, test_func );
    206208}
    207209
    208210//____________________________________________________________________________//
     
    211213inline test_case*
    212214make_test_case( void (UserTestCase::*           test_method )(),
    213215                const_string                    tc_name,
     216                const_string                    tc_file,
     217                std::size_t                     tc_line,
    214218                boost::shared_ptr<InstanceType> user_test_case )
    215219{
    216220    return new test_case( ut_detail::normalize_test_case_name( tc_name ),
     221                          tc_file,
     222                          tc_line,
    217223                          ut_detail::user_tc_method_invoker<InstanceType,UserTestCase>( user_test_case, test_method ) );
    218224}
    219225
  • boost/test/impl/xml_log_formatter.ipp

     
    8080void
    8181xml_log_formatter::test_unit_start( std::ostream& ostr, test_unit const& tu )
    8282{
    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 << ">";
    8491}
    8592
    8693//____________________________________________________________________________//
  • boost/test/impl/test_tree.ipp

     
    5454// **************                   test_unit                  ************** //
    5555// ************************************************************************** //
    5656
    57 test_unit::test_unit( const_string name, test_unit_type t )
     57test_unit::test_unit( const_string name, const_string file_name, std::size_t line_num, test_unit_type t )
    5858: p_type( t )
    5959, p_type_name( t == tut_case ? "case" : "suite" )
     60, p_file_name( file_name )
     61, p_line_num( line_num )
    6062, p_id( INV_TEST_UNIT_ID )
    6163, p_name( std::string( name.begin(), name.size() ) )
    6264, p_enabled( true )
     
    126128// **************                   test_case                  ************** //
    127129// ************************************************************************** //
    128130
    129 test_case::test_case( const_string name, boost::function<void ()> const& test_func )
    130 : test_unit( name, static_cast<test_unit_type>(type) )
     131test_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) )
    131133, p_test_func( test_func )
    132134{
    133135    framework::register_test_unit( this );
     
    141143
    142144//____________________________________________________________________________//
    143145
    144 test_suite::test_suite( const_string name )
    145 : test_unit( name, static_cast<test_unit_type>(type) )
     146test_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) )
    146148{
    147149    framework::register_test_unit( this );
    148150}
     
    292294
    293295//____________________________________________________________________________//
    294296
    295 auto_test_unit_registrar::auto_test_unit_registrar( const_string ts_name, decorator::collector* decorators )
     297auto_test_unit_registrar::auto_test_unit_registrar( const_string ts_name, const_string ts_file, std::size_t ts_line, decorator::collector* decorators )
    296298{
    297299    test_unit_id id = curr_ts_store().back()->get( ts_name );
    298300
     
    303305        BOOST_ASSERT( ts->p_parent_id == curr_ts_store().back()->p_id );
    304306    }
    305307    else {
    306         ts = new test_suite( ts_name );
     308        ts = new test_suite( ts_name, ts_file, ts_line );
    307309        curr_ts_store().back()->add( ts );
    308310    }
    309311
  • boost/test/impl/compiler_log_formatter.ipp

     
    9393{
    9494    BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BRIGHT, term_color::BLUE );
    9595
     96    print_prefix( output, tu.p_file_name, tu.p_line_num );
    9697    output << "Entering test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
    9798}
    9899
     
    230231//____________________________________________________________________________//
    231232
    232233void
    233 compiler_log_formatter::print_prefix( std::ostream& output, const_string file, std::size_t line )
     234compiler_log_formatter::print_prefix( std::ostream& output, const_string file_name, std::size_t line_num )
    234235{
     236    if( !file_name.empty() )
     237    {
    235238#ifdef __APPLE_CC__
    236     // Xcode-compatible logging format, idea by Richard Dingwall at
    237     // <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 << ": ";
    239242#else
    240     output << file << '(' << line << "): ";
     243        output << file_name << '(' << line_num << "): ";
    241244#endif
     245    }
    242246}
    243247
    244248//____________________________________________________________________________//
  • boost/test/unit_test_suite.hpp

     
    2727// **************    Non-auto (explicit) test case interface   ************** //
    2828// ************************************************************************** //
    2929
    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 )                                   \
     31boost::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 )                \
     35boost::unit_test::make_test_case( (test_function),                         \
     36                                  BOOST_TEST_STRINGIZE( test_function ),   \
     37                                  __FILE__, __LINE__, tc_instance )
    3438
    3539// ************************************************************************** //
    3640// **************               BOOST_TEST_SUITE               ************** //
    3741// ************************************************************************** //
    3842
    3943#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__ ) )
    4145
    4246// ************************************************************************** //
    4347// **************             BOOST_AUTO_TEST_SUITE            ************** //
     
    4751namespace suite_name {                                                  \
    4852BOOST_AUTO_TU_REGISTRAR( suite_name )(                                  \
    4953    BOOST_STRINGIZE( suite_name ),                                      \
     54    __FILE__, __LINE__,                                                 \
    5055    boost::unit_test::decorator::collector::instance() );               \
    5156/**/
    5257
     
    97102                                                                        \
    98103BOOST_AUTO_TU_REGISTRAR( test_name )(                                   \
    99104    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__ ),                               \
    101107    boost::unit_test::decorator::collector::instance() );               \
    102108                                                                        \
    103109void test_name::test_method()                                           \
     
    135141BOOST_AUTO_TU_REGISTRAR( test_name )(                                   \
    136142    boost::unit_test::ut_detail::template_test_case_gen<                \
    137143        BOOST_AUTO_TC_INVOKER( test_name ),TL >(                        \
    138           BOOST_STRINGIZE( test_name ) ),                               \
     144          BOOST_STRINGIZE( test_name ), __FILE__, __LINE__ ),           \
    139145    boost::unit_test::decorator::collector::instance() );               \
    140146                                                                        \
    141147template<typename type_name>                                            \
     
    155161
    156162#define BOOST_TEST_CASE_TEMPLATE( name, typelist )                      \
    157163    boost::unit_test::ut_detail::template_test_case_gen<name,typelist >(\
    158         BOOST_TEST_STRINGIZE( name ) )                                  \
     164        BOOST_TEST_STRINGIZE( name ), __FILE__, __LINE__  )             \
    159165/**/
    160166
    161167// ************************************************************************** //
  • boost/test/parameterized_test.hpp

     
    3232#define BOOST_PARAM_TEST_CASE( function, begin, end )                      \
    3333boost::unit_test::make_test_case( function,                                \
    3434                                  BOOST_TEST_STRINGIZE( function ),        \
     35                                  __FILE__, __LINE__,                      \
    3536                                  (begin), (end) )                         \
    3637/**/
    3738
    3839#define BOOST_PARAM_CLASS_TEST_CASE( function, tc_instance, begin, end )   \
    3940boost::unit_test::make_test_case( function,                                \
    4041                                  BOOST_TEST_STRINGIZE( function ),        \
     42                                  __FILE__, __LINE__,                      \
    4143                                  (tc_instance),                           \
    4244                                  (begin), (end) )                         \
    4345/**/
     
    5658public:
    5759    param_test_case_generator( boost::function<void (ParamType)> const& test_func,
    5860                               const_string                             tc_name,
     61                               const_string                             tc_file,
     62                               std::size_t                              tc_line,
    5963                               ParamIter                                par_begin,
    6064                               ParamIter                                par_end )
    6165    : m_test_func( test_func )
    6266    , m_tc_name( ut_detail::normalize_test_case_name( tc_name ) )
     67    , m_tc_file( tc_file )
     68    , m_tc_line( tc_line )
    6369    , m_par_begin( par_begin )
    6470    , m_par_end( par_end )
    6571    {}
     
    6975        if( m_par_begin == m_par_end )
    7076            return (test_unit*)0;
    7177
    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 ) );
    7379
    7480        ++m_par_begin;
    7581
     
    8086    // Data members
    8187    boost::function<void (ParamType)>    m_test_func;
    8288    std::string             m_tc_name;
     89    const_string            m_tc_file;
     90    std::size_t             m_tc_line;
    8391    mutable ParamIter       m_par_begin;
    8492    ParamIter               m_par_end;
    8593};
     
    109117inline ut_detail::param_test_case_generator<ParamType,ParamIter>
    110118make_test_case( boost::function<void (ParamType)> const& test_func,
    111119                const_string                             tc_name,
     120                const_string                             tc_file,
     121                std::size_t                              tc_line,
    112122                ParamIter                                par_begin,
    113123                ParamIter                                par_end )
    114124{
    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 );
    116126}
    117127
    118128//____________________________________________________________________________//
     
    122132    BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type,ParamIter>
    123133make_test_case( void (*test_func)( ParamType ),
    124134                const_string  tc_name,
     135                const_string  tc_file,
     136                std::size_t   tc_line,
    125137                ParamIter     par_begin,
    126138                ParamIter     par_end )
    127139{
    128140    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 );
    130142}
    131143
    132144//____________________________________________________________________________//
     
    136148    BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type,ParamIter>
    137149make_test_case( void (UserTestCase::*test_method )( ParamType ),
    138150                const_string                           tc_name,
     151                const_string                           tc_file,
     152                std::size_t                            tc_line,
    139153                boost::shared_ptr<UserTestCase> const& user_test_case,
    140154                ParamIter                              par_begin,
    141155                ParamIter                              par_end )
     
    144158    return ut_detail::param_test_case_generator<param_value_type,ParamIter>(
    145159               ut_detail::user_param_tc_method_invoker<UserTestCase,ParamType>( user_test_case, test_method ),
    146160               tc_name,
     161               tc_file,
     162               tc_line,
    147163               par_begin,
    148164               par_end );
    149165}