Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reporting an exception in Boost::test

Tags:

c++

boost-test

Using the boost::test framework, is there a way to detect if an exception (of some type) has been thrown from a function?

like image 837
There is nothing we can do Avatar asked Nov 09 '10 17:11

There is nothing we can do


1 Answers

Are you looking to test that a function correctly throws under some circumstances? If so

BOOST_CHECK_THROW( function(), exception_type );

will do it. You can use

BOOST_CHECK_EXCEPTION( function(), exception_type, predicate )

to call an arbitrary predicate on the exception when it's caught and

BOOST_CHECK_NO_THROW( function() )

to ensure a function doesn't throw.

See: http://www.boost.org/doc/libs/1_44_0/libs/test/doc/html/utf/testing-tools/reference.html

like image 54
Adam Bowen Avatar answered Oct 03 '22 13:10

Adam Bowen