Skip to content

Commit a89a566

Browse files
committed
Fixed json_test failures under BOOST_LEAF_NO_EXCEPTIONS and BOOST_LEAF_CFG_CAPTURE=0
1 parent c828dbf commit a89a566

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

test/json_test.cpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,31 +149,42 @@ int main()
149149
BOOST_TEST_EQ(e1j["code"].get<int>(), 1);
150150
BOOST_TEST_EQ(e1j["message"].get<std::string>(), "error one");
151151

152-
auto const & e2j = jc["my_error<2>"];
153-
BOOST_TEST_EQ(e2j["code"].get<int>(), 2);
154-
BOOST_TEST_EQ(e2j["message"].get<std::string>(), "error two");
155-
156-
auto const & ej = jc["boost::leaf::e_errno"];
157-
BOOST_TEST_EQ(ej["value"].get<int>(), ENOENT);
158-
BOOST_TEST(!ej["message"].get<std::string>().empty());
159-
160-
BOOST_TEST_EQ(jc["boost::leaf::e_api_function"].get<std::string>(), "fail");
161-
162-
auto const & ecj = jc["std::error_code"];
163-
BOOST_TEST_EQ(ecj["value"].get<int>(), static_cast<int>(std::errc::invalid_argument));
164-
BOOST_TEST(!ecj["category"].get<std::string>().empty());
165-
BOOST_TEST(!ecj["message"].get<std::string>().empty());
152+
if( BOOST_LEAF_CFG_CAPTURE )
153+
{
154+
auto const & e2j = jc["my_error<2>"];
155+
BOOST_TEST_EQ(e2j["code"].get<int>(), 2);
156+
BOOST_TEST_EQ(e2j["message"].get<std::string>(), "error two");
157+
158+
auto const & ej = jc["boost::leaf::e_errno"];
159+
BOOST_TEST_EQ(ej["value"].get<int>(), ENOENT);
160+
BOOST_TEST(!ej["message"].get<std::string>().empty());
161+
162+
BOOST_TEST_EQ(jc["boost::leaf::e_api_function"].get<std::string>(), "fail");
163+
164+
auto const & ecj = jc["std::error_code"];
165+
BOOST_TEST_EQ(ecj["value"].get<int>(), static_cast<int>(std::errc::invalid_argument));
166+
BOOST_TEST(!ecj["category"].get<std::string>().empty());
167+
BOOST_TEST(!ecj["message"].get<std::string>().empty());
168+
}
169+
else
170+
{
171+
BOOST_TEST(!jc.contains("my_error<2>"));
172+
BOOST_TEST(!jc.contains("boost::leaf::e_errno"));
173+
BOOST_TEST(!jc.contains("boost::leaf::e_api_function"));
174+
BOOST_TEST(!jc.contains("std::error_code"));
175+
}
166176
}
167177
);
168178
}
169179

180+
#ifndef BOOST_LEAF_NO_EXCEPTIONS
170181
{
171182
leaf::try_handle_all(
172183
[]() -> leaf::result<void>
173184
{
174185
return leaf::new_error(std::make_exception_ptr(std::runtime_error("test exception")));
175186
},
176-
[](leaf::diagnostic_details const & dd)
187+
[](leaf::diagnostic_details const & dd, std::exception_ptr *)
177188
{
178189
nlohmann::ordered_json j;
179190
nlohmann_writer w(j);
@@ -185,13 +196,8 @@ int main()
185196
auto const & ep = jc["std::exception_ptr"];
186197
std::string type = ep["typeid.name"].get<std::string>();
187198
std::string what = ep["what"].get<std::string>();
188-
#ifdef BOOST_LEAF_NO_EXCEPTIONS
189-
BOOST_TEST(type == "<<unknown>>" || type == "<<empty>>");
190-
BOOST_TEST_EQ(what, "N/A");
191-
#else
192199
BOOST_TEST(type.find("std::runtime_error") != std::string::npos);
193200
BOOST_TEST_EQ(what, "test exception");
194-
#endif
195201
}
196202
);
197203
}
@@ -202,7 +208,7 @@ int main()
202208
{
203209
return leaf::new_error(std::make_exception_ptr(42));
204210
},
205-
[](leaf::diagnostic_details const & dd)
211+
[](leaf::diagnostic_details const & dd, std::exception_ptr *)
206212
{
207213
nlohmann::ordered_json j;
208214
nlohmann_writer w(j);
@@ -214,15 +220,12 @@ int main()
214220
auto const & ep = jc["std::exception_ptr"];
215221
std::string type = ep["typeid.name"].get<std::string>();
216222
std::string what = ep["what"].get<std::string>();
217-
#ifdef BOOST_LEAF_NO_EXCEPTIONS
218-
BOOST_TEST(type == "<<unknown>>" || type == "<<empty>>");
219-
#else
220223
BOOST_TEST_EQ(type, "<<unknown>>");
221-
#endif
222224
BOOST_TEST_EQ(what, "N/A");
223225
}
224226
);
225227
}
228+
#endif
226229

227230
return boost::report_errors();
228231
}

0 commit comments

Comments
 (0)