1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#include <vcpkg-tests/catch.h>
#include <vcpkg-tests/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);
}
|