I read the boost headers a bit and redefined BOOST_CHECK_NO_THROW_IMPL in my own header file, which I use in the project to override the behavior of boost. Now it looks like this:
#ifndef _CATCH_BOOST_NO_THROW_H_ #define _CATCH_BOOST_NO_THROW_H_ #include <boost/test/unit_test.hpp> #include <sstream> #include <string> #define BOOST_CHECK_NO_THROW_IMPL( S, TL ) \ try { \ S; \ BOOST_CHECK_IMPL( true, "no exceptions thrown by " BOOST_STRINGIZE( S ), TL, CHECK_MSG ); } \ catch( const std::exception & e ) { \ std::stringstream ss; \ ss << std::endl \ << "-----------------------------------------------" << std::endl \ << "test case: " << boost::unit_test::framework::current_test_case().p_name << std::endl \ << std::endl << "exception message: " << e.what() << std::endl; \ BOOST_TEST_MESSAGE(ss.str()); \ BOOST_CHECK_IMPL( false, "exception thrown by " BOOST_STRINGIZE( S ), TL, CHECK_MSG ); \ } \ catch( ... ) { \ std::stringstream ss; \ ss << std::endl \ << "-----------------------------------------------" << std::endl \ << "test case: " << boost::unit_test::framework::current_test_case().p_name << std::endl \ << std::endl << "exception message : <unknown exception>" << std::endl; \ BOOST_TEST_MESSAGE(ss.str()); \ BOOST_CHECK_IMPL( false, "exception thrown by " BOOST_STRINGIZE( S ), TL, CHECK_MSG ); \ } \ /**/ #define BOOST_WARN_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, WARN ) #define BOOST_CHECK_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, CHECK ) #define BOOST_REQUIRE_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, REQUIRE ) #endif // _CATCH_BOOST_NO_THROW_H_
Minuses: it works until there are no changes in BOOST _ * _ NO_THROW
and
an exception message will be printed before it is flagged as an error in the test output. First of all, it looks a bit pitti, so I group the output, write "---" in the upstream to improve reading. But the code after BOOST_CHECK_IMPL will never be reached.
The solution above works pretty well for me. Feel free to use if you have the same whish =)
(Using CDash to output ctest, don't forget to increase the test output limit or just disable the limit: http://web.archiveorange.com/archive/v/5y7PkVuHtkmVcf7jiWol )
550
source share