'Disabling specific test instance defined from a dataset

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?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source