Let's say I have the following test code:
struct MyData
{
MyData( int in_, double out_ )
: m_in{ in_ }
, m_out{ out_ }
{}
int m_in;
double m_out;
};
std::ostream& operator<<( std::ostream& os_, MyData data_ )
{
os_ << data_.m_in << " " << data_.m_out << std::endl;
return os_;
}
std::vector< MyData > DataSetGet()
{
return
{
{ 1, 1.0 },
{ 2, 2.0 }, // I would like to disable this...
{ 3, 3.0 },
};
}
BOOST_DATA_TEST_CASE( CastIntToDouble, DataSetGet() )
{
BOOST_TEST( static_cast< double >( sample.m_in ) == sample.m_out );
}
I would like to disable the second test instance. I could just comment out the second case, like this:
std::vector< MyData > DataSetGet()
{
return
{
{ 1, 1.0 },
//{ 2, 2.0 }, // I would like to disable this...
{ 3, 3.0 },
};
}
but then this case would no longer be compiled, which is not what I am looking for. In my real scenario, test cases are more complex and I would like them compiled, but not run.
I have searched the boost documentation on this topic and I came across the disable decorator, which looks like what I need. However, I have found no way to use it in data test cases. Is this possible?
You can supply a command line argument, like:
Which outputs:
More Advanced/Dynamic
You could also supply your own decorator based on enable_if, which you could make to use your own custom command line options (you'll need to supply your own
test_mainto parse those).For an example of such custom decorator: https://www.boost.org/doc/libs/1_78_0/libs/test/doc/html/boost_test/tests_organization/enabling.html#boost_test.tests_organization.enabling.runtime_run_status
Live Demo
Live On Coliru
Run with
Prints