Change array_elements to return empty vector rather than nullopt.
MODIFY
include/vcpkg/base/jsonreader.h
include/vcpkg/base/jsonreader.h
@@ -172,6 +172,8 @@ namespace vcpkg::Json
Optional<std::vector<Type>> array_elements(const Array& arr, IDeserializer<Type>& visitor)
{
Optional<std::vector<Type>> result{std::vector<Type>()};
+ auto& result_vec = *result.get();
+ bool success = true;
PathGuard guard{m_path};
for (size_t i = 0; i < arr.size(); ++i)
{
@@ -179,15 +181,16 @@ namespace vcpkg::Json
auto opt = visitor.visit(*this, arr[i]);
if (auto parsed = opt.get())
{
- if (auto result_vec = result.get())
+ if (success)
{
- result_vec->push_back(std::move(*parsed));
+ result_vec.push_back(std::move(*parsed));
}
}
else
{
this->add_expected_type_error(visitor.type_name());
- result.clear();
+ result_vec.clear();
+ success = false;
}
}

MODIFY
src/vcpkg-test/registries.cpp
src/vcpkg-test/registries.cpp
@@ -279,7 +279,7 @@ TEST_CASE ("filesystem_version_db_parsing", "[registries]")
}
]
)json");
- CHECK(!r.visit(test_json, filesystem_version_db).has_value());
+ CHECK(r.visit(test_json, filesystem_version_db).value_or_exit(VCPKG_LINE_INFO).empty());
CHECK(!r.errors().empty());
}
@@ -294,7 +294,7 @@ TEST_CASE ("filesystem_version_db_parsing", "[registries]")
}
]
)json");
- CHECK(!r.visit(test_json, filesystem_version_db).has_value());
+ CHECK(r.visit(test_json, filesystem_version_db).value_or_exit(VCPKG_LINE_INFO).empty());
CHECK(!r.errors().empty());
}
@@ -309,7 +309,7 @@ TEST_CASE ("filesystem_version_db_parsing", "[registries]")
}
]
)json");
- CHECK(!r.visit(test_json, filesystem_version_db).has_value());
+ CHECK(r.visit(test_json, filesystem_version_db).value_or_exit(VCPKG_LINE_INFO).empty());
CHECK(!r.errors().empty());
}
@@ -324,7 +324,7 @@ TEST_CASE ("filesystem_version_db_parsing", "[registries]")
}
]
)json");
- CHECK(!r.visit(test_json, filesystem_version_db).has_value());
+ CHECK(r.visit(test_json, filesystem_version_db).value_or_exit(VCPKG_LINE_INFO).empty());
CHECK(!r.errors().empty());
}
@@ -339,7 +339,7 @@ TEST_CASE ("filesystem_version_db_parsing", "[registries]")
}
]
)json");
- CHECK(!r.visit(test_json, filesystem_version_db).has_value());
+ CHECK(r.visit(test_json, filesystem_version_db).value_or_exit(VCPKG_LINE_INFO).empty());
CHECK(!r.errors().empty());
}
@@ -354,7 +354,7 @@ TEST_CASE ("filesystem_version_db_parsing", "[registries]")
}
]
)json");
- CHECK(!r.visit(test_json, filesystem_version_db).has_value());
+ CHECK(r.visit(test_json, filesystem_version_db).value_or_exit(VCPKG_LINE_INFO).empty());
CHECK(!r.errors().empty());
}
@@ -369,7 +369,7 @@ TEST_CASE ("filesystem_version_db_parsing", "[registries]")
}
]
)json");
- CHECK(!r.visit(test_json, filesystem_version_db).has_value());
+ CHECK(r.visit(test_json, filesystem_version_db).value_or_exit(VCPKG_LINE_INFO).empty());
CHECK(!r.errors().empty());
}
@@ -384,7 +384,7 @@ TEST_CASE ("filesystem_version_db_parsing", "[registries]")
}
]
)json");
- CHECK(!r.visit(test_json, filesystem_version_db).has_value());
+ CHECK(r.visit(test_json, filesystem_version_db).value_or_exit(VCPKG_LINE_INFO).empty());
CHECK(!r.errors().empty());
}
@@ -399,7 +399,7 @@ TEST_CASE ("filesystem_version_db_parsing", "[registries]")
}
]
)json");
- CHECK(!r.visit(test_json, filesystem_version_db).has_value());
+ CHECK(r.visit(test_json, filesystem_version_db).value_or_exit(VCPKG_LINE_INFO).empty());
CHECK(!r.errors().empty());
}
}

Change array_elements to return empty vector rather than nullopt. (#146)