[vcpkg] Add tests for remove plans.

This commit is contained in:
Robert Schumacher 2017-11-06 14:22:10 -08:00
parent f1ab66b960
commit eb99b0c705
3 changed files with 171 additions and 103 deletions

View File

@ -38,112 +38,112 @@ namespace Microsoft::VisualStudio::CppUnitTestFramework
namespace UnitTest1
{
class InstallPlanTests : public TestClass<InstallPlanTests>
static std::unique_ptr<SourceControlFile> make_control_file(
const char* name,
const char* depends,
const std::vector<std::pair<const char*, const char*>>& features = {})
{
static std::unique_ptr<SourceControlFile> make_control_file(
const char* name,
const char* depends,
using Pgh = std::unordered_map<std::string, std::string>;
std::vector<Pgh> scf_pghs;
scf_pghs.push_back(Pgh{
{ "Source", name },
{ "Version", "0" },
{ "Build-Depends", depends },
});
for (auto&& feature : features)
{
scf_pghs.push_back(Pgh{
{ "Feature", feature.first },
{ "Description", "feature" },
{ "Build-Depends", feature.second },
});
}
auto m_pgh = vcpkg::SourceControlFile::parse_control_file(std::move(scf_pghs));
Assert::IsTrue(m_pgh.has_value());
return std::move(*m_pgh.get());
}
static void features_check(Dependencies::AnyAction* install_action,
std::string pkg_name,
std::vector<std::string> vec,
const Triplet& triplet = Triplet::X86_WINDOWS)
{
const auto& plan = install_action->install_plan.value_or_exit(VCPKG_LINE_INFO);
const auto& feature_list = plan.feature_list;
Assert::AreEqual(plan.spec.triplet().to_string().c_str(), triplet.to_string().c_str());
Assert::AreEqual(pkg_name.c_str(),
(*plan.any_paragraph.source_control_file.get())->core_paragraph->name.c_str());
Assert::AreEqual(size_t(vec.size()), feature_list.size());
for (auto&& feature_name : vec)
{
if (feature_name == "core" || feature_name == "")
{
Assert::IsTrue(Util::find(feature_list, "core") != feature_list.end() ||
Util::find(feature_list, "") != feature_list.end());
continue;
}
Assert::IsTrue(Util::find(feature_list, feature_name) != feature_list.end());
}
}
static void remove_plan_check(Dependencies::AnyAction* remove_action,
std::string pkg_name,
const Triplet& triplet = Triplet::X86_WINDOWS)
{
const auto& plan = remove_action->remove_plan.value_or_exit(VCPKG_LINE_INFO);
Assert::AreEqual(plan.spec.triplet().to_string().c_str(), triplet.to_string().c_str());
Assert::AreEqual(pkg_name.c_str(), plan.spec.name().c_str());
}
static std::unique_ptr<StatusParagraph> make_status_pgh(const char* name, const char* depends = "")
{
using Pgh = std::unordered_map<std::string, std::string>;
return std::make_unique<StatusParagraph>(Pgh{ { "Package", name },
{ "Version", "1" },
{ "Architecture", "x86-windows" },
{ "Multi-Arch", "same" },
{ "Depends", depends },
{ "Status", "install ok installed" } });
}
static std::unique_ptr<StatusParagraph> make_status_feature_pgh(const char* name,
const char* feature,
const char* depends = "")
{
using Pgh = std::unordered_map<std::string, std::string>;
return std::make_unique<StatusParagraph>(Pgh{ { "Package", name },
{ "Version", "1" },
{ "Feature", feature },
{ "Architecture", "x86-windows" },
{ "Multi-Arch", "same" },
{ "Depends", depends },
{ "Status", "install ok installed" } });
}
struct PackageSpecMap
{
std::unordered_map<std::string, SourceControlFile> map;
Triplet triplet;
PackageSpecMap(const Triplet& t) { triplet = t; }
PackageSpec emplace(const char* name,
const char* depends = "",
const std::vector<std::pair<const char*, const char*>>& features = {})
{
using Pgh = std::unordered_map<std::string, std::string>;
std::vector<Pgh> scf_pghs;
scf_pghs.push_back(Pgh{
{"Source", name},
{"Version", "0"},
{"Build-Depends", depends},
});
for (auto&& feature : features)
{
scf_pghs.push_back(Pgh{
{"Feature", feature.first},
{"Description", "feature"},
{"Build-Depends", feature.second},
});
}
auto m_pgh = vcpkg::SourceControlFile::parse_control_file(std::move(scf_pghs));
Assert::IsTrue(m_pgh.has_value());
return std::move(*m_pgh.get());
return emplace(std::move(*make_control_file(name, depends, features)));
}
static void features_check(Dependencies::AnyAction* install_action,
std::string pkg_name,
std::vector<std::string> vec,
const Triplet& triplet = Triplet::X86_WINDOWS)
PackageSpec emplace(vcpkg::SourceControlFile&& scf)
{
const auto& plan = install_action->install_plan.value_or_exit(VCPKG_LINE_INFO);
const auto& feature_list = plan.feature_list;
Assert::AreEqual(plan.spec.triplet().to_string().c_str(), triplet.to_string().c_str());
Assert::AreEqual(pkg_name.c_str(),
(*plan.any_paragraph.source_control_file.get())->core_paragraph->name.c_str());
Assert::AreEqual(size_t(vec.size()), feature_list.size());
for (auto&& feature_name : vec)
{
if (feature_name == "core" || feature_name == "")
{
Assert::IsTrue(Util::find(feature_list, "core") != feature_list.end() ||
Util::find(feature_list, "") != feature_list.end());
continue;
}
Assert::IsTrue(Util::find(feature_list, feature_name) != feature_list.end());
}
auto spec = PackageSpec::from_name_and_triplet(scf.core_paragraph->name, triplet);
Assert::IsTrue(spec.has_value());
map.emplace(scf.core_paragraph->name, std::move(scf));
return PackageSpec{ *spec.get() };
}
};
static void remove_plan_check(Dependencies::AnyAction* remove_action,
std::string pkg_name,
const Triplet& triplet = Triplet::X86_WINDOWS)
{
const auto& plan = remove_action->remove_plan.value_or_exit(VCPKG_LINE_INFO);
Assert::AreEqual(plan.spec.triplet().to_string().c_str(), triplet.to_string().c_str());
Assert::AreEqual(pkg_name.c_str(), plan.spec.name().c_str());
}
static std::unique_ptr<StatusParagraph> make_status_pgh(const char* name, const char* depends = "")
{
using Pgh = std::unordered_map<std::string, std::string>;
return std::make_unique<StatusParagraph>(Pgh{{"Package", name},
{"Version", "1"},
{"Architecture", "x86-windows"},
{"Multi-Arch", "same"},
{"Depends", depends},
{"Status", "install ok installed"}});
}
static std::unique_ptr<StatusParagraph> make_status_feature_pgh(const char* name,
const char* feature,
const char* depends = "")
{
using Pgh = std::unordered_map<std::string, std::string>;
return std::make_unique<StatusParagraph>(Pgh{{"Package", name},
{"Version", "1"},
{"Feature", feature},
{"Architecture", "x86-windows"},
{"Multi-Arch", "same"},
{"Depends", depends},
{"Status", "install ok installed"}});
}
struct PackageSpecMap
{
std::unordered_map<std::string, SourceControlFile> map;
Triplet triplet;
PackageSpecMap(const Triplet& t) { triplet = t; }
PackageSpec emplace(const char* name,
const char* depends = "",
const std::vector<std::pair<const char*, const char*>>& features = {})
{
return emplace(std::move(*make_control_file(name, depends, features)));
}
PackageSpec emplace(vcpkg::SourceControlFile&& scf)
{
auto spec = PackageSpec::from_name_and_triplet(scf.core_paragraph->name, triplet);
Assert::IsTrue(spec.has_value());
map.emplace(scf.core_paragraph->name, std::move(scf));
return PackageSpec{*spec.get()};
}
};
class InstallPlanTests : public TestClass<InstallPlanTests>
{
TEST_METHOD(basic_install_scheme)
{
std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs;
@ -490,4 +490,72 @@ namespace UnitTest1
features_check(&install_plan[0], "a", {"0", "1", "core"}, Triplet::X64_WINDOWS);
}
};
static PackageSpec unsafe_pspec(std::string name, Triplet t = Triplet::X86_WINDOWS)
{
auto m_ret = PackageSpec::from_name_and_triplet(name, t);
Assert::IsTrue(m_ret.has_value());
return m_ret.value_or_exit(VCPKG_LINE_INFO);
}
class RemovePlanTests : public TestClass<RemovePlanTests>
{
TEST_METHOD(basic_remove_scheme)
{
std::vector<std::unique_ptr<StatusParagraph>> pghs;
pghs.push_back(make_status_pgh("a"));
StatusParagraphs status_db(std::move(pghs));
auto remove_plan = Dependencies::create_remove_plan({ unsafe_pspec("a") }, status_db);
Assert::AreEqual(size_t(1), remove_plan.size());
Assert::AreEqual("a", remove_plan[0].spec.name().c_str());
}
TEST_METHOD(recurse_remove_scheme)
{
std::vector<std::unique_ptr<StatusParagraph>> pghs;
pghs.push_back(make_status_pgh("a"));
pghs.push_back(make_status_pgh("b", "a"));
StatusParagraphs status_db(std::move(pghs));
auto remove_plan = Dependencies::create_remove_plan({ unsafe_pspec("a") }, status_db);
Assert::AreEqual(size_t(2), remove_plan.size());
Assert::AreEqual("b", remove_plan[0].spec.name().c_str());
Assert::AreEqual("a", remove_plan[1].spec.name().c_str());
}
TEST_METHOD(features_depend_remove_scheme)
{
std::vector<std::unique_ptr<StatusParagraph>> pghs;
pghs.push_back(make_status_pgh("a"));
pghs.push_back(make_status_pgh("b"));
pghs.push_back(make_status_feature_pgh("b", "0", "a"));
StatusParagraphs status_db(std::move(pghs));
auto remove_plan = Dependencies::create_remove_plan({ unsafe_pspec("a") }, status_db);
Assert::AreEqual(size_t(2), remove_plan.size());
Assert::AreEqual("b", remove_plan[0].spec.name().c_str());
Assert::AreEqual("a", remove_plan[1].spec.name().c_str());
}
TEST_METHOD(features_depend_remove_scheme_once_removed)
{
std::vector<std::unique_ptr<StatusParagraph>> pghs;
pghs.push_back(make_status_pgh("expat"));
pghs.push_back(make_status_pgh("vtk", "expat"));
pghs.push_back(make_status_pgh("opencv"));
pghs.push_back(make_status_feature_pgh("opencv", "vtk", "vtk"));
StatusParagraphs status_db(std::move(pghs));
auto remove_plan = Dependencies::create_remove_plan({ unsafe_pspec("expat") }, status_db);
Assert::AreEqual(size_t(3), remove_plan.size());
Assert::AreEqual("opencv", remove_plan[0].spec.name().c_str());
Assert::AreEqual("vtk", remove_plan[1].spec.name().c_str());
Assert::AreEqual("expat", remove_plan[2].spec.name().c_str());
}
};
}

View File

@ -23,7 +23,7 @@
<ClCompile Include="..\src\tests.dependencies.cpp" />
<ClCompile Include="..\src\tests.packagespec.cpp" />
<ClCompile Include="..\src\tests.paragraph.cpp" />
<ClCompile Include="..\src\tests.installplan.cpp" />
<ClCompile Include="..\src\tests.plan.cpp" />
<ClCompile Include="..\src\tests.statusparagraphs.cpp" />
</ItemGroup>
<ItemGroup>

View File

@ -15,9 +15,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\tests.installplan.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\tests.arguments.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -33,5 +30,8 @@
<ClCompile Include="..\src\tests.statusparagraphs.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\tests.plan.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>