aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg-test/update.cpp
diff options
context:
space:
mode:
authorJackBoosY <47264268+JackBoosY@users.noreply.github.com>2019-08-16 10:01:32 +0800
committerGitHub <noreply@github.com>2019-08-16 10:01:32 +0800
commitadb84c2658b9774ff535eb88f377ee818dd429be (patch)
treefcfcf4a93057037152a14aa2885598b45c5b03bd /toolsrc/src/vcpkg-test/update.cpp
parent2865da8f4a6d911617cdd9b147816c4cd02bbf7e (diff)
parent22e787f9448a25dae734ca06c80e7e5af5fb6537 (diff)
downloadvcpkg-adb84c2658b9774ff535eb88f377ee818dd429be.tar.gz
vcpkg-adb84c2658b9774ff535eb88f377ee818dd429be.zip
Merge branch 'master' into dev/jack/4167
Diffstat (limited to 'toolsrc/src/vcpkg-test/update.cpp')
-rw-r--r--toolsrc/src/vcpkg-test/update.cpp102
1 files changed, 102 insertions, 0 deletions
diff --git a/toolsrc/src/vcpkg-test/update.cpp b/toolsrc/src/vcpkg-test/update.cpp
new file mode 100644
index 000000000..70b2f04c1
--- /dev/null
+++ b/toolsrc/src/vcpkg-test/update.cpp
@@ -0,0 +1,102 @@
+#include <vcpkg-test/catch.h>
+#include <vcpkg-test/util.h>
+
+#include <vcpkg/base/sortedvector.h>
+
+#include <vcpkg/update.h>
+
+using namespace vcpkg;
+using namespace vcpkg::Update;
+using namespace vcpkg::Test;
+
+using Pgh = std::vector<std::unordered_map<std::string, std::string>>;
+
+TEST_CASE ("find outdated packages basic", "[update]")
+{
+ std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs;
+ status_paragraphs.push_back(make_status_pgh("a"));
+ status_paragraphs.back()->package.version = "2";
+
+ StatusParagraphs status_db(std::move(status_paragraphs));
+
+ std::unordered_map<std::string, SourceControlFileLocation> map;
+ auto scf = unwrap(SourceControlFile::parse_control_file(Pgh{{{"Source", "a"}, {"Version", "0"}}}));
+ map.emplace("a", SourceControlFileLocation{std::move(scf), ""});
+ Dependencies::MapPortFileProvider provider(map);
+
+ auto pkgs = SortedVector<OutdatedPackage>(Update::find_outdated_packages(provider, status_db),
+ &OutdatedPackage::compare_by_name);
+
+ REQUIRE(pkgs.size() == 1);
+ REQUIRE(pkgs[0].version_diff.left.to_string() == "2");
+ REQUIRE(pkgs[0].version_diff.right.to_string() == "0");
+}
+
+TEST_CASE ("find outdated packages features", "[update]")
+{
+ std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs;
+ status_paragraphs.push_back(make_status_pgh("a"));
+ status_paragraphs.back()->package.version = "2";
+
+ status_paragraphs.push_back(make_status_feature_pgh("a", "b"));
+ status_paragraphs.back()->package.version = "2";
+
+ StatusParagraphs status_db(std::move(status_paragraphs));
+
+ std::unordered_map<std::string, SourceControlFileLocation> map;
+ auto scf = unwrap(SourceControlFile::parse_control_file(Pgh{{{"Source", "a"}, {"Version", "0"}}}));
+ map.emplace("a", SourceControlFileLocation{std::move(scf), ""});
+ Dependencies::MapPortFileProvider provider(map);
+
+ auto pkgs = SortedVector<OutdatedPackage>(Update::find_outdated_packages(provider, status_db),
+ &OutdatedPackage::compare_by_name);
+
+ REQUIRE(pkgs.size() == 1);
+ REQUIRE(pkgs[0].version_diff.left.to_string() == "2");
+ REQUIRE(pkgs[0].version_diff.right.to_string() == "0");
+}
+
+TEST_CASE ("find outdated packages features 2", "[update]")
+{
+ std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs;
+ status_paragraphs.push_back(make_status_pgh("a"));
+ status_paragraphs.back()->package.version = "2";
+
+ status_paragraphs.push_back(make_status_feature_pgh("a", "b"));
+ status_paragraphs.back()->package.version = "0";
+ status_paragraphs.back()->state = InstallState::NOT_INSTALLED;
+ status_paragraphs.back()->want = Want::PURGE;
+
+ StatusParagraphs status_db(std::move(status_paragraphs));
+
+ std::unordered_map<std::string, SourceControlFileLocation> map;
+ auto scf = unwrap(SourceControlFile::parse_control_file(Pgh{{{"Source", "a"}, {"Version", "0"}}}));
+ map.emplace("a", SourceControlFileLocation{std::move(scf), ""});
+ Dependencies::MapPortFileProvider provider(map);
+
+ auto pkgs = SortedVector<OutdatedPackage>(Update::find_outdated_packages(provider, status_db),
+ &OutdatedPackage::compare_by_name);
+
+ REQUIRE(pkgs.size() == 1);
+ REQUIRE(pkgs[0].version_diff.left.to_string() == "2");
+ REQUIRE(pkgs[0].version_diff.right.to_string() == "0");
+}
+
+TEST_CASE ("find outdated packages none", "[update]")
+{
+ std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs;
+ status_paragraphs.push_back(make_status_pgh("a"));
+ status_paragraphs.back()->package.version = "2";
+
+ StatusParagraphs status_db(std::move(status_paragraphs));
+
+ std::unordered_map<std::string, SourceControlFileLocation> map;
+ auto scf = unwrap(SourceControlFile::parse_control_file(Pgh{{{"Source", "a"}, {"Version", "2"}}}));
+ map.emplace("a", SourceControlFileLocation{std::move(scf), ""});
+ Dependencies::MapPortFileProvider provider(map);
+
+ auto pkgs = SortedVector<OutdatedPackage>(Update::find_outdated_packages(provider, status_db),
+ &OutdatedPackage::compare_by_name);
+
+ REQUIRE(pkgs.size() == 0);
+}