testing_exception_correctness.qbk 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. [/
  2. / Copyright (c) 2003-2015 Boost.Test contributors
  3. /
  4. / Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. /]
  7. [/ ################################################ ]
  8. [section:exception_correctness Exception correctness]
  9. Any unexpected/uncaught exception raised in the test case body will be intercepted by the Boost.test
  10. framework and will result in the termination of the test-case with the status `failed`.
  11. [bt_example exception_uncaught..Uncaught exception..run-fail]
  12. More control over the exception correctness is often required, for instance to test that
  13. an expression is raising a specific exception, intentionally.
  14. The __UTF__ provides several assertions for testing a code with respect to the exceptions correctness.
  15. The following assertions are available:
  16. * __BOOST_LEVEL_NO_THROW__ checks that no exception is raised from an expression,
  17. * __BOOST_LEVEL_THROW__ checks that an expression raises an exception of a specific type
  18. * __BOOST_LEVEL_EXCEPTION__ checks that an expression raises an exception of a specific type,
  19. a passes the exception instance to a predicate function for further validation (introspection
  20. for instance)
  21. The following example demonstrate how to use these tools to test the correct behavior of the API
  22. of `FileWordHistogram`, in the constructor and the preconditions of the member function.
  23. [bt_example exception_api..Exception correctness of an API..run-fail]
  24. [note An `assert(...)` might call `abort()`: the use of the macros above may not be
  25. suitable for testing for `assert`'s in a portable manner. ]
  26. [h4 Bibliographic references]
  27. [variablelist Publications
  28. [
  29. [[@https://isocpp.org/wiki/faq/exceptions
  30. Exceptions and Error Handling]]
  31. [Standard C++ Foundation]
  32. ]
  33. ]
  34. [endsect]