]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | // Copyright (c) 2018-2020 Emil Dotchevski and Reverge Studios, Inc. |
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 | ||
6 | #include <boost/leaf/detail/config.hpp> | |
7 | #if defined(BOOST_LEAF_NO_EXCEPTIONS) | |
8 | ||
9 | #include <iostream> | |
10 | ||
11 | int main() | |
12 | { | |
13 | std::cout << "Unit test not applicable." << std::endl; | |
14 | return 0; | |
15 | } | |
16 | ||
17 | #else | |
18 | ||
19 | #include <boost/leaf/handle_errors.hpp> | |
20 | #include <boost/leaf/pred.hpp> | |
21 | #include <boost/exception/info.hpp> | |
22 | #include <boost/exception/get_error_info.hpp> | |
23 | #include "lightweight_test.hpp" | |
24 | ||
25 | namespace leaf = boost::leaf; | |
26 | ||
27 | struct test_ex: std::exception { }; | |
28 | ||
29 | typedef boost::error_info<struct test_info_, int> test_info; | |
30 | ||
31 | int main() | |
32 | { | |
33 | static_assert(std::is_same<test_info, decltype(std::declval<leaf::match<test_info, 42>>().matched)>::value, "handler_argument_traits deduction bug"); | |
34 | ||
35 | using tr = leaf::leaf_detail::handler_argument_traits<leaf::match<test_info, 42>>; | |
36 | static_assert(std::is_same<void, tr::error_type>::value, "handler_argument_traits deduction bug"); | |
37 | ||
38 | { | |
39 | int r = leaf::try_catch( | |
40 | [] | |
41 | { | |
42 | try | |
43 | { | |
44 | boost::throw_exception(test_ex()); | |
45 | } | |
46 | catch( boost::exception & ex ) | |
47 | { | |
48 | ex << test_info(42); | |
49 | throw; | |
50 | } | |
51 | return 0; | |
52 | }, | |
53 | []( test_info x ) | |
54 | { | |
55 | BOOST_TEST_EQ(x.value(), 42); | |
56 | return 1; | |
57 | }, | |
58 | [] | |
59 | { | |
60 | return 2; | |
61 | } ); | |
62 | BOOST_TEST_EQ(r, 1); | |
63 | } | |
64 | ||
65 | { | |
66 | int r = leaf::try_catch( | |
67 | [] | |
68 | { | |
69 | try | |
70 | { | |
71 | boost::throw_exception(test_ex()); | |
72 | } | |
73 | catch( boost::exception & ex ) | |
74 | { | |
75 | ex << test_info(42); | |
76 | throw; | |
77 | } | |
78 | return 0; | |
79 | }, | |
80 | []( leaf::match<test_info, 42> ) | |
81 | { | |
82 | return 1; | |
83 | }, | |
84 | [] | |
85 | { | |
86 | return 2; | |
87 | } ); | |
88 | BOOST_TEST_EQ(r, 1); | |
89 | } | |
90 | ||
91 | { | |
92 | int r = leaf::try_catch( | |
93 | [] | |
94 | { | |
95 | try | |
96 | { | |
97 | boost::throw_exception(test_ex()); | |
98 | } | |
99 | catch( boost::exception & ex ) | |
100 | { | |
101 | ex << test_info(42); | |
102 | throw; | |
103 | } | |
104 | return 0; | |
105 | }, | |
106 | []( leaf::match<test_info, 41> ) | |
107 | { | |
108 | return 1; | |
109 | }, | |
110 | [] | |
111 | { | |
112 | return 2; | |
113 | } ); | |
114 | BOOST_TEST_EQ(r, 2); | |
115 | } | |
116 | ||
117 | return boost::report_errors(); | |
118 | } | |
119 | ||
120 | #endif |