I've been using Boost.Test for a project at work, and one thing I found annoying is that BOOST_TEST_CONTEXT requires you to create a new scope using braces, and the context information will only live as long as that new scope. What I originally though it would do (and what I really want it to do) is to make the additional context information last for the remainder of the enclosing scope. This allows me to slowly build context information as my test progresses without requiring excessive indentation.
My current workaround is to use a define as below (notice the declaration is no longer in an "if" condition):
#define MY_BOOST_TEST_CONTEXT( context_descr ) \
::boost::test_tools::tt_detail::context_frame BOOST_JOIN( context_frame_, __LINE__ ) = \
::boost::test_tools::tt_detail::context_frame( BOOST_TEST_LAZY_MSG( context_descr ) )
This allows me to do this:
for (int i = 8; i < 24; ++i) {
MY_BOOST_TEST_CONTEXT("corrupting CRC bit " << i);
// ...
}
Instead of this:
for (int i = 8; i < 24; ++i) {
BOOST_TEST_CONTEXT("corrupting CRC bit " << i) {
// ...
}
}
This particular example may not look like much, but after 3 or 4 additions to the context as my test progresses the indentation starts to get excessive.
I've been using Boost.Test for a project at work, and one thing I found annoying is that BOOST_TEST_CONTEXT requires you to create a new scope using braces, and the context information will only live as long as that new scope. What I originally though it would do (and what I really want it to do) is to make the additional context information last for the remainder of the enclosing scope. This allows me to slowly build context information as my test progresses without requiring excessive indentation.
My current workaround is to use a define as below (notice the declaration is no longer in an "if" condition):
This allows me to do this:
Instead of this:
This particular example may not look like much, but after 3 or 4 additions to the context as my test progresses the indentation starts to get excessive.