BDE 4.14.0 Production release
|
Provide an exception type for handling failed preconditions.
This component implements an exception class, bsls::FuzzTestPreconditionException
, that provides a mechanism to convey context information from a failing precondition to a test handler. The context that is captured consists of the program source of the failing expression, the name of the file containing the assertion, the line number within that file where the asserted expression may be found, and the level of the assertion that has failed.
First we write a macro to act as a precondition testing assert
facility that will throw an exception of type bsls::FuzzTestPreconditionException
if the asserted expression fails. The thrown exception will capture the source-code of the expression, the filename and line number of the failing expression.
Next we use the macro inside a try-block, so that we can catch the exception thrown if the tested expression fails.
If the assertion fails, catch the exception and confirm that it correctly recorded the context of where the assertion failed.