File: testing_exception_correctness.qbk

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (47 lines) | stat: -rw-r--r-- 1,854 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[/
 / Copyright (c) 2003-2015 Boost.Test contributors
 /
 / Distributed under the Boost Software License, Version 1.0. (See accompanying
 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 /]


[/ ################################################ ]
[section:exception_correctness Exception correctness]

Any unexpected/uncaught exception raised in the test case body will be intercepted by the Boost.test
framework and will result in the termination of the test-case with the status `failed`.

[bt_example exception_uncaught..Uncaught exception..run-fail]

More control over the exception correctness is often required, for instance to test that
an expression is raising a specific exception, intentionally.

The __UTF__ provides several assertions for testing a code with respect to the exceptions correctness.
The following assertions are available:

* __BOOST_LEVEL_NO_THROW__ checks that no exception is raised from an expression,
* __BOOST_LEVEL_THROW__ checks that an expression raises an exception of a specific type
* __BOOST_LEVEL_EXCEPTION__ checks that an expression raises an exception of a specific type,
  a passes the exception instance to a predicate function for further validation (introspection
  for instance)

The following example demonstrate how to use these tools to test the correct behavior of the API
of `FileWordHistogram`, in the constructor and the preconditions of the member function.

[bt_example exception_api..Exception correctness of an API..run-fail]

[note An `assert(...)` might call `abort()`: the use of the macros above may not be
      suitable for testing for `assert`'s in a portable manner. ]

[h4 Bibliographic references]

[variablelist Publications
  [
    [[@https://isocpp.org/wiki/faq/exceptions
      Exceptions and Error Handling]]
    [Standard C++ Foundation]
  ]
]

[endsect]