|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r81198 - in trunk/boost/test: . data impl interaction tree
From: gennadiy.rozental_at_[hidden]
Date: 2012-11-05 06:29:41
Author: rogeeff
Date: 2012-11-05 06:29:39 EST (Mon, 05 Nov 2012)
New Revision: 81198
URL: http://svn.boost.org/trac/boost/changeset/81198
Log:
New feature: location of test cases and test suites is registered and reported to improve integration with 3rd party runners
Text files modified:
trunk/boost/test/data/test_case.hpp | 14 +++++++++-----
trunk/boost/test/impl/compiler_log_formatter.ipp | 18 ++++++++++++------
trunk/boost/test/impl/test_tree.ipp | 16 +++++++++-------
trunk/boost/test/impl/xml_log_formatter.ipp | 8 +++++++-
trunk/boost/test/interaction/exception_safety.hpp | 3 ++-
trunk/boost/test/interaction/logged_expectations.hpp | 3 ++-
trunk/boost/test/parameterized_test.hpp | 30 +++++++++++++++++++++++-------
trunk/boost/test/tree/auto_registration.hpp | 2 +-
trunk/boost/test/tree/test_case_template.hpp | 15 +++++++++++----
trunk/boost/test/tree/test_unit.hpp | 18 ++++++++++++------
trunk/boost/test/unit_test_suite.hpp | 22 ++++++++++++++--------
11 files changed, 102 insertions(+), 47 deletions(-)
Modified: trunk/boost/test/data/test_case.hpp
==============================================================================
--- trunk/boost/test/data/test_case.hpp (original)
+++ trunk/boost/test/data/test_case.hpp 2012-11-05 06:29:39 EST (Mon, 05 Nov 2012)
@@ -51,7 +51,7 @@
class test_case_gen : public test_unit_generator {
public:
// Constructor
- test_case_gen( const_string tc_name, DS&& ds )
+ test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line, DS&& ds )
: m_tc_name( ut_detail::normalize_test_case_name( tc_name ) )
{
data::for_each_sample( ds, *this );
@@ -77,7 +77,7 @@
template<BOOST_PP_ENUM_PARAMS(arity, typename Arg)> \
void operator()( BOOST_PP_ENUM_BINARY_PARAMS(arity, Arg, const& arg) ) const \
{ \
- m_test_cases.push_back( new test_case( m_tc_name, \
+ m_test_cases.push_back( new test_case( m_tc_name, m_tc_file, m_tc_line, \
std::bind( &TestCase::template test_method<BOOST_PP_ENUM_PARAMS(arity,Arg)>, \
BOOST_PP_ENUM_PARAMS(arity, arg) ) ) ); \
} \
@@ -87,6 +87,8 @@
private:
// Data members
std::string m_tc_name;
+ const_string m_tc_file;
+ std::size_t m_tc_line;
mutable std::list<test_unit*> m_test_cases;
};
@@ -94,9 +96,9 @@
template<typename TestCase,typename DS>
test_case_gen<TestCase,DS>
-make_test_case_gen( const_string tc_name, DS&& ds )
+make_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line, DS&& ds )
{
- return test_case_gen<TestCase,DS>( tc_name, std::forward<DS>(ds) );
+ return test_case_gen<TestCase,DS>( tc_name, tc_file, tc_line, std::forward<DS>(ds) );
}
//____________________________________________________________________________//
@@ -131,7 +133,9 @@
\
BOOST_AUTO_TU_REGISTRAR( test_name )( \
boost::unit_test::data::ds_detail::make_test_case_gen<test_name>( \
- BOOST_STRINGIZE( test_name ), data::make(dataset) ), \
+ BOOST_STRINGIZE( test_name ), \
+ __FILE__, __LINE__, \
+ data::make(dataset) ), \
boost::unit_test::decorator::collector::instance() ); \
\
template<BOOST_PP_ENUM_PARAMS(arity, typename Arg)> \
Modified: trunk/boost/test/impl/compiler_log_formatter.ipp
==============================================================================
--- trunk/boost/test/impl/compiler_log_formatter.ipp (original)
+++ trunk/boost/test/impl/compiler_log_formatter.ipp 2012-11-05 06:29:39 EST (Mon, 05 Nov 2012)
@@ -93,7 +93,10 @@
{
BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BRIGHT, term_color::BLUE );
- output << "Entering test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
+ print_prefix( output, tu.p_file_name, tu.p_line_num );
+
+ const_string type = tu.p_parent_id == 0 ? BOOST_TEST_L("module") : tu.p_type_name;
+ output << "Entering test " << type << " \"" << tu.p_name << "\"" << std::endl;
}
//____________________________________________________________________________//
@@ -230,15 +233,18 @@
//____________________________________________________________________________//
void
-compiler_log_formatter::print_prefix( std::ostream& output, const_string file, std::size_t line )
+compiler_log_formatter::print_prefix( std::ostream& output, const_string file_name, std::size_t line_num )
{
+ if( !file_name.empty() )
+ {
#ifdef __APPLE_CC__
- // Xcode-compatible logging format, idea by Richard Dingwall at
- // <http://richarddingwall.name/2008/06/01/using-the-boost-unit-test-framework-with-xcode-3/>.
- output << file << ':' << line << ": ";
+ // Xcode-compatible logging format, idea by Richard Dingwall at
+ // <http://richarddingwall.name/2008/06/01/using-the-boost-unit-test-framework-with-xcode-3/>.
+ output << file_name << ':' << line_num << ": ";
#else
- output << file << '(' << line << "): ";
+ output << file_name << '(' << line_num << "): ";
#endif
+ }
}
//____________________________________________________________________________//
Modified: trunk/boost/test/impl/test_tree.ipp
==============================================================================
--- trunk/boost/test/impl/test_tree.ipp (original)
+++ trunk/boost/test/impl/test_tree.ipp 2012-11-05 06:29:39 EST (Mon, 05 Nov 2012)
@@ -54,9 +54,11 @@
// ************** test_unit ************** //
// ************************************************************************** //
-test_unit::test_unit( const_string name, test_unit_type t )
+test_unit::test_unit( const_string name, const_string file_name, std::size_t line_num, test_unit_type t )
: p_type( t )
, p_type_name( t == tut_case ? "case" : "suite" )
+, p_file_name( file_name )
+, p_line_num( line_num )
, p_id( INV_TEST_UNIT_ID )
, p_name( std::string( name.begin(), name.size() ) )
, p_enabled( true )
@@ -126,8 +128,8 @@
// ************** test_case ************** //
// ************************************************************************** //
-test_case::test_case( const_string name, boost::function<void ()> const& test_func )
-: test_unit( name, static_cast<test_unit_type>(type) )
+test_case::test_case( const_string name, const_string file_name, std::size_t line_num, boost::function<void ()> const& test_func )
+: test_unit( name, file_name, line_num, static_cast<test_unit_type>(type) )
, p_test_func( test_func )
{
framework::register_test_unit( this );
@@ -141,8 +143,8 @@
//____________________________________________________________________________//
-test_suite::test_suite( const_string name )
-: test_unit( name, static_cast<test_unit_type>(type) )
+test_suite::test_suite( const_string name, const_string file_name, std::size_t line_num )
+: test_unit( name, file_name, line_num, static_cast<test_unit_type>(type) )
{
framework::register_test_unit( this );
}
@@ -292,7 +294,7 @@
//____________________________________________________________________________//
-auto_test_unit_registrar::auto_test_unit_registrar( const_string ts_name, decorator::collector* decorators )
+auto_test_unit_registrar::auto_test_unit_registrar( const_string ts_name, const_string ts_file, std::size_t ts_line, decorator::collector* decorators )
{
test_unit_id id = framework::current_auto_test_suite().get( ts_name );
@@ -303,7 +305,7 @@
BOOST_ASSERT( ts->p_parent_id == framework::current_auto_test_suite().p_id );
}
else {
- ts = new test_suite( ts_name );
+ ts = new test_suite( ts_name, ts_file, ts_line );
framework::current_auto_test_suite().add( ts );
}
Modified: trunk/boost/test/impl/xml_log_formatter.ipp
==============================================================================
--- trunk/boost/test/impl/xml_log_formatter.ipp (original)
+++ trunk/boost/test/impl/xml_log_formatter.ipp 2012-11-05 06:29:39 EST (Mon, 05 Nov 2012)
@@ -80,7 +80,13 @@
void
xml_log_formatter::test_unit_start( std::ostream& ostr, test_unit const& tu )
{
- ostr << "<" << tu_type_name( tu ) << " name" << attr_value() << tu.p_name.get() << ">";
+ ostr << "<" << tu_type_name( tu ) << " name" << attr_value() << tu.p_name.get();
+
+ if( !tu.p_file_name.get().empty() )
+ ostr << BOOST_TEST_L( " file" ) << attr_value() << tu.p_file_name
+ << BOOST_TEST_L( " line" ) << attr_value() << tu.p_line_num;
+
+ ostr << ">";
}
//____________________________________________________________________________//
Modified: trunk/boost/test/interaction/exception_safety.hpp
==============================================================================
--- trunk/boost/test/interaction/exception_safety.hpp (original)
+++ trunk/boost/test/interaction/exception_safety.hpp 2012-11-05 06:29:39 EST (Mon, 05 Nov 2012)
@@ -52,7 +52,8 @@
\
BOOST_AUTO_TU_REGISTRAR( test_name )( \
boost::unit_test::make_test_case( \
- &BOOST_AUTO_TC_INVOKER( test_name ), #test_name ), \
+ &BOOST_AUTO_TC_INVOKER( test_name ), #test_name, \
+ __FILE__, __LINE__ ), \
boost::unit_test::decorator::collector::instance() ); \
\
void test_name::test_method() \
Modified: trunk/boost/test/interaction/logged_expectations.hpp
==============================================================================
--- trunk/boost/test/interaction/logged_expectations.hpp (original)
+++ trunk/boost/test/interaction/logged_expectations.hpp 2012-11-05 06:29:39 EST (Mon, 05 Nov 2012)
@@ -47,7 +47,8 @@
\
BOOST_AUTO_TU_REGISTRAR( test_name )( \
boost::unit_test::make_test_case( \
- &BOOST_AUTO_TC_INVOKER( test_name ), #test_name ), \
+ &BOOST_AUTO_TC_INVOKER( test_name ), #test_name, \
+ __FILE__, __LINE__ ), \
boost::unit_test::decorator::collector::instance() ); \
\
void test_name::test_method() \
Modified: trunk/boost/test/parameterized_test.hpp
==============================================================================
--- trunk/boost/test/parameterized_test.hpp (original)
+++ trunk/boost/test/parameterized_test.hpp 2012-11-05 06:29:39 EST (Mon, 05 Nov 2012)
@@ -32,12 +32,14 @@
#define BOOST_PARAM_TEST_CASE( function, begin, end ) \
boost::unit_test::make_test_case( function, \
BOOST_TEST_STRINGIZE( function ), \
+ __FILE__, __LINE__, \
(begin), (end) ) \
/**/
#define BOOST_PARAM_CLASS_TEST_CASE( function, tc_instance, begin, end ) \
boost::unit_test::make_test_case( function, \
BOOST_TEST_STRINGIZE( function ), \
+ __FILE__, __LINE__, \
(tc_instance), \
(begin), (end) ) \
/**/
@@ -56,10 +58,14 @@
public:
param_test_case_generator( boost::function<void (ParamType)> const& test_func,
const_string tc_name,
+ const_string tc_file,
+ std::size_t tc_line,
ParamIter par_begin,
ParamIter par_end )
: m_test_func( test_func )
, m_tc_name( ut_detail::normalize_test_case_name( tc_name ) )
+ , m_tc_file( tc_file )
+ , m_tc_line( tc_line )
, m_par_begin( par_begin )
, m_par_end( par_end )
{}
@@ -69,7 +75,7 @@
if( m_par_begin == m_par_end )
return (test_unit*)0;
- test_unit* res = new test_case( m_tc_name, boost::bind( m_test_func, *m_par_begin ) );
+ test_unit* res = new test_case( m_tc_name, m_tc_file, m_tc_line, boost::bind( m_test_func, *m_par_begin ) );
++m_par_begin;
@@ -78,10 +84,12 @@
private:
// Data members
- boost::function<void (ParamType)> m_test_func;
- std::string m_tc_name;
- mutable ParamIter m_par_begin;
- ParamIter m_par_end;
+ boost::function<void (ParamType)> m_test_func;
+ std::string m_tc_name;
+ const_string m_tc_file;
+ std::size_t m_tc_line;
+ mutable ParamIter m_par_begin;
+ ParamIter m_par_end;
};
//____________________________________________________________________________//
@@ -109,10 +117,12 @@
inline ut_detail::param_test_case_generator<ParamType,ParamIter>
make_test_case( boost::function<void (ParamType)> const& test_func,
const_string tc_name,
+ const_string tc_file,
+ std::size_t tc_line,
ParamIter par_begin,
ParamIter par_end )
{
- return ut_detail::param_test_case_generator<ParamType,ParamIter>( test_func, tc_name, par_begin, par_end );
+ return ut_detail::param_test_case_generator<ParamType,ParamIter>( test_func, tc_name, tc_file, tc_line, par_begin, par_end );
}
//____________________________________________________________________________//
@@ -122,11 +132,13 @@
BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type,ParamIter>
make_test_case( void (*test_func)( ParamType ),
const_string tc_name,
+ const_string tc_file,
+ std::size_t tc_line,
ParamIter par_begin,
ParamIter par_end )
{
typedef BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type param_value_type;
- return ut_detail::param_test_case_generator<param_value_type,ParamIter>( test_func, tc_name, par_begin, par_end );
+ return ut_detail::param_test_case_generator<param_value_type,ParamIter>( test_func, tc_name, tc_file, tc_line, par_begin, par_end );
}
//____________________________________________________________________________//
@@ -136,6 +148,8 @@
BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type,ParamIter>
make_test_case( void (UserTestCase::*test_method )( ParamType ),
const_string tc_name,
+ const_string tc_file,
+ std::size_t tc_line,
boost::shared_ptr<UserTestCase> const& user_test_case,
ParamIter par_begin,
ParamIter par_end )
@@ -144,6 +158,8 @@
return ut_detail::param_test_case_generator<param_value_type,ParamIter>(
ut_detail::user_param_tc_method_invoker<UserTestCase,ParamType>( user_test_case, test_method ),
tc_name,
+ tc_file,
+ tc_line,
par_begin,
par_end );
}
Modified: trunk/boost/test/tree/auto_registration.hpp
==============================================================================
--- trunk/boost/test/tree/auto_registration.hpp (original)
+++ trunk/boost/test/tree/auto_registration.hpp 2012-11-05 06:29:39 EST (Mon, 05 Nov 2012)
@@ -38,7 +38,7 @@
struct BOOST_TEST_DECL auto_test_unit_registrar {
// Constructors
auto_test_unit_registrar( test_case* tc, decorator::collector* decorators, counter_t exp_fail = 0 );
- explicit auto_test_unit_registrar( const_string ts_name, decorator::collector* decorators );
+ explicit auto_test_unit_registrar( const_string ts_name, const_string ts_file, std::size_t ts_line, decorator::collector* decorators );
explicit auto_test_unit_registrar( test_unit_generator const& tc_gen, decorator::collector* decorators );
explicit auto_test_unit_registrar( int );
};
Modified: trunk/boost/test/tree/test_case_template.hpp
==============================================================================
--- trunk/boost/test/tree/test_case_template.hpp (original)
+++ trunk/boost/test/tree/test_case_template.hpp 2012-11-05 06:29:39 EST (Mon, 05 Nov 2012)
@@ -64,8 +64,10 @@
template<typename Generator,typename TestCaseTemplate>
struct generate_test_case_4_type {
- explicit generate_test_case_4_type( const_string tc_name, Generator& G )
+ explicit generate_test_case_4_type( const_string tc_name, const_string tc_file, std::size_t tc_line, Generator& G )
: m_test_case_name( tc_name )
+ , m_test_case_file( tc_file )
+ , m_test_case_line( tc_line )
, m_holder( G )
{}
@@ -80,12 +82,17 @@
full_name += " const";
full_name += '>';
- m_holder.m_test_cases.push_back( new test_case( full_name, test_case_template_invoker<TestCaseTemplate,TestType>() ) );
+ m_holder.m_test_cases.push_back( new test_case( full_name,
+ m_test_case_file,
+ m_test_case_line,
+ test_case_template_invoker<TestCaseTemplate,TestType>() ) );
}
private:
// Data members
const_string m_test_case_name;
+ const_string m_test_case_file;
+ std::size_t m_test_case_line;
Generator& m_holder;
};
@@ -97,11 +104,11 @@
class template_test_case_gen : public test_unit_generator {
public:
// Constructor
- template_test_case_gen( const_string tc_name )
+ template_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line )
{
typedef generate_test_case_4_type<template_test_case_gen<TestCaseTemplate,TestTypesList>,TestCaseTemplate> single_test_gen;
- mpl::for_each<TestTypesList,mpl::make_identity<mpl::_> >( single_test_gen( tc_name, *this ) );
+ mpl::for_each<TestTypesList,mpl::make_identity<mpl::_> >( single_test_gen( tc_name, tc_file, tc_line, *this ) );
}
virtual test_unit* next() const
Modified: trunk/boost/test/tree/test_unit.hpp
==============================================================================
--- trunk/boost/test/tree/test_unit.hpp (original)
+++ trunk/boost/test/tree/test_unit.hpp 2012-11-05 06:29:39 EST (Mon, 05 Nov 2012)
@@ -49,7 +49,7 @@
typedef std::list<test_unit_fixture_ptr> fixture_list;
// Constructor
- test_unit( const_string tu_name, test_unit_type t );
+ test_unit( const_string tu_name, const_string tc_file, std::size_t tc_line, test_unit_type t );
// dependencies management
void depends_on( test_unit* tu );
@@ -70,6 +70,8 @@
readonly_property<test_unit_type> p_type; // type for this test unit
readonly_property<const_string> p_type_name; // "case"/"suite"
+ readonly_property<const_string> p_file_name;
+ readonly_property<std::size_t> p_line_num;
id_t p_id; // unique id for this test unit
parent_id_t p_parent_id; // parent test suite id
id_list_t p_dependencies; // list of test units this one depends on
@@ -112,7 +114,7 @@
enum { type = tut_case };
// Constructor
- test_case( const_string tc_name, boost::function<void ()> const& test_func );
+ test_case( const_string tc_name, const_string tc_file, std::size_t tc_line, boost::function<void ()> const& test_func );
// Public property
typedef BOOST_READONLY_PROPERTY(boost::function<void ()>,(test_case)) test_func;
@@ -133,7 +135,7 @@
enum { type = tut_suite };
// Constructor
- explicit test_suite( const_string ts_name );
+ explicit test_suite( const_string ts_name, const_string ts_file, std::size_t ts_line );
// test unit list management
void add( test_unit* tu, counter_t expected_failures = 0, unsigned timeout = 0 );
@@ -160,7 +162,7 @@
class BOOST_TEST_DECL master_test_suite_t : public test_suite {
public:
- master_test_suite_t() : test_suite( "Master Test Suite" )
+ master_test_suite_t() : test_suite( "Master Test Suite", "", 0 )
, argc( 0 )
, argv( 0 )
{}
@@ -200,9 +202,9 @@
// ************************************************************************** //
inline test_case*
-make_test_case( boost::function<void ()> const& test_func, const_string tc_name )
+make_test_case( boost::function<void ()> const& test_func, const_string tc_name, const_string tc_file, std::size_t tc_line )
{
- return new test_case( ut_detail::normalize_test_case_name( tc_name ), test_func );
+ return new test_case( ut_detail::normalize_test_case_name( tc_name ), tc_file, tc_line, test_func );
}
//____________________________________________________________________________//
@@ -211,9 +213,13 @@
inline test_case*
make_test_case( void (UserTestCase::* test_method )(),
const_string tc_name,
+ const_string tc_file,
+ std::size_t tc_line,
boost::shared_ptr<InstanceType> user_test_case )
{
return new test_case( ut_detail::normalize_test_case_name( tc_name ),
+ tc_file,
+ tc_line,
ut_detail::user_tc_method_invoker<InstanceType,UserTestCase>( user_test_case, test_method ) );
}
Modified: trunk/boost/test/unit_test_suite.hpp
==============================================================================
--- trunk/boost/test/unit_test_suite.hpp (original)
+++ trunk/boost/test/unit_test_suite.hpp 2012-11-05 06:29:39 EST (Mon, 05 Nov 2012)
@@ -27,17 +27,21 @@
// ************** Non-auto (explicit) test case interface ************** //
// ************************************************************************** //
-#define BOOST_TEST_CASE( test_function ) \
-boost::unit_test::make_test_case( boost::function<void ()>(test_function), BOOST_TEST_STRINGIZE( test_function ) )
-#define BOOST_CLASS_TEST_CASE( test_function, tc_instance ) \
-boost::unit_test::make_test_case((test_function), BOOST_TEST_STRINGIZE( test_function ), tc_instance )
+#define BOOST_TEST_CASE( test_function ) \
+boost::unit_test::make_test_case( boost::function<void ()>(test_function), \
+ BOOST_TEST_STRINGIZE( test_function ), \
+ __FILE__, __LINE__ )
+#define BOOST_CLASS_TEST_CASE( test_function, tc_instance ) \
+boost::unit_test::make_test_case( (test_function), \
+ BOOST_TEST_STRINGIZE( test_function ), \
+ __FILE__, __LINE__, tc_instance )
// ************************************************************************** //
// ************** BOOST_TEST_SUITE ************** //
// ************************************************************************** //
#define BOOST_TEST_SUITE( testsuite_name ) \
-( new boost::unit_test::test_suite( testsuite_name ) )
+( new boost::unit_test::test_suite( testsuite_name, __FILE__, __LINE__ ) )
// ************************************************************************** //
// ************** BOOST_AUTO_TEST_SUITE ************** //
@@ -47,6 +51,7 @@
namespace suite_name { \
BOOST_AUTO_TU_REGISTRAR( suite_name )( \
BOOST_STRINGIZE( suite_name ), \
+ __FILE__, __LINE__, \
boost::unit_test::decorator::collector::instance() ); \
/**/
@@ -97,7 +102,8 @@
\
BOOST_AUTO_TU_REGISTRAR( test_name )( \
boost::unit_test::make_test_case( \
- &BOOST_AUTO_TC_INVOKER( test_name ), #test_name ), \
+ &BOOST_AUTO_TC_INVOKER( test_name ), \
+ #test_name, __FILE__, __LINE__ ), \
boost::unit_test::decorator::collector::instance() ); \
\
void test_name::test_method() \
@@ -135,7 +141,7 @@
BOOST_AUTO_TU_REGISTRAR( test_name )( \
boost::unit_test::ut_detail::template_test_case_gen< \
BOOST_AUTO_TC_INVOKER( test_name ),TL >( \
- BOOST_STRINGIZE( test_name ) ), \
+ BOOST_STRINGIZE( test_name ), __FILE__, __LINE__ ), \
boost::unit_test::decorator::collector::instance() ); \
\
template<typename type_name> \
@@ -155,7 +161,7 @@
#define BOOST_TEST_CASE_TEMPLATE( name, typelist ) \
boost::unit_test::ut_detail::template_test_case_gen<name,typelist >(\
- BOOST_TEST_STRINGIZE( name ) ) \
+ BOOST_TEST_STRINGIZE( name ), __FILE__, __LINE__ ) \
/**/
// ************************************************************************** //
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