]>
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/handle_errors.hpp> | |
24 | # include <boost/leaf/exception.hpp> | |
25 | # include <boost/leaf/pred.hpp> | |
26 | #endif | |
27 | ||
20effc67 TL |
28 | #include "lightweight_test.hpp" |
29 | ||
30 | namespace leaf = boost::leaf; | |
31 | ||
32 | struct info { int value; }; | |
33 | ||
34 | struct my_error: std::exception { }; | |
35 | ||
36 | int main() | |
37 | { | |
38 | int r = leaf::try_catch( | |
39 | []() -> int | |
40 | { | |
41 | throw leaf::exception( my_error(), info{42} ); | |
42 | }, | |
43 | []( my_error const & x, leaf::catch_<leaf::error_id> id ) | |
44 | { | |
45 | BOOST_TEST(dynamic_cast<leaf::error_id const *>(&id.matched)!=0 && dynamic_cast<leaf::error_id const *>(&id.matched)->value()==1); | |
46 | return 1; | |
47 | }, | |
48 | [] | |
49 | { | |
50 | return 2; | |
51 | } ); | |
52 | BOOST_TEST_EQ(r, 1); | |
53 | return boost::report_errors(); | |
54 | } | |
55 | ||
56 | #endif |