rubygems-update 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (225) hide show
  1. data/ChangeLog +587 -0
  2. data/README +0 -1
  3. data/Rakefile +39 -12
  4. data/TODO +0 -5
  5. data/bin/gem +7 -7
  6. data/bin/update_rubygems +1 -1
  7. data/examples/application/an-app.gemspec +1 -1
  8. data/gemspecs/cgikit-1.1.0.gemspec +1 -2
  9. data/gemspecs/jabber4r.gemspec +1 -1
  10. data/gemspecs/linguistics.gemspec +1 -1
  11. data/gemspecs/ook.gemspec +1 -1
  12. data/gemspecs/progressbar.gemspec +1 -1
  13. data/gemspecs/redcloth.gemspec +1 -1
  14. data/gemspecs/rublog.gemspec +1 -1
  15. data/gemspecs/ruby-doom.gemspec +1 -1
  16. data/gemspecs/rubyjdwp.gemspec +1 -1
  17. data/gemspecs/statistics.gemspec +1 -1
  18. data/lib/rubygems.rb +167 -105
  19. data/lib/rubygems/builder.rb +12 -10
  20. data/lib/rubygems/command.rb +177 -60
  21. data/lib/rubygems/command_manager.rb +30 -38
  22. data/lib/rubygems/commands/build_command.rb +42 -46
  23. data/lib/rubygems/commands/cert_command.rb +72 -69
  24. data/lib/rubygems/commands/check_command.rb +63 -63
  25. data/lib/rubygems/commands/cleanup_command.rb +25 -7
  26. data/lib/rubygems/commands/contents_command.rb +70 -62
  27. data/lib/rubygems/commands/dependency_command.rb +131 -86
  28. data/lib/rubygems/commands/environment_command.rb +67 -46
  29. data/lib/rubygems/commands/fetch_command.rb +62 -0
  30. data/lib/rubygems/commands/generate_index_command.rb +57 -0
  31. data/lib/rubygems/commands/help_command.rb +163 -73
  32. data/lib/rubygems/commands/install_command.rb +114 -128
  33. data/lib/rubygems/commands/list_command.rb +10 -8
  34. data/lib/rubygems/commands/lock_command.rb +101 -0
  35. data/lib/rubygems/commands/mirror_command.rb +105 -0
  36. data/lib/rubygems/commands/outdated_command.rb +24 -15
  37. data/lib/rubygems/commands/pristine_command.rb +118 -88
  38. data/lib/rubygems/commands/query_command.rb +109 -77
  39. data/lib/rubygems/commands/rdoc_command.rb +13 -10
  40. data/lib/rubygems/commands/search_command.rb +10 -8
  41. data/lib/rubygems/commands/server_command.rb +48 -0
  42. data/lib/rubygems/commands/sources_command.rb +104 -83
  43. data/lib/rubygems/commands/specification_command.rb +65 -51
  44. data/lib/rubygems/commands/uninstall_command.rb +17 -12
  45. data/lib/rubygems/commands/unpack_command.rb +68 -68
  46. data/lib/rubygems/commands/update_command.rb +72 -25
  47. data/lib/rubygems/commands/which_command.rb +86 -0
  48. data/lib/rubygems/config_file.rb +202 -78
  49. data/lib/rubygems/custom_require.rb +7 -88
  50. data/lib/rubygems/dependency.rb +65 -0
  51. data/lib/rubygems/dependency_installer.rb +232 -0
  52. data/lib/rubygems/dependency_list.rb +133 -105
  53. data/lib/rubygems/digest/md5.rb +4 -1
  54. data/lib/rubygems/digest/sha2.rb +1 -1
  55. data/lib/rubygems/doc_manager.rb +41 -19
  56. data/lib/rubygems/exceptions.rb +63 -0
  57. data/lib/rubygems/ext.rb +18 -0
  58. data/lib/rubygems/ext/builder.rb +56 -0
  59. data/lib/rubygems/ext/configure_builder.rb +24 -0
  60. data/lib/rubygems/ext/ext_conf_builder.rb +23 -0
  61. data/lib/rubygems/ext/rake_builder.rb +27 -0
  62. data/lib/rubygems/format.rb +16 -6
  63. data/lib/rubygems/gem_openssl.rb +43 -6
  64. data/lib/rubygems/gem_path_searcher.rb +84 -0
  65. data/lib/rubygems/gem_runner.rb +20 -5
  66. data/lib/rubygems/indexer.rb +163 -0
  67. data/lib/rubygems/indexer/abstract_index_builder.rb +80 -0
  68. data/lib/rubygems/indexer/marshal_index_builder.rb +17 -0
  69. data/lib/rubygems/indexer/master_index_builder.rb +53 -0
  70. data/lib/rubygems/indexer/quick_index_builder.rb +48 -0
  71. data/lib/rubygems/install_update_options.rb +87 -0
  72. data/lib/rubygems/installer.rb +316 -562
  73. data/lib/rubygems/local_remote_options.rb +106 -0
  74. data/lib/rubygems/old_format.rb +5 -13
  75. data/lib/rubygems/open-uri.rb +2 -0
  76. data/lib/rubygems/package.rb +28 -32
  77. data/lib/rubygems/platform.rb +187 -0
  78. data/lib/rubygems/remote_fetcher.rb +46 -29
  79. data/lib/rubygems/remote_installer.rb +11 -18
  80. data/lib/rubygems/requirement.rb +157 -0
  81. data/lib/rubygems/rubygems_version.rb +1 -1
  82. data/lib/rubygems/security.rb +715 -457
  83. data/lib/rubygems/server.rb +77 -59
  84. data/lib/rubygems/source_index.rb +154 -83
  85. data/lib/rubygems/source_info_cache.rb +73 -30
  86. data/lib/rubygems/source_info_cache_entry.rb +12 -3
  87. data/lib/rubygems/specification.rb +378 -145
  88. data/lib/rubygems/uninstaller.rb +183 -0
  89. data/lib/rubygems/user_interaction.rb +38 -9
  90. data/lib/rubygems/validator.rb +53 -24
  91. data/lib/rubygems/version.rb +126 -289
  92. data/lib/rubygems/version_option.rb +49 -0
  93. data/pkgs/sources/lib/sources.rb +1 -4
  94. data/pkgs/sources/sources.gemspec +3 -3
  95. data/scripts/gemdoc.rb +0 -1
  96. data/setup.rb +166 -1505
  97. data/test/bogussources.rb +0 -1
  98. data/test/data/gem-private_key.pem +27 -0
  99. data/test/data/gem-public_cert.pem +20 -0
  100. data/test/functional.rb +3 -105
  101. data/test/gemutilities.rb +145 -24
  102. data/test/insure_session.rb +0 -1
  103. data/test/{test_datadir.rb → test_config.rb} +7 -13
  104. data/test/test_gem.rb +360 -9
  105. data/test/test_gem_builder.rb +34 -0
  106. data/test/{test_command.rb → test_gem_command.rb} +119 -62
  107. data/test/{test_parse_commands.rb → test_gem_command_manager.rb} +64 -40
  108. data/test/test_gem_commands_build_command.rb +75 -0
  109. data/test/test_gem_commands_cert_command.rb +122 -0
  110. data/test/test_gem_commands_check_command.rb +25 -0
  111. data/test/test_gem_commands_contents_command.rb +92 -0
  112. data/test/test_gem_commands_dependency_command.rb +108 -0
  113. data/test/test_gem_commands_environment_command.rb +117 -0
  114. data/test/test_gem_commands_fetch_command.rb +34 -0
  115. data/test/test_gem_commands_generate_index_command.rb +32 -0
  116. data/test/test_gem_commands_install_command.rb +160 -0
  117. data/test/test_gem_commands_mirror_command.rb +56 -0
  118. data/test/test_gem_commands_pristine_command.rb +100 -0
  119. data/test/test_gem_commands_query_command.rb +82 -0
  120. data/test/test_gem_commands_sources_command.rb +147 -0
  121. data/test/test_gem_commands_specification_command.rb +93 -0
  122. data/test/test_gem_commands_unpack_command.rb +55 -0
  123. data/test/test_gem_config_file.rb +210 -0
  124. data/test/test_gem_dependency.rb +89 -0
  125. data/test/test_gem_dependency_installer.rb +542 -0
  126. data/test/test_gem_dependency_list.rb +212 -0
  127. data/test/test_gem_doc_manager.rb +32 -0
  128. data/test/test_gem_ext_configure_builder.rb +13 -17
  129. data/test/test_gem_ext_ext_conf_builder.rb +9 -9
  130. data/test/test_gem_ext_rake_builder.rb +23 -11
  131. data/test/test_gem_format.rb +69 -0
  132. data/test/test_gem_gem_path_searcher.rb +57 -0
  133. data/test/test_gem_gem_runner.rb +35 -0
  134. data/test/test_gem_indexer.rb +119 -0
  135. data/test/test_gem_install_update_options.rb +40 -0
  136. data/test/test_gem_installer.rb +796 -0
  137. data/test/test_gem_local_remote_options.rb +84 -0
  138. data/test/test_gem_outdated_command.rb +11 -9
  139. data/test/test_gem_platform.rb +240 -0
  140. data/test/{test_remote_fetcher.rb → test_gem_remote_fetcher.rb} +124 -55
  141. data/test/{test_remote_installer.rb → test_gem_remote_installer.rb} +3 -4
  142. data/test/test_gem_requirement.rb +223 -0
  143. data/test/test_gem_server.rb +71 -0
  144. data/test/test_gem_source_index.rb +429 -0
  145. data/test/test_gem_source_info_cache.rb +79 -17
  146. data/test/test_gem_source_info_cache_entry.rb +11 -9
  147. data/test/test_gem_specification.rb +738 -0
  148. data/test/test_gem_stream_ui.rb +117 -0
  149. data/test/test_gem_validator.rb +70 -0
  150. data/test/test_gem_version.rb +191 -0
  151. data/test/test_gem_version_option.rb +77 -0
  152. data/test/{test_require_gem.rb → test_kernel.rb} +19 -12
  153. data/test/test_open_uri.rb +1 -2
  154. data/test/test_package.rb +45 -34
  155. metadata +116 -141
  156. data/Releases +0 -127
  157. data/bin/gem_mirror +0 -73
  158. data/bin/gem_server +0 -6
  159. data/bin/gemlock +0 -127
  160. data/bin/gemri +0 -24
  161. data/bin/gemwhich +0 -89
  162. data/bin/index_gem_repository.rb +0 -302
  163. data/lib/gemconfigure.rb +0 -24
  164. data/lib/rubygems/gem_commands.rb +0 -273
  165. data/pkgs/sources/sources-0.0.1.gem +0 -0
  166. data/post-install.rb +0 -121
  167. data/test/brokenbuildgem.rb +0 -35
  168. data/test/data/PostMessage-0.0.1.gem +0 -0
  169. data/test/data/a-0.0.1.gem +0 -0
  170. data/test/data/a-0.0.2.gem +0 -0
  171. data/test/data/b-0.0.2.gem +0 -0
  172. data/test/data/broken-1.0.0.gem +0 -0
  173. data/test/data/broken_build/broken-build.gemspec +0 -20
  174. data/test/data/broken_build/ext/extconf.rb +0 -3
  175. data/test/data/broken_build/ext/foo.c +0 -1
  176. data/test/data/c-1.2.gem +0 -0
  177. data/test/data/gemhome/cache/a-0.0.1.gem +0 -0
  178. data/test/data/gemhome/cache/a-0.0.2.gem +0 -0
  179. data/test/data/gemhome/cache/b-0.0.2.gem +0 -0
  180. data/test/data/gemhome/cache/c-1.2.gem +0 -0
  181. data/test/data/gemhome/gems/a-0.0.1/lib/code.rb +0 -1
  182. data/test/data/gemhome/gems/a-0.0.2/lib/code.rb +0 -1
  183. data/test/data/gemhome/gems/b-0.0.2/lib/code.rb +0 -1
  184. data/test/data/gemhome/gems/c-1.2/lib/code.rb +0 -1
  185. data/test/data/gemhome/specifications/a-0.0.1.gemspec +0 -8
  186. data/test/data/gemhome/specifications/a-0.0.2.gemspec +0 -8
  187. data/test/data/gemhome/specifications/b-0.0.2.gemspec +0 -8
  188. data/test/data/gemhome/specifications/c-1.2.gemspec +0 -8
  189. data/test/data/legacy/keyedlist-0.4.0.ruby +0 -11
  190. data/test/data/legacy/keyedlist-0.4.0.yaml +0 -16
  191. data/test/data/lib/code.rb +0 -1
  192. data/test/data/one/README.one +0 -1
  193. data/test/data/one/lib/one.rb +0 -9
  194. data/test/data/one/one-0.0.1.gem +0 -0
  195. data/test/data/one/one.gemspec +0 -17
  196. data/test/data/one/one.yaml +0 -40
  197. data/test/data/post_install.gemspec +0 -19
  198. data/test/functional_extension_gems.rb +0 -48
  199. data/test/functional_generate_yaml_index.rb +0 -104
  200. data/test/gemenvironment.rb +0 -59
  201. data/test/io_capture.rb +0 -33
  202. data/test/mock/gems/gems/sources-0.0.1/lib/sources.rb +0 -11
  203. data/test/mock/gems/specifications/sources-0.0.1.gemspec +0 -8
  204. data/test/onegem.rb +0 -35
  205. data/test/test_builder.rb +0 -34
  206. data/test/test_check_command.rb +0 -34
  207. data/test/test_configfile.rb +0 -42
  208. data/test/test_dependency_list.rb +0 -169
  209. data/test/test_file_list.rb +0 -101
  210. data/test/test_format.rb +0 -49
  211. data/test/test_gem_sources_command.rb +0 -135
  212. data/test/test_gemloadpaths.rb +0 -51
  213. data/test/test_gempaths.rb +0 -170
  214. data/test/test_installer.rb +0 -369
  215. data/test/test_loadmanager.rb +0 -48
  216. data/test/test_process_commands.rb +0 -52
  217. data/test/test_source_index.rb +0 -231
  218. data/test/test_specific_extras.rb +0 -46
  219. data/test/test_specification.rb +0 -565
  220. data/test/test_user_interaction.rb +0 -48
  221. data/test/test_validator.rb +0 -59
  222. data/test/test_version_comparison.rb +0 -321
  223. data/test/testgem.rc +0 -7
  224. data/test/user_capture.rb +0 -7
  225. data/test/yaml_data.rb +0 -63
@@ -5,7 +5,7 @@
5
5
  #++
6
6
 
7
7
  require 'test/unit'
8
- require 'test/gemutilities'
8
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
9
9
  require 'rubygems/remote_installer'
10
10
 
11
11
  class MockFetcher
@@ -50,7 +50,7 @@ class MockFetcher
50
50
  end
51
51
  end
52
52
 
53
- class TestRemoteInstaller < RubyGemTestCase
53
+ class TestGemRemoteInstaller < RubyGemTestCase
54
54
 
55
55
  def setup
56
56
  super
@@ -103,7 +103,7 @@ end
103
103
  # This test suite has a number of TODOs in the test cases. The
104
104
  # TestRemoteInstaller test suite is a reworking of this class from
105
105
  # scratch.
106
- class RemoteInstallerTest #< Test::Unit::TestCase # HACK disabled
106
+ class RemoteInstallerTest #< RubyGemTestCase # HACK disabled
107
107
  class RInst < Gem::RemoteInstaller
108
108
  include Test::Unit::Assertions
109
109
 
@@ -153,7 +153,6 @@ class RemoteInstallerTest #< Test::Unit::TestCase # HACK disabled
153
153
  CACHE_DIR = File.join(Gem.dir, 'cache')
154
154
 
155
155
  def test_install
156
- Gem.use_paths("test/data/gemhome")
157
156
  result = @remote_installer.install('foo')
158
157
  assert_equal [nil], result
159
158
  end
@@ -0,0 +1,223 @@
1
+ #--
2
+ # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+ require 'test/unit'
8
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
9
+ require 'rubygems/version'
10
+
11
+ class TestGemRequirement < RubyGemTestCase
12
+
13
+ def setup
14
+ super
15
+
16
+ @r1_2 = Gem::Requirement.new '= 1.2'
17
+ @r1_3 = Gem::Requirement.new '= 1.3'
18
+ end
19
+
20
+ def test_initialize
21
+ r = Gem::Requirement.new '2'
22
+ assert_equal '= 2', r.to_s, 'String'
23
+
24
+ r = Gem::Requirement.new %w[2]
25
+ assert_equal '= 2', r.to_s, 'Array of Strings'
26
+
27
+ r = Gem::Requirement.new Gem::Version.new('2')
28
+ assert_equal '= 2', r.to_s, 'Gem::Version'
29
+ end
30
+
31
+ def test_equals2
32
+ assert_equal @r1_2, @r1_2.dup
33
+ assert_equal @r1_2.dup, @r1_2
34
+
35
+ assert_not_equal @r1_3, @r1_2
36
+ assert_not_equal @r1_2, @r1_3
37
+
38
+ assert_not_equal Object.new, @r1_2
39
+ assert_not_equal @r1_2, Object.new
40
+ end
41
+
42
+ def test_hash
43
+ assert_equal @r1_2.hash, @r1_2.dup.hash
44
+ assert_equal @r1_2.dup.hash, @r1_2.hash
45
+
46
+ assert_not_equal @r1_2.hash, @r1_3.hash
47
+ assert_not_equal @r1_3.hash, @r1_2.hash
48
+ end
49
+
50
+ # We may get some old gems that have requirements in old formats.
51
+ # We need to be able to handle those old requirements by normalizing
52
+ # them to the latest format.
53
+ def test_normalization
54
+ require 'yaml'
55
+ yamldep = %{--- !ruby/object:Gem::Requirement
56
+ nums:
57
+ - 1
58
+ - 0
59
+ - 4
60
+ op: ">="
61
+ version: ">= 1.0.4"}
62
+ dep = YAML.load(yamldep)
63
+ dep.normalize
64
+ assert_equal ">= 1.0.4", dep.to_s
65
+ end
66
+
67
+ def test_parse
68
+ assert_equal ['=', Gem::Version.new(1)], @r1_2.parse(' 1')
69
+
70
+ assert_equal ['=', Gem::Version.new(1)], @r1_2.parse('= 1')
71
+ assert_equal ['>', Gem::Version.new(1)], @r1_2.parse('> 1')
72
+
73
+ assert_equal ['=', Gem::Version.new(0)], @r1_2.parse('=')
74
+ assert_equal ['>', Gem::Version.new(0)], @r1_2.parse('>')
75
+
76
+ assert_equal ['=', Gem::Version.new(1)], @r1_2.parse("=\n1")
77
+ assert_equal ['=', Gem::Version.new(0)], @r1_2.parse("=\njunk")
78
+
79
+ assert_equal ['=', Gem::Version.new(2)], @r1_2.parse(Gem::Version.new('2'))
80
+ end
81
+
82
+ def test_parse_illformed
83
+ e = assert_raise ArgumentError do
84
+ @r1_2.parse(nil)
85
+ end
86
+
87
+ assert_equal 'Illformed requirement [nil]', e.message
88
+
89
+ e = assert_raise ArgumentError do
90
+ @r1_2.parse('')
91
+ end
92
+
93
+ assert_equal 'Illformed requirement [""]', e.message
94
+ end
95
+
96
+ def test_satisfied_by_eh_bang_equal
97
+ r1_2 = Gem::Requirement.new '!= 1.2'
98
+ v1_1 = Gem::Version.new '1.1'
99
+ v1_2 = Gem::Version.new '1.2'
100
+ v1_3 = Gem::Version.new '1.3'
101
+
102
+ assert_equal true, r1_2.satisfied_by?(nil)
103
+ assert_equal true, r1_2.satisfied_by?(v1_1)
104
+ assert_equal false, r1_2.satisfied_by?(v1_2)
105
+ assert_equal true, r1_2.satisfied_by?(v1_3)
106
+ end
107
+
108
+ def test_satisfied_by_eh_blank
109
+ r1_2 = Gem::Requirement.new '1.2'
110
+ v1_1 = Gem::Version.new '1.1'
111
+ v1_2 = Gem::Version.new '1.2'
112
+ v1_3 = Gem::Version.new '1.3'
113
+
114
+ assert_equal false, r1_2.satisfied_by?(nil)
115
+ assert_equal false, r1_2.satisfied_by?(v1_1)
116
+ assert_equal true, r1_2.satisfied_by?(v1_2)
117
+ assert_equal false, r1_2.satisfied_by?(v1_3)
118
+ end
119
+
120
+ def test_satisfied_by_eh_equal
121
+ r1_2 = @r1_2
122
+ v1_1 = Gem::Version.new '1.1'
123
+ v1_2 = Gem::Version.new '1.2'
124
+ v1_3 = Gem::Version.new '1.3'
125
+
126
+ assert_equal false, r1_2.satisfied_by?(nil)
127
+ assert_equal false, r1_2.satisfied_by?(v1_1)
128
+ assert_equal true, r1_2.satisfied_by?(v1_2)
129
+ assert_equal false, r1_2.satisfied_by?(v1_3)
130
+ end
131
+
132
+ def test_satisfied_by_eh_gt
133
+ r1_2 = Gem::Requirement.new '> 1.2'
134
+ v1_1 = Gem::Version.new '1.1'
135
+ v1_2 = Gem::Version.new '1.2'
136
+ v1_3 = Gem::Version.new '1.3'
137
+
138
+ assert_equal false, r1_2.satisfied_by?(v1_1)
139
+ assert_equal false, r1_2.satisfied_by?(v1_2)
140
+ assert_equal true, r1_2.satisfied_by?(v1_3)
141
+
142
+ assert_raise NoMethodError do
143
+ assert_equal true, r1_2.satisfied_by?(nil)
144
+ end
145
+ end
146
+
147
+ def test_satisfied_by_eh_gte
148
+ r1_2 = Gem::Requirement.new '>= 1.2'
149
+ v1_1 = Gem::Version.new '1.1'
150
+ v1_2 = Gem::Version.new '1.2'
151
+ v1_3 = Gem::Version.new '1.3'
152
+
153
+ assert_equal false, r1_2.satisfied_by?(v1_1)
154
+ assert_equal true, r1_2.satisfied_by?(v1_2)
155
+ assert_equal true, r1_2.satisfied_by?(v1_3)
156
+
157
+ assert_raise NoMethodError do
158
+ assert_equal true, r1_2.satisfied_by?(nil)
159
+ end
160
+ end
161
+
162
+ def test_satisfied_by_eh_list
163
+ r = Gem::Requirement.create(['> 1.1', '< 1.3'])
164
+ v1_1 = Gem::Version.new '1.1'
165
+ v1_2 = Gem::Version.new '1.2'
166
+ v1_3 = Gem::Version.new '1.3'
167
+
168
+ assert_equal false, r.satisfied_by?(v1_1)
169
+ assert_equal true, r.satisfied_by?(v1_2)
170
+ assert_equal false, r.satisfied_by?(v1_3)
171
+
172
+ assert_raise NoMethodError do
173
+ assert_equal true, r.satisfied_by?(nil)
174
+ end
175
+ end
176
+
177
+ def test_satisfied_by_eh_lt
178
+ r1_2 = Gem::Requirement.new '< 1.2'
179
+ v1_1 = Gem::Version.new '1.1'
180
+ v1_2 = Gem::Version.new '1.2'
181
+ v1_3 = Gem::Version.new '1.3'
182
+
183
+ assert_equal true, r1_2.satisfied_by?(v1_1)
184
+ assert_equal false, r1_2.satisfied_by?(v1_2)
185
+ assert_equal false, r1_2.satisfied_by?(v1_3)
186
+
187
+ assert_raise NoMethodError do
188
+ assert_equal true, r1_2.satisfied_by?(nil)
189
+ end
190
+ end
191
+
192
+ def test_satisfied_by_eh_lte
193
+ r1_2 = Gem::Requirement.new '<= 1.2'
194
+ v1_1 = Gem::Version.new '1.1'
195
+ v1_2 = Gem::Version.new '1.2'
196
+ v1_3 = Gem::Version.new '1.3'
197
+
198
+ assert_equal true, r1_2.satisfied_by?(v1_1)
199
+ assert_equal true, r1_2.satisfied_by?(v1_2)
200
+ assert_equal false, r1_2.satisfied_by?(v1_3)
201
+
202
+ assert_raise NoMethodError do
203
+ assert_equal true, r1_2.satisfied_by?(nil)
204
+ end
205
+ end
206
+
207
+ def test_satisfied_by_eh_tilde_gt
208
+ r1_2 = Gem::Requirement.new '~> 1.2'
209
+ v1_1 = Gem::Version.new '1.1'
210
+ v1_2 = Gem::Version.new '1.2'
211
+ v1_3 = Gem::Version.new '1.3'
212
+
213
+ assert_equal false, r1_2.satisfied_by?(v1_1)
214
+ assert_equal true, r1_2.satisfied_by?(v1_2)
215
+ assert_equal true, r1_2.satisfied_by?(v1_3)
216
+
217
+ assert_raise NoMethodError do
218
+ assert_equal true, r1_2.satisfied_by?(nil)
219
+ end
220
+ end
221
+
222
+ end
223
+
@@ -0,0 +1,71 @@
1
+ require 'test/unit'
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3
+ require 'rubygems/server'
4
+ require 'stringio'
5
+
6
+ class Gem::Server
7
+ attr_reader :server
8
+ end
9
+
10
+ class TestGemServer < RubyGemTestCase
11
+
12
+ def setup
13
+ super
14
+
15
+ @a1 = quick_gem 'a', '1'
16
+
17
+ @server = Gem::Server.new Gem.dir, 8809, false
18
+ @req = WEBrick::HTTPRequest.new :Logger => nil
19
+ @res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'
20
+ end
21
+
22
+ def test_quick_index
23
+ data = StringIO.new "GET /quick/index HTTP/1.0\r\n\r\n"
24
+ @req.parse data
25
+
26
+ @server.quick @req, @res
27
+
28
+ assert_match %r| \d\d:\d\d:\d\d |, @res['date']
29
+ assert_equal 'text/plain', @res['content-type']
30
+ assert_equal "a-1", @res.body
31
+ end
32
+
33
+ def test_quick_index_rz
34
+ data = StringIO.new "GET /quick/index.rz HTTP/1.0\r\n\r\n"
35
+ @req.parse data
36
+
37
+ @server.quick @req, @res
38
+
39
+ assert_match %r| \d\d:\d\d:\d\d |, @res['date']
40
+ assert_equal 'text/plain', @res['content-type']
41
+ assert_equal "a-1", Zlib::Inflate.inflate(@res.body)
42
+ end
43
+
44
+ def test_quick_a_1_gemspec_rz
45
+ data = StringIO.new "GET /quick/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
46
+ @req.parse data
47
+
48
+ @server.quick @req, @res
49
+
50
+ assert @res['date']
51
+ assert_equal 'text/plain', @res['content-type']
52
+ yaml = Zlib::Inflate.inflate(@res.body)
53
+ assert_match %r|Gem::Specification|, yaml
54
+ assert_match %r|name: a|, yaml
55
+ assert_match %r|version: "1"|, yaml
56
+ end
57
+
58
+ def test_quick_z_9_gemspec_rz
59
+ data = StringIO.new "GET /quick/z-9.gemspec.rz HTTP/1.0\r\n\r\n"
60
+ @req.parse data
61
+
62
+ @server.quick @req, @res
63
+
64
+ assert_match %r| \d\d:\d\d:\d\d |, @res['date']
65
+ assert_equal 'text/plain', @res['content-type']
66
+ assert_equal '', @res.body
67
+ assert_equal 404, @res.status
68
+ end
69
+
70
+ end
71
+
@@ -0,0 +1,429 @@
1
+ #--
2
+ # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+ require 'test/unit'
8
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
9
+ require 'rubygems/source_index'
10
+ require 'rubygems/config_file'
11
+
12
+ class Gem::SourceIndex
13
+ public :fetcher, :fetch_bulk_index, :fetch_quick_index,
14
+ :find_missing, :gems, :remove_extra,
15
+ :update_with_missing, :unzip
16
+ end
17
+
18
+ class TestGemSourceIndex < RubyGemTestCase
19
+
20
+ def setup
21
+ super
22
+
23
+ util_setup_fake_fetcher
24
+ end
25
+
26
+ def test_create_from_directory
27
+ # TODO
28
+ end
29
+
30
+ def test_fetcher
31
+ assert_equal @fetcher, @source_index.fetcher
32
+ end
33
+
34
+ def test_fetch_bulk_index_compressed
35
+ util_setup_bulk_fetch true
36
+
37
+ use_ui @ui do
38
+ fetched_index = @source_index.fetch_bulk_index @uri
39
+ assert_equal [@gem1.full_name, @gem4.full_name, @gem2.full_name].sort,
40
+ fetched_index.gems.map { |n,s| n }.sort
41
+ end
42
+
43
+ paths = @fetcher.paths
44
+
45
+ assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}.Z", paths.shift
46
+
47
+ assert paths.empty?, paths.join(', ')
48
+ end
49
+
50
+ def test_fetch_bulk_index_error
51
+ @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}.Z"] = proc { raise SocketError }
52
+ @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = proc { raise SocketError }
53
+ @fetcher.data["#{@gem_repo}/yaml.Z"] = proc { raise SocketError }
54
+ @fetcher.data["#{@gem_repo}/yaml"] = proc { raise SocketError }
55
+
56
+ e = assert_raise Gem::RemoteSourceException do
57
+ use_ui @ui do
58
+ @source_index.fetch_bulk_index @uri
59
+ end
60
+ end
61
+
62
+ paths = @fetcher.paths
63
+
64
+ assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}.Z", paths.shift
65
+ assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}", paths.shift
66
+ assert_equal "#{@gem_repo}/yaml.Z", paths.shift
67
+ assert_equal "#{@gem_repo}/yaml", paths.shift
68
+
69
+ assert paths.empty?, paths.join(', ')
70
+
71
+ assert_equal 'Error fetching remote gem cache: SocketError',
72
+ e.message
73
+ end
74
+
75
+ def test_fetch_bulk_index_fallback
76
+ @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}.Z"] =
77
+ proc { raise SocketError }
78
+ @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] =
79
+ proc { raise SocketError }
80
+ @fetcher.data["#{@gem_repo}/yaml.Z"] = proc { raise SocketError }
81
+ @fetcher.data["#{@gem_repo}/yaml"] = @source_index.to_yaml
82
+
83
+ use_ui @ui do
84
+ fetched_index = @source_index.fetch_bulk_index @uri
85
+ assert_equal [@gem1.full_name, @gem4.full_name, @gem2.full_name].sort,
86
+ fetched_index.gems.map { |n,s| n }.sort
87
+ end
88
+
89
+ paths = @fetcher.paths
90
+
91
+ assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}.Z", paths.shift
92
+ assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}", paths.shift
93
+ assert_equal "#{@gem_repo}/yaml.Z", paths.shift
94
+ assert_equal "#{@gem_repo}/yaml", paths.shift
95
+
96
+ assert paths.empty?, paths.join(', ')
97
+ end
98
+
99
+ def test_fetch_bulk_index_marshal_mismatch
100
+ marshal = @source_index.dump
101
+ marshal[0] = (Marshal::MAJOR_VERSION - 1).chr
102
+
103
+ @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = marshal
104
+ @fetcher.data["#{@gem_repo}/yaml"] = @source_index.to_yaml
105
+
106
+ use_ui @ui do
107
+ fetched_index = @source_index.fetch_bulk_index @uri
108
+ assert_equal [@gem1.full_name, @gem4.full_name, @gem2.full_name].sort,
109
+ fetched_index.gems.map { |n,s| n }.sort
110
+ end
111
+
112
+ paths = @fetcher.paths
113
+
114
+ assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}.Z", paths.shift
115
+ assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}", paths.shift
116
+ assert_equal "#{@gem_repo}/yaml.Z", paths.shift
117
+ assert_equal "#{@gem_repo}/yaml", paths.shift
118
+
119
+ assert paths.empty?, paths.join(', ')
120
+ end
121
+
122
+ def test_fetch_bulk_index_uncompressed
123
+ util_setup_bulk_fetch false
124
+ use_ui @ui do
125
+ fetched_index = @source_index.fetch_bulk_index @uri
126
+ assert_equal [@gem1.full_name, @gem4.full_name, @gem2.full_name].sort,
127
+ fetched_index.gems.map { |n,s| n }.sort
128
+ end
129
+
130
+ paths = @fetcher.paths
131
+
132
+ assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}.Z", paths.shift
133
+ assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}", paths.shift
134
+
135
+ assert paths.empty?, paths.join(', ')
136
+ end
137
+
138
+ def test_fetch_quick_index
139
+ quick_index = util_zip @gem_names
140
+ @fetcher.data["#{@gem_repo}/quick/index.rz"] = quick_index
141
+
142
+ quick_index = @source_index.fetch_quick_index @uri
143
+ assert_equal [@gem1.full_name, @gem4.full_name, @gem2.full_name].sort,
144
+ quick_index.sort
145
+
146
+ paths = @fetcher.paths
147
+
148
+ assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
149
+
150
+ assert paths.empty?, paths.join(', ')
151
+ end
152
+
153
+ def test_fetch_quick_index_error
154
+ @fetcher.data["#{@gem_repo}/quick/index.rz"] =
155
+ proc { raise Exception }
156
+
157
+ e = assert_raise Gem::OperationNotSupportedError do
158
+ @source_index.fetch_quick_index @uri
159
+ end
160
+
161
+ assert_equal 'No quick index found: Exception', e.message
162
+
163
+ paths = @fetcher.paths
164
+
165
+ assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
166
+
167
+ assert paths.empty?, paths.join(', ')
168
+ end
169
+
170
+ def test_find_missing
171
+ missing = @source_index.find_missing [@gem3.full_name]
172
+ assert_equal [@gem3.full_name], missing
173
+ end
174
+
175
+ def test_find_missing_none_missing
176
+ missing = @source_index.find_missing @gem_names.split
177
+ assert_equal [], missing
178
+ end
179
+
180
+ def test_latest_specs
181
+ spec = quick_gem @gem1.name, '0.0.1'
182
+ @source_index.add_spec spec
183
+
184
+ expected = [
185
+ @gem1.full_name,
186
+ @gem2.full_name,
187
+ @gem4.full_name,
188
+ ].sort
189
+
190
+ assert_equal expected, @source_index.latest_specs.map { |s| s.full_name }.sort
191
+ end
192
+
193
+ def test_outdated
194
+ sic = Gem::SourceInfoCache.new
195
+ Gem::SourceInfoCache.instance_variable_set :@cache, sic
196
+
197
+ assert_equal [], @source_index.outdated
198
+
199
+ updated = quick_gem @gem1.name, (@gem1.version.bump)
200
+ util_setup_source_info_cache updated
201
+
202
+ assert_equal [updated.name], @source_index.outdated
203
+
204
+ updated_platform = quick_gem @gem1.name, (updated.version.bump) do |s|
205
+ s.platform = Gem::Platform.new 'x86-other_platform1'
206
+ end
207
+
208
+ util_setup_source_info_cache updated, updated_platform
209
+
210
+ assert_equal [updated_platform.name], @source_index.outdated
211
+ end
212
+
213
+ def test_remove_extra
214
+ @source_index.remove_extra [@gem1.full_name]
215
+ assert_equal [@gem1.full_name], @source_index.gems.map { |n,s| n }
216
+ end
217
+
218
+ def test_remove_extra_no_changes
219
+ gems = @gem_names.split.sort
220
+ @source_index.remove_extra gems
221
+ assert_equal gems, @source_index.gems.map { |n,s| n }.sort
222
+ end
223
+
224
+ def test_search
225
+ assert_equal [@gem1, @gem4], @source_index.search("gem_one")
226
+ assert_equal [@gem1], @source_index.search("gem_one", "= 0.0.2")
227
+
228
+ assert_equal [], @source_index.search("bogusstring")
229
+ assert_equal [], @source_index.search("gem_one", "= 3.2.1")
230
+
231
+ @a1 = quick_gem 'a', '1'
232
+ @a2 = quick_gem 'a', '2'
233
+
234
+ source_index = Gem::SourceIndex.new @a1.full_name => @a1,
235
+ @a2.full_name => @a2
236
+
237
+ assert_equal [@a1], source_index.search(@a1.name, '= 1')
238
+
239
+ r1 = Gem::Requirement.create '= 1'
240
+ assert_equal [@a1], source_index.search(@a1.name, r1)
241
+
242
+ dep = Gem::Dependency.new @a1.name, r1
243
+ assert_equal [@a1], source_index.search(dep)
244
+ end
245
+
246
+ def test_search_empty_cache
247
+ empty_source_index = Gem::SourceIndex.new({})
248
+ assert_equal [], empty_source_index.search("foo")
249
+ end
250
+
251
+ def test_search_platform
252
+ util_set_arch 'x86-my_platform1'
253
+
254
+ a1 = quick_gem 'a', '1'
255
+ a1_mine = quick_gem 'a', '1' do |s|
256
+ s.platform = Gem::Platform.new 'x86-my_platform1'
257
+ end
258
+ a1_other = quick_gem 'a', '1' do |s|
259
+ s.platform = Gem::Platform.new 'x86-other_platform1'
260
+ end
261
+
262
+ si = Gem::SourceIndex.new(a1.full_name => a1, a1_mine.full_name => a1_mine,
263
+ a1_other.full_name => a1_other)
264
+
265
+ dep = Gem::Dependency.new 'a', Gem::Requirement.new('1')
266
+
267
+ gems = si.search dep, true
268
+
269
+ assert_equal [a1, a1_mine], gems.sort
270
+ end
271
+
272
+ def test_signature
273
+ sig = @source_index.gem_signature('foo-1.2.3')
274
+ assert_equal 64, sig.length
275
+ assert_match(/^[a-f0-9]{64}$/, sig)
276
+ end
277
+
278
+ def test_specification
279
+ assert_equal @gem1, @source_index.specification(@gem1.full_name)
280
+
281
+ assert_nil @source_index.specification("foo-1.2.4")
282
+ end
283
+
284
+ def test_index_signature
285
+ sig = @source_index.index_signature
286
+ assert_match(/^[a-f0-9]{64}$/, sig)
287
+ end
288
+
289
+ def test_unzip
290
+ input = "x\234+\316\317MU(I\255(\001\000\021\350\003\232"
291
+ assert_equal 'some text', @source_index.unzip(input)
292
+ end
293
+
294
+ def test_update_bulk
295
+ util_setup_bulk_fetch true
296
+
297
+ @source_index.gems.replace({})
298
+ assert_equal [], @source_index.gems.keys.sort
299
+
300
+ use_ui @ui do
301
+ @source_index.update @uri
302
+
303
+ assert_equal @gem_names.split, @source_index.gems.keys.sort
304
+ end
305
+
306
+ paths = @fetcher.paths
307
+
308
+ assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
309
+ assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}.Z", paths.shift
310
+
311
+ assert paths.empty?, paths.join(', ')
312
+ end
313
+
314
+ def test_update_incremental
315
+ old_gem_conf = Gem.configuration
316
+ Gem.configuration = Gem::ConfigFile.new([])
317
+
318
+ quick_index = util_zip @all_gem_names.join("\n")
319
+ @fetcher.data["#{@gem_repo}/quick/index.rz"] = quick_index
320
+
321
+ marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
322
+ "#{@gem3.full_name}.gemspec.rz"
323
+ @fetcher.data[marshal_uri] = util_zip Marshal.dump(@gem3)
324
+
325
+ use_ui @ui do
326
+ @source_index.update @uri
327
+
328
+ assert_equal @all_gem_names, @source_index.gems.keys.sort
329
+ end
330
+
331
+ paths = @fetcher.paths
332
+ assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
333
+ assert_equal marshal_uri, paths.shift
334
+
335
+ assert paths.empty?, paths.join(', ')
336
+ ensure
337
+ Gem.configuration = old_gem_conf
338
+ end
339
+
340
+ def test_update_incremental_fallback
341
+ old_gem_conf = Gem.configuration
342
+ Gem.configuration = Gem::ConfigFile.new([])
343
+
344
+ quick_index = util_zip @all_gem_names.join("\n")
345
+ @fetcher.data["#{@gem_repo}/quick/index.rz"] = quick_index
346
+
347
+ marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
348
+ "#{@gem3.full_name}.gemspec.rz"
349
+
350
+ yaml_uri = "#{@gem_repo}/quick/#{@gem3.full_name}.gemspec.rz"
351
+ @fetcher.data[yaml_uri] = util_zip @gem3.to_yaml
352
+
353
+ use_ui @ui do
354
+ @source_index.update @uri
355
+
356
+ assert_equal @all_gem_names, @source_index.gems.keys.sort
357
+ end
358
+
359
+ paths = @fetcher.paths
360
+ assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
361
+ assert_equal marshal_uri, paths.shift
362
+ assert_equal yaml_uri, paths.shift
363
+
364
+ assert paths.empty?, paths.join(', ')
365
+ ensure
366
+ Gem.configuration = old_gem_conf
367
+ end
368
+
369
+ def test_update_incremental_marshal_mismatch
370
+ old_gem_conf = Gem.configuration
371
+ Gem.configuration = Gem::ConfigFile.new([])
372
+
373
+ quick_index = util_zip @all_gem_names.join("\n")
374
+ @fetcher.data["#{@gem_repo}/quick/index.rz"] = quick_index
375
+
376
+ marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
377
+ "#{@gem3.full_name}.gemspec.rz"
378
+ marshal_data = Marshal.dump(@gem3)
379
+ marshal_data[0] = (Marshal::MAJOR_VERSION - 1).chr
380
+ @fetcher.data[marshal_uri] = util_zip marshal_data
381
+
382
+ yaml_uri = "#{@gem_repo}/quick/#{@gem3.full_name}.gemspec.rz"
383
+ @fetcher.data[yaml_uri] = util_zip @gem3.to_yaml
384
+
385
+ use_ui @ui do
386
+ @source_index.update @uri
387
+
388
+ assert_equal @all_gem_names, @source_index.gems.keys.sort
389
+ end
390
+
391
+ paths = @fetcher.paths
392
+ assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
393
+ assert_equal marshal_uri, paths.shift
394
+ assert_equal yaml_uri, paths.shift
395
+
396
+ assert paths.empty?, paths.join(', ')
397
+ ensure
398
+ Gem.configuration = old_gem_conf
399
+ end
400
+
401
+ def test_update_with_missing
402
+ marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
403
+ "#{@gem3.full_name}.gemspec.rz"
404
+ dumped = Marshal.dump(@gem3)
405
+ @fetcher.data[marshal_uri] = util_zip(dumped)
406
+
407
+ use_ui @ui do
408
+ @source_index.update_with_missing @uri, [@gem3.full_name]
409
+ end
410
+
411
+ spec = @source_index.specification(@gem3.full_name)
412
+ # We don't care about the equality of undumped attributes
413
+ @gem3.files = spec.files
414
+ @gem3.loaded_from = spec.loaded_from
415
+
416
+ assert_equal @gem3, spec
417
+ end
418
+
419
+ def util_setup_bulk_fetch(compressed)
420
+ source_index = @source_index.dump
421
+
422
+ if compressed then
423
+ @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}.Z"] = util_zip source_index
424
+ else
425
+ @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = source_index
426
+ end
427
+ end
428
+
429
+ end