I'm trying to get some data-driven test cases running with BOOST_DATA_TEST_CASE
and figured out the basics o far.
However, I noticed that the type that is used as sample input MUST be printable:
This will work:
std::vector<std::string> printable_cases = { "case1", "case2" };
BOOST_DATA_TEST_CASE(test_mvex, utdata::make(printable_cases), sample) {
// Do some tests with sample
}
This will NOT work:
struct Thingmajig {
// I really don't care for printability!
explicit Thingmajig(int a, int b) { c = a + b; }
int c;
};
std::vector<Thingmajig> nonprintable_cases = { Thingmajig(1, 2), Thingmajig(4, 7) };
BOOST_DATA_TEST_CASE(test_mvex2, utdata::make(nonprintable_cases), sample) {
// Do some tests with sample
}
It will error out with:
Error C2679 binary '<<': no operator found which takes a right-hand operand of type 'const T' (or there is no acceptable conversion)
...\boost\test\tools\detail\print_helper.hpp 54
Error C2338 Type has to implement operator<< to be printable
...\boost\test\tools\detail\print_helper.hpp 52
We have lots of types in out codebase that don't supply operator<<
and having to define one just to make the compilation of the data test case possible seems quite annoying.
Is this a limitation of how BOOST_DATA_TEST_CASE constructs the test case from the data, or is there some way around this?
Preliminary notes:
- Just defining a free-standing bare bones ouput-operator in the unit test file itself is obviously enough, the type does not need to provide one globally/generically. This is still annoying when printability is irrelevant for the test.
- I actually hit this where the sample type contained a
std::vector
and astd::tuple
: For these std lib containers, cxx-prettyprint is a good (-enough) solution inside the test cases.