If I have user defined exceptions in my code, I can’t get Boost test
to consider them as failures.
For example,
BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MyTest,1)
BOOST_AUTO_TEST_CASE(MyTest)
{
// code which throws user defined exception, not derived from std::exception.
}
I get a generic message:
Caught exception: ....
unknown location(0):....
It does not recognize this error as a failure since it is not a std::exception.
So it does not honor the expected_failures clause.
How do I enforce that the piece of code should always throw an exception?
THis seems to be a useful thing to want. In case future code changes cause the code
to pass and the exception is not thrown, I want to know that.
The
EXPECTED_FAILURESare referring to failures againstBOOST_REQUIREor other assertions. The documentation clearly states:Emphasis was mine.
The expected failures are meant to be used as a temporary workaround during testing when an assertion is failing but you want to temporarily ignore it.
Taking a snippet from their expected failures spec:
will result in output of
As you can see, in spite of assertions failing, the test case still passed due to the use of expected failures.
So if you need to verify that something is throwing an exception, you use code like the following: