diff options
| author | Daniel Shaw <t-dansha@microsoft.com> | 2017-07-12 17:40:41 -0700 |
|---|---|---|
| committer | Daniel Shaw <t-dansha@microsoft.com> | 2017-07-14 13:21:25 -0700 |
| commit | 336e25218a73f9b54120e3c35b3d28e6426deeb1 (patch) | |
| tree | 72e2f0fce405def2dcc47b686d4ab7baa5b9afcc /toolsrc/src/test_install_plan.cpp | |
| parent | 7944f9f7779ebbc0923efd27cff268ac23b1c312 (diff) | |
| download | vcpkg-336e25218a73f9b54120e3c35b3d28e6426deeb1.tar.gz vcpkg-336e25218a73f9b54120e3c35b3d28e6426deeb1.zip | |
feature packages graph traversal
Diffstat (limited to 'toolsrc/src/test_install_plan.cpp')
| -rw-r--r-- | toolsrc/src/test_install_plan.cpp | 308 |
1 files changed, 308 insertions, 0 deletions
diff --git a/toolsrc/src/test_install_plan.cpp b/toolsrc/src/test_install_plan.cpp index 93a1436d8..d90e1e523 100644 --- a/toolsrc/src/test_install_plan.cpp +++ b/toolsrc/src/test_install_plan.cpp @@ -1,5 +1,6 @@ #include "CppUnitTest.h" #include "vcpkg_Dependencies.h" +#include "vcpkg_Util.h" using namespace Microsoft::VisualStudio::CppUnitTestFramework; @@ -24,6 +25,35 @@ namespace UnitTest1 return PackageSpec{*spec.get()}; } }; + + static void features_check(Dependencies::AnyAction* install_action, + std::string pkg_name, + std::vector<std::string> vec) + { + const auto& plan = *install_action->install_plan.get(); + const auto& feature_list = plan.feature_list; + + 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* install_action, std::string pkg_name) + { + Assert::AreEqual(pkg_name.c_str(), install_action->remove_plan.get()->spec.name().c_str()); + } + TEST_METHOD(basic_install_scheme) { std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs; @@ -139,5 +169,283 @@ namespace UnitTest1 Assert::AreEqual("b", install_plan[6].spec.name().c_str()); Assert::AreEqual("a", install_plan[7].spec.name().c_str()); } + + TEST_METHOD(basic_feature_test_1) + { + using Pgh = std::unordered_map<std::string, std::string>; + + std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs; + status_paragraphs.push_back(std::make_unique<StatusParagraph>(Pgh{{"Package", "a"}, + {"Default-Features", ""}, + {"Version", "1.3.8"}, + {"Architecture", "x86-windows"}, + {"Multi-Arch", "same"}, + {"Depends", "b, b[beefeatureone]"}, + {"Status", "install ok installed"}})); + status_paragraphs.push_back(std::make_unique<StatusParagraph>(Pgh{{"Package", "b"}, + {"Feature", "beefeatureone"}, + {"Architecture", "x86-windows"}, + {"Multi-Arch", "same"}, + {"Depends", ""}, + {"Status", "install ok installed"}})); + status_paragraphs.push_back(std::make_unique<StatusParagraph>(Pgh{{"Package", "b"}, + {"Default-Features", "beefeatureone"}, + {"Version", "1.3"}, + {"Architecture", "x86-windows"}, + {"Multi-Arch", "same"}, + {"Depends", ""}, + {"Status", "install ok installed"}})); + + PackageSpecMap spec_map; + + auto spec_a = + FullPackageSpec{spec_map.get_package_spec( + {{{"Source", "a"}, {"Version", "1.3.8"}, {"Build-Depends", "b, b[beefeatureone]"}}, + {{"Feature", "featureone"}, + {"Description", "the first feature for a"}, + {"Build-Depends", "b[beefeaturetwo]"}} + + }), + {"featureone"}}; + auto spec_b = FullPackageSpec{spec_map.get_package_spec( + {{{"Source", "b"}, {"Version", "1.3"}, {"Build-Depends", ""}}, + {{"Feature", "beefeatureone"}, {"Description", "the first feature for b"}, {"Build-Depends", ""}}, + {{"Feature", "beefeaturetwo"}, {"Description", "the second feature for b"}, {"Build-Depends", ""}}, + {{"Feature", "beefeaturethree"}, {"Description", "the third feature for b"}, {"Build-Depends", ""}} + + })}; + + auto install_plan = Dependencies::create_feature_install_plan( + spec_map.map, {spec_a}, StatusParagraphs(std::move(status_paragraphs))); + + Assert::AreEqual(size_t(4), install_plan.size()); + remove_plan_check(&install_plan[0], "a"); + remove_plan_check(&install_plan[1], "b"); + features_check(&install_plan[2], "b", {"beefeatureone", "core", "beefeatureone"}); + features_check(&install_plan[3], "a", {"featureone", "core"}); + } + + TEST_METHOD(basic_feature_test_2) + { + using Pgh = std::unordered_map<std::string, std::string>; + + std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs; + + PackageSpecMap spec_map; + + auto spec_a = + FullPackageSpec{spec_map.get_package_spec( + {{{"Source", "a"}, {"Version", "1.3.8"}, {"Build-Depends", "b[beefeatureone]"}}, + {{"Feature", "featureone"}, + {"Description", "the first feature for a"}, + {"Build-Depends", "b[beefeaturetwo]"}} + + }), + {"featureone"}}; + auto spec_b = FullPackageSpec{spec_map.get_package_spec( + {{{"Source", "b"}, {"Version", "1.3"}, {"Build-Depends", ""}}, + {{"Feature", "beefeatureone"}, {"Description", "the first feature for b"}, {"Build-Depends", ""}}, + {{"Feature", "beefeaturetwo"}, {"Description", "the second feature for b"}, {"Build-Depends", ""}}, + {{"Feature", "beefeaturethree"}, {"Description", "the third feature for b"}, {"Build-Depends", ""}} + + })}; + + auto install_plan = Dependencies::create_feature_install_plan( + spec_map.map, {spec_a}, StatusParagraphs(std::move(status_paragraphs))); + + Assert::AreEqual(size_t(2), install_plan.size()); + features_check(&install_plan[0], "b", {"beefeatureone", "beefeaturetwo", "core"}); + features_check(&install_plan[1], "a", {"featureone", "core"}); + } + + TEST_METHOD(basic_feature_test_3) + { + using Pgh = std::unordered_map<std::string, std::string>; + + std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs; + status_paragraphs.push_back(std::make_unique<StatusParagraph>(Pgh{{"Package", "a"}, + {"Default-Features", ""}, + {"Version", "1.3"}, + {"Architecture", "x86-windows"}, + {"Multi-Arch", "same"}, + {"Depends", ""}, + {"Status", "install ok installed"}})); + + PackageSpecMap spec_map; + + auto spec_a = FullPackageSpec{ + spec_map.get_package_spec( + {{{"Source", "a"}, {"Version", "1.3"}, {"Build-Depends", "b"}}, + {{"Feature", "one"}, {"Description", "the first feature for a"}, {"Build-Depends", ""}}}), + {"core"}}; + auto spec_b = FullPackageSpec{spec_map.get_package_spec({ + {{"Source", "b"}, {"Version", "1.3"}, {"Build-Depends", ""}}, + })}; + auto spec_c = FullPackageSpec{spec_map.get_package_spec({ + {{"Source", "c"}, {"Version", "1.3"}, {"Build-Depends", "a[one]"}}, + }), + {"core"}}; + + auto install_plan = Dependencies::create_feature_install_plan( + spec_map.map, {spec_c, spec_a}, StatusParagraphs(std::move(status_paragraphs))); + + Assert::AreEqual(size_t(4), install_plan.size()); + remove_plan_check(&install_plan[0], "a"); + features_check(&install_plan[1], "b", {"core"}); + features_check(&install_plan[2], "a", {"one", "core"}); + features_check(&install_plan[3], "c", {"core"}); + } + + TEST_METHOD(basic_feature_test_4) + { + using Pgh = std::unordered_map<std::string, std::string>; + + std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs; + status_paragraphs.push_back(std::make_unique<StatusParagraph>(Pgh{{"Package", "a"}, + {"Default-Features", ""}, + {"Version", "1.3"}, + {"Architecture", "x86-windows"}, + {"Multi-Arch", "same"}, + {"Depends", ""}, + {"Status", "install ok installed"}})); + status_paragraphs.push_back(std::make_unique<StatusParagraph>(Pgh{{"Package", "a"}, + {"Feature", "one"}, + {"Architecture", "x86-windows"}, + {"Multi-Arch", "same"}, + {"Depends", ""}, + {"Status", "install ok installed"}})); + + PackageSpecMap spec_map; + + auto spec_a = FullPackageSpec{ + spec_map.get_package_spec( + {{{"Source", "a"}, {"Version", "1.3"}, {"Build-Depends", "b"}}, + {{"Feature", "one"}, {"Description", "the first feature for a"}, {"Build-Depends", ""}}}), + }; + auto spec_b = FullPackageSpec{spec_map.get_package_spec({ + {{"Source", "b"}, {"Version", "1.3"}, {"Build-Depends", ""}}, + })}; + auto spec_c = FullPackageSpec{spec_map.get_package_spec({ + {{"Source", "c"}, {"Version", "1.3"}, {"Build-Depends", "a[one]"}}, + }), + {"core"}}; + + auto install_plan = Dependencies::create_feature_install_plan( + spec_map.map, {spec_c}, StatusParagraphs(std::move(status_paragraphs))); + + Assert::AreEqual(size_t(1), install_plan.size()); + features_check(&install_plan[0], "c", {"core"}); + } + + TEST_METHOD(basic_feature_test_5) + { + using Pgh = std::unordered_map<std::string, std::string>; + + std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs; + + PackageSpecMap spec_map; + + auto spec_a = FullPackageSpec{ + spec_map.get_package_spec( + {{{"Source", "a"}, {"Version", "1.3"}, {"Build-Depends", ""}}, + {{"Feature", "1"}, {"Description", "the first feature for a"}, {"Build-Depends", "b[1]"}}, + {{"Feature", "2"}, {"Description", "the first feature for a"}, {"Build-Depends", "b[2]"}}, + {{"Feature", "3"}, {"Description", "the first feature for a"}, {"Build-Depends", "a[2]"}}}), + {"3"}}; + auto spec_b = FullPackageSpec{spec_map.get_package_spec({ + {{"Source", "b"}, {"Version", "1.3"}, {"Build-Depends", ""}}, + {{"Feature", "1"}, {"Description", "the first feature for a"}, {"Build-Depends", ""}}, + {{"Feature", "2"}, {"Description", "the first feature for a"}, {"Build-Depends", ""}}, + })}; + + auto install_plan = Dependencies::create_feature_install_plan( + spec_map.map, {spec_a}, StatusParagraphs(std::move(status_paragraphs))); + + Assert::AreEqual(size_t(2), install_plan.size()); + features_check(&install_plan[0], "b", {"core", "2"}); + features_check(&install_plan[1], "a", {"core", "3", "2"}); + } + + TEST_METHOD(basic_feature_test_6) + { + using Pgh = std::unordered_map<std::string, std::string>; + + std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs; + status_paragraphs.push_back(std::make_unique<StatusParagraph>(Pgh{{"Package", "b"}, + {"Default-Features", ""}, + {"Version", "1.3"}, + {"Architecture", "x86-windows"}, + {"Multi-Arch", "same"}, + {"Depends", ""}, + {"Status", "install ok installed"}})); + PackageSpecMap spec_map; + + auto spec_a = FullPackageSpec{spec_map.get_package_spec({ + {{"Source", "a"}, {"Version", "1.3"}, {"Build-Depends", "b[core]"}}, + }), + {"core"}}; + auto spec_b = FullPackageSpec{ + spec_map.get_package_spec({ + {{"Source", "b"}, {"Version", "1.3"}, {"Build-Depends", ""}}, + {{"Feature", "1"}, {"Description", "the first feature for a"}, {"Build-Depends", ""}}, + }), + {"1"}}; + + auto install_plan = Dependencies::create_feature_install_plan( + spec_map.map, {spec_a, spec_b}, StatusParagraphs(std::move(status_paragraphs))); + + Assert::AreEqual(size_t(3), install_plan.size()); + remove_plan_check(&install_plan[0], "b"); + features_check(&install_plan[1], "b", {"core", "1"}); + features_check(&install_plan[2], "a", {"core"}); + } + + TEST_METHOD(basic_feature_test_7) + { + using Pgh = std::unordered_map<std::string, std::string>; + + std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs; + status_paragraphs.push_back(std::make_unique<StatusParagraph>(Pgh{{"Package", "x"}, + {"Default-Features", ""}, + {"Version", "1.3"}, + {"Architecture", "x86-windows"}, + {"Multi-Arch", "same"}, + {"Depends", "b"}, + {"Status", "install ok installed"}})); + status_paragraphs.push_back(std::make_unique<StatusParagraph>(Pgh{{"Package", "b"}, + {"Default-Features", ""}, + {"Version", "1.3"}, + {"Architecture", "x86-windows"}, + {"Multi-Arch", "same"}, + {"Depends", ""}, + {"Status", "install ok installed"}})); + PackageSpecMap spec_map; + + auto spec_a = FullPackageSpec{spec_map.get_package_spec({ + {{"Source", "a"}, {"Version", "1.3"}, {"Build-Depends", ""}}, + })}; + auto spec_x = FullPackageSpec{spec_map.get_package_spec({ + {{"Source", "x"}, {"Version", "1.3"}, {"Build-Depends", "a"}}, + }), + {"core"}}; + auto spec_b = FullPackageSpec{ + spec_map.get_package_spec({ + {{"Source", "b"}, {"Version", "1.3"}, {"Build-Depends", ""}, {"Default-Features", ""}}, + {{"Feature", "1"}, {"Description", "the first feature for a"}, {"Build-Depends", ""}}, + }), + {"1"}}; + + auto install_plan = Dependencies::create_feature_install_plan( + spec_map.map, {spec_b, spec_x}, StatusParagraphs(std::move(status_paragraphs))); + + Assert::AreEqual(size_t(5), install_plan.size()); + remove_plan_check(&install_plan[0], "x"); + remove_plan_check(&install_plan[1], "b"); + + // order here may change but A < X, and B anywhere + features_check(&install_plan[2], "a", {"core"}); + features_check(&install_plan[3], "x", {"core"}); + features_check(&install_plan[4], "b", {"core", "1"}); + } }; }
\ No newline at end of file |
