File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #ifdef REFLECTCPP_USE_STD_EXPECTED
2+ #include < expected>
3+ #endif
4+
5+ #include < rfl.hpp>
6+ #include < gtest/gtest.h>
7+
8+ namespace test_exceptions {
9+
10+ struct Person {
11+ rfl::Rename<" firstName" , std::string> first_name;
12+ rfl::Rename<" lastName" , std::string> last_name = " Flanders" ;
13+ };
14+
15+ TEST (generic, test_exceptions) {
16+ const std::string error_message = " unified bad access message!" ;
17+ #ifdef REFLECTCPP_USE_STD_EXPECTED
18+ rfl::Result<Person> person = std::unexpected (rfl::Error (error_message));
19+ #else
20+ rfl::Result<Person> person (rfl::error (error_message));
21+ #endif
22+
23+ try {
24+ person.value ();
25+ FAIL () << " Expected an exception!" ;
26+ }
27+ #ifdef REFLECTCPP_USE_STD_EXPECTED
28+ catch (std::bad_expected_access<rfl::Error> const & err) {
29+ EXPECT_EQ (err.what (), error_message);
30+ }
31+ #else
32+ catch (std::runtime_error const & err) {
33+ EXPECT_EQ (err.what (), error_message);
34+ }
35+ #endif
36+ catch (...) {
37+ FAIL () << " Invalid exception type!" ;
38+ }
39+ }
40+ } // namespace test_exceptions
You can’t perform that action at this time.
0 commit comments