~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/rubygems/test_gem_indexer.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require_relative 'gemutilities'
 
1
require 'rubygems/test_case'
2
2
require 'rubygems/indexer'
3
3
 
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
6
6
end
7
7
 
8
 
class TestGemIndexer < RubyGemTestCase
 
8
class TestGemIndexer < Gem::TestCase
9
9
 
10
10
  def setup
11
11
    super
12
12
 
 
13
    util_clear_gems
13
14
    util_make_gems
14
15
 
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
17
18
    end
18
19
    util_build_gem @d2_0
19
20
 
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
22
23
 
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
25
26
 
 
27
    @tempdir = File.join(@tempdir, 'indexer')
 
28
 
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
30
32
 
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')
34
37
  end
35
38
 
36
39
  def test_initialize
54
57
  end
55
58
 
56
59
  def test_build_indicies
57
 
    spec = quick_gem 'd', '2.0'
58
 
    spec.instance_variable_set :@original_platform, ''
59
 
 
60
60
    @indexer.make_temp_directories
61
61
 
62
 
    index = Gem::SourceIndex.new
63
 
    index.add_spec spec
64
 
 
65
62
    use_ui @ui do
66
 
      @indexer.build_indicies index
 
63
      @indexer.build_indicies
67
64
    end
68
65
 
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
72
69
 
73
 
    expected = [
74
 
      ['d',      Gem::Version.new('2.0'), 'ruby'],
75
 
    ]
76
 
 
77
 
    assert_equal expected, specs, 'specs'
78
 
 
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"]]
 
77
 
 
78
    assert_equal expected, specs
 
79
 
 
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
83
84
 
84
 
    expected = [
85
 
      ['d',      Gem::Version.new('2.0'), 'ruby'],
86
 
    ]
 
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"]]
87
91
 
88
92
    assert_equal expected, latest_specs, 'latest_specs'
89
93
  end
93
97
      @indexer.generate_index
94
98
    end
95
99
 
96
 
    assert_indexed @tempdir, 'yaml'
97
 
    assert_indexed @tempdir, 'yaml.Z'
98
100
    assert_indexed @tempdir, "Marshal.#{@marshal_version}"
99
101
    assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
100
102
 
104
106
    assert File.directory?(quickdir)
105
107
    assert File.directory?(marshal_quickdir)
106
108
 
107
 
    assert_indexed quickdir, "index"
108
 
    assert_indexed quickdir, "index.rz"
109
 
 
110
 
    quick_index = File.read File.join(quickdir, 'index')
111
 
    expected = <<-EOF
112
 
a-1
113
 
a-2
114
 
a-3.a
115
 
a_evil-9
116
 
b-2
117
 
c-1.2
118
 
d-2.0
119
 
d-2.0.a
120
 
d-2.0.b
121
 
pl-1-i386-linux
122
 
    EOF
123
 
 
124
 
    assert_equal expected, quick_index
125
 
 
126
 
    assert_indexed quickdir, "latest_index"
127
 
    assert_indexed quickdir, "latest_index.rz"
128
 
 
129
 
    latest_quick_index = File.read File.join(quickdir, 'latest_index')
130
 
    expected = <<-EOF
131
 
a-2
132
 
a_evil-9
133
 
b-2
134
 
c-1.2
135
 
d-2.0
136
 
pl-1-i386-linux
137
 
    EOF
138
 
 
139
 
    assert_equal expected, latest_quick_index
140
 
 
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"
145
 
 
146
 
    assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
147
 
    refute_indexed quickdir, "#{@pl1.spec_name}.rz"
148
 
 
149
 
    assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
150
 
    assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
151
 
 
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"
 
111
 
 
112
    refute_indexed marshal_quickdir, File.basename(@c1_2.spec_file)
154
113
 
155
114
    assert_indexed @tempdir, "specs.#{@marshal_version}"
156
115
    assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
268
227
      <description>
269
228
&lt;pre&gt;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.
273
232
 
274
233
Also, a list:
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.&lt;/pre&gt;
279
238
      </description>
301
260
      @indexer.generate_index
302
261
    end
303
262
 
304
 
    assert_indexed @tempdir, 'yaml'
305
 
    assert_indexed @tempdir, 'yaml.Z'
306
263
    assert_indexed @tempdir, "Marshal.#{@marshal_version}"
307
264
    assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
308
265
 
312
269
    assert File.directory?(quickdir)
313
270
    assert File.directory?(marshal_quickdir)
314
271
 
315
 
    assert_indexed quickdir, "index"
316
 
    assert_indexed quickdir, "index.rz"
317
 
 
318
 
    assert_indexed quickdir, "latest_index"
319
 
    assert_indexed quickdir, "latest_index.rz"
320
 
 
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"
325
 
 
326
 
    assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
327
 
    refute_indexed quickdir, "#{@pl1.spec_name}.rz"
328
 
 
329
 
    assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
330
 
    assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
331
 
 
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"
 
274
 
 
275
    refute_indexed marshal_quickdir, "#{File.basename(@c1_2.spec_file)}"
334
276
 
335
277
    refute_indexed @tempdir, "specs.#{@marshal_version}"
336
278
    refute_indexed @tempdir, "specs.#{@marshal_version}.gz"
355
297
      @indexer.generate_index
356
298
    end
357
299
 
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"
362
302
 
363
303
    quickdir = File.join @tempdir, 'quick'
364
304
    marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
365
305
 
366
 
    assert File.directory?(quickdir)
367
306
    assert File.directory?(marshal_quickdir)
368
307
 
369
 
    assert_indexed quickdir, "index"
370
 
    assert_indexed quickdir, "index.rz"
371
 
 
372
 
    assert_indexed quickdir, "latest_index"
373
 
    assert_indexed quickdir, "latest_index.rz"
374
 
 
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"
379
 
 
380
 
    assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
381
 
 
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"
384
310
 
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"
416
342
 
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"
421
347
 
422
348
    refute_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
423
 
    refute_indexed quickdir, "#{@pl1.spec_name}.rz"
424
 
 
425
 
    assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz"
426
 
    assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz"
427
 
 
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"
 
350
 
 
351
    assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz"
 
352
    assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz"
 
353
 
 
354
    refute_indexed quickdir, "#{File.basename(@c1_2.spec_file)}"
 
355
    refute_indexed marshal_quickdir, "#{File.basename(@c1_2.spec_file)}"
430
356
 
431
357
    assert_indexed @tempdir, "specs.#{@marshal_version}"
432
358
    assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
451
377
      @indexer.generate_index
452
378
    end
453
379
 
454
 
    assert_indexed @tempdir, 'yaml'
455
 
    assert_indexed @tempdir, 'yaml.Z'
456
380
    assert_indexed @tempdir, "Marshal.#{@marshal_version}"
457
381
    assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
458
382
 
462
386
    assert File.directory?(quickdir)
463
387
    assert File.directory?(marshal_quickdir)
464
388
 
465
 
    assert_indexed quickdir, "index"
466
 
    assert_indexed quickdir, "index.rz"
467
 
 
468
 
    assert_indexed quickdir, "latest_index"
469
 
    assert_indexed quickdir, "latest_index.rz"
470
 
 
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"
475
 
 
476
 
    assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
477
 
 
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"
480
391
 
481
392
    assert_indexed @tempdir, "specs.#{@marshal_version}"
482
393
    assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
490
401
      @indexer.generate_index
491
402
    end
492
403
 
493
 
    assert_match %r%^Loading 10 gems from #{Regexp.escape @tempdir}$%,
494
 
                 @ui.output
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$%,
498
406
                 @ui.output
499
 
    assert_match %r%^Generating YAML quick index gemspecs for 10 gems$%,
500
 
                 @ui.output
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
511
414
 
512
415
    assert_equal '', @ui.error
513
416
  end
514
417
 
515
 
  def test_generate_index_master
516
 
    use_ui @ui do
517
 
      @indexer.generate_index
518
 
    end
519
 
 
520
 
    yaml_path = File.join @tempdir, 'yaml'
521
 
    dump_path = File.join @tempdir, "Marshal.#{@marshal_version}"
522
 
 
523
 
    yaml_index = YAML.load_file yaml_path
524
 
    dump_index = Marshal.load Gem.read_binary(dump_path)
525
 
 
526
 
    dump_index.each do |_,gem|
527
 
      gem.send :remove_instance_variable, :@loaded
528
 
    end
529
 
 
530
 
    assert_equal yaml_index, dump_index,
531
 
                 "expected YAML and Marshal to produce identical results"
532
 
  end
533
 
 
534
418
  def test_generate_index_specs
535
419
    use_ui @ui do
536
420
      @indexer.generate_index
621
505
    assert File.directory?(quickdir)
622
506
    assert File.directory?(marshal_quickdir)
623
507
 
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]
627
511
 
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]
631
515
 
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
 
517
 
 
518
    FileUtils.mv @d2_1.cache_file, gems
 
519
    FileUtils.mv @d2_1_a.cache_file, gems
635
520
 
636
521
    use_ui @ui do
637
522
      @indexer.update_index
638
523
    end
639
524
 
640
 
    assert_indexed marshal_quickdir, "#{@d2_1.spec_name}.rz"
 
525
    assert_indexed marshal_quickdir, "#{File.basename(@d2_1.spec_file)}.rz"
641
526
 
642
527
    specs_index = Marshal.load Gem.read_binary(@indexer.dest_specs_index)
643
528
 
669
554
    refute File.exist?(file), "#{file} exists"
670
555
  end
671
556
 
672
 
end if ''.respond_to? :to_xs
 
557
end if defined?(Builder::XChar)
673
558