aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schumacher <roschuma@microsoft.com>2018-02-28 12:15:16 -0800
committerRobert Schumacher <roschuma@microsoft.com>2018-02-28 12:15:16 -0800
commitbbbbfb9e79a201a7c479fbc9e8ca14cd8569703d (patch)
tree6d2335cc0c17ebc4d0a0a566c16f293a3bcfc45f
parentef4febc7ef08d1aaa3fb97efadf09e2ad2b9464d (diff)
downloadvcpkg-bbbbfb9e79a201a7c479fbc9e8ca14cd8569703d.tar.gz
vcpkg-bbbbfb9e79a201a7c479fbc9e8ca14cd8569703d.zip
[vcpkg] Add tests for create_export_plan and remove unused arguments
-rw-r--r--toolsrc/include/vcpkg/dependencies.h6
-rw-r--r--toolsrc/src/tests.plan.cpp94
-rw-r--r--toolsrc/src/vcpkg/dependencies.cpp19
-rw-r--r--toolsrc/src/vcpkg/export.cpp9
4 files changed, 106 insertions, 22 deletions
diff --git a/toolsrc/include/vcpkg/dependencies.h b/toolsrc/include/vcpkg/dependencies.h
index 6e02e4efd..fadb8cc7e 100644
--- a/toolsrc/include/vcpkg/dependencies.h
+++ b/toolsrc/include/vcpkg/dependencies.h
@@ -93,7 +93,7 @@ namespace vcpkg::Dependencies
enum class ExportPlanType
{
UNKNOWN,
- PORT_AVAILABLE_BUT_NOT_BUILT,
+ NOT_BUILT,
ALREADY_BUILT
};
@@ -165,9 +165,7 @@ namespace vcpkg::Dependencies
std::vector<RemovePlanAction> create_remove_plan(const std::vector<PackageSpec>& specs,
const StatusParagraphs& status_db);
- std::vector<ExportPlanAction> create_export_plan(const PortFileProvider& port_file_provider,
- const VcpkgPaths& paths,
- const std::vector<PackageSpec>& specs,
+ std::vector<ExportPlanAction> create_export_plan(const std::vector<PackageSpec>& specs,
const StatusParagraphs& status_db);
std::vector<AnyAction> create_feature_install_plan(const std::unordered_map<std::string, SourceControlFile>& map,
diff --git a/toolsrc/src/tests.plan.cpp b/toolsrc/src/tests.plan.cpp
index aae4d2ee4..08d3c1dab 100644
--- a/toolsrc/src/tests.plan.cpp
+++ b/toolsrc/src/tests.plan.cpp
@@ -997,4 +997,98 @@ namespace UnitTest1
features_check(&plan[1], "a", {"core", "a1"});
}
};
+
+ class ExportPlanTests : public TestClass<ExportPlanTests>
+ {
+ TEST_METHOD(basic_export_scheme)
+ {
+ std::vector<std::unique_ptr<StatusParagraph>> pghs;
+ pghs.push_back(make_status_pgh("a"));
+ StatusParagraphs status_db(std::move(pghs));
+
+ PackageSpecMap spec_map(Triplet::X86_WINDOWS);
+ auto spec_a = spec_map.emplace("a");
+
+ auto plan = Dependencies::create_export_plan({spec_a}, status_db);
+
+ Assert::AreEqual(size_t(1), plan.size());
+ Assert::AreEqual("a", plan[0].spec.name().c_str());
+ Assert::IsTrue(plan[0].plan_type == Dependencies::ExportPlanType::ALREADY_BUILT);
+ }
+
+ TEST_METHOD(basic_export_scheme_with_recurse)
+ {
+ 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));
+
+ PackageSpecMap spec_map(Triplet::X86_WINDOWS);
+ auto spec_a = spec_map.emplace("a");
+ auto spec_b = spec_map.emplace("b", "a");
+
+ auto plan = Dependencies::create_export_plan({spec_b}, status_db);
+
+ Assert::AreEqual(size_t(2), plan.size());
+ Assert::AreEqual("a", plan[0].spec.name().c_str());
+ Assert::IsTrue(plan[0].plan_type == Dependencies::ExportPlanType::ALREADY_BUILT);
+
+ Assert::AreEqual("b", plan[1].spec.name().c_str());
+ Assert::IsTrue(plan[1].plan_type == Dependencies::ExportPlanType::ALREADY_BUILT);
+ }
+
+ TEST_METHOD(basic_export_scheme_with_bystander)
+ {
+ std::vector<std::unique_ptr<StatusParagraph>> pghs;
+ pghs.push_back(make_status_pgh("a"));
+ pghs.push_back(make_status_pgh("b"));
+ StatusParagraphs status_db(std::move(pghs));
+
+ PackageSpecMap spec_map(Triplet::X86_WINDOWS);
+ auto spec_a = spec_map.emplace("a");
+ auto spec_b = spec_map.emplace("b", "a");
+
+ auto plan = Dependencies::create_export_plan({spec_a}, status_db);
+
+ Assert::AreEqual(size_t(1), plan.size());
+ Assert::AreEqual("a", plan[0].spec.name().c_str());
+ Assert::IsTrue(plan[0].plan_type == Dependencies::ExportPlanType::ALREADY_BUILT);
+ }
+
+ TEST_METHOD(basic_export_scheme_with_missing)
+ {
+ StatusParagraphs status_db;
+
+ PackageSpecMap spec_map(Triplet::X86_WINDOWS);
+ auto spec_a = spec_map.emplace("a");
+
+ auto plan = Dependencies::create_export_plan({spec_a}, status_db);
+
+ Assert::AreEqual(size_t(1), plan.size());
+ Assert::AreEqual("a", plan[0].spec.name().c_str());
+ Assert::IsTrue(plan[0].plan_type == Dependencies::ExportPlanType::NOT_BUILT);
+ }
+
+ TEST_METHOD(basic_upgrade_scheme_with_features)
+ {
+ std::vector<std::unique_ptr<StatusParagraph>> pghs;
+ pghs.push_back(make_status_pgh("b"));
+ pghs.push_back(make_status_pgh("a"));
+ pghs.push_back(make_status_feature_pgh("a", "a1", "b[core]"));
+ StatusParagraphs status_db(std::move(pghs));
+
+ PackageSpecMap spec_map(Triplet::X86_WINDOWS);
+ auto spec_a = spec_map.emplace("a", "", {{"a1", ""}});
+
+ auto plan = Dependencies::create_export_plan({spec_a}, status_db);
+
+ Assert::AreEqual(size_t(2), plan.size());
+
+ Assert::AreEqual("b", plan[0].spec.name().c_str());
+ Assert::IsTrue(plan[0].plan_type == Dependencies::ExportPlanType::ALREADY_BUILT);
+
+ Assert::AreEqual("a", plan[1].spec.name().c_str());
+ Assert::IsTrue(plan[1].plan_type == Dependencies::ExportPlanType::ALREADY_BUILT);
+ }
+ };
}
diff --git a/toolsrc/src/vcpkg/dependencies.cpp b/toolsrc/src/vcpkg/dependencies.cpp
index f4a371a2e..1f853014b 100644
--- a/toolsrc/src/vcpkg/dependencies.cpp
+++ b/toolsrc/src/vcpkg/dependencies.cpp
@@ -223,7 +223,7 @@ namespace vcpkg::Dependencies
}
ExportPlanAction::ExportPlanAction(const PackageSpec& spec, const RequestType& request_type)
- : spec(spec), plan_type(ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT), request_type(request_type)
+ : spec(spec), plan_type(ExportPlanType::NOT_BUILT), request_type(request_type)
{
}
@@ -349,23 +349,16 @@ namespace vcpkg::Dependencies
return Graphs::topological_sort(specs, RemoveAdjacencyProvider{status_db, installed_ports, specs_as_set});
}
- std::vector<ExportPlanAction> create_export_plan(const PortFileProvider& port_file_provider,
- const VcpkgPaths& paths,
- const std::vector<PackageSpec>& specs,
+ std::vector<ExportPlanAction> create_export_plan(const std::vector<PackageSpec>& specs,
const StatusParagraphs& status_db)
{
struct ExportAdjacencyProvider final : Graphs::AdjacencyProvider<PackageSpec, ExportPlanAction>
{
- const VcpkgPaths& paths;
const StatusParagraphs& status_db;
- const PortFileProvider& provider;
const std::unordered_set<PackageSpec>& specs_as_set;
- ExportAdjacencyProvider(const VcpkgPaths& p,
- const StatusParagraphs& s,
- const PortFileProvider& prov,
- const std::unordered_set<PackageSpec>& specs_as_set)
- : paths(p), status_db(s), provider(prov), specs_as_set(specs_as_set)
+ ExportAdjacencyProvider(const StatusParagraphs& s, const std::unordered_set<PackageSpec>& specs_as_set)
+ : status_db(s), specs_as_set(specs_as_set)
{
}
@@ -394,8 +387,8 @@ namespace vcpkg::Dependencies
};
const std::unordered_set<PackageSpec> specs_as_set(specs.cbegin(), specs.cend());
- std::vector<ExportPlanAction> toposort = Graphs::topological_sort(
- specs, ExportAdjacencyProvider{paths, status_db, port_file_provider, specs_as_set});
+ std::vector<ExportPlanAction> toposort =
+ Graphs::topological_sort(specs, ExportAdjacencyProvider{status_db, specs_as_set});
return toposort;
}
diff --git a/toolsrc/src/vcpkg/export.cpp b/toolsrc/src/vcpkg/export.cpp
index a9c407dd8..831058007 100644
--- a/toolsrc/src/vcpkg/export.cpp
+++ b/toolsrc/src/vcpkg/export.cpp
@@ -69,7 +69,7 @@ namespace vcpkg::Export
static void print_plan(const std::map<ExportPlanType, std::vector<const ExportPlanAction*>>& group_by_plan_type)
{
static constexpr std::array<ExportPlanType, 2> ORDER = {ExportPlanType::ALREADY_BUILT,
- ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT};
+ ExportPlanType::NOT_BUILT};
static constexpr Build::BuildPackageOptions build_options = {Build::UseHeadVersion::NO,
Build::AllowDownloads::YES};
@@ -92,7 +92,7 @@ namespace vcpkg::Export
case ExportPlanType::ALREADY_BUILT:
System::println("The following packages are already built and will be exported:\n%s", as_string);
continue;
- case ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT:
+ case ExportPlanType::NOT_BUILT:
System::println("The following packages need to be built:\n%s", as_string);
continue;
default: Checks::unreachable(VCPKG_LINE_INFO);
@@ -486,8 +486,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
// create the plan
const StatusParagraphs status_db = database_load_check(paths);
Dependencies::PathsPortFileProvider provider(paths);
- std::vector<ExportPlanAction> export_plan =
- Dependencies::create_export_plan(provider, paths, opts.specs, status_db);
+ std::vector<ExportPlanAction> export_plan = Dependencies::create_export_plan(opts.specs, status_db);
Checks::check_exit(VCPKG_LINE_INFO, !export_plan.empty(), "Export plan cannot be empty");
std::map<ExportPlanType, std::vector<const ExportPlanAction*>> group_by_plan_type;
@@ -505,7 +504,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
"Additional packages (*) need to be exported to complete this operation.");
}
- const auto it = group_by_plan_type.find(ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT);
+ const auto it = group_by_plan_type.find(ExportPlanType::NOT_BUILT);
if (it != group_by_plan_type.cend() && !it->second.empty())
{
System::println(System::Color::error, "There are packages that have not been built.");