libgems 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) 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 +113 -0
  6. data/lib/gauntlet_libgems.rb +50 -0
  7. data/lib/libgems.rb +1246 -0
  8. data/lib/libgems/builder.rb +102 -0
  9. data/lib/libgems/command.rb +534 -0
  10. data/lib/libgems/command_manager.rb +182 -0
  11. data/lib/libgems/commands/build_command.rb +53 -0
  12. data/lib/libgems/commands/cert_command.rb +86 -0
  13. data/lib/libgems/commands/check_command.rb +80 -0
  14. data/lib/libgems/commands/cleanup_command.rb +106 -0
  15. data/lib/libgems/commands/contents_command.rb +98 -0
  16. data/lib/libgems/commands/dependency_command.rb +195 -0
  17. data/lib/libgems/commands/environment_command.rb +133 -0
  18. data/lib/libgems/commands/fetch_command.rb +67 -0
  19. data/lib/libgems/commands/generate_index_command.rb +133 -0
  20. data/lib/libgems/commands/help_command.rb +172 -0
  21. data/lib/libgems/commands/install_command.rb +178 -0
  22. data/lib/libgems/commands/list_command.rb +35 -0
  23. data/lib/libgems/commands/lock_command.rb +110 -0
  24. data/lib/libgems/commands/mirror_command.rb +111 -0
  25. data/lib/libgems/commands/outdated_command.rb +33 -0
  26. data/lib/libgems/commands/owner_command.rb +75 -0
  27. data/lib/libgems/commands/pristine_command.rb +93 -0
  28. data/lib/libgems/commands/push_command.rb +56 -0
  29. data/lib/libgems/commands/query_command.rb +280 -0
  30. data/lib/libgems/commands/rdoc_command.rb +91 -0
  31. data/lib/libgems/commands/search_command.rb +31 -0
  32. data/lib/libgems/commands/server_command.rb +86 -0
  33. data/lib/libgems/commands/sources_command.rb +157 -0
  34. data/lib/libgems/commands/specification_command.rb +125 -0
  35. data/lib/libgems/commands/stale_command.rb +27 -0
  36. data/lib/libgems/commands/uninstall_command.rb +83 -0
  37. data/lib/libgems/commands/unpack_command.rb +121 -0
  38. data/lib/libgems/commands/update_command.rb +160 -0
  39. data/lib/libgems/commands/which_command.rb +86 -0
  40. data/lib/libgems/config_file.rb +345 -0
  41. data/lib/libgems/custom_require.rb +44 -0
  42. data/lib/libgems/defaults.rb +101 -0
  43. data/lib/libgems/dependency.rb +227 -0
  44. data/lib/libgems/dependency_installer.rb +286 -0
  45. data/lib/libgems/dependency_list.rb +208 -0
  46. data/lib/libgems/doc_manager.rb +242 -0
  47. data/lib/libgems/errors.rb +35 -0
  48. data/lib/libgems/exceptions.rb +91 -0
  49. data/lib/libgems/ext.rb +18 -0
  50. data/lib/libgems/ext/builder.rb +56 -0
  51. data/lib/libgems/ext/configure_builder.rb +25 -0
  52. data/lib/libgems/ext/ext_conf_builder.rb +24 -0
  53. data/lib/libgems/ext/rake_builder.rb +39 -0
  54. data/lib/libgems/format.rb +81 -0
  55. data/lib/libgems/gem_openssl.rb +92 -0
  56. data/lib/libgems/gem_path_searcher.rb +100 -0
  57. data/lib/libgems/gem_runner.rb +79 -0
  58. data/lib/libgems/gemcutter_utilities.rb +49 -0
  59. data/lib/libgems/indexer.rb +720 -0
  60. data/lib/libgems/install_update_options.rb +125 -0
  61. data/lib/libgems/installer.rb +604 -0
  62. data/lib/libgems/local_remote_options.rb +135 -0
  63. data/lib/libgems/old_format.rb +153 -0
  64. data/lib/libgems/package.rb +97 -0
  65. data/lib/libgems/package/f_sync_dir.rb +23 -0
  66. data/lib/libgems/package/tar_header.rb +266 -0
  67. data/lib/libgems/package/tar_input.rb +222 -0
  68. data/lib/libgems/package/tar_output.rb +144 -0
  69. data/lib/libgems/package/tar_reader.rb +106 -0
  70. data/lib/libgems/package/tar_reader/entry.rb +141 -0
  71. data/lib/libgems/package/tar_writer.rb +241 -0
  72. data/lib/libgems/package_task.rb +126 -0
  73. data/lib/libgems/platform.rb +183 -0
  74. data/lib/libgems/remote_fetcher.rb +414 -0
  75. data/lib/libgems/require_paths_builder.rb +18 -0
  76. data/lib/libgems/requirement.rb +153 -0
  77. data/lib/libgems/security.rb +814 -0
  78. data/lib/libgems/server.rb +872 -0
  79. data/lib/libgems/source_index.rb +597 -0
  80. data/lib/libgems/source_info_cache.rb +395 -0
  81. data/lib/libgems/source_info_cache_entry.rb +56 -0
  82. data/lib/libgems/spec_fetcher.rb +337 -0
  83. data/lib/libgems/specification.rb +1487 -0
  84. data/lib/libgems/test_utilities.rb +147 -0
  85. data/lib/libgems/text.rb +65 -0
  86. data/lib/libgems/uninstaller.rb +278 -0
  87. data/lib/libgems/user_interaction.rb +527 -0
  88. data/lib/libgems/validator.rb +240 -0
  89. data/lib/libgems/version.rb +316 -0
  90. data/lib/libgems/version_option.rb +65 -0
  91. data/lib/rbconfig/datadir.rb +20 -0
  92. data/test/bogussources.rb +8 -0
  93. data/test/data/gem-private_key.pem +27 -0
  94. data/test/data/gem-public_cert.pem +20 -0
  95. data/test/fake_certlib/openssl.rb +7 -0
  96. data/test/foo/discover.rb +0 -0
  97. data/test/gem_installer_test_case.rb +97 -0
  98. data/test/gem_package_tar_test_case.rb +132 -0
  99. data/test/gemutilities.rb +605 -0
  100. data/test/insure_session.rb +43 -0
  101. data/test/mockgemui.rb +56 -0
  102. data/test/plugin/exception/libgems_plugin.rb +2 -0
  103. data/test/plugin/load/libgems_plugin.rb +1 -0
  104. data/test/plugin/standarderror/libgems_plugin.rb +2 -0
  105. data/test/private_key.pem +27 -0
  106. data/test/public_cert.pem +20 -0
  107. data/test/rubygems_plugin.rb +21 -0
  108. data/test/simple_gem.rb +66 -0
  109. data/test/test_config.rb +12 -0
  110. data/test/test_gem.rb +780 -0
  111. data/test/test_gem_builder.rb +27 -0
  112. data/test/test_gem_command.rb +178 -0
  113. data/test/test_gem_command_manager.rb +207 -0
  114. data/test/test_gem_commands_build_command.rb +74 -0
  115. data/test/test_gem_commands_cert_command.rb +124 -0
  116. data/test/test_gem_commands_check_command.rb +18 -0
  117. data/test/test_gem_commands_contents_command.rb +156 -0
  118. data/test/test_gem_commands_dependency_command.rb +216 -0
  119. data/test/test_gem_commands_environment_command.rb +144 -0
  120. data/test/test_gem_commands_fetch_command.rb +76 -0
  121. data/test/test_gem_commands_generate_index_command.rb +135 -0
  122. data/test/test_gem_commands_install_command.rb +315 -0
  123. data/test/test_gem_commands_list_command.rb +36 -0
  124. data/test/test_gem_commands_lock_command.rb +68 -0
  125. data/test/test_gem_commands_mirror_command.rb +60 -0
  126. data/test/test_gem_commands_outdated_command.rb +40 -0
  127. data/test/test_gem_commands_owner_command.rb +105 -0
  128. data/test/test_gem_commands_pristine_command.rb +108 -0
  129. data/test/test_gem_commands_push_command.rb +81 -0
  130. data/test/test_gem_commands_query_command.rb +426 -0
  131. data/test/test_gem_commands_server_command.rb +59 -0
  132. data/test/test_gem_commands_sources_command.rb +209 -0
  133. data/test/test_gem_commands_specification_command.rb +139 -0
  134. data/test/test_gem_commands_stale_command.rb +38 -0
  135. data/test/test_gem_commands_uninstall_command.rb +83 -0
  136. data/test/test_gem_commands_unpack_command.rb +199 -0
  137. data/test/test_gem_commands_update_command.rb +207 -0
  138. data/test/test_gem_commands_which_command.rb +66 -0
  139. data/test/test_gem_config_file.rb +287 -0
  140. data/test/test_gem_dependency.rb +149 -0
  141. data/test/test_gem_dependency_installer.rb +661 -0
  142. data/test/test_gem_dependency_list.rb +230 -0
  143. data/test/test_gem_doc_manager.rb +31 -0
  144. data/test/test_gem_ext_configure_builder.rb +84 -0
  145. data/test/test_gem_ext_ext_conf_builder.rb +173 -0
  146. data/test/test_gem_ext_rake_builder.rb +81 -0
  147. data/test/test_gem_format.rb +70 -0
  148. data/test/test_gem_gem_path_searcher.rb +78 -0
  149. data/test/test_gem_gem_runner.rb +45 -0
  150. data/test/test_gem_gemcutter_utilities.rb +103 -0
  151. data/test/test_gem_indexer.rb +673 -0
  152. data/test/test_gem_install_update_options.rb +68 -0
  153. data/test/test_gem_installer.rb +857 -0
  154. data/test/test_gem_local_remote_options.rb +97 -0
  155. data/test/test_gem_package_tar_header.rb +130 -0
  156. data/test/test_gem_package_tar_input.rb +112 -0
  157. data/test/test_gem_package_tar_output.rb +97 -0
  158. data/test/test_gem_package_tar_reader.rb +46 -0
  159. data/test/test_gem_package_tar_reader_entry.rb +109 -0
  160. data/test/test_gem_package_tar_writer.rb +144 -0
  161. data/test/test_gem_package_task.rb +59 -0
  162. data/test/test_gem_platform.rb +264 -0
  163. data/test/test_gem_remote_fetcher.rb +740 -0
  164. data/test/test_gem_requirement.rb +292 -0
  165. data/test/test_gem_server.rb +356 -0
  166. data/test/test_gem_silent_ui.rb +113 -0
  167. data/test/test_gem_source_index.rb +461 -0
  168. data/test/test_gem_spec_fetcher.rb +410 -0
  169. data/test/test_gem_specification.rb +1334 -0
  170. data/test/test_gem_stream_ui.rb +218 -0
  171. data/test/test_gem_text.rb +43 -0
  172. data/test/test_gem_uninstaller.rb +146 -0
  173. data/test/test_gem_validator.rb +63 -0
  174. data/test/test_gem_version.rb +181 -0
  175. data/test/test_gem_version_option.rb +89 -0
  176. data/test/test_kernel.rb +59 -0
  177. metadata +402 -0
@@ -0,0 +1,68 @@
1
+ require File.expand_path('../gem_installer_test_case', __FILE__)
2
+ require 'libgems/install_update_options'
3
+ require 'libgems/command'
4
+
5
+ class TestGemInstallUpdateOptions < LibGemsInstallerTestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @cmd = LibGems::Command.new 'dummy', 'dummy'
11
+ @cmd.extend LibGems::InstallUpdateOptions
12
+ @cmd.add_install_update_options
13
+ end
14
+
15
+ def test_add_install_update_options
16
+ args = %w[-i /install_to --rdoc --ri -E -f -t -w -P HighSecurity
17
+ --ignore-dependencies --format-exec --include-dependencies]
18
+
19
+ assert @cmd.handles?(args)
20
+ end
21
+
22
+ def test_security_policy
23
+ @cmd.handle_options %w[-P HighSecurity]
24
+
25
+ assert_equal LibGems::Security::HighSecurity, @cmd.options[:security_policy]
26
+ end
27
+
28
+ def test_security_policy_unknown
29
+ @cmd.add_install_update_options
30
+
31
+ assert_raises OptionParser::InvalidArgument do
32
+ @cmd.handle_options %w[-P UnknownSecurity]
33
+ end
34
+ end
35
+
36
+ def test_user_install_enabled
37
+ @cmd.handle_options %w[--user-install]
38
+
39
+ assert @cmd.options[:user_install]
40
+
41
+ @installer = LibGems::Installer.new @gem, @cmd.options
42
+ @installer.install
43
+ assert File.exist?(File.join(LibGems.user_dir, 'gems'))
44
+ assert File.exist?(File.join(LibGems.user_dir, 'gems',
45
+ @spec.full_name))
46
+ end
47
+
48
+ def test_user_install_disabled_read_only
49
+ if win_platform?
50
+ skip('test_user_install_disabled_read_only test skipped on MS Windows')
51
+ else
52
+ @cmd.handle_options %w[--no-user-install]
53
+
54
+ refute @cmd.options[:user_install]
55
+
56
+ File.chmod 0755, @userhome
57
+ FileUtils.chmod 0000, @gemhome
58
+
59
+ assert_raises(LibGems::FilePermissionError) do
60
+ @installer = LibGems::Installer.new @gem, @cmd.options
61
+ end
62
+ end
63
+ ensure
64
+ FileUtils.chmod 0755, @gemhome
65
+ end
66
+
67
+ end
68
+
@@ -0,0 +1,857 @@
1
+ require File.expand_path('../gem_installer_test_case', __FILE__)
2
+
3
+ class TestGemInstaller < LibGemsInstallerTestCase
4
+
5
+ def test_app_script_text
6
+ util_make_exec '2', ''
7
+
8
+ expected = <<-EOF
9
+ #!#{LibGems.ruby}
10
+ #
11
+ # This file was generated by LibGems.
12
+ #
13
+ # The application 'a' is installed as part of a gem, and
14
+ # this file is here to facilitate running it.
15
+ #
16
+
17
+ require 'libgems'
18
+
19
+ version = \">= 0\"
20
+
21
+ if ARGV.first =~ /^_(.*)_$/ and LibGems::Version.correct? $1 then
22
+ version = $1
23
+ ARGV.shift
24
+ end
25
+
26
+ gem 'a', version
27
+ load LibGems.bin_path('a', 'my_exec', version)
28
+ EOF
29
+
30
+ wrapper = @installer.app_script_text 'my_exec'
31
+ assert_equal expected, wrapper
32
+ end
33
+
34
+ def test_build_extensions_none
35
+ use_ui @ui do
36
+ @installer.build_extensions
37
+ end
38
+
39
+ assert_equal '', @ui.output
40
+ assert_equal '', @ui.error
41
+
42
+ refute File.exist?('gem_make.out')
43
+ end
44
+
45
+ def test_build_extensions_extconf_bad
46
+ @spec.extensions << 'extconf.rb'
47
+
48
+ e = assert_raises LibGems::Installer::ExtensionBuildError do
49
+ use_ui @ui do
50
+ @installer.build_extensions
51
+ end
52
+ end
53
+
54
+ assert_match(/\AERROR: Failed to build gem native extension.$/, e.message)
55
+
56
+ assert_equal "Building native extensions. This could take a while...\n",
57
+ @ui.output
58
+ assert_equal '', @ui.error
59
+
60
+ gem_make_out = File.join @gemhome, 'gems', @spec.full_name, 'gem_make.out'
61
+ expected = <<-EOF
62
+ #{LibGems.ruby} extconf.rb
63
+ #{LibGems.ruby}: No such file or directory -- extconf.rb (LoadError)
64
+ EOF
65
+
66
+ assert_match %r%#{Regexp.escape LibGems.ruby} extconf\.rb%,
67
+ File.read(gem_make_out)
68
+ assert_match %r%#{Regexp.escape LibGems.ruby}: No such file%,
69
+ File.read(gem_make_out)
70
+ end
71
+
72
+ def test_build_extensions_unsupported
73
+ @spec.extensions << nil
74
+
75
+ e = assert_raises LibGems::Installer::ExtensionBuildError do
76
+ use_ui @ui do
77
+ @installer.build_extensions
78
+ end
79
+ end
80
+
81
+ assert_match(/^No builder for extension ''$/, e.message)
82
+
83
+ assert_equal "Building native extensions. This could take a while...\n",
84
+ @ui.output
85
+ assert_equal '', @ui.error
86
+
87
+ assert_equal "No builder for extension ''\n", File.read('gem_make.out')
88
+ ensure
89
+ FileUtils.rm_f 'gem_make.out'
90
+ end
91
+
92
+ def test_ensure_dependency
93
+ dep = LibGems::Dependency.new 'a', '>= 2'
94
+ assert @installer.ensure_dependency(@spec, dep)
95
+
96
+ dep = LibGems::Dependency.new 'b', '> 2'
97
+ e = assert_raises LibGems::InstallError do
98
+ @installer.ensure_dependency @spec, dep
99
+ end
100
+
101
+ assert_equal 'a requires b (> 2, runtime)', e.message
102
+ end
103
+
104
+ def test_extract_files
105
+ format = Object.new
106
+ def format.file_entries
107
+ [[{'size' => 7, 'mode' => 0400, 'path' => 'thefile'}, 'thefile']]
108
+ end
109
+
110
+ @installer.format = format
111
+
112
+ @installer.extract_files
113
+
114
+ thefile_path = File.join(util_gem_dir, 'thefile')
115
+ assert_equal 'thefile', File.read(thefile_path)
116
+
117
+ unless LibGems.win_platform? then
118
+ assert_equal 0400, File.stat(thefile_path).mode & 0777
119
+ end
120
+ end
121
+
122
+ def test_extract_files_bad_dest
123
+ @installer.gem_dir = 'somedir'
124
+ @installer.format = nil
125
+ e = assert_raises ArgumentError do
126
+ @installer.extract_files
127
+ end
128
+
129
+ assert_equal 'format required to extract from', e.message
130
+ end
131
+
132
+ def test_extract_files_relative
133
+ format = Object.new
134
+ def format.file_entries
135
+ [[{'size' => 10, 'mode' => 0644, 'path' => '../thefile'}, '../thefile']]
136
+ end
137
+
138
+ @installer.format = format
139
+
140
+ e = assert_raises LibGems::InstallError do
141
+ @installer.extract_files
142
+ end
143
+
144
+ assert_equal "attempt to install file into \"../thefile\" under #{util_gem_dir.inspect}",
145
+ e.message
146
+ assert_equal false, File.file?(File.join(@tempdir, '../thefile')),
147
+ "You may need to remove this file if you broke the test once"
148
+ end
149
+
150
+ def test_extract_files_absolute
151
+ format = Object.new
152
+ def format.file_entries
153
+ [[{'size' => 8, 'mode' => 0644, 'path' => '/thefile'}, '/thefile']]
154
+ end
155
+
156
+ @installer.format = format
157
+
158
+ e = assert_raises LibGems::InstallError do
159
+ @installer.extract_files
160
+ end
161
+
162
+ assert_equal 'attempt to install file into "/thefile"', e.message
163
+ assert_equal false, File.file?(File.join('/thefile')),
164
+ "You may need to remove this file if you broke the test once"
165
+ end
166
+
167
+ def test_generate_bin_bindir
168
+ @installer.wrappers = true
169
+
170
+ @spec.executables = ["my_exec"]
171
+ @spec.bindir = '.'
172
+
173
+ exec_file = @installer.formatted_program_filename "my_exec"
174
+ exec_path = File.join util_gem_dir(@spec.version), exec_file
175
+ File.open exec_path, 'w' do |f|
176
+ f.puts '#!/usr/bin/ruby'
177
+ end
178
+
179
+ @installer.gem_dir = util_gem_dir
180
+
181
+ @installer.generate_bin
182
+
183
+ assert_equal true, File.directory?(util_inst_bindir)
184
+ installed_exec = File.join(util_inst_bindir, "my_exec")
185
+ assert_equal true, File.exist?(installed_exec)
186
+ assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform?
187
+
188
+ wrapper = File.read installed_exec
189
+ assert_match %r|generated by #{LibGems::NAME}|, wrapper
190
+ end
191
+
192
+ def test_generate_bin_script
193
+ @installer.wrappers = true
194
+ util_make_exec
195
+ @installer.gem_dir = util_gem_dir
196
+
197
+ @installer.generate_bin
198
+ assert_equal true, File.directory?(util_inst_bindir)
199
+ installed_exec = File.join(util_inst_bindir, "my_exec")
200
+ assert_equal true, File.exist?(installed_exec)
201
+ assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform?
202
+
203
+ wrapper = File.read installed_exec
204
+ assert_match %r|generated by #{LibGems::NAME}|, wrapper
205
+ end
206
+
207
+ def test_generate_bin_script_format
208
+ @installer.format_executable = true
209
+ @installer.wrappers = true
210
+ util_make_exec
211
+ @installer.gem_dir = util_gem_dir
212
+
213
+ LibGems::Installer.exec_format = 'foo-%s-bar'
214
+ @installer.generate_bin
215
+ assert_equal true, File.directory?(util_inst_bindir)
216
+ installed_exec = File.join util_inst_bindir, 'foo-my_exec-bar'
217
+ assert_equal true, File.exist?(installed_exec)
218
+ ensure
219
+ LibGems::Installer.exec_format = nil
220
+ end
221
+
222
+ def test_generate_bin_script_format_disabled
223
+ @installer.wrappers = true
224
+ util_make_exec
225
+ @installer.gem_dir = util_gem_dir
226
+
227
+ LibGems::Installer.exec_format = 'foo-%s-bar'
228
+ @installer.generate_bin
229
+ assert_equal true, File.directory?(util_inst_bindir)
230
+ installed_exec = File.join util_inst_bindir, 'my_exec'
231
+ assert_equal true, File.exist?(installed_exec)
232
+ ensure
233
+ LibGems::Installer.exec_format = nil
234
+ end
235
+
236
+ def test_generate_bin_script_install_dir
237
+ @installer.wrappers = true
238
+ @spec.executables = ["my_exec"]
239
+
240
+ gem_dir = File.join "#{@gemhome}2", 'gems', @spec.full_name
241
+ gem_bindir = File.join gem_dir, 'bin'
242
+ FileUtils.mkdir_p gem_bindir
243
+ File.open File.join(gem_bindir, "my_exec"), 'w' do |f|
244
+ f.puts "#!/bin/ruby"
245
+ end
246
+
247
+ @installer.gem_home = "#{@gemhome}2"
248
+ @installer.gem_dir = gem_dir
249
+
250
+ @installer.generate_bin
251
+
252
+ installed_exec = File.join("#{@gemhome}2", 'bin', 'my_exec')
253
+ assert_equal true, File.exist?(installed_exec)
254
+ assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform?
255
+
256
+ wrapper = File.read installed_exec
257
+ assert_match %r|generated by #{LibGems::NAME}|, wrapper
258
+ end
259
+
260
+ def test_generate_bin_script_no_execs
261
+ @installer.wrappers = true
262
+ @installer.generate_bin
263
+ assert_equal false, File.exist?(util_inst_bindir)
264
+ end
265
+
266
+ def test_generate_bin_script_no_perms
267
+ @installer.wrappers = true
268
+ util_make_exec
269
+
270
+ Dir.mkdir util_inst_bindir
271
+
272
+ if win_platform?
273
+ skip('test_generate_bin_script_no_perms skipped on MS Windows')
274
+ else
275
+ File.chmod 0000, util_inst_bindir
276
+
277
+ assert_raises LibGems::FilePermissionError do
278
+ @installer.generate_bin
279
+ end
280
+ end
281
+ ensure
282
+ File.chmod 0700, util_inst_bindir unless $DEBUG
283
+ end
284
+
285
+ def test_generate_bin_script_no_shebang
286
+ @installer.wrappers = true
287
+ @spec.executables = ["my_exec"]
288
+
289
+ gem_dir = File.join @gemhome, 'gems', @spec.full_name
290
+ gem_bindir = File.join gem_dir, 'bin'
291
+ FileUtils.mkdir_p gem_bindir
292
+ File.open File.join(gem_bindir, "my_exec"), 'w' do |f|
293
+ f.puts "blah blah blah"
294
+ end
295
+
296
+ @installer.generate_bin
297
+
298
+ installed_exec = File.join @gemhome, 'bin', 'my_exec'
299
+ assert_equal true, File.exist?(installed_exec)
300
+ assert_equal 0100755, File.stat(installed_exec).mode unless win_platform?
301
+
302
+ wrapper = File.read installed_exec
303
+ assert_match %r|generated by #{LibGems::NAME}|, wrapper
304
+ # HACK some gems don't have #! in their executables, restore 2008/06
305
+ #assert_no_match %r|generated by #{LibGems::NAME}|, wrapper
306
+ end
307
+
308
+ def test_generate_bin_script_wrappers
309
+ @installer.wrappers = true
310
+ util_make_exec
311
+ @installer.gem_dir = util_gem_dir
312
+ installed_exec = File.join(util_inst_bindir, "my_exec")
313
+
314
+ real_exec = File.join util_gem_dir, 'bin', 'my_exec'
315
+
316
+ # fake --no-wrappers for previous install
317
+ unless LibGems.win_platform? then
318
+ FileUtils.mkdir_p File.dirname(installed_exec)
319
+ FileUtils.ln_s real_exec, installed_exec
320
+ end
321
+
322
+ @installer.generate_bin
323
+ assert_equal true, File.directory?(util_inst_bindir)
324
+ assert_equal true, File.exist?(installed_exec)
325
+ assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform?
326
+
327
+ assert_match %r|generated by #{LibGems::NAME}|, File.read(installed_exec)
328
+
329
+ refute_match %r|generated by #{LibGems::NAME}|, File.read(real_exec),
330
+ 'real executable overwritten'
331
+ end
332
+
333
+ def test_generate_bin_symlink
334
+ return if win_platform? #Windows FS do not support symlinks
335
+
336
+ @installer.wrappers = false
337
+ util_make_exec
338
+ @installer.gem_dir = util_gem_dir
339
+
340
+ @installer.generate_bin
341
+ assert_equal true, File.directory?(util_inst_bindir)
342
+ installed_exec = File.join(util_inst_bindir, "my_exec")
343
+ assert_equal true, File.symlink?(installed_exec)
344
+ assert_equal(File.join(util_gem_dir, "bin", "my_exec"),
345
+ File.readlink(installed_exec))
346
+ end
347
+
348
+ def test_generate_bin_symlink_no_execs
349
+ @installer.wrappers = false
350
+ @installer.generate_bin
351
+ assert_equal false, File.exist?(util_inst_bindir)
352
+ end
353
+
354
+ def test_generate_bin_symlink_no_perms
355
+ @installer.wrappers = false
356
+ util_make_exec
357
+ @installer.gem_dir = util_gem_dir
358
+
359
+ Dir.mkdir util_inst_bindir
360
+
361
+ if win_platform?
362
+ skip('test_generate_bin_symlink_no_perms skipped on MS Windows')
363
+ else
364
+ File.chmod 0000, util_inst_bindir
365
+
366
+ assert_raises LibGems::FilePermissionError do
367
+ @installer.generate_bin
368
+ end
369
+ end
370
+ ensure
371
+ File.chmod 0700, util_inst_bindir unless $DEBUG
372
+ end
373
+
374
+ def test_generate_bin_symlink_update_newer
375
+ return if win_platform? #Windows FS do not support symlinks
376
+
377
+ @installer.wrappers = false
378
+ util_make_exec
379
+ @installer.gem_dir = util_gem_dir
380
+
381
+ @installer.generate_bin
382
+ installed_exec = File.join(util_inst_bindir, "my_exec")
383
+ assert_equal(File.join(util_gem_dir, "bin", "my_exec"),
384
+ File.readlink(installed_exec))
385
+
386
+ @spec = LibGems::Specification.new do |s|
387
+ s.files = ['lib/code.rb']
388
+ s.name = "a"
389
+ s.version = "3"
390
+ s.summary = "summary"
391
+ s.description = "desc"
392
+ s.require_path = 'lib'
393
+ end
394
+
395
+ util_make_exec '3'
396
+ @installer.gem_dir = File.join util_gem_dir('3')
397
+ @installer.generate_bin
398
+ installed_exec = File.join(util_inst_bindir, "my_exec")
399
+ assert_equal(File.join(util_gem_bindir('3'), "my_exec"),
400
+ File.readlink(installed_exec),
401
+ "Ensure symlink moved to latest version")
402
+ end
403
+
404
+ def test_generate_bin_symlink_update_older
405
+ return if win_platform? #Windows FS do not support symlinks
406
+
407
+ @installer.wrappers = false
408
+ util_make_exec
409
+ @installer.gem_dir = util_gem_dir
410
+
411
+ @installer.generate_bin
412
+ installed_exec = File.join(util_inst_bindir, "my_exec")
413
+ assert_equal(File.join(util_gem_dir, "bin", "my_exec"),
414
+ File.readlink(installed_exec))
415
+
416
+ spec = LibGems::Specification.new do |s|
417
+ s.files = ['lib/code.rb']
418
+ s.name = "a"
419
+ s.version = "1"
420
+ s.summary = "summary"
421
+ s.description = "desc"
422
+ s.require_path = 'lib'
423
+ end
424
+
425
+ util_make_exec '1'
426
+ @installer.gem_dir = util_gem_dir('1')
427
+ @installer.spec = spec
428
+
429
+ @installer.generate_bin
430
+
431
+ installed_exec = File.join(util_inst_bindir, "my_exec")
432
+ assert_equal(File.join(util_gem_dir('2'), "bin", "my_exec"),
433
+ File.readlink(installed_exec),
434
+ "Ensure symlink not moved")
435
+ end
436
+
437
+ def test_generate_bin_symlink_update_remove_wrapper
438
+ return if win_platform? #Windows FS do not support symlinks
439
+
440
+ @installer.wrappers = true
441
+ util_make_exec
442
+ @installer.gem_dir = util_gem_dir
443
+
444
+ @installer.generate_bin
445
+ installed_exec = File.join(util_inst_bindir, "my_exec")
446
+ assert_equal true, File.exist?(installed_exec)
447
+
448
+ @spec = LibGems::Specification.new do |s|
449
+ s.files = ['lib/code.rb']
450
+ s.name = "a"
451
+ s.version = "3"
452
+ s.summary = "summary"
453
+ s.description = "desc"
454
+ s.require_path = 'lib'
455
+ end
456
+
457
+ @installer.wrappers = false
458
+ util_make_exec '3'
459
+ @installer.gem_dir = util_gem_dir '3'
460
+ @installer.generate_bin
461
+ installed_exec = File.join(util_inst_bindir, "my_exec")
462
+ assert_equal(File.join(util_gem_dir('3'), "bin", "my_exec"),
463
+ File.readlink(installed_exec),
464
+ "Ensure symlink moved to latest version")
465
+ end
466
+
467
+ def test_generate_bin_symlink_win32
468
+ old_win_platform = LibGems.win_platform?
469
+ LibGems.win_platform = true
470
+ @installer.wrappers = false
471
+ util_make_exec
472
+ @installer.gem_dir = util_gem_dir
473
+
474
+ use_ui @ui do
475
+ @installer.generate_bin
476
+ end
477
+
478
+ assert_equal true, File.directory?(util_inst_bindir)
479
+ installed_exec = File.join(util_inst_bindir, "my_exec")
480
+ assert_equal true, File.exist?(installed_exec)
481
+
482
+ assert_match(/Unable to use symlinks on Windows, installing wrapper/i,
483
+ @ui.error)
484
+
485
+ wrapper = File.read installed_exec
486
+ assert_match(/generated by #{LibGems::NAME}/, wrapper)
487
+ ensure
488
+ LibGems.win_platform = old_win_platform
489
+ end
490
+
491
+ def test_generate_bin_uses_default_shebang
492
+ return if win_platform? #Windows FS do not support symlinks
493
+
494
+ @installer.wrappers = true
495
+ util_make_exec
496
+
497
+ @installer.generate_bin
498
+
499
+ default_shebang = LibGems.ruby
500
+ shebang_line = open("#{@gemhome}/bin/my_exec") { |f| f.readlines.first }
501
+ assert_match(/\A#!/, shebang_line)
502
+ assert_match(/#{default_shebang}/, shebang_line)
503
+ end
504
+
505
+ def test_initialize
506
+ spec = quick_gem 'a' do |s| s.platform = LibGems::Platform.new 'mswin32' end
507
+ gem = File.join @tempdir, spec.file_name
508
+
509
+ Dir.mkdir util_inst_bindir
510
+ util_build_gem spec
511
+ FileUtils.mv File.join(@gemhome, 'cache', spec.file_name),
512
+ @tempdir
513
+
514
+ installer = LibGems::Installer.new gem
515
+
516
+ assert_equal File.join(@gemhome, 'gems', spec.full_name), installer.gem_dir
517
+ end
518
+
519
+ def test_install
520
+ Dir.mkdir util_inst_bindir
521
+ util_setup_gem
522
+
523
+ cache_file = File.join @gemhome, 'cache', @spec.file_name
524
+
525
+ LibGems.pre_install do |installer|
526
+ assert !File.exist?(cache_file), 'cache file should not exist yet'
527
+ end
528
+
529
+ LibGems.post_install do |installer|
530
+ assert File.exist?(cache_file), 'cache file should exist'
531
+ end
532
+
533
+ build_rake_in do
534
+ use_ui @ui do
535
+ assert_equal @spec, @installer.install
536
+ end
537
+ end
538
+
539
+ gemdir = File.join @gemhome, 'gems', @spec.full_name
540
+ assert File.exist?(gemdir)
541
+
542
+ exe = File.join(gemdir, 'bin', 'executable')
543
+ assert File.exist?(exe)
544
+ exe_mode = File.stat(exe).mode & 0111
545
+ assert_equal 0111, exe_mode, "0%o" % exe_mode unless win_platform?
546
+
547
+ assert File.exist?(File.join(gemdir, 'lib', 'code.rb'))
548
+
549
+ assert File.exist?(File.join(gemdir, 'ext', 'a', 'Rakefile'))
550
+
551
+ spec_file = File.join(@gemhome, 'specifications', @spec.spec_name)
552
+
553
+ assert_equal spec_file, @spec.loaded_from
554
+ assert File.exist?(spec_file)
555
+
556
+ assert_same @installer, @pre_install_hook_arg
557
+ assert_same @installer, @post_install_hook_arg
558
+ end
559
+
560
+ def test_install_bad_gem
561
+ gem = nil
562
+
563
+ use_ui @ui do
564
+ Dir.chdir @tempdir do LibGems::Builder.new(@spec).build end
565
+ gem = File.join @tempdir, @spec.file_name
566
+ end
567
+
568
+ gem_data = File.open gem, 'rb' do |fp| fp.read 1024 end
569
+ File.open gem, 'wb' do |fp| fp.write gem_data end
570
+
571
+ e = assert_raises LibGems::InstallError do
572
+ use_ui @ui do
573
+ @installer = LibGems::Installer.new gem
574
+ @installer.install
575
+ end
576
+ end
577
+
578
+ assert_equal "invalid gem format for #{gem}", e.message
579
+ end
580
+
581
+ def test_install_check_dependencies
582
+ @spec.add_dependency 'b', '> 5'
583
+ util_setup_gem
584
+
585
+ use_ui @ui do
586
+ assert_raises LibGems::InstallError do
587
+ @installer.install
588
+ end
589
+ end
590
+ end
591
+
592
+ def test_install_check_dependencies_install_dir
593
+ gemhome2 = "#{@gemhome}2"
594
+ @spec.add_dependency 'b'
595
+
596
+ b2 = quick_gem 'b', 2
597
+
598
+ FileUtils.mv @gemhome, gemhome2
599
+ LibGems.source_index.gems.delete b2.full_name
600
+ source_index = LibGems::SourceIndex.from_gems_in File.join(gemhome2,
601
+ 'specifications')
602
+
603
+ util_setup_gem
604
+
605
+ @installer = LibGems::Installer.new @gem, :install_dir => gemhome2,
606
+ :source_index => source_index
607
+
608
+ build_rake_in do
609
+ use_ui @ui do
610
+ @installer.install
611
+ end
612
+ end
613
+
614
+ assert File.exist?(File.join(gemhome2, 'gems', @spec.full_name))
615
+ end
616
+
617
+ def test_install_force
618
+ use_ui @ui do
619
+ installer = LibGems::Installer.new old_ruby_required, :force => true
620
+ installer.install
621
+ end
622
+
623
+ gem_dir = File.join(@gemhome, 'gems', 'old_ruby_required-1')
624
+ assert File.exist?(gem_dir)
625
+ end
626
+
627
+ def test_install_ignore_dependencies
628
+ Dir.mkdir util_inst_bindir
629
+ @spec.add_dependency 'b', '> 5'
630
+ util_setup_gem
631
+ @installer.ignore_dependencies = true
632
+
633
+ build_rake_in do
634
+ use_ui @ui do
635
+ assert_equal @spec, @installer.install
636
+ end
637
+ end
638
+
639
+ gemdir = File.join @gemhome, 'gems', @spec.full_name
640
+ assert File.exist?(gemdir)
641
+
642
+ exe = File.join(gemdir, 'bin', 'executable')
643
+ assert File.exist?(exe)
644
+ exe_mode = File.stat(exe).mode & 0111
645
+ assert_equal 0111, exe_mode, "0%o" % exe_mode unless win_platform?
646
+ assert File.exist?(File.join(gemdir, 'lib', 'code.rb'))
647
+
648
+ assert File.exist?(File.join(@gemhome, 'specifications', @spec.spec_name))
649
+ end
650
+
651
+ def test_install_missing_dirs
652
+ FileUtils.rm_f File.join(LibGems.dir, 'cache')
653
+ FileUtils.rm_f File.join(LibGems.dir, 'docs')
654
+ FileUtils.rm_f File.join(LibGems.dir, 'specifications')
655
+
656
+ use_ui @ui do
657
+ Dir.chdir @tempdir do LibGems::Builder.new(@spec).build end
658
+ gem = File.join @tempdir, @spec.file_name
659
+
660
+ @installer.install
661
+ end
662
+
663
+ File.directory? File.join(LibGems.dir, 'cache')
664
+ File.directory? File.join(LibGems.dir, 'docs')
665
+ File.directory? File.join(LibGems.dir, 'specifications')
666
+
667
+ assert File.exist?(File.join(@gemhome, 'cache', @spec.file_name))
668
+ assert File.exist?(File.join(@gemhome, 'specifications', @spec.spec_name))
669
+ end
670
+
671
+ def test_install_with_message
672
+ @spec.post_install_message = 'I am a shiny gem!'
673
+
674
+ use_ui @ui do
675
+ Dir.chdir @tempdir do LibGems::Builder.new(@spec).build end
676
+
677
+ @installer.install
678
+ end
679
+
680
+ assert_match %r|I am a shiny gem!|, @ui.output
681
+ end
682
+
683
+ def test_install_wrong_ruby_version
684
+ use_ui @ui do
685
+ installer = LibGems::Installer.new old_ruby_required
686
+ e = assert_raises LibGems::InstallError do
687
+ installer.install
688
+ end
689
+ assert_equal 'old_ruby_required requires Ruby version = 1.4.6.',
690
+ e.message
691
+ end
692
+ end
693
+
694
+ def test_install_wrong_rubygems_version
695
+ spec = quick_gem 'old_rubygems_required', '1' do |s|
696
+ s.required_rubygems_version = '< 0'
697
+ end
698
+
699
+ util_build_gem spec
700
+
701
+ gem = File.join @gemhome, 'cache', spec.file_name
702
+
703
+ use_ui @ui do
704
+ @installer = LibGems::Installer.new gem
705
+ e = assert_raises LibGems::InstallError do
706
+ @installer.install
707
+ end
708
+ assert_equal "old_rubygems_required requires #{LibGems::NAME} version < 0. " +
709
+ "Try 'gem update --system' to update #{LibGems::NAME} itself.", e.message
710
+ end
711
+ end
712
+
713
+ def test_installation_satisfies_dependency_eh
714
+ dep = LibGems::Dependency.new 'a', '>= 2'
715
+ assert @installer.installation_satisfies_dependency?(dep)
716
+
717
+ dep = LibGems::Dependency.new 'a', '> 2'
718
+ refute @installer.installation_satisfies_dependency?(dep)
719
+ end
720
+
721
+ def test_shebang
722
+ util_make_exec '2', "#!/usr/bin/ruby"
723
+
724
+ shebang = @installer.shebang 'my_exec'
725
+
726
+ assert_equal "#!#{LibGems.ruby}", shebang
727
+ end
728
+
729
+ def test_shebang_arguments
730
+ util_make_exec '2', "#!/usr/bin/ruby -ws"
731
+
732
+ shebang = @installer.shebang 'my_exec'
733
+
734
+ assert_equal "#!#{LibGems.ruby} -ws", shebang
735
+ end
736
+
737
+ def test_shebang_empty
738
+ util_make_exec '2', ''
739
+
740
+ shebang = @installer.shebang 'my_exec'
741
+ assert_equal "#!#{LibGems.ruby}", shebang
742
+ end
743
+
744
+ def test_shebang_env
745
+ util_make_exec '2', "#!/usr/bin/env ruby"
746
+
747
+ shebang = @installer.shebang 'my_exec'
748
+
749
+ assert_equal "#!#{LibGems.ruby}", shebang
750
+ end
751
+
752
+ def test_shebang_env_arguments
753
+ util_make_exec '2', "#!/usr/bin/env ruby -ws"
754
+
755
+ shebang = @installer.shebang 'my_exec'
756
+
757
+ assert_equal "#!#{LibGems.ruby} -ws", shebang
758
+ end
759
+
760
+ def test_shebang_env_shebang
761
+ util_make_exec '2', ''
762
+ @installer.env_shebang = true
763
+
764
+ shebang = @installer.shebang 'my_exec'
765
+
766
+ env_shebang = "/usr/bin/env" unless LibGems.win_platform?
767
+
768
+ assert_equal("#!#{env_shebang} #{LibGems::ConfigMap[:ruby_install_name]}",
769
+ shebang)
770
+ end
771
+
772
+ def test_shebang_nested
773
+ util_make_exec '2', "#!/opt/local/ruby/bin/ruby"
774
+
775
+ shebang = @installer.shebang 'my_exec'
776
+
777
+ assert_equal "#!#{LibGems.ruby}", shebang
778
+ end
779
+
780
+ def test_shebang_nested_arguments
781
+ util_make_exec '2', "#!/opt/local/ruby/bin/ruby -ws"
782
+
783
+ shebang = @installer.shebang 'my_exec'
784
+
785
+ assert_equal "#!#{LibGems.ruby} -ws", shebang
786
+ end
787
+
788
+ def test_shebang_version
789
+ util_make_exec '2', "#!/usr/bin/ruby18"
790
+
791
+ shebang = @installer.shebang 'my_exec'
792
+
793
+ assert_equal "#!#{LibGems.ruby}", shebang
794
+ end
795
+
796
+ def test_shebang_version_arguments
797
+ util_make_exec '2', "#!/usr/bin/ruby18 -ws"
798
+
799
+ shebang = @installer.shebang 'my_exec'
800
+
801
+ assert_equal "#!#{LibGems.ruby} -ws", shebang
802
+ end
803
+
804
+ def test_shebang_version_env
805
+ util_make_exec '2', "#!/usr/bin/env ruby18"
806
+
807
+ shebang = @installer.shebang 'my_exec'
808
+
809
+ assert_equal "#!#{LibGems.ruby}", shebang
810
+ end
811
+
812
+ def test_shebang_version_env_arguments
813
+ util_make_exec '2', "#!/usr/bin/env ruby18 -ws"
814
+
815
+ shebang = @installer.shebang 'my_exec'
816
+
817
+ assert_equal "#!#{LibGems.ruby} -ws", shebang
818
+ end
819
+
820
+ def test_unpack
821
+ util_setup_gem
822
+
823
+ dest = File.join @gemhome, 'gems', @spec.full_name
824
+
825
+ @installer.unpack dest
826
+
827
+ assert File.exist?(File.join(dest, 'lib', 'code.rb'))
828
+ assert File.exist?(File.join(dest, 'bin', 'executable'))
829
+ end
830
+
831
+ def test_write_spec
832
+ spec_dir = File.join @gemhome, 'specifications'
833
+ spec_file = File.join spec_dir, @spec.spec_name
834
+ FileUtils.rm spec_file
835
+ refute File.exist?(spec_file)
836
+
837
+ @installer.spec = @spec
838
+ @installer.gem_home = @gemhome
839
+
840
+ @installer.write_spec
841
+
842
+ assert File.exist?(spec_file)
843
+ assert_equal @spec, LibGems.gemspec_eval(File.read(spec_file))
844
+ end
845
+
846
+ def old_ruby_required
847
+ spec = quick_gem 'old_ruby_required', '1' do |s|
848
+ s.required_ruby_version = '= 1.4.6'
849
+ end
850
+
851
+ util_build_gem spec
852
+
853
+ File.join @gemhome, 'cache', spec.file_name
854
+ end
855
+
856
+ end
857
+