slimgems 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/ChangeLog +5811 -0
  2. data/History.txt +887 -0
  3. data/LICENSE.txt +51 -0
  4. data/README.md +87 -0
  5. data/Rakefile +120 -0
  6. data/bin/gem +25 -0
  7. data/bin/update_slimgems +35 -0
  8. data/bootstrap/Rakefile +4 -0
  9. data/hide_lib_for_update/note.txt +5 -0
  10. data/lib/gauntlet_rubygems.rb +50 -0
  11. data/lib/rbconfig/datadir.rb +20 -0
  12. data/lib/rubygems.rb +1220 -0
  13. data/lib/rubygems/builder.rb +102 -0
  14. data/lib/rubygems/command.rb +534 -0
  15. data/lib/rubygems/command_manager.rb +182 -0
  16. data/lib/rubygems/commands/build_command.rb +53 -0
  17. data/lib/rubygems/commands/cert_command.rb +86 -0
  18. data/lib/rubygems/commands/check_command.rb +80 -0
  19. data/lib/rubygems/commands/cleanup_command.rb +106 -0
  20. data/lib/rubygems/commands/contents_command.rb +98 -0
  21. data/lib/rubygems/commands/dependency_command.rb +195 -0
  22. data/lib/rubygems/commands/environment_command.rb +132 -0
  23. data/lib/rubygems/commands/fetch_command.rb +67 -0
  24. data/lib/rubygems/commands/generate_index_command.rb +133 -0
  25. data/lib/rubygems/commands/help_command.rb +172 -0
  26. data/lib/rubygems/commands/install_command.rb +178 -0
  27. data/lib/rubygems/commands/list_command.rb +35 -0
  28. data/lib/rubygems/commands/lock_command.rb +110 -0
  29. data/lib/rubygems/commands/mirror_command.rb +111 -0
  30. data/lib/rubygems/commands/outdated_command.rb +33 -0
  31. data/lib/rubygems/commands/owner_command.rb +75 -0
  32. data/lib/rubygems/commands/pristine_command.rb +93 -0
  33. data/lib/rubygems/commands/push_command.rb +56 -0
  34. data/lib/rubygems/commands/query_command.rb +280 -0
  35. data/lib/rubygems/commands/rdoc_command.rb +91 -0
  36. data/lib/rubygems/commands/search_command.rb +31 -0
  37. data/lib/rubygems/commands/server_command.rb +86 -0
  38. data/lib/rubygems/commands/setup_command.rb +387 -0
  39. data/lib/rubygems/commands/sources_command.rb +157 -0
  40. data/lib/rubygems/commands/specification_command.rb +125 -0
  41. data/lib/rubygems/commands/stale_command.rb +27 -0
  42. data/lib/rubygems/commands/uninstall_command.rb +83 -0
  43. data/lib/rubygems/commands/unpack_command.rb +121 -0
  44. data/lib/rubygems/commands/update_command.rb +212 -0
  45. data/lib/rubygems/commands/which_command.rb +86 -0
  46. data/lib/rubygems/config_file.rb +345 -0
  47. data/lib/rubygems/custom_require.rb +44 -0
  48. data/lib/rubygems/defaults.rb +101 -0
  49. data/lib/rubygems/dependency.rb +227 -0
  50. data/lib/rubygems/dependency_installer.rb +286 -0
  51. data/lib/rubygems/dependency_list.rb +208 -0
  52. data/lib/rubygems/doc_manager.rb +242 -0
  53. data/lib/rubygems/errors.rb +35 -0
  54. data/lib/rubygems/exceptions.rb +91 -0
  55. data/lib/rubygems/ext.rb +18 -0
  56. data/lib/rubygems/ext/builder.rb +56 -0
  57. data/lib/rubygems/ext/configure_builder.rb +25 -0
  58. data/lib/rubygems/ext/ext_conf_builder.rb +24 -0
  59. data/lib/rubygems/ext/rake_builder.rb +39 -0
  60. data/lib/rubygems/format.rb +81 -0
  61. data/lib/rubygems/gem_openssl.rb +92 -0
  62. data/lib/rubygems/gem_path_searcher.rb +100 -0
  63. data/lib/rubygems/gem_runner.rb +79 -0
  64. data/lib/rubygems/gemcutter_utilities.rb +49 -0
  65. data/lib/rubygems/indexer.rb +720 -0
  66. data/lib/rubygems/install_update_options.rb +125 -0
  67. data/lib/rubygems/installer.rb +604 -0
  68. data/lib/rubygems/local_remote_options.rb +135 -0
  69. data/lib/rubygems/old_format.rb +153 -0
  70. data/lib/rubygems/package.rb +97 -0
  71. data/lib/rubygems/package/f_sync_dir.rb +23 -0
  72. data/lib/rubygems/package/tar_header.rb +266 -0
  73. data/lib/rubygems/package/tar_input.rb +222 -0
  74. data/lib/rubygems/package/tar_output.rb +144 -0
  75. data/lib/rubygems/package/tar_reader.rb +106 -0
  76. data/lib/rubygems/package/tar_reader/entry.rb +141 -0
  77. data/lib/rubygems/package/tar_writer.rb +241 -0
  78. data/lib/rubygems/package_task.rb +126 -0
  79. data/lib/rubygems/platform.rb +183 -0
  80. data/lib/rubygems/remote_fetcher.rb +414 -0
  81. data/lib/rubygems/require_paths_builder.rb +18 -0
  82. data/lib/rubygems/requirement.rb +153 -0
  83. data/lib/rubygems/security.rb +814 -0
  84. data/lib/rubygems/server.rb +872 -0
  85. data/lib/rubygems/source_index.rb +597 -0
  86. data/lib/rubygems/source_info_cache.rb +395 -0
  87. data/lib/rubygems/source_info_cache_entry.rb +56 -0
  88. data/lib/rubygems/spec_fetcher.rb +337 -0
  89. data/lib/rubygems/specification.rb +1486 -0
  90. data/lib/rubygems/test_utilities.rb +147 -0
  91. data/lib/rubygems/text.rb +65 -0
  92. data/lib/rubygems/uninstaller.rb +278 -0
  93. data/lib/rubygems/user_interaction.rb +527 -0
  94. data/lib/rubygems/validator.rb +240 -0
  95. data/lib/rubygems/version.rb +316 -0
  96. data/lib/rubygems/version_option.rb +65 -0
  97. data/lib/ubygems.rb +10 -0
  98. data/setup.rb +42 -0
  99. data/test/bogussources.rb +8 -0
  100. data/test/data/gem-private_key.pem +27 -0
  101. data/test/data/gem-public_cert.pem +20 -0
  102. data/test/fake_certlib/openssl.rb +7 -0
  103. data/test/foo/discover.rb +0 -0
  104. data/test/functional.rb +92 -0
  105. data/test/gem_installer_test_case.rb +97 -0
  106. data/test/gem_package_tar_test_case.rb +132 -0
  107. data/test/gemutilities.rb +605 -0
  108. data/test/insure_session.rb +43 -0
  109. data/test/mockgemui.rb +56 -0
  110. data/test/plugin/exception/rubygems_plugin.rb +2 -0
  111. data/test/plugin/load/rubygems_plugin.rb +1 -0
  112. data/test/plugin/standarderror/rubygems_plugin.rb +2 -0
  113. data/test/private_key.pem +27 -0
  114. data/test/public_cert.pem +20 -0
  115. data/test/rubygems_plugin.rb +21 -0
  116. data/test/simple_gem.rb +66 -0
  117. data/test/test_config.rb +12 -0
  118. data/test/test_gem.rb +766 -0
  119. data/test/test_gem_builder.rb +27 -0
  120. data/test/test_gem_command.rb +178 -0
  121. data/test/test_gem_command_manager.rb +207 -0
  122. data/test/test_gem_commands_build_command.rb +74 -0
  123. data/test/test_gem_commands_cert_command.rb +124 -0
  124. data/test/test_gem_commands_check_command.rb +18 -0
  125. data/test/test_gem_commands_contents_command.rb +156 -0
  126. data/test/test_gem_commands_dependency_command.rb +216 -0
  127. data/test/test_gem_commands_environment_command.rb +144 -0
  128. data/test/test_gem_commands_fetch_command.rb +76 -0
  129. data/test/test_gem_commands_generate_index_command.rb +135 -0
  130. data/test/test_gem_commands_install_command.rb +315 -0
  131. data/test/test_gem_commands_list_command.rb +36 -0
  132. data/test/test_gem_commands_lock_command.rb +68 -0
  133. data/test/test_gem_commands_mirror_command.rb +60 -0
  134. data/test/test_gem_commands_outdated_command.rb +40 -0
  135. data/test/test_gem_commands_owner_command.rb +105 -0
  136. data/test/test_gem_commands_pristine_command.rb +108 -0
  137. data/test/test_gem_commands_push_command.rb +81 -0
  138. data/test/test_gem_commands_query_command.rb +426 -0
  139. data/test/test_gem_commands_server_command.rb +59 -0
  140. data/test/test_gem_commands_sources_command.rb +209 -0
  141. data/test/test_gem_commands_specification_command.rb +139 -0
  142. data/test/test_gem_commands_stale_command.rb +38 -0
  143. data/test/test_gem_commands_uninstall_command.rb +83 -0
  144. data/test/test_gem_commands_unpack_command.rb +199 -0
  145. data/test/test_gem_commands_update_command.rb +353 -0
  146. data/test/test_gem_commands_which_command.rb +66 -0
  147. data/test/test_gem_config_file.rb +287 -0
  148. data/test/test_gem_dependency.rb +149 -0
  149. data/test/test_gem_dependency_installer.rb +661 -0
  150. data/test/test_gem_dependency_list.rb +230 -0
  151. data/test/test_gem_doc_manager.rb +31 -0
  152. data/test/test_gem_ext_configure_builder.rb +84 -0
  153. data/test/test_gem_ext_ext_conf_builder.rb +173 -0
  154. data/test/test_gem_ext_rake_builder.rb +81 -0
  155. data/test/test_gem_format.rb +70 -0
  156. data/test/test_gem_gem_path_searcher.rb +78 -0
  157. data/test/test_gem_gem_runner.rb +45 -0
  158. data/test/test_gem_gemcutter_utilities.rb +103 -0
  159. data/test/test_gem_indexer.rb +673 -0
  160. data/test/test_gem_install_update_options.rb +68 -0
  161. data/test/test_gem_installer.rb +857 -0
  162. data/test/test_gem_local_remote_options.rb +97 -0
  163. data/test/test_gem_package_tar_header.rb +130 -0
  164. data/test/test_gem_package_tar_input.rb +112 -0
  165. data/test/test_gem_package_tar_output.rb +97 -0
  166. data/test/test_gem_package_tar_reader.rb +46 -0
  167. data/test/test_gem_package_tar_reader_entry.rb +109 -0
  168. data/test/test_gem_package_tar_writer.rb +144 -0
  169. data/test/test_gem_package_task.rb +59 -0
  170. data/test/test_gem_platform.rb +264 -0
  171. data/test/test_gem_remote_fetcher.rb +740 -0
  172. data/test/test_gem_requirement.rb +292 -0
  173. data/test/test_gem_server.rb +356 -0
  174. data/test/test_gem_silent_ui.rb +113 -0
  175. data/test/test_gem_source_index.rb +461 -0
  176. data/test/test_gem_spec_fetcher.rb +410 -0
  177. data/test/test_gem_specification.rb +1291 -0
  178. data/test/test_gem_stream_ui.rb +218 -0
  179. data/test/test_gem_text.rb +43 -0
  180. data/test/test_gem_uninstaller.rb +146 -0
  181. data/test/test_gem_validator.rb +63 -0
  182. data/test/test_gem_version.rb +181 -0
  183. data/test/test_gem_version_option.rb +89 -0
  184. data/test/test_kernel.rb +59 -0
  185. metadata +413 -0
@@ -0,0 +1,81 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/ext'
3
+
4
+ class TestGemExtRakeBuilder < RubyGemTestCase
5
+ def setup
6
+ super
7
+
8
+ @ext = File.join @tempdir, 'ext'
9
+ @dest_path = File.join @tempdir, 'prefix'
10
+
11
+ FileUtils.mkdir_p @ext
12
+ FileUtils.mkdir_p @dest_path
13
+ end
14
+
15
+ def test_class_build
16
+ File.open File.join(@ext, 'mkrf_conf.rb'), 'w' do |mkrf_conf|
17
+ mkrf_conf.puts <<-EO_MKRF
18
+ File.open("Rakefile","w") do |f|
19
+ f.puts "task :default"
20
+ end
21
+ EO_MKRF
22
+ end
23
+
24
+ output = []
25
+ realdir = nil # HACK /tmp vs. /private/tmp
26
+
27
+ build_rake_in do
28
+ Dir.chdir @ext do
29
+ realdir = Dir.pwd
30
+ Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', nil, @dest_path, output
31
+ end
32
+ end
33
+
34
+ output = output.join "\n"
35
+
36
+ expected = [
37
+ "#{@@ruby} mkrf_conf.rb",
38
+ "",
39
+ "#{@@rake} RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}",
40
+ "(in #{realdir})\n"
41
+ ]
42
+
43
+ refute_match %r%^rake failed:%, output
44
+ assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, output
45
+ assert_match %r%^#{Regexp.escape @@rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, output
46
+ end
47
+
48
+ def test_class_build_fail
49
+ File.open File.join(@ext, 'mkrf_conf.rb'), 'w' do |mkrf_conf|
50
+ mkrf_conf.puts <<-EO_MKRF
51
+ File.open("Rakefile","w") do |f|
52
+ f.puts "task :default do abort 'fail' end"
53
+ end
54
+ EO_MKRF
55
+ end
56
+
57
+ output = []
58
+
59
+ error = assert_raises Gem::InstallError do
60
+ build_rake_in do
61
+ Dir.chdir @ext do
62
+ Gem::Ext::RakeBuilder.build "mkrf_conf.rb", nil, @dest_path, output
63
+ end
64
+ end
65
+ end
66
+
67
+ expected = <<-EOF.strip
68
+ rake failed:
69
+
70
+ #{@@ruby} mkrf_conf.rb
71
+
72
+ #{@@rake} RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}
73
+ EOF
74
+
75
+ assert_match %r%^rake failed:%, error.message
76
+ assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, error.message
77
+ assert_match %r%^#{Regexp.escape @@rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, error.message
78
+ end
79
+
80
+ end
81
+
@@ -0,0 +1,70 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require File.expand_path('../simple_gem', __FILE__)
3
+ require 'rubygems/format'
4
+
5
+ class TestGemFormat < RubyGemTestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @simple_gem = SIMPLE_GEM
11
+ end
12
+
13
+ def test_class_from_file_by_path
14
+ util_make_gems
15
+
16
+ gems = Dir[File.join(@gemhome, 'cache', '*.gem')]
17
+
18
+ names = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].map do |spec|
19
+ spec.original_name
20
+ end
21
+
22
+ gems_n_names = gems.sort.zip names
23
+
24
+ gems_n_names.each do |gemfile, name|
25
+ spec = Gem::Format.from_file_by_path(gemfile).spec
26
+
27
+ assert_equal name, spec.original_name
28
+ end
29
+ end
30
+
31
+ def test_class_from_file_by_path_empty
32
+ util_make_gems
33
+
34
+ empty_gem = File.join @tempdir, 'empty.gem'
35
+ FileUtils.touch empty_gem
36
+
37
+ assert_nil Gem::Format.from_file_by_path(empty_gem)
38
+ end
39
+
40
+ def test_class_from_file_by_path_nonexistent
41
+ assert_raises Gem::Exception do
42
+ Gem::Format.from_file_by_path '/nonexistent'
43
+ end
44
+ end
45
+
46
+ def test_class_from_io_garbled
47
+ e = assert_raises Gem::Package::FormatError do
48
+ # subtly bogus input
49
+ Gem::Format.from_io(StringIO.new(@simple_gem.upcase))
50
+ end
51
+
52
+ assert_equal 'No metadata found!', e.message
53
+
54
+ e = assert_raises Gem::Package::FormatError do
55
+ # Totally bogus input
56
+ Gem::Format.from_io(StringIO.new(@simple_gem.reverse))
57
+ end
58
+
59
+ assert_equal 'No metadata found!', e.message
60
+
61
+ e = assert_raises Gem::Package::FormatError do
62
+ # This was intentionally screws up YAML parsing.
63
+ Gem::Format.from_io(StringIO.new(@simple_gem.gsub(/:/, "boom")))
64
+ end
65
+
66
+ assert_equal 'No metadata found!', e.message
67
+ end
68
+
69
+ end
70
+
@@ -0,0 +1,78 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/gem_path_searcher'
3
+
4
+ class Gem::GemPathSearcher
5
+ attr_accessor :gemspecs
6
+ attr_accessor :lib_dirs
7
+ end
8
+
9
+ class TestGemGemPathSearcher < RubyGemTestCase
10
+
11
+ def setup
12
+ super
13
+
14
+ @foo1 = quick_gem 'foo', '0.1' do |s|
15
+ s.require_paths << 'lib2'
16
+ s.files << 'lib/foo.rb'
17
+ end
18
+
19
+ path = File.join 'gems', @foo1.full_name, 'lib', 'foo.rb'
20
+ write_file(path) { |fp| fp.puts "# #{path}" }
21
+
22
+ @foo2 = quick_gem 'foo', '0.2'
23
+ @bar1 = quick_gem 'bar', '0.1'
24
+ @bar2 = quick_gem 'bar', '0.2'
25
+ @nrp = quick_gem 'nil_require_paths', '0.1'
26
+ @nrp.require_paths = nil
27
+
28
+
29
+ @fetcher = Gem::FakeFetcher.new
30
+ Gem::RemoteFetcher.fetcher = @fetcher
31
+
32
+ Gem.source_index = util_setup_spec_fetcher @foo1, @foo2, @bar1, @bar2
33
+
34
+ @gps = Gem::GemPathSearcher.new
35
+ end
36
+
37
+ def test_find
38
+ assert_equal @foo1, @gps.find('foo')
39
+ end
40
+
41
+ def test_find_all
42
+ assert_equal [@foo1], @gps.find_all('foo')
43
+ end
44
+
45
+ def test_init_gemspecs
46
+ assert_equal [@bar2, @bar1, @foo2, @foo1], @gps.init_gemspecs
47
+ end
48
+
49
+ def test_lib_dirs_for
50
+ lib_dirs = @gps.lib_dirs_for(@foo1)
51
+ expected = File.join @gemhome, 'gems', @foo1.full_name, '{lib,lib2}'
52
+
53
+ assert_equal expected, lib_dirs
54
+ end
55
+
56
+ def test_lib_dirs_for_nil_require_paths
57
+ assert_nil @gps.lib_dirs_for(@nrp)
58
+ end
59
+
60
+ def test_matching_file_eh
61
+ refute @gps.matching_file?(@foo1, 'bar')
62
+ assert @gps.matching_file?(@foo1, 'foo')
63
+ end
64
+
65
+ def test_matching_files
66
+ assert_equal [], @gps.matching_files(@foo1, 'bar')
67
+
68
+ expected = File.join @foo1.full_gem_path, 'lib', 'foo.rb'
69
+
70
+ assert_equal [expected], @gps.matching_files(@foo1, 'foo')
71
+ end
72
+
73
+ def test_matching_files_nil_require_paths
74
+ assert_empty @gps.matching_files(@nrp, 'foo')
75
+ end
76
+
77
+ end
78
+
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/gem_runner'
3
+
4
+ class TestGemGemRunner < RubyGemTestCase
5
+
6
+ def test_do_configuration
7
+ Gem.clear_paths
8
+
9
+ temp_conf = File.join @tempdir, '.gemrc'
10
+
11
+ other_gem_path = File.join @tempdir, 'other_gem_path'
12
+ other_gem_home = File.join @tempdir, 'other_gem_home'
13
+
14
+ Gem.ensure_gem_subdirectories other_gem_path
15
+ Gem.ensure_gem_subdirectories other_gem_home
16
+
17
+ File.open temp_conf, 'w' do |fp|
18
+ fp.puts "gem: --commands"
19
+ fp.puts "gemhome: #{other_gem_home}"
20
+ fp.puts "gempath:"
21
+ fp.puts " - #{other_gem_path}"
22
+ fp.puts "rdoc: --all"
23
+ end
24
+
25
+ gr = Gem::GemRunner.new
26
+ gr.send :do_configuration, %W[--config-file #{temp_conf}]
27
+
28
+ assert_equal [other_gem_path, other_gem_home], Gem.path
29
+ assert_equal %w[--commands], Gem::Command.extra_args
30
+ assert_equal %w[--all], Gem::DocManager.configured_args
31
+ end
32
+
33
+ def test_build_args__are_handled
34
+ Gem.clear_paths
35
+
36
+ gr = Gem::GemRunner.new
37
+ assert_raises(Gem::SystemExitException) do
38
+ gr.run(%W[--help -- --build_arg1 --build_arg2])
39
+ end
40
+
41
+ assert_equal %w[--build_arg1 --build_arg2], Gem::Command.build_args
42
+ end
43
+
44
+ end
45
+
@@ -0,0 +1,103 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems'
3
+ require 'rubygems/gemcutter_utilities'
4
+
5
+ class TestGemGemcutterUtilities < RubyGemTestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ ENV['RUBYGEMS_HOST'] = nil
11
+ Gem.configuration.rubygems_api_key = nil
12
+
13
+ @cmd = Gem::Command.new '', 'summary'
14
+ @cmd.extend Gem::GemcutterUtilities
15
+ end
16
+
17
+ def test_sign_in
18
+ api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
19
+ util_sign_in [api_key, 200, 'OK']
20
+
21
+ assert_match %r{Enter your rubygems.org credentials.}, @sign_in_ui.output
22
+ assert @fetcher.last_request["authorization"]
23
+ assert_match %r{Signed in.}, @sign_in_ui.output
24
+
25
+ credentials = YAML.load_file Gem.configuration.credentials_path
26
+ assert_equal api_key, credentials[:rubygems_api_key]
27
+ end
28
+
29
+ def test_sign_in_with_host
30
+ api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
31
+ util_sign_in [api_key, 200, 'OK'], 'http://example.com'
32
+
33
+ assert_match %r{Enter your rubygems.org credentials.}, @sign_in_ui.output
34
+ assert @fetcher.last_request["authorization"]
35
+ assert_match %r{Signed in.}, @sign_in_ui.output
36
+
37
+ credentials = YAML.load_file Gem.configuration.credentials_path
38
+ assert_equal api_key, credentials[:rubygems_api_key]
39
+ end
40
+
41
+ def test_sign_in_skips_with_existing_credentials
42
+ api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
43
+ Gem.configuration.rubygems_api_key = api_key
44
+
45
+ util_sign_in [api_key, 200, 'OK']
46
+
47
+ assert_equal "", @sign_in_ui.output
48
+ end
49
+
50
+ def test_sign_in_with_other_credentials_doesnt_overwrite_other_keys
51
+ api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
52
+ other_api_key = 'f46dbb18bb6a9c97cdc61b5b85c186a17403cdcbf'
53
+
54
+ FileUtils.mkdir_p File.dirname(Gem.configuration.credentials_path)
55
+ open Gem.configuration.credentials_path, 'w' do |f|
56
+ f.write Hash[:other_api_key, other_api_key].to_yaml
57
+ end
58
+ util_sign_in [api_key, 200, 'OK']
59
+
60
+ assert_match %r{Enter your rubygems.org credentials.}, @sign_in_ui.output
61
+ assert_match %r{Signed in.}, @sign_in_ui.output
62
+
63
+ credentials = YAML.load_file Gem.configuration.credentials_path
64
+ assert_equal api_key, credentials[:rubygems_api_key]
65
+ assert_equal other_api_key, credentials[:other_api_key]
66
+ end
67
+
68
+ def test_sign_in_with_bad_credentials
69
+ skip 'Always uses $stdin on windows' if Gem.win_platform?
70
+
71
+ assert_raises MockGemUi::TermError do
72
+ util_sign_in ['Access Denied.', 403, 'Forbidden']
73
+ end
74
+
75
+ assert_match %r{Enter your rubygems.org credentials.}, @sign_in_ui.output
76
+ assert_match %r{Access Denied.}, @sign_in_ui.output
77
+ end
78
+
79
+ def util_sign_in response, host = nil
80
+ skip 'Always uses $stdin on windows' if Gem.win_platform?
81
+
82
+ email = 'you@example.com'
83
+ password = 'secret'
84
+
85
+ if host
86
+ ENV['RUBYGEMS_HOST'] = host
87
+ else
88
+ host = Gem.host
89
+ end
90
+
91
+ @fetcher = Gem::FakeFetcher.new
92
+ @fetcher.data["#{host}/api/v1/api_key"] = response
93
+ Gem::RemoteFetcher.fetcher = @fetcher
94
+
95
+ @sign_in_ui = MockGemUi.new "#{email}\n#{password}\n"
96
+
97
+ use_ui @sign_in_ui do
98
+ @cmd.sign_in
99
+ end
100
+ end
101
+
102
+ end
103
+
@@ -0,0 +1,673 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/indexer'
3
+
4
+ unless defined?(Builder::XChar) then
5
+ warn "Gem::Indexer tests are being skipped. Install builder gem." if $VERBOSE
6
+ end
7
+
8
+ class TestGemIndexer < RubyGemTestCase
9
+
10
+ def setup
11
+ super
12
+
13
+ util_make_gems
14
+
15
+ @d2_0 = quick_gem 'd', '2.0' do |s|
16
+ s.date = Gem::Specification::TODAY - 86400 * 3
17
+ end
18
+ util_build_gem @d2_0
19
+
20
+ @d2_0_a = quick_gem 'd', '2.0.a'
21
+ util_build_gem @d2_0_a
22
+
23
+ @d2_0_b = quick_gem 'd', '2.0.b'
24
+ util_build_gem @d2_0_b
25
+
26
+ gems = File.join(@tempdir, 'gems')
27
+ FileUtils.mkdir_p gems
28
+ cache_gems = File.join @gemhome, 'cache', '*.gem'
29
+ FileUtils.mv Dir[cache_gems], gems
30
+
31
+ @indexer = Gem::Indexer.new @tempdir, :rss_title => 'ExampleForge gems',
32
+ :rss_host => 'example.com',
33
+ :rss_gems_host => 'gems.example.com'
34
+ end
35
+
36
+ def test_initialize
37
+ assert_equal @tempdir, @indexer.dest_directory
38
+ assert_equal File.join(Dir.tmpdir, "gem_generate_index_#{$$}"),
39
+ @indexer.directory
40
+
41
+ indexer = Gem::Indexer.new @tempdir
42
+ assert indexer.build_legacy
43
+ assert indexer.build_modern
44
+
45
+ indexer = Gem::Indexer.new @tempdir, :build_legacy => false,
46
+ :build_modern => true
47
+ refute indexer.build_legacy
48
+ assert indexer.build_modern
49
+
50
+ indexer = Gem::Indexer.new @tempdir, :build_legacy => true,
51
+ :build_modern => false
52
+ assert indexer.build_legacy
53
+ refute indexer.build_modern
54
+ end
55
+
56
+ def test_build_indicies
57
+ spec = quick_gem 'd', '2.0'
58
+ spec.instance_variable_set :@original_platform, ''
59
+
60
+ @indexer.make_temp_directories
61
+
62
+ index = Gem::SourceIndex.new
63
+ index.add_spec spec
64
+
65
+ use_ui @ui do
66
+ @indexer.build_indicies index
67
+ end
68
+
69
+ specs_path = File.join @indexer.directory, "specs.#{@marshal_version}"
70
+ specs_dump = Gem.read_binary specs_path
71
+ specs = Marshal.load specs_dump
72
+
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}"
81
+ latest_specs_dump = Gem.read_binary latest_specs_path
82
+ latest_specs = Marshal.load latest_specs_dump
83
+
84
+ expected = [
85
+ ['d', Gem::Version.new('2.0'), 'ruby'],
86
+ ]
87
+
88
+ assert_equal expected, latest_specs, 'latest_specs'
89
+ end
90
+
91
+ def test_generate_index
92
+ use_ui @ui do
93
+ @indexer.generate_index
94
+ end
95
+
96
+ assert_indexed @tempdir, 'yaml'
97
+ assert_indexed @tempdir, 'yaml.Z'
98
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}"
99
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
100
+
101
+ quickdir = File.join @tempdir, 'quick'
102
+ marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
103
+
104
+ assert File.directory?(quickdir)
105
+ assert File.directory?(marshal_quickdir)
106
+
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
154
+
155
+ assert_indexed @tempdir, "specs.#{@marshal_version}"
156
+ assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
157
+
158
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
159
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
160
+
161
+ expected = <<-EOF
162
+ <?xml version=\"1.0\"?>
163
+ <rss version=\"2.0\">
164
+ <channel>
165
+ <title>ExampleForge gems</title>
166
+ <link>http://example.com</link>
167
+ <description>Recently released gems from http://example.com</description>
168
+ <generator>#{Gem::NAME} v#{Gem::VERSION}</generator>
169
+ <docs>http://cyber.law.harvard.edu/rss/rss.html</docs>
170
+ <item>
171
+ <title>a-2</title>
172
+ <description>
173
+ &lt;pre&gt;This is a test description&lt;/pre&gt;
174
+ </description>
175
+ <author>example@example.com (A User)</author>
176
+ <guid>a-2</guid>
177
+ <enclosure url=\"http://gems.example.com/gems/a-2.gem\"
178
+ length=\"3072\" type=\"application/octet-stream\" />
179
+ <pubDate>#{@a2.date.rfc2822}</pubDate>
180
+ <link>http://example.com</link>
181
+ </item>
182
+ <item>
183
+ <title>a-3.a</title>
184
+ <description>
185
+ &lt;pre&gt;This is a test description&lt;/pre&gt;
186
+ </description>
187
+ <author>example@example.com (A User)</author>
188
+ <guid>a-3.a</guid>
189
+ <enclosure url=\"http://gems.example.com/gems/a-3.a.gem\"
190
+ length=\"3072\" type=\"application/octet-stream\" />
191
+ <pubDate>#{@a3a.date.rfc2822}</pubDate>
192
+ <link>http://example.com</link>
193
+ </item>
194
+ <item>
195
+ <title>a_evil-9</title>
196
+ <description>
197
+ &lt;pre&gt;This is a test description&lt;/pre&gt;
198
+ </description>
199
+ <author>example@example.com (A User)</author>
200
+ <guid>a_evil-9</guid>
201
+ <enclosure url=\"http://gems.example.com/gems/a_evil-9.gem\"
202
+ length=\"3072\" type=\"application/octet-stream\" />
203
+ <pubDate>#{@a_evil9.date.rfc2822}</pubDate>
204
+ <link>http://example.com</link>
205
+ </item>
206
+ <item>
207
+ <title>b-2</title>
208
+ <description>
209
+ &lt;pre&gt;This is a test description&lt;/pre&gt;
210
+ </description>
211
+ <author>example@example.com (A User)</author>
212
+ <guid>b-2</guid>
213
+ <enclosure url=\"http://gems.example.com/gems/b-2.gem\"
214
+ length=\"3072\" type=\"application/octet-stream\" />
215
+ <pubDate>#{@b2.date.rfc2822}</pubDate>
216
+ <link>http://example.com</link>
217
+ </item>
218
+ <item>
219
+ <title>c-1.2</title>
220
+ <description>
221
+ &lt;pre&gt;This is a test description&lt;/pre&gt;
222
+ </description>
223
+ <author>example@example.com (A User)</author>
224
+ <guid>c-1.2</guid>
225
+ <enclosure url=\"http://gems.example.com/gems/c-1.2.gem\"
226
+ length=\"3072\" type=\"application/octet-stream\" />
227
+ <pubDate>#{@c1_2.date.rfc2822}</pubDate>
228
+ <link>http://example.com</link>
229
+ </item>
230
+ <item>
231
+ <title>d-2.0.a</title>
232
+ <description>
233
+ &lt;pre&gt;This is a test description&lt;/pre&gt;
234
+ </description>
235
+ <author>example@example.com (A User)</author>
236
+ <guid>d-2.0.a</guid>
237
+ <enclosure url=\"http://gems.example.com/gems/d-2.0.a.gem\"
238
+ length=\"3072\" type=\"application/octet-stream\" />
239
+ <pubDate>#{@d2_0_a.date.rfc2822}</pubDate>
240
+ <link>http://example.com</link>
241
+ </item>
242
+ <item>
243
+ <title>d-2.0.b</title>
244
+ <description>
245
+ &lt;pre&gt;This is a test description&lt;/pre&gt;
246
+ </description>
247
+ <author>example@example.com (A User)</author>
248
+ <guid>d-2.0.b</guid>
249
+ <enclosure url=\"http://gems.example.com/gems/d-2.0.b.gem\"
250
+ length=\"3072\" type=\"application/octet-stream\" />
251
+ <pubDate>#{@d2_0_b.date.rfc2822}</pubDate>
252
+ <link>http://example.com</link>
253
+ </item>
254
+ <item>
255
+ <title>pl-1-x86-linux</title>
256
+ <description>
257
+ &lt;pre&gt;This is a test description&lt;/pre&gt;
258
+ </description>
259
+ <author>example@example.com (A User)</author>
260
+ <guid>pl-1-x86-linux</guid>
261
+ <enclosure url=\"http://gems.example.com/gems/pl-1-x86-linux.gem\"
262
+ length=\"3072\" type=\"application/octet-stream\" />
263
+ <pubDate>#{@pl1.date.rfc2822}</pubDate>
264
+ <link>http://example.com</link>
265
+ </item>
266
+ <item>
267
+ <title>a-1</title>
268
+ <description>
269
+ &lt;pre&gt;This line is really, really long. So long, in fact, that it is more than
270
+ 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.
272
+ Without the wrapping, the text might not look good in the RSS feed.
273
+
274
+ Also, a list:
275
+ * An entry that's actually kind of sort
276
+ * an entry that's really long, which will probably get wrapped funny.
277
+ That's ok, somebody wasn't thinking straight when they made it more than
278
+ eighty characters.&lt;/pre&gt;
279
+ </description>
280
+ <author>example@example.com (Example), example2@example.com (Example2)</author>
281
+ <guid>a-1</guid>
282
+ <enclosure url=\"http://gems.example.com/gems/a-1.gem\"
283
+ length=\"3584\" type=\"application/octet-stream\" />
284
+ <pubDate>#{@a1.date.rfc2822}</pubDate>
285
+ <link>http://a.example.com</link>
286
+ </item>
287
+ </channel>
288
+ </rss>
289
+ EOF
290
+
291
+ gems_rss = File.read File.join(@tempdir, 'index.rss')
292
+
293
+ assert_equal expected, gems_rss
294
+ end
295
+
296
+ def test_generate_index_legacy
297
+ @indexer.build_modern = false
298
+ @indexer.build_legacy = true
299
+
300
+ use_ui @ui do
301
+ @indexer.generate_index
302
+ end
303
+
304
+ assert_indexed @tempdir, 'yaml'
305
+ assert_indexed @tempdir, 'yaml.Z'
306
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}"
307
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
308
+
309
+ quickdir = File.join @tempdir, 'quick'
310
+ marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
311
+
312
+ assert File.directory?(quickdir)
313
+ assert File.directory?(marshal_quickdir)
314
+
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}"
334
+
335
+ refute_indexed @tempdir, "specs.#{@marshal_version}"
336
+ refute_indexed @tempdir, "specs.#{@marshal_version}.gz"
337
+
338
+ refute_indexed @tempdir, "latest_specs.#{@marshal_version}"
339
+ refute_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
340
+ end
341
+
342
+ def test_generate_index_legacy_back_to_back
343
+ @indexer.build_modern = true
344
+ @indexer.build_legacy = true
345
+
346
+ use_ui @ui do
347
+ @indexer.generate_index
348
+ end
349
+
350
+ @indexer = Gem::Indexer.new @tempdir
351
+ @indexer.build_modern = false
352
+ @indexer.build_legacy = true
353
+
354
+ use_ui @ui do
355
+ @indexer.generate_index
356
+ end
357
+
358
+ assert_indexed @tempdir, 'yaml'
359
+ assert_indexed @tempdir, 'yaml.Z'
360
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}"
361
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
362
+
363
+ quickdir = File.join @tempdir, 'quick'
364
+ marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
365
+
366
+ assert File.directory?(quickdir)
367
+ assert File.directory?(marshal_quickdir)
368
+
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"
384
+
385
+ assert_indexed @tempdir, "specs.#{@marshal_version}"
386
+ assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
387
+
388
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
389
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
390
+ end
391
+
392
+ def test_generate_index_modern
393
+ @indexer.build_modern = true
394
+ @indexer.build_legacy = false
395
+
396
+ use_ui @ui do
397
+ @indexer.generate_index
398
+ end
399
+
400
+ refute_indexed @tempdir, 'yaml'
401
+ refute_indexed @tempdir, 'yaml.Z'
402
+ refute_indexed @tempdir, "Marshal.#{@marshal_version}"
403
+ refute_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
404
+
405
+ quickdir = File.join @tempdir, 'quick'
406
+ marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
407
+
408
+ assert File.directory?(quickdir), 'quickdir should be directory'
409
+ assert File.directory?(marshal_quickdir)
410
+
411
+ refute_indexed quickdir, "index"
412
+ refute_indexed quickdir, "index.rz"
413
+
414
+ refute_indexed quickdir, "latest_index"
415
+ refute_indexed quickdir, "latest_index.rz"
416
+
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"
421
+
422
+ 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}"
430
+
431
+ assert_indexed @tempdir, "specs.#{@marshal_version}"
432
+ assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
433
+
434
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
435
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
436
+ end
437
+
438
+ def test_generate_index_modern_back_to_back
439
+ @indexer.build_modern = true
440
+ @indexer.build_legacy = true
441
+
442
+ use_ui @ui do
443
+ @indexer.generate_index
444
+ end
445
+
446
+ @indexer = Gem::Indexer.new @tempdir
447
+ @indexer.build_modern = true
448
+ @indexer.build_legacy = false
449
+
450
+ use_ui @ui do
451
+ @indexer.generate_index
452
+ end
453
+
454
+ assert_indexed @tempdir, 'yaml'
455
+ assert_indexed @tempdir, 'yaml.Z'
456
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}"
457
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
458
+
459
+ quickdir = File.join @tempdir, 'quick'
460
+ marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
461
+
462
+ assert File.directory?(quickdir)
463
+ assert File.directory?(marshal_quickdir)
464
+
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"
480
+
481
+ assert_indexed @tempdir, "specs.#{@marshal_version}"
482
+ assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
483
+
484
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
485
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
486
+ end
487
+
488
+ def test_generate_index_ui
489
+ use_ui @ui do
490
+ @indexer.generate_index
491
+ end
492
+
493
+ assert_match %r%^Loading 10 gems from #{Regexp.escape @tempdir}$%,
494
+ @ui.output
495
+ assert_match %r%^\.\.\.\.\.\.\.\.\.\.$%, @ui.output
496
+ assert_match %r%^Loaded all gems$%, @ui.output
497
+ assert_match %r%^Generating Marshal quick index gemspecs for 10 gems$%,
498
+ @ui.output
499
+ assert_match %r%^Generating YAML quick index gemspecs for 10 gems$%,
500
+ @ui.output
501
+ assert_match %r%^Complete$%, @ui.output
502
+ assert_match %r%^Generating specs index$%, @ui.output
503
+ 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
+ assert_match %r%^Generating prerelease specs index$%, @ui.output
507
+ 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
+ assert_match %r%^Complete$%, @ui.output
510
+ assert_match %r%^Compressing indicies$%, @ui.output
511
+
512
+ assert_equal '', @ui.error
513
+ end
514
+
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
+ def test_generate_index_specs
535
+ use_ui @ui do
536
+ @indexer.generate_index
537
+ end
538
+
539
+ specs_path = File.join @tempdir, "specs.#{@marshal_version}"
540
+
541
+ specs_dump = Gem.read_binary specs_path
542
+ specs = Marshal.load specs_dump
543
+
544
+ expected = [
545
+ ['a', Gem::Version.new(1), 'ruby'],
546
+ ['a', Gem::Version.new(2), 'ruby'],
547
+ ['a_evil', Gem::Version.new(9), 'ruby'],
548
+ ['b', Gem::Version.new(2), 'ruby'],
549
+ ['c', Gem::Version.new('1.2'), 'ruby'],
550
+ ['d', Gem::Version.new('2.0'), 'ruby'],
551
+ ['pl', Gem::Version.new(1), 'i386-linux'],
552
+ ]
553
+
554
+ assert_equal expected, specs
555
+
556
+ assert_same specs[0].first, specs[1].first,
557
+ 'identical names not identical'
558
+
559
+ assert_same specs[0][1], specs[-1][1],
560
+ 'identical versions not identical'
561
+
562
+ assert_same specs[0].last, specs[1].last,
563
+ 'identical platforms not identical'
564
+
565
+ refute_same specs[1][1], specs[5][1],
566
+ 'different versions not different'
567
+ end
568
+
569
+ def test_generate_index_latest_specs
570
+ use_ui @ui do
571
+ @indexer.generate_index
572
+ end
573
+
574
+ latest_specs_path = File.join @tempdir, "latest_specs.#{@marshal_version}"
575
+
576
+ latest_specs_dump = Gem.read_binary latest_specs_path
577
+ latest_specs = Marshal.load latest_specs_dump
578
+
579
+ expected = [
580
+ ['a', Gem::Version.new(2), 'ruby'],
581
+ ['a_evil', Gem::Version.new(9), 'ruby'],
582
+ ['b', Gem::Version.new(2), 'ruby'],
583
+ ['c', Gem::Version.new('1.2'), 'ruby'],
584
+ ['d', Gem::Version.new('2.0'), 'ruby'],
585
+ ['pl', Gem::Version.new(1), 'i386-linux'],
586
+ ]
587
+
588
+ assert_equal expected, latest_specs
589
+
590
+ assert_same latest_specs[0][1], latest_specs[2][1],
591
+ 'identical versions not identical'
592
+
593
+ assert_same latest_specs[0].last, latest_specs[1].last,
594
+ 'identical platforms not identical'
595
+ end
596
+
597
+ def test_generate_index_prerelease_specs
598
+ use_ui @ui do
599
+ @indexer.generate_index
600
+ end
601
+
602
+ prerelease_specs_path = File.join @tempdir, "prerelease_specs.#{@marshal_version}"
603
+
604
+ prerelease_specs_dump = Gem.read_binary prerelease_specs_path
605
+ prerelease_specs = Marshal.load prerelease_specs_dump
606
+
607
+ assert_equal [['a', Gem::Version.new('3.a'), 'ruby'],
608
+ ['d', Gem::Version.new('2.0.a'), 'ruby'],
609
+ ['d', Gem::Version.new('2.0.b'), 'ruby']],
610
+ prerelease_specs
611
+ end
612
+
613
+ def test_update_index
614
+ use_ui @ui do
615
+ @indexer.generate_index
616
+ end
617
+
618
+ quickdir = File.join @tempdir, 'quick'
619
+ marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
620
+
621
+ assert File.directory?(quickdir)
622
+ assert File.directory?(marshal_quickdir)
623
+
624
+ @d2_1 = quick_gem 'd', '2.1'
625
+ util_build_gem @d2_1
626
+ @d2_1_tuple = [@d2_1.name, @d2_1.version, @d2_1.original_platform]
627
+
628
+ @d2_1_a = quick_gem 'd', '2.2.a'
629
+ util_build_gem @d2_1_a
630
+ @d2_1_a_tuple = [@d2_1_a.name, @d2_1_a.version, @d2_1_a.original_platform]
631
+
632
+ 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
635
+
636
+ use_ui @ui do
637
+ @indexer.update_index
638
+ end
639
+
640
+ assert_indexed marshal_quickdir, "#{@d2_1.spec_name}.rz"
641
+
642
+ specs_index = Marshal.load Gem.read_binary(@indexer.dest_specs_index)
643
+
644
+ assert_includes specs_index, @d2_1_tuple
645
+ refute_includes specs_index, @d2_1_a_tuple
646
+
647
+ latest_specs_index = Marshal.load \
648
+ Gem.read_binary(@indexer.dest_latest_specs_index)
649
+
650
+ assert_includes latest_specs_index, @d2_1_tuple
651
+ assert_includes latest_specs_index,
652
+ [@d2_0.name, @d2_0.version, @d2_0.original_platform]
653
+ refute_includes latest_specs_index, @d2_1_a_tuple
654
+
655
+ pre_specs_index = Marshal.load \
656
+ Gem.read_binary(@indexer.dest_prerelease_specs_index)
657
+
658
+ assert_includes pre_specs_index, @d2_1_a_tuple
659
+ refute_includes pre_specs_index, @d2_1_tuple
660
+ end
661
+
662
+ def assert_indexed(dir, name)
663
+ file = File.join dir, name
664
+ assert File.exist?(file), "#{file} does not exist"
665
+ end
666
+
667
+ def refute_indexed(dir, name)
668
+ file = File.join dir, name
669
+ refute File.exist?(file), "#{file} exists"
670
+ end
671
+
672
+ end if defined?(Builder::XChar)
673
+