Skip to content

Commit

Permalink
Check for clashing names in adding test units
Browse files Browse the repository at this point in the history
- clashing on name only
- adding tests
  • Loading branch information
raffienficiaud committed Jan 2, 2018
1 parent dcefa9f commit 306b552
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/boost/test/impl/test_tree.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ test_suite::test_suite( const_string module_name )
void
test_suite::add( test_unit* tu, counter_t expected_failures, unsigned timeout )
{
// check for clashing names #12597
for( test_unit_id_list::const_iterator it(m_children.begin()), ite(m_children.end());
it < ite;
++it) {
BOOST_TEST_SETUP_ASSERT( tu->p_name != framework::get(*it, TUT_ANY).p_name,
"test unit with name '" + tu->p_name.value + std::string("' registered multiple times") );

This comment has been minimized.

Copy link
@rhalbersma

rhalbersma Apr 24, 2018

I understand the general rationale for adding such a test. However, it breaks fairly innocent tests over type lists. E.g. I have tests for bit-twiddling code over unsigned, unsigned long and unsigned long long, as well as uint32_t and uint64_t. On most architectures this has 2 independent types, but I would like not to have to specify which types are redundant. With Boost 1.67 this now breaks my existing code. It it possible to guard this with a macro that can be opted-out as a build option? E.g. BOOST_TEST_DUPLICATE_CHECK or something like that?

This comment has been minimized.

Copy link
@raffienficiaud

raffienficiaud Apr 24, 2018

Author Member

I understand. What about continuing the discussion on trac? https://svn.boost.org/ Please open a ticket there and I will address it. Maybe we can transform that to a warning instead.

This comment has been minimized.

Copy link
@rhalbersma

rhalbersma Apr 24, 2018

On second thought, I think the warning is useful; I refactored my code instead to only use fixed width integers instead.

BTW, I opened another GitHub issue earlier: is svn/Trac still preferred?

This comment has been minimized.

Copy link
@raffienficiaud

raffienficiaud Apr 24, 2018

Author Member

To me trac is useful 😃 and I am also mentioning it there: https://github.com/boostorg/test/blob/develop/CONTRIBUTE.md . So would you prefer a warning or an error? You are saying it is useful ...

This comment has been minimized.

Copy link
@mgaunard

mgaunard Sep 10, 2018

there are bugs in the way the name is computed (doesn't show top-level reference and cv qualifiers), so different tests are wrongly being reported as being unique.

This comment has been minimized.

Copy link
@raffienficiaud

raffienficiaud Sep 10, 2018

Author Member

@mgaunard I haven't thought about that, thanks for pointing it out. So I suppose that you have class member function that you register as tests, right?

This comment has been minimized.

Copy link
@mgaunard

mgaunard Sep 20, 2018

no, I simply have a template test which tests both int and int volatile.

This comment has been minimized.

Copy link
@raffienficiaud

raffienficiaud Mar 9, 2019

Author Member

Fixed, currently in master

}

tu->p_timeout.value = timeout;

m_children.push_back( tu->p_id );
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ test-suite "test-organization-ts"
[ boost.test-self-test run : test-organization-ts : test_unit-nested-suite-dependency ]
[ boost.test-self-test run : test-organization-ts : test-tree-management-test ]
[ boost.test-self-test run : test-organization-ts : test-tree-several-suite-decl ]
[ boost.test-self-test run : test-organization-ts : test_unit-report-clashing-names ]
;

#_________________________________________________________________________________________________#
Expand Down
68 changes: 68 additions & 0 deletions test/test-organization-ts/test_unit-report-clashing-names.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// (C) Copyright Raffi Enficiaud 2018.
// 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)

// See http://www.boost.org/libs/test for the library home page.
//
//! @file
//! checking the clashing names, ticket trac #12597
// *****************************************************************************

#define BOOST_TEST_MODULE test_clashing_names
#include <boost/test/unit_test.hpp>
#include <boost/mpl/list.hpp>

void suite1_test1()
{
BOOST_CHECK(true);
}

BOOST_AUTO_TEST_CASE( test_clashing_suites )
{
using namespace boost::unit_test;
test_suite* master_ts = BOOST_TEST_SUITE("local master");
test_suite* t_suite1 = BOOST_TEST_SUITE( "suite1" );
test_suite* t_suite2 = BOOST_TEST_SUITE( "suite1" );
master_ts->add(t_suite1);
BOOST_CHECK_THROW( master_ts->add(t_suite2),
boost::unit_test::framework::setup_error );
}

BOOST_AUTO_TEST_CASE( test_clashing_cases )
{
using namespace boost::unit_test;
test_suite* master_ts = BOOST_TEST_SUITE("local master");
test_suite* t_suite1 = BOOST_TEST_SUITE( "suite1" );
test_suite* t_suite2 = BOOST_TEST_SUITE( "suite2" );
master_ts->add(t_suite1);
master_ts->add(t_suite2);

t_suite1->add( BOOST_TEST_CASE( suite1_test1 ) );
BOOST_CHECK_THROW( t_suite1->add( BOOST_TEST_CASE( suite1_test1 ) ),
boost::unit_test::framework::setup_error );

BOOST_CHECK_NO_THROW( t_suite2->add( BOOST_TEST_CASE( suite1_test1 ) ) );
}

BOOST_TEST_CASE_TEMPLATE_FUNCTION( template_test_case, T )
{
BOOST_TEST( sizeof(T) == 4U );
}

BOOST_AUTO_TEST_CASE( test_clashing_cases_template_test_case )
{
using namespace boost::unit_test;
test_suite* master_ts = BOOST_TEST_SUITE("local master");
test_suite* t_suite1 = BOOST_TEST_SUITE( "suite1" );
test_suite* t_suite2 = BOOST_TEST_SUITE( "suite2" );
master_ts->add(t_suite1);
master_ts->add(t_suite2);

typedef boost::mpl::list<int, long, unsigned char> test_types1;
typedef boost::mpl::list<int, long, unsigned char, int> test_types2;

BOOST_CHECK_NO_THROW( t_suite2->add( BOOST_TEST_CASE_TEMPLATE( template_test_case, test_types1 ) ) );
BOOST_CHECK_THROW( t_suite1->add( BOOST_TEST_CASE_TEMPLATE( template_test_case, test_types2 ) ),
boost::unit_test::framework::setup_error );
}

0 comments on commit 306b552

Please sign in to comment.