tests: explicitely call optional<T>::has_value in dataFromSysrepo
In dateFromSysrepo test function we check if getData return value
(std::optional) actually has value by calling REQUIRE(data).
However, if the std::optional does not have value and the REQUIRE fails
something like this gets printed:
velia/tests/test_sysrepo_helpers.h:21: FATAL ERROR: REQUIRE( data ) is NOT correct!
values: REQUIRE( {?} )
That is because doctest does not know how to print instances of
std::optional. A minor change to the REQUIRE expression seems like a
better idea than performing some template magic to allow doctest to
start printing std::optional objects.
And now the message shows a less confusing message (at least for me).
velia/tests/test_sysrepo_helpers.h:21: FATAL ERROR: REQUIRE( data.has_value() ) is NOT correct!
values: REQUIRE( false )
Change-Id: Id6f02f9efea1338328b4a53540296e012c6e573d
diff --git a/tests/test_sysrepo_helpers.h b/tests/test_sysrepo_helpers.h
index b1959a7..abec915 100644
--- a/tests/test_sysrepo_helpers.h
+++ b/tests/test_sysrepo_helpers.h
@@ -18,7 +18,7 @@
spdlog::get("main")->error("dataFrom {}", xpath);
std::map<std::string, std::string> res;
auto data = session.getData(xpath + "/*");
- REQUIRE(data);
+ REQUIRE(data.has_value());
for (const auto& sibling : data->findXPath(xpath)) { // Use findXPath here in case the xpath is list without keys.
for (const auto& node : sibling.childrenDfs()) {
const auto briefXPath = std::string(node.path()).substr(boost::algorithm::ends_with(xpath, ":*") ? xpath.size() - 1 : xpath.size());