File: testing_exception_correctness.qbk

package info (click to toggle)
boost1.74 1.74.0%2Bds1-21
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 463,588 kB
  • sloc: cpp: 3,338,117; xml: 131,293; python: 33,088; ansic: 14,292; asm: 4,038; sh: 3,353; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (47 lines) | stat: -rw-r--r-- 1,854 bytes parent folder | download | duplicates (11)
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]