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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
require 'rubygems/test_case'
require 'rubygems/request_set'
require 'rubygems/request_set/lockfile'
class TestGemRequestSetLockfile < Gem::TestCase
def setup
super
Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new
util_set_arch 'i686-darwin8.10.1'
@set = Gem::RequestSet.new
@vendor_set = Gem::DependencyResolver::VendorSet.new
@set.instance_variable_set :@vendor_set, @vendor_set
@gem_deps_file = 'gem.deps.rb'
@lockfile = Gem::RequestSet::Lockfile.new @set, @gem_deps_file
end
def write_gem_deps gem_deps
open @gem_deps_file, 'w' do |io|
io.write gem_deps
end
end
def write_lockfile lockfile
@lock_file = File.expand_path "#{@gem_deps_file}.lock"
open @lock_file, 'w' do |io|
io.write lockfile
end
end
def test_get
@lockfile.instance_variable_set :@tokens, [:token]
assert_equal :token, @lockfile.get
end
def test_get_type_mismatch
@lockfile.instance_variable_set :@tokens, [[:section, 'x', 5, 1]]
e = assert_raises Gem::RequestSet::Lockfile::ParseError do
@lockfile.get :text
end
expected = 'unexpected token [:section, "x"], expected :text (at 5:1)'
assert_equal expected, e.message
assert_equal 5, e.line
assert_equal 1, e.column
assert_equal File.expand_path("#{@gem_deps_file}.lock"), e.path
end
def test_get_type_value_mismatch
@lockfile.instance_variable_set :@tokens, [[:section, 'x', 5, 1]]
e = assert_raises Gem::RequestSet::Lockfile::ParseError do
@lockfile.get :section, 'y'
end
expected =
'unexpected token [:section, "x"], expected [:section, "y"] (at 5:1)'
assert_equal expected, e.message
assert_equal 5, e.line
assert_equal 1, e.column
assert_equal File.expand_path("#{@gem_deps_file}.lock"), e.path
end
def test_parse
write_lockfile <<-LOCKFILE
GEM
remote: #{@gem_repo}
specs:
a (2)
PLATFORMS
#{Gem::Platform::RUBY}
DEPENDENCIES
a
LOCKFILE
@lockfile.parse
assert_equal [dep('a')], @set.dependencies
assert_equal [Gem::Platform::RUBY], @lockfile.platforms
lockfile_set = @set.sets.find do |set|
Gem::DependencyResolver::LockSet === set
end
assert lockfile_set, 'could not find a LockSet'
assert_equal %w[a-2], lockfile_set.specs.map { |tuple| tuple.full_name }
end
def test_peek
@lockfile.instance_variable_set :@tokens, [:token]
assert_equal :token, @lockfile.peek
assert_equal :token, @lockfile.get
end
def test_skip
tokens = [[:token]]
@lockfile.instance_variable_set :@tokens, tokens
@lockfile.skip :token
assert_empty tokens
end
def test_token_pos
assert_equal [5, 0], @lockfile.token_pos(5)
@lockfile.instance_variable_set :@line_pos, 2
@lockfile.instance_variable_set :@line, 1
assert_equal [3, 1], @lockfile.token_pos(5)
end
def test_tokenize
write_lockfile <<-LOCKFILE
GEM
remote: #{@gem_repo}
specs:
a (2)
PLATFORMS
#{Gem::Platform::RUBY}
DEPENDENCIES
a
LOCKFILE
expected = [
[:section, 'GEM', 0, 0],
[:newline, nil, 3, 0],
[:entry, 'remote', 2, 1],
[:text, @gem_repo, 10, 1],
[:newline, nil, 34, 1],
[:entry, 'specs', 2, 2],
[:newline, nil, 8, 2],
[:text, 'a', 4, 3],
[:l_paren, nil, 6, 3],
[:text, '2', 7, 3],
[:r_paren, nil, 8, 3],
[:newline, nil, 9, 3],
[:newline, nil, 0, 4],
[:section, 'PLATFORMS', 0, 5],
[:newline, nil, 9, 5],
[:text, Gem::Platform::RUBY, 2, 6],
[:newline, nil, 6, 6],
[:newline, nil, 0, 7],
[:section, 'DEPENDENCIES', 0, 8],
[:newline, nil, 12, 8],
[:text, 'a', 2, 9],
[:newline, nil, 3, 9],
]
assert_equal expected, @lockfile.tokenize
end
def test_tokenize_conflict_markers
write_lockfile '<<<<<<<'
e = assert_raises Gem::RequestSet::Lockfile::ParseError do
@lockfile.tokenize
end
assert_equal "your #{@lock_file} contains merge conflict markers (at 0:0)",
e.message
write_lockfile '|||||||'
e = assert_raises Gem::RequestSet::Lockfile::ParseError do
@lockfile.tokenize
end
assert_equal "your #{@lock_file} contains merge conflict markers (at 0:0)",
e.message
write_lockfile '======='
e = assert_raises Gem::RequestSet::Lockfile::ParseError do
@lockfile.tokenize
end
assert_equal "your #{@lock_file} contains merge conflict markers (at 0:0)",
e.message
write_lockfile '>>>>>>>'
e = assert_raises Gem::RequestSet::Lockfile::ParseError do
@lockfile.tokenize
end
assert_equal "your #{@lock_file} contains merge conflict markers (at 0:0)",
e.message
end
def test_to_s_gem
spec_fetcher do |fetcher|
fetcher.spec 'a', 2
end
@set.gem 'a'
expected = <<-LOCKFILE
GEM
remote: #{@gem_repo}
specs:
a (2)
PLATFORMS
#{Gem::Platform::RUBY}
DEPENDENCIES
a
LOCKFILE
assert_equal expected, @lockfile.to_s
end
def test_to_s_gem_dependency
spec_fetcher do |fetcher|
fetcher.spec 'a', 2, 'c' => '>= 0', 'b' => '>= 0'
fetcher.spec 'b', 2
fetcher.spec 'c', 2
end
@set.gem 'a'
expected = <<-LOCKFILE
GEM
remote: #{@gem_repo}
specs:
a (2)
b
c
b (2)
c (2)
PLATFORMS
#{Gem::Platform::RUBY}
DEPENDENCIES
a
LOCKFILE
assert_equal expected, @lockfile.to_s
end
def test_to_s_gem_dependency_non_default
spec_fetcher do |fetcher|
fetcher.spec 'a', 2, 'b' => '>= 1'
fetcher.spec 'b', 2
end
@set.gem 'b'
@set.gem 'a'
expected = <<-LOCKFILE
GEM
remote: #{@gem_repo}
specs:
a (2)
b (>= 1)
b (2)
PLATFORMS
#{Gem::Platform::RUBY}
DEPENDENCIES
a
b
LOCKFILE
assert_equal expected, @lockfile.to_s
end
def test_to_s_gem_dependency_requirement
spec_fetcher do |fetcher|
fetcher.spec 'a', 2, 'b' => '>= 0'
fetcher.spec 'b', 2
end
@set.gem 'a', '>= 1'
expected = <<-LOCKFILE
GEM
remote: #{@gem_repo}
specs:
a (2)
b
b (2)
PLATFORMS
#{Gem::Platform::RUBY}
DEPENDENCIES
a (>= 1)
LOCKFILE
assert_equal expected, @lockfile.to_s
end
def test_to_s_gem_path
name, version, directory = vendor_gem
@vendor_set.add_vendor_gem name, directory
@set.gem 'a'
expected = <<-LOCKFILE
PATH
remote: #{directory}
specs:
#{name} (#{version})
GEM
PLATFORMS
#{Gem::Platform::RUBY}
DEPENDENCIES
a!
LOCKFILE
assert_equal expected, @lockfile.to_s
end
def test_to_s_gem_path_absolute
name, version, directory = vendor_gem
@vendor_set.add_vendor_gem name, File.expand_path(directory)
@set.gem 'a'
expected = <<-LOCKFILE
PATH
remote: #{directory}
specs:
#{name} (#{version})
GEM
PLATFORMS
#{Gem::Platform::RUBY}
DEPENDENCIES
a!
LOCKFILE
assert_equal expected, @lockfile.to_s
end
def test_to_s_gem_platform
spec_fetcher do |fetcher|
fetcher.spec 'a', 2 do |spec|
spec.platform = Gem::Platform.local
end
end
@set.gem 'a'
expected = <<-LOCKFILE
GEM
remote: #{@gem_repo}
specs:
a (2-#{Gem::Platform.local})
PLATFORMS
#{Gem::Platform.local}
DEPENDENCIES
a
LOCKFILE
assert_equal expected, @lockfile.to_s
end
def test_unget
@lockfile.instance_variable_set :@current_token, :token
@lockfile.unget
assert_equal :token, @lockfile.get
end
end
|