]>
Commit | Line | Data |
---|---|---|
1e59de90 | 1 | // Copyright 2018-2022 Emil Dotchevski and Reverge Studios, Inc. |
20effc67 TL |
2 | |
3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
1e59de90 TL |
6 | #include <boost/leaf/config.hpp> |
7 | ||
20effc67 TL |
8 | #ifdef BOOST_LEAF_NO_EXCEPTIONS |
9 | ||
10 | #include <iostream> | |
11 | ||
12 | int main() | |
13 | { | |
14 | std::cout << "Unit test not applicable." << std::endl; | |
15 | return 0; | |
16 | } | |
17 | ||
18 | #else | |
19 | ||
1e59de90 TL |
20 | #ifdef BOOST_LEAF_TEST_SINGLE_HEADER |
21 | # include "leaf.hpp" | |
22 | #else | |
23 | # include <boost/leaf/on_error.hpp> | |
24 | # include <boost/leaf/handle_errors.hpp> | |
25 | #endif | |
26 | ||
20effc67 TL |
27 | #include "lightweight_test.hpp" |
28 | ||
29 | namespace leaf = boost::leaf; | |
30 | ||
31 | struct info { int value; }; | |
32 | ||
33 | void g1() | |
34 | { | |
35 | auto load = leaf::on_error( info{1} ); | |
36 | } | |
37 | ||
38 | void g2() | |
39 | { | |
40 | throw std::exception(); | |
41 | } | |
42 | ||
43 | void f() | |
44 | { | |
45 | auto load = leaf::on_error( info{2} ); | |
46 | g1(); | |
47 | g2(); | |
48 | } | |
49 | ||
50 | int main() | |
51 | { | |
52 | int r = leaf::try_catch( | |
53 | [] | |
54 | { | |
55 | f(); | |
56 | return 0; | |
57 | }, | |
58 | []( info x ) | |
59 | { | |
60 | BOOST_TEST_EQ(x.value, 2); | |
61 | return 1; | |
62 | }, | |
63 | [] | |
64 | { | |
65 | return 2; | |
66 | } ); | |
67 | BOOST_TEST_EQ(r, 1); | |
68 | ||
69 | return boost::report_errors(); | |
70 | } | |
71 | ||
72 | #endif |