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,661 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems/dependency_installer'
3
+
4
+ class TestGemDependencyInstaller < RubyGemTestCase
5
+
6
+ def setup
7
+ super
8
+
9
+ @gems_dir = File.join @tempdir, 'gems'
10
+ @cache_dir = File.join @gemhome, 'cache'
11
+ FileUtils.mkdir @gems_dir
12
+
13
+ write_file File.join('gems', 'a-1', 'bin', 'a_bin') do |fp|
14
+ fp.puts "#!/usr/bin/ruby"
15
+ end
16
+
17
+ @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end
18
+ @aa1, @aa1_gem = util_gem 'aa', '1'
19
+ @a1_pre, @a1_pre_gem = util_gem 'a', '1.a'
20
+
21
+ @b1, @b1_gem = util_gem 'b', '1' do |s|
22
+ s.add_dependency 'a'
23
+ s.add_development_dependency 'aa'
24
+ end
25
+
26
+ @b1_pre, @b1_pre_gem = util_gem 'b', '1.a' do |s|
27
+ s.add_dependency 'a'
28
+ s.add_development_dependency 'aa'
29
+ end
30
+
31
+ @c1_pre, @c1_pre_gem = util_gem 'c', '1.a' do |s|
32
+ s.add_dependency 'a', '1.a'
33
+ s.add_dependency 'b', '1'
34
+ end
35
+
36
+ @d1, @d1_gem = util_gem 'd', '1'
37
+ @d2, @d2_gem = util_gem 'd', '2'
38
+
39
+ @x1_m, @x1_m_gem = util_gem 'x', '1' do |s|
40
+ s.platform = Gem::Platform.new %w[cpu my_platform 1]
41
+ end
42
+
43
+ @x1_o, @x1_o_gem = util_gem 'x', '1' do |s|
44
+ s.platform = Gem::Platform.new %w[cpu other_platform 1]
45
+ end
46
+
47
+ @w1, @w1_gem = util_gem 'w', '1' do |s| s.add_dependency 'x' end
48
+
49
+ @y1, @y1_gem = util_gem 'y', '1'
50
+ @y1_1_p, @y1_1_p_gem = util_gem 'y', '1.1' do |s|
51
+ s.platform = Gem::Platform.new %w[cpu my_platform 1]
52
+ end
53
+
54
+ @z1, @z1_gem = util_gem 'z', '1' do |s| s.add_dependency 'y' end
55
+
56
+ @fetcher = Gem::FakeFetcher.new
57
+ Gem::RemoteFetcher.fetcher = @fetcher
58
+
59
+ si = util_setup_spec_fetcher(@a1, @a1_pre, @b1, @b1_pre, @c1_pre, @d1, @d2,
60
+ @x1_m, @x1_o, @w1, @y1, @y1_1_p, @z1)
61
+
62
+ util_clear_gems
63
+ end
64
+
65
+ def test_install
66
+ FileUtils.mv @a1_gem, @tempdir
67
+ inst = nil
68
+
69
+ Dir.chdir @tempdir do
70
+ inst = Gem::DependencyInstaller.new
71
+ inst.install 'a'
72
+ end
73
+
74
+ assert_equal Gem::SourceIndex.new(@a1.full_name => @a1),
75
+ Gem::SourceIndex.from_installed_gems
76
+
77
+ assert_equal [@a1], inst.installed_gems
78
+ end
79
+
80
+ def test_install_all_dependencies
81
+ e1, e1_gem = util_gem 'e', '1' do |s|
82
+ s.add_dependency 'b'
83
+ end
84
+
85
+ util_clear_gems
86
+
87
+ FileUtils.mv @a1_gem, @tempdir
88
+ FileUtils.mv @b1_gem, @tempdir
89
+ FileUtils.mv e1_gem, @tempdir
90
+ inst = nil
91
+
92
+ Dir.chdir @tempdir do
93
+ inst = Gem::DependencyInstaller.new :ignore_dependencies => true
94
+ inst.install 'b'
95
+ end
96
+
97
+ Dir.chdir @tempdir do
98
+ inst = Gem::DependencyInstaller.new
99
+ inst.install 'e'
100
+ end
101
+
102
+ assert_equal %w[e-1 a-1], inst.installed_gems.map { |s| s.full_name }
103
+ end
104
+
105
+ def test_install_cache_dir
106
+ FileUtils.mv @a1_gem, @tempdir
107
+ FileUtils.mv @b1_gem, @tempdir
108
+ inst = nil
109
+
110
+ Dir.chdir @tempdir do
111
+ inst = Gem::DependencyInstaller.new :cache_dir => @tempdir
112
+ inst.install 'b'
113
+ end
114
+
115
+ assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
116
+
117
+ assert File.exist?(File.join(@tempdir, 'cache', @a1.file_name))
118
+ assert File.exist?(File.join(@tempdir, 'cache', @b1.file_name))
119
+ end
120
+
121
+ def test_install_dependencies_satisfied
122
+ a2, a2_gem = util_gem 'a', '2'
123
+
124
+ FileUtils.rm_rf File.join(@gemhome, 'gems')
125
+ Gem.source_index.refresh!
126
+
127
+ FileUtils.mv @a1_gem, @tempdir
128
+ FileUtils.mv a2_gem, @tempdir # not in index
129
+ FileUtils.mv @b1_gem, @tempdir
130
+ inst = nil
131
+
132
+ Dir.chdir @tempdir do
133
+ inst = Gem::DependencyInstaller.new
134
+ inst.install 'a-2'
135
+ end
136
+
137
+ FileUtils.rm File.join(@tempdir, a2.file_name)
138
+
139
+ Dir.chdir @tempdir do
140
+ inst = Gem::DependencyInstaller.new
141
+ inst.install 'b'
142
+ end
143
+
144
+ installed = Gem::SourceIndex.from_installed_gems.map { |n,s| s.full_name }
145
+
146
+ assert_equal %w[a-2 b-1], installed.sort
147
+
148
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
149
+ end
150
+
151
+ def test_install_dependency
152
+ FileUtils.mv @a1_gem, @tempdir
153
+ FileUtils.mv @b1_gem, @tempdir
154
+ inst = nil
155
+
156
+ Dir.chdir @tempdir do
157
+ inst = Gem::DependencyInstaller.new
158
+ inst.install 'b'
159
+ end
160
+
161
+ assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
162
+ end
163
+
164
+ def test_install_dependency_development
165
+ FileUtils.mv @a1_gem, @tempdir
166
+ FileUtils.mv @aa1_gem, @tempdir
167
+ FileUtils.mv @b1_gem, @tempdir
168
+ inst = nil
169
+
170
+ Dir.chdir @tempdir do
171
+ inst = Gem::DependencyInstaller.new(:development => true)
172
+ inst.install 'b'
173
+ end
174
+
175
+ assert_equal %w[a-1 aa-1 b-1], inst.installed_gems.map { |s| s.full_name }
176
+ end
177
+
178
+ def test_install_dependency_existing
179
+ Gem::Installer.new(@a1_gem).install
180
+ FileUtils.mv @a1_gem, @tempdir
181
+ FileUtils.mv @b1_gem, @tempdir
182
+ inst = nil
183
+
184
+ Dir.chdir @tempdir do
185
+ inst = Gem::DependencyInstaller.new
186
+ inst.install 'b'
187
+ end
188
+
189
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
190
+ end
191
+
192
+ def test_install_dependency_old
193
+ e1, e1_gem = util_gem 'e', '1'
194
+ f1, f1_gem = util_gem 'f', '1' do |s| s.add_dependency 'e' end
195
+ f2, f2_gem = util_gem 'f', '2'
196
+
197
+ FileUtils.mv e1_gem, @tempdir
198
+ FileUtils.mv f1_gem, @tempdir
199
+ FileUtils.mv f2_gem, @tempdir
200
+ inst = nil
201
+
202
+ Dir.chdir @tempdir do
203
+ inst = Gem::DependencyInstaller.new
204
+ inst.install 'f'
205
+ end
206
+
207
+ assert_equal %w[f-2], inst.installed_gems.map { |s| s.full_name }
208
+ end
209
+
210
+ def test_install_local
211
+ FileUtils.mv @a1_gem, @tempdir
212
+ inst = nil
213
+
214
+ Dir.chdir @tempdir do
215
+ inst = Gem::DependencyInstaller.new :domain => :local
216
+ inst.install 'a-1.gem'
217
+ end
218
+
219
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
220
+ end
221
+
222
+ def test_install_local_dependency
223
+ FileUtils.mv @a1_gem, @tempdir
224
+ FileUtils.mv @b1_gem, @tempdir
225
+
226
+ inst = nil
227
+
228
+ Dir.chdir @tempdir do
229
+ inst = Gem::DependencyInstaller.new :domain => :local
230
+ inst.install 'b-1.gem'
231
+ end
232
+
233
+ assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
234
+ end
235
+
236
+ def test_install_local_dependency_installed
237
+ FileUtils.mv @a1_gem, @tempdir
238
+ FileUtils.mv @b1_gem, @tempdir
239
+
240
+ inst = nil
241
+
242
+ Dir.chdir @tempdir do
243
+ Gem::Installer.new('a-1.gem').install
244
+
245
+ inst = Gem::DependencyInstaller.new :domain => :local
246
+ inst.install 'b-1.gem'
247
+ end
248
+
249
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
250
+ end
251
+
252
+ def test_install_local_subdir
253
+ inst = nil
254
+
255
+ Dir.chdir @tempdir do
256
+ inst = Gem::DependencyInstaller.new :domain => :local
257
+ inst.install 'gems/a-1.gem'
258
+ end
259
+
260
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
261
+ end
262
+
263
+ def test_install_env_shebang
264
+ FileUtils.mv @a1_gem, @tempdir
265
+ inst = nil
266
+
267
+ Dir.chdir @tempdir do
268
+ inst = Gem::DependencyInstaller.new :env_shebang => true, :wrappers => true
269
+ inst.install 'a'
270
+ end
271
+
272
+ env = "/\\S+/env" unless Gem.win_platform?
273
+
274
+ assert_match %r|\A#!#{env} #{Gem::ConfigMap[:ruby_install_name]}\n|,
275
+ File.read(File.join(@gemhome, 'bin', 'a_bin'))
276
+ end
277
+
278
+ def test_install_force
279
+ FileUtils.mv @b1_gem, @tempdir
280
+ si = util_setup_spec_fetcher @b1
281
+ @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
282
+ inst = nil
283
+
284
+ Dir.chdir @tempdir do
285
+ inst = Gem::DependencyInstaller.new :force => true
286
+ inst.install 'b'
287
+ end
288
+
289
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
290
+ end
291
+
292
+ def test_install_ignore_dependencies
293
+ FileUtils.mv @b1_gem, @tempdir
294
+ inst = nil
295
+
296
+ Dir.chdir @tempdir do
297
+ inst = Gem::DependencyInstaller.new :ignore_dependencies => true
298
+ inst.install 'b'
299
+ end
300
+
301
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
302
+ end
303
+
304
+ def test_install_install_dir
305
+ FileUtils.mv @a1_gem, @tempdir
306
+ gemhome2 = File.join @tempdir, 'gemhome2'
307
+ Dir.mkdir gemhome2
308
+ inst = nil
309
+
310
+ Dir.chdir @tempdir do
311
+ inst = Gem::DependencyInstaller.new :install_dir => gemhome2
312
+ inst.install 'a'
313
+ end
314
+
315
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
316
+
317
+ assert File.exist?(File.join(gemhome2, 'specifications', @a1.spec_name))
318
+ assert File.exist?(File.join(gemhome2, 'cache', @a1.file_name))
319
+ end
320
+
321
+ def test_install_domain_both
322
+ a1_data = nil
323
+ File.open @a1_gem, 'rb' do |fp|
324
+ a1_data = fp.read
325
+ end
326
+
327
+ @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data
328
+
329
+ FileUtils.mv @b1_gem, @tempdir
330
+ inst = nil
331
+
332
+ Dir.chdir @tempdir do
333
+ inst = Gem::DependencyInstaller.new :domain => :both
334
+ inst.install 'b'
335
+ end
336
+
337
+ assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
338
+ a1, b1 = inst.installed_gems
339
+
340
+ a1_expected = File.join(@gemhome, 'specifications', a1.spec_name)
341
+ b1_expected = File.join(@gemhome, 'specifications', b1.spec_name)
342
+
343
+ assert_equal a1_expected, a1.loaded_from
344
+ assert_equal b1_expected, b1.loaded_from
345
+ end
346
+
347
+ def test_install_domain_both_no_network
348
+ @fetcher.data["http://gems.example.com/gems/Marshal.#{@marshal_version}"] =
349
+ proc do
350
+ raise Gem::RemoteFetcher::FetchError
351
+ end
352
+
353
+ FileUtils.mv @a1_gem, @tempdir
354
+ FileUtils.mv @b1_gem, @tempdir
355
+ inst = nil
356
+
357
+ Dir.chdir @tempdir do
358
+ inst = Gem::DependencyInstaller.new :domain => :both
359
+ inst.install 'b'
360
+ end
361
+
362
+ assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
363
+ end
364
+
365
+ def test_install_domain_local
366
+ FileUtils.mv @b1_gem, @tempdir
367
+ inst = nil
368
+
369
+ Gem.source_index.remove_spec @a1.full_name
370
+ Gem.source_index.remove_spec @a1_pre.full_name
371
+
372
+ Dir.chdir @tempdir do
373
+ e = assert_raises Gem::InstallError do
374
+ inst = Gem::DependencyInstaller.new :domain => :local
375
+ inst.install 'b'
376
+ end
377
+
378
+ assert_equal 'b requires a (>= 0, runtime)', e.message
379
+ end
380
+
381
+ assert_equal [], inst.installed_gems.map { |s| s.full_name }
382
+ end
383
+
384
+ def test_install_domain_remote
385
+ a1_data = nil
386
+ File.open @a1_gem, 'rb' do |fp|
387
+ a1_data = fp.read
388
+ end
389
+
390
+ @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data
391
+
392
+ inst = Gem::DependencyInstaller.new :domain => :remote
393
+ inst.install 'a'
394
+
395
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
396
+ end
397
+
398
+ def test_install_dual_repository
399
+ FileUtils.mv @a1_gem, @tempdir
400
+ FileUtils.mv @b1_gem, @tempdir
401
+ inst = nil
402
+
403
+ gemhome2 = "#{@gemhome}2"
404
+
405
+ Dir.chdir @tempdir do
406
+ inst = Gem::DependencyInstaller.new :install_dir => gemhome2
407
+ inst.install 'a'
408
+ end
409
+
410
+ ENV['GEM_HOME'] = @gemhome
411
+ ENV['GEM_PATH'] = [@gemhome, gemhome2].join File::PATH_SEPARATOR
412
+ Gem.clear_paths
413
+
414
+ Dir.chdir @tempdir do
415
+ inst = Gem::DependencyInstaller.new
416
+ inst.install 'b'
417
+ end
418
+
419
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
420
+ end
421
+
422
+ def test_install_remote
423
+ a1_data = nil
424
+ File.open @a1_gem, 'rb' do |fp|
425
+ a1_data = fp.read
426
+ end
427
+
428
+ @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data
429
+
430
+ inst = Gem::DependencyInstaller.new
431
+
432
+ Dir.chdir @tempdir do
433
+ inst.install 'a'
434
+ end
435
+
436
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
437
+ end
438
+
439
+ def test_install_remote_dep
440
+ a1_data = nil
441
+ File.open @a1_gem, 'rb' do |fp|
442
+ a1_data = fp.read
443
+ end
444
+
445
+ @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data
446
+
447
+ inst = Gem::DependencyInstaller.new
448
+
449
+ Dir.chdir @tempdir do
450
+ dep = Gem::Dependency.new @a1.name, @a1.version
451
+ inst.install dep
452
+ end
453
+
454
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
455
+ end
456
+
457
+ def test_install_domain_remote_platform_newer
458
+ a2_o, a2_o_gem = util_gem 'a', '2' do |s|
459
+ s.platform = Gem::Platform.new %w[cpu other_platform 1]
460
+ end
461
+
462
+ util_clear_gems
463
+
464
+ si = util_setup_spec_fetcher @a1, a2_o
465
+
466
+ @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
467
+
468
+ a1_data = nil
469
+ a2_o_data = nil
470
+
471
+ File.open @a1_gem, 'rb' do |fp| a1_data = fp.read end
472
+ File.open a2_o_gem, 'rb' do |fp| a2_o_data = fp.read end
473
+
474
+ @fetcher.data["http://gems.example.com/gems/#{@a1.file_name}"] =
475
+ a1_data
476
+ @fetcher.data["http://gems.example.com/gems/#{a2_o.file_name}"] =
477
+ a2_o_data
478
+
479
+ inst = Gem::DependencyInstaller.new :domain => :remote
480
+ inst.install 'a'
481
+
482
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
483
+ end
484
+
485
+ def test_install_reinstall
486
+ Gem::Installer.new(@a1_gem).install
487
+ FileUtils.mv @a1_gem, @tempdir
488
+ inst = nil
489
+
490
+ Dir.chdir @tempdir do
491
+ inst = Gem::DependencyInstaller.new
492
+ inst.install 'a'
493
+ end
494
+
495
+ assert_equal Gem::SourceIndex.new(@a1.full_name => @a1),
496
+ Gem::SourceIndex.from_installed_gems
497
+
498
+ assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
499
+ end
500
+
501
+ if defined? OpenSSL then
502
+ def test_install_security_policy
503
+ data = File.open(@a1_gem, 'rb') { |f| f.read }
504
+ @fetcher.data['http://gems.example.com/gems/a-1.gem'] = data
505
+
506
+ data = File.open(@b1_gem, 'rb') { |f| f.read }
507
+ @fetcher.data['http://gems.example.com/gems/b-1.gem'] = data
508
+
509
+ policy = Gem::Security::HighSecurity
510
+ inst = Gem::DependencyInstaller.new :security_policy => policy
511
+
512
+ e = assert_raises Gem::Exception do
513
+ inst.install 'b'
514
+ end
515
+
516
+ assert_equal 'Unsigned gem', e.message
517
+
518
+ assert_equal %w[], inst.installed_gems.map { |s| s.full_name }
519
+ end
520
+ end
521
+
522
+ # Wrappers don't work on mswin
523
+ unless win_platform? then
524
+ def test_install_no_wrappers
525
+ @fetcher.data['http://gems.example.com/gems/a-1.gem'] = read_binary(@a1_gem)
526
+
527
+ inst = Gem::DependencyInstaller.new :wrappers => false
528
+ inst.install 'a'
529
+
530
+ refute_match(%r|This file was generated by #{Gem::NAME}.|,
531
+ File.read(File.join(@gemhome, 'bin', 'a_bin')))
532
+ end
533
+ end
534
+
535
+ def test_install_version
536
+ data = File.open(@d2_gem, 'rb') { |f| f.read }
537
+ @fetcher.data['http://gems.example.com/gems/d-2.gem'] = data
538
+
539
+ data = File.open(@d1_gem, 'rb') { |f| f.read }
540
+ @fetcher.data['http://gems.example.com/gems/d-1.gem'] = data
541
+
542
+ inst = Gem::DependencyInstaller.new
543
+
544
+ inst.install 'd', '= 1'
545
+
546
+ assert_equal %w[d-1], inst.installed_gems.map { |s| s.full_name }
547
+ end
548
+
549
+ def test_install_version_default
550
+ data = File.open(@d2_gem, 'rb') { |f| f.read }
551
+ @fetcher.data['http://gems.example.com/gems/d-2.gem'] = data
552
+
553
+ data = File.open(@d1_gem, 'rb') { |f| f.read }
554
+ @fetcher.data['http://gems.example.com/gems/d-1.gem'] = data
555
+
556
+ inst = Gem::DependencyInstaller.new
557
+ inst.install 'd'
558
+
559
+ assert_equal %w[d-2], inst.installed_gems.map { |s| s.full_name }
560
+ end
561
+
562
+ def test_find_gems_gems_with_sources
563
+ inst = Gem::DependencyInstaller.new
564
+ dep = Gem::Dependency.new 'b', '>= 0'
565
+
566
+ assert_equal [[@b1, @gem_repo]],
567
+ inst.find_gems_with_sources(dep)
568
+ end
569
+
570
+ def test_find_gems_with_sources_local
571
+ FileUtils.mv @a1_gem, @tempdir
572
+ inst = Gem::DependencyInstaller.new
573
+ dep = Gem::Dependency.new 'a', '>= 0'
574
+ gems = nil
575
+
576
+ Dir.chdir @tempdir do
577
+ gems = inst.find_gems_with_sources dep
578
+ end
579
+
580
+ assert_equal 2, gems.length
581
+ remote = gems.first
582
+ assert_equal 'a-1', remote.first.full_name, 'remote spec'
583
+ assert_equal @gem_repo, remote.last, 'remote path'
584
+
585
+ local = gems.last
586
+ assert_equal 'a-1', local.first.full_name, 'local spec'
587
+ assert_equal File.join(@tempdir, @a1.file_name),
588
+ local.last, 'local path'
589
+ end
590
+
591
+ def test_find_gems_with_sources_prerelease
592
+ installer = Gem::DependencyInstaller.new
593
+
594
+ dependency = Gem::Dependency.new('a', Gem::Requirement.default)
595
+
596
+ releases =
597
+ installer.find_gems_with_sources(dependency).map { |gems, *| gems }
598
+
599
+ assert releases.any? { |s| s.name == 'a' and s.version.to_s == '1' }
600
+ refute releases.any? { |s| s.name == 'a' and s.version.to_s == '1.a' }
601
+
602
+ dependency.prerelease = true
603
+
604
+ prereleases =
605
+ installer.find_gems_with_sources(dependency).map { |gems, *| gems }
606
+
607
+ assert_equal [@a1_pre], prereleases
608
+ end
609
+
610
+ def test_gather_dependencies
611
+ inst = Gem::DependencyInstaller.new
612
+ inst.find_spec_by_name_and_version 'b'
613
+ inst.gather_dependencies
614
+
615
+ assert_equal %w[a-1 b-1], inst.gems_to_install.map { |s| s.full_name }
616
+ end
617
+
618
+ def test_gather_dependencies_platform_alternate
619
+ util_set_arch 'cpu-my_platform1'
620
+
621
+ inst = Gem::DependencyInstaller.new
622
+ inst.find_spec_by_name_and_version 'w'
623
+ inst.gather_dependencies
624
+
625
+ assert_equal %w[x-1-cpu-my_platform-1 w-1],
626
+ inst.gems_to_install.map { |s| s.full_name }
627
+ end
628
+
629
+ def test_gather_dependencies_platform_bump
630
+ inst = Gem::DependencyInstaller.new
631
+ inst.find_spec_by_name_and_version 'z'
632
+ inst.gather_dependencies
633
+
634
+ assert_equal %w[y-1 z-1], inst.gems_to_install.map { |s| s.full_name }
635
+ end
636
+
637
+ def test_gather_dependencies_prerelease
638
+ inst = Gem::DependencyInstaller.new :prerelease => true
639
+ inst.find_spec_by_name_and_version 'c', '1.a'
640
+ inst.gather_dependencies
641
+
642
+ assert_equal %w[a-1.a b-1 c-1.a],
643
+ inst.gems_to_install.map { |s| s.full_name }
644
+ end
645
+
646
+ def test_gather_dependencies_old_required
647
+ e1, = util_gem 'e', '1' do |s| s.add_dependency 'd', '= 1' end
648
+
649
+ util_clear_gems
650
+
651
+ si = util_setup_spec_fetcher @d1, @d2, e1
652
+
653
+ inst = Gem::DependencyInstaller.new
654
+ inst.find_spec_by_name_and_version 'e'
655
+ inst.gather_dependencies
656
+
657
+ assert_equal %w[d-1 e-1], inst.gems_to_install.map { |s| s.full_name }
658
+ end
659
+
660
+ end
661
+