diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2017-11-06 14:22:10 -0800 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2017-11-06 14:22:10 -0800 |
| commit | eb99b0c705b78e6c278e0a3782a8324e9d304e69 (patch) | |
| tree | 8502ebd9181d5b7d218020d20b11595edfd88caf /toolsrc | |
| parent | f1ab66b960f4b46ecb0f61cd46094f51dbe454f2 (diff) | |
| download | vcpkg-eb99b0c705b78e6c278e0a3782a8324e9d304e69.tar.gz vcpkg-eb99b0c705b78e6c278e0a3782a8324e9d304e69.zip | |
[vcpkg] Add tests for remove plans.
Diffstat (limited to 'toolsrc')
| -rw-r--r-- | toolsrc/src/tests.plan.cpp (renamed from toolsrc/src/tests.installplan.cpp) | 242 | ||||
| -rw-r--r-- | toolsrc/vcpkgtest/vcpkgtest.vcxproj | 2 | ||||
| -rw-r--r-- | toolsrc/vcpkgtest/vcpkgtest.vcxproj.filters | 6 |
3 files changed, 159 insertions, 91 deletions
diff --git a/toolsrc/src/tests.installplan.cpp b/toolsrc/src/tests.plan.cpp index 129926317..d62178bdf 100644 --- a/toolsrc/src/tests.installplan.cpp +++ b/toolsrc/src/tests.plan.cpp @@ -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, - 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) { - 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}, + { "Feature", feature.first }, + { "Description", "feature" }, + { "Build-Depends", feature.second }, }); - 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()); } + 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; + 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(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()); + 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) + for (auto&& feature_name : vec) + { + if (feature_name == "core" || feature_name == "") { - 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()); + 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 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 = "") + 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>; - return std::make_unique<StatusParagraph>(Pgh{{"Package", name}, - {"Version", "1"}, - {"Architecture", "x86-windows"}, - {"Multi-Arch", "same"}, - {"Depends", depends}, - {"Status", "install ok installed"}}); + return emplace(std::move(*make_control_file(name, depends, features))); } - static std::unique_ptr<StatusParagraph> make_status_feature_pgh(const char* name, - const char* feature, - const char* depends = "") + PackageSpec emplace(vcpkg::SourceControlFile&& scf) { - 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"}}); + 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() }; } - 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()); + } + }; } diff --git a/toolsrc/vcpkgtest/vcpkgtest.vcxproj b/toolsrc/vcpkgtest/vcpkgtest.vcxproj index 766b4bf67..88dc14a75 100644 --- a/toolsrc/vcpkgtest/vcpkgtest.vcxproj +++ b/toolsrc/vcpkgtest/vcpkgtest.vcxproj @@ -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> diff --git a/toolsrc/vcpkgtest/vcpkgtest.vcxproj.filters b/toolsrc/vcpkgtest/vcpkgtest.vcxproj.filters index b6f1ced06..217c5b608 100644 --- a/toolsrc/vcpkgtest/vcpkgtest.vcxproj.filters +++ b/toolsrc/vcpkgtest/vcpkgtest.vcxproj.filters @@ -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>
\ No newline at end of file |
