Skip to content

Commit bc2b84d

Browse files
F'up to #14654: Fix Boost test macro definitions (#8590)
CI failure is unrelated.
1 parent 97b642f commit bc2b84d

2 files changed

Lines changed: 49 additions & 4 deletions

File tree

cfg/boost.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@
8383
<define name="BOOST_MATH_INT_TABLE_TYPE" value=""/>
8484
<define name="BOOST_MATH_INT_VALUE_SUFFIX" value=""/>
8585
<!-- Tell cppcheck to interpret BOOST_AUTO_TEST_CASE as a function definition -->
86-
<define name="BOOST_AUTO_TEST_CASE(test_name)" value="void BOOST_AUTO_TEST_CASE_run ## test_name ()"/>
86+
<define name="BOOST_AUTO_TEST_CASE(test_name, ...)" value="void BOOST_AUTO_TEST_CASE_run ## test_name ()"/>
8787
<define name="BOOST_AUTO_TEST_CASE_TEMPLATE(test_name, type_name, TL)" value="template&lt;typename type_name&gt;void test_name()"/>
88-
<define name="BOOST_FIXTURE_TEST_CASE(name, fixture)" value="struct name : fixture { void test_method(); }; void name::test_method()" />
88+
<define name="BOOST_FIXTURE_TEST_CASE(name, fixture, ...)" value="struct name : fixture { void test_method(); }; void name::test_method()" />
8989
<define name="BOOST_FIXTURE_TEST_CASE_TEMPLATE(test_name, type_name, TL, F)" value="template&lt;typename type_name&gt; struct test_name : public F { void test_method(); }; template&lt;typename type_name&gt; void test_name&lt;type_name&gt;::test_method()" />
90-
<define name="BOOST_DATA_TEST_CASE(test_name)" value="void BOOST_DATA_TEST_CASE_run ## test_name ()"/>
91-
<define name="BOOST_DATA_TEST_CASE_F(test_name)" value="void BOOST_DATA_TEST_CASE_F_run ## test_name ()"/>
90+
<define name="BOOST_DATA_TEST_CASE(test_name, ...)" value="void BOOST_DATA_TEST_CASE_run ## test_name ()"/>
91+
<define name="BOOST_DATA_TEST_CASE_F(test_name, ...)" value="void BOOST_DATA_TEST_CASE_F_run ## test_name ()"/>
9292
<define name="BOOST_PYTHON_MODULE(str)" value="void BOOST_PYTHON_MODULE_definition(str)"/>
9393
<define name="BOOST_SCOPED_ENUM_DECLARE_BEGIN(x)" value=""/>
9494
<define name="BOOST_SCOPED_ENUM_DECLARE_END(x)" value=""/>

test/cfg/boost.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <boost/thread/mutex.hpp> // IWYU pragma: keep
2323
#include <boost/thread/lock_guard.hpp>
2424
#include <boost/test/unit_test.hpp> // IWYU pragma: keep
25+
#include <boost/test/data/test_case.hpp>
26+
#include <boost/test/data/monomorphic.hpp>
2527
#include <boost/core/scoped_enum.hpp>
2628
#include <boost/foreach.hpp>
2729

@@ -199,3 +201,46 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(my_tuple_test, T, test_types_w_tuples)
199201
}
200202

201203
BOOST_AUTO_TEST_SUITE_END()
204+
205+
// https://www.boost.org/doc/libs/latest/libs/test/doc/html/boost_test/tests_organization/test_cases/test_case_generation/datasets.html
206+
namespace bdata = boost::unit_test::data;
207+
208+
// Dataset generating a Fibonacci sequence
209+
struct fibonacci_dataset {
210+
// the type of the samples is deduced
211+
// cppcheck-suppress unusedStructMember // FP #14795, used in template is_dataset
212+
static const int arity = 1;
213+
214+
struct iterator {
215+
int operator*() const { return b; }
216+
void operator++() {
217+
a = a + b;
218+
std::swap(a, b);
219+
}
220+
private:
221+
int a = 1;
222+
int b = 1; // b is the output
223+
};
224+
225+
// size is infinite
226+
bdata::size_t size() const { return bdata::BOOST_TEST_DS_INFINITE_SIZE; }
227+
228+
// iterator
229+
static iterator begin() { return iterator(); }
230+
};
231+
232+
namespace boost { namespace unit_test { namespace data { namespace monomorphic {
233+
// registering fibonacci_dataset as a proper dataset
234+
template <>
235+
struct is_dataset<fibonacci_dataset> : boost::mpl::true_ {};
236+
}}}}
237+
238+
// Creating a test-driven dataset, the zip is for checking
239+
BOOST_DATA_TEST_CASE(
240+
test1,
241+
fibonacci_dataset() ^ bdata::make( { 1, 2, 3, 5, 8, 13, 21, 35, 56 } ),
242+
fib_sample, exp)
243+
{
244+
// cppcheck-suppress valueFlowBailoutIncompleteVar // TODO: fib_sample declared in test case
245+
BOOST_TEST(fib_sample == exp);
246+
}

0 commit comments

Comments
 (0)