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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
require 'rubygems/test_case'
class TestGemResolverInstallerSet < Gem::TestCase
def test_add_always_install
spec_fetcher do |fetcher|
fetcher.spec 'a', 1
fetcher.spec 'a', 2
fetcher.clear
end
util_gem 'a', 1
set = Gem::Resolver::InstallerSet.new :both
set.add_always_install dep('a')
assert_equal %w[a-2], set.always_install.map { |s| s.full_name }
e = assert_raises Gem::UnsatisfiableDependencyError do
set.add_always_install dep('b')
end
assert_equal dep('b'), e.dependency.dependency
end
def test_add_always_install_errors
@fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher
set = Gem::Resolver::InstallerSet.new :both
e = assert_raises Gem::UnsatisfiableDependencyError do
set.add_always_install dep 'a'
end
refute_empty e.errors
end
def test_add_always_install_platform
spec_fetcher do |fetcher|
fetcher.spec 'a', 1
fetcher.spec 'a', 2 do |s|
s.platform = Gem::Platform.new 'x86-freebsd-9'
end
fetcher.clear
end
set = Gem::Resolver::InstallerSet.new :both
set.add_always_install dep('a')
assert_equal %w[a-1], set.always_install.map { |s| s.full_name }
end
def test_add_always_install_prerelease
spec_fetcher do |fetcher|
fetcher.gem 'a', 1
fetcher.gem 'a', '3.a'
end
set = Gem::Resolver::InstallerSet.new :both
set.add_always_install dep('a')
assert_equal %w[a-1], set.always_install.map { |s| s.full_name }
end
def test_add_always_install_prerelease_only
spec_fetcher do |fetcher|
fetcher.gem 'a', '3.a'
end
set = Gem::Resolver::InstallerSet.new :both
assert_raises Gem::UnsatisfiableDependencyError do
set.add_always_install dep('a')
end
end
def test_add_local
a_1, a_1_gem = util_gem 'a', 1
a_1_source = Gem::Source::SpecificFile.new a_1_gem
set = Gem::Resolver::InstallerSet.new :both
set.add_local File.basename(a_1_gem), a_1, a_1_source
assert set.local? File.basename(a_1_gem)
FileUtils.rm a_1_gem
util_clear_gems
req = Gem::Resolver::DependencyRequest.new dep('a'), nil
assert_equal %w[a-1], set.find_all(req).map { |spec| spec.full_name }
end
def test_consider_local_eh
set = Gem::Resolver::InstallerSet.new :remote
refute set.consider_local?
set = Gem::Resolver::InstallerSet.new :both
assert set.consider_local?
set = Gem::Resolver::InstallerSet.new :local
assert set.consider_local?
end
def test_consider_remote_eh
set = Gem::Resolver::InstallerSet.new :remote
assert set.consider_remote?
set = Gem::Resolver::InstallerSet.new :both
assert set.consider_remote?
set = Gem::Resolver::InstallerSet.new :local
refute set.consider_remote?
end
def test_errors
set = Gem::Resolver::InstallerSet.new :both
set.instance_variable_get(:@errors) << :a
req = Gem::Resolver::DependencyRequest.new dep('a'), nil
set.find_all req
assert_equal [:a, set.remote_set.errors.first], set.errors
end
def test_find_all_always_install
spec_fetcher do |fetcher|
fetcher.spec 'a', 2
fetcher.clear
end
util_gem 'a', 1
set = Gem::Resolver::InstallerSet.new :both
set.add_always_install dep 'a'
req = Gem::Resolver::DependencyRequest.new dep('a'), nil
assert_equal %w[a-2], set.find_all(req).map { |spec| spec.full_name }
end
def test_find_all_prerelease
spec_fetcher do |fetcher|
fetcher.spec 'a', '1'
fetcher.spec 'a', '1.a'
fetcher.clear
end
set = Gem::Resolver::InstallerSet.new :both
req = Gem::Resolver::DependencyRequest.new dep('a'), nil
assert_equal %w[a-1], set.find_all(req).map { |spec| spec.full_name }
req = Gem::Resolver::DependencyRequest.new dep('a', '>= 0.a'), nil
assert_equal %w[a-1 a-1.a],
set.find_all(req).map { |spec| spec.full_name }.sort
end
def test_load_spec
specs = spec_fetcher do |fetcher|
fetcher.spec 'a', 2
fetcher.spec 'a', 2 do |s| s.platform = Gem::Platform.local end
end
source = Gem::Source.new @gem_repo
version = v 2
set = Gem::Resolver::InstallerSet.new :remote
spec = set.load_spec 'a', version, Gem::Platform.local, source
assert_equal specs["a-2-#{Gem::Platform.local}"].full_name, spec.full_name
end
def test_prefetch
set = Gem::Resolver::InstallerSet.new :remote
def (set.remote_set).prefetch(_)
raise "called"
end
assert_raises(RuntimeError){ set.prefetch(nil) }
set = Gem::Resolver::InstallerSet.new :local
def (set.remote_set).prefetch(_)
raise "called"
end
assert_equal nil, set.prefetch(nil)
end
def test_prerelease_equals
set = Gem::Resolver::InstallerSet.new :remote
refute set.prerelease
refute set.remote_set.prerelease
set.prerelease = true
assert set.prerelease
assert set.remote_set.prerelease
end
def test_remote_equals_both
set = Gem::Resolver::InstallerSet.new :both
set.remote = true
assert set.consider_local?
assert set.consider_remote?
set = Gem::Resolver::InstallerSet.new :both
set.remote = false
assert set.consider_local?
refute set.consider_remote?
end
def test_remote_equals_local
set = Gem::Resolver::InstallerSet.new :local
set.remote = true
assert set.consider_local?
assert set.consider_remote?
set = Gem::Resolver::InstallerSet.new :local
set.remote = false
assert set.consider_local?
refute set.consider_remote?
end
def test_remote_equals_remote
set = Gem::Resolver::InstallerSet.new :remote
set.remote = true
refute set.consider_local?
assert set.consider_remote?
set = Gem::Resolver::InstallerSet.new :remote
set.remote = false
refute set.consider_local?
refute set.consider_remote?
end
end
|