Merge branch 'topic/GH-141-mp11-hana-typelist' into next-internal

* topic/GH-141-mp11-hana-typelist:
  Change log
  Template test cases: handling the references and volatile in the test-case names
  Template test cases with arbitrary parameter pack
This commit is contained in:
Raffi Enficiaud 2019-03-05 21:52:18 +01:00
commit c7066f7f9a
5 changed files with 231 additions and 23 deletions

View File

@ -82,6 +82,8 @@ Boost.Test releases:
# [github_issue 133] Timeout effect on Windows
# [github_issue 138] expected_failures doesnt work for `BOOST_DATA_TEST_CASE`
# [github_issue 141] Support for Boost.MP11 and Boost.Hana type lists
# [github_issue 157] Test name should handle `const`-`volatile` specifiers
# [github_issue 160] suppress `-Wformat-overflow` when optimization is enabled on GCC 8.2.0
# [github_issue 174] `UBSAN` identified a problem at exit time by `gcc-8` only
# [github_issue 176] `[snippet_dataset1_3]` seems to be broken
@ -109,6 +111,7 @@ Boost.Test releases:
# [ticket 7397] Boost.Test, since boost `1.48` is using the deprecated `Boost.Timer` class (solved via [github_issue 202])
# [ticket 9434] error: `namespace boost::timer {}` redeclared as different kind of symbol (solved via [github_issue 202])
# [ticket 13106] `libs/test/tools/console_test_runner` does not compile
# [ticket 13418] Request: allow general typelist types in `BOOST_AUTO_TEST_CASE_TEMPLATE()`
[#ref_CHANGE_LOG_3_9][h4 Boost.Test v3.9 / boost 1.69]

View File

@ -29,6 +29,10 @@
#include <boost/mpl/identity.hpp>
#include <boost/type.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_volatile.hpp>
#include <boost/type_traits/is_lvalue_reference.hpp>
#include <boost/type_traits/is_rvalue_reference.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/function/function0.hpp>
#if defined(BOOST_NO_TYPEID) || defined(BOOST_NO_RTTI)
@ -42,9 +46,9 @@
#include <list> // for std::list
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
!defined(BOOST_NO_CXX11_HDR_TUPLE) && \
!defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
#include <tuple>
#include <type_traits>
#include <boost/mpl/is_sequence.hpp>
#endif
#include <boost/test/detail/suppress_warnings.hpp>
@ -90,8 +94,16 @@ struct generate_test_case_4_type {
#else
full_name += BOOST_CURRENT_FUNCTION;
#endif
if( boost::is_const<TestType>::value )
typedef typename boost::remove_reference<TestType>::type TestTypewoRef;
if( boost::is_const<TestTypewoRef>::value )
full_name += "_const";
if( boost::is_volatile<TestTypewoRef>::value )
full_name += "_volatile";
if( boost::is_rvalue_reference<TestType>::value )
full_name += "_refref";
else if( boost::is_lvalue_reference<TestType>::value )
full_name += "_ref";
full_name += '>';
m_holder.m_test_cases.push_back( new test_case( ut_detail::normalize_test_case_name( full_name ),
@ -129,7 +141,7 @@ public:
mutable std::list<test_unit*> m_test_cases;
};
template<typename TestCaseTemplate,typename TestTypesList>
template<typename TestCaseTemplate,typename TestTypesList, typename enabler = void>
class template_test_case_gen : public template_test_case_gen_base {
public:
// Constructor
@ -143,26 +155,22 @@ public:
// Describing template test cases with tuples
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
!defined(BOOST_NO_CXX11_HDR_TUPLE) && \
!defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && \
!defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
template<typename TestCaseTemplate, typename... tuple_parameter_pack>
class template_test_case_gen<TestCaseTemplate, std::tuple<tuple_parameter_pack...> > : public template_test_case_gen_base {
template<typename TestCaseTemplate,
template <class ...> class C,
typename... parameter_pack>
class template_test_case_gen<
TestCaseTemplate,
C<parameter_pack...>,
typename std::enable_if<!boost::mpl::is_sequence<C<parameter_pack...>>::value>::type >
: public template_test_case_gen_base {
template<int... Is>
struct seq { };
template<int N, int... Is>
struct gen_seq : gen_seq<N - 1, N - 1, Is...> { };
template<int... Is>
struct gen_seq<0, Is...> : seq<Is...> { };
template<typename tuple_t, typename F, int... Is>
void for_each(F &f, seq<Is...>)
template<typename F>
void for_each(F &f)
{
auto l = { (f(mpl::identity<typename std::tuple_element<Is, tuple_t>::type>()), 0)... };
auto l = { (f(mpl::identity<parameter_pack>()), 0)... };
(void)l; // silence warning
}
@ -170,17 +178,19 @@ public:
// Constructor
template_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line )
{
using tuple_t = std::tuple<tuple_parameter_pack...>;
using this_type = template_test_case_gen<TestCaseTemplate, tuple_t >;
using this_type = template_test_case_gen<
TestCaseTemplate,
C<parameter_pack...>,
typename std::enable_if<!boost::mpl::is_sequence<C<parameter_pack...>>::value>::type>;
using single_test_gen = generate_test_case_4_type<this_type, TestCaseTemplate>;
single_test_gen op( tc_name, tc_file, tc_line, *this );
this->for_each<tuple_t>(op, gen_seq<sizeof...(tuple_parameter_pack)>());
this->for_each(op);
}
};
#endif /* C++11 variadic, tuples and type alias */
#endif /* C++11 variadic, type alias */
} // namespace ut_detail
} // unit_test

View File

@ -189,6 +189,7 @@ test-suite "test-organization-ts"
[ boost.test-self-test run : test-organization-ts : parameterized_test-test ]
[ boost.test-self-test run : test-organization-ts : test_case_template-test ]
[ boost.test-self-test run : test-organization-ts : test_case_template-with-tuples-test : : : : : : [ requires cxx11_hdr_tuple cxx11_auto_declarations cxx11_variadic_templates ] ]
[ boost.test-self-test run : test-organization-ts : test_case_template-with-variadic-typelist : : : : : : [ requires cxx11_hdr_tuple cxx11_auto_declarations cxx11_variadic_templates ] ]
[ boost.test-self-test run : test-organization-ts : datasets-test : : : [ glob test-organization-ts/datasets-test/*.cpp ] : : : $(requirements_datasets) ]
[ boost.test-self-test run : test-organization-ts : dataset-variadic_and_move_semantic-test : : : : : : $(requirements_datasets) ]
[ boost.test-self-test run : test-organization-ts : test_unit-order-test ]

View File

@ -23,8 +23,11 @@ typedef boost::onullstream onullstream_type;
// BOOST
#include <boost/mpl/range_c.hpp>
#include <boost/mpl/list_c.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/config.hpp>
namespace ut = boost::unit_test;
namespace mpl = boost::mpl;
@ -160,4 +163,37 @@ BOOST_AUTO_TEST_CASE( test2_one_to_three )
//____________________________________________________________________________//
// checks if volatile, const, ... are properly handled
typedef boost::mpl::vector<int,int const, int volatile,int const volatile> test_types_ints_variations;
BOOST_AUTO_TEST_CASE_TEMPLATE( tctempl2, T, test_types_ints_variations )
{
BOOST_TEST( sizeof(T) == sizeof(int) );
}
// checks if references are properly handled
typedef boost::mpl::vector<
int
, int&
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
, int&&
#endif
, int const
, int const&
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
, int const&&
#endif
> test_types_ints_ref_variations;
BOOST_AUTO_TEST_CASE_TEMPLATE( tctempl3, T, test_types_ints_ref_variations )
{
BOOST_TEST( (sizeof(T) == sizeof(int&) || sizeof(T) == sizeof(int)) );
}
// checks if pointers are properly handled
typedef boost::mpl::vector<int,int*,int const*, int const volatile*, int const*const, int*&> test_types_ints_pointer_variations;
BOOST_AUTO_TEST_CASE_TEMPLATE( tctempl4, T, test_types_ints_pointer_variations )
{
BOOST_TEST( (sizeof(T) == sizeof(int*) || sizeof(T) == sizeof(int)));
}
// EOF

View File

@ -0,0 +1,158 @@
// (C) Copyright Raffi Enficiaud 2019.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Extends #12092 with arbitrary type list
// see https://svn.boost.org/trac10/ticket/13418 and
// https://github.com/boostorg/test/issues/141
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_MODULE template_test_case_with_variadic
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_log.hpp>
#include <boost/test/results_collector.hpp>
#include <boost/test/utils/nullstream.hpp>
typedef boost::onullstream onullstream_type;
#include <boost/mpl/integral_c.hpp>
// tuple already done in another test module
// #include <tuple>
namespace ut = boost::unit_test;
namespace mpl = boost::mpl;
#include <iostream>
struct logger_guard {
logger_guard(std::ostream& s_out) {
ut::unit_test_log.set_stream( s_out );
}
~logger_guard() {
ut::unit_test_log.set_stream( std::cout );
}
};
template <class ... T>
struct dummy1 {
};
//____________________________________________________________________________//
BOOST_TEST_CASE_TEMPLATE_FUNCTION( test0, Number )
{
BOOST_TEST( 2 == (int)Number::value );
}
BOOST_AUTO_TEST_CASE( test0_only_2 )
{
onullstream_type null_output;
logger_guard G(null_output);
typedef dummy1< mpl::integral_c<int,2> > only_2;
ut::test_suite* test = BOOST_TEST_SUITE( "" );
test->add( BOOST_TEST_CASE_TEMPLATE( test0, only_2 ) );
test->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( test->p_id );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 0U );
BOOST_TEST( !tr.p_aborted );
}
BOOST_AUTO_TEST_CASE( test1_with_9_errors )
{
onullstream_type null_output;
logger_guard G(null_output);
typedef dummy1<
mpl::integral_c<int,0>,
mpl::integral_c<int,1>,
mpl::integral_c<int,2>,
mpl::integral_c<int,3>,
mpl::integral_c<int,4>,
mpl::integral_c<int,5>,
mpl::integral_c<int,6>,
mpl::integral_c<int,7>,
mpl::integral_c<int,8>,
mpl::integral_c<int,9>
> range_10;
ut::test_suite* test = BOOST_TEST_SUITE( "" );
test->add( BOOST_TEST_CASE_TEMPLATE( test0, range_10 ) );
test->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( test->p_id );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 9U );
BOOST_TEST( !tr.p_aborted );
}
int counter = 0;
BOOST_TEST_CASE_TEMPLATE_FUNCTION( test_counter, Number )
{
BOOST_TEST( counter++ == (int)Number::value );
}
BOOST_AUTO_TEST_CASE( test_left_to_right_evaluation )
{
onullstream_type null_output;
logger_guard G(null_output);
typedef dummy1<
mpl::integral_c<int,0>,
mpl::integral_c<int,1>,
mpl::integral_c<int,2>,
mpl::integral_c<int,3>,
mpl::integral_c<int,4>,
mpl::integral_c<int,5>,
mpl::integral_c<int,6>,
mpl::integral_c<int,7>,
mpl::integral_c<int,8>,
mpl::integral_c<int,9>
> range_10;
ut::test_suite* test = BOOST_TEST_SUITE( "" );
test->add( BOOST_TEST_CASE_TEMPLATE( test_counter, range_10 ) );
test->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( test->p_id );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 0U );
BOOST_TEST( !tr.p_aborted );
}
typedef dummy1<
mpl::integral_c<int,1>,
mpl::integral_c<int,3>,
mpl::integral_c<int,5>,
mpl::integral_c<int,6>,
mpl::integral_c<int,7>,
mpl::integral_c<int,8>,
mpl::integral_c<int,9>
> range_special;
BOOST_AUTO_TEST_CASE_TEMPLATE(odd_or_above_5, T, range_special) {
BOOST_TEST( (T::value % 2 || T::value >= 5 ) );
}