I recently discovered a bug in one of my tests - it would always pass even when it should have failed. Is there a way to use the Boost.Test framework to require that a test fails when given inputs for which it is expected to fail? (I don't want to write two separate tests because the goal is to test the test itself.) Here's what I have in mind:
void test_funct(double arg_a, double arg_b) {
BOOST_CHECK_CLOSE(arg_a, 1.0, 0.1);
BOOST_CHECK_CLOSE(arg_b, 1.0, 0.1);
}
BOOST_AUTO_TEST_CASE(test) {
test_funct(1.0, 1.0); // this should be required to have no failures
test_funct(1.0, 2.0); // this should be required to have at least one failure
}
I did find a couple of things that aren't exactly what I want. There's the expected_failures decorator but it doesn't actually require an error. There's also this old post on the boost mailing list which proposes
BOOST_CHECK_PREDICATE( not( check_is_close ), (a)(b)(percent_tolerance(t)) );
but it would require every check_is_close to fail rather than just requiring at least one to fail. (Plus that code doesn't compile for me.)