libgems 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +5811 -0
- data/History.txt +887 -0
- data/LICENSE.txt +51 -0
- data/README.md +87 -0
- data/Rakefile +113 -0
- data/lib/gauntlet_libgems.rb +50 -0
- data/lib/libgems.rb +1246 -0
- data/lib/libgems/builder.rb +102 -0
- data/lib/libgems/command.rb +534 -0
- data/lib/libgems/command_manager.rb +182 -0
- data/lib/libgems/commands/build_command.rb +53 -0
- data/lib/libgems/commands/cert_command.rb +86 -0
- data/lib/libgems/commands/check_command.rb +80 -0
- data/lib/libgems/commands/cleanup_command.rb +106 -0
- data/lib/libgems/commands/contents_command.rb +98 -0
- data/lib/libgems/commands/dependency_command.rb +195 -0
- data/lib/libgems/commands/environment_command.rb +133 -0
- data/lib/libgems/commands/fetch_command.rb +67 -0
- data/lib/libgems/commands/generate_index_command.rb +133 -0
- data/lib/libgems/commands/help_command.rb +172 -0
- data/lib/libgems/commands/install_command.rb +178 -0
- data/lib/libgems/commands/list_command.rb +35 -0
- data/lib/libgems/commands/lock_command.rb +110 -0
- data/lib/libgems/commands/mirror_command.rb +111 -0
- data/lib/libgems/commands/outdated_command.rb +33 -0
- data/lib/libgems/commands/owner_command.rb +75 -0
- data/lib/libgems/commands/pristine_command.rb +93 -0
- data/lib/libgems/commands/push_command.rb +56 -0
- data/lib/libgems/commands/query_command.rb +280 -0
- data/lib/libgems/commands/rdoc_command.rb +91 -0
- data/lib/libgems/commands/search_command.rb +31 -0
- data/lib/libgems/commands/server_command.rb +86 -0
- data/lib/libgems/commands/sources_command.rb +157 -0
- data/lib/libgems/commands/specification_command.rb +125 -0
- data/lib/libgems/commands/stale_command.rb +27 -0
- data/lib/libgems/commands/uninstall_command.rb +83 -0
- data/lib/libgems/commands/unpack_command.rb +121 -0
- data/lib/libgems/commands/update_command.rb +160 -0
- data/lib/libgems/commands/which_command.rb +86 -0
- data/lib/libgems/config_file.rb +345 -0
- data/lib/libgems/custom_require.rb +44 -0
- data/lib/libgems/defaults.rb +101 -0
- data/lib/libgems/dependency.rb +227 -0
- data/lib/libgems/dependency_installer.rb +286 -0
- data/lib/libgems/dependency_list.rb +208 -0
- data/lib/libgems/doc_manager.rb +242 -0
- data/lib/libgems/errors.rb +35 -0
- data/lib/libgems/exceptions.rb +91 -0
- data/lib/libgems/ext.rb +18 -0
- data/lib/libgems/ext/builder.rb +56 -0
- data/lib/libgems/ext/configure_builder.rb +25 -0
- data/lib/libgems/ext/ext_conf_builder.rb +24 -0
- data/lib/libgems/ext/rake_builder.rb +39 -0
- data/lib/libgems/format.rb +81 -0
- data/lib/libgems/gem_openssl.rb +92 -0
- data/lib/libgems/gem_path_searcher.rb +100 -0
- data/lib/libgems/gem_runner.rb +79 -0
- data/lib/libgems/gemcutter_utilities.rb +49 -0
- data/lib/libgems/indexer.rb +720 -0
- data/lib/libgems/install_update_options.rb +125 -0
- data/lib/libgems/installer.rb +604 -0
- data/lib/libgems/local_remote_options.rb +135 -0
- data/lib/libgems/old_format.rb +153 -0
- data/lib/libgems/package.rb +97 -0
- data/lib/libgems/package/f_sync_dir.rb +23 -0
- data/lib/libgems/package/tar_header.rb +266 -0
- data/lib/libgems/package/tar_input.rb +222 -0
- data/lib/libgems/package/tar_output.rb +144 -0
- data/lib/libgems/package/tar_reader.rb +106 -0
- data/lib/libgems/package/tar_reader/entry.rb +141 -0
- data/lib/libgems/package/tar_writer.rb +241 -0
- data/lib/libgems/package_task.rb +126 -0
- data/lib/libgems/platform.rb +183 -0
- data/lib/libgems/remote_fetcher.rb +414 -0
- data/lib/libgems/require_paths_builder.rb +18 -0
- data/lib/libgems/requirement.rb +153 -0
- data/lib/libgems/security.rb +814 -0
- data/lib/libgems/server.rb +872 -0
- data/lib/libgems/source_index.rb +597 -0
- data/lib/libgems/source_info_cache.rb +395 -0
- data/lib/libgems/source_info_cache_entry.rb +56 -0
- data/lib/libgems/spec_fetcher.rb +337 -0
- data/lib/libgems/specification.rb +1487 -0
- data/lib/libgems/test_utilities.rb +147 -0
- data/lib/libgems/text.rb +65 -0
- data/lib/libgems/uninstaller.rb +278 -0
- data/lib/libgems/user_interaction.rb +527 -0
- data/lib/libgems/validator.rb +240 -0
- data/lib/libgems/version.rb +316 -0
- data/lib/libgems/version_option.rb +65 -0
- data/lib/rbconfig/datadir.rb +20 -0
- data/test/bogussources.rb +8 -0
- data/test/data/gem-private_key.pem +27 -0
- data/test/data/gem-public_cert.pem +20 -0
- data/test/fake_certlib/openssl.rb +7 -0
- data/test/foo/discover.rb +0 -0
- data/test/gem_installer_test_case.rb +97 -0
- data/test/gem_package_tar_test_case.rb +132 -0
- data/test/gemutilities.rb +605 -0
- data/test/insure_session.rb +43 -0
- data/test/mockgemui.rb +56 -0
- data/test/plugin/exception/libgems_plugin.rb +2 -0
- data/test/plugin/load/libgems_plugin.rb +1 -0
- data/test/plugin/standarderror/libgems_plugin.rb +2 -0
- data/test/private_key.pem +27 -0
- data/test/public_cert.pem +20 -0
- data/test/rubygems_plugin.rb +21 -0
- data/test/simple_gem.rb +66 -0
- data/test/test_config.rb +12 -0
- data/test/test_gem.rb +780 -0
- data/test/test_gem_builder.rb +27 -0
- data/test/test_gem_command.rb +178 -0
- data/test/test_gem_command_manager.rb +207 -0
- data/test/test_gem_commands_build_command.rb +74 -0
- data/test/test_gem_commands_cert_command.rb +124 -0
- data/test/test_gem_commands_check_command.rb +18 -0
- data/test/test_gem_commands_contents_command.rb +156 -0
- data/test/test_gem_commands_dependency_command.rb +216 -0
- data/test/test_gem_commands_environment_command.rb +144 -0
- data/test/test_gem_commands_fetch_command.rb +76 -0
- data/test/test_gem_commands_generate_index_command.rb +135 -0
- data/test/test_gem_commands_install_command.rb +315 -0
- data/test/test_gem_commands_list_command.rb +36 -0
- data/test/test_gem_commands_lock_command.rb +68 -0
- data/test/test_gem_commands_mirror_command.rb +60 -0
- data/test/test_gem_commands_outdated_command.rb +40 -0
- data/test/test_gem_commands_owner_command.rb +105 -0
- data/test/test_gem_commands_pristine_command.rb +108 -0
- data/test/test_gem_commands_push_command.rb +81 -0
- data/test/test_gem_commands_query_command.rb +426 -0
- data/test/test_gem_commands_server_command.rb +59 -0
- data/test/test_gem_commands_sources_command.rb +209 -0
- data/test/test_gem_commands_specification_command.rb +139 -0
- data/test/test_gem_commands_stale_command.rb +38 -0
- data/test/test_gem_commands_uninstall_command.rb +83 -0
- data/test/test_gem_commands_unpack_command.rb +199 -0
- data/test/test_gem_commands_update_command.rb +207 -0
- data/test/test_gem_commands_which_command.rb +66 -0
- data/test/test_gem_config_file.rb +287 -0
- data/test/test_gem_dependency.rb +149 -0
- data/test/test_gem_dependency_installer.rb +661 -0
- data/test/test_gem_dependency_list.rb +230 -0
- data/test/test_gem_doc_manager.rb +31 -0
- data/test/test_gem_ext_configure_builder.rb +84 -0
- data/test/test_gem_ext_ext_conf_builder.rb +173 -0
- data/test/test_gem_ext_rake_builder.rb +81 -0
- data/test/test_gem_format.rb +70 -0
- data/test/test_gem_gem_path_searcher.rb +78 -0
- data/test/test_gem_gem_runner.rb +45 -0
- data/test/test_gem_gemcutter_utilities.rb +103 -0
- data/test/test_gem_indexer.rb +673 -0
- data/test/test_gem_install_update_options.rb +68 -0
- data/test/test_gem_installer.rb +857 -0
- data/test/test_gem_local_remote_options.rb +97 -0
- data/test/test_gem_package_tar_header.rb +130 -0
- data/test/test_gem_package_tar_input.rb +112 -0
- data/test/test_gem_package_tar_output.rb +97 -0
- data/test/test_gem_package_tar_reader.rb +46 -0
- data/test/test_gem_package_tar_reader_entry.rb +109 -0
- data/test/test_gem_package_tar_writer.rb +144 -0
- data/test/test_gem_package_task.rb +59 -0
- data/test/test_gem_platform.rb +264 -0
- data/test/test_gem_remote_fetcher.rb +740 -0
- data/test/test_gem_requirement.rb +292 -0
- data/test/test_gem_server.rb +356 -0
- data/test/test_gem_silent_ui.rb +113 -0
- data/test/test_gem_source_index.rb +461 -0
- data/test/test_gem_spec_fetcher.rb +410 -0
- data/test/test_gem_specification.rb +1334 -0
- data/test/test_gem_stream_ui.rb +218 -0
- data/test/test_gem_text.rb +43 -0
- data/test/test_gem_uninstaller.rb +146 -0
- data/test/test_gem_validator.rb +63 -0
- data/test/test_gem_version.rb +181 -0
- data/test/test_gem_version_option.rb +89 -0
- data/test/test_kernel.rb +59 -0
- metadata +402 -0
@@ -0,0 +1,287 @@
|
|
1
|
+
require File.expand_path('../gemutilities', __FILE__)
|
2
|
+
require 'libgems/config_file'
|
3
|
+
|
4
|
+
class TestGemConfigFile < RubyGemTestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
|
9
|
+
@temp_conf = File.join @tempdir, '.gemrc'
|
10
|
+
|
11
|
+
@cfg_args = %W[--config-file #{@temp_conf}]
|
12
|
+
|
13
|
+
@orig_SYSTEM_WIDE_CONFIG_FILE = LibGems::ConfigFile::SYSTEM_WIDE_CONFIG_FILE
|
14
|
+
LibGems::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
|
15
|
+
LibGems::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
|
16
|
+
File.join(@tempdir, 'system-gemrc')
|
17
|
+
LibGems::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear
|
18
|
+
LibGems::ConfigFile::PLATFORM_DEFAULTS.clear
|
19
|
+
|
20
|
+
util_config_file
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
LibGems::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear
|
25
|
+
LibGems::ConfigFile::PLATFORM_DEFAULTS.clear
|
26
|
+
LibGems::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
|
27
|
+
LibGems::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
|
28
|
+
@orig_SYSTEM_WIDE_CONFIG_FILE
|
29
|
+
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_initialize
|
34
|
+
assert_equal @temp_conf, @cfg.config_file_name
|
35
|
+
|
36
|
+
assert_equal false, @cfg.backtrace
|
37
|
+
assert_equal true, @cfg.update_sources
|
38
|
+
assert_equal false, @cfg.benchmark
|
39
|
+
assert_equal LibGems::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold
|
40
|
+
assert_equal true, @cfg.verbose
|
41
|
+
assert_equal [@gem_repo], LibGems.sources
|
42
|
+
|
43
|
+
File.open @temp_conf, 'w' do |fp|
|
44
|
+
fp.puts ":backtrace: true"
|
45
|
+
fp.puts ":update_sources: false"
|
46
|
+
fp.puts ":benchmark: true"
|
47
|
+
fp.puts ":bulk_threshold: 10"
|
48
|
+
fp.puts ":verbose: false"
|
49
|
+
fp.puts ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97"
|
50
|
+
fp.puts ":sources:"
|
51
|
+
fp.puts " - http://more-gems.example.com"
|
52
|
+
fp.puts "install: --wrappers"
|
53
|
+
fp.puts ":gempath:"
|
54
|
+
fp.puts "- /usr/ruby/1.8/lib/ruby/gems/1.8"
|
55
|
+
fp.puts "- /var/ruby/1.8/gem_home"
|
56
|
+
end
|
57
|
+
|
58
|
+
util_config_file
|
59
|
+
|
60
|
+
assert_equal true, @cfg.backtrace
|
61
|
+
assert_equal true, @cfg.benchmark
|
62
|
+
assert_equal 10, @cfg.bulk_threshold
|
63
|
+
assert_equal false, @cfg.verbose
|
64
|
+
assert_equal false, @cfg.update_sources
|
65
|
+
assert_equal "701229f217cdf23b1344c7b4b54ca97", @cfg.rubygems_api_key
|
66
|
+
assert_equal %w[http://more-gems.example.com], LibGems.sources
|
67
|
+
assert_equal '--wrappers', @cfg[:install]
|
68
|
+
assert_equal(['/usr/ruby/1.8/lib/ruby/gems/1.8', '/var/ruby/1.8/gem_home'],
|
69
|
+
@cfg.path)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_initialize_handle_arguments_config_file
|
73
|
+
util_config_file %W[--config-file #{@temp_conf}]
|
74
|
+
|
75
|
+
assert_equal @temp_conf, @cfg.config_file_name
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_initialize_handle_arguments_config_file_with_other_params
|
79
|
+
util_config_file %W[--config-file #{@temp_conf} --backtrace]
|
80
|
+
|
81
|
+
assert_equal @temp_conf, @cfg.config_file_name
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_initialize_handle_arguments_config_file_equals
|
85
|
+
util_config_file %W[--config-file=#{@temp_conf}]
|
86
|
+
|
87
|
+
assert_equal @temp_conf, @cfg.config_file_name
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_initialize_operating_system_override
|
91
|
+
LibGems::ConfigFile::OPERATING_SYSTEM_DEFAULTS[:bulk_threshold] = 1
|
92
|
+
LibGems::ConfigFile::OPERATING_SYSTEM_DEFAULTS['install'] = '--no-env-shebang'
|
93
|
+
|
94
|
+
LibGems::ConfigFile::PLATFORM_DEFAULTS[:bulk_threshold] = 2
|
95
|
+
|
96
|
+
util_config_file
|
97
|
+
|
98
|
+
assert_equal 2, @cfg.bulk_threshold
|
99
|
+
assert_equal '--no-env-shebang', @cfg[:install]
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_initialize_platform_override
|
103
|
+
LibGems::ConfigFile::PLATFORM_DEFAULTS[:bulk_threshold] = 2
|
104
|
+
LibGems::ConfigFile::PLATFORM_DEFAULTS['install'] = '--no-env-shebang'
|
105
|
+
|
106
|
+
File.open LibGems::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, 'w' do |fp|
|
107
|
+
fp.puts ":bulk_threshold: 3"
|
108
|
+
end
|
109
|
+
|
110
|
+
util_config_file
|
111
|
+
|
112
|
+
assert_equal 3, @cfg.bulk_threshold
|
113
|
+
assert_equal '--no-env-shebang', @cfg[:install]
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_initialize_system_wide_override
|
117
|
+
File.open LibGems::ConfigFile::SYSTEM_WIDE_CONFIG_FILE, 'w' do |fp|
|
118
|
+
fp.puts ":backtrace: false"
|
119
|
+
fp.puts ":bulk_threshold: 2048"
|
120
|
+
end
|
121
|
+
|
122
|
+
File.open @temp_conf, 'w' do |fp|
|
123
|
+
fp.puts ":backtrace: true"
|
124
|
+
end
|
125
|
+
|
126
|
+
util_config_file
|
127
|
+
|
128
|
+
assert_equal 2048, @cfg.bulk_threshold
|
129
|
+
assert_equal true, @cfg.backtrace
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_handle_arguments
|
133
|
+
args = %w[--backtrace --bunch --of --args here]
|
134
|
+
|
135
|
+
@cfg.handle_arguments args
|
136
|
+
|
137
|
+
assert_equal %w[--bunch --of --args here], @cfg.args
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_handle_arguments_backtrace
|
141
|
+
assert_equal false, @cfg.backtrace
|
142
|
+
|
143
|
+
args = %w[--backtrace]
|
144
|
+
|
145
|
+
@cfg.handle_arguments args
|
146
|
+
|
147
|
+
assert_equal true, @cfg.backtrace
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_handle_arguments_benchmark
|
151
|
+
assert_equal false, @cfg.benchmark
|
152
|
+
|
153
|
+
args = %w[--benchmark]
|
154
|
+
|
155
|
+
@cfg.handle_arguments args
|
156
|
+
|
157
|
+
assert_equal true, @cfg.benchmark
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_handle_arguments_debug
|
161
|
+
old_dollar_DEBUG = $DEBUG
|
162
|
+
assert_equal false, $DEBUG
|
163
|
+
|
164
|
+
args = %w[--debug]
|
165
|
+
|
166
|
+
@cfg.handle_arguments args
|
167
|
+
|
168
|
+
assert_equal true, $DEBUG
|
169
|
+
ensure
|
170
|
+
$DEBUG = old_dollar_DEBUG
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_handle_arguments_override
|
174
|
+
File.open @temp_conf, 'w' do |fp|
|
175
|
+
fp.puts ":benchmark: false"
|
176
|
+
end
|
177
|
+
|
178
|
+
util_config_file %W[--benchmark --config-file=#{@temp_conf}]
|
179
|
+
|
180
|
+
assert_equal true, @cfg.benchmark
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_handle_arguments_traceback
|
184
|
+
assert_equal false, @cfg.backtrace
|
185
|
+
|
186
|
+
args = %w[--traceback]
|
187
|
+
|
188
|
+
@cfg.handle_arguments args
|
189
|
+
|
190
|
+
assert_equal true, @cfg.backtrace
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_really_verbose
|
194
|
+
assert_equal false, @cfg.really_verbose
|
195
|
+
|
196
|
+
@cfg.verbose = true
|
197
|
+
|
198
|
+
assert_equal false, @cfg.really_verbose
|
199
|
+
|
200
|
+
@cfg.verbose = 1
|
201
|
+
|
202
|
+
assert_equal true, @cfg.really_verbose
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_write
|
206
|
+
@cfg.backtrace = true
|
207
|
+
@cfg.benchmark = true
|
208
|
+
@cfg.update_sources = false
|
209
|
+
@cfg.bulk_threshold = 10
|
210
|
+
@cfg.verbose = false
|
211
|
+
LibGems.sources.replace %w[http://more-gems.example.com]
|
212
|
+
@cfg[:install] = '--wrappers'
|
213
|
+
|
214
|
+
@cfg.write
|
215
|
+
|
216
|
+
util_config_file
|
217
|
+
|
218
|
+
# These should not be written out to the config file.
|
219
|
+
assert_equal false, @cfg.backtrace, 'backtrace'
|
220
|
+
assert_equal false, @cfg.benchmark, 'benchmark'
|
221
|
+
assert_equal LibGems::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold,
|
222
|
+
'bulk_threshold'
|
223
|
+
assert_equal true, @cfg.update_sources, 'update_sources'
|
224
|
+
assert_equal true, @cfg.verbose, 'verbose'
|
225
|
+
|
226
|
+
assert_equal '--wrappers', @cfg[:install], 'install'
|
227
|
+
|
228
|
+
# this should be written out to the config file.
|
229
|
+
assert_equal %w[http://more-gems.example.com], LibGems.sources
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_write_from_hash
|
233
|
+
File.open @temp_conf, 'w' do |fp|
|
234
|
+
fp.puts ":backtrace: true"
|
235
|
+
fp.puts ":benchmark: true"
|
236
|
+
fp.puts ":bulk_threshold: 10"
|
237
|
+
fp.puts ":update_sources: false"
|
238
|
+
fp.puts ":verbose: false"
|
239
|
+
fp.puts ":sources:"
|
240
|
+
fp.puts " - http://more-gems.example.com"
|
241
|
+
fp.puts "install: --wrappers"
|
242
|
+
end
|
243
|
+
|
244
|
+
util_config_file
|
245
|
+
|
246
|
+
@cfg.backtrace = :junk
|
247
|
+
@cfg.benchmark = :junk
|
248
|
+
@cfg.update_sources = :junk
|
249
|
+
@cfg.bulk_threshold = 20
|
250
|
+
@cfg.verbose = :junk
|
251
|
+
LibGems.sources.replace %w[http://even-more-gems.example.com]
|
252
|
+
@cfg[:install] = '--wrappers --no-rdoc'
|
253
|
+
|
254
|
+
@cfg.write
|
255
|
+
|
256
|
+
util_config_file
|
257
|
+
|
258
|
+
# These should not be written out to the config file
|
259
|
+
assert_equal true, @cfg.backtrace, 'backtrace'
|
260
|
+
assert_equal true, @cfg.benchmark, 'benchmark'
|
261
|
+
assert_equal 10, @cfg.bulk_threshold, 'bulk_threshold'
|
262
|
+
assert_equal false, @cfg.update_sources, 'update_sources'
|
263
|
+
assert_equal false, @cfg.verbose, 'verbose'
|
264
|
+
|
265
|
+
assert_equal '--wrappers --no-rdoc', @cfg[:install], 'install'
|
266
|
+
|
267
|
+
assert_equal %w[http://even-more-gems.example.com], LibGems.sources
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_load_rubygems_api_key_from_credentials
|
271
|
+
temp_cred = File.join LibGems.user_home, '.gem', 'credentials'
|
272
|
+
FileUtils.mkdir File.dirname(temp_cred)
|
273
|
+
File.open temp_cred, 'w' do |fp|
|
274
|
+
fp.puts ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97"
|
275
|
+
end
|
276
|
+
|
277
|
+
util_config_file
|
278
|
+
|
279
|
+
assert_equal "701229f217cdf23b1344c7b4b54ca97", @cfg.rubygems_api_key
|
280
|
+
end
|
281
|
+
|
282
|
+
def util_config_file(args = @cfg_args)
|
283
|
+
@cfg = LibGems::ConfigFile.new args
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|
287
|
+
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require File.expand_path('../gemutilities', __FILE__)
|
2
|
+
require 'libgems/dependency'
|
3
|
+
|
4
|
+
class TestGemDependency < RubyGemTestCase
|
5
|
+
|
6
|
+
def test_subclass
|
7
|
+
sc = Class.new LibGems::Dependency
|
8
|
+
def sc.requirement() bogus; end
|
9
|
+
|
10
|
+
out, err = capture_io do
|
11
|
+
assert_equal LibGems::Requirement.default, sc.new('a').version_requirement
|
12
|
+
end
|
13
|
+
|
14
|
+
assert_match %r%deprecated%, err
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_initialize
|
18
|
+
d = dep "pkg", "> 1.0"
|
19
|
+
|
20
|
+
assert_equal "pkg", d.name
|
21
|
+
assert_equal req("> 1.0"), d.requirement
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_initialize_double
|
25
|
+
d = dep "pkg", "> 1.0", "< 2.0"
|
26
|
+
assert_equal req("> 1.0", "< 2.0"), d.requirement
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_initialize_empty
|
30
|
+
d = dep "pkg"
|
31
|
+
assert_equal req(">= 0"), d.requirement
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_initialize_type
|
35
|
+
assert_equal :runtime, dep("pkg").type
|
36
|
+
assert_equal :development, dep("pkg", [], :development).type
|
37
|
+
|
38
|
+
assert_raises ArgumentError do
|
39
|
+
dep "pkg", :sometimes
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_initialize_version
|
44
|
+
d = dep "pkg", v("2")
|
45
|
+
assert_equal req("= 2"), d.requirement
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_equals2
|
49
|
+
o = dep "other"
|
50
|
+
d = dep "pkg", "> 1.0"
|
51
|
+
d1 = dep "pkg", "> 1.1"
|
52
|
+
|
53
|
+
assert_equal d, d.dup
|
54
|
+
assert_equal d.dup, d
|
55
|
+
|
56
|
+
refute_equal d, d1
|
57
|
+
refute_equal d1, d
|
58
|
+
|
59
|
+
refute_equal d, o
|
60
|
+
refute_equal o, d
|
61
|
+
|
62
|
+
refute_equal d, Object.new
|
63
|
+
refute_equal Object.new, d
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_equals2_type
|
67
|
+
refute_equal dep("pkg", :runtime), dep("pkg", :development)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_equals_tilde
|
71
|
+
d = dep "a", "0"
|
72
|
+
|
73
|
+
assert_match d, d, "matche self"
|
74
|
+
assert_match dep("a", ">= 0"), d, "match version exact"
|
75
|
+
assert_match dep("a", ">= 0"), dep("a", "1"), "match version"
|
76
|
+
assert_match dep(/a/, ">= 0"), d, "match simple regexp"
|
77
|
+
assert_match dep(/a|b/, ">= 0"), d, "match scary regexp"
|
78
|
+
|
79
|
+
refute_match dep(/a/), dep("b")
|
80
|
+
refute_match dep("a"), Object.new
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_equals_tilde_escape
|
84
|
+
refute_match dep("a|b"), dep("a", "1")
|
85
|
+
assert_match dep(/a|b/), dep("a", "1")
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_equals_tilde_object
|
89
|
+
o = Object.new
|
90
|
+
def o.name ; 'a' end
|
91
|
+
def o.version ; '0' end
|
92
|
+
|
93
|
+
assert_match dep("a"), o
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_equals_tilde_spec
|
97
|
+
assert_match dep("a", ">= 0"), spec("a", "0")
|
98
|
+
assert_match dep("a", "1"), spec("a", "1")
|
99
|
+
assert_match dep(/a/, ">= 0"), spec("a", "0")
|
100
|
+
assert_match dep(/a|b/, ">= 0"), spec("b", "0")
|
101
|
+
refute_match dep(/a/, ">= 0"), spec("b", "0")
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_hash
|
105
|
+
d = dep "pkg", "1.0"
|
106
|
+
|
107
|
+
assert_equal d.hash, d.dup.hash
|
108
|
+
assert_equal d.dup.hash, d.hash
|
109
|
+
|
110
|
+
refute_equal dep("pkg", "1.0").hash, dep("pkg", "2.0").hash, "requirement"
|
111
|
+
refute_equal dep("pkg", "1.0").hash, dep("abc", "1.0").hash, "name"
|
112
|
+
refute_equal dep("pkg", :development), dep("pkg", :runtime), "type"
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_prerelease_eh
|
116
|
+
d = dep "pkg", "= 1"
|
117
|
+
|
118
|
+
refute d.prerelease?
|
119
|
+
|
120
|
+
d.prerelease = true
|
121
|
+
|
122
|
+
assert d.prerelease?
|
123
|
+
|
124
|
+
d = dep "pkg", "= 1.a"
|
125
|
+
|
126
|
+
assert d.prerelease?
|
127
|
+
|
128
|
+
d.prerelease = false
|
129
|
+
|
130
|
+
assert d.prerelease?
|
131
|
+
|
132
|
+
d = dep "pkg", "> 1.a", "> 2"
|
133
|
+
|
134
|
+
assert d.prerelease?
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_version_requirements_equals_deprecated
|
138
|
+
d = dep "pkg", "1.0"
|
139
|
+
|
140
|
+
out, err = capture_io do
|
141
|
+
d.version_requirements = '2.0'
|
142
|
+
assert_equal LibGems::Requirement.new(%w[2.0]), d.requirement
|
143
|
+
end
|
144
|
+
|
145
|
+
assert_match %r%deprecated%, err
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
@@ -0,0 +1,661 @@
|
|
1
|
+
require File.expand_path('../gemutilities', __FILE__)
|
2
|
+
require 'libgems/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 = LibGems::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 = LibGems::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 = LibGems::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 = LibGems::FakeFetcher.new
|
57
|
+
LibGems::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 = LibGems::DependencyInstaller.new
|
71
|
+
inst.install 'a'
|
72
|
+
end
|
73
|
+
|
74
|
+
assert_equal LibGems::SourceIndex.new(@a1.full_name => @a1),
|
75
|
+
LibGems::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 = LibGems::DependencyInstaller.new :ignore_dependencies => true
|
94
|
+
inst.install 'b'
|
95
|
+
end
|
96
|
+
|
97
|
+
Dir.chdir @tempdir do
|
98
|
+
inst = LibGems::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 = LibGems::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
|
+
LibGems.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 = LibGems::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 = LibGems::DependencyInstaller.new
|
141
|
+
inst.install 'b'
|
142
|
+
end
|
143
|
+
|
144
|
+
installed = LibGems::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 = LibGems::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 = LibGems::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
|
+
LibGems::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 = LibGems::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 = LibGems::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 = LibGems::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 = LibGems::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
|
+
LibGems::Installer.new('a-1.gem').install
|
244
|
+
|
245
|
+
inst = LibGems::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 = LibGems::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 = LibGems::DependencyInstaller.new :env_shebang => true, :wrappers => true
|
269
|
+
inst.install 'a'
|
270
|
+
end
|
271
|
+
|
272
|
+
env = "/\\S+/env" unless LibGems.win_platform?
|
273
|
+
|
274
|
+
assert_match %r|\A#!#{env} #{LibGems::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 = LibGems::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 = LibGems::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 = LibGems::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 = LibGems::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 LibGems::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 = LibGems::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
|
+
LibGems.source_index.remove_spec @a1.full_name
|
370
|
+
LibGems.source_index.remove_spec @a1_pre.full_name
|
371
|
+
|
372
|
+
Dir.chdir @tempdir do
|
373
|
+
e = assert_raises LibGems::InstallError do
|
374
|
+
inst = LibGems::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 = LibGems::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 = LibGems::DependencyInstaller.new :install_dir => gemhome2
|
407
|
+
inst.install 'a'
|
408
|
+
end
|
409
|
+
|
410
|
+
ENV['LIBGEMS_HOME'] = @gemhome
|
411
|
+
ENV['LIBGEMS_PATH'] = [@gemhome, gemhome2].join File::PATH_SEPARATOR
|
412
|
+
LibGems.clear_paths
|
413
|
+
|
414
|
+
Dir.chdir @tempdir do
|
415
|
+
inst = LibGems::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 = LibGems::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 = LibGems::DependencyInstaller.new
|
448
|
+
|
449
|
+
Dir.chdir @tempdir do
|
450
|
+
dep = LibGems::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 = LibGems::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 = LibGems::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
|
+
LibGems::Installer.new(@a1_gem).install
|
487
|
+
FileUtils.mv @a1_gem, @tempdir
|
488
|
+
inst = nil
|
489
|
+
|
490
|
+
Dir.chdir @tempdir do
|
491
|
+
inst = LibGems::DependencyInstaller.new
|
492
|
+
inst.install 'a'
|
493
|
+
end
|
494
|
+
|
495
|
+
assert_equal LibGems::SourceIndex.new(@a1.full_name => @a1),
|
496
|
+
LibGems::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 = LibGems::Security::HighSecurity
|
510
|
+
inst = LibGems::DependencyInstaller.new :security_policy => policy
|
511
|
+
|
512
|
+
e = assert_raises LibGems::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 = LibGems::DependencyInstaller.new :wrappers => false
|
528
|
+
inst.install 'a'
|
529
|
+
|
530
|
+
refute_match(%r|This file was generated by #{LibGems::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 = LibGems::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 = LibGems::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 = LibGems::DependencyInstaller.new
|
564
|
+
dep = LibGems::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 = LibGems::DependencyInstaller.new
|
573
|
+
dep = LibGems::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 = LibGems::DependencyInstaller.new
|
593
|
+
|
594
|
+
dependency = LibGems::Dependency.new('a', LibGems::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 = LibGems::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 = LibGems::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 = LibGems::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 = LibGems::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 = LibGems::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
|
+
|