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,43 @@
1
+ require 'libgems'
2
+
3
+ def install_session
4
+ path_to_gem = File.join("redist", "session.gem")
5
+ begin
6
+ LibGems::Installer.new(path_to_gem).install
7
+ rescue Errno::EACCES => ex
8
+ puts
9
+ puts "*****************************************************************"
10
+ puts "Unable to install LibGems '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 LibGems 'Session' missing."
29
+ puts "We can attempt to install from the #{LibGems::NAME} Distribution,"
30
+ puts "but installation may require admin privileges on your system."
31
+ puts
32
+ print "Install now from #{LibGems::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 'libgems/user_interaction'
3
+
4
+ class MockGemUi < LibGems::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 LibGems::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 'libgems/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 LibGems::Commands::InterruptCommand < LibGems::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
+ LibGems::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 LibGems") {|options[:directory]|}
10
+ opts.on('--force', "Force LibGems to intall, bypassing dependency checks") {|options[:force]|}
11
+ opts.on('--gen-rdoc', "Generate RDoc documentation for the LibGems") {|options[:gen_rdoc]|}
12
+ opts.parse!
13
+ end
14
+
15
+ require 'libgems'
16
+ @directory = options[:directory] || LibGems.dir
17
+ @force = options[:force]
18
+
19
+ gem = LibGems::Installer.new(__FILE__).install(@force, @directory)
20
+ if options[:gen_rdoc]
21
+ LibGems::DocManager.new(gem).generate_rdoc
22
+ end
23
+ end
24
+
25
+ __END__
26
+ --- !ruby/object:LibGems::Specification
27
+ rubygems_version: "1.0"
28
+ name: testing
29
+ version: !ruby/object:LibGems::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 'libgems'
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,780 @@
1
+ require File.expand_path('../gemutilities', __FILE__)
2
+ require 'libgems'
3
+ require 'libgems/gem_openssl'
4
+ require 'libgems/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, LibGems.all_load_paths.sort
37
+ end
38
+
39
+ def test_self_available?
40
+ util_make_gems
41
+ assert(LibGems.available?("a"))
42
+ assert(LibGems.available?("a", "1"))
43
+ assert(LibGems.available?("a", ">1"))
44
+ assert(!LibGems.available?("monkeys"))
45
+ end
46
+
47
+ def test_self_bin_path_bin_name
48
+ util_exec_gem
49
+ assert_equal @abin_path, LibGems.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, LibGems.bin_path('a', 'abin', '4')
55
+ end
56
+
57
+ def test_self_bin_path_name
58
+ util_exec_gem
59
+ assert_equal @exec_path, LibGems.bin_path('a')
60
+ end
61
+
62
+ def test_self_bin_path_name_version
63
+ util_exec_gem
64
+ assert_equal @exec_path, LibGems.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(LibGems::GemNotFoundException) do
72
+ LibGems.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(LibGems::Exception) do
79
+ LibGems.bin_path('a', nil, '1')
80
+ end
81
+ end
82
+
83
+ def test_self_bin_path_not_found
84
+ assert_raises(LibGems::GemNotFoundException) do
85
+ LibGems.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, LibGems.bin_path('a', 'abin')
97
+ end
98
+
99
+ def test_self_bindir
100
+ assert_equal File.join(@gemhome, 'bin'), LibGems.bindir
101
+ assert_equal File.join(@gemhome, 'bin'), LibGems.bindir(LibGems.dir)
102
+ assert_equal File.join(@gemhome, 'bin'), LibGems.bindir(Pathname.new(LibGems.dir))
103
+ end
104
+
105
+ def test_self_bindir_default_dir
106
+ default = LibGems.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, LibGems.bindir(default)
114
+ assert_equal bindir, LibGems.bindir(Pathname.new(default))
115
+ end
116
+
117
+ def test_self_clear_paths
118
+ LibGems.dir
119
+ LibGems.path
120
+ searcher = LibGems.searcher
121
+ source_index = LibGems.source_index
122
+
123
+ LibGems.clear_paths
124
+
125
+ assert_equal nil, LibGems.instance_variable_get(:@gem_home)
126
+ assert_equal nil, LibGems.instance_variable_get(:@gem_path)
127
+ refute_equal searcher, LibGems.searcher
128
+ refute_equal source_index.object_id, LibGems.source_index.object_id
129
+ end
130
+
131
+ def test_self_configuration
132
+ expected = LibGems::ConfigFile.new []
133
+ LibGems.configuration = nil
134
+
135
+ assert_equal expected, LibGems.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
+ LibGems.source_index = nil
152
+
153
+ gem 'foo'
154
+
155
+ expected = File.join @gemhome, 'gems', foo.full_name, 'data', 'foo'
156
+
157
+ assert_equal expected, LibGems.datadir('foo')
158
+ end
159
+
160
+ def test_self_datadir_nonexistent_package
161
+ assert_nil LibGems.datadir('xyzzy')
162
+ end
163
+
164
+ def test_self_default_dir
165
+ assert_match @default_dir_re, LibGems.default_dir
166
+ end
167
+
168
+ def test_self_default_exec_format
169
+ orig_RUBY_INSTALL_NAME = LibGems::ConfigMap[:ruby_install_name]
170
+ LibGems::ConfigMap[:ruby_install_name] = 'ruby'
171
+
172
+ assert_equal '%s', LibGems.default_exec_format
173
+ ensure
174
+ LibGems::ConfigMap[:ruby_install_name] = orig_RUBY_INSTALL_NAME
175
+ end
176
+
177
+ def test_self_default_exec_format_18
178
+ orig_RUBY_INSTALL_NAME = LibGems::ConfigMap[:ruby_install_name]
179
+ LibGems::ConfigMap[:ruby_install_name] = 'ruby18'
180
+
181
+ assert_equal '%s18', LibGems.default_exec_format
182
+ ensure
183
+ LibGems::ConfigMap[:ruby_install_name] = orig_RUBY_INSTALL_NAME
184
+ end
185
+
186
+ def test_self_default_exec_format_jruby
187
+ orig_RUBY_INSTALL_NAME = LibGems::ConfigMap[:ruby_install_name]
188
+ LibGems::ConfigMap[:ruby_install_name] = 'jruby'
189
+
190
+ assert_equal 'j%s', LibGems.default_exec_format
191
+ ensure
192
+ LibGems::ConfigMap[:ruby_install_name] = orig_RUBY_INSTALL_NAME
193
+ end
194
+
195
+ def test_self_default_sources
196
+ assert_equal %w[http://rubygems.org/], LibGems.default_sources
197
+ end
198
+
199
+ def test_self_dir
200
+ assert_equal @gemhome, LibGems.dir
201
+ end
202
+
203
+ def test_self_ensure_gem_directories
204
+ FileUtils.rm_r @gemhome
205
+ LibGems.use_paths @gemhome
206
+
207
+ LibGems.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
+ LibGems.use_paths gemdir
218
+
219
+ LibGems.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
+ LibGems.use_paths gemdir
232
+
233
+ LibGems.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
+ LibGems.use_paths(gemdir)
249
+
250
+ LibGems.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 = LibGems.ssl_available?
260
+
261
+ LibGems.ssl_available = true
262
+ LibGems.ensure_ssl_available
263
+
264
+ LibGems.ssl_available = false
265
+ e = assert_raises LibGems::Exception do LibGems.ensure_ssl_available end
266
+ assert_equal 'SSL is not installed on this system', e.message
267
+ ensure
268
+ LibGems.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 = LibGems::FakeFetcher.new
291
+ LibGems::RemoteFetcher.fetcher = @fetcher
292
+
293
+ LibGems.source_index = util_setup_spec_fetcher foo1, foo2
294
+
295
+ LibGems.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, LibGems.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, LibGems.latest_load_paths.sort
320
+ end
321
+
322
+ def test_self_loaded_specs
323
+ foo = quick_gem 'foo'
324
+ install_gem foo
325
+ LibGems.source_index = nil
326
+
327
+ LibGems.activate 'foo'
328
+
329
+ assert_equal true, LibGems.loaded_specs.keys.include?('foo')
330
+ end
331
+
332
+ def test_self_path
333
+ assert_equal [LibGems.dir], LibGems.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
+ orig_GEM_HOME = ENV.delete 'GEM_HOME'
342
+ orig_GEM_PATH = ENV.delete 'GEM_PATH'
343
+
344
+ LibGems.instance_variable_set :@gem_path, nil
345
+
346
+ assert_equal [LibGems.default_path, LibGems.dir].flatten, LibGems.path
347
+ ensure
348
+ Object.const_set :APPLE_GEM_HOME, orig_APPLE_GEM_HOME
349
+ ENV['GEM_HOME'] = orig_GEM_HOME
350
+ ENV['GEM_PATH'] = orig_GEM_PATH
351
+ end
352
+
353
+ unless win_platform?
354
+ def test_self_path_APPLE_GEM_HOME
355
+ orig_GEM_HOME = ENV.delete 'GEM_HOME'
356
+ orig_GEM_PATH = ENV.delete 'GEM_PATH'
357
+
358
+ LibGems.clear_paths
359
+ apple_gem_home = File.join @tempdir, 'apple_gem_home'
360
+ LibGems.const_set :APPLE_GEM_HOME, apple_gem_home
361
+
362
+ assert_includes LibGems.path, apple_gem_home
363
+ ensure
364
+ LibGems.send :remove_const, :APPLE_GEM_HOME
365
+ ENV['GEM_HOME'] = orig_GEM_HOME
366
+ ENV['GEM_PATH'] = orig_GEM_PATH
367
+ end
368
+
369
+ def test_self_path_APPLE_GEM_HOME_GEM_PATH
370
+ LibGems.clear_paths
371
+ ENV['LIBGEMS_PATH'] = @gemhome
372
+ apple_gem_home = File.join @tempdir, 'apple_gem_home'
373
+ LibGems.const_set :APPLE_GEM_HOME, apple_gem_home
374
+
375
+ refute LibGems.path.include?(apple_gem_home)
376
+ ensure
377
+ LibGems.send :remove_const, :APPLE_GEM_HOME
378
+ end
379
+ end
380
+
381
+ def test_self_path_ENV_PATH
382
+ LibGems.send :set_paths, nil
383
+ path_count = LibGems.path.size
384
+ LibGems.clear_paths
385
+
386
+ ENV['LIBGEMS_PATH'] = @additional.join(File::PATH_SEPARATOR)
387
+
388
+ assert_equal @additional, LibGems.path[0,2]
389
+
390
+ assert_equal path_count + @additional.size, LibGems.path.size,
391
+ "extra path components: #{LibGems.path[2..-1].inspect}"
392
+ assert_equal LibGems.dir, LibGems.path.last
393
+ end
394
+
395
+ def test_self_path_duplicate
396
+ LibGems.clear_paths
397
+ util_ensure_gem_dirs
398
+ dirs = @additional + [@gemhome] + [File.join(@tempdir, 'a')]
399
+
400
+ ENV['LIBGEMS_HOME'] = @gemhome
401
+ ENV['LIBGEMS_PATH'] = dirs.join File::PATH_SEPARATOR
402
+
403
+ assert_equal @gemhome, LibGems.dir
404
+
405
+ paths = [LibGems.dir]
406
+ assert_equal @additional + paths, LibGems.path
407
+ end
408
+
409
+ def test_self_path_overlap
410
+ LibGems.clear_paths
411
+
412
+ util_ensure_gem_dirs
413
+ ENV['LIBGEMS_HOME'] = @gemhome
414
+ ENV['LIBGEMS_PATH'] = @additional.join(File::PATH_SEPARATOR)
415
+
416
+ assert_equal @gemhome, LibGems.dir
417
+
418
+ paths = [LibGems.dir]
419
+ assert_equal @additional + paths, LibGems.path
420
+ end
421
+
422
+ def test_self_platforms
423
+ assert_equal [LibGems::Platform::RUBY, LibGems::Platform.local], LibGems.platforms
424
+ end
425
+
426
+ def test_self_prefix
427
+ file_name = File.expand_path __FILE__
428
+
429
+ prefix = File.dirname File.dirname(file_name)
430
+ prefix = File.dirname prefix if File.basename(prefix) == 'test'
431
+
432
+ assert_equal prefix, LibGems.prefix
433
+ end
434
+
435
+ def test_self_prefix_libdir
436
+ orig_libdir = LibGems::ConfigMap[:libdir]
437
+
438
+ file_name = File.expand_path __FILE__
439
+ prefix = File.dirname File.dirname(file_name)
440
+ prefix = File.dirname prefix if File.basename(prefix) == 'test'
441
+
442
+ LibGems::ConfigMap[:libdir] = prefix
443
+
444
+ assert_nil LibGems.prefix
445
+ ensure
446
+ LibGems::ConfigMap[:libdir] = orig_libdir
447
+ end
448
+
449
+ def test_self_prefix_sitelibdir
450
+ orig_sitelibdir = LibGems::ConfigMap[:sitelibdir]
451
+
452
+ file_name = File.expand_path __FILE__
453
+ prefix = File.dirname File.dirname(file_name)
454
+ prefix = File.dirname prefix if File.basename(prefix) == 'test'
455
+
456
+ LibGems::ConfigMap[:sitelibdir] = prefix
457
+
458
+ assert_nil LibGems.prefix
459
+ ensure
460
+ LibGems::ConfigMap[:sitelibdir] = orig_sitelibdir
461
+ end
462
+
463
+ def test_self_refresh
464
+ util_make_gems
465
+
466
+ a1_spec = File.join @gemhome, "specifications", @a1.spec_name
467
+
468
+ FileUtils.mv a1_spec, @tempdir
469
+
470
+ refute LibGems.source_index.gems.include?(@a1.full_name)
471
+
472
+ FileUtils.mv File.join(@tempdir, @a1.spec_name), a1_spec
473
+
474
+ LibGems.refresh
475
+
476
+ assert_includes LibGems.source_index.gems, @a1.full_name
477
+ assert_equal nil, LibGems.instance_variable_get(:@searcher)
478
+ end
479
+
480
+ def test_self_required_location
481
+ util_make_gems
482
+
483
+ assert_equal File.join(@tempdir, *%w[gemhome gems c-1.2 lib code.rb]),
484
+ LibGems.required_location("c", "code.rb")
485
+ assert_equal File.join(@tempdir, *%w[gemhome gems a-1 lib code.rb]),
486
+ LibGems.required_location("a", "code.rb", "< 2")
487
+ assert_equal File.join(@tempdir, *%w[gemhome gems a-2 lib code.rb]),
488
+ LibGems.required_location("a", "code.rb", "= 2")
489
+ end
490
+
491
+ def test_self_ruby_escaping_spaces_in_path
492
+ orig_ruby = LibGems.ruby
493
+ orig_bindir = LibGems::ConfigMap[:bindir]
494
+ orig_ruby_install_name = LibGems::ConfigMap[:ruby_install_name]
495
+ orig_exe_ext = LibGems::ConfigMap[:EXEEXT]
496
+
497
+ LibGems::ConfigMap[:bindir] = "C:/Ruby 1.8/bin"
498
+ LibGems::ConfigMap[:ruby_install_name] = "ruby"
499
+ LibGems::ConfigMap[:EXEEXT] = ".exe"
500
+ LibGems.instance_variable_set("@ruby", nil)
501
+
502
+ assert_equal "\"C:/Ruby 1.8/bin/ruby.exe\"", LibGems.ruby
503
+ ensure
504
+ LibGems.instance_variable_set("@ruby", orig_ruby)
505
+ LibGems::ConfigMap[:bindir] = orig_bindir
506
+ LibGems::ConfigMap[:ruby_install_name] = orig_ruby_install_name
507
+ LibGems::ConfigMap[:EXEEXT] = orig_exe_ext
508
+ end
509
+
510
+ def test_self_ruby_path_without_spaces
511
+ orig_ruby = LibGems.ruby
512
+ orig_bindir = LibGems::ConfigMap[:bindir]
513
+ orig_ruby_install_name = LibGems::ConfigMap[:ruby_install_name]
514
+ orig_exe_ext = LibGems::ConfigMap[:EXEEXT]
515
+
516
+ LibGems::ConfigMap[:bindir] = "C:/Ruby18/bin"
517
+ LibGems::ConfigMap[:ruby_install_name] = "ruby"
518
+ LibGems::ConfigMap[:EXEEXT] = ".exe"
519
+ LibGems.instance_variable_set("@ruby", nil)
520
+
521
+ assert_equal "C:/Ruby18/bin/ruby.exe", LibGems.ruby
522
+ ensure
523
+ LibGems.instance_variable_set("@ruby", orig_ruby)
524
+ LibGems::ConfigMap[:bindir] = orig_bindir
525
+ LibGems::ConfigMap[:ruby_install_name] = orig_ruby_install_name
526
+ LibGems::ConfigMap[:EXEEXT] = orig_exe_ext
527
+ end
528
+
529
+ def test_self_ruby_version_1_8_5
530
+ util_set_RUBY_VERSION '1.8.5'
531
+
532
+ assert_equal LibGems::Version.new('1.8.5'), LibGems.ruby_version
533
+ ensure
534
+ util_restore_RUBY_VERSION
535
+ end
536
+
537
+ def test_self_ruby_version_1_8_6p287
538
+ util_set_RUBY_VERSION '1.8.6', 287
539
+
540
+ assert_equal LibGems::Version.new('1.8.6.287'), LibGems.ruby_version
541
+ ensure
542
+ util_restore_RUBY_VERSION
543
+ end
544
+
545
+ def test_self_ruby_version_1_9_2dev_r23493
546
+ util_set_RUBY_VERSION '1.9.2', -1, 23493
547
+
548
+ assert_equal LibGems::Version.new('1.9.2.dev.23493'), LibGems.ruby_version
549
+ ensure
550
+ util_restore_RUBY_VERSION
551
+ end
552
+
553
+ def test_self_searcher
554
+ assert_kind_of LibGems::GemPathSearcher, LibGems.searcher
555
+ end
556
+
557
+ def test_self_set_paths
558
+ other = File.join @tempdir, 'other'
559
+ path = [@userhome, other].join File::PATH_SEPARATOR
560
+ LibGems.send :set_paths, path
561
+
562
+ assert_equal [@userhome, other, @gemhome], LibGems.path
563
+ end
564
+
565
+ def test_self_set_paths_nonexistent_home
566
+ ENV['LIBGEMS_HOME'] = @gemhome
567
+ LibGems.clear_paths
568
+
569
+ other = File.join @tempdir, 'other'
570
+
571
+ ENV['HOME'] = other
572
+
573
+ LibGems.send :set_paths, other
574
+
575
+ assert_equal [other, @gemhome], LibGems.path
576
+ end
577
+
578
+ def test_self_source_index
579
+ assert_kind_of LibGems::SourceIndex, LibGems.source_index
580
+ end
581
+
582
+ def test_self_sources
583
+ assert_equal %w[http://gems.example.com/], LibGems.sources
584
+ end
585
+
586
+ def test_ssl_available_eh
587
+ orig_Gem_ssl_available = LibGems.ssl_available?
588
+
589
+ LibGems.ssl_available = true
590
+ assert_equal true, LibGems.ssl_available?
591
+
592
+ LibGems.ssl_available = false
593
+ assert_equal false, LibGems.ssl_available?
594
+ ensure
595
+ LibGems.ssl_available = orig_Gem_ssl_available
596
+ end
597
+
598
+ def test_self_use_paths
599
+ util_ensure_gem_dirs
600
+
601
+ LibGems.use_paths @gemhome, @additional
602
+
603
+ assert_equal @gemhome, LibGems.dir
604
+ assert_equal @additional + [LibGems.dir], LibGems.path
605
+ end
606
+
607
+ def test_self_user_dir
608
+ assert_equal File.join(@userhome, '.gem', LibGems.ruby_engine,
609
+ LibGems::ConfigMap[:ruby_version]), LibGems.user_dir
610
+ end
611
+
612
+ def test_self_user_home
613
+ if ENV['HOME'] then
614
+ assert_equal ENV['HOME'], LibGems.user_home
615
+ else
616
+ assert true, 'count this test'
617
+ end
618
+ end
619
+
620
+ if LibGems.win_platform? then
621
+ def test_self_user_home_userprofile
622
+ skip 'Ruby 1.9 properly handles ~ path expansion' unless '1.9' > RUBY_VERSION
623
+
624
+ LibGems.clear_paths
625
+
626
+ # safe-keep env variables
627
+ orig_home, orig_user_profile = ENV['HOME'], ENV['USERPROFILE']
628
+
629
+ # prepare for the test
630
+ ENV.delete('HOME')
631
+ ENV['USERPROFILE'] = "W:\\Users\\RubyUser"
632
+
633
+ assert_equal 'W:/Users/RubyUser', LibGems.user_home
634
+
635
+ ensure
636
+ ENV['HOME'] = orig_home
637
+ ENV['USERPROFILE'] = orig_user_profile
638
+ end
639
+
640
+ def test_self_user_home_user_drive_and_path
641
+ skip 'Ruby 1.9 properly handles ~ path expansion' unless '1.9' > RUBY_VERSION
642
+
643
+ LibGems.clear_paths
644
+
645
+ # safe-keep env variables
646
+ orig_home, orig_user_profile = ENV['HOME'], ENV['USERPROFILE']
647
+ orig_home_drive, orig_home_path = ENV['HOMEDRIVE'], ENV['HOMEPATH']
648
+
649
+ # prepare the environment
650
+ ENV.delete('HOME')
651
+ ENV.delete('USERPROFILE')
652
+ ENV['HOMEDRIVE'] = 'Z:'
653
+ ENV['HOMEPATH'] = "\\Users\\RubyUser"
654
+
655
+ assert_equal 'Z:/Users/RubyUser', LibGems.user_home
656
+
657
+ ensure
658
+ ENV['HOME'] = orig_home
659
+ ENV['USERPROFILE'] = orig_user_profile
660
+ ENV['HOMEDRIVE'] = orig_home_drive
661
+ ENV['HOMEPATH'] = orig_home_path
662
+ end
663
+ end
664
+
665
+ def test_load_plugins
666
+ ["libgems", "rubygems"].each do |type|
667
+ TestGem.send :remove_const, :TEST_SPEC_PLUGIN_LOAD if defined?(TEST_SPEC_PLUGIN_LOAD)
668
+
669
+ plugin_path = File.join "lib", "#{type}_plugin.rb"
670
+
671
+ Dir.chdir @tempdir do
672
+ FileUtils.mkdir_p 'lib'
673
+ File.open plugin_path, "w" do |fp|
674
+ fp.puts "TestGem::TEST_SPEC_PLUGIN_LOAD = :loaded"
675
+ end
676
+
677
+ foo = quick_gem "foo-#{type}", '1' do |s|
678
+ s.files << plugin_path
679
+ end
680
+
681
+ install_gem foo
682
+ end
683
+
684
+ LibGems.source_index = nil
685
+
686
+ gem "foo-#{type}"
687
+
688
+ LibGems.load_plugins
689
+
690
+ assert_equal :loaded, TEST_SPEC_PLUGIN_LOAD
691
+ end
692
+ end
693
+
694
+ def test_load_env_plugins
695
+ with_plugin('load') { LibGems.load_env_plugins }
696
+ assert_equal :loaded, TEST_PLUGIN_LOAD
697
+
698
+ util_remove_interrupt_command
699
+
700
+ # Should attempt to cause a StandardError
701
+ with_plugin('standarderror') { LibGems.load_env_plugins }
702
+ assert_equal :loaded, TEST_PLUGIN_STANDARDERROR
703
+
704
+ util_remove_interrupt_command
705
+
706
+ # Should attempt to cause an Exception
707
+ with_plugin('exception') { LibGems.load_env_plugins }
708
+ assert_equal :loaded, TEST_PLUGIN_EXCEPTION
709
+ end
710
+
711
+ def with_plugin(path)
712
+ test_plugin_path = File.expand_path "../plugin/#{path}", __FILE__
713
+
714
+ # A single test plugin should get loaded once only, in order to preserve
715
+ # sane test semantics.
716
+ refute_includes $LOAD_PATH, test_plugin_path
717
+ $LOAD_PATH.unshift test_plugin_path
718
+
719
+ capture_io do
720
+ yield
721
+ end
722
+ ensure
723
+ $LOAD_PATH.delete test_plugin_path
724
+ end
725
+
726
+ def util_ensure_gem_dirs
727
+ LibGems.ensure_gem_subdirectories @gemhome
728
+ @additional.each do |dir|
729
+ LibGems.ensure_gem_subdirectories @gemhome
730
+ end
731
+ end
732
+
733
+ def util_exec_gem
734
+ spec, _ = quick_gem 'a', '4' do |s|
735
+ s.default_executable = 'exec'
736
+ s.executables = ['exec', 'abin']
737
+ end
738
+
739
+ @exec_path = File.join spec.full_gem_path, spec.bindir, 'exec'
740
+ @abin_path = File.join spec.full_gem_path, spec.bindir, 'abin'
741
+ end
742
+
743
+ def util_set_RUBY_VERSION(version, patchlevel = nil, revision = nil)
744
+ if LibGems.instance_variables.include? :@ruby_version or
745
+ LibGems.instance_variables.include? '@ruby_version' then
746
+ LibGems.send :remove_instance_variable, :@ruby_version
747
+ end
748
+
749
+ @RUBY_VERSION = RUBY_VERSION
750
+ @RUBY_PATCHLEVEL = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
751
+ @RUBY_REVISION = RUBY_REVISION if defined?(RUBY_REVISION)
752
+
753
+ Object.send :remove_const, :RUBY_VERSION
754
+ Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
755
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
756
+
757
+ Object.const_set :RUBY_VERSION, version
758
+ Object.const_set :RUBY_PATCHLEVEL, patchlevel if patchlevel
759
+ Object.const_set :RUBY_REVISION, revision if revision
760
+ end
761
+
762
+ def util_restore_RUBY_VERSION
763
+ Object.send :remove_const, :RUBY_VERSION
764
+ Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
765
+ Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
766
+
767
+ Object.const_set :RUBY_VERSION, @RUBY_VERSION
768
+ Object.const_set :RUBY_PATCHLEVEL, @RUBY_PATCHLEVEL if
769
+ defined?(@RUBY_PATCHLEVEL)
770
+ Object.const_set :RUBY_REVISION, @RUBY_REVISION if
771
+ defined?(@RUBY_REVISION)
772
+ end
773
+
774
+ def util_remove_interrupt_command
775
+ LibGems::Commands.send :remove_const, :InterruptCommand if
776
+ LibGems::Commands.const_defined? :InterruptCommand
777
+ end
778
+
779
+ end
780
+