rubygems-update 3.4.22 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (528) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +99 -2
  3. data/Manifest.txt +34 -221
  4. data/README.md +1 -3
  5. data/bundler/CHANGELOG.md +53 -0
  6. data/bundler/bundler.gemspec +4 -2
  7. data/bundler/exe/bundle +1 -10
  8. data/bundler/lib/bundler/build_metadata.rb +3 -3
  9. data/bundler/lib/bundler/capistrano.rb +1 -1
  10. data/bundler/lib/bundler/checksum.rb +245 -0
  11. data/bundler/lib/bundler/ci_detector.rb +75 -0
  12. data/bundler/lib/bundler/cli/add.rb +3 -3
  13. data/bundler/lib/bundler/cli/binstubs.rb +4 -4
  14. data/bundler/lib/bundler/cli/cache.rb +1 -1
  15. data/bundler/lib/bundler/cli/check.rb +1 -1
  16. data/bundler/lib/bundler/cli/common.rb +9 -1
  17. data/bundler/lib/bundler/cli/config.rb +8 -7
  18. data/bundler/lib/bundler/cli/console.rb +3 -2
  19. data/bundler/lib/bundler/cli/doctor.rb +2 -2
  20. data/bundler/lib/bundler/cli/exec.rb +1 -1
  21. data/bundler/lib/bundler/cli/gem.rb +28 -23
  22. data/bundler/lib/bundler/cli/info.rb +2 -13
  23. data/bundler/lib/bundler/cli/install.rb +5 -4
  24. data/bundler/lib/bundler/cli/issue.rb +1 -1
  25. data/bundler/lib/bundler/cli/lock.rb +4 -4
  26. data/bundler/lib/bundler/cli/open.rb +1 -1
  27. data/bundler/lib/bundler/cli/outdated.rb +6 -6
  28. data/bundler/lib/bundler/cli/plugin.rb +7 -14
  29. data/bundler/lib/bundler/cli/pristine.rb +38 -30
  30. data/bundler/lib/bundler/cli/show.rb +2 -2
  31. data/bundler/lib/bundler/cli/update.rb +5 -5
  32. data/bundler/lib/bundler/cli.rb +215 -263
  33. data/bundler/lib/bundler/compact_index_client/cache.rb +29 -9
  34. data/bundler/lib/bundler/compact_index_client/cache_file.rb +153 -0
  35. data/bundler/lib/bundler/compact_index_client/gem_parser.rb +7 -3
  36. data/bundler/lib/bundler/compact_index_client/updater.rb +79 -81
  37. data/bundler/lib/bundler/compact_index_client.rb +14 -7
  38. data/bundler/lib/bundler/constants.rb +1 -1
  39. data/bundler/lib/bundler/current_ruby.rb +5 -21
  40. data/bundler/lib/bundler/definition.rb +42 -15
  41. data/bundler/lib/bundler/dependency.rb +16 -12
  42. data/bundler/lib/bundler/digest.rb +2 -2
  43. data/bundler/lib/bundler/dsl.rb +43 -25
  44. data/bundler/lib/bundler/endpoint_specification.rb +5 -1
  45. data/bundler/lib/bundler/env.rb +1 -3
  46. data/bundler/lib/bundler/errors.rb +43 -0
  47. data/bundler/lib/bundler/fetcher/base.rb +3 -1
  48. data/bundler/lib/bundler/fetcher/compact_index.rb +4 -4
  49. data/bundler/lib/bundler/fetcher/downloader.rb +13 -11
  50. data/bundler/lib/bundler/fetcher/gem_remote_fetcher.rb +16 -0
  51. data/bundler/lib/bundler/fetcher/index.rb +1 -1
  52. data/bundler/lib/bundler/fetcher.rb +28 -25
  53. data/bundler/lib/bundler/friendly_errors.rb +5 -5
  54. data/bundler/lib/bundler/gem_helper.rb +1 -1
  55. data/bundler/lib/bundler/gem_helpers.rb +5 -2
  56. data/bundler/lib/bundler/graph.rb +9 -9
  57. data/bundler/lib/bundler/index.rb +1 -2
  58. data/bundler/lib/bundler/injector.rb +1 -1
  59. data/bundler/lib/bundler/inline.rb +3 -3
  60. data/bundler/lib/bundler/installer/gem_installer.rb +5 -5
  61. data/bundler/lib/bundler/installer/parallel_installer.rb +16 -8
  62. data/bundler/lib/bundler/installer/standalone.rb +2 -3
  63. data/bundler/lib/bundler/installer.rb +9 -9
  64. data/bundler/lib/bundler/lazy_specification.rb +24 -17
  65. data/bundler/lib/bundler/lockfile_generator.rb +9 -0
  66. data/bundler/lib/bundler/lockfile_parser.rb +81 -10
  67. data/bundler/lib/bundler/man/bundle-add.1 +3 -26
  68. data/bundler/lib/bundler/man/bundle-binstubs.1 +4 -16
  69. data/bundler/lib/bundler/man/bundle-cache.1 +3 -24
  70. data/bundler/lib/bundler/man/bundle-check.1 +3 -12
  71. data/bundler/lib/bundler/man/bundle-clean.1 +3 -10
  72. data/bundler/lib/bundler/man/bundle-config.1 +20 -211
  73. data/bundler/lib/bundler/man/bundle-config.1.ronn +6 -0
  74. data/bundler/lib/bundler/man/bundle-console.1 +4 -22
  75. data/bundler/lib/bundler/man/bundle-doctor.1 +4 -18
  76. data/bundler/lib/bundler/man/bundle-exec.1 +12 -73
  77. data/bundler/lib/bundler/man/bundle-gem.1 +13 -49
  78. data/bundler/lib/bundler/man/bundle-help.1 +3 -7
  79. data/bundler/lib/bundler/man/bundle-info.1 +3 -9
  80. data/bundler/lib/bundler/man/bundle-init.1 +3 -12
  81. data/bundler/lib/bundler/man/bundle-inject.1 +6 -19
  82. data/bundler/lib/bundler/man/bundle-install.1 +27 -125
  83. data/bundler/lib/bundler/man/bundle-install.1.ronn +1 -0
  84. data/bundler/lib/bundler/man/bundle-list.1 +4 -19
  85. data/bundler/lib/bundler/man/bundle-lock.1 +5 -29
  86. data/bundler/lib/bundler/man/bundle-open.1 +7 -27
  87. data/bundler/lib/bundler/man/bundle-outdated.1 +3 -55
  88. data/bundler/lib/bundler/man/bundle-outdated.1.ronn +1 -0
  89. data/bundler/lib/bundler/man/bundle-platform.1 +5 -27
  90. data/bundler/lib/bundler/man/bundle-plugin.1 +3 -29
  91. data/bundler/lib/bundler/man/bundle-pristine.1 +5 -16
  92. data/bundler/lib/bundler/man/bundle-remove.1 +4 -14
  93. data/bundler/lib/bundler/man/bundle-show.1 +3 -10
  94. data/bundler/lib/bundler/man/bundle-update.1 +18 -137
  95. data/bundler/lib/bundler/man/bundle-version.1 +3 -16
  96. data/bundler/lib/bundler/man/bundle-viz.1 +4 -16
  97. data/bundler/lib/bundler/man/bundle.1 +5 -44
  98. data/bundler/lib/bundler/man/gemfile.5 +24 -301
  99. data/bundler/lib/bundler/man/gemfile.5.ronn +4 -0
  100. data/bundler/lib/bundler/match_metadata.rb +4 -0
  101. data/bundler/lib/bundler/match_platform.rb +1 -1
  102. data/bundler/lib/bundler/plugin/api/source.rb +3 -2
  103. data/bundler/lib/bundler/plugin/installer.rb +1 -1
  104. data/bundler/lib/bundler/plugin.rb +3 -3
  105. data/bundler/lib/bundler/resolver/base.rb +1 -1
  106. data/bundler/lib/bundler/resolver/incompatibility.rb +1 -1
  107. data/bundler/lib/bundler/resolver/spec_group.rb +1 -4
  108. data/bundler/lib/bundler/resolver.rb +16 -16
  109. data/bundler/lib/bundler/ruby_dsl.rb +20 -12
  110. data/bundler/lib/bundler/ruby_version.rb +1 -1
  111. data/bundler/lib/bundler/rubygems_ext.rb +24 -50
  112. data/bundler/lib/bundler/rubygems_gem_installer.rb +6 -56
  113. data/bundler/lib/bundler/rubygems_integration.rb +25 -94
  114. data/bundler/lib/bundler/runtime.rb +2 -2
  115. data/bundler/lib/bundler/self_manager.rb +23 -7
  116. data/bundler/lib/bundler/settings.rb +27 -7
  117. data/bundler/lib/bundler/setup.rb +4 -1
  118. data/bundler/lib/bundler/shared_helpers.rb +35 -13
  119. data/bundler/lib/bundler/source/git/git_proxy.rb +15 -15
  120. data/bundler/lib/bundler/source/git.rb +4 -3
  121. data/bundler/lib/bundler/source/metadata.rb +15 -15
  122. data/bundler/lib/bundler/source/path.rb +7 -6
  123. data/bundler/lib/bundler/source/rubygems.rb +21 -14
  124. data/bundler/lib/bundler/source.rb +2 -0
  125. data/bundler/lib/bundler/spec_set.rb +38 -10
  126. data/bundler/lib/bundler/stub_specification.rb +1 -0
  127. data/bundler/lib/bundler/templates/Executable.bundler +1 -1
  128. data/bundler/lib/bundler/templates/newgem/README.md.tt +3 -3
  129. data/bundler/lib/bundler/templates/newgem/Rakefile.tt +2 -6
  130. data/bundler/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt +1 -1
  131. data/bundler/lib/bundler/templates/newgem/standard.yml.tt +1 -1
  132. data/bundler/lib/bundler/ui/shell.rb +1 -1
  133. data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb +1 -1
  134. data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +53 -6
  135. data/bundler/lib/bundler/vendor/fileutils/lib/fileutils.rb +8 -20
  136. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb +3 -3
  137. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb +2 -2
  138. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb +1 -1
  139. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +35 -35
  140. data/bundler/lib/bundler/vendor/tsort/lib/tsort.rb +3 -0
  141. data/bundler/lib/bundler/vendor/uri/lib/uri/common.rb +256 -132
  142. data/bundler/lib/bundler/vendor/uri/lib/uri/generic.rb +1 -0
  143. data/bundler/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +95 -31
  144. data/bundler/lib/bundler/vendor/uri/lib/uri/version.rb +1 -1
  145. data/bundler/lib/bundler/vendored_net_http.rb +8 -0
  146. data/bundler/lib/bundler/vendored_persistent.rb +0 -4
  147. data/bundler/lib/bundler/vendored_timeout.rb +8 -0
  148. data/bundler/lib/bundler/version.rb +1 -1
  149. data/bundler/lib/bundler/vlad.rb +1 -1
  150. data/bundler/lib/bundler/yaml_serializer.rb +3 -3
  151. data/bundler/lib/bundler.rb +38 -27
  152. data/lib/rubygems/available_set.rb +4 -4
  153. data/lib/rubygems/basic_specification.rb +35 -37
  154. data/lib/rubygems/bundler_version_finder.rb +4 -4
  155. data/lib/rubygems/ci_detector.rb +75 -0
  156. data/lib/rubygems/command.rb +13 -15
  157. data/lib/rubygems/command_manager.rb +5 -4
  158. data/lib/rubygems/commands/build_command.rb +2 -2
  159. data/lib/rubygems/commands/cert_command.rb +1 -2
  160. data/lib/rubygems/commands/check_command.rb +4 -4
  161. data/lib/rubygems/commands/cleanup_command.rb +12 -14
  162. data/lib/rubygems/commands/contents_command.rb +4 -4
  163. data/lib/rubygems/commands/dependency_command.rb +4 -5
  164. data/lib/rubygems/commands/environment_command.rb +1 -3
  165. data/lib/rubygems/commands/exec_command.rb +1 -1
  166. data/lib/rubygems/commands/fetch_command.rb +2 -2
  167. data/lib/rubygems/commands/generate_index_command.rb +39 -74
  168. data/lib/rubygems/commands/help_command.rb +3 -3
  169. data/lib/rubygems/commands/info_command.rb +2 -2
  170. data/lib/rubygems/commands/install_command.rb +8 -16
  171. data/lib/rubygems/commands/list_command.rb +2 -2
  172. data/lib/rubygems/commands/lock_command.rb +1 -1
  173. data/lib/rubygems/commands/open_command.rb +1 -1
  174. data/lib/rubygems/commands/owner_command.rb +1 -1
  175. data/lib/rubygems/commands/pristine_command.rb +13 -15
  176. data/lib/rubygems/commands/push_command.rb +2 -2
  177. data/lib/rubygems/commands/query_command.rb +4 -5
  178. data/lib/rubygems/commands/rdoc_command.rb +2 -2
  179. data/lib/rubygems/commands/search_command.rb +2 -2
  180. data/lib/rubygems/commands/setup_command.rb +31 -34
  181. data/lib/rubygems/commands/sources_command.rb +12 -12
  182. data/lib/rubygems/commands/specification_command.rb +10 -10
  183. data/lib/rubygems/commands/stale_command.rb +1 -1
  184. data/lib/rubygems/commands/uninstall_command.rb +9 -10
  185. data/lib/rubygems/commands/unpack_command.rb +4 -4
  186. data/lib/rubygems/commands/update_command.rb +10 -12
  187. data/lib/rubygems/commands/which_command.rb +1 -1
  188. data/lib/rubygems/commands/yank_command.rb +1 -1
  189. data/lib/rubygems/compatibility.rb +5 -6
  190. data/lib/rubygems/config_file.rb +4 -4
  191. data/lib/rubygems/core_ext/kernel_gem.rb +0 -2
  192. data/lib/rubygems/core_ext/kernel_require.rb +19 -48
  193. data/lib/rubygems/core_ext/kernel_warn.rb +1 -1
  194. data/lib/rubygems/core_ext/tcpsocket_init.rb +1 -1
  195. data/lib/rubygems/defaults.rb +15 -3
  196. data/lib/rubygems/dependency.rb +12 -14
  197. data/lib/rubygems/dependency_installer.rb +29 -30
  198. data/lib/rubygems/dependency_list.rb +1 -1
  199. data/lib/rubygems/deprecate.rb +16 -15
  200. data/lib/rubygems/doctor.rb +5 -5
  201. data/lib/rubygems/errors.rb +2 -6
  202. data/lib/rubygems/exceptions.rb +2 -1
  203. data/lib/rubygems/ext/builder.rb +15 -10
  204. data/lib/rubygems/ext/cargo_builder.rb +5 -5
  205. data/lib/rubygems/ext/ext_conf_builder.rb +1 -3
  206. data/lib/rubygems/gem_runner.rb +4 -4
  207. data/lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb +3 -3
  208. data/lib/rubygems/gemcutter_utilities/webauthn_poller.rb +3 -3
  209. data/lib/rubygems/gemcutter_utilities.rb +18 -19
  210. data/lib/rubygems/install_update_options.rb +18 -19
  211. data/lib/rubygems/installer.rb +59 -33
  212. data/lib/rubygems/installer_uninstaller_utils.rb +0 -2
  213. data/lib/rubygems/local_remote_options.rb +7 -10
  214. data/lib/rubygems/name_tuple.rb +7 -9
  215. data/lib/rubygems/net/http.rb +3 -0
  216. data/lib/rubygems/net-http/LICENSE.txt +22 -0
  217. data/lib/rubygems/net-http/lib/net/http/backward.rb +40 -0
  218. data/lib/rubygems/net-http/lib/net/http/exceptions.rb +34 -0
  219. data/lib/rubygems/net-http/lib/net/http/generic_request.rb +414 -0
  220. data/lib/rubygems/net-http/lib/net/http/header.rb +981 -0
  221. data/lib/rubygems/net-http/lib/net/http/proxy_delta.rb +17 -0
  222. data/lib/rubygems/net-http/lib/net/http/request.rb +88 -0
  223. data/lib/rubygems/net-http/lib/net/http/requests.rb +425 -0
  224. data/lib/rubygems/net-http/lib/net/http/response.rb +738 -0
  225. data/lib/rubygems/net-http/lib/net/http/responses.rb +1174 -0
  226. data/lib/rubygems/net-http/lib/net/http/status.rb +84 -0
  227. data/lib/rubygems/net-http/lib/net/http.rb +2496 -0
  228. data/lib/rubygems/net-http/lib/net/https.rb +23 -0
  229. data/lib/rubygems/net-protocol/LICENSE.txt +22 -0
  230. data/lib/rubygems/net-protocol/lib/net/protocol.rb +544 -0
  231. data/lib/rubygems/optparse/lib/optparse.rb +39 -17
  232. data/lib/rubygems/package/old.rb +2 -2
  233. data/lib/rubygems/package/tar_header.rb +45 -39
  234. data/lib/rubygems/package/tar_reader/entry.rb +5 -4
  235. data/lib/rubygems/package/tar_reader.rb +5 -3
  236. data/lib/rubygems/package/tar_writer.rb +19 -17
  237. data/lib/rubygems/package.rb +27 -26
  238. data/lib/rubygems/package_task.rb +2 -2
  239. data/lib/rubygems/path_support.rb +9 -10
  240. data/lib/rubygems/platform.rb +60 -45
  241. data/lib/rubygems/query_utils.rb +7 -9
  242. data/lib/rubygems/remote_fetcher.rb +15 -15
  243. data/lib/rubygems/request/connection_pools.rb +3 -3
  244. data/lib/rubygems/request.rb +20 -17
  245. data/lib/rubygems/request_set/gem_dependency_api.rb +119 -122
  246. data/lib/rubygems/request_set/lockfile/parser.rb +9 -9
  247. data/lib/rubygems/request_set/lockfile/tokenizer.rb +20 -12
  248. data/lib/rubygems/request_set/lockfile.rb +6 -11
  249. data/lib/rubygems/request_set.rb +5 -5
  250. data/lib/rubygems/requirement.rb +7 -7
  251. data/lib/rubygems/resolv/LICENSE.txt +22 -0
  252. data/lib/rubygems/resolv/lib/resolv.rb +3387 -0
  253. data/lib/rubygems/resolver/activation_request.rb +1 -3
  254. data/lib/rubygems/resolver/api_set/gem_parser.rb +7 -3
  255. data/lib/rubygems/resolver/best_set.rb +1 -1
  256. data/lib/rubygems/resolver/composed_set.rb +1 -1
  257. data/lib/rubygems/resolver/conflict.rb +4 -12
  258. data/lib/rubygems/resolver/index_set.rb +4 -4
  259. data/lib/rubygems/resolver/index_specification.rb +2 -2
  260. data/lib/rubygems/resolver/installer_set.rb +5 -6
  261. data/lib/rubygems/resolver/lock_set.rb +1 -1
  262. data/lib/rubygems/resolver.rb +3 -10
  263. data/lib/rubygems/s3_uri_signer.rb +6 -6
  264. data/lib/rubygems/safe_marshal/elements.rb +138 -0
  265. data/lib/rubygems/safe_marshal/reader.rb +306 -0
  266. data/lib/rubygems/safe_marshal/visitors/stream_printer.rb +31 -0
  267. data/lib/rubygems/safe_marshal/visitors/to_ruby.rb +385 -0
  268. data/lib/rubygems/safe_marshal/visitors/visitor.rb +74 -0
  269. data/lib/rubygems/safe_marshal.rb +74 -0
  270. data/lib/rubygems/safe_yaml.rb +5 -28
  271. data/lib/rubygems/security/policies.rb +36 -38
  272. data/lib/rubygems/security/policy.rb +7 -11
  273. data/lib/rubygems/security/signer.rb +1 -1
  274. data/lib/rubygems/security/trust_dir.rb +3 -3
  275. data/lib/rubygems/security.rb +8 -22
  276. data/lib/rubygems/source/git.rb +1 -3
  277. data/lib/rubygems/source/installed.rb +0 -2
  278. data/lib/rubygems/source/local.rb +5 -8
  279. data/lib/rubygems/source/lock.rb +1 -3
  280. data/lib/rubygems/source/specific_file.rb +0 -1
  281. data/lib/rubygems/source/vendor.rb +0 -2
  282. data/lib/rubygems/source.rb +12 -12
  283. data/lib/rubygems/source_list.rb +4 -4
  284. data/lib/rubygems/spec_fetcher.rb +29 -29
  285. data/lib/rubygems/specification.rb +125 -138
  286. data/lib/rubygems/specification_policy.rb +55 -25
  287. data/lib/rubygems/stub_specification.rb +4 -5
  288. data/lib/rubygems/text.rb +1 -2
  289. data/lib/rubygems/timeout/LICENSE.txt +22 -0
  290. data/lib/rubygems/timeout/lib/timeout.rb +199 -0
  291. data/lib/rubygems/timeout.rb +3 -0
  292. data/lib/rubygems/tsort/lib/tsort.rb +3 -0
  293. data/lib/rubygems/uninstaller.rb +7 -9
  294. data/lib/rubygems/update_suggestion.rb +5 -18
  295. data/lib/rubygems/uri_formatter.rb +1 -1
  296. data/lib/rubygems/user_interaction.rb +15 -21
  297. data/lib/rubygems/util/licenses.rb +65 -35
  298. data/lib/rubygems/util/list.rb +3 -1
  299. data/lib/rubygems/util.rb +2 -4
  300. data/lib/rubygems/validator.rb +5 -3
  301. data/lib/rubygems/version.rb +34 -28
  302. data/lib/rubygems/version_option.rb +2 -5
  303. data/lib/rubygems/yaml_serializer.rb +3 -3
  304. data/lib/rubygems.rb +37 -37
  305. data/rubygems-update.gemspec +4 -4
  306. data/setup.rb +2 -2
  307. metadata +38 -225
  308. data/lib/rubygems/indexer.rb +0 -428
  309. data/lib/rubygems/mock_gem_ui.rb +0 -86
  310. data/test/rubygems/alternate_cert.pem +0 -19
  311. data/test/rubygems/alternate_cert_32.pem +0 -19
  312. data/test/rubygems/alternate_key.pem +0 -27
  313. data/test/rubygems/bad_rake.rb +0 -3
  314. data/test/rubygems/bundler_test_gem.rb +0 -424
  315. data/test/rubygems/ca_cert.pem +0 -77
  316. data/test/rubygems/child_cert.pem +0 -19
  317. data/test/rubygems/child_cert_32.pem +0 -19
  318. data/test/rubygems/child_key.pem +0 -27
  319. data/test/rubygems/client.pem +0 -107
  320. data/test/rubygems/data/excon-0.7.7.gemspec.rz +0 -0
  321. data/test/rubygems/data/gem-private_key.pem +0 -27
  322. data/test/rubygems/data/gem-public_cert.pem +0 -20
  323. data/test/rubygems/data/null-required-ruby-version.gemspec.rz +0 -0
  324. data/test/rubygems/data/null-required-rubygems-version.gemspec.rz +0 -0
  325. data/test/rubygems/data/pry-0.4.7.gemspec.rz +0 -0
  326. data/test/rubygems/encrypted_private_key.pem +0 -30
  327. data/test/rubygems/expired_cert.pem +0 -19
  328. data/test/rubygems/fake_certlib/openssl.rb +0 -9
  329. data/test/rubygems/foo/discover.rb +0 -1
  330. data/test/rubygems/future_cert.pem +0 -19
  331. data/test/rubygems/future_cert_32.pem +0 -19
  332. data/test/rubygems/good_rake.rb +0 -3
  333. data/test/rubygems/grandchild_cert.pem +0 -19
  334. data/test/rubygems/grandchild_cert_32.pem +0 -19
  335. data/test/rubygems/grandchild_key.pem +0 -27
  336. data/test/rubygems/helper.rb +0 -1649
  337. data/test/rubygems/installer_test_case.rb +0 -248
  338. data/test/rubygems/invalid_client.pem +0 -49
  339. data/test/rubygems/invalid_issuer_cert.pem +0 -20
  340. data/test/rubygems/invalid_issuer_cert_32.pem +0 -20
  341. data/test/rubygems/invalid_key.pem +0 -27
  342. data/test/rubygems/invalid_signer_cert.pem +0 -19
  343. data/test/rubygems/invalid_signer_cert_32.pem +0 -19
  344. data/test/rubygems/invalidchild_cert.pem +0 -19
  345. data/test/rubygems/invalidchild_cert_32.pem +0 -19
  346. data/test/rubygems/invalidchild_key.pem +0 -27
  347. data/test/rubygems/multifactor_auth_utilities.rb +0 -111
  348. data/test/rubygems/package/tar_test_case.rb +0 -175
  349. data/test/rubygems/packages/Bluebie-legs-0.6.2.gem +0 -0
  350. data/test/rubygems/packages/ascii_binder-0.1.10.1.gem +0 -0
  351. data/test/rubygems/packages/ill-formatted-platform-1.0.0.10.gem +0 -0
  352. data/test/rubygems/plugin/exception/rubygems_plugin.rb +0 -4
  353. data/test/rubygems/plugin/load/rubygems_plugin.rb +0 -5
  354. data/test/rubygems/plugin/standarderror/rubygems_plugin.rb +0 -4
  355. data/test/rubygems/private3072_key.pem +0 -40
  356. data/test/rubygems/private_ec_key.pem +0 -9
  357. data/test/rubygems/private_key.pem +0 -27
  358. data/test/rubygems/public3072_cert.pem +0 -25
  359. data/test/rubygems/public_cert.pem +0 -20
  360. data/test/rubygems/public_cert_32.pem +0 -19
  361. data/test/rubygems/public_key.pem +0 -9
  362. data/test/rubygems/rubygems/commands/crash_command.rb +0 -5
  363. data/test/rubygems/rubygems_plugin.rb +0 -24
  364. data/test/rubygems/sff/discover.rb +0 -1
  365. data/test/rubygems/simple_gem.rb +0 -68
  366. data/test/rubygems/specifications/bar-0.0.2.gemspec +0 -9
  367. data/test/rubygems/specifications/foo-0.0.1-x86-mswin32.gemspec +0 -0
  368. data/test/rubygems/specifications/rubyforge-0.0.1.gemspec +0 -14
  369. data/test/rubygems/ssl_cert.pem +0 -80
  370. data/test/rubygems/ssl_key.pem +0 -27
  371. data/test/rubygems/test_bundled_ca.rb +0 -61
  372. data/test/rubygems/test_config.rb +0 -28
  373. data/test/rubygems/test_deprecate.rb +0 -158
  374. data/test/rubygems/test_exit.rb +0 -17
  375. data/test/rubygems/test_gem.rb +0 -1799
  376. data/test/rubygems/test_gem_available_set.rb +0 -130
  377. data/test/rubygems/test_gem_bundler_version_finder.rb +0 -127
  378. data/test/rubygems/test_gem_command.rb +0 -403
  379. data/test/rubygems/test_gem_command_manager.rb +0 -400
  380. data/test/rubygems/test_gem_commands_build_command.rb +0 -739
  381. data/test/rubygems/test_gem_commands_cert_command.rb +0 -866
  382. data/test/rubygems/test_gem_commands_check_command.rb +0 -68
  383. data/test/rubygems/test_gem_commands_cleanup_command.rb +0 -292
  384. data/test/rubygems/test_gem_commands_contents_command.rb +0 -271
  385. data/test/rubygems/test_gem_commands_dependency_command.rb +0 -228
  386. data/test/rubygems/test_gem_commands_environment_command.rb +0 -169
  387. data/test/rubygems/test_gem_commands_exec_command.rb +0 -857
  388. data/test/rubygems/test_gem_commands_fetch_command.rb +0 -258
  389. data/test/rubygems/test_gem_commands_generate_index_command.rb +0 -81
  390. data/test/rubygems/test_gem_commands_help_command.rb +0 -94
  391. data/test/rubygems/test_gem_commands_info_command.rb +0 -70
  392. data/test/rubygems/test_gem_commands_install_command.rb +0 -1573
  393. data/test/rubygems/test_gem_commands_list_command.rb +0 -33
  394. data/test/rubygems/test_gem_commands_lock_command.rb +0 -67
  395. data/test/rubygems/test_gem_commands_mirror.rb +0 -20
  396. data/test/rubygems/test_gem_commands_open_command.rb +0 -101
  397. data/test/rubygems/test_gem_commands_outdated_command.rb +0 -50
  398. data/test/rubygems/test_gem_commands_owner_command.rb +0 -503
  399. data/test/rubygems/test_gem_commands_pristine_command.rb +0 -708
  400. data/test/rubygems/test_gem_commands_push_command.rb +0 -603
  401. data/test/rubygems/test_gem_commands_query_command.rb +0 -858
  402. data/test/rubygems/test_gem_commands_search_command.rb +0 -16
  403. data/test/rubygems/test_gem_commands_server_command.rb +0 -20
  404. data/test/rubygems/test_gem_commands_setup_command.rb +0 -474
  405. data/test/rubygems/test_gem_commands_signin_command.rb +0 -259
  406. data/test/rubygems/test_gem_commands_signout_command.rb +0 -30
  407. data/test/rubygems/test_gem_commands_sources_command.rb +0 -534
  408. data/test/rubygems/test_gem_commands_specification_command.rb +0 -277
  409. data/test/rubygems/test_gem_commands_stale_command.rb +0 -43
  410. data/test/rubygems/test_gem_commands_uninstall_command.rb +0 -542
  411. data/test/rubygems/test_gem_commands_unpack_command.rb +0 -224
  412. data/test/rubygems/test_gem_commands_update_command.rb +0 -836
  413. data/test/rubygems/test_gem_commands_which_command.rb +0 -85
  414. data/test/rubygems/test_gem_commands_yank_command.rb +0 -299
  415. data/test/rubygems/test_gem_config_file.rb +0 -551
  416. data/test/rubygems/test_gem_dependency.rb +0 -398
  417. data/test/rubygems/test_gem_dependency_installer.rb +0 -1190
  418. data/test/rubygems/test_gem_dependency_list.rb +0 -265
  419. data/test/rubygems/test_gem_dependency_resolution_error.rb +0 -27
  420. data/test/rubygems/test_gem_doctor.rb +0 -195
  421. data/test/rubygems/test_gem_ext_builder.rb +0 -337
  422. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/.gitignore +0 -1
  423. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec +0 -10
  424. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.lock +0 -249
  425. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.toml +0 -10
  426. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/src/lib.rs +0 -27
  427. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/lib/custom_name.rb +0 -3
  428. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/.gitignore +0 -1
  429. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.lock +0 -249
  430. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.toml +0 -10
  431. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/rust_ruby_example.gemspec +0 -10
  432. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/src/lib.rs +0 -51
  433. data/test/rubygems/test_gem_ext_cargo_builder.rb +0 -167
  434. data/test/rubygems/test_gem_ext_cargo_builder_link_flag_converter.rb +0 -34
  435. data/test/rubygems/test_gem_ext_cargo_builder_unit.rb +0 -60
  436. data/test/rubygems/test_gem_ext_cmake_builder.rb +0 -84
  437. data/test/rubygems/test_gem_ext_configure_builder.rb +0 -80
  438. data/test/rubygems/test_gem_ext_ext_conf_builder.rb +0 -229
  439. data/test/rubygems/test_gem_ext_rake_builder.rb +0 -113
  440. data/test/rubygems/test_gem_gem_runner.rb +0 -119
  441. data/test/rubygems/test_gem_gemcutter_utilities.rb +0 -361
  442. data/test/rubygems/test_gem_impossible_dependencies_error.rb +0 -60
  443. data/test/rubygems/test_gem_indexer.rb +0 -381
  444. data/test/rubygems/test_gem_install_update_options.rb +0 -208
  445. data/test/rubygems/test_gem_installer.rb +0 -2512
  446. data/test/rubygems/test_gem_local_remote_options.rb +0 -133
  447. data/test/rubygems/test_gem_name_tuple.rb +0 -43
  448. data/test/rubygems/test_gem_package.rb +0 -1306
  449. data/test/rubygems/test_gem_package_old.rb +0 -91
  450. data/test/rubygems/test_gem_package_tar_header.rb +0 -226
  451. data/test/rubygems/test_gem_package_tar_reader.rb +0 -150
  452. data/test/rubygems/test_gem_package_tar_reader_entry.rb +0 -350
  453. data/test/rubygems/test_gem_package_tar_writer.rb +0 -331
  454. data/test/rubygems/test_gem_package_task.rb +0 -118
  455. data/test/rubygems/test_gem_path_support.rb +0 -139
  456. data/test/rubygems/test_gem_platform.rb +0 -497
  457. data/test/rubygems/test_gem_rdoc.rb +0 -137
  458. data/test/rubygems/test_gem_remote_fetcher.rb +0 -1227
  459. data/test/rubygems/test_gem_request.rb +0 -547
  460. data/test/rubygems/test_gem_request_connection_pools.rb +0 -152
  461. data/test/rubygems/test_gem_request_set.rb +0 -672
  462. data/test/rubygems/test_gem_request_set_gem_dependency_api.rb +0 -853
  463. data/test/rubygems/test_gem_request_set_lockfile.rb +0 -469
  464. data/test/rubygems/test_gem_request_set_lockfile_parser.rb +0 -544
  465. data/test/rubygems/test_gem_request_set_lockfile_tokenizer.rb +0 -307
  466. data/test/rubygems/test_gem_requirement.rb +0 -505
  467. data/test/rubygems/test_gem_resolver.rb +0 -859
  468. data/test/rubygems/test_gem_resolver_activation_request.rb +0 -43
  469. data/test/rubygems/test_gem_resolver_api_set.rb +0 -210
  470. data/test/rubygems/test_gem_resolver_api_specification.rb +0 -167
  471. data/test/rubygems/test_gem_resolver_best_set.rb +0 -159
  472. data/test/rubygems/test_gem_resolver_composed_set.rb +0 -44
  473. data/test/rubygems/test_gem_resolver_conflict.rb +0 -82
  474. data/test/rubygems/test_gem_resolver_dependency_request.rb +0 -83
  475. data/test/rubygems/test_gem_resolver_git_set.rb +0 -188
  476. data/test/rubygems/test_gem_resolver_git_specification.rb +0 -114
  477. data/test/rubygems/test_gem_resolver_index_set.rb +0 -88
  478. data/test/rubygems/test_gem_resolver_index_specification.rb +0 -93
  479. data/test/rubygems/test_gem_resolver_installed_specification.rb +0 -47
  480. data/test/rubygems/test_gem_resolver_installer_set.rb +0 -320
  481. data/test/rubygems/test_gem_resolver_local_specification.rb +0 -44
  482. data/test/rubygems/test_gem_resolver_lock_set.rb +0 -62
  483. data/test/rubygems/test_gem_resolver_lock_specification.rb +0 -98
  484. data/test/rubygems/test_gem_resolver_requirement_list.rb +0 -19
  485. data/test/rubygems/test_gem_resolver_specification.rb +0 -63
  486. data/test/rubygems/test_gem_resolver_vendor_set.rb +0 -82
  487. data/test/rubygems/test_gem_resolver_vendor_specification.rb +0 -82
  488. data/test/rubygems/test_gem_security.rb +0 -341
  489. data/test/rubygems/test_gem_security_policy.rb +0 -535
  490. data/test/rubygems/test_gem_security_signer.rb +0 -218
  491. data/test/rubygems/test_gem_security_trust_dir.rb +0 -99
  492. data/test/rubygems/test_gem_silent_ui.rb +0 -123
  493. data/test/rubygems/test_gem_source.rb +0 -254
  494. data/test/rubygems/test_gem_source_fetch_problem.rb +0 -37
  495. data/test/rubygems/test_gem_source_git.rb +0 -310
  496. data/test/rubygems/test_gem_source_installed.rb +0 -35
  497. data/test/rubygems/test_gem_source_list.rb +0 -119
  498. data/test/rubygems/test_gem_source_local.rb +0 -107
  499. data/test/rubygems/test_gem_source_lock.rb +0 -113
  500. data/test/rubygems/test_gem_source_specific_file.rb +0 -76
  501. data/test/rubygems/test_gem_source_subpath_problem.rb +0 -50
  502. data/test/rubygems/test_gem_source_vendor.rb +0 -30
  503. data/test/rubygems/test_gem_spec_fetcher.rb +0 -338
  504. data/test/rubygems/test_gem_specification.rb +0 -3856
  505. data/test/rubygems/test_gem_stream_ui.rb +0 -255
  506. data/test/rubygems/test_gem_stub_specification.rb +0 -278
  507. data/test/rubygems/test_gem_text.rb +0 -103
  508. data/test/rubygems/test_gem_uninstaller.rb +0 -675
  509. data/test/rubygems/test_gem_unsatisfiable_dependency_error.rb +0 -31
  510. data/test/rubygems/test_gem_update_suggestion.rb +0 -209
  511. data/test/rubygems/test_gem_uri.rb +0 -41
  512. data/test/rubygems/test_gem_uri_formatter.rb +0 -27
  513. data/test/rubygems/test_gem_util.rb +0 -91
  514. data/test/rubygems/test_gem_validator.rb +0 -42
  515. data/test/rubygems/test_gem_version.rb +0 -305
  516. data/test/rubygems/test_gem_version_option.rb +0 -165
  517. data/test/rubygems/test_kernel.rb +0 -124
  518. data/test/rubygems/test_project_sanity.rb +0 -49
  519. data/test/rubygems/test_remote_fetch_error.rb +0 -20
  520. data/test/rubygems/test_require.rb +0 -732
  521. data/test/rubygems/test_rubygems.rb +0 -76
  522. data/test/rubygems/test_webauthn_listener.rb +0 -143
  523. data/test/rubygems/test_webauthn_listener_response.rb +0 -93
  524. data/test/rubygems/test_webauthn_poller.rb +0 -124
  525. data/test/rubygems/utilities.rb +0 -436
  526. data/test/rubygems/wrong_key_cert.pem +0 -19
  527. data/test/rubygems/wrong_key_cert_32.pem +0 -19
  528. data/test/test_changelog_generator.rb +0 -17
@@ -1,3856 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "benchmark"
4
- require_relative "helper"
5
- require "date"
6
- require "pathname"
7
- require "stringio"
8
- require "rubygems/ext"
9
- require "rubygems/specification"
10
- require "rubygems/installer"
11
- require "rubygems/platform"
12
-
13
- class TestGemSpecification < Gem::TestCase
14
- LEGACY_YAML_SPEC = <<-EOF
15
- --- !ruby/object:Gem::Specification
16
- rubygems_version: "1.0"
17
- name: keyedlist
18
- version: !ruby/object:Gem::Version
19
- version: 0.4.0
20
- date: 2004-03-28 15:37:49.828000 +02:00
21
- platform:
22
- summary: A Hash which automatically computes keys.
23
- require_paths:
24
- - lib
25
- files:
26
- - lib/keyedlist.rb
27
- autorequire: keyedlist
28
- author: Florian Gross
29
- email: flgr@ccan.de
30
- has_rdoc: true
31
- EOF
32
-
33
- LEGACY_RUBY_SPEC = <<-EOF
34
- Gem::Specification.new do |s|
35
- s.name = %q{keyedlist}
36
- s.version = %q{0.4.0}
37
- s.has_rdoc = true
38
- s.summary = %q{A Hash which automatically computes keys.}
39
- s.files = [%q{lib/keyedlist.rb}]
40
- s.require_paths = [%q{lib}]
41
- s.autorequire = %q{keyedlist}
42
- s.author = %q{Florian Gross}
43
- s.email = %q{flgr@ccan.de}
44
- end
45
- EOF
46
-
47
- def make_spec_c1
48
- @c1 = util_spec "a", "1" do |s|
49
- s.executable = "exec"
50
- s.extensions << "ext/a/extconf.rb"
51
- s.test_file = "test/suite.rb"
52
- s.requirements << "A working computer"
53
- s.license = "MIT"
54
-
55
- s.add_dependency "rake", "> 0.4"
56
- s.add_dependency "jabber4r", "> 0.0.0"
57
- s.add_dependency "pqa", ["> 0.4", "<= 0.6"]
58
-
59
- s.mark_version
60
- s.files = %w[lib/code.rb]
61
- end
62
- end
63
-
64
- def ext_spec(platform: Gem::Platform::RUBY)
65
- @ext = util_spec "ext", "1" do |s|
66
- s.executable = "exec"
67
- s.test_file = "test/suite.rb"
68
- s.extensions = %w[ext/extconf.rb]
69
- s.license = "MIT"
70
- s.platform = platform
71
-
72
- s.mark_version
73
- s.files = %w[lib/code.rb]
74
- s.installed_by_version = v("2.2")
75
- end
76
- end
77
-
78
- def assert_date(date)
79
- assert_kind_of Time, date
80
- assert_equal [0, 0, 0], [date.hour, date.min, date.sec]
81
- assert_operator (Gem::Specification::TODAY..Time.now), :cover?, date
82
- end
83
-
84
- def setup
85
- super
86
-
87
- # Setting `@default_source_date_epoch` to `nil` effectively resets the
88
- # value used for `Gem.source_date_epoch` whenever `$SOURCE_DATE_EPOCH`
89
- # is not set.
90
- Gem.instance_variable_set(:'@default_source_date_epoch', nil)
91
-
92
- @a1 = util_spec "a", "1" do |s|
93
- s.executable = "exec"
94
- s.test_file = "test/suite.rb"
95
- s.requirements << "A working computer"
96
- s.license = "MIT"
97
-
98
- s.mark_version
99
- s.files = %w[lib/code.rb]
100
- end
101
-
102
- @a2 = util_spec "a", "2" do |s|
103
- s.files = %w[lib/code.rb]
104
- end
105
-
106
- @a3 = util_spec "a", "3" do |s|
107
- s.metadata["allowed_push_host"] = "https://privategemserver.com"
108
- end
109
-
110
- @current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
111
- end
112
-
113
- def test_self_find_active_stub_by_path
114
- spec = util_spec("a", "1", nil, "lib/foo.rb")
115
- spec.activated = true
116
-
117
- # There used to be a bug (introduced in a9c1aaf) when Gem::Specification
118
- # objects are present in the @stubs collection. This test verifies that
119
- # this scenario works correctly.
120
- Gem::Specification.all = [spec]
121
- assert_equal spec, Gem::Specification.find_active_stub_by_path("foo")
122
- end
123
-
124
- def test_self_activate
125
- foo = util_spec "foo", "1"
126
-
127
- assert_activate %w[foo-1], foo
128
- end
129
-
130
- def test_self_activate_ambiguous_direct
131
- a1 = util_spec "a", "1", "b" => "> 0"
132
- b1 = util_spec("b", "1", { "c" => ">= 1" }, "lib/d#{$$}.rb")
133
- b2 = util_spec("b", "2", { "c" => ">= 2" }, "lib/d#{$$}.rb")
134
- c1 = util_spec "c", "1"
135
- c2 = util_spec "c", "2"
136
-
137
- Gem::Specification.reset
138
- install_specs c1, c2, b1, b2, a1
139
-
140
- a1.activate
141
- assert_equal %w[a-1], loaded_spec_names
142
- assert_equal ["b (> 0)"], unresolved_names
143
-
144
- require "d#{$$}"
145
-
146
- assert_equal %w[a-1 b-2 c-2], loaded_spec_names
147
- assert_equal [], unresolved_names
148
- end
149
-
150
- def test_find_in_unresolved_tree_is_not_exponentiental
151
- pend "currently slower in CI on TruffleRuby" if RUBY_ENGINE == "truffleruby"
152
- num_of_pkg = 7
153
- num_of_version_per_pkg = 3
154
- packages = (0..num_of_pkg).map do |pkgi|
155
- (0..num_of_version_per_pkg).map do |pkg_version|
156
- deps = Hash[((pkgi + 1)..num_of_pkg).map do |deppkgi|
157
- ["pkg#{deppkgi}", ">= 0"]
158
- end]
159
- util_spec "pkg#{pkgi}", pkg_version.to_s, deps
160
- end
161
- end
162
- base = util_spec "pkg_base", "1", { "pkg0" => ">= 0" }
163
-
164
- Gem::Specification.reset
165
- install_specs(*packages.flatten.reverse)
166
- install_specs base
167
- base.activate
168
-
169
- tms = Benchmark.measure do
170
- assert_raise(LoadError) { require "no_such_file_foo" }
171
- end
172
- assert_operator tms.total, :<=, 10
173
- end
174
-
175
- def test_self_activate_ambiguous_indirect
176
- a1 = util_spec "a", "1", "b" => "> 0"
177
- b1 = util_spec "b", "1", "c" => ">= 1"
178
- b2 = util_spec "b", "2", "c" => ">= 2"
179
- c1 = util_spec "c", "1", nil, "lib/d#{$$}.rb"
180
- c2 = util_spec "c", "2", nil, "lib/d#{$$}.rb"
181
-
182
- install_specs c1, c2, b1, b2, a1
183
-
184
- a1.activate
185
- assert_equal %w[a-1], loaded_spec_names
186
- assert_equal ["b (> 0)"], unresolved_names
187
-
188
- require "d#{$$}"
189
-
190
- assert_equal %w[a-1 b-2 c-2], loaded_spec_names
191
- assert_equal [], unresolved_names
192
- end
193
-
194
- def test_self_activate_ambiguous_indirect_conflict
195
- a1 = util_spec "a", "1", "b" => "> 0"
196
- a2 = util_spec "a", "2", "b" => "> 0"
197
- b1 = util_spec "b", "1", "c" => ">= 1"
198
- b2 = util_spec "b", "2", "c" => ">= 2"
199
- c1 = util_spec "c", "1", nil, "lib/d#{$$}.rb"
200
- c2 = util_spec("c", "2", { "a" => "1" }, "lib/d#{$$}.rb") # conflicts with a-2
201
-
202
- install_specs c1, b1, a1, a2, c2, b2
203
-
204
- a2.activate
205
- assert_equal %w[a-2], loaded_spec_names
206
- assert_equal ["b (> 0)"], unresolved_names
207
-
208
- require "d#{$$}"
209
-
210
- assert_equal %w[a-2 b-1 c-1], loaded_spec_names
211
- assert_equal [], unresolved_names
212
- end
213
-
214
- def test_self_activate_ambiguous_unrelated
215
- a1 = util_spec "a", "1", "b" => "> 0"
216
- b1 = util_spec "b", "1", "c" => ">= 1"
217
- b2 = util_spec "b", "2", "c" => ">= 2"
218
- c1 = util_spec "c", "1"
219
- c2 = util_spec "c", "2"
220
- d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb"
221
-
222
- install_specs d1, c1, c2, b1, b2, a1
223
-
224
- a1.activate
225
- assert_equal %w[a-1], loaded_spec_names
226
- assert_equal ["b (> 0)"], unresolved_names
227
-
228
- require "d#{$$}"
229
-
230
- assert_equal %w[a-1 d-1], loaded_spec_names
231
- assert_equal ["b (> 0)"], unresolved_names
232
- end
233
-
234
- def test_require_should_prefer_latest_gem_level1
235
- a1 = util_spec "a", "1", "b" => "> 0"
236
- b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
237
- b2 = util_spec "b", "2", "c" => ">= 0"
238
- c1 = util_spec "c", "1", nil, "lib/c#{$$}.rb" # 1st level
239
- c2 = util_spec "c", "2", nil, "lib/c#{$$}.rb"
240
-
241
- install_specs c1, c2, b1, b2, a1
242
-
243
- a1.activate
244
-
245
- require "c#{$$}"
246
-
247
- assert_equal %w[a-1 b-2 c-2], loaded_spec_names
248
- end
249
-
250
- def test_require_should_prefer_latest_gem_level2
251
- a1 = util_spec "a", "1", "b" => "> 0"
252
- b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
253
- b2 = util_spec "b", "2", "c" => ">= 0"
254
- c1 = util_spec "c", "1", "d" => ">= 0" # 1st level
255
- c2 = util_spec "c", "2", "d" => ">= 0"
256
- d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
257
- d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
258
-
259
- install_specs d1, d2, c1, c2, b1, b2, a1
260
-
261
- a1.activate
262
-
263
- require "d#{$$}"
264
-
265
- assert_equal %w[a-1 b-2 c-2 d-2], loaded_spec_names
266
- end
267
-
268
- def test_require_finds_in_2nd_level_indirect
269
- a1 = util_spec "a", "1", "b" => "> 0"
270
- b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
271
- b2 = util_spec "b", "2", "c" => ">= 0"
272
- c1 = util_spec "c", "1", "d" => "<= 2" # 1st level
273
- c2 = util_spec "c", "2", "d" => "<= 2"
274
- d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
275
- d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
276
- d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
277
-
278
- install_specs d1, d2, d3, c1, c2, b1, b2, a1
279
-
280
- a1.activate
281
-
282
- require "d#{$$}"
283
-
284
- assert_equal %w[a-1 b-2 c-2 d-2], loaded_spec_names
285
- end
286
-
287
- def test_require_should_prefer_reachable_gems
288
- a1 = util_spec "a", "1", "b" => "> 0"
289
- b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
290
- b2 = util_spec "b", "2", "c" => ">= 0"
291
- c1 = util_spec "c", "1", "d" => "<= 2" # 1st level
292
- c2 = util_spec "c", "2", "d" => "<= 2"
293
- d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
294
- d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
295
- d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
296
- e = util_spec "anti_d", "1", nil, "lib/d#{$$}.rb"
297
-
298
- install_specs d1, d2, d3, e, c1, c2, b1, b2, a1
299
-
300
- a1.activate
301
-
302
- require "d#{$$}"
303
-
304
- assert_equal %w[a-1 b-2 c-2 d-2], loaded_spec_names
305
- end
306
-
307
- def test_require_should_not_conflict
308
- base = util_spec "0", "1", "A" => ">= 1"
309
- a1 = util_spec "A", "1", { "c" => ">= 2", "b" => "> 0" }, "lib/a.rb"
310
- a2 = util_spec "A", "2", { "c" => ">= 2", "b" => "> 0" }, "lib/a.rb"
311
- b1 = util_spec "b", "1", { "c" => "= 1" }, "lib/d#{$$}.rb"
312
- b2 = util_spec "b", "2", { "c" => "= 2" }, "lib/d#{$$}.rb"
313
- c1 = util_spec "c", "1", {}, "lib/c.rb"
314
- c2 = util_spec "c", "2", {}, "lib/c.rb"
315
- c3 = util_spec "c", "3", {}, "lib/c.rb"
316
-
317
- install_specs c1, c2, c3, b1, b2, a1, a2, base
318
-
319
- base.activate
320
- assert_equal %w[0-1], loaded_spec_names
321
- assert_equal ["A (>= 1)"], unresolved_names
322
-
323
- require "d#{$$}"
324
-
325
- assert_equal %w[0-1 A-2 b-2 c-2], loaded_spec_names
326
- assert_equal [], unresolved_names
327
- end
328
-
329
- def test_inner_clonflict_in_indirect_gems
330
- a1 = util_spec "a", "1", "b" => "> 0"
331
- b1 = util_spec "b", "1", "c" => ">= 1" # unresolved
332
- b2 = util_spec "b", "2", "c" => ">= 1", "d" => "< 3"
333
- c1 = util_spec "c", "1", "d" => "<= 2" # 1st level
334
- c2 = util_spec "c", "2", "d" => "<= 2"
335
- c3 = util_spec "c", "3", "d" => "<= 3"
336
- d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
337
- d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
338
- d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
339
-
340
- install_specs d1, d2, d3, c1, c2, c3, b1, b2, a1
341
-
342
- a1.activate
343
-
344
- require "d#{$$}"
345
-
346
- assert_includes [%w[a-1 b-2 c-3 d-2],%w[a-1 b-2 d-2]], loaded_spec_names
347
- end
348
-
349
- def test_inner_clonflict_in_indirect_gems_reversed
350
- a1 = util_spec "a", "1", "b" => "> 0"
351
- b1 = util_spec "b", "1", "xc" => ">= 1" # unresolved
352
- b2 = util_spec "b", "2", "xc" => ">= 1", "d" => "< 3"
353
- c1 = util_spec "xc", "1", "d" => "<= 3" # 1st level
354
- c2 = util_spec "xc", "2", "d" => "<= 2"
355
- c3 = util_spec "xc", "3", "d" => "<= 3"
356
- d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
357
- d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
358
- d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
359
-
360
- install_specs d1, d2, d3, c1, c2, c3, b1, b2, a1
361
-
362
- a1.activate
363
-
364
- require "d#{$$}"
365
-
366
- assert_includes [%w[a-1 b-2 d-2 xc-3], %w[a-1 b-2 d-2]], loaded_spec_names
367
- end
368
-
369
- ##
370
- # [A] depends on
371
- # [C] = 1.0 depends on
372
- # [B] = 2.0
373
- # [B] ~> 1.0 (satisfied by 1.0)
374
-
375
- def test_self_activate_checks_dependencies
376
- a = util_spec "a", "1.0"
377
- a.add_dependency "c", "= 1.0"
378
- a.add_dependency "b", "~> 1.0"
379
-
380
- b1 = util_spec "b", "1.0"
381
- b2 = util_spec "b", "2.0"
382
- c = util_spec "c", "1.0", "b" => "= 2.0"
383
- install_specs b1, b2, c, a
384
-
385
- e = assert_raise Gem::LoadError do
386
- assert_activate nil, a, c, "b"
387
- end
388
-
389
- expected = "can't satisfy 'b (~> 1.0)', already activated 'b-2.0'"
390
- assert_equal expected, e.message
391
- end
392
-
393
- ##
394
- # [A] depends on
395
- # [B] ~> 1.0 (satisfied by 1.0)
396
- # [C] = 1.0 depends on
397
- # [B] = 2.0
398
-
399
- def test_self_activate_divergent
400
- a = util_spec "a", "1.0", "b" => "~> 1.0", "c" => "= 1.0"
401
- b1 = util_spec "b", "1.0"
402
- b2 = util_spec "b", "2.0"
403
- c = util_spec "c", "1.0", "b" => "= 2.0"
404
-
405
- install_specs b1, b2, c, a
406
-
407
- e = assert_raise Gem::ConflictError do
408
- assert_activate nil, a, c, "b"
409
- end
410
-
411
- assert_match(/Unable to activate c-1.0,/, e.message)
412
- assert_match(/because b-1.0 conflicts with b .= 2.0/, e.message)
413
- end
414
-
415
- ##
416
- # DOC
417
-
418
- def test_self_activate_old_required
419
- e1, = util_spec "e", "1", "d" => "= 1"
420
- @d1 = util_spec "d", "1"
421
- @d2 = util_spec "d", "2"
422
-
423
- install_specs @d1, @d2, e1
424
-
425
- assert_activate %w[d-1 e-1], e1, "d"
426
- end
427
-
428
- ##
429
- # DOC
430
-
431
- def test_self_activate_platform_alternate
432
- @x1_m = util_spec "x", "1" do |s|
433
- s.platform = Gem::Platform.new %w[cpu my_platform 1]
434
- end
435
-
436
- @x1_o = util_spec "x", "1" do |s|
437
- s.platform = Gem::Platform.new %w[cpu other_platform 1]
438
- end
439
-
440
- @w1 = util_spec "w", "1", "x" => nil
441
-
442
- util_set_arch "cpu-my_platform1"
443
- install_specs @x1_m, @x1_o, @w1
444
-
445
- assert_activate %w[x-1-cpu-my_platform-1 w-1], @w1, @x1_m
446
- end
447
-
448
- ##
449
- # DOC
450
-
451
- def test_self_activate_platform_bump
452
- @y1 = util_spec "y", "1"
453
-
454
- @y1_1_p = util_spec "y", "1.1" do |s|
455
- s.platform = Gem::Platform.new %w[cpu my_platform 1]
456
- end
457
-
458
- @z1 = util_spec "z", "1", "y" => nil
459
- install_specs @y1, @y1_1_p, @z1
460
-
461
- assert_activate %w[y-1 z-1], @z1, @y1
462
- end
463
-
464
- ##
465
- # [C] depends on
466
- # [A] = 1.a
467
- # [B] = 1.0 depends on
468
- # [A] >= 0 (satisfied by 1.a)
469
-
470
- def test_self_activate_prerelease
471
- @c1_pre = util_spec "c", "1.a", "a" => "1.a", "b" => "1"
472
- @a1_pre = util_spec "a", "1.a"
473
- @b1 = util_spec "b", "1" do |s|
474
- s.add_dependency "a"
475
- s.add_development_dependency "aa"
476
- end
477
- install_specs @a1_pre, @b1, @c1_pre
478
-
479
- assert_activate %w[a-1.a b-1 c-1.a], @c1_pre, @a1_pre, @b1
480
- end
481
-
482
- def test_self_activate_via_require
483
- a1 = util_spec "a", "1", "b" => "= 1"
484
- b1 = util_spec "b", "1", nil, "lib/b/c.rb"
485
- b2 = util_spec "b", "2", nil, "lib/b/c.rb"
486
-
487
- install_specs b1, b2, a1
488
-
489
- a1.activate
490
- require "b/c"
491
-
492
- assert_equal %w[a-1 b-1], loaded_spec_names
493
- end
494
-
495
- def test_self_activate_via_require_wtf
496
- a1 = util_spec "a", "1", "b" => "> 0", "d" => "> 0" # this
497
- b1 = util_spec "b", "1", { "c" => ">= 1" }, "lib/b#{$$}.rb"
498
- b2 = util_spec "b", "2", { "c" => ">= 2" }, "lib/b#{$$}.rb" # this
499
- c1 = util_spec "c", "1"
500
- c2 = util_spec "c", "2" # this
501
- d1 = util_spec "d", "1", { "c" => "< 2" }, "lib/d#{$$}.rb"
502
- d2 = util_spec "d", "2", { "c" => "< 2" }, "lib/d#{$$}.rb" # this
503
-
504
- install_specs c1, c2, b1, b2, d1, d2, a1
505
-
506
- a1.activate
507
-
508
- assert_equal %w[a-1], loaded_spec_names
509
- assert_equal ["b (> 0)", "d (> 0)"], unresolved_names
510
-
511
- require "b#{$$}"
512
-
513
- e = assert_raise Gem::LoadError do
514
- require "d#{$$}"
515
- end
516
-
517
- assert_equal "unable to find a version of 'd' to activate", e.message
518
-
519
- assert_equal %w[a-1 b-2 c-2], loaded_spec_names
520
- assert_equal ["d (> 0)"], unresolved_names
521
- end
522
-
523
- def test_self_activate_deep_unambiguous
524
- a1 = util_spec "a", "1", "b" => "= 1"
525
- b1 = util_spec "b", "1", "c" => "= 1"
526
- b2 = util_spec "b", "2", "c" => "= 2"
527
- c1 = util_spec "c", "1"
528
- c2 = util_spec "c", "2"
529
-
530
- install_specs c1, c2, b1, b2, a1
531
-
532
- a1.activate
533
- assert_equal %w[a-1 b-1 c-1], loaded_spec_names
534
- end
535
-
536
- def test_self_activate_loaded
537
- foo = util_spec "foo", "1"
538
-
539
- assert foo.activate
540
- refute foo.activate
541
- end
542
-
543
- ##
544
- # [A] depends on
545
- # [B] >= 1.0 (satisfied by 2.0)
546
- # [C] depends on nothing
547
-
548
- def test_self_activate_unrelated
549
- a = util_spec "a", "1.0", "b" => ">= 1.0"
550
- b = util_spec "b", "1.0"
551
- c = util_spec "c", "1.0"
552
- install_specs b, c, a
553
-
554
- assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b"
555
- end
556
-
557
- ##
558
- # [A] depends on
559
- # [B] >= 1.0 (satisfied by 2.0)
560
- # [C] = 1.0 depends on
561
- # [B] ~> 1.0
562
- #
563
- # and should resolve using b-1.0
564
- # TODO: move these to specification
565
-
566
- def test_self_activate_over
567
- a = util_spec "a", "1.0", "b" => ">= 1.0", "c" => "= 1.0"
568
- install_specs util_spec "b", "1.0"
569
- install_specs util_spec "b", "1.1"
570
- install_specs util_spec "b", "2.0"
571
- install_specs util_spec "c", "1.0", "b" => "~> 1.0"
572
- install_specs a
573
-
574
- a.activate
575
-
576
- assert_equal %w[a-1.0 c-1.0], loaded_spec_names
577
- assert_equal ["b (>= 1.0, ~> 1.0)"], unresolved_names
578
- end
579
-
580
- ##
581
- # [A] depends on
582
- # [B] ~> 1.0 (satisfied by 1.1)
583
- # [C] = 1.0 depends on
584
- # [B] = 1.0
585
- #
586
- # and should resolve using b-1.0
587
- #
588
- # TODO: this is not under, but over... under would require depth
589
- # first resolve through a dependency that is later pruned.
590
-
591
- def test_self_activate_under
592
- a = util_spec "a", "1.0", "b" => "~> 1.0", "c" => "= 1.0"
593
- b1 = util_spec "b", "1.0"
594
- b1_1 = util_spec "b", "1.1"
595
- c = util_spec "c", "1.0", "b" => "= 1.0"
596
-
597
- install_specs b1, b1_1, c, a
598
-
599
- assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b"
600
- end
601
-
602
- ##
603
- # [A1] depends on
604
- # [B] > 0 (satisfied by 2.0)
605
- # [B1] depends on
606
- # [C] > 0 (satisfied by 1.0)
607
- # [B2] depends on nothing!
608
- # [C1] depends on nothing
609
-
610
- def test_self_activate_dropped
611
- a1 = util_spec "a", "1", "b" => nil
612
- b1 = util_spec "b", "1", "c" => nil
613
- b2 = util_spec "b", "2"
614
- c1 = util_spec "c", "1"
615
- install_specs c1, b1, b2, a1
616
-
617
- assert_activate %w[b-2 a-1], a1, "b"
618
- end
619
-
620
- ##
621
- # [A] depends on
622
- # [B] >= 1.0 (satisfied by 1.1) depends on
623
- # [Z]
624
- # [C] >= 1.0 depends on
625
- # [B] = 1.0
626
- #
627
- # and should backtrack to resolve using b-1.0, pruning Z from the
628
- # resolve.
629
-
630
- def test_self_activate_raggi_the_edgecase_generator
631
- a = util_spec "a", "1.0", "b" => ">= 1.0", "c" => ">= 1.0"
632
- b1 = util_spec "b", "1.0"
633
- b1_0 = util_spec "b", "1.1", "z" => ">= 1.0"
634
- c = util_spec "c", "1.0", "b" => "= 1.0"
635
- z = util_spec "z", "1"
636
-
637
- install_specs z, b1, b1_0, c, z
638
-
639
- assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b"
640
- end
641
-
642
- def test_self_activate_conflict
643
- install_specs util_spec "b", "1.0"
644
- install_specs util_spec "b", "2.0"
645
-
646
- gem "b", "= 1.0"
647
-
648
- assert_raise Gem::LoadError do
649
- gem "b", "= 2.0"
650
- end
651
- end
652
-
653
- def test_self_all_equals
654
- a = util_spec "foo", "1", nil, "lib/foo.rb"
655
-
656
- install_specs a
657
- Gem::Specification.all = [a]
658
-
659
- assert_equal a, Gem::Specification.find_inactive_by_path("foo")
660
- end
661
-
662
- def test_self_attribute_names
663
- expected_value = %w[
664
- authors
665
- autorequire
666
- bindir
667
- cert_chain
668
- date
669
- dependencies
670
- description
671
- email
672
- executables
673
- extensions
674
- extra_rdoc_files
675
- files
676
- homepage
677
- licenses
678
- metadata
679
- name
680
- platform
681
- post_install_message
682
- rdoc_options
683
- require_paths
684
- required_ruby_version
685
- required_rubygems_version
686
- requirements
687
- rubygems_version
688
- signing_key
689
- specification_version
690
- summary
691
- test_files
692
- version
693
- ]
694
-
695
- actual_value = Gem::Specification.attribute_names.map {|a| a.to_s }.sort
696
-
697
- assert_equal expected_value, actual_value
698
- end
699
-
700
- def test_self__load_future
701
- spec = Gem::Specification.new
702
- spec.name = "a"
703
- spec.version = "1"
704
- spec.specification_version = @current_version + 1
705
-
706
- load_spec = Marshal.load Marshal.dump(spec)
707
-
708
- assert_equal "a", load_spec.name
709
- assert_equal Gem::Version.new(1), load_spec.version
710
- assert_equal @current_version, load_spec.specification_version
711
- end
712
-
713
- def test_self_from_yaml
714
- @a1.instance_variable_set :@specification_version, nil
715
-
716
- spec = Gem::Specification.from_yaml @a1.to_yaml
717
-
718
- assert_equal Gem::Specification::NONEXISTENT_SPECIFICATION_VERSION,
719
- spec.specification_version
720
- end
721
-
722
- def test_self_from_yaml_cleans_up_Date_objects
723
- yaml = <<-YAML
724
- --- !ruby/object:Gem::Specification
725
- rubygems_version: 0.8.1
726
- specification_version: 1
727
- name: diff-lcs
728
- version: !ruby/object:Gem::Version
729
- version: 1.1.2
730
- date: 2004-10-20
731
- summary: Provides a list of changes that represent the difference between two sequenced collections.
732
- require_paths:
733
- - lib
734
- author: Austin Ziegler
735
- email: diff-lcs@halostatue.ca
736
- homepage: http://rubyforge.org/projects/ruwiki/
737
- description: "Test"
738
- bindir: bin
739
- has_rdoc: true
740
- required_ruby_version: !ruby/object:Gem::Version::Requirement
741
- requirements:
742
- -
743
- - ">="
744
- - !ruby/object:Gem::Version
745
- version: 1.8.1
746
- version:
747
- platform: ruby
748
- files:
749
- - tests/00test.rb
750
- rdoc_options:
751
- - "--title"
752
- - "Diff::LCS -- A Diff Algorithm"
753
- - "--main"
754
- - README
755
- - "--line-numbers"
756
- extra_rdoc_files:
757
- - README
758
- - ChangeLog
759
- - Install
760
- executables:
761
- - ldiff
762
- - htmldiff
763
- extensions: []
764
- requirements: []
765
- dependencies: []
766
- YAML
767
-
768
- spec = Gem::Specification.from_yaml yaml
769
-
770
- assert_kind_of Time, spec.date
771
- end
772
-
773
- def test_self_load
774
- full_path = @a2.spec_file
775
- write_file full_path do |io|
776
- io.write @a2.to_ruby_for_cache
777
- end
778
-
779
- spec = Gem::Specification.load full_path
780
-
781
- @a2.files.clear
782
-
783
- assert_equal @a2, spec
784
- end
785
-
786
- def test_self_load_relative
787
- File.open "a-2.gemspec", "w" do |io|
788
- io.write @a2.to_ruby_for_cache
789
- end
790
-
791
- spec = Gem::Specification.load "a-2.gemspec"
792
-
793
- @a2.files.clear
794
-
795
- assert_equal @a2, spec
796
-
797
- assert_equal File.join(@tempdir, "a-2.gemspec"), spec.loaded_from
798
- end
799
-
800
- if RUBY_ENGINE == "ruby" && RUBY_VERSION < "2.7"
801
- def test_self_load_tainted
802
- full_path = @a2.spec_file
803
- write_file full_path do |io|
804
- io.write @a2.to_ruby_for_cache
805
- end
806
-
807
- full_path.taint
808
- loader = Thread.new { $SAFE = 1; Gem::Specification.load full_path }
809
- spec = loader.value
810
-
811
- @a2.files.clear
812
-
813
- assert_equal @a2, spec
814
-
815
- ensure
816
- $SAFE = 0
817
- end
818
- end
819
-
820
- def test_self_load_escape_curly
821
- @a2.name = 'a};raise "improper escaping";%q{'
822
-
823
- full_path = @a2.spec_file
824
- begin
825
- write_file full_path do |io|
826
- io.write @a2.to_ruby_for_cache
827
- end
828
- rescue Errno::EINVAL
829
- pend "cannot create '#{full_path}' on this platform"
830
- end
831
-
832
- spec = Gem::Specification.load full_path
833
-
834
- @a2.files.clear
835
-
836
- assert_equal @a2, spec
837
- end
838
-
839
- def test_self_load_escape_interpolation
840
- @a2.name = 'a#{raise %<improper escaping>}'
841
-
842
- full_path = @a2.spec_file
843
- begin
844
- write_file full_path do |io|
845
- io.write @a2.to_ruby_for_cache
846
- end
847
- rescue Errno::EINVAL
848
- pend "cannot create '#{full_path}' on this platform"
849
- end
850
-
851
- spec = Gem::Specification.load full_path
852
-
853
- @a2.files.clear
854
-
855
- assert_equal @a2, spec
856
- end
857
-
858
- def test_self_load_escape_quote
859
- @a2.name = 'a";raise "improper escaping";"'
860
-
861
- full_path = @a2.spec_file
862
- begin
863
- write_file full_path do |io|
864
- io.write @a2.to_ruby_for_cache
865
- end
866
- rescue Errno::EINVAL
867
- pend "cannot create '#{full_path}' on this platform"
868
- end
869
-
870
- spec = Gem::Specification.load full_path
871
-
872
- @a2.files.clear
873
-
874
- assert_equal @a2, spec
875
- end
876
-
877
- def test_self_load_utf8_with_ascii_encoding
878
- with_internal_encoding("US-ASCII") do
879
- spec2 = @a2.dup
880
- bin = "\u5678".dup
881
- spec2.authors = [bin]
882
- full_path = spec2.spec_file
883
- write_file full_path do |io|
884
- io.write spec2.to_ruby_for_cache.force_encoding("BINARY").sub("\\u{5678}", bin.force_encoding("BINARY"))
885
- end
886
-
887
- spec = Gem::Specification.load full_path
888
-
889
- spec2.files.clear
890
-
891
- assert_equal spec2, spec
892
- end
893
- end
894
-
895
- def test_self_load_legacy_ruby
896
- spec = Gem::Deprecate.skip_during do
897
- eval LEGACY_RUBY_SPEC
898
- end
899
- assert_equal "keyedlist", spec.name
900
- assert_equal "0.4.0", spec.version.to_s
901
- assert_kind_of Time, spec.date
902
- assert spec.required_ruby_version.satisfied_by?(Gem::Version.new("1"))
903
- assert_equal false, spec.has_unit_tests?
904
- end
905
-
906
- def test_self_normalize_yaml_input_with_183_yaml
907
- input = "!ruby/object:Gem::Specification "
908
- assert_equal "--- #{input}", Gem::Specification.normalize_yaml_input(input)
909
- end
910
-
911
- def test_self_normalize_yaml_input_with_non_183_yaml
912
- input = "--- !ruby/object:Gem::Specification "
913
- assert_equal input, Gem::Specification.normalize_yaml_input(input)
914
- end
915
-
916
- def test_self_normalize_yaml_input_with_183_io
917
- input = "!ruby/object:Gem::Specification "
918
- assert_equal "--- #{input}",
919
- Gem::Specification.normalize_yaml_input(StringIO.new(input))
920
- end
921
-
922
- def test_self_normalize_yaml_input_with_non_183_io
923
- input = "--- !ruby/object:Gem::Specification "
924
- assert_equal input,
925
- Gem::Specification.normalize_yaml_input(StringIO.new(input))
926
- end
927
-
928
- def test_self_normalize_yaml_input_with_192_yaml
929
- input = "--- !ruby/object:Gem::Specification \nblah: !!null \n"
930
- expected = "--- !ruby/object:Gem::Specification \nblah: \n"
931
-
932
- assert_equal expected, Gem::Specification.normalize_yaml_input(input)
933
- end
934
-
935
- def test_self_outdated
936
- spec_fetcher do |fetcher|
937
- fetcher.download "a", 4
938
-
939
- fetcher.spec "a", 3
940
- end
941
-
942
- assert_equal %w[a], Gem::Specification.outdated
943
- end
944
-
945
- def test_self_outdated_and_latest_remotes
946
- spec_fetcher do |fetcher|
947
- fetcher.download "a", 4
948
- fetcher.download "b", 3
949
-
950
- fetcher.spec "a", "3.a"
951
- fetcher.spec "b", 2
952
- end
953
-
954
- expected = [
955
- [Gem::Specification.stubs.find {|s| s.full_name == "a-3.a" }, v(4)],
956
- [Gem::Specification.stubs.find {|s| s.full_name == "b-2" }, v(3)],
957
- ]
958
-
959
- assert_equal expected, Gem::Specification.outdated_and_latest_version.to_a
960
- end
961
-
962
- def test_self_remove_spec
963
- install_specs @a1
964
-
965
- assert_includes Gem::Specification.all_names, "a-1"
966
- assert_includes Gem::Specification.stubs.map {|s| s.full_name }, "a-1"
967
-
968
- uninstall_gem @a1
969
- Gem::Specification.reset
970
-
971
- refute_includes Gem::Specification.all_names, "a-1"
972
- refute_includes Gem::Specification.stubs.map {|s| s.full_name }, "a-1"
973
- end
974
-
975
- def test_self_remove_spec_removed
976
- File.open @a1.spec_file, "w" do |io|
977
- io.write @a1.to_ruby
978
- end
979
-
980
- Gem::Specification.reset
981
-
982
- FileUtils.rm @a1.spec_file # bug #698
983
-
984
- Gem::Specification.reset
985
-
986
- refute_includes Gem::Specification.all_names, "a-1"
987
- refute_includes Gem::Specification.stubs.map {|s| s.full_name }, "a-1"
988
- end
989
-
990
- def test_self_stubs_for_lazy_loading
991
- Gem.loaded_specs.clear
992
- Gem::Specification.class_variable_set(:@@stubs, nil)
993
-
994
- dir_standard_specs = File.join Gem.dir, "specifications"
995
-
996
- save_gemspec("a-1", "1", dir_standard_specs) {|s| s.name = "a" }
997
- save_gemspec("b-1", "1", dir_standard_specs) {|s| s.name = "b" }
998
-
999
- assert_equal ["a-1"], Gem::Specification.stubs_for("a").map {|s| s.full_name }
1000
- assert_equal 1, Gem::Specification.class_variable_get(:@@stubs_by_name).length
1001
- assert_equal ["b-1"], Gem::Specification.stubs_for("b").map {|s| s.full_name }
1002
- assert_equal 2, Gem::Specification.class_variable_get(:@@stubs_by_name).length
1003
-
1004
- assert_equal(
1005
- Gem::Specification.stubs_for("a").map {|s| s.object_id },
1006
- Gem::Specification.stubs_for("a").map {|s| s.object_id }
1007
- )
1008
-
1009
- Gem.loaded_specs.delete "a"
1010
- Gem.loaded_specs.delete "b"
1011
- Gem::Specification.class_variable_set(:@@stubs, nil)
1012
- end
1013
-
1014
- def test_self_stubs_for_no_lazy_loading_after_all_specs_setup
1015
- Gem::Specification.all = [util_spec("a", "1")]
1016
-
1017
- save_gemspec("b-1", "1", File.join(Gem.dir, "specifications")) {|s| s.name = "b" }
1018
-
1019
- assert_equal [], Gem::Specification.stubs_for("b").map {|s| s.full_name }
1020
- end
1021
-
1022
- def test_self_stubs_for_mult_platforms
1023
- # gems for two different platforms are installed with --user-install
1024
- # the correct one should be returned in the array
1025
-
1026
- orig_platform = Gem.platforms.dup
1027
-
1028
- # create user spec
1029
- user_spec_dir = File.join Gem.user_dir, "specifications"
1030
- FileUtils.mkdir_p(user_spec_dir) unless Dir.exist? user_spec_dir
1031
- # dirs doesn't include user ?
1032
- Gem::Specification.dirs << user_spec_dir
1033
-
1034
- gem = "mingw"
1035
- v = "1.1.1"
1036
- platforms = ["x86-mingw32", "x64-mingw32"]
1037
-
1038
- #create specs
1039
- platforms.each do |plat|
1040
- spec = Gem::Specification.new(gem, v) {|s| s.platform = plat }
1041
- File.open File.join(user_spec_dir, "#{gem}-#{v}-#{plat}.gemspec"), "w" do |io|
1042
- io.write spec.to_ruby
1043
- end
1044
- end
1045
-
1046
- platforms.each do |plat|
1047
- cur_plat = Gem::Platform.new plat
1048
- Gem.platforms = ["ruby", cur_plat]
1049
-
1050
- Gem::Specification.class_variable_set :@@stubs, nil
1051
- Gem::Specification.stubs if plat == platforms.last # test loading via stubs
1052
- t = Gem::Specification.stubs_for "mingw"
1053
-
1054
- assert_equal 1, t.length
1055
- assert_equal cur_plat, t.first.platform
1056
- end
1057
-
1058
- Gem.platforms = orig_platform
1059
- end
1060
-
1061
- def test_self_stubs_returns_only_specified_named_specs
1062
- dir_standard_specs = File.join Gem.dir, "specifications"
1063
-
1064
- save_gemspec("a-1", "1", dir_standard_specs) {|s| s.name = "a" }
1065
- save_gemspec("a-2", "2", dir_standard_specs) {|s| s.name = "a" }
1066
- save_gemspec("a-a", "3", dir_standard_specs) {|s| s.name = "a-a" }
1067
-
1068
- assert_equal ["a-1", "a-2"], Gem::Specification.stubs_for("a").map(&:full_name).sort
1069
- end
1070
-
1071
- def test_handles_private_null_type
1072
- yaml_defined = Object.const_defined?("YAML")
1073
-
1074
- path = File.expand_path "data/pry-0.4.7.gemspec.rz", __dir__
1075
-
1076
- data = Marshal.load Gem::Util.inflate(Gem.read_binary(path))
1077
-
1078
- assert_instance_of Gem::Specification, data
1079
-
1080
- assert_equal(yaml_defined, Object.const_defined?("YAML"))
1081
- end
1082
-
1083
- def test_handles_dependencies_with_syck_requirements_bug
1084
- yaml_defined = Object.const_defined?("YAML")
1085
-
1086
- path = File.expand_path "data/excon-0.7.7.gemspec.rz", __dir__
1087
-
1088
- data = Marshal.load Gem::Util.inflate(Gem.read_binary(path))
1089
-
1090
- assert_instance_of Gem::Specification, data
1091
-
1092
- assert_equal(yaml_defined, Object.const_defined?("YAML"))
1093
- end
1094
-
1095
- def test_handles_dependencies_with_other_syck_requirements_argument_error
1096
- yaml_defined = Object.const_defined?("YAML")
1097
-
1098
- data = Marshal.dump(Gem::Specification.new do |s|
1099
- v = Gem::Version.allocate
1100
- v.instance_variable_set :@version, "YAML::Syck::DefaultKey"
1101
- s.instance_variable_set :@version, v
1102
- end)
1103
-
1104
- assert_raise(ArgumentError) { Marshal.load(data) }
1105
- out, err = capture_output do
1106
- assert_raise(ArgumentError) { Marshal.load(data) }
1107
- end
1108
- assert_empty out
1109
- assert_empty err
1110
-
1111
- assert_equal(yaml_defined, Object.const_defined?("YAML"))
1112
- end
1113
-
1114
- def test_initialize
1115
- spec = Gem::Specification.new do |s|
1116
- s.name = "blah"
1117
- s.version = "1.3.5"
1118
- end
1119
-
1120
- assert_equal "blah", spec.name
1121
- assert_equal "1.3.5", spec.version.to_s
1122
- assert_equal Gem::Platform::RUBY, spec.platform
1123
- assert_nil spec.summary
1124
- assert_equal [], spec.files
1125
-
1126
- assert_equal [], spec.test_files
1127
- assert_equal [], spec.rdoc_options
1128
- assert_equal [], spec.extra_rdoc_files
1129
- assert_equal [], spec.executables
1130
- assert_equal [], spec.extensions
1131
- assert_equal [], spec.requirements
1132
- assert_equal [], spec.dependencies
1133
- assert_equal "bin", spec.bindir
1134
- assert_equal ">= 0", spec.required_ruby_version.to_s
1135
- assert_equal ">= 0", spec.required_rubygems_version.to_s
1136
- end
1137
-
1138
- def test_initialize_future
1139
- version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + 1
1140
- spec = Gem::Specification.new do |s|
1141
- s.name = "blah"
1142
- s.version = "1.3.5"
1143
-
1144
- s.specification_version = version
1145
-
1146
- s.new_unknown_attribute = "a value"
1147
- end
1148
-
1149
- assert_equal "blah", spec.name
1150
- assert_equal "1.3.5", spec.version.to_s
1151
- end
1152
-
1153
- def test_initialize_copy
1154
- spec = Gem::Specification.new do |s|
1155
- s.name = "blah"
1156
- s.version = "1.3.5"
1157
- s.summary = "summary"
1158
- s.description = "description"
1159
- s.authors = "author a", "author b"
1160
- s.licenses = "BSD-2-Clause"
1161
- s.files = "lib/file.rb"
1162
- s.test_files = "test/file.rb"
1163
- s.rdoc_options = "--foo"
1164
- s.extra_rdoc_files = "README.txt"
1165
- s.executables = "exec"
1166
- s.extensions = "ext/extconf.rb"
1167
- s.requirements = "requirement"
1168
- s.add_dependency "some_gem"
1169
- end
1170
-
1171
- dup_spec = spec.dup
1172
-
1173
- assert_equal "blah", spec.name
1174
- assert_same spec.name, dup_spec.name
1175
-
1176
- assert_equal "1.3.5", spec.version.to_s
1177
- assert_same spec.version, dup_spec.version
1178
-
1179
- assert_equal Gem::Platform::RUBY, spec.platform
1180
- assert_same spec.platform, dup_spec.platform
1181
-
1182
- assert_equal "summary", spec.summary
1183
- assert_same spec.summary, dup_spec.summary
1184
-
1185
- assert_equal %w[README.txt bin/exec ext/extconf.rb lib/file.rb
1186
- test/file.rb].sort,
1187
- spec.files
1188
- refute_same spec.files, dup_spec.files, "files"
1189
-
1190
- assert_equal %w[test/file.rb], spec.test_files
1191
- refute_same spec.test_files, dup_spec.test_files, "test_files"
1192
-
1193
- assert_equal %w[--foo], spec.rdoc_options
1194
- refute_same spec.rdoc_options, dup_spec.rdoc_options, "rdoc_options"
1195
-
1196
- assert_equal %w[README.txt], spec.extra_rdoc_files
1197
- refute_same spec.extra_rdoc_files, dup_spec.extra_rdoc_files,
1198
- "extra_rdoc_files"
1199
-
1200
- assert_equal %w[exec], spec.executables
1201
- refute_same spec.executables, dup_spec.executables, "executables"
1202
-
1203
- assert_equal %w[ext/extconf.rb], spec.extensions
1204
- refute_same spec.extensions, dup_spec.extensions, "extensions"
1205
-
1206
- assert_equal %w[requirement], spec.requirements
1207
- refute_same spec.requirements, dup_spec.requirements, "requirements"
1208
-
1209
- assert_equal [Gem::Dependency.new("some_gem", Gem::Requirement.default)],
1210
- spec.dependencies
1211
- refute_same spec.dependencies, dup_spec.dependencies, "dependencies"
1212
-
1213
- assert_equal "bin", spec.bindir
1214
- assert_same spec.bindir, dup_spec.bindir
1215
-
1216
- assert_equal ">= 0", spec.required_ruby_version.to_s
1217
- assert_same spec.required_ruby_version, dup_spec.required_ruby_version
1218
-
1219
- assert_equal ">= 0", spec.required_rubygems_version.to_s
1220
- assert_same spec.required_rubygems_version,
1221
- dup_spec.required_rubygems_version
1222
- end
1223
-
1224
- def test_initialize_copy_broken
1225
- spec = Gem::Specification.new do |s|
1226
- s.name = "a"
1227
- s.version = "1"
1228
- end
1229
-
1230
- spec.instance_variable_set :@licenses, (class << (Object.new);self;end)
1231
- spec.loaded_from = "/path/to/file"
1232
-
1233
- e = assert_raise Gem::FormatException do
1234
- spec.dup
1235
- end
1236
-
1237
- assert_equal "a-1 has an invalid value for @licenses", e.message
1238
- assert_equal "/path/to/file", e.file_path
1239
- end
1240
-
1241
- def test_initialize_prerelease_version_before_name
1242
- spec = Gem::Specification.new do |s|
1243
- s.version = "1.0.0.dev"
1244
- s.name = "a"
1245
- end
1246
-
1247
- assert_equal "a", spec.name
1248
- assert_equal "1.0.0.dev", spec.version.to_s
1249
- end
1250
-
1251
- def test_initialize_nil_version
1252
- expected = "nil versions are discouraged and will be deprecated in Rubygems 4\n"
1253
- actual_stdout, actual_stderr = capture_output do
1254
- Gem::Specification.new.version = nil
1255
- end
1256
- assert_empty actual_stdout
1257
- assert_equal(expected, actual_stderr)
1258
- end
1259
-
1260
- def test__dump
1261
- @a2.platform = Gem::Platform.local
1262
- @a2.instance_variable_set :@original_platform, "old_platform"
1263
-
1264
- data = Marshal.dump @a2
1265
-
1266
- same_spec = Marshal.load data
1267
-
1268
- assert_equal "old_platform", same_spec.original_platform
1269
- end
1270
-
1271
- def test_activate
1272
- @a2.activate
1273
-
1274
- assert @a2.activated?
1275
- end
1276
-
1277
- def test_add_dependency_with_type
1278
- gem = util_spec "awesome", "1.0" do |awesome|
1279
- awesome.add_dependency true
1280
- awesome.add_dependency :gem_name
1281
- end
1282
-
1283
- assert_equal %w[true gem_name], gem.dependencies.map {|dep| dep.name }
1284
- end
1285
-
1286
- def test_add_dependency_from_existing_dependency
1287
- dep = Gem::Dependency.new("existing_dep", Gem::Requirement.new("> 1"), :runtime)
1288
- spec = Gem::Specification.new {|s| s.add_dependency dep }
1289
- assert_equal dep, spec.dependencies.first
1290
- end
1291
-
1292
- def test_add_dependency_with_type_explicit
1293
- gem = util_spec "awesome", "1.0" do |awesome|
1294
- awesome.add_development_dependency "monkey"
1295
- end
1296
-
1297
- monkey = gem.dependencies.detect {|d| d.name == "monkey" }
1298
- assert_equal(:development, monkey.type)
1299
- end
1300
-
1301
- def test_author
1302
- assert_equal "A User", @a1.author
1303
- end
1304
-
1305
- def test_authors
1306
- assert_equal ["A User"], @a1.authors
1307
- end
1308
-
1309
- def test_bindir_equals
1310
- @a1.bindir = "apps"
1311
-
1312
- assert_equal "apps", @a1.bindir
1313
- end
1314
-
1315
- def test_bindir_equals_nil
1316
- @a2.bindir = nil
1317
- @a2.executable = "app"
1318
-
1319
- assert_nil @a2.bindir
1320
- assert_equal %w[app lib/code.rb].sort, @a2.files
1321
- end
1322
-
1323
- def test_extensions_equals_nil
1324
- @a2.instance_variable_set(:@extensions, nil)
1325
- assert_nil @a2.instance_variable_get(:@extensions)
1326
- assert_equal %w[lib/code.rb], @a2.files
1327
- end
1328
-
1329
- def test_test_files_equals_nil
1330
- @a2.instance_variable_set(:@test_files, nil)
1331
- assert_nil @a2.instance_variable_get(:@test_files)
1332
- assert_equal %w[lib/code.rb], @a2.files
1333
- end
1334
-
1335
- def test_executables_equals_nil
1336
- @a2.instance_variable_set(:@executables, nil)
1337
- assert_nil @a2.instance_variable_get(:@executables)
1338
- assert_equal %w[lib/code.rb], @a2.files
1339
- end
1340
-
1341
- def test_extra_rdoc_files_equals_nil
1342
- @a2.instance_variable_set(:@extra_rdoc_files, nil)
1343
- assert_nil @a2.instance_variable_get(:@extra_rdoc_files)
1344
- assert_equal %w[lib/code.rb], @a2.files
1345
- end
1346
-
1347
- def test_build_args
1348
- pend "extensions don't quite work on jruby" if Gem.java_platform?
1349
- ext_spec
1350
-
1351
- assert_empty @ext.build_args
1352
-
1353
- File.open @ext.build_info_file, "w" do |io|
1354
- io.puts
1355
- end
1356
-
1357
- assert_empty @ext.build_args
1358
-
1359
- File.open @ext.build_info_file, "w" do |io|
1360
- io.puts "--with-foo-dir=wherever"
1361
- end
1362
-
1363
- assert_equal %w[--with-foo-dir=wherever], @ext.build_args
1364
- end
1365
-
1366
- def test_build_extensions
1367
- pend "extensions don't quite work on jruby" if Gem.java_platform?
1368
- ext_spec
1369
-
1370
- assert_path_not_exist @ext.extension_dir, "sanity check"
1371
- refute_empty @ext.extensions, "sanity check"
1372
-
1373
- extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
1374
- FileUtils.mkdir_p File.dirname extconf_rb
1375
-
1376
- File.open extconf_rb, "w" do |f|
1377
- f.write <<-'RUBY'
1378
- File.open 'Makefile', 'w' do |f|
1379
- f.puts "clean:\n\techo clean"
1380
- f.puts "default:\n\techo built"
1381
- f.puts "install:\n\techo installed"
1382
- end
1383
- RUBY
1384
- end
1385
-
1386
- @ext.build_extensions
1387
-
1388
- assert_path_exist @ext.extension_dir
1389
- end
1390
-
1391
- def test_default_spec_stub_is_marked_default
1392
- default = new_default_spec "default", 2
1393
- install_default_gems default
1394
-
1395
- stub = Gem::Specification.stubs.find {|s| s.name == "default" }
1396
- assert_predicate stub, :default_gem?
1397
-
1398
- stub = Gem::Specification.find_all_by_name("default").first
1399
- assert_predicate stub, :default_gem?
1400
- end
1401
-
1402
- def test_build_extensions_built
1403
- pend "extensions don't quite work on jruby" if Gem.java_platform?
1404
- ext_spec
1405
-
1406
- refute_empty @ext.extensions, "sanity check"
1407
-
1408
- gem_build_complete =
1409
- File.join @ext.extension_dir, "gem.build_complete"
1410
-
1411
- FileUtils.mkdir_p @ext.extension_dir
1412
- FileUtils.touch gem_build_complete
1413
-
1414
- @ext.build_extensions
1415
-
1416
- gem_make_out = File.join @ext.extension_dir, "gem_make.out"
1417
- assert_path_not_exist gem_make_out
1418
- end
1419
-
1420
- def test_build_extensions_default_gem
1421
- spec = new_default_spec "default", 1
1422
- spec.extensions << "extconf.rb"
1423
-
1424
- extconf_rb = File.join spec.gem_dir, spec.extensions.first
1425
- FileUtils.mkdir_p File.dirname extconf_rb
1426
-
1427
- File.open extconf_rb, "w" do |f|
1428
- f.write <<-'RUBY'
1429
- File.open 'Makefile', 'w' do |f|
1430
- f.puts "default:\n\techo built"
1431
- f.puts "install:\n\techo installed"
1432
- end
1433
- RUBY
1434
- end
1435
-
1436
- spec.build_extensions
1437
-
1438
- assert_path_not_exist spec.extension_dir
1439
- end
1440
-
1441
- def test_build_extensions_error
1442
- pend "extensions don't quite work on jruby" if Gem.java_platform?
1443
- ext_spec
1444
-
1445
- refute_empty @ext.extensions, "sanity check"
1446
-
1447
- assert_raise Gem::Ext::BuildError do
1448
- @ext.build_extensions
1449
- end
1450
- end
1451
-
1452
- def test_build_extensions_extensions_dir_unwritable
1453
- pend "chmod not supported" if Gem.win_platform?
1454
- pend "skipped in root privilege" if Process.uid.zero?
1455
-
1456
- pend "extensions don't quite work on jruby" if Gem.java_platform?
1457
- ext_spec
1458
-
1459
- refute_empty @ext.extensions, "sanity check"
1460
-
1461
- extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
1462
- FileUtils.mkdir_p File.dirname extconf_rb
1463
-
1464
- File.open extconf_rb, "w" do |f|
1465
- f.write <<-'RUBY'
1466
- File.open 'Makefile', 'w' do |f|
1467
- f.puts "clean:\n\techo clean"
1468
- f.puts "default:\n\techo built"
1469
- f.puts "install:\n\techo installed"
1470
- end
1471
- RUBY
1472
- end
1473
-
1474
- FileUtils.mkdir_p File.join @ext.base_dir, "extensions"
1475
- FileUtils.chmod 0o555, @ext.base_dir
1476
- FileUtils.chmod 0o555, File.join(@ext.base_dir, "extensions")
1477
-
1478
- @ext.build_extensions
1479
- assert_path_not_exist @ext.extension_dir
1480
- ensure
1481
- unless ($DEBUG || win_platform? || Process.uid.zero? || Gem.java_platform?)
1482
- FileUtils.chmod 0o755, File.join(@ext.base_dir, "extensions")
1483
- FileUtils.chmod 0o755, @ext.base_dir
1484
- end
1485
- end
1486
-
1487
- def test_build_extensions_no_extensions_dir_unwritable
1488
- pend "chmod not supported" if Gem.win_platform?
1489
- pend "extensions don't quite work on jruby" if Gem.java_platform?
1490
- ext_spec
1491
-
1492
- refute_empty @ext.extensions, "sanity check"
1493
-
1494
- extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
1495
- FileUtils.mkdir_p File.dirname extconf_rb
1496
-
1497
- File.open extconf_rb, "w" do |f|
1498
- f.write <<-'RUBY'
1499
- File.open 'Makefile', 'w' do |f|
1500
- f.puts "clean:\n\techo clean"
1501
- f.puts "default:\n\techo built"
1502
- f.puts "install:\n\techo installed"
1503
- end
1504
- RUBY
1505
- end
1506
-
1507
- FileUtils.rm_r File.join @gemhome, "extensions"
1508
- FileUtils.chmod 0o555, @gemhome
1509
-
1510
- @ext.build_extensions
1511
-
1512
- gem_make_out = File.join @ext.extension_dir, "gem_make.out"
1513
- assert_path_not_exist gem_make_out
1514
- ensure
1515
- FileUtils.chmod 0o755, @gemhome
1516
- end
1517
-
1518
- def test_build_extensions_none
1519
- assert_path_not_exist @a1.extension_dir, "sanity check"
1520
- assert_empty @a1.extensions, "sanity check"
1521
-
1522
- @a1.build_extensions
1523
-
1524
- assert_path_not_exist @a1.extension_dir
1525
- end
1526
-
1527
- def test_build_extensions_preview
1528
- pend "extensions don't quite work on jruby" if Gem.java_platform?
1529
- ext_spec
1530
-
1531
- extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
1532
- FileUtils.mkdir_p File.dirname extconf_rb
1533
-
1534
- File.open extconf_rb, "w" do |f|
1535
- f.write <<-'RUBY'
1536
- File.open 'Makefile', 'w' do |f|
1537
- f.puts "clean:\n\techo clean"
1538
- f.puts "default:\n\techo built"
1539
- f.puts "install:\n\techo installed"
1540
- end
1541
- RUBY
1542
- end
1543
-
1544
- refute_empty @ext.extensions, "sanity check"
1545
-
1546
- @ext.installed_by_version = v("2.2.0.preview.2")
1547
-
1548
- @ext.build_extensions
1549
-
1550
- gem_make_out = File.join @ext.extension_dir, "gem_make.out"
1551
- assert_path_exist gem_make_out
1552
- end
1553
-
1554
- def test_contains_requirable_file_eh
1555
- code_rb = File.join @a1.gem_dir, "lib", "code.rb"
1556
- FileUtils.mkdir_p File.dirname code_rb
1557
- FileUtils.touch code_rb
1558
-
1559
- assert @a1.contains_requirable_file? "code"
1560
- end
1561
-
1562
- def test_contains_requirable_file_eh_extension
1563
- pend "extensions don't quite work on jruby" if Gem.java_platform?
1564
- ext_spec
1565
-
1566
- _, err = capture_output do
1567
- refute @ext.contains_requirable_file? "nonexistent"
1568
- end
1569
-
1570
- expected = "Ignoring ext-1 because its extensions are not built. " +
1571
- "Try: gem pristine ext --version 1\n"
1572
-
1573
- assert_equal expected, err
1574
- end
1575
-
1576
- def test_contains_requirable_file_eh_extension_java_platform
1577
- ext_spec(platform: Gem::Platform.new("java"))
1578
-
1579
- _, err = capture_output do
1580
- refute @ext.contains_requirable_file? "nonexistent"
1581
- end
1582
-
1583
- assert_empty err
1584
- end
1585
-
1586
- def test_date
1587
- assert_date @a1.date
1588
- end
1589
-
1590
- def test_date_equals_date
1591
- @a1.date = Date.new(2003, 9, 17)
1592
- assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
1593
- end
1594
-
1595
- def test_date_equals_string
1596
- @a1.date = "2003-09-17"
1597
- assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
1598
- end
1599
-
1600
- def test_date_equals_string_bad
1601
- assert_raise Gem::InvalidSpecificationException do
1602
- @a1.date = "9/11/2003"
1603
- end
1604
- end
1605
-
1606
- def test_date_equals_time
1607
- @a1.date = Time.local(2003, 9, 17, 0,0,0)
1608
- assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
1609
- end
1610
-
1611
- def test_date_equals_time_local
1612
- @a1.date = Time.local(2003, 9, 17, 19,50,0) # may not pass in utc >= +4
1613
- assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
1614
- end
1615
-
1616
- def test_date_equals_time_utc
1617
- @a1.date = Time.utc(2003, 9, 17, 19,50,0)
1618
- assert_equal Time.utc(2003, 9, 17, 0,0,0), @a1.date
1619
- end
1620
-
1621
- def test_date_tolerates_hour_sec_zulu
1622
- @a1.date = "2012-01-12 11:22:33.4444444 Z"
1623
- assert_equal Time.utc(2012,0o1,12,0,0,0), @a1.date
1624
- end
1625
-
1626
- def test_date_tolerates_hour_sec_and_timezone
1627
- @a1.date = "2012-01-12 11:22:33.4444444 +02:33"
1628
- assert_equal Time.utc(2012,0o1,12,0,0,0), @a1.date
1629
- end
1630
-
1631
- def test_date_use_env_source_date_epoch
1632
- epoch = ENV["SOURCE_DATE_EPOCH"]
1633
- ENV["SOURCE_DATE_EPOCH"] = "123456789"
1634
- assert_equal Time.utc(1973,11,29,0,0,0), @a1.date
1635
- ensure
1636
- ENV["SOURCE_DATE_EPOCH"] = epoch
1637
- end
1638
-
1639
- def test_dependencies
1640
- util_setup_deps
1641
- assert_equal [@bonobo, @monkey], @gem.dependencies
1642
- end
1643
-
1644
- def test_dependent_gems
1645
- util_setup_deps
1646
-
1647
- assert_empty @gem.dependent_gems
1648
-
1649
- bonobo = util_spec "bonobo", 1
1650
- install_gem bonobo
1651
- install_gem @gem
1652
-
1653
- expected = [
1654
- [@gem, @bonobo, [bonobo]],
1655
- ]
1656
-
1657
- assert_equal expected, bonobo.dependent_gems
1658
- end
1659
-
1660
- def test_doc_dir
1661
- assert_equal File.join(@gemhome, "doc", "a-1"), @a1.doc_dir
1662
- end
1663
-
1664
- def test_doc_dir_type
1665
- assert_equal File.join(@gemhome, "doc", "a-1", "ri"), @a1.doc_dir("ri")
1666
- end
1667
-
1668
- def test_runtime_dependencies
1669
- util_setup_deps
1670
- assert_equal [@bonobo], @gem.runtime_dependencies
1671
- end
1672
-
1673
- def test_development_dependencies
1674
- util_setup_deps
1675
- assert_equal [@monkey], @gem.development_dependencies
1676
- end
1677
-
1678
- def test_description
1679
- assert_equal "This is a test description", @a1.description
1680
- end
1681
-
1682
- def test_eql_eh
1683
- g1 = util_spec "gem", 1
1684
- g2 = util_spec "gem", 1
1685
-
1686
- assert_equal g1, g2
1687
- assert_equal g1.hash, g2.hash
1688
- assert_equal true, g1.eql?(g2)
1689
- end
1690
-
1691
- def test_eql_eh_extensions
1692
- spec = @a1.dup
1693
- spec.extensions = "xx"
1694
-
1695
- refute_operator @a1, :eql?, spec
1696
- refute_operator spec, :eql?, @a1
1697
- end
1698
-
1699
- def test_executables
1700
- @a1.executable = "app"
1701
- assert_equal %w[app], @a1.executables
1702
- end
1703
-
1704
- def test_executable_equals
1705
- @a2.executable = "app"
1706
- assert_equal "app", @a2.executable
1707
- assert_equal %w[bin/app lib/code.rb].sort, @a2.files
1708
- end
1709
-
1710
- def test_extensions
1711
- assert_equal ["ext/extconf.rb"], ext_spec.extensions
1712
- end
1713
-
1714
- def test_extension_dir
1715
- enable_shared = RbConfig::CONFIG["ENABLE_SHARED"]
1716
- RbConfig::CONFIG["ENABLE_SHARED"] = "no"
1717
-
1718
- ext_spec
1719
-
1720
- refute_empty @ext.extensions
1721
-
1722
- expected =
1723
- File.join(@ext.base_dir, "extensions", Gem::Platform.local.to_s,
1724
- "#{Gem.ruby_api_version}-static", @ext.full_name)
1725
-
1726
- assert_equal expected, @ext.extension_dir
1727
- ensure
1728
- RbConfig::CONFIG["ENABLE_SHARED"] = enable_shared
1729
- end
1730
-
1731
- def test_extension_dir_override
1732
- enable_shared = RbConfig::CONFIG["ENABLE_SHARED"]
1733
- RbConfig::CONFIG["ENABLE_SHARED"] = "no"
1734
-
1735
- class << Gem
1736
- alias orig_default_ext_dir_for default_ext_dir_for
1737
-
1738
- remove_method :default_ext_dir_for
1739
-
1740
- def Gem.default_ext_dir_for(base_dir)
1741
- "elsewhere"
1742
- end
1743
- end
1744
-
1745
- ext_spec
1746
-
1747
- refute_empty @ext.extensions
1748
-
1749
- expected = File.join @tempdir, "elsewhere", @ext.full_name
1750
-
1751
- assert_equal expected, @ext.extension_dir
1752
- ensure
1753
- RbConfig::CONFIG["ENABLE_SHARED"] = enable_shared
1754
-
1755
- class << Gem
1756
- remove_method :default_ext_dir_for
1757
-
1758
- alias default_ext_dir_for orig_default_ext_dir_for
1759
- end
1760
- end
1761
-
1762
- def test_files
1763
- @a1.files = %w[files bin/common]
1764
- @a1.test_files = %w[test_files bin/common]
1765
- @a1.executables = %w[executables common]
1766
- @a1.extra_rdoc_files = %w[extra_rdoc_files bin/common]
1767
- @a1.extensions = %w[extensions bin/common]
1768
-
1769
- expected = %w[
1770
- bin/common
1771
- bin/executables
1772
- extensions
1773
- extra_rdoc_files
1774
- files
1775
- test_files
1776
- ]
1777
- assert_equal expected, @a1.files
1778
- end
1779
-
1780
- def test_files_append
1781
- @a1.files = %w[files bin/common]
1782
- @a1.test_files = %w[test_files bin/common]
1783
- @a1.executables = %w[executables common]
1784
- @a1.extra_rdoc_files = %w[extra_rdoc_files bin/common]
1785
- @a1.extensions = %w[extensions bin/common]
1786
-
1787
- expected = %w[
1788
- bin/common
1789
- bin/executables
1790
- extensions
1791
- extra_rdoc_files
1792
- files
1793
- test_files
1794
- ]
1795
- assert_equal expected, @a1.files
1796
-
1797
- @a1.files << "generated_file.c"
1798
-
1799
- expected << "generated_file.c"
1800
- expected.sort!
1801
-
1802
- assert_equal expected, @a1.files
1803
- end
1804
-
1805
- def test_files_duplicate
1806
- @a2.files = %w[a b c d b]
1807
- @a2.extra_rdoc_files = %w[x y z x]
1808
- @a2.normalize
1809
-
1810
- assert_equal %w[a b c d x y z], @a2.files
1811
- assert_equal %w[x y z], @a2.extra_rdoc_files
1812
- end
1813
-
1814
- def test_files_extra_rdoc_files
1815
- @a2.files = %w[a b c d]
1816
- @a2.extra_rdoc_files = %w[x y z]
1817
- @a2.normalize
1818
- assert_equal %w[a b c d x y z], @a2.files
1819
- end
1820
-
1821
- def test_files_non_array
1822
- @a1.files = "F"
1823
- @a1.test_files = "TF"
1824
- @a1.executables = "X"
1825
- @a1.extra_rdoc_files = "ERF"
1826
- @a1.extensions = "E"
1827
-
1828
- assert_equal %w[E ERF F TF bin/X], @a1.files
1829
- end
1830
-
1831
- def test_files_non_array_pathological
1832
- @a1.instance_variable_set :@files, "F"
1833
- @a1.instance_variable_set :@test_files, "TF"
1834
- @a1.instance_variable_set :@extra_rdoc_files, "ERF"
1835
- @a1.instance_variable_set :@extensions, "E"
1836
- @a1.instance_variable_set :@executables, "X"
1837
-
1838
- assert_equal %w[E ERF F TF bin/X], @a1.files
1839
- assert_kind_of Integer, @a1.hash
1840
- end
1841
-
1842
- def test_for_cache
1843
- @a2.add_runtime_dependency "b", "1"
1844
- @a2.dependencies.first.instance_variable_set :@type, nil
1845
- @a2.required_rubygems_version = Gem::Requirement.new "> 0"
1846
- @a2.test_files = %w[test/test_b.rb]
1847
-
1848
- refute_empty @a2.files
1849
- refute_empty @a2.test_files
1850
-
1851
- spec = @a2.for_cache
1852
-
1853
- assert_empty spec.files
1854
- assert_empty spec.test_files
1855
-
1856
- refute_empty @a2.files
1857
- refute_empty @a2.test_files
1858
- end
1859
-
1860
- def test_full_gem_path
1861
- assert_equal File.join(@gemhome, "gems", @a1.full_name), @a1.full_gem_path
1862
-
1863
- @a1.original_platform = "mswin32"
1864
-
1865
- assert_equal File.join(@gemhome, "gems", @a1.original_name),
1866
- @a1.full_gem_path
1867
- end
1868
-
1869
- def test_full_gem_path_double_slash
1870
- gemhome = @gemhome.to_s.sub(/\w\//, '\&/')
1871
- @a1.loaded_from = File.join gemhome, "specifications", @a1.spec_name
1872
-
1873
- expected = File.join @gemhome, "gems", @a1.full_name
1874
- assert_equal expected, @a1.full_gem_path
1875
- end
1876
-
1877
- def test_full_name
1878
- assert_equal "a-1", @a1.full_name
1879
-
1880
- @a1 = Gem::Specification.new "a", 1
1881
- @a1.platform = Gem::Platform.new ["universal", "darwin", nil]
1882
- assert_equal "a-1-universal-darwin", @a1.full_name
1883
-
1884
- @a1 = Gem::Specification.new "a", 1
1885
- @a1.instance_variable_set :@new_platform, "mswin32"
1886
- assert_equal "a-1-mswin32", @a1.full_name, "legacy"
1887
-
1888
- return if win_platform?
1889
-
1890
- @a1 = Gem::Specification.new "a", 1
1891
- @a1.platform = "current"
1892
- assert_equal "a-1-x86-darwin-8", @a1.full_name
1893
- end
1894
-
1895
- def test_full_name_windows
1896
- test_cases = {
1897
- "i386-mswin32" => "a-1-x86-mswin32-60",
1898
- "i386-mswin32_80" => "a-1-x86-mswin32-80",
1899
- "i386-mingw32" => "a-1-x86-mingw32",
1900
- }
1901
-
1902
- test_cases.each do |arch, expected|
1903
- @a1 = Gem::Specification.new "a", 1
1904
- util_set_arch arch
1905
- @a1.platform = "current"
1906
- assert_equal expected, @a1.full_name
1907
- end
1908
- end
1909
-
1910
- def test_gem_build_complete_path
1911
- expected = File.join @a1.extension_dir, "gem.build_complete"
1912
- assert_equal expected, @a1.gem_build_complete_path
1913
- end
1914
-
1915
- def test_hash
1916
- assert_equal @a1.hash, @a1.hash
1917
- assert_equal @a1.hash, @a1.dup.hash
1918
- refute_equal @a1.hash, @a2.hash
1919
- end
1920
-
1921
- def test_installed_by_version
1922
- assert_equal v(0), @a1.installed_by_version
1923
-
1924
- @a1.installed_by_version = Gem.rubygems_version
1925
-
1926
- assert_equal Gem.rubygems_version, @a1.installed_by_version
1927
- end
1928
-
1929
- def test_base_dir
1930
- assert_equal @gemhome, @a1.base_dir
1931
- end
1932
-
1933
- def test_base_dir_not_loaded
1934
- @a1.instance_variable_set :@loaded_from, nil
1935
-
1936
- assert_equal Gem.dir, @a1.base_dir
1937
- end
1938
-
1939
- def test_base_dir_default
1940
- default_dir =
1941
- File.join Gem.default_specifications_dir, @a1.spec_name
1942
-
1943
- @a1.instance_variable_set :@loaded_from, default_dir
1944
-
1945
- assert_equal Gem.default_dir, @a1.base_dir
1946
- end
1947
-
1948
- def test_lib_files
1949
- @a1.files = %w[lib/foo.rb Rakefile]
1950
-
1951
- assert_equal %w[lib/foo.rb], @a1.lib_files
1952
- end
1953
-
1954
- def test_license
1955
- assert_equal "MIT", @a1.license
1956
- end
1957
-
1958
- def test_licenses
1959
- assert_equal ["MIT"], @a1.licenses
1960
- end
1961
-
1962
- def test_name
1963
- assert_equal "a", @a1.name
1964
- end
1965
-
1966
- def test_original_name
1967
- assert_equal "a-1", @a1.full_name
1968
-
1969
- @a1.platform = "i386-linux"
1970
- @a1.instance_variable_set :@original_platform, "i386-linux"
1971
- assert_equal "a-1-i386-linux", @a1.original_name
1972
- end
1973
-
1974
- def test_platform
1975
- assert_equal Gem::Platform::RUBY, @a1.platform
1976
- end
1977
-
1978
- def test_platform_change_reset_full_name
1979
- orig_full_name = @a1.full_name
1980
-
1981
- @a1.platform = "universal-unknown"
1982
- refute_equal orig_full_name, @a1.full_name
1983
- end
1984
-
1985
- def test_platform_change_reset_cache_file
1986
- orig_cache_file = @a1.cache_file
1987
-
1988
- @a1.platform = "universal-unknown"
1989
- refute_equal orig_cache_file, @a1.cache_file
1990
- end
1991
-
1992
- def test_platform_equals
1993
- @a1.platform = nil
1994
- assert_equal Gem::Platform::RUBY, @a1.platform
1995
-
1996
- @a1.platform = Gem::Platform::RUBY
1997
- assert_equal Gem::Platform::RUBY, @a1.platform
1998
-
1999
- test_cases = {
2000
- "i386-mswin32" => ["x86", "mswin32", "60"],
2001
- "i386-mswin32_80" => ["x86", "mswin32", "80"],
2002
- "i386-mingw32" => ["x86", "mingw32", nil ],
2003
- "x86-darwin8" => ["x86", "darwin", "8" ],
2004
- }
2005
-
2006
- test_cases.each do |arch, expected|
2007
- util_set_arch arch
2008
- @a1.platform = Gem::Platform::CURRENT
2009
- assert_equal Gem::Platform.new(expected), @a1.platform
2010
- end
2011
- end
2012
-
2013
- def test_platform_equals_current
2014
- @a1.platform = Gem::Platform::CURRENT
2015
- assert_equal Gem::Platform.local, @a1.platform
2016
- assert_equal Gem::Platform.local.to_s, @a1.original_platform
2017
- end
2018
-
2019
- def test_platform_equals_legacy
2020
- @a1.platform = "mswin32"
2021
- assert_equal Gem::Platform.new("x86-mswin32"), @a1.platform
2022
-
2023
- @a1.platform = "i586-linux"
2024
- assert_equal Gem::Platform.new("x86-linux"), @a1.platform
2025
-
2026
- @a1.platform = "powerpc-darwin"
2027
- assert_equal Gem::Platform.new("ppc-darwin"), @a1.platform
2028
- end
2029
-
2030
- def test_prerelease_spec_adds_required_rubygems_version
2031
- @prerelease = util_spec("tardis", "2.2.0.a")
2032
- refute @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new("1.3.1"))
2033
- assert @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new("1.4.0"))
2034
- end
2035
-
2036
- def test_require_paths
2037
- enable_shared "no" do
2038
- ext_spec
2039
-
2040
- @ext.require_paths = "lib"
2041
-
2042
- assert_equal [@ext.extension_dir, "lib"], @ext.require_paths
2043
- end
2044
- end
2045
-
2046
- def test_require_paths_default_ext_dir_for
2047
- class << Gem
2048
- send :alias_method, :orig_default_ext_dir_for, :default_ext_dir_for
2049
-
2050
- remove_method :default_ext_dir_for
2051
- end
2052
-
2053
- def Gem.default_ext_dir_for(base_dir)
2054
- "/foo"
2055
- end
2056
-
2057
- enable_shared "no" do
2058
- ext_spec
2059
-
2060
- @ext.require_paths = "lib"
2061
-
2062
- assert_equal [File.expand_path("/foo/ext-1"), "lib"], @ext.require_paths
2063
- end
2064
- ensure
2065
- class << Gem
2066
- send :remove_method, :default_ext_dir_for
2067
- send :alias_method, :default_ext_dir_for, :orig_default_ext_dir_for
2068
- send :remove_method, :orig_default_ext_dir_for
2069
- end
2070
- end
2071
-
2072
- def test_source
2073
- assert_kind_of Gem::Source::Installed, @a1.source
2074
- end
2075
-
2076
- def test_source_paths
2077
- ext_spec
2078
-
2079
- @ext.require_paths = %w[lib ext foo]
2080
- @ext.extensions << "bar/baz"
2081
-
2082
- expected = %w[
2083
- lib
2084
- ext
2085
- foo
2086
- bar
2087
- ]
2088
-
2089
- assert_equal expected, @ext.source_paths
2090
- end
2091
-
2092
- def test_full_require_paths
2093
- ext_spec
2094
-
2095
- @ext.require_paths = "lib"
2096
-
2097
- expected = [
2098
- File.join(@gemhome, "gems", @ext.original_name, "lib"),
2099
- @ext.extension_dir,
2100
- ]
2101
-
2102
- assert_equal expected, @ext.full_require_paths
2103
- end
2104
-
2105
- def test_to_fullpath
2106
- ext_spec
2107
-
2108
- @ext.require_paths = "lib"
2109
-
2110
- dir = File.join(@gemhome, "gems", @ext.original_name, "lib")
2111
- expected_rb = File.join(dir, "code.rb")
2112
- FileUtils.mkdir_p dir
2113
- FileUtils.touch expected_rb
2114
-
2115
- dir = @ext.extension_dir
2116
- ext = RbConfig::CONFIG["DLEXT"]
2117
- expected_so = File.join(dir, "ext.#{ext}")
2118
- FileUtils.mkdir_p dir
2119
- FileUtils.touch expected_so
2120
-
2121
- assert_nil @ext.to_fullpath("code")
2122
- assert_nil @ext.to_fullpath("code.rb")
2123
- assert_nil @ext.to_fullpath("code.#{ext}")
2124
-
2125
- assert_nil @ext.to_fullpath("ext")
2126
- assert_nil @ext.to_fullpath("ext.rb")
2127
- assert_nil @ext.to_fullpath("ext.#{ext}")
2128
-
2129
- @ext.activate
2130
-
2131
- assert_equal expected_rb, @ext.to_fullpath("code")
2132
- assert_equal expected_rb, @ext.to_fullpath("code.rb")
2133
- assert_nil @ext.to_fullpath("code.#{ext}")
2134
-
2135
- assert_equal expected_so, @ext.to_fullpath("ext")
2136
- assert_nil @ext.to_fullpath("ext.rb")
2137
- assert_equal expected_so, @ext.to_fullpath("ext.#{ext}")
2138
-
2139
- assert_nil @ext.to_fullpath("notexist")
2140
- end
2141
-
2142
- def test_fullpath_return_rb_extension_file_when_exist_the_same_name_file
2143
- ext_spec
2144
-
2145
- @ext.require_paths = "lib"
2146
-
2147
- dir = File.join(@gemhome, "gems", @ext.original_name, "lib")
2148
- expected_rb = File.join(dir, "code.rb")
2149
- FileUtils.mkdir_p dir
2150
- FileUtils.touch expected_rb
2151
-
2152
- dir = @ext.extension_dir
2153
- ext = RbConfig::CONFIG["DLEXT"]
2154
- expected_so = File.join(dir, "code.#{ext}")
2155
- FileUtils.mkdir_p dir
2156
- FileUtils.touch expected_so
2157
-
2158
- @ext.activate
2159
-
2160
- assert_equal expected_rb, @ext.to_fullpath("code")
2161
- end
2162
-
2163
- def test_require_already_activated
2164
- a1 = util_spec "a", "1", nil, "lib/d#{$$}.rb"
2165
-
2166
- install_specs a1 # , a2, b1, b2, c1, c2
2167
-
2168
- a1.activate
2169
- assert_equal %w[a-1], loaded_spec_names
2170
- assert_equal [], unresolved_names
2171
-
2172
- assert require "d#{$$}"
2173
-
2174
- assert_equal %w[a-1], loaded_spec_names
2175
- assert_equal [], unresolved_names
2176
- end
2177
-
2178
- def test_require_already_activated_indirect_conflict
2179
- a1 = util_spec "a", "1", "b" => "> 0"
2180
- a2 = util_spec "a", "2", "b" => "> 0"
2181
- b1 = util_spec "b", "1", "c" => ">= 1"
2182
- b2 = util_spec "b", "2", "c" => ">= 2"
2183
- c1 = util_spec "c", "1", nil, "lib/d#{$$}.rb"
2184
- c2 = util_spec("c", "2", { "a" => "1" }, "lib/d#{$$}.rb") # conflicts with a-2
2185
-
2186
- install_specs c1, b1, a1, a2, c2, b2
2187
-
2188
- a1.activate
2189
- c1.activate
2190
- assert_equal %w[a-1 c-1], loaded_spec_names
2191
- assert_equal ["b (> 0)"], unresolved_names
2192
-
2193
- assert require "d#{$$}"
2194
-
2195
- assert_equal %w[a-1 c-1], loaded_spec_names
2196
- assert_equal ["b (> 0)"], unresolved_names
2197
- end
2198
-
2199
- def test_requirements
2200
- assert_equal ["A working computer"], @a1.requirements
2201
- end
2202
-
2203
- def test_allowed_push_host
2204
- assert_nil @a1.metadata["allowed_push_host"]
2205
- assert_equal "https://privategemserver.com", @a3.metadata["allowed_push_host"]
2206
- end
2207
-
2208
- def test_runtime_dependencies_legacy
2209
- make_spec_c1
2210
- # legacy gems don't have a type
2211
- @c1.runtime_dependencies.each do |dep|
2212
- dep.instance_variable_set :@type, nil
2213
- end
2214
-
2215
- expected = %w[rake jabber4r pqa]
2216
-
2217
- assert_equal expected, @c1.runtime_dependencies.map {|d| d.name }
2218
- end
2219
-
2220
- def test_spaceship_name
2221
- s1 = util_spec "a", "1"
2222
- s2 = util_spec "b", "1"
2223
-
2224
- assert_equal(-1, (s1 <=> s2))
2225
- assert_equal(0, (s1 <=> s1))
2226
- assert_equal(1, (s2 <=> s1))
2227
- end
2228
-
2229
- def test_spaceship_platform
2230
- s1 = util_spec "a", "1"
2231
- s2 = util_spec "a", "1" do |s|
2232
- s.platform = Gem::Platform.new "x86-my_platform1"
2233
- end
2234
-
2235
- assert_equal(-1, (s1 <=> s2))
2236
- assert_equal(0, (s1 <=> s1))
2237
- assert_equal(1, (s2 <=> s1))
2238
- end
2239
-
2240
- def test_spaceship_version
2241
- s1 = util_spec "a", "1"
2242
- s2 = util_spec "a", "2"
2243
-
2244
- assert_equal(-1, (s1 <=> s2))
2245
- assert_equal(0, (s1 <=> s1))
2246
- assert_equal(1, (s2 <=> s1))
2247
- end
2248
-
2249
- def test_spec_file
2250
- assert_equal File.join(@gemhome, "specifications", "a-1.gemspec"),
2251
- @a1.spec_file
2252
- end
2253
-
2254
- def test_spec_name
2255
- assert_equal "a-1.gemspec", @a1.spec_name
2256
- end
2257
-
2258
- def test_summary
2259
- assert_equal "this is a summary", @a1.summary
2260
- end
2261
-
2262
- def test_test_files
2263
- @a1.test_file = "test/suite.rb"
2264
- assert_equal ["test/suite.rb"], @a1.test_files
2265
- end
2266
-
2267
- def test_runtime_predicate_true
2268
- @a2.add_runtime_dependency "b", "1"
2269
- assert_predicate @a2.dependencies.first, :runtime?
2270
-
2271
- @a2.dependencies.first.instance_variable_set :@type, nil
2272
- assert_predicate @a2.dependencies.first, :runtime?
2273
- end
2274
-
2275
- def test_runtime_predicate_false
2276
- @a2.add_development_dependency "b", "1"
2277
- refute_predicate @a2.dependencies.first, :runtime?
2278
- end
2279
-
2280
- def test_to_ruby
2281
- @a2.add_runtime_dependency "b", "1"
2282
- @a2.dependencies.first.instance_variable_set :@type, nil
2283
- @a2.required_rubygems_version = Gem::Requirement.new "> 0"
2284
- @a2.require_paths << "other"
2285
-
2286
- ruby_code = @a2.to_ruby
2287
-
2288
- expected = <<-SPEC
2289
- # -*- encoding: utf-8 -*-
2290
- # stub: a 2 ruby lib\0other
2291
-
2292
- Gem::Specification.new do |s|
2293
- s.name = "a".freeze
2294
- s.version = "2".freeze
2295
-
2296
- s.required_rubygems_version = Gem::Requirement.new(\"> 0\".freeze) if s.respond_to? :required_rubygems_version=
2297
- s.require_paths = ["lib".freeze, "other".freeze]
2298
- s.authors = ["A User".freeze]
2299
- s.date = "#{@a2.date.strftime("%Y-%m-%d")}"
2300
- s.description = "This is a test description".freeze
2301
- s.email = "example@example.com".freeze
2302
- s.files = ["lib/code.rb".freeze]
2303
- s.homepage = "http://example.com".freeze
2304
- s.rubygems_version = "#{Gem::VERSION}".freeze
2305
- s.summary = "this is a summary".freeze
2306
-
2307
- s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
2308
-
2309
- s.add_runtime_dependency(%q<b>.freeze, [\"= 1\".freeze])
2310
- end
2311
- SPEC
2312
-
2313
- assert_equal expected, ruby_code
2314
-
2315
- same_spec = eval ruby_code
2316
-
2317
- assert_equal @a2, same_spec
2318
- end
2319
-
2320
- def test_to_ruby_with_rsa_key
2321
- require "rubygems/openssl"
2322
- pend "openssl is missing" unless defined?(OpenSSL::PKey::RSA)
2323
-
2324
- rsa_key = OpenSSL::PKey::RSA.new(2048)
2325
- @a2.signing_key = rsa_key
2326
- ruby_code = @a2.to_ruby
2327
-
2328
- expected = <<-SPEC
2329
- # -*- encoding: utf-8 -*-
2330
- # stub: a 2 ruby lib
2331
-
2332
- Gem::Specification.new do |s|
2333
- s.name = "a".freeze
2334
- s.version = "2".freeze
2335
-
2336
- s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
2337
- s.require_paths = ["lib".freeze]
2338
- s.authors = ["A User".freeze]
2339
- s.date = "#{@a2.date.strftime("%Y-%m-%d")}"
2340
- s.description = "This is a test description".freeze
2341
- s.email = "example@example.com".freeze
2342
- s.files = ["lib/code.rb".freeze]
2343
- s.homepage = "http://example.com".freeze
2344
- s.rubygems_version = "#{Gem::VERSION}".freeze
2345
- s.summary = "this is a summary".freeze
2346
- end
2347
- SPEC
2348
-
2349
- assert_equal expected, ruby_code
2350
- end
2351
-
2352
- def test_to_ruby_for_cache
2353
- @a2.add_runtime_dependency "b", "1"
2354
- @a2.dependencies.first.instance_variable_set :@type, nil
2355
- @a2.required_rubygems_version = Gem::Requirement.new "> 0"
2356
- @a2.installed_by_version = Gem.rubygems_version
2357
-
2358
- # cached specs do not have spec.files populated:
2359
- ruby_code = @a2.to_ruby_for_cache
2360
-
2361
- expected = <<-SPEC
2362
- # -*- encoding: utf-8 -*-
2363
- # stub: a 2 ruby lib
2364
-
2365
- Gem::Specification.new do |s|
2366
- s.name = "a".freeze
2367
- s.version = "2".freeze
2368
-
2369
- s.required_rubygems_version = Gem::Requirement.new(\"> 0\".freeze) if s.respond_to? :required_rubygems_version=
2370
- s.require_paths = ["lib".freeze]
2371
- s.authors = ["A User".freeze]
2372
- s.date = "#{@a2.date.strftime("%Y-%m-%d")}"
2373
- s.description = "This is a test description".freeze
2374
- s.email = "example@example.com".freeze
2375
- s.homepage = "http://example.com".freeze
2376
- s.rubygems_version = "#{Gem::VERSION}".freeze
2377
- s.summary = "this is a summary".freeze
2378
-
2379
- s.installed_by_version = "#{Gem::VERSION}".freeze if s.respond_to? :installed_by_version
2380
-
2381
- s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
2382
-
2383
- s.add_runtime_dependency(%q<b>.freeze, ["= 1".freeze])
2384
- end
2385
- SPEC
2386
-
2387
- assert_equal expected, ruby_code
2388
-
2389
- same_spec = eval ruby_code
2390
-
2391
- # cached specs do not have spec.files populated:
2392
- @a2.files = []
2393
- assert_equal @a2, same_spec
2394
- end
2395
-
2396
- def test_to_ruby_fancy
2397
- make_spec_c1
2398
-
2399
- @c1.platform = Gem::Platform.local
2400
- ruby_code = @c1.to_ruby
2401
-
2402
- local = Gem::Platform.local
2403
- expected_platform = "[#{local.cpu.inspect}.freeze, #{local.os.inspect}.freeze, #{local.version.inspect}.freeze]"
2404
- stub_require_paths =
2405
- @c1.instance_variable_get(:@require_paths).join "\u0000"
2406
- extensions = @c1.extensions.join "\u0000"
2407
-
2408
- expected = <<-SPEC
2409
- # -*- encoding: utf-8 -*-
2410
- # stub: a 1 #{win_platform? ? "x86-mswin32-60" : "x86-darwin-8"} #{stub_require_paths}
2411
- # stub: #{extensions}
2412
-
2413
- Gem::Specification.new do |s|
2414
- s.name = "a".freeze
2415
- s.version = "1".freeze
2416
- s.platform = Gem::Platform.new(#{expected_platform})
2417
-
2418
- s.required_rubygems_version = Gem::Requirement.new(\">= 0\".freeze) if s.respond_to? :required_rubygems_version=
2419
- s.require_paths = ["lib".freeze]
2420
- s.authors = ["A User".freeze]
2421
- s.date = "#{@c1.date.strftime("%Y-%m-%d")}"
2422
- s.description = "This is a test description".freeze
2423
- s.email = "example@example.com".freeze
2424
- s.executables = ["exec".freeze]
2425
- s.extensions = ["ext/a/extconf.rb".freeze]
2426
- s.files = ["bin/exec".freeze, "ext/a/extconf.rb".freeze, "lib/code.rb".freeze, "test/suite.rb".freeze]
2427
- s.homepage = "http://example.com".freeze
2428
- s.licenses = ["MIT".freeze]
2429
- s.requirements = ["A working computer".freeze]
2430
- s.rubygems_version = "#{Gem::VERSION}".freeze
2431
- s.summary = "this is a summary".freeze
2432
- s.test_files = ["test/suite.rb".freeze]
2433
-
2434
- s.specification_version = 4
2435
-
2436
- s.add_runtime_dependency(%q<rake>.freeze, [\"> 0.4\".freeze])
2437
- s.add_runtime_dependency(%q<jabber4r>.freeze, [\"> 0.0.0\".freeze])
2438
- s.add_runtime_dependency(%q<pqa>.freeze, [\"> 0.4\".freeze, \"<= 0.6\".freeze])
2439
- end
2440
- SPEC
2441
-
2442
- assert_equal expected, ruby_code
2443
-
2444
- same_spec = eval ruby_code
2445
-
2446
- assert_equal @c1, same_spec
2447
- end
2448
-
2449
- def test_to_ruby_keeps_requirements_as_originally_specified
2450
- spec = util_spec "a", "1" do |s|
2451
- s.add_dependency "b", ["~> 1.0", ">= 1.0.0"]
2452
- end
2453
-
2454
- assert_includes spec.to_ruby, '"~> 1.0".freeze, ">= 1.0.0".freeze'
2455
- end
2456
-
2457
- def test_to_ruby_legacy
2458
- gemspec1 = Gem::Deprecate.skip_during do
2459
- eval LEGACY_RUBY_SPEC
2460
- end
2461
- ruby_code = gemspec1.to_ruby
2462
- gemspec2 = eval ruby_code
2463
-
2464
- assert_equal gemspec1, gemspec2
2465
- end
2466
-
2467
- def test_to_ruby_nested_hash
2468
- metadata = {}
2469
- metadata[metadata] = metadata
2470
-
2471
- @a2.metadata = metadata
2472
-
2473
- ruby = @a2.to_ruby
2474
-
2475
- assert_match %r%^ s\.metadata = \{ "%, ruby
2476
- end
2477
-
2478
- def test_to_ruby_platform
2479
- @a2.platform = Gem::Platform.local
2480
- @a2.instance_variable_set :@original_platform, "old_platform"
2481
-
2482
- ruby_code = @a2.to_ruby
2483
-
2484
- same_spec = eval ruby_code
2485
-
2486
- assert_equal "old_platform", same_spec.original_platform
2487
- end
2488
-
2489
- def test_to_yaml
2490
- yaml_str = @a1.to_yaml
2491
-
2492
- refute_match %r{!!null}, yaml_str
2493
-
2494
- same_spec = Gem::Specification.from_yaml(yaml_str)
2495
-
2496
- assert_equal @a1, same_spec
2497
- end
2498
-
2499
- def test_to_yaml_fancy
2500
- @a1.platform = Gem::Platform.local
2501
- yaml_str = @a1.to_yaml
2502
-
2503
- same_spec = Gem::Specification.from_yaml(yaml_str)
2504
-
2505
- assert_equal Gem::Platform.local, same_spec.platform
2506
-
2507
- assert_equal @a1, same_spec
2508
- end
2509
-
2510
- def test_to_yaml_platform_empty_string
2511
- @a1.instance_variable_set :@original_platform, ""
2512
-
2513
- assert_match %r{^platform: ruby$}, @a1.to_yaml
2514
- end
2515
-
2516
- def test_to_yaml_platform_legacy
2517
- @a1.platform = "powerpc-darwin7.9.0"
2518
- @a1.instance_variable_set :@original_platform, "powerpc-darwin7.9.0"
2519
-
2520
- yaml_str = @a1.to_yaml
2521
-
2522
- same_spec = load_yaml yaml_str
2523
-
2524
- assert_equal Gem::Platform.new("powerpc-darwin7"), same_spec.platform
2525
- assert_equal "powerpc-darwin7.9.0", same_spec.original_platform
2526
- end
2527
-
2528
- def test_to_yaml_platform_nil
2529
- @a1.instance_variable_set :@original_platform, nil
2530
-
2531
- assert_match %r{^platform: ruby$}, @a1.to_yaml
2532
- end
2533
-
2534
- def test_validate
2535
- util_setup_validate
2536
-
2537
- Dir.chdir @tempdir do
2538
- assert @a1.validate
2539
- end
2540
- end
2541
-
2542
- def x(s); s.gsub(/xxx/, ""); end
2543
- def w; x "WARxxxNING"; end
2544
- def t; x "TOxxxDO"; end
2545
- def f; x "FxxxIXME"; end
2546
-
2547
- def test_validate_authors
2548
- util_setup_validate
2549
-
2550
- Dir.chdir @tempdir do
2551
- @a1.authors = [""]
2552
-
2553
- use_ui @ui do
2554
- @a1.validate
2555
- end
2556
-
2557
- assert_match "#{w}: no author specified\n", @ui.error, "error"
2558
-
2559
- @a1.authors = [Object.new]
2560
-
2561
- assert_equal [], @a1.authors
2562
-
2563
- e = assert_raise Gem::InvalidSpecificationException do
2564
- @a1.validate
2565
- end
2566
-
2567
- assert_equal "authors may not be empty", e.message
2568
-
2569
- @a1.authors = ["#{f} (who is writing this software)"]
2570
-
2571
- e = assert_raise Gem::InvalidSpecificationException do
2572
- @a1.validate
2573
- end
2574
-
2575
- assert_equal %("#{f}" or "#{t}" is not an author), e.message
2576
-
2577
- @a1.authors = ["#{t} (who is writing this software)"]
2578
-
2579
- e = assert_raise Gem::InvalidSpecificationException do
2580
- @a1.validate
2581
- end
2582
-
2583
- assert_equal %("#{f}" or "#{t}" is not an author), e.message
2584
- end
2585
- end
2586
-
2587
- def test_validate_autorequire
2588
- util_setup_validate
2589
-
2590
- Dir.chdir @tempdir do
2591
- @a1.autorequire = "code"
2592
-
2593
- use_ui @ui do
2594
- @a1.validate
2595
- end
2596
-
2597
- assert_match "#{w}: deprecated autorequire specified\n",
2598
- @ui.error, "error"
2599
- end
2600
- end
2601
-
2602
- def test_validate_dependencies
2603
- util_setup_validate
2604
-
2605
- Dir.chdir @tempdir do
2606
- @a1.add_runtime_dependency "b", ">= 1.0.rc1"
2607
- @a1.add_development_dependency "c", ">= 2.0.rc2"
2608
- @a1.add_runtime_dependency "d", "~> 1.2.3"
2609
- @a1.add_runtime_dependency "e", "~> 1.2.3.4"
2610
- @a1.add_runtime_dependency "g", "~> 1.2.3", ">= 1.2.3.4"
2611
- @a1.add_runtime_dependency "h", ">= 1.2.3", "<= 2"
2612
- @a1.add_runtime_dependency "i", ">= 1.2"
2613
- @a1.add_runtime_dependency "j", ">= 1.2.3"
2614
- @a1.add_runtime_dependency "k", "> 1.2"
2615
- @a1.add_runtime_dependency "l", "> 1.2.3"
2616
- @a1.add_runtime_dependency "m", "~> 2.1.0"
2617
- @a1.add_runtime_dependency "n", "~> 0.1.0"
2618
- @a1.add_runtime_dependency "o"
2619
-
2620
- use_ui @ui do
2621
- @a1.validate
2622
- end
2623
-
2624
- expected = <<-EXPECTED
2625
- #{w}: prerelease dependency on b (>= 1.0.rc1) is not recommended
2626
- #{w}: prerelease dependency on c (>= 2.0.rc2, development) is not recommended
2627
- #{w}: open-ended dependency on i (>= 1.2) is not recommended
2628
- if i is semantically versioned, use:
2629
- add_runtime_dependency 'i', '~> 1.2'
2630
- #{w}: open-ended dependency on j (>= 1.2.3) is not recommended
2631
- if j is semantically versioned, use:
2632
- add_runtime_dependency 'j', '~> 1.2', '>= 1.2.3'
2633
- #{w}: open-ended dependency on k (> 1.2) is not recommended
2634
- if k is semantically versioned, use:
2635
- add_runtime_dependency 'k', '~> 1.2', '> 1.2'
2636
- #{w}: open-ended dependency on l (> 1.2.3) is not recommended
2637
- if l is semantically versioned, use:
2638
- add_runtime_dependency 'l', '~> 1.2', '> 1.2.3'
2639
- #{w}: open-ended dependency on o (>= 0) is not recommended
2640
- use a bounded requirement, such as '~> x.y'
2641
- #{w}: See https://guides.rubygems.org/specification-reference/ for help
2642
- EXPECTED
2643
-
2644
- assert_equal expected, @ui.error, "warning"
2645
- end
2646
- end
2647
-
2648
- def test_validate_dependencies_duplicates
2649
- util_setup_validate
2650
-
2651
- Dir.chdir @tempdir do
2652
- @a1.add_runtime_dependency "b", "~> 1.2"
2653
- @a1.add_runtime_dependency "b", ">= 1.2.3"
2654
- @a1.add_development_dependency "c", "~> 1.2"
2655
- @a1.add_development_dependency "c", ">= 1.2.3"
2656
-
2657
- use_ui @ui do
2658
- e = assert_raise Gem::InvalidSpecificationException do
2659
- @a1.validate
2660
- end
2661
-
2662
- expected = <<-EXPECTED
2663
- duplicate dependency on b (>= 1.2.3), (~> 1.2) use:
2664
- add_runtime_dependency 'b', '>= 1.2.3', '~> 1.2'
2665
- duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use:
2666
- add_development_dependency 'c', '>= 1.2.3', '~> 1.2'
2667
- EXPECTED
2668
-
2669
- assert_equal expected, e.message
2670
- end
2671
-
2672
- assert_equal <<-EXPECTED, @ui.error
2673
- #{w}: See https://guides.rubygems.org/specification-reference/ for help
2674
- EXPECTED
2675
- end
2676
- end
2677
-
2678
- def test_validate_dependencies_allowed_duplicates
2679
- util_setup_validate
2680
-
2681
- Dir.chdir @tempdir do
2682
- @a1.add_runtime_dependency "b", "~> 1.2"
2683
- @a1.add_development_dependency "b", "= 1.2.3"
2684
-
2685
- use_ui @ui do
2686
- @a1.validate
2687
- end
2688
-
2689
- assert_equal "", @ui.error, "warning"
2690
- end
2691
- end
2692
-
2693
- def test_validate_prerelease_dependencies_with_prerelease_version
2694
- util_setup_validate
2695
-
2696
- Dir.chdir @tempdir do
2697
- @a1.version = "1.0.0.beta.1"
2698
- @a1.add_runtime_dependency "b", "~> 1.2.0.beta.1"
2699
-
2700
- use_ui @ui do
2701
- @a1.validate
2702
- end
2703
-
2704
- assert_equal "", @ui.error, "warning"
2705
- end
2706
- end
2707
-
2708
- def test_validate_self_referencing_dependencies
2709
- util_setup_validate
2710
-
2711
- Dir.chdir @tempdir do
2712
- @a1.add_runtime_dependency @a1.name, "1"
2713
-
2714
- use_ui @ui do
2715
- @a1.validate
2716
- end
2717
-
2718
- assert_equal <<-EXPECTED, @ui.error
2719
- #{w}: Self referencing dependency is unnecessary and strongly discouraged.
2720
- #{w}: See https://guides.rubygems.org/specification-reference/ for help
2721
- EXPECTED
2722
- end
2723
- end
2724
-
2725
- def test_validate_rake_extension_have_rake_dependency_warning
2726
- util_setup_validate
2727
-
2728
- Dir.chdir @tempdir do
2729
- @a1.extensions = ["Rakefile"]
2730
- File.write File.join(@tempdir, "Rakefile"), ""
2731
-
2732
- use_ui @ui do
2733
- @a1.validate
2734
- end
2735
-
2736
- assert_match(/add rake as a dependency/, @ui.error)
2737
- end
2738
- end
2739
-
2740
- def test_validate_rake_extension_have_rake_dependency_no_warning
2741
- util_setup_validate
2742
-
2743
- Dir.chdir @tempdir do
2744
- @a1.extensions = ["Rakefile"]
2745
- @a1.add_runtime_dependency "rake"
2746
- File.write File.join(@tempdir, "Rakefile"), ""
2747
-
2748
- use_ui @ui do
2749
- @a1.validate
2750
- end
2751
-
2752
- refute_match(/add rake as a dependency/, @ui.error)
2753
- end
2754
- end
2755
-
2756
- def test_validate_rust_extension_have_missing_cargo_toml_error
2757
- util_setup_validate
2758
-
2759
- Dir.chdir @tempdir do
2760
- @a1.extensions = ["Cargo.toml"]
2761
- File.write File.join(@tempdir, "Cargo.toml"), ""
2762
-
2763
- e = assert_raise Gem::InvalidSpecificationException do
2764
- use_ui @ui do
2765
- @a1.validate
2766
- end
2767
- end
2768
-
2769
- assert_match(/but Cargo.lock is not part of the gem files/, e.message)
2770
- end
2771
- end
2772
-
2773
- def test_validate_rust_extension_have_no_missing_cargo_toml_error
2774
- util_setup_validate
2775
-
2776
- Dir.chdir @tempdir do
2777
- @a1.extensions = ["Cargo.toml"]
2778
- @a1.files << "Cargo.toml"
2779
- @a1.files << "Cargo.lock"
2780
- File.write File.join(@tempdir, "Cargo.toml"), ""
2781
- File.write File.join(@tempdir, "Cargo.lock"), ""
2782
-
2783
- use_ui @ui do
2784
- @a1.validate
2785
- end
2786
- end
2787
- end
2788
-
2789
- def test_validate_description
2790
- util_setup_validate
2791
-
2792
- Dir.chdir @tempdir do
2793
- @a1.description = ""
2794
-
2795
- use_ui @ui do
2796
- @a1.validate
2797
- end
2798
-
2799
- @ui = Gem::MockGemUi.new
2800
- @a1.summary = "this is my summary"
2801
- @a1.description = @a1.summary
2802
-
2803
- use_ui @ui do
2804
- @a1.validate
2805
- end
2806
-
2807
- assert_match "#{w}: description and summary are identical\n",
2808
- @ui.error, "error"
2809
-
2810
- @a1.description = "#{f} (describe your package)"
2811
-
2812
- e = assert_raise Gem::InvalidSpecificationException do
2813
- @a1.validate
2814
- end
2815
-
2816
- assert_equal %("#{f}" or "#{t}" is not a description), e.message
2817
-
2818
- @a1.description = "#{t} (describe your package)"
2819
-
2820
- e = assert_raise Gem::InvalidSpecificationException do
2821
- @a1.validate
2822
- end
2823
-
2824
- assert_equal %("#{f}" or "#{t}" is not a description), e.message
2825
-
2826
- # Adding #{f} anywhere after the start of the description should be fine.
2827
- @a1.description = "(some description) #{f}"
2828
-
2829
- assert_nothing_raised do
2830
- @a1.validate
2831
- end
2832
-
2833
- # Adding #{t} anywhere after the start of the description should be fine.
2834
- @a1.description = "(some description) #{t}"
2835
-
2836
- assert_nothing_raised do
2837
- @a1.validate
2838
- end
2839
-
2840
- # Adding #{f} at the start of the second or later line should be fine.
2841
- @a1.description = "(some description)\n#{f}"
2842
-
2843
- assert_nothing_raised do
2844
- @a1.validate
2845
- end
2846
-
2847
- # Adding #{t} at the start of the second or later line should be fine.
2848
- @a1.description = "(some description)\n#{t}"
2849
-
2850
- assert_nothing_raised do
2851
- @a1.validate
2852
- end
2853
- end
2854
- end
2855
-
2856
- def test_validate_email
2857
- util_setup_validate
2858
-
2859
- Dir.chdir @tempdir do
2860
- @a1.email = "FIxxxXME (your e-mail)".sub(/xxx/, "")
2861
-
2862
- e = assert_raise Gem::InvalidSpecificationException do
2863
- @a1.validate
2864
- end
2865
-
2866
- assert_equal %("#{f}" or "#{t}" is not an email), e.message
2867
-
2868
- @a1.email = "#{t} (your e-mail)"
2869
-
2870
- e = assert_raise Gem::InvalidSpecificationException do
2871
- @a1.validate
2872
- end
2873
-
2874
- assert_equal %("#{f}" or "#{t}" is not an email), e.message
2875
- end
2876
- end
2877
-
2878
- def test_validate_empty
2879
- e = assert_raise Gem::InvalidSpecificationException do
2880
- Gem::Specification.new.validate
2881
- end
2882
-
2883
- assert_equal "missing value for attribute name", e.message
2884
- end
2885
-
2886
- def test_validate_error
2887
- assert_raise Gem::InvalidSpecificationException do
2888
- use_ui @ui do
2889
- Gem::Specification.new.validate
2890
- end
2891
- end
2892
-
2893
- assert_match "See https://guides.rubygems.org/specification-reference/ for help", @ui.error
2894
- end
2895
-
2896
- def test_validate_executables
2897
- util_setup_validate
2898
-
2899
- FileUtils.mkdir_p File.join(@tempdir, "bin")
2900
- File.write File.join(@tempdir, "bin", "exec"), ""
2901
- FileUtils.mkdir_p File.join(@tempdir, "exec")
2902
-
2903
- use_ui @ui do
2904
- Dir.chdir @tempdir do
2905
- assert @a1.validate
2906
- end
2907
- end
2908
-
2909
- assert_equal %w[exec], @a1.executables
2910
-
2911
- assert_equal "", @ui.output, "output"
2912
- assert_match "#{w}: bin/exec is missing #! line\n", @ui.error, "error"
2913
- end
2914
-
2915
- def test_validate_empty_require_paths
2916
- if win_platform?
2917
- pend "test_validate_empty_require_paths skipped on MS Windows (symlink)"
2918
- else
2919
- util_setup_validate
2920
-
2921
- @a1.require_paths = []
2922
- e = assert_raise Gem::InvalidSpecificationException do
2923
- @a1.validate
2924
- end
2925
-
2926
- assert_equal "specification must have at least one require_path",
2927
- e.message
2928
- end
2929
- end
2930
-
2931
- def test_validate_files
2932
- pend "test_validate_files skipped on MS Windows (symlink)" if win_platform?
2933
- util_setup_validate
2934
-
2935
- @a1.files += ["lib", "lib2"]
2936
- @a1.extensions << "ext/a/extconf.rb"
2937
-
2938
- Dir.chdir @tempdir do
2939
- FileUtils.ln_s "lib/code.rb", "lib2" unless vc_windows?
2940
-
2941
- use_ui @ui do
2942
- @a1.validate
2943
- end
2944
-
2945
- assert_match "WARNING: lib2 is a symlink, which is not supported on all platforms", @ui.error
2946
- end
2947
-
2948
- assert_equal %w[bin/exec ext/a/extconf.rb lib/code.rb lib2 test/suite.rb].sort,
2949
- @a1.files
2950
- end
2951
-
2952
- def test_unresolved_specs
2953
- specification = Gem::Specification.clone
2954
-
2955
- set_orig specification
2956
-
2957
- specification.define_singleton_method(:unresolved_deps) do
2958
- { b: Gem::Dependency.new("x","1") }
2959
- end
2960
-
2961
- specification.define_singleton_method(:find_all_by_name) do |dep_name|
2962
- []
2963
- end
2964
-
2965
- expected = <<-EXPECTED
2966
- WARN: Unresolved or ambiguous specs during Gem::Specification.reset:
2967
- x (= 1)
2968
- WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>'
2969
- Please report a bug if this causes problems.
2970
- EXPECTED
2971
-
2972
- actual_stdout, actual_stderr = capture_output do
2973
- specification.reset
2974
- end
2975
- assert_empty actual_stdout
2976
- assert_equal(expected, actual_stderr)
2977
- end
2978
-
2979
- def test_unresolved_specs_with_versions
2980
- specification = Gem::Specification.clone
2981
-
2982
- set_orig specification
2983
-
2984
- specification.define_singleton_method(:unresolved_deps) do
2985
- { b: Gem::Dependency.new("x","1") }
2986
- end
2987
-
2988
- specification.define_singleton_method(:find_all_by_name) do |dep_name|
2989
- [
2990
- specification.new {|s| s.name = "z", s.version = Gem::Version.new("1") },
2991
- specification.new {|s| s.name = "z", s.version = Gem::Version.new("2") },
2992
- ]
2993
- end
2994
-
2995
- expected = <<-EXPECTED
2996
- WARN: Unresolved or ambiguous specs during Gem::Specification.reset:
2997
- x (= 1)
2998
- Available/installed versions of this gem:
2999
- - 1
3000
- - 2
3001
- WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>'
3002
- Please report a bug if this causes problems.
3003
- EXPECTED
3004
-
3005
- actual_stdout, actual_stderr = capture_output do
3006
- specification.reset
3007
- end
3008
- assert_empty actual_stdout
3009
- assert_equal(expected, actual_stderr)
3010
- end
3011
-
3012
- def test_duplicate_runtime_dependency
3013
- expected = "WARNING: duplicated b dependency [\"~> 3.0\", \"~> 3.0\"]\n"
3014
- out, err = capture_output do
3015
- @a1.add_runtime_dependency "b", "~> 3.0", "~> 3.0"
3016
- end
3017
- assert_empty out
3018
- assert_equal(expected, err)
3019
- end
3020
-
3021
- def set_orig(cls)
3022
- s_cls = cls.singleton_class
3023
- s_cls.send :alias_method, :orig_unresolved_deps , :unresolved_deps
3024
- s_cls.send :alias_method, :orig_find_all_by_name, :find_all_by_name
3025
- end
3026
-
3027
- def test_validate_files_recursive
3028
- util_setup_validate
3029
- FileUtils.touch @a1.file_name
3030
-
3031
- @a1.files = [@a1.file_name]
3032
-
3033
- e = assert_raise Gem::InvalidSpecificationException do
3034
- @a1.validate
3035
- end
3036
-
3037
- assert_equal "#{@a1.full_name} contains itself (#{@a1.file_name}), check your files list",
3038
- e.message
3039
- end
3040
-
3041
- def test_validate_homepage
3042
- util_setup_validate
3043
-
3044
- Dir.chdir @tempdir do
3045
- @a1.homepage = nil
3046
-
3047
- use_ui @ui do
3048
- @a1.validate
3049
- end
3050
-
3051
- assert_match "#{w}: no homepage specified\n", @ui.error, "error"
3052
-
3053
- @ui = Gem::MockGemUi.new
3054
-
3055
- @a1.homepage = ""
3056
-
3057
- use_ui @ui do
3058
- @a1.validate
3059
- end
3060
-
3061
- assert_match "#{w}: no homepage specified\n", @ui.error, "error"
3062
-
3063
- @a1.homepage = "over at my cool site"
3064
-
3065
- e = assert_raise Gem::InvalidSpecificationException do
3066
- @a1.validate
3067
- end
3068
-
3069
- assert_equal '"over at my cool site" is not a valid HTTP URI', e.message
3070
-
3071
- @a1.homepage = "ftp://rubygems.org"
3072
-
3073
- e = assert_raise Gem::InvalidSpecificationException do
3074
- @a1.validate
3075
- end
3076
-
3077
- assert_equal '"ftp://rubygems.org" is not a valid HTTP URI', e.message
3078
-
3079
- @a1.homepage = "https://rubygems.org/"
3080
- assert_equal true, @a1.validate
3081
-
3082
- @a1.homepage = "https://rubygems.org"
3083
- assert_equal true, @a1.validate
3084
- end
3085
- end
3086
-
3087
- def test_validate_license
3088
- util_setup_validate
3089
-
3090
- use_ui @ui do
3091
- @a1.licenses.clear
3092
- @a1.validate
3093
- end
3094
-
3095
- assert_match <<-WARNING, @ui.error
3096
- WARNING: licenses is empty, but is recommended. Use a license identifier from
3097
- http://spdx.org/licenses or 'Nonstandard' for a nonstandard license,
3098
- or set it to nil if you don't want to specify a license.
3099
- WARNING
3100
- end
3101
-
3102
- def test_validate_nil_license
3103
- util_setup_validate
3104
-
3105
- use_ui @ui do
3106
- @a1.license = nil
3107
- @a1.validate
3108
- end
3109
-
3110
- assert_empty @ui.error
3111
- end
3112
-
3113
- def test_validate_license_in_a_non_packaging_context
3114
- util_setup_validate
3115
-
3116
- use_ui @ui do
3117
- @a1.licenses.clear
3118
- @a1.validate(false)
3119
- end
3120
-
3121
- assert_empty @ui.error
3122
- end
3123
-
3124
- def test_removed_methods
3125
- assert_equal Gem::Specification::REMOVED_METHODS, [:rubyforge_project=]
3126
- end
3127
-
3128
- def test_validate_removed_rubyforge_project
3129
- util_setup_validate
3130
-
3131
- use_ui @ui do
3132
- @a1.rubyforge_project = "invalid-attribute"
3133
- @a1.validate
3134
- end
3135
-
3136
- assert_match "rubyforge_project= is deprecated", @ui.error
3137
- end
3138
-
3139
- def test_validate_license_values
3140
- util_setup_validate
3141
-
3142
- use_ui @ui do
3143
- @a1.licenses = ["BSD"]
3144
- @a1.validate
3145
- end
3146
-
3147
- assert_match <<-WARNING, @ui.error
3148
- WARNING: license value 'BSD' is invalid. Use a license identifier from
3149
- http://spdx.org/licenses or 'Nonstandard' for a nonstandard license,
3150
- or set it to nil if you don't want to specify a license.
3151
- WARNING
3152
- end
3153
-
3154
- def test_validate_license_ref
3155
- util_setup_validate
3156
-
3157
- use_ui @ui do
3158
- @a1.licenses = ["LicenseRef-LICENSE.md"]
3159
- @a1.validate
3160
- end
3161
-
3162
- assert_empty @ui.error
3163
- end
3164
-
3165
- def test_validate_license_values_plus
3166
- util_setup_validate
3167
-
3168
- use_ui @ui do
3169
- @a1.licenses = ["GPL-2.0+"]
3170
- @a1.validate
3171
- end
3172
-
3173
- assert_empty @ui.error
3174
- end
3175
-
3176
- def test_validate_license_values_or_later
3177
- util_setup_validate
3178
-
3179
- use_ui @ui do
3180
- @a1.licenses = ["GPL-2.0-or-later"]
3181
- @a1.validate
3182
- end
3183
-
3184
- assert_empty @ui.error
3185
- end
3186
-
3187
- def test_validate_license_values_with
3188
- util_setup_validate
3189
-
3190
- use_ui @ui do
3191
- @a1.licenses = ["GPL-2.0+ WITH Autoconf-exception-2.0"]
3192
- @a1.validate
3193
- end
3194
-
3195
- assert_empty @ui.error
3196
- end
3197
-
3198
- def test_validate_license_with_nonsense_suffix
3199
- util_setup_validate
3200
-
3201
- use_ui @ui do
3202
- @a1.licenses = ["GPL-2.0+ FOO", "GPL-2.0 FOO"]
3203
- @a1.validate
3204
- end
3205
-
3206
- assert_match <<-WARNING, @ui.error
3207
- WARNING: license value 'GPL-2.0+ FOO' is invalid. Use a license identifier from
3208
- http://spdx.org/licenses or 'Nonstandard' for a nonstandard license,
3209
- or set it to nil if you don't want to specify a license.
3210
- WARNING
3211
- assert_match <<-WARNING, @ui.error
3212
- WARNING: license value 'GPL-2.0 FOO' is invalid. Use a license identifier from
3213
- http://spdx.org/licenses or 'Nonstandard' for a nonstandard license,
3214
- or set it to nil if you don't want to specify a license.
3215
- WARNING
3216
- end
3217
-
3218
- def test_validate_license_with_invalid_exception
3219
- util_setup_validate
3220
-
3221
- use_ui @ui do
3222
- @a1.licenses = ["GPL-2.0+ WITH Autocofn-exception-2.0"]
3223
- @a1.validate
3224
- end
3225
-
3226
- assert_match <<-WARNING, @ui.error
3227
- WARNING: license value 'GPL-2.0+ WITH Autocofn-exception-2.0' is invalid. Use a license identifier from
3228
- http://spdx.org/licenses or 'Nonstandard' for a nonstandard license,
3229
- or set it to nil if you don't want to specify a license.
3230
- WARNING
3231
- end
3232
-
3233
- def test_validate_license_gives_suggestions
3234
- util_setup_validate
3235
-
3236
- use_ui @ui do
3237
- @a1.licenses = ["ruby"]
3238
- @a1.validate
3239
- end
3240
-
3241
- assert_match <<-WARNING, @ui.error
3242
- WARNING: license value 'ruby' is invalid. Use a license identifier from
3243
- http://spdx.org/licenses or 'Nonstandard' for a nonstandard license,
3244
- or set it to nil if you don't want to specify a license.
3245
- Did you mean 'Ruby'?
3246
- WARNING
3247
- end
3248
-
3249
- def test_validate_empty_files
3250
- util_setup_validate
3251
-
3252
- use_ui @ui do
3253
- # we have to set all of these for #files to be empty
3254
- @a1.files = []
3255
- @a1.test_files = []
3256
- @a1.executables = []
3257
-
3258
- @a1.validate
3259
- end
3260
-
3261
- assert_match "no files specified", @ui.error
3262
- end
3263
-
3264
- def test_validate_empty_homepage
3265
- util_setup_validate
3266
-
3267
- use_ui @ui do
3268
- @a1.homepage = nil
3269
- @a1.validate
3270
- end
3271
-
3272
- assert_match "no homepage specified", @ui.error
3273
- end
3274
-
3275
- def test_validate_empty_summary
3276
- util_setup_validate
3277
-
3278
- use_ui @ui do
3279
- @a1.summary = nil
3280
- @a1.validate
3281
- end
3282
-
3283
- assert_match "no summary specified", @ui.error
3284
- end
3285
-
3286
- def test_validate_name
3287
- util_setup_validate
3288
-
3289
- e = assert_raise Gem::InvalidSpecificationException do
3290
- @a1.name = :json
3291
- @a1.validate
3292
- end
3293
-
3294
- assert_equal 'invalid value for attribute name: ":json" must be a string', e.message
3295
-
3296
- @a1.name = []
3297
- e = assert_raise Gem::InvalidSpecificationException do
3298
- @a1.validate
3299
- end
3300
- assert_equal "invalid value for attribute name: \"[]\" must be a string", e.message
3301
-
3302
- @a1.name = ""
3303
- e = assert_raise Gem::InvalidSpecificationException do
3304
- @a1.validate
3305
- end
3306
- assert_equal "invalid value for attribute name: \"\" must include at least one letter", e.message
3307
-
3308
- @a1.name = "12345"
3309
- e = assert_raise Gem::InvalidSpecificationException do
3310
- @a1.validate
3311
- end
3312
- assert_equal "invalid value for attribute name: \"12345\" must include at least one letter", e.message
3313
-
3314
- @a1.name = "../malicious"
3315
- e = assert_raise Gem::InvalidSpecificationException do
3316
- @a1.validate
3317
- end
3318
- assert_equal "invalid value for attribute name: \"../malicious\" can only include letters, numbers, dashes, and underscores", e.message
3319
-
3320
- @a1.name = "\ba\t"
3321
- e = assert_raise Gem::InvalidSpecificationException do
3322
- @a1.validate
3323
- end
3324
- assert_equal "invalid value for attribute name: \"\\ba\\t\" can only include letters, numbers, dashes, and underscores", e.message
3325
- end
3326
-
3327
- def test_validate_non_nil
3328
- util_setup_validate
3329
-
3330
- Dir.chdir @tempdir do
3331
- assert @a1.validate
3332
-
3333
- Gem::Specification.non_nil_attributes.each do |name|
3334
- next if name == :files # set by #normalize
3335
- spec = @a1.dup
3336
- spec.instance_variable_set "@#{name}", nil
3337
-
3338
- e = assert_raise Gem::InvalidSpecificationException do
3339
- spec.validate
3340
- end
3341
-
3342
- assert_match %r{^#{name}}, e.message
3343
- end
3344
- end
3345
- end
3346
-
3347
- def test_validate_permissions
3348
- pend "chmod not supported" if Gem.win_platform?
3349
-
3350
- util_setup_validate
3351
-
3352
- Dir.chdir @tempdir do
3353
- File.chmod 0o640, File.join("lib", "code.rb")
3354
- File.chmod 0o640, File.join("bin", "exec")
3355
-
3356
- use_ui @ui do
3357
- @a1.validate
3358
- end
3359
-
3360
- assert_match "#{w}: lib/code.rb is not world-readable\n", @ui.error
3361
- assert_match "#{w}: bin/exec is not world-readable\n", @ui.error
3362
- assert_match "#{w}: bin/exec is not executable\n", @ui.error
3363
- end
3364
- end
3365
-
3366
- def test_validate_permissions_of_missing_file_non_packaging
3367
- pend "chmod not supported" if Gem.win_platform?
3368
-
3369
- util_setup_validate
3370
-
3371
- Dir.chdir @tempdir do
3372
- File.delete File.join("lib", "code.rb")
3373
-
3374
- use_ui @ui do
3375
- assert @a1.validate(false)
3376
- end
3377
- end
3378
- end
3379
-
3380
- def test_validate_platform_legacy
3381
- util_setup_validate
3382
-
3383
- Dir.chdir @tempdir do
3384
- @a1.platform = "mswin32"
3385
- assert @a1.validate
3386
-
3387
- @a1.platform = "i586-linux"
3388
- assert @a1.validate
3389
-
3390
- @a1.platform = "powerpc-darwin"
3391
- assert @a1.validate
3392
- end
3393
- end
3394
-
3395
- def test_validate_rubygems_version
3396
- util_setup_validate
3397
-
3398
- @a1.rubygems_version = "3"
3399
- e = assert_raise Gem::InvalidSpecificationException do
3400
- @a1.validate
3401
- end
3402
-
3403
- assert_equal "expected RubyGems version #{Gem::VERSION}, was 3",
3404
- e.message
3405
- end
3406
-
3407
- def test_validate_specification_version
3408
- util_setup_validate
3409
-
3410
- Dir.chdir @tempdir do
3411
- @a1.specification_version = "1.0"
3412
-
3413
- e = assert_raise Gem::InvalidSpecificationException do
3414
- use_ui @ui do
3415
- @a1.validate
3416
- end
3417
- end
3418
-
3419
- err = "specification_version must be an Integer (did you mean version?)"
3420
- assert_equal err, e.message
3421
- end
3422
- end
3423
-
3424
- def test_validate_summary
3425
- util_setup_validate
3426
-
3427
- Dir.chdir @tempdir do
3428
- @a1.summary = ""
3429
-
3430
- use_ui @ui do
3431
- @a1.validate
3432
- end
3433
-
3434
- assert_match "#{w}: no summary specified\n", @ui.error, "error"
3435
-
3436
- @a1.summary = "#{f} (describe your package)"
3437
-
3438
- e = assert_raise Gem::InvalidSpecificationException do
3439
- @a1.validate
3440
- end
3441
-
3442
- assert_equal %("#{f}" or "#{t}" is not a summary), e.message
3443
-
3444
- @a1.summary = "#{t} (describe your package)"
3445
-
3446
- e = assert_raise Gem::InvalidSpecificationException do
3447
- @a1.validate
3448
- end
3449
-
3450
- assert_equal %("#{f}" or "#{t}" is not a summary), e.message
3451
- end
3452
- end
3453
-
3454
- def test_validate_warning
3455
- util_setup_validate
3456
-
3457
- use_ui @ui do
3458
- @a1.licenses.clear
3459
- @a1.validate
3460
- end
3461
-
3462
- assert_match "See https://guides.rubygems.org/specification-reference/ for help", @ui.error
3463
- end
3464
-
3465
- def test_version
3466
- assert_equal Gem::Version.new("1"), @a1.version
3467
- end
3468
-
3469
- def test_version_change_reset_full_name
3470
- orig_full_name = @a1.full_name
3471
-
3472
- @a1.version = "2"
3473
-
3474
- refute_equal orig_full_name, @a1.full_name
3475
- end
3476
-
3477
- def test_version_change_reset_cache_file
3478
- orig_cache_file = @a1.cache_file
3479
-
3480
- @a1.version = "2"
3481
-
3482
- refute_equal orig_cache_file, @a1.cache_file
3483
- end
3484
-
3485
- def test__load_fixes_Date_objects
3486
- spec = util_spec "a", 1
3487
- spec.instance_variable_set :@date, Date.today
3488
-
3489
- spec = Marshal.load Marshal.dump(spec)
3490
-
3491
- assert_kind_of Time, spec.date
3492
- end
3493
-
3494
- def test_load_errors_contain_filename
3495
- specfile = Tempfile.new(self.class.name.downcase)
3496
- specfile.write "raise 'boom'"
3497
- specfile.close
3498
- begin
3499
- capture_output do
3500
- Gem::Specification.load(specfile.path)
3501
- end
3502
- rescue StandardError => e
3503
- name_rexp = Regexp.new(Regexp.escape(specfile.path))
3504
- assert e.backtrace.grep(name_rexp).any?
3505
- end
3506
- ensure
3507
- specfile.delete
3508
- end
3509
-
3510
- def test_latest_specs
3511
- spec_fetcher do |fetcher|
3512
- fetcher.spec "a", 1 do |s|
3513
- s.platform = Gem::Platform.new "x86-my_platform1"
3514
- end
3515
-
3516
- fetcher.spec "a", 2
3517
-
3518
- fetcher.spec "a", 2 do |s|
3519
- s.platform = Gem::Platform.new "x86-my_platform1"
3520
- end
3521
-
3522
- fetcher.spec "a", 2 do |s|
3523
- s.platform = Gem::Platform.new "x86-other_platform1"
3524
- end
3525
-
3526
- fetcher.spec "a", 3 do |s|
3527
- s.platform = Gem::Platform.new "x86-other_platform1"
3528
- end
3529
- end
3530
-
3531
- expected = %W[
3532
- a-3-x86-other_platform-1
3533
- ]
3534
-
3535
- latest_specs = Gem::Specification.latest_specs.map(&:full_name).sort
3536
-
3537
- assert_equal expected, latest_specs
3538
- end
3539
-
3540
- def test_metadata_validates_ok
3541
- util_setup_validate
3542
-
3543
- Dir.chdir @tempdir do
3544
- @m1 = quick_gem "m", "1" do |s|
3545
- s.files = %w[lib/code.rb]
3546
- s.metadata = {
3547
- "one" => "two",
3548
- "home" => "three",
3549
- "homepage_uri" => "https://example.com/user/repo",
3550
- "funding_uri" => "https://example.com/donate",
3551
- }
3552
- end
3553
-
3554
- use_ui @ui do
3555
- @m1.validate
3556
- end
3557
- end
3558
- end
3559
-
3560
- def test_metadata_key_type_validation_fails
3561
- util_setup_validate
3562
-
3563
- Dir.chdir @tempdir do
3564
- @m2 = quick_gem "m", "2" do |s|
3565
- s.files = %w[lib/code.rb]
3566
- s.metadata = { 1 => "fail" }
3567
- end
3568
-
3569
- e = assert_raise Gem::InvalidSpecificationException do
3570
- @m2.validate
3571
- end
3572
-
3573
- assert_equal "metadata keys must be a String", e.message
3574
- end
3575
- end
3576
-
3577
- def test_metadata_key_size_validation_fails
3578
- util_setup_validate
3579
-
3580
- Dir.chdir @tempdir do
3581
- @m2 = quick_gem "m", "2" do |s|
3582
- s.files = %w[lib/code.rb]
3583
- s.metadata = { ("x" * 129) => "fail" }
3584
- end
3585
-
3586
- e = assert_raise Gem::InvalidSpecificationException do
3587
- @m2.validate
3588
- end
3589
-
3590
- assert_equal "metadata key is too large (129 > 128)", e.message
3591
- end
3592
- end
3593
-
3594
- def test_metadata_value_type_validation_fails
3595
- util_setup_validate
3596
-
3597
- Dir.chdir @tempdir do
3598
- @m2 = quick_gem "m", "2" do |s|
3599
- s.files = %w[lib/code.rb]
3600
- s.metadata = { "fail" => [] }
3601
- end
3602
-
3603
- e = assert_raise Gem::InvalidSpecificationException do
3604
- @m2.validate
3605
- end
3606
-
3607
- assert_equal "metadata['fail'] value must be a String", e.message
3608
- end
3609
- end
3610
-
3611
- def test_metadata_value_size_validation_fails
3612
- util_setup_validate
3613
-
3614
- Dir.chdir @tempdir do
3615
- @m2 = quick_gem "m", "2" do |s|
3616
- s.files = %w[lib/code.rb]
3617
- s.metadata = { "fail" => ("x" * 1025) }
3618
- end
3619
-
3620
- e = assert_raise Gem::InvalidSpecificationException do
3621
- @m2.validate
3622
- end
3623
-
3624
- assert_equal "metadata['fail'] value is too large (1025 > 1024)", e.message
3625
- end
3626
- end
3627
-
3628
- def test_metadata_link_validation_fails
3629
- util_setup_validate
3630
-
3631
- Dir.chdir @tempdir do
3632
- @m2 = quick_gem "m", "2" do |s|
3633
- s.files = %w[lib/code.rb]
3634
- s.metadata = { "homepage_uri" => "http:/example.com" }
3635
- end
3636
-
3637
- e = assert_raise Gem::InvalidSpecificationException do
3638
- @m2.validate
3639
- end
3640
-
3641
- assert_equal "metadata['homepage_uri'] has invalid link: \"http:/example.com\"", e.message
3642
- end
3643
- end
3644
-
3645
- def test_metadata_specs
3646
- @m1 = quick_gem "m", "1" do |s|
3647
- s.files = %w[lib/code.rb]
3648
- s.metadata = { "one" => "two", "two" => "three" }
3649
- end
3650
-
3651
- valid_ruby_spec = <<-EOF
3652
- # -*- encoding: utf-8 -*-
3653
- # stub: m 1 ruby lib
3654
-
3655
- Gem::Specification.new do |s|
3656
- s.name = "m".freeze
3657
- s.version = "1".freeze
3658
-
3659
- s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
3660
- s.metadata = { "one" => "two", "two" => "three" } if s.respond_to? :metadata=
3661
- s.require_paths = ["lib".freeze]
3662
- s.authors = ["A User".freeze]
3663
- s.date = "#{@m1.date.strftime("%Y-%m-%d")}"
3664
- s.description = "This is a test description".freeze
3665
- s.email = "example@example.com".freeze
3666
- s.files = ["lib/code.rb".freeze]
3667
- s.homepage = "http://example.com".freeze
3668
- s.rubygems_version = "#{Gem::VERSION}".freeze
3669
- s.summary = "this is a summary".freeze
3670
- end
3671
- EOF
3672
-
3673
- assert_equal @m1.to_ruby, valid_ruby_spec
3674
- end
3675
-
3676
- def test_missing_extensions_eh
3677
- pend "extensions don't quite work on jruby" if Gem.java_platform?
3678
- ext_spec
3679
-
3680
- assert @ext.missing_extensions?
3681
-
3682
- extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
3683
- FileUtils.mkdir_p File.dirname extconf_rb
3684
-
3685
- File.open extconf_rb, "w" do |f|
3686
- f.write <<-'RUBY'
3687
- File.open 'Makefile', 'w' do |f|
3688
- f.puts "clean:\n\techo clean"
3689
- f.puts "default:\n\techo built"
3690
- f.puts "install:\n\techo installed"
3691
- end
3692
- RUBY
3693
- end
3694
-
3695
- @ext.build_extensions
3696
-
3697
- refute @ext.missing_extensions?
3698
- end
3699
-
3700
- def test_missing_extensions_eh_default_gem
3701
- spec = new_default_spec "default", 1
3702
- spec.extensions << "extconf.rb"
3703
-
3704
- refute spec.missing_extensions?
3705
- end
3706
-
3707
- def test_missing_extensions_eh_none
3708
- refute @a1.missing_extensions?
3709
- end
3710
-
3711
- def test_find_all_by_full_name
3712
- pl = Gem::Platform.new "i386-linux"
3713
-
3714
- a1 = util_spec "a", "1"
3715
- a1_pre = util_spec "a", "1.0.0.pre.1"
3716
- a_1_platform = util_spec("a", "1") {|s| s.platform = pl }
3717
- a_b_1 = util_spec "a-b", "1"
3718
- a_b_1_platform = util_spec("a-b", "1") {|s| s.platform = pl }
3719
-
3720
- a_b_1_1 = util_spec "a-b-1", "1"
3721
- a_b_1_1_platform = util_spec("a-b-1", "1") {|s| s.platform = pl }
3722
-
3723
- install_specs(a1, a1_pre, a_1_platform, a_b_1, a_b_1_platform,
3724
- a_b_1_1, a_b_1_1_platform)
3725
-
3726
- assert_equal [a1], Gem::Specification.find_all_by_full_name("a-1")
3727
- assert_equal [a1_pre], Gem::Specification.find_all_by_full_name("a-1.0.0.pre.1")
3728
- assert_equal [a_1_platform], Gem::Specification.find_all_by_full_name("a-1-x86-linux")
3729
- assert_equal [a_b_1_1], Gem::Specification.find_all_by_full_name("a-b-1-1")
3730
- assert_equal [a_b_1_1_platform], Gem::Specification.find_all_by_full_name("a-b-1-1-x86-linux")
3731
-
3732
- assert_equal [], Gem::Specification.find_all_by_full_name("monkeys")
3733
- assert_equal [], Gem::Specification.find_all_by_full_name("a-1-foo")
3734
- end
3735
-
3736
- def test_find_by_name
3737
- install_specs util_spec "a"
3738
- install_specs util_spec "a", 1
3739
-
3740
- assert Gem::Specification.find_by_name "a"
3741
- assert Gem::Specification.find_by_name "a", "1"
3742
- assert Gem::Specification.find_by_name "a", ">1"
3743
-
3744
- assert_raise Gem::MissingSpecError do
3745
- Gem::Specification.find_by_name "monkeys"
3746
- end
3747
- end
3748
-
3749
- def test_find_by_name_with_only_prereleases
3750
- q = util_spec "q", "2.a"
3751
- install_specs q
3752
-
3753
- assert Gem::Specification.find_by_name "q"
3754
- end
3755
-
3756
- def test_find_by_name_prerelease
3757
- b = util_spec "b", "2.a"
3758
-
3759
- b.activate
3760
-
3761
- install_specs b
3762
-
3763
- Gem::Specification.reset
3764
-
3765
- assert Gem::Specification.find_by_name "b"
3766
-
3767
- assert_raise Gem::MissingSpecVersionError do
3768
- Gem::Specification.find_by_name "b", "1"
3769
- end
3770
-
3771
- assert Gem::Specification.find_by_name "b", ">1"
3772
- end
3773
-
3774
- def test_find_by_full_name
3775
- pl = Gem::Platform.new "x86_64-linux"
3776
-
3777
- a = util_spec "a", "1"
3778
- install_specs a
3779
-
3780
- a_pl = util_spec("a", "1") {|s| s.platform = pl }
3781
- install_specs a_pl
3782
-
3783
- assert_equal a, Gem::Specification.find_by_full_name("a-1")
3784
- assert_equal a_pl, Gem::Specification.find_by_full_name("a-1-x86_64-linux")
3785
-
3786
- assert_nil Gem::Specification.find_by_full_name("a-2")
3787
- assert_nil Gem::Specification.find_by_full_name("b-1")
3788
- assert_nil Gem::Specification.find_by_full_name("a-1-arm64-linux")
3789
- end
3790
-
3791
- def test_find_by_path
3792
- a = util_spec "foo", "1", nil, "lib/foo.rb"
3793
-
3794
- install_specs a
3795
-
3796
- assert_equal a, Gem::Specification.find_by_path("foo")
3797
- a.activate
3798
- assert_equal a, Gem::Specification.find_by_path("foo")
3799
- end
3800
-
3801
- def test_find_inactive_by_path
3802
- a = util_spec "foo", "1", nil, "lib/foo.rb"
3803
-
3804
- install_specs a
3805
-
3806
- assert_equal a, Gem::Specification.find_inactive_by_path("foo")
3807
- a.activate
3808
- assert_nil Gem::Specification.find_inactive_by_path("foo")
3809
- end
3810
-
3811
- def test_load_default_gem
3812
- Gem::Specification.reset
3813
- assert_equal [], Gem::Specification.map(&:full_name)
3814
-
3815
- default_gem_spec = new_default_spec("default", "2.0.0.0",
3816
- nil, "default/gem.rb")
3817
- spec_path = File.join(@gemhome, "specifications", "default", default_gem_spec.spec_name)
3818
- write_file(spec_path) do |file|
3819
- file.print(default_gem_spec.to_ruby)
3820
- end
3821
- Gem::Specification.reset
3822
- assert_equal ["default-2.0.0.0"], Gem::Specification.map(&:full_name)
3823
- end
3824
-
3825
- def util_setup_deps
3826
- @gem = util_spec "awesome", "1.0" do |awesome|
3827
- awesome.add_runtime_dependency "bonobo", []
3828
- awesome.add_development_dependency "monkey", []
3829
- end
3830
-
3831
- @bonobo = Gem::Dependency.new("bonobo", [])
3832
- @monkey = Gem::Dependency.new("monkey", [], :development)
3833
- end
3834
-
3835
- def util_setup_validate
3836
- Dir.chdir @tempdir do
3837
- FileUtils.mkdir_p File.join("ext", "a")
3838
- FileUtils.mkdir_p "lib"
3839
- FileUtils.mkdir_p "test"
3840
- FileUtils.mkdir_p "bin"
3841
-
3842
- begin
3843
- umask_orig = File.umask(2)
3844
- FileUtils.touch File.join("ext", "a", "extconf.rb")
3845
- FileUtils.touch File.join("lib", "code.rb")
3846
- FileUtils.touch File.join("test", "suite.rb")
3847
-
3848
- File.open "bin/exec", "w", 0o755 do |fp|
3849
- fp.puts "#!#{Gem.ruby}"
3850
- end
3851
- ensure
3852
- File.umask(umask_orig)
3853
- end
3854
- end
3855
- end
3856
- end