Skip to content

Commit

Permalink
Add serialization of manifest contacts and summary (#291)
Browse files Browse the repository at this point in the history
* Add serialization of manifest contacts and summary

* Fix merge conflict

* Fix formatting
  • Loading branch information
ras0219-msft authored Dec 3, 2021
1 parent 56228f8 commit 59307f0
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 23 deletions.
4 changes: 4 additions & 0 deletions include/vcpkg-test/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,9 @@ namespace vcpkg::Test
void check_json_eq(const Json::Object& l, const Json::Object& r);
void check_json_eq(const Json::Array& l, const Json::Array& r);

void check_json_eq_ordered(const Json::Value& l, const Json::Value& r);
void check_json_eq_ordered(const Json::Object& l, const Json::Object& r);
void check_json_eq_ordered(const Json::Array& l, const Json::Array& r);

const Path& base_temporary_directory() noexcept;
}
32 changes: 22 additions & 10 deletions src/vcpkg-test/manifests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,27 +708,31 @@ TEST_CASE ("manifest embed configuration", "[manifests]")

TEST_CASE ("manifest construct maximum", "[manifests]")
{
auto m_pgh = test_parse_manifest(R"json({
auto raw = R"json({
"name": "s",
"version-string": "v",
"maintainers": ["m"],
"maintainers": "m",
"contacts": { "a": { "aa": "aa" } },
"summary": "d",
"description": "d",
"builtin-baseline": "123",
"dependencies": ["bd"],
"default-features": ["df"],
"features": {
"iroh" : {
"$comment": "hello",
"description": "zuko's uncle",
"dependencies": [
"firebending",
{
"name": "tea"
},
{
"name": "order.white-lotus",
"features": [ "the-ancient-ways" ],
"platform": "!(windows & arm)"
},
{
"$extra": [],
"$my": [],
"name": "tea"
}
]
},
Expand All @@ -737,9 +741,16 @@ TEST_CASE ("manifest construct maximum", "[manifests]")
"supports": "!(windows & arm)"
}
}
})json");
REQUIRE(m_pgh.has_value());
auto& pgh = **m_pgh.get();
})json";
auto object = parse_json_object(raw);
auto res = SourceControlFile::parse_manifest_object("<test manifest>", object);
if (!res.has_value())
{
print_error_message(res.error());
}
REQUIRE(res.has_value());
REQUIRE(*res.get() != nullptr);
auto& pgh = **res.get();

REQUIRE(pgh.core_paragraph->name == "s");
REQUIRE(pgh.core_paragraph->version == "v");
Expand All @@ -762,6 +773,7 @@ TEST_CASE ("manifest construct maximum", "[manifests]")
REQUIRE(pgh.core_paragraph->default_features.size() == 1);
REQUIRE(pgh.core_paragraph->default_features[0] == "df");
REQUIRE(pgh.core_paragraph->supports_expression.is_empty());
REQUIRE(pgh.core_paragraph->builtin_baseline == "123");

REQUIRE(pgh.feature_paragraphs.size() == 2);

Expand Down Expand Up @@ -793,7 +805,7 @@ TEST_CASE ("manifest construct maximum", "[manifests]")
REQUIRE(pgh.feature_paragraphs[1]->supports_expression.evaluate(
{{"VCPKG_CMAKE_SYSTEM_NAME", ""}, {"VCPKG_TARGET_ARCHITECTURE", "x86"}}));

REQUIRE(!pgh.check_against_feature_flags({}, feature_flags_without_versioning));
check_json_eq_ordered(serialize_manifest(pgh), object);
}

TEST_CASE ("SourceParagraph manifest two dependencies", "[manifests]")
Expand Down Expand Up @@ -956,7 +968,7 @@ TEST_CASE ("SourceParagraph manifest non-string supports", "[manifests]")
REQUIRE_FALSE(m_pgh.has_value());
}

TEST_CASE ("Serialize all the ports", "[manifests]")
TEST_CASE ("Serialize all the ports", "[all-manifests]")
{
std::vector<std::string> args_list = {"format-manifest"};
auto& fs = get_real_filesystem();
Expand Down
57 changes: 44 additions & 13 deletions src/vcpkg-test/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ namespace vcpkg::Test
return BASE_TEMPORARY_DIRECTORY;
}

static void check_json_eq(const Json::Value& l, const Json::Value& r, std::string& path);
static void check_json_eq(const Json::Value& l, const Json::Value& r, std::string& path, bool ordered);

static void check_json_eq(const Json::Object& l, const Json::Object& r, std::string& path)
static void check_json_eq(const Json::Object& l, const Json::Object& r, std::string& path, bool ordered)
{
std::set<std::string> keys_l;
for (auto&& kv : l)
Expand All @@ -124,6 +124,19 @@ namespace vcpkg::Test
{
INFO(path)
CHECK(keys_l == keys_r);
if (ordered && keys_l == keys_r)
{
size_t index = 0;
for (auto i_l = l.begin(), i_r = r.begin(); i_l != l.end() && i_r != r.end(); ++i_l, ++i_r)
{
if ((*i_l).first != (*i_r).first)
{
INFO("index = " << index);
CHECK((*i_l).first.to_string() == (*i_r).first.to_string());
}
++index;
}
}
}
const size_t orig_path_len = path.size();
for (auto&& key : keys_l)
Expand All @@ -134,12 +147,12 @@ namespace vcpkg::Test
{
path.push_back('.');
path.append(key);
check_json_eq(*vl, *vr, path);
check_json_eq(*vl, *vr, path, ordered);
path.resize(orig_path_len);
}
}
}
static void check_json_eq(const Json::Array& l, const Json::Array& r, std::string& path)
static void check_json_eq(const Json::Array& l, const Json::Array& r, std::string& path, bool ordered)
{
{
INFO(path)
Expand All @@ -149,41 +162,59 @@ namespace vcpkg::Test
for (size_t i = 0; i < l.size() && i < r.size(); ++i)
{
Strings::append(path, '[', i, ']');
check_json_eq(r[i], l[i], path);
check_json_eq(r[i], l[i], path, ordered);
path.resize(orig_path_len);
}
}
static void check_json_eq(const Json::Value& l, const Json::Value& r, std::string& path)
static void check_json_eq(const Json::Value& l, const Json::Value& r, std::string& path, bool ordered)
{
if (l.is_object() && r.is_object())
{
check_json_eq(l.object(), r.object(), path);
check_json_eq(l.object(), r.object(), path, ordered);
}
else if (l.is_array() && r.is_array())
{
check_json_eq(l.array(), r.array(), path);
check_json_eq(l.array(), r.array(), path, ordered);
}
else
else if (l != r)
{
INFO(path);
REQUIRE(l == r);
INFO("l = " << Json::stringify(l, {}));
INFO("r = " << Json::stringify(r, {}));
CHECK(false);
}
}

void check_json_eq(const Json::Value& l, const Json::Value& r)
{
std::string path = "$";
check_json_eq(l, r, path);
check_json_eq(l, r, path, false);
}
void check_json_eq(const Json::Object& l, const Json::Object& r)
{
std::string path = "$";
check_json_eq(l, r, path);
check_json_eq(l, r, path, false);
}
void check_json_eq(const Json::Array& l, const Json::Array& r)
{
std::string path = "$";
check_json_eq(l, r, path);
check_json_eq(l, r, path, false);
}

void check_json_eq_ordered(const Json::Value& l, const Json::Value& r)
{
std::string path = "$";
check_json_eq(l, r, path, true);
}
void check_json_eq_ordered(const Json::Object& l, const Json::Object& r)
{
std::string path = "$";
check_json_eq(l, r, path, true);
}
void check_json_eq_ordered(const Json::Array& l, const Json::Array& r)
{
std::string path = "$";
check_json_eq(l, r, path, true);
}

}
5 changes: 5 additions & 0 deletions src/vcpkg/sourceparagraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,11 @@ namespace vcpkg
debug);

serialize_paragraph(obj, ManifestDeserializer::MAINTAINERS, scf.core_paragraph->maintainers);
if (scf.core_paragraph->contacts.size() > 0)
{
obj.insert(ManifestDeserializer::CONTACTS, scf.core_paragraph->contacts);
}
serialize_paragraph(obj, ManifestDeserializer::SUMMARY, scf.core_paragraph->summary);
serialize_paragraph(obj, ManifestDeserializer::DESCRIPTION, scf.core_paragraph->description);

serialize_optional_string(obj, ManifestDeserializer::HOMEPAGE, scf.core_paragraph->homepage);
Expand Down

0 comments on commit 59307f0

Please sign in to comment.