1
require_relative 'gemutilities'
1
require 'rubygems/test_case'
2
2
require 'rubygems/indexer'
4
unless ''.respond_to? :to_xs then
4
unless defined?(Builder::XChar) then
5
5
warn "Gem::Indexer tests are being skipped. Install builder gem." if $VERBOSE
8
class TestGemIndexer < RubyGemTestCase
8
class TestGemIndexer < Gem::TestCase
15
@d2_0 = quick_gem 'd', '2.0' do |s|
16
@d2_0 = quick_spec 'd', '2.0' do |s|
16
17
s.date = Gem::Specification::TODAY - 86400 * 3
18
19
util_build_gem @d2_0
20
@d2_0_a = quick_gem 'd', '2.0.a'
21
@d2_0_a = quick_spec 'd', '2.0.a'
21
22
util_build_gem @d2_0_a
23
@d2_0_b = quick_gem 'd', '2.0.b'
24
@d2_0_b = quick_spec 'd', '2.0.b'
24
25
util_build_gem @d2_0_b
27
@tempdir = File.join(@tempdir, 'indexer')
26
29
gems = File.join(@tempdir, 'gems')
27
30
FileUtils.mkdir_p gems
28
cache_gems = File.join @gemhome, 'cache', '*.gem'
29
FileUtils.mv Dir[cache_gems], gems
31
FileUtils.mv Dir[File.join(@gemhome, "cache", '*.gem')], gems
31
@indexer = Gem::Indexer.new @tempdir, :rss_title => 'ExampleForge gems',
32
:rss_host => 'example.com',
33
:rss_gems_host => 'gems.example.com'
33
@indexer = Gem::Indexer.new(@tempdir,
34
:rss_title => 'ExampleForge gems',
35
:rss_host => 'example.com',
36
:rss_gems_host => 'gems.example.com')
36
39
def test_initialize
56
59
def test_build_indicies
57
spec = quick_gem 'd', '2.0'
58
spec.instance_variable_set :@original_platform, ''
60
60
@indexer.make_temp_directories
62
index = Gem::SourceIndex.new
66
@indexer.build_indicies index
63
@indexer.build_indicies
69
66
specs_path = File.join @indexer.directory, "specs.#{@marshal_version}"
70
67
specs_dump = Gem.read_binary specs_path
71
68
specs = Marshal.load specs_dump
74
['d', Gem::Version.new('2.0'), 'ruby'],
77
assert_equal expected, specs, 'specs'
79
latest_specs_path = File.join @indexer.directory,
80
"latest_specs.#{@marshal_version}"
70
expected = [["a", Gem::Version.new("1"), "ruby"],
71
["a", Gem::Version.new("2"), "ruby"],
72
["a_evil", Gem::Version.new("9"), "ruby"],
73
["b", Gem::Version.new("2"), "ruby"],
74
["c", Gem::Version.new("1.2"), "ruby"],
75
["d", Gem::Version.new("2.0"), "ruby"],
76
["pl", Gem::Version.new("1"), "i386-linux"]]
78
assert_equal expected, specs
80
latest_specs_path = File.join(@indexer.directory,
81
"latest_specs.#{@marshal_version}")
81
82
latest_specs_dump = Gem.read_binary latest_specs_path
82
83
latest_specs = Marshal.load latest_specs_dump
85
['d', Gem::Version.new('2.0'), 'ruby'],
85
expected = [["a", Gem::Version.new("2"), "ruby"],
86
["a_evil", Gem::Version.new("9"), "ruby"],
87
["b", Gem::Version.new("2"), "ruby"],
88
["c", Gem::Version.new("1.2"), "ruby"],
89
["d", Gem::Version.new("2.0"), "ruby"],
90
["pl", Gem::Version.new("1"), "i386-linux"]]
88
92
assert_equal expected, latest_specs, 'latest_specs'
104
106
assert File.directory?(quickdir)
105
107
assert File.directory?(marshal_quickdir)
107
assert_indexed quickdir, "index"
108
assert_indexed quickdir, "index.rz"
110
quick_index = File.read File.join(quickdir, 'index')
124
assert_equal expected, quick_index
126
assert_indexed quickdir, "latest_index"
127
assert_indexed quickdir, "latest_index.rz"
129
latest_quick_index = File.read File.join(quickdir, 'latest_index')
139
assert_equal expected, latest_quick_index
141
assert_indexed quickdir, "#{@a1.spec_name}.rz"
142
assert_indexed quickdir, "#{@a2.spec_name}.rz"
143
assert_indexed quickdir, "#{@b2.spec_name}.rz"
144
assert_indexed quickdir, "#{@c1_2.spec_name}.rz"
146
assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
147
refute_indexed quickdir, "#{@pl1.spec_name}.rz"
149
assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
150
assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
152
refute_indexed quickdir, @c1_2.spec_name
153
refute_indexed marshal_quickdir, @c1_2.spec_name
109
assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz"
110
assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz"
112
refute_indexed marshal_quickdir, File.basename(@c1_2.spec_file)
155
114
assert_indexed @tempdir, "specs.#{@marshal_version}"
156
115
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
269
228
<pre>This line is really, really long. So long, in fact, that it is more than
270
229
eighty characters long! The purpose of this line is for testing wrapping
271
behavior because sometimes people don't wrap their text to eighty characters.
230
behavior because sometimes people don't wrap their text to eighty characters.
272
231
Without the wrapping, the text might not look good in the RSS feed.
275
234
* An entry that's actually kind of sort
276
* an entry that's really long, which will probably get wrapped funny.
235
* an entry that's really long, which will probably get wrapped funny.
277
236
That's ok, somebody wasn't thinking straight when they made it more than
278
237
eighty characters.</pre>
312
269
assert File.directory?(quickdir)
313
270
assert File.directory?(marshal_quickdir)
315
assert_indexed quickdir, "index"
316
assert_indexed quickdir, "index.rz"
318
assert_indexed quickdir, "latest_index"
319
assert_indexed quickdir, "latest_index.rz"
321
assert_indexed quickdir, "#{@a1.spec_name}.rz"
322
assert_indexed quickdir, "#{@a2.spec_name}.rz"
323
assert_indexed quickdir, "#{@b2.spec_name}.rz"
324
assert_indexed quickdir, "#{@c1_2.spec_name}.rz"
326
assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
327
refute_indexed quickdir, "#{@pl1.spec_name}.rz"
329
assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
330
assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
332
refute_indexed quickdir, "#{@c1_2.spec_name}"
333
refute_indexed marshal_quickdir, "#{@c1_2.spec_name}"
272
assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz"
273
assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz"
275
refute_indexed marshal_quickdir, "#{File.basename(@c1_2.spec_file)}"
335
277
refute_indexed @tempdir, "specs.#{@marshal_version}"
336
278
refute_indexed @tempdir, "specs.#{@marshal_version}.gz"
355
297
@indexer.generate_index
358
assert_indexed @tempdir, 'yaml'
359
assert_indexed @tempdir, 'yaml.Z'
360
300
assert_indexed @tempdir, "Marshal.#{@marshal_version}"
361
301
assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
363
303
quickdir = File.join @tempdir, 'quick'
364
304
marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
366
assert File.directory?(quickdir)
367
306
assert File.directory?(marshal_quickdir)
369
assert_indexed quickdir, "index"
370
assert_indexed quickdir, "index.rz"
372
assert_indexed quickdir, "latest_index"
373
assert_indexed quickdir, "latest_index.rz"
375
assert_indexed quickdir, "#{@a1.spec_name}.rz"
376
assert_indexed quickdir, "#{@a2.spec_name}.rz"
377
assert_indexed quickdir, "#{@b2.spec_name}.rz"
378
assert_indexed quickdir, "#{@c1_2.spec_name}.rz"
380
assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
382
assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
383
assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
308
assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz"
309
assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz"
385
311
assert_indexed @tempdir, "specs.#{@marshal_version}"
386
312
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
414
340
refute_indexed quickdir, "latest_index"
415
341
refute_indexed quickdir, "latest_index.rz"
417
refute_indexed quickdir, "#{@a1.spec_name}.rz"
418
refute_indexed quickdir, "#{@a2.spec_name}.rz"
419
refute_indexed quickdir, "#{@b2.spec_name}.rz"
420
refute_indexed quickdir, "#{@c1_2.spec_name}.rz"
343
refute_indexed quickdir, "#{File.basename(@a1.spec_file)}.rz"
344
refute_indexed quickdir, "#{File.basename(@a2.spec_file)}.rz"
345
refute_indexed quickdir, "#{File.basename(@b2.spec_file)}.rz"
346
refute_indexed quickdir, "#{File.basename(@c1_2.spec_file)}.rz"
422
348
refute_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
423
refute_indexed quickdir, "#{@pl1.spec_name}.rz"
425
assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
426
assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
428
refute_indexed quickdir, "#{@c1_2.spec_name}"
429
refute_indexed marshal_quickdir, "#{@c1_2.spec_name}"
349
refute_indexed quickdir, "#{File.basename(@pl1.spec_file)}.rz"
351
assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz"
352
assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz"
354
refute_indexed quickdir, "#{File.basename(@c1_2.spec_file)}"
355
refute_indexed marshal_quickdir, "#{File.basename(@c1_2.spec_file)}"
431
357
assert_indexed @tempdir, "specs.#{@marshal_version}"
432
358
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
462
386
assert File.directory?(quickdir)
463
387
assert File.directory?(marshal_quickdir)
465
assert_indexed quickdir, "index"
466
assert_indexed quickdir, "index.rz"
468
assert_indexed quickdir, "latest_index"
469
assert_indexed quickdir, "latest_index.rz"
471
assert_indexed quickdir, "#{@a1.spec_name}.rz"
472
assert_indexed quickdir, "#{@a2.spec_name}.rz"
473
assert_indexed quickdir, "#{@b2.spec_name}.rz"
474
assert_indexed quickdir, "#{@c1_2.spec_name}.rz"
476
assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
478
assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
479
assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
389
assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz"
390
assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz"
481
392
assert_indexed @tempdir, "specs.#{@marshal_version}"
482
393
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
490
401
@indexer.generate_index
493
assert_match %r%^Loading 10 gems from #{Regexp.escape @tempdir}$%,
495
404
assert_match %r%^\.\.\.\.\.\.\.\.\.\.$%, @ui.output
496
assert_match %r%^Loaded all gems$%, @ui.output
497
405
assert_match %r%^Generating Marshal quick index gemspecs for 10 gems$%,
499
assert_match %r%^Generating YAML quick index gemspecs for 10 gems$%,
501
407
assert_match %r%^Complete$%, @ui.output
502
408
assert_match %r%^Generating specs index$%, @ui.output
503
409
assert_match %r%^Generating latest specs index$%, @ui.output
504
assert_match %r%^Generating quick index$%, @ui.output
505
assert_match %r%^Generating latest index$%, @ui.output
506
410
assert_match %r%^Generating prerelease specs index$%, @ui.output
507
411
assert_match %r%^Generating Marshal master index$%, @ui.output
508
assert_match %r%^Generating YAML master index for 10 gems \(this may take a while\)$%, @ui.output
509
412
assert_match %r%^Complete$%, @ui.output
510
413
assert_match %r%^Compressing indicies$%, @ui.output
512
415
assert_equal '', @ui.error
515
def test_generate_index_master
517
@indexer.generate_index
520
yaml_path = File.join @tempdir, 'yaml'
521
dump_path = File.join @tempdir, "Marshal.#{@marshal_version}"
523
yaml_index = YAML.load_file yaml_path
524
dump_index = Marshal.load Gem.read_binary(dump_path)
526
dump_index.each do |_,gem|
527
gem.send :remove_instance_variable, :@loaded
530
assert_equal yaml_index, dump_index,
531
"expected YAML and Marshal to produce identical results"
534
418
def test_generate_index_specs
536
420
@indexer.generate_index
621
505
assert File.directory?(quickdir)
622
506
assert File.directory?(marshal_quickdir)
624
@d2_1 = quick_gem 'd', '2.1'
508
@d2_1 = quick_spec 'd', '2.1'
625
509
util_build_gem @d2_1
626
510
@d2_1_tuple = [@d2_1.name, @d2_1.version, @d2_1.original_platform]
628
@d2_1_a = quick_gem 'd', '2.2.a'
512
@d2_1_a = quick_spec 'd', '2.2.a'
629
513
util_build_gem @d2_1_a
630
514
@d2_1_a_tuple = [@d2_1_a.name, @d2_1_a.version, @d2_1_a.original_platform]
632
516
gems = File.join @tempdir, 'gems'
633
FileUtils.mv File.join(@gemhome, 'cache', @d2_1.file_name), gems
634
FileUtils.mv File.join(@gemhome, 'cache', @d2_1_a.file_name), gems
518
FileUtils.mv @d2_1.cache_file, gems
519
FileUtils.mv @d2_1_a.cache_file, gems
637
522
@indexer.update_index
640
assert_indexed marshal_quickdir, "#{@d2_1.spec_name}.rz"
525
assert_indexed marshal_quickdir, "#{File.basename(@d2_1.spec_file)}.rz"
642
527
specs_index = Marshal.load Gem.read_binary(@indexer.dest_specs_index)