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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
#include <catch2/catch.hpp>
#include <vcpkg/base/jsonreader.h>
#include <vcpkg/registries.h>
using namespace vcpkg;
namespace
{
struct TestRegistryImplementation final : RegistryImplementation
{
std::unique_ptr<RegistryEntry> get_port_entry(const VcpkgPaths&, StringView) const override { return nullptr; }
void get_all_port_names(std::vector<std::string>&, const VcpkgPaths&) const override { }
Optional<VersionT> get_baseline_version(const VcpkgPaths&, StringView) const override { return nullopt; }
int number;
TestRegistryImplementation(int n) : number(n) { }
};
Registry make_registry(int n, std::vector<std::string>&& port_names)
{
return {std::move(port_names), std::make_unique<TestRegistryImplementation>(n)};
}
int get_tri_num(const RegistryImplementation& r)
{
if (auto tri = dynamic_cast<const TestRegistryImplementation*>(&r))
{
return tri->number;
}
else
{
return -1;
}
}
// test functions which parse string literals, so no concerns about failure
Json::Value parse_json(StringView sv) { return Json::parse(sv).value_or_exit(VCPKG_LINE_INFO).first; }
}
TEST_CASE ("registry_set_selects_registry", "[registries]")
{
RegistrySet set;
set.set_default_registry(std::make_unique<TestRegistryImplementation>(0));
set.add_registry(make_registry(1, {"p1", "q1", "r1"}));
set.add_registry(make_registry(2, {"p2", "q2", "r2"}));
auto reg = set.registry_for_port("p1");
REQUIRE(reg);
CHECK(get_tri_num(*reg) == 1);
reg = set.registry_for_port("r2");
REQUIRE(reg);
CHECK(get_tri_num(*reg) == 2);
reg = set.registry_for_port("a");
REQUIRE(reg);
CHECK(get_tri_num(*reg) == 0);
set.set_default_registry(nullptr);
reg = set.registry_for_port("q1");
REQUIRE(reg);
CHECK(get_tri_num(*reg) == 1);
reg = set.registry_for_port("p2");
REQUIRE(reg);
CHECK(get_tri_num(*reg) == 2);
reg = set.registry_for_port("a");
CHECK_FALSE(reg);
}
TEST_CASE ("registry_parsing", "[registries]")
{
Json::Reader r;
auto registry_impl_des = get_registry_implementation_deserializer({});
auto test_json = parse_json(R"json(
{
"kind": "builtin"
}
)json");
auto registry_impl = r.visit(test_json, *registry_impl_des);
REQUIRE(registry_impl);
CHECK(*registry_impl.get());
CHECK(r.errors().empty());
test_json = parse_json(R"json(
{
"kind": "builtin",
"baseline": "hi"
}
)json");
registry_impl = r.visit(test_json, *registry_impl_des);
REQUIRE(registry_impl);
CHECK(*registry_impl.get());
CHECK(r.errors().empty());
test_json = parse_json(R"json(
{
"kind": "builtin",
"path": "a/b"
}
)json");
registry_impl = r.visit(test_json, *registry_impl_des);
CHECK_FALSE(r.errors().empty());
r.errors().clear();
test_json = parse_json(R"json(
{
"kind": "filesystem",
"path": "a/b/c"
}
)json");
registry_impl = r.visit(test_json, *registry_impl_des);
REQUIRE(registry_impl);
CHECK(*registry_impl.get());
CHECK(r.errors().empty());
test_json = parse_json(R"json(
{
"kind": "filesystem",
"path": "/a/b/c"
}
)json");
registry_impl = r.visit(test_json, *registry_impl_des);
REQUIRE(registry_impl);
CHECK(*registry_impl.get());
CHECK(r.errors().empty());
}
|