rubygems-update 3.4.21 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (564) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +132 -2
  3. data/Manifest.txt +39 -221
  4. data/README.md +1 -3
  5. data/bundler/CHANGELOG.md +74 -0
  6. data/bundler/README.md +1 -2
  7. data/bundler/bundler.gemspec +4 -2
  8. data/bundler/exe/bundle +1 -10
  9. data/bundler/lib/bundler/build_metadata.rb +3 -3
  10. data/bundler/lib/bundler/capistrano.rb +1 -1
  11. data/bundler/lib/bundler/checksum.rb +245 -0
  12. data/bundler/lib/bundler/ci_detector.rb +75 -0
  13. data/bundler/lib/bundler/cli/add.rb +3 -3
  14. data/bundler/lib/bundler/cli/binstubs.rb +4 -4
  15. data/bundler/lib/bundler/cli/cache.rb +1 -1
  16. data/bundler/lib/bundler/cli/check.rb +1 -1
  17. data/bundler/lib/bundler/cli/common.rb +9 -1
  18. data/bundler/lib/bundler/cli/config.rb +8 -7
  19. data/bundler/lib/bundler/cli/console.rb +3 -2
  20. data/bundler/lib/bundler/cli/doctor.rb +2 -2
  21. data/bundler/lib/bundler/cli/exec.rb +1 -1
  22. data/bundler/lib/bundler/cli/gem.rb +31 -23
  23. data/bundler/lib/bundler/cli/info.rb +2 -13
  24. data/bundler/lib/bundler/cli/install.rb +5 -4
  25. data/bundler/lib/bundler/cli/issue.rb +1 -1
  26. data/bundler/lib/bundler/cli/lock.rb +4 -4
  27. data/bundler/lib/bundler/cli/open.rb +1 -1
  28. data/bundler/lib/bundler/cli/outdated.rb +6 -6
  29. data/bundler/lib/bundler/cli/plugin.rb +7 -14
  30. data/bundler/lib/bundler/cli/pristine.rb +38 -30
  31. data/bundler/lib/bundler/cli/show.rb +2 -2
  32. data/bundler/lib/bundler/cli/update.rb +5 -5
  33. data/bundler/lib/bundler/cli.rb +215 -263
  34. data/bundler/lib/bundler/compact_index_client/cache.rb +29 -9
  35. data/bundler/lib/bundler/compact_index_client/cache_file.rb +153 -0
  36. data/bundler/lib/bundler/compact_index_client/gem_parser.rb +7 -3
  37. data/bundler/lib/bundler/compact_index_client/updater.rb +79 -81
  38. data/bundler/lib/bundler/compact_index_client.rb +14 -7
  39. data/bundler/lib/bundler/constants.rb +1 -1
  40. data/bundler/lib/bundler/current_ruby.rb +5 -21
  41. data/bundler/lib/bundler/definition.rb +43 -16
  42. data/bundler/lib/bundler/dependency.rb +16 -12
  43. data/bundler/lib/bundler/digest.rb +2 -2
  44. data/bundler/lib/bundler/dsl.rb +43 -25
  45. data/bundler/lib/bundler/endpoint_specification.rb +6 -2
  46. data/bundler/lib/bundler/env.rb +1 -3
  47. data/bundler/lib/bundler/errors.rb +58 -0
  48. data/bundler/lib/bundler/fetcher/base.rb +3 -1
  49. data/bundler/lib/bundler/fetcher/compact_index.rb +4 -4
  50. data/bundler/lib/bundler/fetcher/downloader.rb +13 -11
  51. data/bundler/lib/bundler/fetcher/gem_remote_fetcher.rb +16 -0
  52. data/bundler/lib/bundler/fetcher/index.rb +1 -1
  53. data/bundler/lib/bundler/fetcher.rb +28 -25
  54. data/bundler/lib/bundler/friendly_errors.rb +5 -5
  55. data/bundler/lib/bundler/gem_helper.rb +1 -1
  56. data/bundler/lib/bundler/gem_helpers.rb +12 -2
  57. data/bundler/lib/bundler/graph.rb +9 -9
  58. data/bundler/lib/bundler/index.rb +1 -2
  59. data/bundler/lib/bundler/injector.rb +1 -1
  60. data/bundler/lib/bundler/inline.rb +3 -3
  61. data/bundler/lib/bundler/installer/gem_installer.rb +10 -10
  62. data/bundler/lib/bundler/installer/parallel_installer.rb +16 -8
  63. data/bundler/lib/bundler/installer/standalone.rb +2 -3
  64. data/bundler/lib/bundler/installer.rb +9 -9
  65. data/bundler/lib/bundler/lazy_specification.rb +28 -17
  66. data/bundler/lib/bundler/lockfile_generator.rb +9 -0
  67. data/bundler/lib/bundler/lockfile_parser.rb +81 -10
  68. data/bundler/lib/bundler/man/bundle-add.1 +3 -26
  69. data/bundler/lib/bundler/man/bundle-binstubs.1 +4 -16
  70. data/bundler/lib/bundler/man/bundle-cache.1 +3 -24
  71. data/bundler/lib/bundler/man/bundle-check.1 +3 -12
  72. data/bundler/lib/bundler/man/bundle-clean.1 +3 -10
  73. data/bundler/lib/bundler/man/bundle-config.1 +20 -211
  74. data/bundler/lib/bundler/man/bundle-config.1.ronn +6 -0
  75. data/bundler/lib/bundler/man/bundle-console.1 +4 -22
  76. data/bundler/lib/bundler/man/bundle-doctor.1 +4 -18
  77. data/bundler/lib/bundler/man/bundle-exec.1 +12 -73
  78. data/bundler/lib/bundler/man/bundle-gem.1 +13 -49
  79. data/bundler/lib/bundler/man/bundle-help.1 +3 -7
  80. data/bundler/lib/bundler/man/bundle-info.1 +3 -9
  81. data/bundler/lib/bundler/man/bundle-init.1 +3 -12
  82. data/bundler/lib/bundler/man/bundle-inject.1 +6 -19
  83. data/bundler/lib/bundler/man/bundle-install.1 +27 -125
  84. data/bundler/lib/bundler/man/bundle-install.1.ronn +1 -0
  85. data/bundler/lib/bundler/man/bundle-list.1 +4 -19
  86. data/bundler/lib/bundler/man/bundle-lock.1 +5 -29
  87. data/bundler/lib/bundler/man/bundle-open.1 +7 -27
  88. data/bundler/lib/bundler/man/bundle-outdated.1 +3 -55
  89. data/bundler/lib/bundler/man/bundle-outdated.1.ronn +1 -0
  90. data/bundler/lib/bundler/man/bundle-platform.1 +5 -27
  91. data/bundler/lib/bundler/man/bundle-plugin.1 +3 -29
  92. data/bundler/lib/bundler/man/bundle-pristine.1 +5 -16
  93. data/bundler/lib/bundler/man/bundle-remove.1 +4 -14
  94. data/bundler/lib/bundler/man/bundle-show.1 +3 -10
  95. data/bundler/lib/bundler/man/bundle-update.1 +18 -137
  96. data/bundler/lib/bundler/man/bundle-version.1 +3 -16
  97. data/bundler/lib/bundler/man/bundle-viz.1 +4 -16
  98. data/bundler/lib/bundler/man/bundle.1 +5 -44
  99. data/bundler/lib/bundler/man/gemfile.5 +24 -301
  100. data/bundler/lib/bundler/man/gemfile.5.ronn +4 -0
  101. data/bundler/lib/bundler/match_metadata.rb +4 -0
  102. data/bundler/lib/bundler/match_platform.rb +1 -1
  103. data/bundler/lib/bundler/plugin/api/source.rb +3 -2
  104. data/bundler/lib/bundler/plugin/index.rb +8 -0
  105. data/bundler/lib/bundler/plugin/installer.rb +1 -1
  106. data/bundler/lib/bundler/plugin.rb +12 -5
  107. data/bundler/lib/bundler/resolver/base.rb +1 -1
  108. data/bundler/lib/bundler/resolver/incompatibility.rb +1 -1
  109. data/bundler/lib/bundler/resolver/spec_group.rb +1 -4
  110. data/bundler/lib/bundler/resolver.rb +16 -16
  111. data/bundler/lib/bundler/ruby_dsl.rb +20 -12
  112. data/bundler/lib/bundler/ruby_version.rb +1 -1
  113. data/bundler/lib/bundler/rubygems_ext.rb +27 -54
  114. data/bundler/lib/bundler/rubygems_gem_installer.rb +23 -58
  115. data/bundler/lib/bundler/rubygems_integration.rb +25 -94
  116. data/bundler/lib/bundler/runtime.rb +2 -2
  117. data/bundler/lib/bundler/self_manager.rb +23 -7
  118. data/bundler/lib/bundler/settings.rb +27 -7
  119. data/bundler/lib/bundler/setup.rb +4 -1
  120. data/bundler/lib/bundler/shared_helpers.rb +35 -13
  121. data/bundler/lib/bundler/source/git/git_proxy.rb +22 -14
  122. data/bundler/lib/bundler/source/git.rb +4 -3
  123. data/bundler/lib/bundler/source/metadata.rb +16 -16
  124. data/bundler/lib/bundler/source/path.rb +7 -6
  125. data/bundler/lib/bundler/source/rubygems.rb +21 -14
  126. data/bundler/lib/bundler/source.rb +2 -0
  127. data/bundler/lib/bundler/spec_set.rb +43 -12
  128. data/bundler/lib/bundler/stub_specification.rb +1 -0
  129. data/bundler/lib/bundler/templates/Executable.bundler +1 -1
  130. data/bundler/lib/bundler/templates/newgem/README.md.tt +3 -3
  131. data/bundler/lib/bundler/templates/newgem/Rakefile.tt +2 -6
  132. data/bundler/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt +1 -1
  133. data/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt +1 -1
  134. data/bundler/lib/bundler/templates/newgem/standard.yml.tt +1 -1
  135. data/bundler/lib/bundler/ui/shell.rb +2 -2
  136. data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb +1 -1
  137. data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +53 -6
  138. data/bundler/lib/bundler/vendor/fileutils/lib/fileutils.rb +8 -20
  139. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb +4 -3
  140. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb +23 -11
  141. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb +1 -1
  142. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +36 -36
  143. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +3 -2
  144. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +1 -1
  145. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb +1 -1
  146. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +8 -10
  147. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +15 -4
  148. data/bundler/lib/bundler/vendor/thor/lib/thor/actions.rb +15 -15
  149. data/bundler/lib/bundler/vendor/thor/lib/thor/base.rb +140 -14
  150. data/bundler/lib/bundler/vendor/thor/lib/thor/command.rb +13 -4
  151. data/bundler/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +4 -0
  152. data/bundler/lib/bundler/vendor/thor/lib/thor/error.rb +16 -25
  153. data/bundler/lib/bundler/vendor/thor/lib/thor/group.rb +1 -1
  154. data/bundler/lib/bundler/vendor/thor/lib/thor/invocation.rb +1 -1
  155. data/bundler/lib/bundler/vendor/thor/lib/thor/nested_context.rb +2 -2
  156. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/argument.rb +20 -1
  157. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +33 -17
  158. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/option.rb +27 -8
  159. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/options.rb +44 -6
  160. data/bundler/lib/bundler/vendor/thor/lib/thor/rake_compat.rb +2 -2
  161. data/bundler/lib/bundler/vendor/thor/lib/thor/runner.rb +40 -30
  162. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +26 -150
  163. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/color.rb +4 -46
  164. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb +29 -0
  165. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/html.rb +3 -45
  166. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/lcs_diff.rb +49 -0
  167. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/table_printer.rb +134 -0
  168. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/terminal.rb +42 -0
  169. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb +38 -0
  170. data/bundler/lib/bundler/vendor/thor/lib/thor/shell.rb +1 -1
  171. data/bundler/lib/bundler/vendor/thor/lib/thor/util.rb +8 -7
  172. data/bundler/lib/bundler/vendor/thor/lib/thor/version.rb +1 -1
  173. data/bundler/lib/bundler/vendor/thor/lib/thor.rb +155 -8
  174. data/bundler/lib/bundler/vendor/tsort/lib/tsort.rb +3 -0
  175. data/bundler/lib/bundler/vendor/uri/lib/uri/common.rb +256 -132
  176. data/bundler/lib/bundler/vendor/uri/lib/uri/generic.rb +1 -0
  177. data/bundler/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +95 -31
  178. data/bundler/lib/bundler/vendor/uri/lib/uri/version.rb +1 -1
  179. data/bundler/lib/bundler/vendored_net_http.rb +8 -0
  180. data/bundler/lib/bundler/vendored_persistent.rb +0 -4
  181. data/bundler/lib/bundler/vendored_timeout.rb +8 -0
  182. data/bundler/lib/bundler/version.rb +1 -1
  183. data/bundler/lib/bundler/vlad.rb +1 -1
  184. data/bundler/lib/bundler/yaml_serializer.rb +9 -4
  185. data/bundler/lib/bundler.rb +38 -35
  186. data/lib/rubygems/available_set.rb +4 -4
  187. data/lib/rubygems/basic_specification.rb +35 -37
  188. data/lib/rubygems/bundler_version_finder.rb +4 -4
  189. data/lib/rubygems/ci_detector.rb +75 -0
  190. data/lib/rubygems/command.rb +15 -17
  191. data/lib/rubygems/command_manager.rb +5 -4
  192. data/lib/rubygems/commands/build_command.rb +2 -2
  193. data/lib/rubygems/commands/cert_command.rb +2 -3
  194. data/lib/rubygems/commands/check_command.rb +4 -4
  195. data/lib/rubygems/commands/cleanup_command.rb +12 -14
  196. data/lib/rubygems/commands/contents_command.rb +5 -5
  197. data/lib/rubygems/commands/dependency_command.rb +4 -5
  198. data/lib/rubygems/commands/environment_command.rb +3 -5
  199. data/lib/rubygems/commands/exec_command.rb +1 -1
  200. data/lib/rubygems/commands/fetch_command.rb +2 -2
  201. data/lib/rubygems/commands/generate_index_command.rb +39 -74
  202. data/lib/rubygems/commands/help_command.rb +4 -4
  203. data/lib/rubygems/commands/info_command.rb +2 -2
  204. data/lib/rubygems/commands/install_command.rb +8 -16
  205. data/lib/rubygems/commands/list_command.rb +2 -2
  206. data/lib/rubygems/commands/lock_command.rb +1 -1
  207. data/lib/rubygems/commands/open_command.rb +1 -1
  208. data/lib/rubygems/commands/owner_command.rb +1 -1
  209. data/lib/rubygems/commands/pristine_command.rb +13 -15
  210. data/lib/rubygems/commands/push_command.rb +2 -2
  211. data/lib/rubygems/commands/query_command.rb +4 -5
  212. data/lib/rubygems/commands/rdoc_command.rb +2 -2
  213. data/lib/rubygems/commands/search_command.rb +2 -2
  214. data/lib/rubygems/commands/setup_command.rb +33 -36
  215. data/lib/rubygems/commands/sources_command.rb +12 -12
  216. data/lib/rubygems/commands/specification_command.rb +10 -10
  217. data/lib/rubygems/commands/stale_command.rb +1 -1
  218. data/lib/rubygems/commands/uninstall_command.rb +13 -14
  219. data/lib/rubygems/commands/unpack_command.rb +7 -7
  220. data/lib/rubygems/commands/update_command.rb +11 -13
  221. data/lib/rubygems/commands/which_command.rb +1 -1
  222. data/lib/rubygems/commands/yank_command.rb +1 -1
  223. data/lib/rubygems/compatibility.rb +5 -6
  224. data/lib/rubygems/config_file.rb +7 -7
  225. data/lib/rubygems/core_ext/kernel_gem.rb +0 -2
  226. data/lib/rubygems/core_ext/kernel_require.rb +20 -49
  227. data/lib/rubygems/core_ext/kernel_warn.rb +1 -1
  228. data/lib/rubygems/core_ext/tcpsocket_init.rb +1 -1
  229. data/lib/rubygems/defaults.rb +15 -3
  230. data/lib/rubygems/dependency.rb +12 -14
  231. data/lib/rubygems/dependency_installer.rb +30 -31
  232. data/lib/rubygems/dependency_list.rb +1 -1
  233. data/lib/rubygems/deprecate.rb +16 -15
  234. data/lib/rubygems/doctor.rb +6 -6
  235. data/lib/rubygems/errors.rb +2 -6
  236. data/lib/rubygems/exceptions.rb +2 -1
  237. data/lib/rubygems/ext/builder.rb +15 -10
  238. data/lib/rubygems/ext/cargo_builder.rb +5 -5
  239. data/lib/rubygems/ext/ext_conf_builder.rb +2 -4
  240. data/lib/rubygems/ext/rake_builder.rb +1 -1
  241. data/lib/rubygems/gem_runner.rb +4 -4
  242. data/lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb +3 -3
  243. data/lib/rubygems/gemcutter_utilities/webauthn_poller.rb +3 -3
  244. data/lib/rubygems/gemcutter_utilities.rb +18 -19
  245. data/lib/rubygems/install_update_options.rb +18 -19
  246. data/lib/rubygems/installer.rb +66 -45
  247. data/lib/rubygems/installer_uninstaller_utils.rb +0 -2
  248. data/lib/rubygems/local_remote_options.rb +8 -11
  249. data/lib/rubygems/name_tuple.rb +7 -9
  250. data/lib/rubygems/net/http.rb +3 -0
  251. data/lib/rubygems/net-http/LICENSE.txt +22 -0
  252. data/lib/rubygems/net-http/lib/net/http/backward.rb +40 -0
  253. data/lib/rubygems/net-http/lib/net/http/exceptions.rb +34 -0
  254. data/lib/rubygems/net-http/lib/net/http/generic_request.rb +414 -0
  255. data/lib/rubygems/net-http/lib/net/http/header.rb +981 -0
  256. data/lib/rubygems/net-http/lib/net/http/proxy_delta.rb +17 -0
  257. data/lib/rubygems/net-http/lib/net/http/request.rb +88 -0
  258. data/lib/rubygems/net-http/lib/net/http/requests.rb +425 -0
  259. data/lib/rubygems/net-http/lib/net/http/response.rb +738 -0
  260. data/lib/rubygems/net-http/lib/net/http/responses.rb +1174 -0
  261. data/lib/rubygems/net-http/lib/net/http/status.rb +84 -0
  262. data/lib/rubygems/net-http/lib/net/http.rb +2496 -0
  263. data/lib/rubygems/net-http/lib/net/https.rb +23 -0
  264. data/lib/rubygems/net-protocol/LICENSE.txt +22 -0
  265. data/lib/rubygems/net-protocol/lib/net/protocol.rb +544 -0
  266. data/lib/rubygems/optparse/lib/optparse.rb +39 -17
  267. data/lib/rubygems/package/digest_io.rb +1 -1
  268. data/lib/rubygems/package/old.rb +2 -2
  269. data/lib/rubygems/package/tar_header.rb +45 -39
  270. data/lib/rubygems/package/tar_reader/entry.rb +5 -4
  271. data/lib/rubygems/package/tar_reader.rb +14 -5
  272. data/lib/rubygems/package/tar_writer.rb +20 -18
  273. data/lib/rubygems/package.rb +28 -27
  274. data/lib/rubygems/package_task.rb +2 -2
  275. data/lib/rubygems/path_support.rb +10 -11
  276. data/lib/rubygems/platform.rb +65 -48
  277. data/lib/rubygems/query_utils.rb +7 -9
  278. data/lib/rubygems/remote_fetcher.rb +17 -17
  279. data/lib/rubygems/request/connection_pools.rb +3 -3
  280. data/lib/rubygems/request.rb +20 -17
  281. data/lib/rubygems/request_set/gem_dependency_api.rb +120 -123
  282. data/lib/rubygems/request_set/lockfile/parser.rb +9 -9
  283. data/lib/rubygems/request_set/lockfile/tokenizer.rb +20 -12
  284. data/lib/rubygems/request_set/lockfile.rb +6 -11
  285. data/lib/rubygems/request_set.rb +5 -5
  286. data/lib/rubygems/requirement.rb +7 -7
  287. data/lib/rubygems/resolv/LICENSE.txt +22 -0
  288. data/lib/rubygems/resolv/lib/resolv.rb +3387 -0
  289. data/lib/rubygems/resolver/activation_request.rb +1 -3
  290. data/lib/rubygems/resolver/api_set/gem_parser.rb +7 -3
  291. data/lib/rubygems/resolver/best_set.rb +1 -1
  292. data/lib/rubygems/resolver/composed_set.rb +1 -1
  293. data/lib/rubygems/resolver/conflict.rb +4 -12
  294. data/lib/rubygems/resolver/index_set.rb +4 -4
  295. data/lib/rubygems/resolver/index_specification.rb +2 -2
  296. data/lib/rubygems/resolver/installer_set.rb +5 -6
  297. data/lib/rubygems/resolver/lock_set.rb +1 -1
  298. data/lib/rubygems/resolver.rb +6 -13
  299. data/lib/rubygems/s3_uri_signer.rb +6 -6
  300. data/lib/rubygems/safe_marshal/elements.rb +138 -0
  301. data/lib/rubygems/safe_marshal/reader.rb +306 -0
  302. data/lib/rubygems/safe_marshal/visitors/stream_printer.rb +31 -0
  303. data/lib/rubygems/safe_marshal/visitors/to_ruby.rb +385 -0
  304. data/lib/rubygems/safe_marshal/visitors/visitor.rb +74 -0
  305. data/lib/rubygems/safe_marshal.rb +74 -0
  306. data/lib/rubygems/safe_yaml.rb +5 -28
  307. data/lib/rubygems/security/policies.rb +36 -38
  308. data/lib/rubygems/security/policy.rb +7 -11
  309. data/lib/rubygems/security/signer.rb +1 -1
  310. data/lib/rubygems/security/trust_dir.rb +4 -4
  311. data/lib/rubygems/security.rb +8 -22
  312. data/lib/rubygems/source/git.rb +1 -3
  313. data/lib/rubygems/source/installed.rb +0 -2
  314. data/lib/rubygems/source/local.rb +7 -9
  315. data/lib/rubygems/source/lock.rb +1 -3
  316. data/lib/rubygems/source/specific_file.rb +0 -1
  317. data/lib/rubygems/source/vendor.rb +0 -2
  318. data/lib/rubygems/source.rb +12 -12
  319. data/lib/rubygems/source_list.rb +5 -5
  320. data/lib/rubygems/spec_fetcher.rb +31 -31
  321. data/lib/rubygems/specification.rb +145 -150
  322. data/lib/rubygems/specification_policy.rb +61 -31
  323. data/lib/rubygems/stub_specification.rb +4 -5
  324. data/lib/rubygems/text.rb +1 -2
  325. data/lib/rubygems/timeout/LICENSE.txt +22 -0
  326. data/lib/rubygems/timeout/lib/timeout.rb +199 -0
  327. data/lib/rubygems/timeout.rb +3 -0
  328. data/lib/rubygems/tsort/lib/tsort.rb +3 -0
  329. data/lib/rubygems/uninstaller.rb +9 -11
  330. data/lib/rubygems/update_suggestion.rb +5 -18
  331. data/lib/rubygems/uri_formatter.rb +1 -1
  332. data/lib/rubygems/user_interaction.rb +17 -23
  333. data/lib/rubygems/util/licenses.rb +113 -35
  334. data/lib/rubygems/util/list.rb +3 -1
  335. data/lib/rubygems/util.rb +2 -4
  336. data/lib/rubygems/validator.rb +6 -4
  337. data/lib/rubygems/version.rb +35 -29
  338. data/lib/rubygems/version_option.rb +2 -5
  339. data/lib/rubygems/yaml_serializer.rb +9 -4
  340. data/lib/rubygems.rb +42 -42
  341. data/rubygems-update.gemspec +4 -4
  342. data/setup.rb +2 -2
  343. metadata +43 -225
  344. data/lib/rubygems/indexer.rb +0 -428
  345. data/lib/rubygems/mock_gem_ui.rb +0 -86
  346. data/test/rubygems/alternate_cert.pem +0 -19
  347. data/test/rubygems/alternate_cert_32.pem +0 -19
  348. data/test/rubygems/alternate_key.pem +0 -27
  349. data/test/rubygems/bad_rake.rb +0 -3
  350. data/test/rubygems/bundler_test_gem.rb +0 -424
  351. data/test/rubygems/ca_cert.pem +0 -77
  352. data/test/rubygems/child_cert.pem +0 -19
  353. data/test/rubygems/child_cert_32.pem +0 -19
  354. data/test/rubygems/child_key.pem +0 -27
  355. data/test/rubygems/client.pem +0 -107
  356. data/test/rubygems/data/excon-0.7.7.gemspec.rz +0 -0
  357. data/test/rubygems/data/gem-private_key.pem +0 -27
  358. data/test/rubygems/data/gem-public_cert.pem +0 -20
  359. data/test/rubygems/data/null-required-ruby-version.gemspec.rz +0 -0
  360. data/test/rubygems/data/null-required-rubygems-version.gemspec.rz +0 -0
  361. data/test/rubygems/data/pry-0.4.7.gemspec.rz +0 -0
  362. data/test/rubygems/encrypted_private_key.pem +0 -30
  363. data/test/rubygems/expired_cert.pem +0 -19
  364. data/test/rubygems/fake_certlib/openssl.rb +0 -9
  365. data/test/rubygems/foo/discover.rb +0 -1
  366. data/test/rubygems/future_cert.pem +0 -19
  367. data/test/rubygems/future_cert_32.pem +0 -19
  368. data/test/rubygems/good_rake.rb +0 -3
  369. data/test/rubygems/grandchild_cert.pem +0 -19
  370. data/test/rubygems/grandchild_cert_32.pem +0 -19
  371. data/test/rubygems/grandchild_key.pem +0 -27
  372. data/test/rubygems/helper.rb +0 -1649
  373. data/test/rubygems/installer_test_case.rb +0 -248
  374. data/test/rubygems/invalid_client.pem +0 -49
  375. data/test/rubygems/invalid_issuer_cert.pem +0 -20
  376. data/test/rubygems/invalid_issuer_cert_32.pem +0 -20
  377. data/test/rubygems/invalid_key.pem +0 -27
  378. data/test/rubygems/invalid_signer_cert.pem +0 -19
  379. data/test/rubygems/invalid_signer_cert_32.pem +0 -19
  380. data/test/rubygems/invalidchild_cert.pem +0 -19
  381. data/test/rubygems/invalidchild_cert_32.pem +0 -19
  382. data/test/rubygems/invalidchild_key.pem +0 -27
  383. data/test/rubygems/multifactor_auth_utilities.rb +0 -111
  384. data/test/rubygems/package/tar_test_case.rb +0 -175
  385. data/test/rubygems/packages/Bluebie-legs-0.6.2.gem +0 -0
  386. data/test/rubygems/packages/ascii_binder-0.1.10.1.gem +0 -0
  387. data/test/rubygems/packages/ill-formatted-platform-1.0.0.10.gem +0 -0
  388. data/test/rubygems/plugin/exception/rubygems_plugin.rb +0 -4
  389. data/test/rubygems/plugin/load/rubygems_plugin.rb +0 -5
  390. data/test/rubygems/plugin/standarderror/rubygems_plugin.rb +0 -4
  391. data/test/rubygems/private3072_key.pem +0 -40
  392. data/test/rubygems/private_ec_key.pem +0 -9
  393. data/test/rubygems/private_key.pem +0 -27
  394. data/test/rubygems/public3072_cert.pem +0 -25
  395. data/test/rubygems/public_cert.pem +0 -20
  396. data/test/rubygems/public_cert_32.pem +0 -19
  397. data/test/rubygems/public_key.pem +0 -9
  398. data/test/rubygems/rubygems/commands/crash_command.rb +0 -5
  399. data/test/rubygems/rubygems_plugin.rb +0 -24
  400. data/test/rubygems/sff/discover.rb +0 -1
  401. data/test/rubygems/simple_gem.rb +0 -68
  402. data/test/rubygems/specifications/bar-0.0.2.gemspec +0 -9
  403. data/test/rubygems/specifications/foo-0.0.1-x86-mswin32.gemspec +0 -0
  404. data/test/rubygems/specifications/rubyforge-0.0.1.gemspec +0 -14
  405. data/test/rubygems/ssl_cert.pem +0 -80
  406. data/test/rubygems/ssl_key.pem +0 -27
  407. data/test/rubygems/test_bundled_ca.rb +0 -61
  408. data/test/rubygems/test_config.rb +0 -28
  409. data/test/rubygems/test_deprecate.rb +0 -158
  410. data/test/rubygems/test_exit.rb +0 -17
  411. data/test/rubygems/test_gem.rb +0 -1799
  412. data/test/rubygems/test_gem_available_set.rb +0 -130
  413. data/test/rubygems/test_gem_bundler_version_finder.rb +0 -127
  414. data/test/rubygems/test_gem_command.rb +0 -403
  415. data/test/rubygems/test_gem_command_manager.rb +0 -400
  416. data/test/rubygems/test_gem_commands_build_command.rb +0 -739
  417. data/test/rubygems/test_gem_commands_cert_command.rb +0 -866
  418. data/test/rubygems/test_gem_commands_check_command.rb +0 -68
  419. data/test/rubygems/test_gem_commands_cleanup_command.rb +0 -292
  420. data/test/rubygems/test_gem_commands_contents_command.rb +0 -271
  421. data/test/rubygems/test_gem_commands_dependency_command.rb +0 -228
  422. data/test/rubygems/test_gem_commands_environment_command.rb +0 -169
  423. data/test/rubygems/test_gem_commands_exec_command.rb +0 -857
  424. data/test/rubygems/test_gem_commands_fetch_command.rb +0 -258
  425. data/test/rubygems/test_gem_commands_generate_index_command.rb +0 -81
  426. data/test/rubygems/test_gem_commands_help_command.rb +0 -94
  427. data/test/rubygems/test_gem_commands_info_command.rb +0 -70
  428. data/test/rubygems/test_gem_commands_install_command.rb +0 -1573
  429. data/test/rubygems/test_gem_commands_list_command.rb +0 -33
  430. data/test/rubygems/test_gem_commands_lock_command.rb +0 -67
  431. data/test/rubygems/test_gem_commands_mirror.rb +0 -20
  432. data/test/rubygems/test_gem_commands_open_command.rb +0 -101
  433. data/test/rubygems/test_gem_commands_outdated_command.rb +0 -50
  434. data/test/rubygems/test_gem_commands_owner_command.rb +0 -503
  435. data/test/rubygems/test_gem_commands_pristine_command.rb +0 -708
  436. data/test/rubygems/test_gem_commands_push_command.rb +0 -603
  437. data/test/rubygems/test_gem_commands_query_command.rb +0 -858
  438. data/test/rubygems/test_gem_commands_search_command.rb +0 -16
  439. data/test/rubygems/test_gem_commands_server_command.rb +0 -20
  440. data/test/rubygems/test_gem_commands_setup_command.rb +0 -474
  441. data/test/rubygems/test_gem_commands_signin_command.rb +0 -259
  442. data/test/rubygems/test_gem_commands_signout_command.rb +0 -30
  443. data/test/rubygems/test_gem_commands_sources_command.rb +0 -534
  444. data/test/rubygems/test_gem_commands_specification_command.rb +0 -277
  445. data/test/rubygems/test_gem_commands_stale_command.rb +0 -43
  446. data/test/rubygems/test_gem_commands_uninstall_command.rb +0 -522
  447. data/test/rubygems/test_gem_commands_unpack_command.rb +0 -224
  448. data/test/rubygems/test_gem_commands_update_command.rb +0 -836
  449. data/test/rubygems/test_gem_commands_which_command.rb +0 -85
  450. data/test/rubygems/test_gem_commands_yank_command.rb +0 -299
  451. data/test/rubygems/test_gem_config_file.rb +0 -551
  452. data/test/rubygems/test_gem_dependency.rb +0 -398
  453. data/test/rubygems/test_gem_dependency_installer.rb +0 -1190
  454. data/test/rubygems/test_gem_dependency_list.rb +0 -265
  455. data/test/rubygems/test_gem_dependency_resolution_error.rb +0 -27
  456. data/test/rubygems/test_gem_doctor.rb +0 -195
  457. data/test/rubygems/test_gem_ext_builder.rb +0 -337
  458. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/.gitignore +0 -1
  459. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec +0 -10
  460. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.lock +0 -249
  461. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.toml +0 -10
  462. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/src/lib.rs +0 -27
  463. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/lib/custom_name.rb +0 -3
  464. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/.gitignore +0 -1
  465. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.lock +0 -249
  466. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.toml +0 -10
  467. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/rust_ruby_example.gemspec +0 -10
  468. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/src/lib.rs +0 -51
  469. data/test/rubygems/test_gem_ext_cargo_builder.rb +0 -167
  470. data/test/rubygems/test_gem_ext_cargo_builder_link_flag_converter.rb +0 -34
  471. data/test/rubygems/test_gem_ext_cargo_builder_unit.rb +0 -60
  472. data/test/rubygems/test_gem_ext_cmake_builder.rb +0 -84
  473. data/test/rubygems/test_gem_ext_configure_builder.rb +0 -80
  474. data/test/rubygems/test_gem_ext_ext_conf_builder.rb +0 -229
  475. data/test/rubygems/test_gem_ext_rake_builder.rb +0 -113
  476. data/test/rubygems/test_gem_gem_runner.rb +0 -119
  477. data/test/rubygems/test_gem_gemcutter_utilities.rb +0 -361
  478. data/test/rubygems/test_gem_impossible_dependencies_error.rb +0 -60
  479. data/test/rubygems/test_gem_indexer.rb +0 -381
  480. data/test/rubygems/test_gem_install_update_options.rb +0 -208
  481. data/test/rubygems/test_gem_installer.rb +0 -2512
  482. data/test/rubygems/test_gem_local_remote_options.rb +0 -133
  483. data/test/rubygems/test_gem_name_tuple.rb +0 -43
  484. data/test/rubygems/test_gem_package.rb +0 -1306
  485. data/test/rubygems/test_gem_package_old.rb +0 -91
  486. data/test/rubygems/test_gem_package_tar_header.rb +0 -226
  487. data/test/rubygems/test_gem_package_tar_reader.rb +0 -135
  488. data/test/rubygems/test_gem_package_tar_reader_entry.rb +0 -350
  489. data/test/rubygems/test_gem_package_tar_writer.rb +0 -331
  490. data/test/rubygems/test_gem_package_task.rb +0 -118
  491. data/test/rubygems/test_gem_path_support.rb +0 -139
  492. data/test/rubygems/test_gem_platform.rb +0 -497
  493. data/test/rubygems/test_gem_rdoc.rb +0 -137
  494. data/test/rubygems/test_gem_remote_fetcher.rb +0 -1227
  495. data/test/rubygems/test_gem_request.rb +0 -547
  496. data/test/rubygems/test_gem_request_connection_pools.rb +0 -152
  497. data/test/rubygems/test_gem_request_set.rb +0 -672
  498. data/test/rubygems/test_gem_request_set_gem_dependency_api.rb +0 -853
  499. data/test/rubygems/test_gem_request_set_lockfile.rb +0 -469
  500. data/test/rubygems/test_gem_request_set_lockfile_parser.rb +0 -544
  501. data/test/rubygems/test_gem_request_set_lockfile_tokenizer.rb +0 -307
  502. data/test/rubygems/test_gem_requirement.rb +0 -505
  503. data/test/rubygems/test_gem_resolver.rb +0 -859
  504. data/test/rubygems/test_gem_resolver_activation_request.rb +0 -43
  505. data/test/rubygems/test_gem_resolver_api_set.rb +0 -210
  506. data/test/rubygems/test_gem_resolver_api_specification.rb +0 -167
  507. data/test/rubygems/test_gem_resolver_best_set.rb +0 -159
  508. data/test/rubygems/test_gem_resolver_composed_set.rb +0 -44
  509. data/test/rubygems/test_gem_resolver_conflict.rb +0 -82
  510. data/test/rubygems/test_gem_resolver_dependency_request.rb +0 -83
  511. data/test/rubygems/test_gem_resolver_git_set.rb +0 -188
  512. data/test/rubygems/test_gem_resolver_git_specification.rb +0 -114
  513. data/test/rubygems/test_gem_resolver_index_set.rb +0 -88
  514. data/test/rubygems/test_gem_resolver_index_specification.rb +0 -93
  515. data/test/rubygems/test_gem_resolver_installed_specification.rb +0 -47
  516. data/test/rubygems/test_gem_resolver_installer_set.rb +0 -320
  517. data/test/rubygems/test_gem_resolver_local_specification.rb +0 -44
  518. data/test/rubygems/test_gem_resolver_lock_set.rb +0 -62
  519. data/test/rubygems/test_gem_resolver_lock_specification.rb +0 -98
  520. data/test/rubygems/test_gem_resolver_requirement_list.rb +0 -19
  521. data/test/rubygems/test_gem_resolver_specification.rb +0 -63
  522. data/test/rubygems/test_gem_resolver_vendor_set.rb +0 -82
  523. data/test/rubygems/test_gem_resolver_vendor_specification.rb +0 -82
  524. data/test/rubygems/test_gem_security.rb +0 -341
  525. data/test/rubygems/test_gem_security_policy.rb +0 -535
  526. data/test/rubygems/test_gem_security_signer.rb +0 -218
  527. data/test/rubygems/test_gem_security_trust_dir.rb +0 -99
  528. data/test/rubygems/test_gem_silent_ui.rb +0 -123
  529. data/test/rubygems/test_gem_source.rb +0 -254
  530. data/test/rubygems/test_gem_source_fetch_problem.rb +0 -37
  531. data/test/rubygems/test_gem_source_git.rb +0 -310
  532. data/test/rubygems/test_gem_source_installed.rb +0 -35
  533. data/test/rubygems/test_gem_source_list.rb +0 -119
  534. data/test/rubygems/test_gem_source_local.rb +0 -107
  535. data/test/rubygems/test_gem_source_lock.rb +0 -113
  536. data/test/rubygems/test_gem_source_specific_file.rb +0 -76
  537. data/test/rubygems/test_gem_source_subpath_problem.rb +0 -50
  538. data/test/rubygems/test_gem_source_vendor.rb +0 -30
  539. data/test/rubygems/test_gem_spec_fetcher.rb +0 -338
  540. data/test/rubygems/test_gem_specification.rb +0 -3856
  541. data/test/rubygems/test_gem_stream_ui.rb +0 -255
  542. data/test/rubygems/test_gem_stub_specification.rb +0 -278
  543. data/test/rubygems/test_gem_text.rb +0 -103
  544. data/test/rubygems/test_gem_uninstaller.rb +0 -675
  545. data/test/rubygems/test_gem_unsatisfiable_dependency_error.rb +0 -31
  546. data/test/rubygems/test_gem_update_suggestion.rb +0 -209
  547. data/test/rubygems/test_gem_uri.rb +0 -41
  548. data/test/rubygems/test_gem_uri_formatter.rb +0 -27
  549. data/test/rubygems/test_gem_util.rb +0 -91
  550. data/test/rubygems/test_gem_validator.rb +0 -42
  551. data/test/rubygems/test_gem_version.rb +0 -305
  552. data/test/rubygems/test_gem_version_option.rb +0 -165
  553. data/test/rubygems/test_kernel.rb +0 -124
  554. data/test/rubygems/test_project_sanity.rb +0 -49
  555. data/test/rubygems/test_remote_fetch_error.rb +0 -20
  556. data/test/rubygems/test_require.rb +0 -732
  557. data/test/rubygems/test_rubygems.rb +0 -76
  558. data/test/rubygems/test_webauthn_listener.rb +0 -143
  559. data/test/rubygems/test_webauthn_listener_response.rb +0 -93
  560. data/test/rubygems/test_webauthn_poller.rb +0 -124
  561. data/test/rubygems/utilities.rb +0 -436
  562. data/test/rubygems/wrong_key_cert.pem +0 -19
  563. data/test/rubygems/wrong_key_cert_32.pem +0 -19
  564. data/test/test_changelog_generator.rb +0 -17
@@ -1,1799 +0,0 @@
1
- # coding: US-ASCII
2
-
3
- require_relative "helper"
4
- require "rubygems"
5
- require "rubygems/command"
6
- require "rubygems/installer"
7
- require "pathname"
8
- require "tmpdir"
9
- require "rbconfig"
10
-
11
- class TestGem < Gem::TestCase
12
- PLUGINS_LOADED = [] # rubocop:disable Style/MutableConstant
13
-
14
- PROJECT_DIR = File.expand_path("../..", __dir__).tap(&Gem::UNTAINT)
15
-
16
- def setup
17
- super
18
-
19
- PLUGINS_LOADED.clear
20
-
21
- common_installer_setup
22
-
23
- @additional = %w[a b].map {|d| File.join @tempdir, d }
24
-
25
- util_remove_interrupt_command
26
- end
27
-
28
- def test_self_finish_resolve
29
- a1 = util_spec "a", "1", "b" => "> 0"
30
- b1 = util_spec "b", "1", "c" => ">= 1"
31
- b2 = util_spec "b", "2", "c" => ">= 2"
32
- c1 = util_spec "c", "1"
33
- c2 = util_spec "c", "2"
34
-
35
- install_specs c1, c2, b1, b2, a1
36
-
37
- a1.activate
38
-
39
- assert_equal %w[a-1], loaded_spec_names
40
- assert_equal ["b (> 0)"], unresolved_names
41
-
42
- Gem.finish_resolve
43
-
44
- assert_equal %w[a-1 b-2 c-2], loaded_spec_names
45
- assert_equal [], unresolved_names
46
- end
47
-
48
- def test_self_finish_resolve_wtf
49
- a1 = util_spec "a", "1", "b" => "> 0", "d" => "> 0" # this
50
- b1 = util_spec "b", "1", { "c" => ">= 1" }, "lib/b.rb" # this
51
- b2 = util_spec "b", "2", { "c" => ">= 2" }, "lib/b.rb"
52
- c1 = util_spec "c", "1" # this
53
- c2 = util_spec "c", "2"
54
- d1 = util_spec "d", "1", { "c" => "< 2" }, "lib/d.rb"
55
- d2 = util_spec "d", "2", { "c" => "< 2" }, "lib/d.rb" # this
56
-
57
- install_specs c1, c2, b1, b2, d1, d2, a1
58
-
59
- a1.activate
60
-
61
- assert_equal %w[a-1], loaded_spec_names
62
- assert_equal ["b (> 0)", "d (> 0)"], unresolved_names
63
-
64
- Gem.finish_resolve
65
-
66
- assert_equal %w[a-1 b-1 c-1 d-2], loaded_spec_names
67
- assert_equal [], unresolved_names
68
- end
69
-
70
- def test_self_finish_resolve_respects_loaded_specs
71
- a1 = util_spec "a", "1", "b" => "> 0"
72
- b1 = util_spec "b", "1", "c" => ">= 1"
73
- b2 = util_spec "b", "2", "c" => ">= 2"
74
- c1 = util_spec "c", "1"
75
- c2 = util_spec "c", "2"
76
-
77
- install_specs c1, c2, b1, b2, a1
78
-
79
- a1.activate
80
- c1.activate
81
-
82
- assert_equal %w[a-1 c-1], loaded_spec_names
83
- assert_equal ["b (> 0)"], unresolved_names
84
-
85
- Gem.finish_resolve
86
-
87
- assert_equal %w[a-1 b-1 c-1], loaded_spec_names
88
- assert_equal [], unresolved_names
89
- end
90
-
91
- def test_self_install
92
- spec_fetcher do |f|
93
- f.gem "a", 1
94
- f.spec "a", 2
95
- end
96
-
97
- gemhome2 = "#{@gemhome}2"
98
-
99
- installed = Gem.install "a", "= 1", :install_dir => gemhome2
100
-
101
- assert_equal %w[a-1], installed.map {|spec| spec.full_name }
102
-
103
- assert_path_exist File.join(gemhome2, "gems", "a-1")
104
- end
105
-
106
- def test_self_install_in_rescue
107
- spec_fetcher do |f|
108
- f.gem "a", 1
109
- f.spec "a", 2
110
- end
111
-
112
- gemhome2 = "#{@gemhome}2"
113
-
114
- installed =
115
- begin
116
- raise "Error"
117
- rescue StandardError
118
- Gem.install "a", "= 1", :install_dir => gemhome2
119
- end
120
- assert_equal %w[a-1], installed.map {|spec| spec.full_name }
121
- end
122
-
123
- def test_self_install_permissions
124
- assert_self_install_permissions
125
- end
126
-
127
- def test_self_install_permissions_umask_0
128
- umask = File.umask(0)
129
- assert_self_install_permissions
130
- ensure
131
- File.umask(umask)
132
- end
133
-
134
- def test_self_install_permissions_umask_077
135
- umask = File.umask(0o77)
136
- assert_self_install_permissions
137
- ensure
138
- File.umask(umask)
139
- end
140
-
141
- def test_self_install_permissions_with_format_executable
142
- assert_self_install_permissions(format_executable: true)
143
- end
144
-
145
- def test_self_install_permissions_with_format_executable_and_non_standard_ruby_install_name
146
- Gem::Installer.exec_format = nil
147
- ruby_install_name "ruby27" do
148
- assert_self_install_permissions(format_executable: true)
149
- end
150
- ensure
151
- Gem::Installer.exec_format = nil
152
- end
153
-
154
- def assert_self_install_permissions(format_executable: false)
155
- mask = win_platform? ? 0o700 : 0o777
156
- options = {
157
- :dir_mode => 0o500,
158
- :prog_mode => win_platform? ? 0o410 : 0o510,
159
- :data_mode => 0o640,
160
- :wrappers => true,
161
- :format_executable => format_executable,
162
- }
163
- Dir.chdir @tempdir do
164
- Dir.mkdir "bin"
165
- Dir.mkdir "data"
166
-
167
- File.write "bin/foo", "#!/usr/bin/env ruby\n"
168
- File.chmod 0o755, "bin/foo"
169
-
170
- File.write "data/foo.txt", "blah\n"
171
-
172
- spec_fetcher do |f|
173
- f.gem "foo", 1 do |s|
174
- s.executables = ["foo"]
175
- s.files = %w[bin/foo data/foo.txt]
176
- end
177
- end
178
- Gem.install "foo", Gem::Requirement.default, options
179
- end
180
-
181
- prog_mode = (options[:prog_mode] & mask).to_s(8)
182
- dir_mode = (options[:dir_mode] & mask).to_s(8)
183
- data_mode = (options[:data_mode] & mask).to_s(8)
184
- prog_name = "foo"
185
- prog_name = RbConfig::CONFIG["ruby_install_name"].sub("ruby", "foo") if options[:format_executable]
186
- expected = {
187
- "bin/#{prog_name}" => prog_mode,
188
- "gems/foo-1" => dir_mode,
189
- "gems/foo-1/bin" => dir_mode,
190
- "gems/foo-1/data" => dir_mode,
191
- "gems/foo-1/bin/foo" => prog_mode,
192
- "gems/foo-1/data/foo.txt" => data_mode,
193
- }
194
- # add Windows script
195
- expected["bin/#{prog_name}.bat"] = mask.to_s(8) if win_platform?
196
- result = {}
197
- Dir.chdir @gemhome do
198
- expected.each_key do |n|
199
- result[n] = (File.stat(n).mode & mask).to_s(8)
200
- end
201
- end
202
- assert_equal(expected, result)
203
- ensure
204
- File.chmod(0o755, *Dir.glob(@gemhome + "/gems/**/").map {|path| path.tap(&Gem::UNTAINT) })
205
- end
206
-
207
- def test_require_missing
208
- assert_raise ::LoadError do
209
- require "test_require_missing"
210
- end
211
- end
212
-
213
- def test_require_does_not_glob
214
- a1 = util_spec "a", "1", nil, "lib/a1.rb"
215
-
216
- install_specs a1
217
-
218
- assert_raise ::LoadError do
219
- require "a*"
220
- end
221
-
222
- assert_equal [], loaded_spec_names
223
- end
224
-
225
- def test_self_bin_path_active
226
- a1 = util_spec "a", "1" do |s|
227
- s.executables = ["exec"]
228
- end
229
-
230
- util_spec "a", "2" do |s|
231
- s.executables = ["exec"]
232
- end
233
-
234
- a1.activate
235
-
236
- assert_match "a-1/bin/exec", Gem.bin_path("a", "exec", ">= 0")
237
- end
238
-
239
- def test_self_bin_path_picking_newest
240
- a1 = util_spec "a", "1" do |s|
241
- s.executables = ["exec"]
242
- end
243
-
244
- a2 = util_spec "a", "2" do |s|
245
- s.executables = ["exec"]
246
- end
247
-
248
- install_specs a1, a2
249
-
250
- assert_match "a-2/bin/exec", Gem.bin_path("a", "exec", ">= 0")
251
- end
252
-
253
- def test_self_activate_bin_path_no_exec_name
254
- e = assert_raise ArgumentError do
255
- Gem.activate_bin_path "a"
256
- end
257
-
258
- assert_equal "you must supply exec_name", e.message
259
- end
260
-
261
- def test_activate_bin_path_resolves_eagerly
262
- a1 = util_spec "a", "1" do |s|
263
- s.executables = ["exec"]
264
- s.add_dependency "b"
265
- end
266
-
267
- b1 = util_spec "b", "1" do |s|
268
- s.add_dependency "c", "2"
269
- end
270
-
271
- b2 = util_spec "b", "2" do |s|
272
- s.add_dependency "c", "1"
273
- end
274
-
275
- c1 = util_spec "c", "1"
276
- c2 = util_spec "c", "2"
277
-
278
- install_specs c1, c2, b1, b2, a1
279
-
280
- Gem.activate_bin_path("a", "exec", ">= 0")
281
-
282
- # If we didn't eagerly resolve, this would activate c-2 and then the
283
- # finish_resolve would cause a conflict
284
- gem "c"
285
- Gem.finish_resolve
286
-
287
- assert_equal %w[a-1 b-2 c-1], loaded_spec_names
288
- end
289
-
290
- def test_activate_bin_path_does_not_error_if_a_gem_thats_not_finally_activated_has_orphaned_dependencies
291
- a1 = util_spec "a", "1" do |s|
292
- s.executables = ["exec"]
293
- s.add_dependency "b"
294
- end
295
-
296
- b1 = util_spec "b", "1" do |s|
297
- s.add_dependency "c", "1"
298
- end
299
-
300
- b2 = util_spec "b", "2" do |s|
301
- s.add_dependency "c", "2"
302
- end
303
-
304
- c2 = util_spec "c", "2"
305
-
306
- install_specs c2, b1, b2, a1
307
-
308
- # c1 is missing, but not needed for activation, so we should not get any errors here
309
-
310
- Gem.activate_bin_path("a", "exec", ">= 0")
311
-
312
- assert_equal %w[a-1 b-2 c-2], loaded_spec_names
313
- end
314
-
315
- def test_activate_bin_path_raises_a_meaningful_error_if_a_gem_thats_finally_activated_has_orphaned_dependencies
316
- a1 = util_spec "a", "1" do |s|
317
- s.executables = ["exec"]
318
- s.add_dependency "b"
319
- end
320
-
321
- b1 = util_spec "b", "1" do |s|
322
- s.add_dependency "c", "1"
323
- end
324
-
325
- b2 = util_spec "b", "2" do |s|
326
- s.add_dependency "c", "2"
327
- end
328
-
329
- c1 = util_spec "c", "1"
330
-
331
- install_specs c1, b1, b2, a1
332
-
333
- # c2 is missing, and b2 which has it as a dependency will be activated, so we should get an error about the orphaned dependency
334
-
335
- e = assert_raise Gem::UnsatisfiableDependencyError do
336
- load Gem.activate_bin_path("a", "exec", ">= 0")
337
- end
338
-
339
- assert_equal "Unable to resolve dependency: 'b (>= 0)' requires 'c (= 2)'", e.message
340
- end
341
-
342
- def test_activate_bin_path_in_debug_mode
343
- a1 = util_spec "a", "1" do |s|
344
- s.executables = ["exec"]
345
- end
346
-
347
- install_specs a1
348
-
349
- require "open3"
350
- output, status = Open3.capture2e(
351
- { "GEM_HOME" => Gem.paths.home, "DEBUG_RESOLVER" => "1" },
352
- *ruby_with_rubygems_in_load_path, "-e", "\"Gem.activate_bin_path('a', 'exec', '>= 0')\""
353
- )
354
-
355
- assert status.success?, output
356
- end
357
-
358
- def test_activate_bin_path_selects_exact_bundler_version_if_present
359
- bundler_latest = util_spec "bundler", "2.0.1" do |s|
360
- s.executables = ["bundle"]
361
- end
362
-
363
- bundler_previous = util_spec "bundler", "2.0.0" do |s|
364
- s.executables = ["bundle"]
365
- end
366
-
367
- install_specs bundler_latest, bundler_previous
368
-
369
- File.open("Gemfile.lock", "w") do |f|
370
- f.write <<-L.gsub(/ {8}/, "")
371
- GEM
372
- remote: https://rubygems.org/
373
- specs:
374
-
375
- PLATFORMS
376
- ruby
377
-
378
- DEPENDENCIES
379
-
380
- BUNDLED WITH
381
- 2.0.0
382
- L
383
- end
384
-
385
- File.open("Gemfile", "w") {|f| f.puts('source "https://rubygems.org"') }
386
-
387
- load Gem.activate_bin_path("bundler", "bundle", ">= 0.a")
388
-
389
- assert_equal %w[bundler-2.0.0], loaded_spec_names
390
- end
391
-
392
- def test_activate_bin_path_respects_underscore_selection_if_given
393
- bundler_latest = util_spec "bundler", "2.0.1" do |s|
394
- s.executables = ["bundle"]
395
- end
396
-
397
- bundler_previous = util_spec "bundler", "1.17.3" do |s|
398
- s.executables = ["bundle"]
399
- end
400
-
401
- install_specs bundler_latest, bundler_previous
402
-
403
- File.open("Gemfile.lock", "w") do |f|
404
- f.write <<-L.gsub(/ {8}/, "")
405
- GEM
406
- remote: https://rubygems.org/
407
- specs:
408
-
409
- PLATFORMS
410
- ruby
411
-
412
- DEPENDENCIES
413
-
414
- BUNDLED WITH
415
- 2.0.1
416
- L
417
- end
418
-
419
- File.open("Gemfile", "w") {|f| f.puts('source "https://rubygems.org"') }
420
-
421
- load Gem.activate_bin_path("bundler", "bundle", "= 1.17.3")
422
-
423
- assert_equal %w[bundler-1.17.3], loaded_spec_names
424
- end
425
-
426
- def test_activate_bin_path_gives_proper_error_for_bundler_when_underscore_selection_given
427
- File.open("Gemfile.lock", "w") do |f|
428
- f.write <<-L.gsub(/ {8}/, "")
429
- GEM
430
- remote: https://rubygems.org/
431
- specs:
432
-
433
- PLATFORMS
434
- ruby
435
-
436
- DEPENDENCIES
437
-
438
- BUNDLED WITH
439
- 2.1.4
440
- L
441
- end
442
-
443
- File.open("Gemfile", "w") {|f| f.puts('source "https://rubygems.org"') }
444
-
445
- e = assert_raise Gem::GemNotFoundException do
446
- load Gem.activate_bin_path("bundler", "bundle", "= 2.2.8")
447
- end
448
-
449
- assert_equal "can't find gem bundler (= 2.2.8) with executable bundle", e.message
450
- end
451
-
452
- def test_self_bin_path_no_exec_name
453
- e = assert_raise ArgumentError do
454
- Gem.bin_path "a"
455
- end
456
-
457
- assert_equal "you must supply exec_name", e.message
458
- end
459
-
460
- def test_self_bin_path_bin_name
461
- install_specs util_exec_gem
462
- assert_equal @abin_path, Gem.bin_path("a", "abin")
463
- end
464
-
465
- def test_self_bin_path_bin_name_version
466
- install_specs util_exec_gem
467
- assert_equal @abin_path, Gem.bin_path("a", "abin", "4")
468
- end
469
-
470
- def test_self_bin_path_nonexistent_binfile
471
- util_spec "a", "2" do |s|
472
- s.executables = ["exec"]
473
- end
474
- assert_raise(Gem::GemNotFoundException) do
475
- Gem.bin_path("a", "other", "2")
476
- end
477
- end
478
-
479
- def test_self_bin_path_no_bin_file
480
- util_spec "a", "1"
481
- assert_raise(ArgumentError) do
482
- Gem.bin_path("a", nil, "1")
483
- end
484
- end
485
-
486
- def test_self_bin_path_not_found
487
- assert_raise(Gem::GemNotFoundException) do
488
- Gem.bin_path("non-existent", "blah")
489
- end
490
- end
491
-
492
- def test_self_bin_path_bin_file_gone_in_latest
493
- install_specs util_exec_gem
494
- spec = util_spec "a", "10" do |s|
495
- s.executables = []
496
- end
497
- install_specs spec
498
- assert_equal @abin_path, Gem.bin_path("a", "abin")
499
- end
500
-
501
- def test_self_bindir
502
- assert_equal File.join(@gemhome, "bin"), Gem.bindir
503
- assert_equal File.join(@gemhome, "bin"), Gem.bindir(Gem.dir)
504
- assert_equal File.join(@gemhome, "bin"), Gem.bindir(Pathname.new(Gem.dir))
505
- end
506
-
507
- def test_self_bindir_default_dir
508
- default = Gem.default_dir
509
-
510
- assert_equal Gem.default_bindir, Gem.bindir(default)
511
- end
512
-
513
- def test_self_clear_paths
514
- assert_match(/gemhome$/, Gem.dir)
515
- assert_match(/gemhome$/, Gem.path.first)
516
-
517
- Gem.clear_paths
518
-
519
- assert_nil Gem::Specification.send(:class_variable_get, :@@all)
520
- end
521
-
522
- def test_self_configuration
523
- expected = Gem::ConfigFile.new []
524
- Gem.configuration = nil
525
-
526
- assert_equal expected, Gem.configuration
527
- end
528
-
529
- def test_self_datadir
530
- foo = nil
531
-
532
- Dir.chdir @tempdir do
533
- FileUtils.mkdir_p "data"
534
- File.open File.join("data", "foo.txt"), "w" do |fp|
535
- fp.puts "blah"
536
- end
537
-
538
- foo = util_spec "foo" do |s|
539
- s.files = %w[data/foo.txt]
540
- end
541
-
542
- install_gem foo
543
- end
544
-
545
- gem "foo"
546
-
547
- expected = File.join @gemhome, "gems", foo.full_name, "data", "foo"
548
-
549
- assert_equal expected, Gem::Specification.find_by_name("foo").datadir
550
- end
551
-
552
- def test_self_datadir_nonexistent_package
553
- assert_raise(Gem::MissingSpecError) do
554
- Gem::Specification.find_by_name("xyzzy").datadir
555
- end
556
- end
557
-
558
- def test_self_default_exec_format
559
- ruby_install_name "ruby" do
560
- assert_equal "%s", Gem.default_exec_format
561
- end
562
- end
563
-
564
- def test_self_default_exec_format_18
565
- ruby_install_name "ruby18" do
566
- assert_equal "%s18", Gem.default_exec_format
567
- end
568
- end
569
-
570
- def test_self_default_exec_format_jruby
571
- ruby_install_name "jruby" do
572
- assert_equal "j%s", Gem.default_exec_format
573
- end
574
- end
575
-
576
- def test_default_path
577
- vendordir(File.join(@tempdir, "vendor")) do
578
- FileUtils.rm_rf Gem.user_home
579
-
580
- expected = [Gem.default_dir]
581
-
582
- assert_equal expected, Gem.default_path
583
- end
584
- end
585
-
586
- def test_default_path_missing_vendor
587
- vendordir(nil) do
588
- FileUtils.rm_rf Gem.user_home
589
-
590
- expected = [Gem.default_dir]
591
-
592
- assert_equal expected, Gem.default_path
593
- end
594
- end
595
-
596
- def test_default_path_user_home
597
- vendordir(File.join(@tempdir, "vendor")) do
598
- expected = [Gem.user_dir, Gem.default_dir]
599
-
600
- assert_equal expected, Gem.default_path
601
- end
602
- end
603
-
604
- def test_default_path_vendor_dir
605
- vendordir(File.join(@tempdir, "vendor")) do
606
- FileUtils.mkdir_p Gem.vendor_dir
607
-
608
- FileUtils.rm_rf Gem.user_home
609
-
610
- expected = [Gem.default_dir, Gem.vendor_dir]
611
-
612
- assert_equal expected, Gem.default_path
613
- end
614
- end
615
-
616
- def test_self_default_sources
617
- assert_equal %w[https://rubygems.org/], Gem.default_sources
618
- end
619
-
620
- def test_self_dir
621
- assert_equal @gemhome, Gem.dir
622
- end
623
-
624
- def test_self_ensure_gem_directories
625
- FileUtils.rm_r @gemhome
626
- Gem.use_paths @gemhome
627
-
628
- Gem.ensure_gem_subdirectories @gemhome
629
-
630
- assert_path_exist File.join @gemhome, "build_info"
631
- assert_path_exist File.join @gemhome, "cache"
632
- assert_path_exist File.join @gemhome, "doc"
633
- assert_path_exist File.join @gemhome, "extensions"
634
- assert_path_exist File.join @gemhome, "gems"
635
- assert_path_exist File.join @gemhome, "specifications"
636
- end
637
-
638
- def test_self_ensure_gem_directories_permissions
639
- FileUtils.rm_r @gemhome
640
- Gem.use_paths @gemhome
641
-
642
- Gem.ensure_gem_subdirectories @gemhome, 0o750
643
-
644
- assert_directory_exists File.join(@gemhome, "cache")
645
-
646
- assert_equal 0o750, File::Stat.new(@gemhome).mode & 0o777
647
- assert_equal 0o750, File::Stat.new(File.join(@gemhome, "cache")).mode & 0o777
648
- end unless win_platform?
649
-
650
- def test_self_ensure_gem_directories_safe_permissions
651
- FileUtils.rm_r @gemhome
652
- Gem.use_paths @gemhome
653
-
654
- old_umask = File.umask
655
- File.umask 0
656
- Gem.ensure_gem_subdirectories @gemhome
657
-
658
- assert_equal 0, File::Stat.new(@gemhome).mode & 0o02
659
- assert_equal 0, File::Stat.new(File.join(@gemhome, "cache")).mode & 0o02
660
- ensure
661
- File.umask old_umask
662
- end unless win_platform?
663
-
664
- def test_self_ensure_gem_directories_missing_parents
665
- gemdir = File.join @tempdir, "a/b/c/gemdir"
666
- begin
667
- FileUtils.rm_rf File.join(@tempdir, "a")
668
- rescue StandardError
669
- nil
670
- end
671
- refute File.exist?(File.join(@tempdir, "a")),
672
- "manually remove #{File.join @tempdir, "a"}, tests are broken"
673
- Gem.use_paths gemdir
674
-
675
- Gem.ensure_gem_subdirectories gemdir
676
-
677
- assert_directory_exists util_cache_dir
678
- end
679
-
680
- unless win_platform? || Process.uid.zero? # only for FS that support write protection
681
- def test_self_ensure_gem_directories_write_protected
682
- gemdir = File.join @tempdir, "egd"
683
- begin
684
- FileUtils.rm_r gemdir
685
- rescue StandardError
686
- nil
687
- end
688
- refute File.exist?(gemdir), "manually remove #{gemdir}, tests are broken"
689
- FileUtils.mkdir_p gemdir
690
- FileUtils.chmod 0o400, gemdir
691
- Gem.use_paths gemdir
692
-
693
- Gem.ensure_gem_subdirectories gemdir
694
-
695
- refute File.exist?(util_cache_dir)
696
- ensure
697
- FileUtils.chmod 0o600, gemdir
698
- end
699
-
700
- def test_self_ensure_gem_directories_write_protected_parents
701
- parent = File.join(@tempdir, "egd")
702
- gemdir = "#{parent}/a/b/c"
703
-
704
- begin
705
- FileUtils.rm_r parent
706
- rescue StandardError
707
- nil
708
- end
709
- refute File.exist?(parent), "manually remove #{parent}, tests are broken"
710
- FileUtils.mkdir_p parent
711
- FileUtils.chmod 0o400, parent
712
- Gem.use_paths(gemdir)
713
-
714
- Gem.ensure_gem_subdirectories gemdir
715
-
716
- refute File.exist? File.join(gemdir, "gems")
717
- ensure
718
- FileUtils.chmod 0o600, parent
719
- end
720
-
721
- def test_self_ensure_gem_directories_non_existent_paths
722
- Gem.ensure_gem_subdirectories "/proc/0123456789/bogus" # should not raise
723
- Gem.ensure_gem_subdirectories "classpath:/bogus/x" # JRuby embed scenario
724
- end
725
- end
726
-
727
- def test_self_extension_dir_shared
728
- enable_shared "yes" do
729
- assert_equal Gem.ruby_api_version, Gem.extension_api_version
730
- end
731
- end
732
-
733
- def test_self_extension_dir_static
734
- enable_shared "no" do
735
- assert_equal "#{Gem.ruby_api_version}-static", Gem.extension_api_version
736
- end
737
- end
738
-
739
- def test_self_find_files
740
- cwd = File.expand_path("test/rubygems", PROJECT_DIR)
741
- $LOAD_PATH.unshift cwd
742
-
743
- discover_path = File.join "lib", "sff", "discover.rb"
744
-
745
- foo1, foo2 = %w[1 2].map do |version|
746
- spec = quick_gem "sff", version do |s|
747
- s.files << discover_path
748
- end
749
-
750
- write_file(File.join "gems", spec.full_name, discover_path) do |fp|
751
- fp.puts "# #{spec.full_name}"
752
- end
753
-
754
- spec
755
- end
756
-
757
- Gem.refresh
758
-
759
- expected = [
760
- File.expand_path("test/rubygems/sff/discover.rb", PROJECT_DIR),
761
- File.join(foo2.full_gem_path, discover_path),
762
- File.join(foo1.full_gem_path, discover_path),
763
- ]
764
-
765
- assert_equal expected, Gem.find_files("sff/discover")
766
- assert_equal expected, Gem.find_files("sff/**.rb"), "[ruby-core:31730]"
767
- ensure
768
- assert_equal cwd, $LOAD_PATH.shift
769
- end
770
-
771
- def test_self_find_latest_files
772
- cwd = File.expand_path("test/rubygems", PROJECT_DIR)
773
- $LOAD_PATH.unshift cwd
774
-
775
- discover_path = File.join "lib", "sff", "discover.rb"
776
-
777
- _, foo2 = %w[1 2].map do |version|
778
- spec = quick_gem "sff", version do |s|
779
- s.files << discover_path
780
- end
781
-
782
- write_file(File.join "gems", spec.full_name, discover_path) do |fp|
783
- fp.puts "# #{spec.full_name}"
784
- end
785
-
786
- spec
787
- end
788
-
789
- Gem.refresh
790
-
791
- expected = [
792
- File.expand_path("test/rubygems/sff/discover.rb", PROJECT_DIR),
793
- File.join(foo2.full_gem_path, discover_path),
794
- ]
795
-
796
- assert_equal expected, Gem.find_latest_files("sff/discover")
797
- assert_equal expected, Gem.find_latest_files("sff/**.rb"), "[ruby-core:31730]"
798
- ensure
799
- assert_equal cwd, $LOAD_PATH.shift
800
- end
801
-
802
- def test_self_latest_spec_for
803
- gems = spec_fetcher do |fetcher|
804
- fetcher.spec "a", 1
805
- fetcher.spec "a", "3.a"
806
- fetcher.spec "a", 2
807
- end
808
-
809
- spec = Gem.latest_spec_for "a"
810
-
811
- assert_equal gems["a-2"], spec
812
- end
813
-
814
- def test_self_latest_spec_for_multiple_sources
815
- uri = "https://example.sample.com/"
816
- source = Gem::Source.new(uri)
817
- source_list = Gem::SourceList.new
818
- source_list << Gem::Source.new(@uri)
819
- source_list << source
820
- Gem.sources.replace source_list
821
-
822
- spec_fetcher(uri) do |fetcher|
823
- fetcher.spec "a", 1.1
824
- end
825
-
826
- gems = spec_fetcher do |fetcher|
827
- fetcher.spec "a", 1
828
- fetcher.spec "a", "3.a"
829
- fetcher.spec "a", 2
830
- end
831
- spec = Gem.latest_spec_for "a"
832
- assert_equal gems["a-2"], spec
833
- end
834
-
835
- def test_self_latest_rubygems_version
836
- spec_fetcher do |fetcher|
837
- fetcher.spec "rubygems-update", "1.8.23"
838
- fetcher.spec "rubygems-update", "1.8.24"
839
- fetcher.spec "rubygems-update", "2.0.0.preview3"
840
- end
841
-
842
- version = Gem.latest_rubygems_version
843
-
844
- assert_equal Gem::Version.new("1.8.24"), version
845
- end
846
-
847
- def test_self_latest_version_for
848
- spec_fetcher do |fetcher|
849
- fetcher.spec "a", 1
850
- fetcher.spec "a", 2
851
- fetcher.spec "a", "3.a"
852
- end
853
-
854
- version = Gem.latest_version_for "a"
855
-
856
- assert_equal Gem::Version.new(2), version
857
- end
858
-
859
- def test_self_latest_version_for_multiple_sources
860
- uri = "https://example.sample.com/"
861
- source = Gem::Source.new(uri)
862
- source_list = Gem::SourceList.new
863
- source_list << Gem::Source.new(@uri)
864
- source_list << source
865
- Gem.sources.replace source_list
866
-
867
- spec_fetcher(uri) do |fetcher|
868
- fetcher.spec "a", 1.1
869
- end
870
-
871
- spec_fetcher do |fetcher|
872
- fetcher.spec "a", 1
873
- fetcher.spec "a", 2
874
- fetcher.spec "a", "3.a"
875
- end
876
-
877
- version = Gem.latest_version_for "a"
878
-
879
- assert_equal Gem::Version.new(2), version
880
- end
881
-
882
- def test_self_loaded_specs
883
- foo = util_spec "foo"
884
- install_gem foo
885
-
886
- foo.activate
887
-
888
- assert_equal true, Gem.loaded_specs.keys.include?("foo")
889
- end
890
-
891
- def test_self_path
892
- assert_equal [Gem.dir], Gem.path
893
- end
894
-
895
- def test_self_path_default
896
- ENV.delete "GEM_HOME"
897
- ENV.delete "GEM_PATH"
898
-
899
- Gem.instance_variable_set :@paths, nil
900
-
901
- assert_equal [Gem.default_path, Gem.dir].flatten.uniq, Gem.path
902
- end
903
-
904
- def test_self_path_ENV_PATH
905
- path_count = Gem.path.size
906
- Gem.clear_paths
907
-
908
- ENV["GEM_PATH"] = @additional.join(File::PATH_SEPARATOR)
909
-
910
- assert_equal @additional, Gem.path[0,2]
911
-
912
- assert_equal path_count + @additional.size, Gem.path.size,
913
- "extra path components: #{Gem.path[2..-1].inspect}"
914
- assert_equal Gem.dir, Gem.path.last
915
- end
916
-
917
- def test_self_path_duplicate
918
- Gem.clear_paths
919
- util_ensure_gem_dirs
920
- dirs = @additional + [@gemhome] + [File.join(@tempdir, "a")]
921
-
922
- ENV["GEM_HOME"] = @gemhome
923
- ENV["GEM_PATH"] = dirs.join File::PATH_SEPARATOR
924
-
925
- assert_equal @gemhome, Gem.dir
926
-
927
- paths = [Gem.dir]
928
- assert_equal @additional + paths, Gem.path
929
- end
930
-
931
- def test_self_path_overlap
932
- Gem.clear_paths
933
-
934
- util_ensure_gem_dirs
935
- ENV["GEM_HOME"] = @gemhome
936
- ENV["GEM_PATH"] = @additional.join(File::PATH_SEPARATOR)
937
-
938
- assert_equal @gemhome, Gem.dir
939
-
940
- paths = [Gem.dir]
941
- assert_equal @additional + paths, Gem.path
942
- end
943
-
944
- def test_self_platforms
945
- assert_equal [Gem::Platform::RUBY, Gem::Platform.local], Gem.platforms
946
- end
947
-
948
- def test_self_prefix
949
- assert_equal PROJECT_DIR, Gem.prefix
950
- end
951
-
952
- def test_self_prefix_libdir
953
- orig_libdir = RbConfig::CONFIG["libdir"]
954
- RbConfig::CONFIG["libdir"] = PROJECT_DIR
955
-
956
- assert_nil Gem.prefix
957
- ensure
958
- RbConfig::CONFIG["libdir"] = orig_libdir
959
- end
960
-
961
- def test_self_prefix_sitelibdir
962
- orig_sitelibdir = RbConfig::CONFIG["sitelibdir"]
963
- RbConfig::CONFIG["sitelibdir"] = PROJECT_DIR
964
-
965
- assert_nil Gem.prefix
966
- ensure
967
- RbConfig::CONFIG["sitelibdir"] = orig_sitelibdir
968
- end
969
-
970
- def test_self_read_binary
971
- File.open "test", "w" do |io|
972
- io.write "\xCF\x80"
973
- end
974
-
975
- assert_equal ["\xCF", "\x80"], Gem.read_binary("test").chars.to_a
976
-
977
- pend "chmod not supported" if Gem.win_platform?
978
-
979
- begin
980
- File.chmod 0o444, "test"
981
-
982
- assert_equal ["\xCF", "\x80"], Gem.read_binary("test").chars.to_a
983
- ensure
984
- File.chmod 0o644, "test"
985
- end
986
- end
987
-
988
- def test_self_refresh
989
- util_make_gems
990
-
991
- a1_spec = @a1.spec_file
992
- moved_path = File.join @tempdir, File.basename(a1_spec)
993
-
994
- FileUtils.mv a1_spec, moved_path
995
-
996
- Gem.refresh
997
-
998
- refute_includes Gem::Specification.all_names, @a1.full_name
999
-
1000
- FileUtils.mv moved_path, a1_spec
1001
-
1002
- Gem.refresh
1003
-
1004
- assert_includes Gem::Specification.all_names, @a1.full_name
1005
- end
1006
-
1007
- def test_self_refresh_keeps_loaded_specs_activated
1008
- util_make_gems
1009
-
1010
- a1_spec = @a1.spec_file
1011
- moved_path = File.join @tempdir, File.basename(a1_spec)
1012
-
1013
- FileUtils.mv a1_spec, moved_path
1014
-
1015
- Gem.refresh
1016
-
1017
- s = Gem::Specification.first
1018
- s.activate
1019
-
1020
- Gem.refresh
1021
-
1022
- Gem::Specification.each {|spec| assert spec.activated? if spec == s }
1023
-
1024
- Gem.loaded_specs.delete(s)
1025
- Gem.refresh
1026
- end
1027
-
1028
- def test_self_ruby_escaping_spaces_in_path
1029
- with_clean_path_to_ruby do
1030
- with_rb_config_ruby("C:/Ruby 1.8/bin/ruby.exe") do
1031
- assert_equal "\"C:/Ruby 1.8/bin/ruby.exe\"", Gem.ruby
1032
- end
1033
- end
1034
- end
1035
-
1036
- def test_self_ruby_path_without_spaces
1037
- with_clean_path_to_ruby do
1038
- with_rb_config_ruby("C:/Ruby18/bin/ruby.exe") do
1039
- assert_equal "C:/Ruby18/bin/ruby.exe", Gem.ruby
1040
- end
1041
- end
1042
- end
1043
-
1044
- def test_self_ruby_api_version
1045
- orig_ruby_version = RbConfig::CONFIG["ruby_version"]
1046
- RbConfig::CONFIG["ruby_version"] = "1.2.3"
1047
-
1048
- Gem.instance_variable_set :@ruby_api_version, nil
1049
-
1050
- assert_equal "1.2.3", Gem.ruby_api_version
1051
- ensure
1052
- Gem.instance_variable_set :@ruby_api_version, nil
1053
-
1054
- RbConfig::CONFIG["ruby_version"] = orig_ruby_version
1055
- end
1056
-
1057
- def test_self_env_requirement
1058
- ENV["GEM_REQUIREMENT_FOO"] = ">= 1.2.3"
1059
- ENV["GEM_REQUIREMENT_BAR"] = "1.2.3"
1060
- ENV["GEM_REQUIREMENT_BAZ"] = "abcd"
1061
-
1062
- assert_equal Gem::Requirement.create(">= 1.2.3"), Gem.env_requirement("foo")
1063
- assert_equal Gem::Requirement.create("1.2.3"), Gem.env_requirement("bAr")
1064
- assert_raise(Gem::Requirement::BadRequirementError) { Gem.env_requirement("baz") }
1065
- assert_equal Gem::Requirement.default, Gem.env_requirement("qux")
1066
- end
1067
-
1068
- def test_self_ruby_version_with_non_mri_implementations
1069
- util_set_RUBY_VERSION "2.5.0", 0, 60_928, "jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 [linux-x86_64]"
1070
-
1071
- assert_equal Gem::Version.new("2.5.0"), Gem.ruby_version
1072
- ensure
1073
- util_restore_RUBY_VERSION
1074
- end
1075
-
1076
- def test_self_ruby_version_with_svn_prerelease
1077
- util_set_RUBY_VERSION "2.6.0", -1, 63_539, "ruby 2.6.0preview2 (2018-05-31 trunk 63539) [x86_64-linux]"
1078
-
1079
- assert_equal Gem::Version.new("2.6.0.preview2"), Gem.ruby_version
1080
- ensure
1081
- util_restore_RUBY_VERSION
1082
- end
1083
-
1084
- def test_self_ruby_version_with_git_prerelease
1085
- util_set_RUBY_VERSION "2.7.0", -1, "b563439274a402e33541f5695b1bfd4ac1085638", "ruby 2.7.0preview3 (2019-11-23 master b563439274) [x86_64-linux]"
1086
-
1087
- assert_equal Gem::Version.new("2.7.0.preview3"), Gem.ruby_version
1088
- ensure
1089
- util_restore_RUBY_VERSION
1090
- end
1091
-
1092
- def test_self_ruby_version_with_non_mri_implementations_with_mri_prerelase_compatibility
1093
- util_set_RUBY_VERSION "2.6.0", -1, 63_539, "weirdjruby 9.2.0.0 (2.6.0preview2) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 [linux-x86_64]", "weirdjruby", "9.2.0.0"
1094
-
1095
- assert_equal Gem::Version.new("2.6.0.preview2"), Gem.ruby_version
1096
- ensure
1097
- util_restore_RUBY_VERSION
1098
- end
1099
-
1100
- def test_self_ruby_version_with_svn_trunk
1101
- util_set_RUBY_VERSION "1.9.2", -1, 23_493, "ruby 1.9.2dev (2009-05-20 trunk 23493) [x86_64-linux]"
1102
-
1103
- assert_equal Gem::Version.new("1.9.2.dev"), Gem.ruby_version
1104
- ensure
1105
- util_restore_RUBY_VERSION
1106
- end
1107
-
1108
- def test_self_ruby_version_with_git_master
1109
- util_set_RUBY_VERSION "2.7.0", -1, "5de284ec78220e75643f89b454ce999da0c1c195", "ruby 2.7.0dev (2019-12-23T01:37:30Z master 5de284ec78) [x86_64-linux]"
1110
-
1111
- assert_equal Gem::Version.new("2.7.0.dev"), Gem.ruby_version
1112
- ensure
1113
- util_restore_RUBY_VERSION
1114
- end
1115
-
1116
- def test_self_rubygems_version
1117
- assert_equal Gem::Version.new(Gem::VERSION), Gem.rubygems_version
1118
- end
1119
-
1120
- def test_self_paths_eq
1121
- other = File.join @tempdir, "other"
1122
- path = [@userhome, other].join File::PATH_SEPARATOR
1123
-
1124
- #
1125
- # FIXME remove after fixing test_case
1126
- #
1127
- ENV["GEM_HOME"] = @gemhome
1128
- Gem.paths = { "GEM_PATH" => path }
1129
-
1130
- assert_equal [@userhome, other, @gemhome], Gem.path
1131
- end
1132
-
1133
- def test_self_paths_eq_nonexistent_home
1134
- ENV["GEM_HOME"] = @gemhome
1135
- Gem.clear_paths
1136
-
1137
- other = File.join @tempdir, "other"
1138
-
1139
- ENV["HOME"] = other
1140
-
1141
- Gem.paths = { "GEM_PATH" => other }
1142
-
1143
- assert_equal [other, @gemhome], Gem.path
1144
- end
1145
-
1146
- def test_self_post_build
1147
- assert_equal 1, Gem.post_build_hooks.length
1148
-
1149
- Gem.post_build {|installer| }
1150
-
1151
- assert_equal 2, Gem.post_build_hooks.length
1152
- end
1153
-
1154
- def test_self_post_install
1155
- assert_equal 1, Gem.post_install_hooks.length
1156
-
1157
- Gem.post_install {|installer| }
1158
-
1159
- assert_equal 2, Gem.post_install_hooks.length
1160
- end
1161
-
1162
- def test_self_done_installing
1163
- assert_empty Gem.done_installing_hooks
1164
-
1165
- Gem.done_installing {|gems| }
1166
-
1167
- assert_equal 1, Gem.done_installing_hooks.length
1168
- end
1169
-
1170
- def test_self_post_reset
1171
- assert_empty Gem.post_reset_hooks
1172
-
1173
- Gem.post_reset {}
1174
-
1175
- assert_equal 1, Gem.post_reset_hooks.length
1176
- end
1177
-
1178
- def test_self_post_uninstall
1179
- assert_equal 1, Gem.post_uninstall_hooks.length
1180
-
1181
- Gem.post_uninstall {|installer| }
1182
-
1183
- assert_equal 2, Gem.post_uninstall_hooks.length
1184
- end
1185
-
1186
- def test_self_pre_install
1187
- assert_equal 1, Gem.pre_install_hooks.length
1188
-
1189
- Gem.pre_install {|installer| }
1190
-
1191
- assert_equal 2, Gem.pre_install_hooks.length
1192
- end
1193
-
1194
- def test_self_pre_reset
1195
- assert_empty Gem.pre_reset_hooks
1196
-
1197
- Gem.pre_reset {}
1198
-
1199
- assert_equal 1, Gem.pre_reset_hooks.length
1200
- end
1201
-
1202
- def test_self_pre_uninstall
1203
- assert_equal 1, Gem.pre_uninstall_hooks.length
1204
-
1205
- Gem.pre_uninstall {|installer| }
1206
-
1207
- assert_equal 2, Gem.pre_uninstall_hooks.length
1208
- end
1209
-
1210
- def test_self_sources
1211
- assert_equal %w[http://gems.example.com/], Gem.sources
1212
- Gem.sources = nil
1213
- Gem.configuration.sources = %w[http://test.example.com/]
1214
- assert_equal %w[http://test.example.com/], Gem.sources
1215
- end
1216
-
1217
- def test_try_activate_returns_true_for_activated_specs
1218
- b = util_spec "b", "1.0" do |spec|
1219
- spec.files << "lib/b.rb"
1220
- end
1221
- install_specs b
1222
-
1223
- assert Gem.try_activate("b"), "try_activate should return true"
1224
- assert Gem.try_activate("b"), "try_activate should still return true"
1225
- end
1226
-
1227
- def test_spec_order_is_consistent
1228
- b1 = util_spec "b", "1.0"
1229
- b2 = util_spec "b", "2.0"
1230
- b3 = util_spec "b", "3.0"
1231
-
1232
- install_specs b1, b2, b3
1233
-
1234
- specs1 = Gem::Specification.stubs.find_all {|s| s.name == "b" }
1235
- Gem::Specification.reset
1236
- specs2 = Gem::Specification.stubs_for("b")
1237
- assert_equal specs1.map(&:version), specs2.map(&:version)
1238
- end
1239
-
1240
- def test_self_try_activate_missing_dep
1241
- b = util_spec "b", "1.0"
1242
- a = util_spec "a", "1.0", "b" => ">= 1.0"
1243
-
1244
- install_specs b, a
1245
- uninstall_gem b
1246
-
1247
- a_file = File.join a.gem_dir, "lib", "a_file.rb"
1248
-
1249
- write_file a_file do |io|
1250
- io.puts "# a_file.rb"
1251
- end
1252
-
1253
- e = assert_raise Gem::MissingSpecError do
1254
- Gem.try_activate "a_file"
1255
- end
1256
-
1257
- assert_match %r{Could not find 'b' }, e.message
1258
- assert_match %r{at: #{a.spec_file}}, e.message
1259
- end
1260
-
1261
- def test_self_try_activate_missing_prerelease
1262
- b = util_spec "b", "1.0rc1"
1263
- a = util_spec "a", "1.0rc1", "b" => "1.0rc1"
1264
-
1265
- install_specs b, a
1266
- uninstall_gem b
1267
-
1268
- a_file = File.join a.gem_dir, "lib", "a_file.rb"
1269
-
1270
- write_file a_file do |io|
1271
- io.puts "# a_file.rb"
1272
- end
1273
-
1274
- e = assert_raise Gem::MissingSpecError do
1275
- Gem.try_activate "a_file"
1276
- end
1277
-
1278
- assert_match %r{Could not find 'b' \(= 1.0rc1\)}, e.message
1279
- end
1280
-
1281
- def test_self_try_activate_missing_extensions
1282
- spec = util_spec "ext", "1" do |s|
1283
- s.extensions = %w[ext/extconf.rb]
1284
- s.mark_version
1285
- s.installed_by_version = v("2.2")
1286
- end
1287
-
1288
- # write the spec without install to simulate a failed install
1289
- write_file spec.spec_file do |io|
1290
- io.write spec.to_ruby_for_cache
1291
- end
1292
-
1293
- _, err = capture_output do
1294
- refute Gem.try_activate "nonexistent"
1295
- end
1296
-
1297
- expected = "Ignoring ext-1 because its extensions are not built. " +
1298
- "Try: gem pristine ext --version 1\n"
1299
-
1300
- assert_equal expected, err
1301
- end
1302
-
1303
- def test_self_use_paths_with_nils
1304
- orig_home = ENV.delete "GEM_HOME"
1305
- orig_path = ENV.delete "GEM_PATH"
1306
- Gem.use_paths nil, nil
1307
- assert_equal Gem.default_dir, Gem.paths.home
1308
- path = (Gem.default_path + [Gem.paths.home]).uniq
1309
- assert_equal path, Gem.paths.path
1310
- ensure
1311
- ENV["GEM_HOME"] = orig_home
1312
- ENV["GEM_PATH"] = orig_path
1313
- end
1314
-
1315
- def test_setting_paths_does_not_warn_about_unknown_keys
1316
- stdout, stderr = capture_output do
1317
- Gem.paths = { "foo" => [],
1318
- "bar" => Object.new,
1319
- "GEM_HOME" => Gem.paths.home,
1320
- "GEM_PATH" => "foo" }
1321
- end
1322
- assert_equal ["foo", Gem.paths.home], Gem.paths.path
1323
- assert_equal "", stderr
1324
- assert_equal "", stdout
1325
- end
1326
-
1327
- def test_setting_paths_does_not_mutate_parameter_object
1328
- Gem.paths = { "GEM_HOME" => Gem.paths.home,
1329
- "GEM_PATH" => "foo" }.freeze
1330
- assert_equal ["foo", Gem.paths.home], Gem.paths.path
1331
- end
1332
-
1333
- def test_deprecated_paths=
1334
- stdout, stderr = capture_output do
1335
- Gem.paths = { "GEM_HOME" => Gem.paths.home,
1336
- "GEM_PATH" => [Gem.paths.home, "foo"] }
1337
- end
1338
- assert_equal [Gem.paths.home, "foo"], Gem.paths.path
1339
- assert_match(/Array values in the parameter to `Gem.paths=` are deprecated.\nPlease use a String or nil/m, stderr)
1340
- assert_equal "", stdout
1341
- end
1342
-
1343
- def test_self_use_paths
1344
- util_ensure_gem_dirs
1345
-
1346
- Gem.use_paths @gemhome, @additional
1347
-
1348
- assert_equal @gemhome, Gem.dir
1349
- assert_equal @additional + [Gem.dir], Gem.path
1350
- end
1351
-
1352
- def test_self_user_dir
1353
- parts = [@userhome, ".gem", Gem.ruby_engine]
1354
- parts << RbConfig::CONFIG["ruby_version"] unless RbConfig::CONFIG["ruby_version"].empty?
1355
-
1356
- FileUtils.mkdir_p File.join(parts)
1357
-
1358
- assert_equal File.join(parts), Gem.user_dir
1359
- end
1360
-
1361
- def test_self_user_home
1362
- if ENV["HOME"]
1363
- assert_equal ENV["HOME"], Gem.user_home
1364
- else
1365
- assert true, "count this test"
1366
- end
1367
- end
1368
-
1369
- def test_self_needs
1370
- a = util_spec "a", "1"
1371
- b = util_spec "b", "1", "c" => nil
1372
- c = util_spec "c", "2"
1373
-
1374
- install_specs a, c, b
1375
-
1376
- Gem.needs do |r|
1377
- r.gem "a"
1378
- r.gem "b", "= 1"
1379
- end
1380
-
1381
- activated = Gem::Specification.map {|x| x.full_name }
1382
-
1383
- assert_equal %w[a-1 b-1 c-2], activated.sort
1384
- end
1385
-
1386
- def test_self_needs_picks_up_unresolved_deps
1387
- a = util_spec "a", "1"
1388
- b = util_spec "b", "1", "c" => nil
1389
- c = util_spec "c", "2"
1390
- d = util_spec "d", "1", { "e" => "= 1" }, "lib/d#{$$}.rb"
1391
- e = util_spec "e", "1"
1392
-
1393
- install_specs a, c, b, e, d
1394
-
1395
- Gem.needs do |r|
1396
- r.gem "a"
1397
- r.gem "b", "= 1"
1398
-
1399
- require "d#{$$}"
1400
- end
1401
-
1402
- assert_equal %w[a-1 b-1 c-2 d-1 e-1], loaded_spec_names
1403
- end
1404
-
1405
- def test_self_gunzip
1406
- input = "\x1F\x8B\b\0\xED\xA3\x1AQ\0\x03\xCBH" +
1407
- "\xCD\xC9\xC9\a\0\x86\xA6\x106\x05\0\0\0"
1408
-
1409
- output = Gem::Util.gunzip input
1410
-
1411
- assert_equal "hello", output
1412
- assert_equal Encoding::BINARY, output.encoding
1413
- end
1414
-
1415
- def test_self_gzip
1416
- input = "hello"
1417
-
1418
- output = Gem::Util.gzip input
1419
-
1420
- zipped = StringIO.new output
1421
-
1422
- assert_equal "hello", Zlib::GzipReader.new(zipped).read
1423
- assert_equal Encoding::BINARY, output.encoding
1424
- end
1425
-
1426
- def test_self_vendor_dir
1427
- vendordir(File.join(@tempdir, "vendor")) do
1428
- expected =
1429
- File.join RbConfig::CONFIG["vendordir"], "gems",
1430
- RbConfig::CONFIG["ruby_version"]
1431
-
1432
- assert_equal expected, Gem.vendor_dir
1433
- end
1434
- end
1435
-
1436
- def test_self_vendor_dir_ENV_GEM_VENDOR
1437
- ENV["GEM_VENDOR"] = File.join @tempdir, "vendor", "gems"
1438
-
1439
- assert_equal ENV["GEM_VENDOR"], Gem.vendor_dir
1440
- refute Gem.vendor_dir.frozen?
1441
- end
1442
-
1443
- def test_self_vendor_dir_missing
1444
- vendordir(nil) do
1445
- assert_nil Gem.vendor_dir
1446
- end
1447
- end
1448
-
1449
- def test_load_plugins
1450
- plugin_path = File.join "lib", "rubygems_plugin.rb"
1451
-
1452
- foo1_plugin_path = nil
1453
- foo2_plugin_path = nil
1454
- Dir.chdir @tempdir do
1455
- FileUtils.mkdir_p "lib"
1456
- File.open plugin_path, "w" do |fp|
1457
- fp.puts "class TestGem; PLUGINS_LOADED << 'plugin'; end"
1458
- end
1459
-
1460
- foo1 = util_spec "foo", "1" do |s|
1461
- s.files << plugin_path
1462
- end
1463
- foo1_plugin_path = File.join(foo1.gem_dir, plugin_path)
1464
-
1465
- install_gem foo1
1466
-
1467
- foo2 = util_spec "foo", "2" do |s|
1468
- s.files << plugin_path
1469
- end
1470
- foo2_plugin_path = File.join(foo2.gem_dir, plugin_path)
1471
-
1472
- install_gem foo2
1473
- end
1474
-
1475
- Gem::Specification.reset
1476
- PLUGINS_LOADED.clear
1477
- $LOADED_FEATURES.delete(foo1_plugin_path)
1478
- $LOADED_FEATURES.delete(foo2_plugin_path)
1479
-
1480
- gem "foo"
1481
-
1482
- Gem.load_plugins
1483
-
1484
- assert_equal %w[plugin], PLUGINS_LOADED
1485
- end
1486
-
1487
- def test_load_user_installed_plugins
1488
- @orig_gem_home = ENV["GEM_HOME"]
1489
- ENV["GEM_HOME"] = @gemhome
1490
-
1491
- plugin_path = File.join "lib", "rubygems_plugin.rb"
1492
-
1493
- Dir.chdir @tempdir do
1494
- FileUtils.mkdir_p "lib"
1495
- File.open plugin_path, "w" do |fp|
1496
- fp.puts "class TestGem; PLUGINS_LOADED << 'plugin'; end"
1497
- end
1498
-
1499
- foo = util_spec "foo", "1" do |s|
1500
- s.files << plugin_path
1501
- end
1502
-
1503
- install_gem_user foo
1504
- end
1505
-
1506
- Gem.paths = { "GEM_PATH" => [Gem.dir, Gem.user_dir].join(File::PATH_SEPARATOR) }
1507
-
1508
- gem "foo"
1509
-
1510
- Gem.load_plugins
1511
-
1512
- assert_equal %w[plugin], PLUGINS_LOADED
1513
- ensure
1514
- ENV["GEM_HOME"] = @orig_gem_home
1515
- end
1516
-
1517
- def test_load_env_plugins
1518
- with_plugin("load") { Gem.load_env_plugins }
1519
- begin
1520
- assert_equal :loaded, TEST_PLUGIN_LOAD
1521
- rescue StandardError
1522
- nil
1523
- end
1524
-
1525
- util_remove_interrupt_command
1526
-
1527
- # Should attempt to cause a StandardError
1528
- with_plugin("standarderror") { Gem.load_env_plugins }
1529
- begin
1530
- assert_equal :loaded, TEST_PLUGIN_STANDARDERROR
1531
- rescue StandardError
1532
- nil
1533
- end
1534
-
1535
- util_remove_interrupt_command
1536
-
1537
- # Should attempt to cause an Exception
1538
- with_plugin("exception") { Gem.load_env_plugins }
1539
- begin
1540
- assert_equal :loaded, TEST_PLUGIN_EXCEPTION
1541
- rescue StandardError
1542
- nil
1543
- end
1544
- end
1545
-
1546
- def test_gem_path_ordering
1547
- refute_equal Gem.dir, Gem.user_dir
1548
-
1549
- write_file File.join(@tempdir, "lib", "g.rb") {|fp| fp.puts "" }
1550
- write_file File.join(@tempdir, "lib", "m.rb") {|fp| fp.puts "" }
1551
-
1552
- g = util_spec "g", "1", nil, "lib/g.rb"
1553
- m = util_spec "m", "1", nil, "lib/m.rb"
1554
-
1555
- install_gem g, :install_dir => Gem.dir
1556
- m0 = install_gem m, :install_dir => Gem.dir
1557
- m1 = install_gem m, :install_dir => Gem.user_dir
1558
-
1559
- assert_equal m0.gem_dir, File.join(Gem.dir, "gems", "m-1")
1560
- assert_equal m1.gem_dir, File.join(Gem.user_dir, "gems", "m-1")
1561
-
1562
- tests = [
1563
- [:dir0, [ Gem.dir, Gem.user_dir], m0],
1564
- [:dir1, [ Gem.user_dir, Gem.dir], m1],
1565
- ]
1566
-
1567
- tests.each do |_name, _paths, expected|
1568
- Gem.use_paths _paths.first, _paths
1569
- Gem::Specification.reset
1570
- Gem.searcher = nil
1571
-
1572
- assert_equal Gem::Dependency.new("m","1").to_specs,
1573
- Gem::Dependency.new("m","1").to_specs.sort
1574
-
1575
- assert_equal \
1576
- [expected.gem_dir],
1577
- Gem::Dependency.new("m","1").to_specs.map(&:gem_dir).sort,
1578
- "Wrong specs for #{_name}"
1579
-
1580
- spec = Gem::Dependency.new("m","1").to_spec
1581
-
1582
- assert_equal \
1583
- File.join(_paths.first, "gems", "m-1"),
1584
- spec.gem_dir,
1585
- "Wrong spec before require for #{_name}"
1586
- refute spec.activated?, "dependency already activated for #{_name}"
1587
-
1588
- gem "m"
1589
-
1590
- spec = Gem::Dependency.new("m","1").to_spec
1591
- assert spec.activated?, "dependency not activated for #{_name}"
1592
-
1593
- assert_equal \
1594
- File.join(_paths.first, "gems", "m-1"),
1595
- spec.gem_dir,
1596
- "Wrong spec after require for #{_name}"
1597
-
1598
- spec.instance_variable_set :@activated, false
1599
- Gem.loaded_specs.delete(spec.name)
1600
- $:.delete(File.join(spec.gem_dir, "lib"))
1601
- end
1602
- end
1603
-
1604
- def test_gem_path_ordering_short
1605
- write_file File.join(@tempdir, "lib", "g.rb") {|fp| fp.puts "" }
1606
- write_file File.join(@tempdir, "lib", "m.rb") {|fp| fp.puts "" }
1607
-
1608
- g = util_spec "g", "1", nil, "lib/g.rb"
1609
- m = util_spec "m", "1", nil, "lib/m.rb"
1610
-
1611
- install_gem g, :install_dir => Gem.dir
1612
- install_gem m, :install_dir => Gem.dir
1613
- install_gem m, :install_dir => Gem.user_dir
1614
-
1615
- Gem.use_paths Gem.dir, [ Gem.dir, Gem.user_dir]
1616
-
1617
- assert_equal \
1618
- File.join(Gem.dir, "gems", "m-1"),
1619
- Gem::Dependency.new("m","1").to_spec.gem_dir,
1620
- "Wrong spec selected"
1621
- end
1622
-
1623
- def test_register_default_spec
1624
- Gem.clear_default_specs
1625
-
1626
- old_style = Gem::Specification.new do |spec|
1627
- spec.files = ["foo.rb", "bar.rb"]
1628
- end
1629
-
1630
- Gem.register_default_spec old_style
1631
-
1632
- assert_equal old_style, Gem.find_unresolved_default_spec("foo.rb")
1633
- assert_equal old_style, Gem.find_unresolved_default_spec("bar.rb")
1634
- assert_nil Gem.find_unresolved_default_spec("baz.rb")
1635
-
1636
- Gem.clear_default_specs
1637
-
1638
- new_style = Gem::Specification.new do |spec|
1639
- spec.files = ["lib/foo.rb", "ext/bar.rb", "bin/exec", "README"]
1640
- spec.require_paths = ["lib", "ext"]
1641
- end
1642
-
1643
- Gem.register_default_spec new_style
1644
-
1645
- assert_equal new_style, Gem.find_unresolved_default_spec("foo.rb")
1646
- assert_equal new_style, Gem.find_unresolved_default_spec("bar.rb")
1647
- assert_nil Gem.find_unresolved_default_spec("exec")
1648
- assert_nil Gem.find_unresolved_default_spec("README")
1649
- end
1650
-
1651
- def test_register_default_spec_old_style_with_folder_starting_with_lib
1652
- Gem.clear_default_specs
1653
-
1654
- old_style = Gem::Specification.new do |spec|
1655
- spec.files = ["libexec/bundle", "foo.rb", "bar.rb"]
1656
- end
1657
-
1658
- Gem.register_default_spec old_style
1659
-
1660
- assert_equal old_style, Gem.find_unresolved_default_spec("foo.rb")
1661
- end
1662
-
1663
- def test_operating_system_defaults
1664
- operating_system_defaults = Gem.operating_system_defaults
1665
-
1666
- assert operating_system_defaults != nil
1667
- assert operating_system_defaults.is_a? Hash
1668
- end
1669
-
1670
- def test_platform_defaults
1671
- platform_defaults = Gem.platform_defaults
1672
-
1673
- assert platform_defaults != nil
1674
- assert platform_defaults.is_a? Hash
1675
- end
1676
-
1677
- # Ensure that `Gem.source_date_epoch` is consistent even if
1678
- # $SOURCE_DATE_EPOCH has not been set.
1679
- def test_default_source_date_epoch_doesnt_change
1680
- old_epoch = ENV["SOURCE_DATE_EPOCH"]
1681
- ENV["SOURCE_DATE_EPOCH"] = nil
1682
-
1683
- # Unfortunately, there is no real way to test this aside from waiting
1684
- # enough for `Time.now.to_i` to change -- which is a whole second.
1685
- #
1686
- # Fortunately, we only need to do this once.
1687
- a = Gem.source_date_epoch
1688
- sleep 1
1689
- b = Gem.source_date_epoch
1690
- assert_equal a, b
1691
- ensure
1692
- ENV["SOURCE_DATE_EPOCH"] = old_epoch
1693
- end
1694
-
1695
- def test_data_home_default
1696
- expected = File.join(@userhome, ".local", "share")
1697
- assert_equal expected, Gem.data_home
1698
- end
1699
-
1700
- def test_data_home_from_env
1701
- ENV["XDG_DATA_HOME"] = expected = "/test/data/home"
1702
- assert_equal expected, Gem.data_home
1703
- end
1704
-
1705
- def test_state_home_default
1706
- Gem.instance_variable_set :@state_home, nil
1707
- Gem.data_home # memoize @data_home, to demonstrate GH-6418
1708
- expected = File.join(@userhome, ".local", "state")
1709
- assert_equal expected, Gem.state_home
1710
- end
1711
-
1712
- def test_state_home_from_env
1713
- Gem.instance_variable_set :@state_home, nil
1714
- Gem.data_home # memoize @data_home, to demonstrate GH-6418
1715
- ENV["XDG_STATE_HOME"] = expected = "/test/state/home"
1716
- assert_equal expected, Gem.state_home
1717
- end
1718
-
1719
- private
1720
-
1721
- def ruby_install_name(name)
1722
- with_clean_path_to_ruby do
1723
- orig_RUBY_INSTALL_NAME = RbConfig::CONFIG["ruby_install_name"]
1724
- RbConfig::CONFIG["ruby_install_name"] = name
1725
-
1726
- begin
1727
- yield
1728
- ensure
1729
- if orig_RUBY_INSTALL_NAME
1730
- RbConfig::CONFIG["ruby_install_name"] = orig_RUBY_INSTALL_NAME
1731
- else
1732
- RbConfig::CONFIG.delete "ruby_install_name"
1733
- end
1734
- end
1735
- end
1736
- end
1737
-
1738
- def with_rb_config_ruby(path)
1739
- rb_config_singleton_class = class << RbConfig; self; end
1740
- orig_path = RbConfig.ruby
1741
-
1742
- redefine_method(rb_config_singleton_class, :ruby, path)
1743
-
1744
- yield
1745
- ensure
1746
- redefine_method(rb_config_singleton_class, :ruby, orig_path)
1747
- end
1748
-
1749
- def redefine_method(base, method, new_result)
1750
- base.alias_method(method, method)
1751
- base.define_method(method) { new_result }
1752
- end
1753
-
1754
- def with_plugin(path)
1755
- test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}",
1756
- PROJECT_DIR)
1757
-
1758
- # A single test plugin should get loaded once only, in order to preserve
1759
- # sane test semantics.
1760
- refute_includes $LOAD_PATH, test_plugin_path
1761
- $LOAD_PATH.unshift test_plugin_path
1762
-
1763
- capture_output do
1764
- yield
1765
- end
1766
- ensure
1767
- $LOAD_PATH.delete test_plugin_path
1768
- end
1769
-
1770
- def util_ensure_gem_dirs
1771
- Gem.ensure_gem_subdirectories @gemhome
1772
-
1773
- #
1774
- # FIXME what does this solve precisely? -ebh
1775
- #
1776
- @additional.each do |dir|
1777
- Gem.ensure_gem_subdirectories @gemhome
1778
- end
1779
- end
1780
-
1781
- def util_exec_gem
1782
- spec, _ = util_spec "a", "4" do |s|
1783
- s.executables = ["exec", "abin"]
1784
- end
1785
-
1786
- @exec_path = File.join spec.full_gem_path, spec.bindir, "exec"
1787
- @abin_path = File.join spec.full_gem_path, spec.bindir, "abin"
1788
- spec
1789
- end
1790
-
1791
- def util_remove_interrupt_command
1792
- Gem::Commands.send :remove_const, :InterruptCommand if
1793
- Gem::Commands.const_defined? :InterruptCommand
1794
- end
1795
-
1796
- def util_cache_dir
1797
- File.join Gem.dir, "cache"
1798
- end
1799
- end