diff --git a/include/boost/test/impl/framework.ipp b/include/boost/test/impl/framework.ipp index 9786a42f..15c30565 100644 --- a/include/boost/test/impl/framework.ipp +++ b/include/boost/test/impl/framework.ipp @@ -347,12 +347,10 @@ public: , m_dep_collector( dep_collector ) {} -private: // test_tree_visitor interface virtual bool visit( test_unit const& tu ) { const_cast(tu).p_run_status.value = m_new_status == test_unit::RS_INVALID ? tu.p_default_status : m_new_status; - if( m_dep_collector ) { BOOST_TEST_FOREACH( test_unit_id, dep_id, tu.p_dependencies.get() ) { test_unit const& dep = framework::get( dep_id, TUT_ANY ); @@ -369,6 +367,7 @@ private: return true; } +private: // Data members test_unit::run_status m_new_status; test_unit_id_list* m_dep_collector; @@ -623,8 +622,13 @@ public: while( parent_id != INV_TEST_UNIT_ID && parent_id != master_tu_id ) { - traverse_test_tree( parent_id, enabler, true ); - parent_id = framework::get( parent_id, TUT_ANY ).p_parent_id; + // we do not use the traverse_test_tree as otherwise it would enable the sibblings and subtree + // of the test case we want to enable (we need to enable the parent suites and their dependencies only) + // the parent_id needs to be enabled in order to be properly parsed by finalize_run_status, the visit + // does the job + test_unit& tu_parent = framework::get( parent_id, TUT_ANY ); + enabler.visit( tu_parent ); + parent_id = tu_parent.p_parent_id; } } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f5bc1fd5..2f71457c 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -173,6 +173,7 @@ test-suite "test-organization-ts" [ 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 ] [ boost.test-self-test run : test-organization-ts : test_unit-order-shuffled-test : : : : : : $(requirements_boost_test_full_support) ] + [ 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 ] ; diff --git a/test/test-organization-ts/test_unit-nested-suite-dependency.cpp b/test/test-organization-ts/test_unit-nested-suite-dependency.cpp new file mode 100644 index 00000000..1cf38cfe --- /dev/null +++ b/test/test-organization-ts/test_unit-nested-suite-dependency.cpp @@ -0,0 +1,84 @@ +// (C) Copyright Raffi Enficiaud 2017. +// 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 nested suites activation, ticket trac #13149 +// ***************************************************************************** + +#define BOOST_TEST_MODULE test_nested_dependency +#include +#include +#include +#include + +// initial reproducing snippet on the corresponding ticket +#if 0 +BOOST_AUTO_TEST_SUITE(suite1, *boost::unit_test::depends_on("suite2")) + BOOST_AUTO_TEST_SUITE(suite1_nested) + BOOST_AUTO_TEST_CASE(suite1_test1) + { + BOOST_CHECK(true); + } + BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(suite2) + BOOST_AUTO_TEST_CASE(suite2_test2) + { + BOOST_CHECK(true); + } +BOOST_AUTO_TEST_SUITE_END() +#endif + +void suite1_test1() +{ + BOOST_CHECK(true); +} + +void suite2_test2() +{ + BOOST_CHECK(true); +} + +BOOST_AUTO_TEST_CASE( some_test ) +{ + using namespace boost::unit_test; + + // test tree + test_suite* master_ts = BOOST_TEST_SUITE("local master"); + test_suite* t_suite1 = BOOST_TEST_SUITE( "suite1" ); + test_suite* t_suite1_nested = BOOST_TEST_SUITE( "suite1_nested" ); + t_suite1_nested->add( BOOST_TEST_CASE( suite1_test1 ) ); + t_suite1->add(t_suite1_nested); + + test_suite* t_suite2 = BOOST_TEST_SUITE( "suite2" ); + t_suite2->add( BOOST_TEST_CASE( suite2_test2 ) ); + + master_ts->add(t_suite1); + master_ts->add(t_suite2); + + // dependencies + t_suite1->depends_on( t_suite2 ); + + // running + char const* argv[] = { "dummy-test-module.exe", "--log_level=all", "--run_test=suite1/suite1_nested"}; + int argc = sizeof(argv)/sizeof(argv[0]); + + master_ts->p_default_status.value = test_unit::RS_ENABLED; + framework::finalize_setup_phase( master_ts->p_id ); + + runtime_config::init( argc, (char**)argv ); + framework::impl::setup_for_execution( *master_ts ); + + // no need to run + //framework::run( master_ts ); + + // we should have 2 test cases enabled with this run parameters + test_case_counter tcc; + traverse_test_tree( master_ts->p_id, tcc ); + BOOST_TEST( tcc.p_count == 2 ); +}