From bbbbfb9e79a201a7c479fbc9e8ca14cd8569703d Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Wed, 28 Feb 2018 12:15:16 -0800 Subject: [PATCH] [vcpkg] Add tests for create_export_plan and remove unused arguments --- toolsrc/include/vcpkg/dependencies.h | 6 +- toolsrc/src/tests.plan.cpp | 94 ++++++++++++++++++++++++++++ toolsrc/src/vcpkg/dependencies.cpp | 19 ++---- toolsrc/src/vcpkg/export.cpp | 9 ++- 4 files changed, 106 insertions(+), 22 deletions(-) diff --git a/toolsrc/include/vcpkg/dependencies.h b/toolsrc/include/vcpkg/dependencies.h index 6e02e4efd9c..fadb8cc7eb4 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 create_remove_plan(const std::vector& specs, const StatusParagraphs& status_db); - std::vector create_export_plan(const PortFileProvider& port_file_provider, - const VcpkgPaths& paths, - const std::vector& specs, + std::vector create_export_plan(const std::vector& specs, const StatusParagraphs& status_db); std::vector create_feature_install_plan(const std::unordered_map& map, diff --git a/toolsrc/src/tests.plan.cpp b/toolsrc/src/tests.plan.cpp index aae4d2ee4f6..08d3c1dab17 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 + { + TEST_METHOD(basic_export_scheme) + { + std::vector> 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> 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> 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> 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 f4a371a2e0a..1f853014b62 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 create_export_plan(const PortFileProvider& port_file_provider, - const VcpkgPaths& paths, - const std::vector& specs, + std::vector create_export_plan(const std::vector& specs, const StatusParagraphs& status_db) { struct ExportAdjacencyProvider final : Graphs::AdjacencyProvider { - const VcpkgPaths& paths; const StatusParagraphs& status_db; - const PortFileProvider& provider; const std::unordered_set& specs_as_set; - ExportAdjacencyProvider(const VcpkgPaths& p, - const StatusParagraphs& s, - const PortFileProvider& prov, - const std::unordered_set& specs_as_set) - : paths(p), status_db(s), provider(prov), specs_as_set(specs_as_set) + ExportAdjacencyProvider(const StatusParagraphs& s, const std::unordered_set& specs_as_set) + : status_db(s), specs_as_set(specs_as_set) { } @@ -394,8 +387,8 @@ namespace vcpkg::Dependencies }; const std::unordered_set specs_as_set(specs.cbegin(), specs.cend()); - std::vector toposort = Graphs::topological_sort( - specs, ExportAdjacencyProvider{paths, status_db, port_file_provider, specs_as_set}); + std::vector 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 a9c407dd86a..83105800785 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>& group_by_plan_type) { static constexpr std::array 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 export_plan = - Dependencies::create_export_plan(provider, paths, opts.specs, status_db); + std::vector 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> 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.");