slimgems 1.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,43 @@
1
+ require 'rubygems'
2
+
3
+ def install_session
4
+ path_to_gem = File.join("redist", "session.gem")
5
+ begin
6
+ Gem::Installer.new(path_to_gem).install
7
+ rescue Errno::EACCES => ex
8
+ puts
9
+ puts "*****************************************************************"
10
+ puts "Unable to install Gem 'Session'."
11
+ puts "Reason: #{ex.message}"
12
+ puts "Try running:"
13
+ puts
14
+ puts " gem -Li #{path_to_gem}"
15
+ puts
16
+ puts "with the appropriate admin privileges."
17
+ puts "*****************************************************************"
18
+ puts
19
+ exit
20
+ end
21
+ gem 'session'
22
+ end
23
+
24
+ begin
25
+ require 'session'
26
+ rescue LoadError => e
27
+ puts
28
+ puts "Required Gem 'Session' missing."
29
+ puts "We can attempt to install from the #{Gem::NAME} Distribution,"
30
+ puts "but installation may require admin privileges on your system."
31
+ puts
32
+ print "Install now from #{Gem::NAME} distribution? [Yn]"
33
+ answer = gets
34
+ if(answer =~ /^y/i || answer =~ /^[^a-zA-Z0-9]$/) then
35
+ install_session
36
+ puts
37
+ puts "Retry running the functional tests."
38
+ exit(0)
39
+ else
40
+ puts "Test cancelled...quitting"
41
+ exit(1)
42
+ end
43
+ end
@@ -0,0 +1,56 @@
1
+ require 'stringio'
2
+ require 'rubygems/user_interaction'
3
+
4
+ class MockGemUi < Gem::StreamUI
5
+ class TermError < RuntimeError; end
6
+
7
+ module TTY
8
+
9
+ attr_accessor :tty
10
+
11
+ def tty?()
12
+ @tty = true unless defined?(@tty)
13
+ @tty
14
+ end
15
+
16
+ end
17
+
18
+ def initialize(input = "")
19
+ ins = StringIO.new input
20
+ outs = StringIO.new
21
+ errs = StringIO.new
22
+
23
+ ins.extend TTY
24
+ outs.extend TTY
25
+ errs.extend TTY
26
+
27
+ super ins, outs, errs
28
+
29
+ @terminated = false
30
+ end
31
+
32
+ def input
33
+ @ins.string
34
+ end
35
+
36
+ def output
37
+ @outs.string
38
+ end
39
+
40
+ def error
41
+ @errs.string
42
+ end
43
+
44
+ def terminated?
45
+ @terminated
46
+ end
47
+
48
+ def terminate_interaction(status=0)
49
+ @terminated = true
50
+
51
+ raise TermError unless status == 0
52
+ raise Gem::SystemExitException, status
53
+ end
54
+
55
+ end
56
+
@@ -0,0 +1,2 @@
1
+ TestGem::TEST_PLUGIN_EXCEPTION = :loaded
2
+ raise Exception.new('boom')
@@ -0,0 +1 @@
1
+ TestGem::TEST_PLUGIN_LOAD = :loaded
@@ -0,0 +1,2 @@
1
+ TestGem::TEST_PLUGIN_STANDARDERROR = :loaded
2
+ raise StandardError.new('boom')
@@ -0,0 +1,27 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIEpAIBAAKCAQEAm24C6xixiAxO+i1f3L8XRMwrmLkt6BvT60mZ7g8HsklH3af7
3
+ KNHA6vo/G6sujs2UsNO4HY8BTEneiVOXXWQlcsJ+Z5wEPlIu4zFueAmLefx+n9lE
4
+ ulNIUDoyUenKX4spoMRnX8k4lXL05ho/6JFq0JdDY2DmAaQ4vvTz5mh9kZiybtHQ
5
+ fzcpbA51uY+sjdQRCPDHyUUfh0SmWJlLYMwcBdVeCiGUPBLi+iP5x1btO4uiJK6Q
6
+ IMaV1H3SUCYtKGQKl7qwFd8k8ZBcHYOtmK61tupg3vqWQc0em6SxPj5lws8+1MVK
7
+ twBNIDx24jF4ntxBRNKMZ7FN5SHbobAgDYkPAQIDAQABAoIBAGQilgK8X/PUajVH
8
+ clEXU3hhSV0VQHwfIYKeYms6h6zXBVPKW0dLC0zXeDztJgueasMZQ67XaPCrTpGO
9
+ px/l2zJ6F1HM8/bqn4aDXDY9f/xRLYryQRMBgL8fHzgitNylHWaT4j2Vt7yg2SI9
10
+ mxrMRNKqASJPVR+Nm3l6+n9gpjVb99wEucWplPPHI6KhXLYPZOqSwt+zaH5roz3k
11
+ UQmMs0Bs4hF1SzVl0n+KNoXHOwswVrmBWXgWvm2OhnwY2e26jfejc8toJc/ShAJ7
12
+ C9exnrdimcgEKbd22Sum4G00CDYhcrG5LHHqkgwifcAEVctrvBZBZHGgpxlO8a8U
13
+ eF2Vr7kCgYEAykdrBlzp7Fn9xzUInBQ3NXTTYAq51lpuJdmHQmPuTSY0buoHkd9f
14
+ xbUCZ2qR9QAesrx4hI0qGLetc8IOKDoWx2rPepCCvO3Kx61o1SB5fAvBue03qVoq
15
+ HqACX3Uk24Em8zAz9xuP13ETH/wU7sUbUxRHMCre6ZDmlxn4g5l+Nl8CgYEAxLVl
16
+ 22yBx0dfRr3UsHY9rxll2gIlnfnYfiJzq8wetzt/TfztRV5ILz7FyWqL5d7IoqkA
17
+ fT2V4HAasRJASnKohwJe7z5M/H2ExwkGNFvY+jefb2CoUl5WouK9AlhbqBk3zmHi
18
+ sY5GqQkAp/kHMntEin+sErJw6mkgAGdser3a9p8CgYEAqi31w++tunRnxw4+RRnY
19
+ 7Pdx0k6T1NxV6TAe1ONAHNY0rM/mOHqml65W7GzDiU1lhlh8SIB/VzZJDqfHw15D
20
+ xdh94A7uf0bMILwrA4wDyTIW9Xa3Kpq57vQNqwPiU25QN69pOM+Ob+IpBfLOJafc
21
+ +kOINOUMj5Kh/aQS6Zzci58CgYEAk24dlFKEBjbRCvU2FrfYTYcsljPru7ZJc2gg
22
+ 588J6m0WYf5CWy5pzbcviGFpzvSlzXv7GOLylQ+QgcxbETFUbDPzsT4xd0AgJwj1
23
+ dIKuYgMUZOa94VZBer2TydEtiRS1heJJhKhM/1329u4nXceTvHYqIq1JAfeee48I
24
+ eAoZtaMCgYBz1FjWFQnMTD5nmyPEEZneoBPAR5+9jwOps+IYOoHtazoMFszzd0qo
25
+ JZW3Ihn9KRrVSxfFApKS/ZwjiZ+tJUk7DE/v/0l0sszefY7s8b0pL1lpeZSoL71e
26
+ QoG1WLXUiDV3BRlmyOAF1h3p12KRTLgwubN51ajECwcs3QwE+ZT8Gg==
27
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,20 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
3
+ YWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu
4
+ ZXQwHhcNMDcxMjIxMDIwNDE0WhcNMDgxMjIwMDIwNDE0WjBBMRAwDgYDVQQDDAdk
5
+ cmJyYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZ
6
+ FgNuZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCbbgLrGLGIDE76
7
+ LV/cvxdEzCuYuS3oG9PrSZnuDweySUfdp/so0cDq+j8bqy6OzZSw07gdjwFMSd6J
8
+ U5ddZCVywn5nnAQ+Ui7jMW54CYt5/H6f2US6U0hQOjJR6cpfiymgxGdfyTiVcvTm
9
+ Gj/okWrQl0NjYOYBpDi+9PPmaH2RmLJu0dB/NylsDnW5j6yN1BEI8MfJRR+HRKZY
10
+ mUtgzBwF1V4KIZQ8EuL6I/nHVu07i6IkrpAgxpXUfdJQJi0oZAqXurAV3yTxkFwd
11
+ g62YrrW26mDe+pZBzR6bpLE+PmXCzz7UxUq3AE0gPHbiMXie3EFE0oxnsU3lIduh
12
+ sCANiQ8BAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
13
+ BBS5k4Z75VSpdM0AclG2UvzFA/VW5DANBgkqhkiG9w0BAQUFAAOCAQEAHagT4lfX
14
+ kP/hDaiwGct7XPuVGbrOsKRVD59FF5kETBxEc9UQ1clKWngf8JoVuEoKD774dW19
15
+ bU0GOVWO+J6FMmT/Cp7nuFJ79egMf/gy4gfUfQMuvfcr6DvZUPIs9P/TlK59iMYF
16
+ DIOQ3DxdF3rMzztNUCizN4taVscEsjCcgW6WkUJnGdqlu3OHWpQxZBJkBTjPCoc6
17
+ UW6on70SFPmAy/5Cq0OJNGEWBfgD9q7rrs/X8GGwUWqXb85RXnUVi/P8Up75E0ag
18
+ 14jEc90kN+C7oI/AGCBN0j6JnEtYIEJZibjjDJTSMWlUKKkj30kq7hlUC2CepJ4v
19
+ x52qPcexcYZR7w==
20
+ -----END CERTIFICATE-----
@@ -0,0 +1,21 @@
1
+ require 'rubygems/command_manager'
2
+
3
+ ##
4
+ # This is an example of exactly what NOT to do.
5
+ #
6
+ # DO NOT include code like this in your rubygems_plugin.rb
7
+
8
+ class Gem::Commands::InterruptCommand < Gem::Command
9
+
10
+ def initialize
11
+ super('interrupt', 'Raises an Interrupt Exception', {})
12
+ end
13
+
14
+ def execute
15
+ raise Interrupt, "Interrupt exception"
16
+ end
17
+
18
+ end
19
+
20
+ Gem::CommandManager.instance.register_command :interrupt
21
+
@@ -0,0 +1,66 @@
1
+ SIMPLE_GEM = <<-GEMDATA
2
+ MD5SUM = "b12a4d48febeb2289c539c2574c4b6f8"
3
+ if $0 == __FILE__
4
+ require 'optparse'
5
+
6
+ options = {}
7
+ ARGV.options do |opts|
8
+ opts.on_tail("--help", "show this message") {puts opts; exit}
9
+ opts.on('--dir=DIRNAME', "Installation directory for the Gem") {|options[:directory]|}
10
+ opts.on('--force', "Force Gem to intall, bypassing dependency checks") {|options[:force]|}
11
+ opts.on('--gen-rdoc', "Generate RDoc documentation for the Gem") {|options[:gen_rdoc]|}
12
+ opts.parse!
13
+ end
14
+
15
+ require 'rubygems'
16
+ @directory = options[:directory] || Gem.dir
17
+ @force = options[:force]
18
+
19
+ gem = Gem::Installer.new(__FILE__).install(@force, @directory)
20
+ if options[:gen_rdoc]
21
+ Gem::DocManager.new(gem).generate_rdoc
22
+ end
23
+ end
24
+
25
+ __END__
26
+ --- !ruby/object:Gem::Specification
27
+ rubygems_version: "1.0"
28
+ name: testing
29
+ version: !ruby/object:Gem::Version
30
+ version: 1.2.3
31
+ date: 2004-03-18 22:01:52.859121 -05:00
32
+ platform:
33
+ summary: This exercise the gem testing stuff.
34
+ require_paths:
35
+ - lib
36
+ files:
37
+ - lib/foo.rb
38
+ - lib/test
39
+ - lib/test.rb
40
+ - lib/test/wow.rb
41
+ autorequire: test
42
+ test_suite_file: foo
43
+ requirements:
44
+ - a computer processor
45
+ ---
46
+ -
47
+ size: 109
48
+ mode: 420
49
+ path: lib/foo.rb
50
+ -
51
+ size: 0
52
+ mode: 420
53
+ path: lib/test.rb
54
+ -
55
+ size: 15
56
+ mode: 420
57
+ path: lib/test/wow.rb
58
+ ---
59
+ eJwVjDEKgDAUQ/eeIpsKguhY3ARPoHMp9quF0mL7e39/h5DwQpLpqz4TOqbC
60
+ U42eO6WuYEvBntIhECuaaX1KqXXLmy2kAEc32szExK+PjyBAlpTZyK0N/Twu
61
+ g1CKTjX9BGAj1w==
62
+ ---
63
+ eJwDAAAAAAE=
64
+ ---
65
+ eJwrKC0pVlAvzy9XyE3MU+cCACwiBP4=
66
+ GEMDATA
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems'
3
+
4
+ class TestConfig < RubyGemTestCase
5
+
6
+ def test_datadir
7
+ datadir = RbConfig::CONFIG['datadir']
8
+ assert_equal "#{datadir}/xyz", RbConfig.datadir('xyz')
9
+ end
10
+
11
+ end
12
+
@@ -0,0 +1,766 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'rubygems'
3
+ require 'rubygems/gem_openssl'
4
+ require 'rubygems/installer'
5
+ require 'pathname'
6
+ require 'tmpdir'
7
+
8
+ class TestGem < RubyGemTestCase
9
+
10
+ def setup
11
+ super
12
+
13
+ @additional = %w[a b].map { |d| File.join @tempdir, d }
14
+ @default_dir_re = if RUBY_VERSION > '1.9' then
15
+ %r|/.*?[Rr]uby.*?/[Gg]ems/[0-9.]+|
16
+ else
17
+ %r|/[Rr]uby/[Gg]ems/[0-9.]+|
18
+ end
19
+
20
+ util_remove_interrupt_command
21
+ end
22
+
23
+ def test_self_all_load_paths
24
+ util_make_gems
25
+
26
+ expected = [
27
+ File.join(@gemhome, *%W[gems #{@a1.full_name} lib]),
28
+ File.join(@gemhome, *%W[gems #{@a2.full_name} lib]),
29
+ File.join(@gemhome, *%W[gems #{@a3a.full_name} lib]),
30
+ File.join(@gemhome, *%W[gems #{@a_evil9.full_name} lib]),
31
+ File.join(@gemhome, *%W[gems #{@b2.full_name} lib]),
32
+ File.join(@gemhome, *%W[gems #{@c1_2.full_name} lib]),
33
+ File.join(@gemhome, *%W[gems #{@pl1.full_name} lib]),
34
+ ]
35
+
36
+ assert_equal expected, Gem.all_load_paths.sort
37
+ end
38
+
39
+ def test_self_available?
40
+ util_make_gems
41
+ assert(Gem.available?("a"))
42
+ assert(Gem.available?("a", "1"))
43
+ assert(Gem.available?("a", ">1"))
44
+ assert(!Gem.available?("monkeys"))
45
+ end
46
+
47
+ def test_self_bin_path_bin_name
48
+ util_exec_gem
49
+ assert_equal @abin_path, Gem.bin_path('a', 'abin')
50
+ end
51
+
52
+ def test_self_bin_path_bin_name_version
53
+ util_exec_gem
54
+ assert_equal @abin_path, Gem.bin_path('a', 'abin', '4')
55
+ end
56
+
57
+ def test_self_bin_path_name
58
+ util_exec_gem
59
+ assert_equal @exec_path, Gem.bin_path('a')
60
+ end
61
+
62
+ def test_self_bin_path_name_version
63
+ util_exec_gem
64
+ assert_equal @exec_path, Gem.bin_path('a', nil, '4')
65
+ end
66
+
67
+ def test_self_bin_path_nonexistent_binfile
68
+ quick_gem 'a', '2' do |s|
69
+ s.executables = ['exec']
70
+ end
71
+ assert_raises(Gem::GemNotFoundException) do
72
+ Gem.bin_path('a', 'other', '2')
73
+ end
74
+ end
75
+
76
+ def test_self_bin_path_no_bin_file
77
+ quick_gem 'a', '1'
78
+ assert_raises(Gem::Exception) do
79
+ Gem.bin_path('a', nil, '1')
80
+ end
81
+ end
82
+
83
+ def test_self_bin_path_not_found
84
+ assert_raises(Gem::GemNotFoundException) do
85
+ Gem.bin_path('non-existent')
86
+ end
87
+ end
88
+
89
+ def test_self_bin_path_bin_file_gone_in_latest
90
+ util_exec_gem
91
+ quick_gem 'a', '10' do |s|
92
+ s.executables = []
93
+ s.default_executable = nil
94
+ end
95
+ # Should not find a-10's non-abin (bug)
96
+ assert_equal @abin_path, Gem.bin_path('a', 'abin')
97
+ end
98
+
99
+ def test_self_bindir
100
+ assert_equal File.join(@gemhome, 'bin'), Gem.bindir
101
+ assert_equal File.join(@gemhome, 'bin'), Gem.bindir(Gem.dir)
102
+ assert_equal File.join(@gemhome, 'bin'), Gem.bindir(Pathname.new(Gem.dir))
103
+ end
104
+
105
+ def test_self_bindir_default_dir
106
+ default = Gem.default_dir
107
+ bindir = if defined?(RUBY_FRAMEWORK_VERSION) then
108
+ '/usr/bin'
109
+ else
110
+ RbConfig::CONFIG['bindir']
111
+ end
112
+
113
+ assert_equal bindir, Gem.bindir(default)
114
+ assert_equal bindir, Gem.bindir(Pathname.new(default))
115
+ end
116
+
117
+ def test_self_clear_paths
118
+ Gem.dir
119
+ Gem.path
120
+ searcher = Gem.searcher
121
+ source_index = Gem.source_index
122
+
123
+ Gem.clear_paths
124
+
125
+ assert_equal nil, Gem.instance_variable_get(:@gem_home)
126
+ assert_equal nil, Gem.instance_variable_get(:@gem_path)
127
+ refute_equal searcher, Gem.searcher
128
+ refute_equal source_index.object_id, Gem.source_index.object_id
129
+ end
130
+
131
+ def test_self_configuration
132
+ expected = Gem::ConfigFile.new []
133
+ Gem.configuration = nil
134
+
135
+ assert_equal expected, Gem.configuration
136
+ end
137
+
138
+ def test_self_datadir
139
+ foo = nil
140
+
141
+ Dir.chdir @tempdir do
142
+ FileUtils.mkdir_p 'data'
143
+ File.open File.join('data', 'foo.txt'), 'w' do |fp|
144
+ fp.puts 'blah'
145
+ end
146
+
147
+ foo = quick_gem 'foo' do |s| s.files = %w[data/foo.txt] end
148
+ install_gem foo
149
+ end
150
+
151
+ Gem.source_index = nil
152
+
153
+ gem 'foo'
154
+
155
+ expected = File.join @gemhome, 'gems', foo.full_name, 'data', 'foo'
156
+
157
+ assert_equal expected, Gem.datadir('foo')
158
+ end
159
+
160
+ def test_self_datadir_nonexistent_package
161
+ assert_nil Gem.datadir('xyzzy')
162
+ end
163
+
164
+ def test_self_default_dir
165
+ assert_match @default_dir_re, Gem.default_dir
166
+ end
167
+
168
+ def test_self_default_exec_format
169
+ orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:ruby_install_name]
170
+ Gem::ConfigMap[:ruby_install_name] = 'ruby'
171
+
172
+ assert_equal '%s', Gem.default_exec_format
173
+ ensure
174
+ Gem::ConfigMap[:ruby_install_name] = orig_RUBY_INSTALL_NAME
175
+ end
176
+
177
+ def test_self_default_exec_format_18
178
+ orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:ruby_install_name]
179
+ Gem::ConfigMap[:ruby_install_name] = 'ruby18'
180
+
181
+ assert_equal '%s18', Gem.default_exec_format
182
+ ensure
183
+ Gem::ConfigMap[:ruby_install_name] = orig_RUBY_INSTALL_NAME
184
+ end
185
+
186
+ def test_self_default_exec_format_jruby
187
+ orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:ruby_install_name]
188
+ Gem::ConfigMap[:ruby_install_name] = 'jruby'
189
+
190
+ assert_equal 'j%s', Gem.default_exec_format
191
+ ensure
192
+ Gem::ConfigMap[:ruby_install_name] = orig_RUBY_INSTALL_NAME
193
+ end
194
+
195
+ def test_self_default_sources
196
+ assert_equal %w[http://rubygems.org/], Gem.default_sources
197
+ end
198
+
199
+ def test_self_dir
200
+ assert_equal @gemhome, Gem.dir
201
+ end
202
+
203
+ def test_self_ensure_gem_directories
204
+ FileUtils.rm_r @gemhome
205
+ Gem.use_paths @gemhome
206
+
207
+ Gem.ensure_gem_subdirectories @gemhome
208
+
209
+ assert File.directory?(File.join(@gemhome, "cache"))
210
+ end
211
+
212
+ def test_self_ensure_gem_directories_missing_parents
213
+ gemdir = File.join @tempdir, 'a/b/c/gemdir'
214
+ FileUtils.rm_rf File.join(@tempdir, 'a') rescue nil
215
+ refute File.exist?(File.join(@tempdir, 'a')),
216
+ "manually remove #{File.join @tempdir, 'a'}, tests are broken"
217
+ Gem.use_paths gemdir
218
+
219
+ Gem.ensure_gem_subdirectories gemdir
220
+
221
+ assert File.directory?("#{gemdir}/cache")
222
+ end
223
+
224
+ unless win_platform? then # only for FS that support write protection
225
+ def test_self_ensure_gem_directories_write_protected
226
+ gemdir = File.join @tempdir, "egd"
227
+ FileUtils.rm_r gemdir rescue nil
228
+ refute File.exist?(gemdir), "manually remove #{gemdir}, tests are broken"
229
+ FileUtils.mkdir_p gemdir
230
+ FileUtils.chmod 0400, gemdir
231
+ Gem.use_paths gemdir
232
+
233
+ Gem.ensure_gem_subdirectories gemdir
234
+
235
+ refute File.exist?("#{gemdir}/cache")
236
+ ensure
237
+ FileUtils.chmod 0600, gemdir
238
+ end
239
+
240
+ def test_self_ensure_gem_directories_write_protected_parents
241
+ parent = File.join(@tempdir, "egd")
242
+ gemdir = "#{parent}/a/b/c"
243
+
244
+ FileUtils.rm_r parent rescue nil
245
+ refute File.exist?(parent), "manually remove #{parent}, tests are broken"
246
+ FileUtils.mkdir_p parent
247
+ FileUtils.chmod 0400, parent
248
+ Gem.use_paths(gemdir)
249
+
250
+ Gem.ensure_gem_subdirectories gemdir
251
+
252
+ refute File.exist?("#{gemdir}/cache")
253
+ ensure
254
+ FileUtils.chmod 0600, parent
255
+ end
256
+ end
257
+
258
+ def test_ensure_ssl_available
259
+ orig_Gem_ssl_available = Gem.ssl_available?
260
+
261
+ Gem.ssl_available = true
262
+ Gem.ensure_ssl_available
263
+
264
+ Gem.ssl_available = false
265
+ e = assert_raises Gem::Exception do Gem.ensure_ssl_available end
266
+ assert_equal 'SSL is not installed on this system', e.message
267
+ ensure
268
+ Gem.ssl_available = orig_Gem_ssl_available
269
+ end
270
+
271
+ def test_self_find_files
272
+ discover_path = File.join 'lib', 'foo', 'discover.rb'
273
+ cwd = File.expand_path '..', __FILE__
274
+ $LOAD_PATH.unshift cwd.dup
275
+
276
+ foo1 = quick_gem 'foo', '1' do |s|
277
+ s.files << discover_path
278
+ end
279
+
280
+ foo2 = quick_gem 'foo', '2' do |s|
281
+ s.files << discover_path
282
+ end
283
+
284
+ path = File.join 'gems', foo1.full_name, discover_path
285
+ write_file(path) { |fp| fp.puts "# #{path}" }
286
+
287
+ path = File.join 'gems', foo2.full_name, discover_path
288
+ write_file(path) { |fp| fp.puts "# #{path}" }
289
+
290
+ @fetcher = Gem::FakeFetcher.new
291
+ Gem::RemoteFetcher.fetcher = @fetcher
292
+
293
+ Gem.source_index = util_setup_spec_fetcher foo1, foo2
294
+
295
+ Gem.searcher = nil
296
+
297
+ expected = [
298
+ File.expand_path('../foo/discover.rb', __FILE__),
299
+ File.join(foo2.full_gem_path, discover_path),
300
+ File.join(foo1.full_gem_path, discover_path),
301
+ ]
302
+
303
+ assert_equal expected, Gem.find_files('foo/discover')
304
+ ensure
305
+ assert_equal cwd, $LOAD_PATH.shift
306
+ end
307
+
308
+ def test_self_latest_load_paths
309
+ util_make_gems
310
+
311
+ expected = [
312
+ File.join(@gemhome, *%W[gems #{@a3a.full_name} lib]),
313
+ File.join(@gemhome, *%W[gems #{@a_evil9.full_name} lib]),
314
+ File.join(@gemhome, *%W[gems #{@b2.full_name} lib]),
315
+ File.join(@gemhome, *%W[gems #{@c1_2.full_name} lib]),
316
+ File.join(@gemhome, *%W[gems #{@pl1.full_name} lib]),
317
+ ]
318
+
319
+ assert_equal expected, Gem.latest_load_paths.sort
320
+ end
321
+
322
+ def test_self_loaded_specs
323
+ foo = quick_gem 'foo'
324
+ install_gem foo
325
+ Gem.source_index = nil
326
+
327
+ Gem.activate 'foo'
328
+
329
+ assert_equal true, Gem.loaded_specs.keys.include?('foo')
330
+ end
331
+
332
+ def test_self_path
333
+ assert_equal [Gem.dir], Gem.path
334
+ end
335
+
336
+ def test_self_path_default
337
+ if defined? APPLE_GEM_HOME
338
+ orig_APPLE_GEM_HOME = APPLE_GEM_HOME
339
+ Object.send :remove_const, :APPLE_GEM_HOME
340
+ end
341
+ Gem.instance_variable_set :@gem_path, nil
342
+
343
+ assert_equal [Gem.default_path, Gem.dir].flatten, Gem.path
344
+ ensure
345
+ Object.const_set :APPLE_GEM_HOME, orig_APPLE_GEM_HOME
346
+ end
347
+
348
+ unless win_platform?
349
+ def test_self_path_APPLE_GEM_HOME
350
+ Gem.clear_paths
351
+ apple_gem_home = File.join @tempdir, 'apple_gem_home'
352
+ Gem.const_set :APPLE_GEM_HOME, apple_gem_home
353
+
354
+ assert_includes Gem.path, apple_gem_home
355
+ ensure
356
+ Gem.send :remove_const, :APPLE_GEM_HOME
357
+ end
358
+
359
+ def test_self_path_APPLE_GEM_HOME_GEM_PATH
360
+ Gem.clear_paths
361
+ ENV['GEM_PATH'] = @gemhome
362
+ apple_gem_home = File.join @tempdir, 'apple_gem_home'
363
+ Gem.const_set :APPLE_GEM_HOME, apple_gem_home
364
+
365
+ refute Gem.path.include?(apple_gem_home)
366
+ ensure
367
+ Gem.send :remove_const, :APPLE_GEM_HOME
368
+ end
369
+ end
370
+
371
+ def test_self_path_ENV_PATH
372
+ Gem.send :set_paths, nil
373
+ path_count = Gem.path.size
374
+ Gem.clear_paths
375
+
376
+ ENV['GEM_PATH'] = @additional.join(File::PATH_SEPARATOR)
377
+
378
+ assert_equal @additional, Gem.path[0,2]
379
+
380
+ assert_equal path_count + @additional.size, Gem.path.size,
381
+ "extra path components: #{Gem.path[2..-1].inspect}"
382
+ assert_equal Gem.dir, Gem.path.last
383
+ end
384
+
385
+ def test_self_path_duplicate
386
+ Gem.clear_paths
387
+ util_ensure_gem_dirs
388
+ dirs = @additional + [@gemhome] + [File.join(@tempdir, 'a')]
389
+
390
+ ENV['GEM_HOME'] = @gemhome
391
+ ENV['GEM_PATH'] = dirs.join File::PATH_SEPARATOR
392
+
393
+ assert_equal @gemhome, Gem.dir
394
+
395
+ paths = [Gem.dir]
396
+ assert_equal @additional + paths, Gem.path
397
+ end
398
+
399
+ def test_self_path_overlap
400
+ Gem.clear_paths
401
+
402
+ util_ensure_gem_dirs
403
+ ENV['GEM_HOME'] = @gemhome
404
+ ENV['GEM_PATH'] = @additional.join(File::PATH_SEPARATOR)
405
+
406
+ assert_equal @gemhome, Gem.dir
407
+
408
+ paths = [Gem.dir]
409
+ assert_equal @additional + paths, Gem.path
410
+ end
411
+
412
+ def test_self_platforms
413
+ assert_equal [Gem::Platform::RUBY, Gem::Platform.local], Gem.platforms
414
+ end
415
+
416
+ def test_self_prefix
417
+ file_name = File.expand_path __FILE__
418
+
419
+ prefix = File.dirname File.dirname(file_name)
420
+ prefix = File.dirname prefix if File.basename(prefix) == 'test'
421
+
422
+ assert_equal prefix, Gem.prefix
423
+ end
424
+
425
+ def test_self_prefix_libdir
426
+ orig_libdir = Gem::ConfigMap[:libdir]
427
+
428
+ file_name = File.expand_path __FILE__
429
+ prefix = File.dirname File.dirname(file_name)
430
+ prefix = File.dirname prefix if File.basename(prefix) == 'test'
431
+
432
+ Gem::ConfigMap[:libdir] = prefix
433
+
434
+ assert_nil Gem.prefix
435
+ ensure
436
+ Gem::ConfigMap[:libdir] = orig_libdir
437
+ end
438
+
439
+ def test_self_prefix_sitelibdir
440
+ orig_sitelibdir = Gem::ConfigMap[:sitelibdir]
441
+
442
+ file_name = File.expand_path __FILE__
443
+ prefix = File.dirname File.dirname(file_name)
444
+ prefix = File.dirname prefix if File.basename(prefix) == 'test'
445
+
446
+ Gem::ConfigMap[:sitelibdir] = prefix
447
+
448
+ assert_nil Gem.prefix
449
+ ensure
450
+ Gem::ConfigMap[:sitelibdir] = orig_sitelibdir
451
+ end
452
+
453
+ def test_self_refresh
454
+ util_make_gems
455
+
456
+ a1_spec = File.join @gemhome, "specifications", @a1.spec_name
457
+
458
+ FileUtils.mv a1_spec, @tempdir
459
+
460
+ refute Gem.source_index.gems.include?(@a1.full_name)
461
+
462
+ FileUtils.mv File.join(@tempdir, @a1.spec_name), a1_spec
463
+
464
+ Gem.refresh
465
+
466
+ assert_includes Gem.source_index.gems, @a1.full_name
467
+ assert_equal nil, Gem.instance_variable_get(:@searcher)
468
+ end
469
+
470
+ def test_self_required_location
471
+ util_make_gems
472
+
473
+ assert_equal File.join(@tempdir, *%w[gemhome gems c-1.2 lib code.rb]),
474
+ Gem.required_location("c", "code.rb")
475
+ assert_equal File.join(@tempdir, *%w[gemhome gems a-1 lib code.rb]),
476
+ Gem.required_location("a", "code.rb", "< 2")
477
+ assert_equal File.join(@tempdir, *%w[gemhome gems a-2 lib code.rb]),
478
+ Gem.required_location("a", "code.rb", "= 2")
479
+ end
480
+
481
+ def test_self_ruby_escaping_spaces_in_path
482
+ orig_ruby = Gem.ruby
483
+ orig_bindir = Gem::ConfigMap[:bindir]
484
+ orig_ruby_install_name = Gem::ConfigMap[:ruby_install_name]
485
+ orig_exe_ext = Gem::ConfigMap[:EXEEXT]
486
+
487
+ Gem::ConfigMap[:bindir] = "C:/Ruby 1.8/bin"
488
+ Gem::ConfigMap[:ruby_install_name] = "ruby"
489
+ Gem::ConfigMap[:EXEEXT] = ".exe"
490
+ Gem.instance_variable_set("@ruby", nil)
491
+
492
+ assert_equal "\"C:/Ruby 1.8/bin/ruby.exe\"", Gem.ruby
493
+ ensure
494
+ Gem.instance_variable_set("@ruby", orig_ruby)
495
+ Gem::ConfigMap[:bindir] = orig_bindir
496
+ Gem::ConfigMap[:ruby_install_name] = orig_ruby_install_name
497
+ Gem::ConfigMap[:EXEEXT] = orig_exe_ext
498
+ end
499
+
500
+ def test_self_ruby_path_without_spaces
501
+ orig_ruby = Gem.ruby
502
+ orig_bindir = Gem::ConfigMap[:bindir]
503
+ orig_ruby_install_name = Gem::ConfigMap[:ruby_install_name]
504
+ orig_exe_ext = Gem::ConfigMap[:EXEEXT]
505
+
506
+ Gem::ConfigMap[:bindir] = "C:/Ruby18/bin"
507
+ Gem::ConfigMap[:ruby_install_name] = "ruby"
508
+ Gem::ConfigMap[:EXEEXT] = ".exe"
509
+ Gem.instance_variable_set("@ruby", nil)
510
+
511
+ assert_equal "C:/Ruby18/bin/ruby.exe", Gem.ruby
512
+ ensure
513
+ Gem.instance_variable_set("@ruby", orig_ruby)
514
+ Gem::ConfigMap[:bindir] = orig_bindir
515
+ Gem::ConfigMap[:ruby_install_name] = orig_ruby_install_name
516
+ Gem::ConfigMap[:EXEEXT] = orig_exe_ext
517
+ end
518
+
519
+ def test_self_ruby_version_1_8_5
520
+ util_set_RUBY_VERSION '1.8.5'
521
+
522
+ assert_equal Gem::Version.new('1.8.5'), Gem.ruby_version
523
+ ensure
524
+ util_restore_RUBY_VERSION
525
+ end
526
+
527
+ def test_self_ruby_version_1_8_6p287
528
+ util_set_RUBY_VERSION '1.8.6', 287
529
+
530
+ assert_equal Gem::Version.new('1.8.6.287'), Gem.ruby_version
531
+ ensure
532
+ util_restore_RUBY_VERSION
533
+ end
534
+
535
+ def test_self_ruby_version_1_9_2dev_r23493
536
+ util_set_RUBY_VERSION '1.9.2', -1, 23493
537
+
538
+ assert_equal Gem::Version.new('1.9.2.dev.23493'), Gem.ruby_version
539
+ ensure
540
+ util_restore_RUBY_VERSION
541
+ end
542
+
543
+ def test_self_searcher
544
+ assert_kind_of Gem::GemPathSearcher, Gem.searcher
545
+ end
546
+
547
+ def test_self_set_paths
548
+ other = File.join @tempdir, 'other'
549
+ path = [@userhome, other].join File::PATH_SEPARATOR
550
+ Gem.send :set_paths, path
551
+
552
+ assert_equal [@userhome, other, @gemhome], Gem.path
553
+ end
554
+
555
+ def test_self_set_paths_nonexistent_home
556
+ ENV['GEM_HOME'] = @gemhome
557
+ Gem.clear_paths
558
+
559
+ other = File.join @tempdir, 'other'
560
+
561
+ ENV['HOME'] = other
562
+
563
+ Gem.send :set_paths, other
564
+
565
+ assert_equal [other, @gemhome], Gem.path
566
+ end
567
+
568
+ def test_self_source_index
569
+ assert_kind_of Gem::SourceIndex, Gem.source_index
570
+ end
571
+
572
+ def test_self_sources
573
+ assert_equal %w[http://gems.example.com/], Gem.sources
574
+ end
575
+
576
+ def test_ssl_available_eh
577
+ orig_Gem_ssl_available = Gem.ssl_available?
578
+
579
+ Gem.ssl_available = true
580
+ assert_equal true, Gem.ssl_available?
581
+
582
+ Gem.ssl_available = false
583
+ assert_equal false, Gem.ssl_available?
584
+ ensure
585
+ Gem.ssl_available = orig_Gem_ssl_available
586
+ end
587
+
588
+ def test_self_use_paths
589
+ util_ensure_gem_dirs
590
+
591
+ Gem.use_paths @gemhome, @additional
592
+
593
+ assert_equal @gemhome, Gem.dir
594
+ assert_equal @additional + [Gem.dir], Gem.path
595
+ end
596
+
597
+ def test_self_user_dir
598
+ assert_equal File.join(@userhome, '.gem', Gem.ruby_engine,
599
+ Gem::ConfigMap[:ruby_version]), Gem.user_dir
600
+ end
601
+
602
+ def test_self_user_home
603
+ if ENV['HOME'] then
604
+ assert_equal ENV['HOME'], Gem.user_home
605
+ else
606
+ assert true, 'count this test'
607
+ end
608
+ end
609
+
610
+ if Gem.win_platform? then
611
+ def test_self_user_home_userprofile
612
+ skip 'Ruby 1.9 properly handles ~ path expansion' unless '1.9' > RUBY_VERSION
613
+
614
+ Gem.clear_paths
615
+
616
+ # safe-keep env variables
617
+ orig_home, orig_user_profile = ENV['HOME'], ENV['USERPROFILE']
618
+
619
+ # prepare for the test
620
+ ENV.delete('HOME')
621
+ ENV['USERPROFILE'] = "W:\\Users\\RubyUser"
622
+
623
+ assert_equal 'W:/Users/RubyUser', Gem.user_home
624
+
625
+ ensure
626
+ ENV['HOME'] = orig_home
627
+ ENV['USERPROFILE'] = orig_user_profile
628
+ end
629
+
630
+ def test_self_user_home_user_drive_and_path
631
+ skip 'Ruby 1.9 properly handles ~ path expansion' unless '1.9' > RUBY_VERSION
632
+
633
+ Gem.clear_paths
634
+
635
+ # safe-keep env variables
636
+ orig_home, orig_user_profile = ENV['HOME'], ENV['USERPROFILE']
637
+ orig_home_drive, orig_home_path = ENV['HOMEDRIVE'], ENV['HOMEPATH']
638
+
639
+ # prepare the environment
640
+ ENV.delete('HOME')
641
+ ENV.delete('USERPROFILE')
642
+ ENV['HOMEDRIVE'] = 'Z:'
643
+ ENV['HOMEPATH'] = "\\Users\\RubyUser"
644
+
645
+ assert_equal 'Z:/Users/RubyUser', Gem.user_home
646
+
647
+ ensure
648
+ ENV['HOME'] = orig_home
649
+ ENV['USERPROFILE'] = orig_user_profile
650
+ ENV['HOMEDRIVE'] = orig_home_drive
651
+ ENV['HOMEPATH'] = orig_home_path
652
+ end
653
+ end
654
+
655
+ def test_load_plugins
656
+ plugin_path = File.join "lib", "rubygems_plugin.rb"
657
+
658
+ Dir.chdir @tempdir do
659
+ FileUtils.mkdir_p 'lib'
660
+ File.open plugin_path, "w" do |fp|
661
+ fp.puts "TestGem::TEST_SPEC_PLUGIN_LOAD = :loaded"
662
+ end
663
+
664
+ foo = quick_gem 'foo', '1' do |s|
665
+ s.files << plugin_path
666
+ end
667
+
668
+ install_gem foo
669
+ end
670
+
671
+ Gem.source_index = nil
672
+
673
+ gem 'foo'
674
+
675
+ Gem.load_plugins
676
+
677
+ assert_equal :loaded, TEST_SPEC_PLUGIN_LOAD
678
+ end
679
+
680
+ def test_load_env_plugins
681
+ with_plugin('load') { Gem.load_env_plugins }
682
+ assert_equal :loaded, TEST_PLUGIN_LOAD
683
+
684
+ util_remove_interrupt_command
685
+
686
+ # Should attempt to cause a StandardError
687
+ with_plugin('standarderror') { Gem.load_env_plugins }
688
+ assert_equal :loaded, TEST_PLUGIN_STANDARDERROR
689
+
690
+ util_remove_interrupt_command
691
+
692
+ # Should attempt to cause an Exception
693
+ with_plugin('exception') { Gem.load_env_plugins }
694
+ assert_equal :loaded, TEST_PLUGIN_EXCEPTION
695
+ end
696
+
697
+ def with_plugin(path)
698
+ test_plugin_path = File.expand_path "../plugin/#{path}", __FILE__
699
+
700
+ # A single test plugin should get loaded once only, in order to preserve
701
+ # sane test semantics.
702
+ refute_includes $LOAD_PATH, test_plugin_path
703
+ $LOAD_PATH.unshift test_plugin_path
704
+
705
+ capture_io do
706
+ yield
707
+ end
708
+ ensure
709
+ $LOAD_PATH.delete test_plugin_path
710
+ end
711
+
712
+ def util_ensure_gem_dirs
713
+ Gem.ensure_gem_subdirectories @gemhome
714
+ @additional.each do |dir|
715
+ Gem.ensure_gem_subdirectories @gemhome
716
+ end
717
+ end
718
+
719
+ def util_exec_gem
720
+ spec, _ = quick_gem 'a', '4' do |s|
721
+ s.default_executable = 'exec'
722
+ s.executables = ['exec', 'abin']
723
+ end
724
+
725
+ @exec_path = File.join spec.full_gem_path, spec.bindir, 'exec'
726
+ @abin_path = File.join spec.full_gem_path, spec.bindir, 'abin'
727
+ end
728
+
729
+ def util_set_RUBY_VERSION(version, patchlevel = nil, revision = nil)
730
+ if Gem.instance_variables.include? :@ruby_version or
731
+ Gem.instance_variables.include? '@ruby_version' then
732
+ Gem.send :remove_instance_variable, :@ruby_version
733
+ end
734
+
735
+ @RUBY_VERSION = RUBY_VERSION
736
+ @RUBY_PATCHLEVEL = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
737
+ @RUBY_REVISION = RUBY_REVISION if defined?(RUBY_REVISION)
738
+
739
+ Object.send :remove_const, :RUBY_VERSION
740
+ Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
741
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
742
+
743
+ Object.const_set :RUBY_VERSION, version
744
+ Object.const_set :RUBY_PATCHLEVEL, patchlevel if patchlevel
745
+ Object.const_set :RUBY_REVISION, revision if revision
746
+ end
747
+
748
+ def util_restore_RUBY_VERSION
749
+ Object.send :remove_const, :RUBY_VERSION
750
+ Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
751
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
752
+
753
+ Object.const_set :RUBY_VERSION, @RUBY_VERSION
754
+ Object.const_set :RUBY_PATCHLEVEL, @RUBY_PATCHLEVEL if
755
+ defined?(@RUBY_PATCHLEVEL)
756
+ Object.const_set :RUBY_REVISION, @RUBY_REVISION if
757
+ defined?(@RUBY_REVISION)
758
+ end
759
+
760
+ def util_remove_interrupt_command
761
+ Gem::Commands.send :remove_const, :InterruptCommand if
762
+ Gem::Commands.const_defined? :InterruptCommand
763
+ end
764
+
765
+ end
766
+