rubygems-update 3.4.4 → 3.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1121 -1095
  3. data/Manifest.txt +5 -5
  4. data/bundler/CHANGELOG.md +23 -0
  5. data/bundler/lib/bundler/build_metadata.rb +2 -2
  6. data/bundler/lib/bundler/cli/binstubs.rb +5 -1
  7. data/bundler/lib/bundler/definition.rb +3 -3
  8. data/bundler/lib/bundler/inline.rb +6 -8
  9. data/bundler/lib/bundler/installer/standalone.rb +11 -7
  10. data/bundler/lib/bundler/man/bundle-exec.1 +4 -4
  11. data/bundler/lib/bundler/man/bundle-exec.1.ronn +5 -5
  12. data/bundler/lib/bundler/resolver/base.rb +11 -4
  13. data/bundler/lib/bundler/resolver.rb +2 -11
  14. data/bundler/lib/bundler/rubygems_integration.rb +8 -4
  15. data/bundler/lib/bundler/source/rubygems.rb +1 -1
  16. data/bundler/lib/bundler/version.rb +1 -1
  17. data/lib/rubygems/core_ext/kernel_require.rb +113 -109
  18. data/lib/rubygems/ext/builder.rb +1 -2
  19. data/lib/rubygems/ext/cargo_builder.rb +129 -89
  20. data/lib/rubygems/specification_policy.rb +1 -1
  21. data/lib/rubygems.rb +11 -1
  22. data/rubygems-update.gemspec +1 -1
  23. data/test/rubygems/bundler_test_gem.rb +419 -0
  24. data/test/rubygems/test_gem.rb +0 -412
  25. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec +2 -4
  26. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/{Cargo.lock → ext/custom_name_lib/Cargo.lock} +0 -0
  27. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/{Cargo.toml → ext/custom_name_lib/Cargo.toml} +0 -0
  28. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/{src → ext/custom_name_lib/src}/lib.rs +1 -1
  29. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/lib/custom_name.rb +1 -0
  30. data/test/rubygems/test_gem_ext_cargo_builder.rb +9 -16
  31. data/test/rubygems/test_gem_ext_cargo_builder_unit.rb +5 -10
  32. data/test/rubygems/test_require.rb +1 -2
  33. metadata +8 -8
  34. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb +0 -21
  35. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb +0 -21
@@ -0,0 +1,419 @@
1
+ require_relative "helper"
2
+
3
+ class TestBundlerGem < Gem::TestCase
4
+ PROJECT_DIR = File.expand_path("../..", __dir__).tap(&Gem::UNTAINT)
5
+
6
+ def test_self_use_gemdeps
7
+ with_local_bundler_at(Gem.dir) do
8
+ with_rubygems_gemdeps("-") do
9
+ FileUtils.mkdir_p "detect/a/b"
10
+ FileUtils.mkdir_p "detect/a/Isolate"
11
+
12
+ FileUtils.touch "detect/Isolate"
13
+
14
+ begin
15
+ Dir.chdir "detect/a/b"
16
+
17
+ Gem.use_gemdeps
18
+
19
+ assert_equal add_bundler_full_name([]), loaded_spec_names
20
+ ensure
21
+ Dir.chdir @tempdir
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ def test_self_find_files_with_gemfile
28
+ with_local_bundler_at(Gem.dir) do
29
+ cwd = File.expand_path("test/rubygems", PROJECT_DIR)
30
+ actual_load_path = $LOAD_PATH.unshift(cwd).dup
31
+
32
+ discover_path = File.join "lib", "sff", "discover.rb"
33
+
34
+ foo1, _ = %w[1 2].map do |version|
35
+ spec = quick_gem "sff", version do |s|
36
+ s.files << discover_path
37
+ end
38
+
39
+ write_file(File.join "gems", spec.full_name, discover_path) do |fp|
40
+ fp.puts "# #{spec.full_name}"
41
+ end
42
+
43
+ spec
44
+ end
45
+ Gem.refresh
46
+
47
+ write_file(File.join Dir.pwd, "Gemfile") do |fp|
48
+ fp.puts "source 'https://rubygems.org'"
49
+ fp.puts "gem '#{foo1.name}', '#{foo1.version}'"
50
+ end
51
+ Gem.use_gemdeps(File.join Dir.pwd, "Gemfile")
52
+
53
+ expected = [
54
+ File.expand_path("test/rubygems/sff/discover.rb", PROJECT_DIR),
55
+ File.join(foo1.full_gem_path, discover_path),
56
+ ].sort
57
+
58
+ assert_equal expected, Gem.find_files("sff/discover").sort
59
+ assert_equal expected, Gem.find_files("sff/**.rb").sort, "[ruby-core:31730]"
60
+ assert_equal cwd, actual_load_path.shift
61
+ end
62
+ end
63
+
64
+ def test_auto_activation_of_specific_gemdeps_file
65
+ with_local_bundler_at(Gem.dir) do
66
+ a = util_spec "a", "1", nil, "lib/a.rb"
67
+ b = util_spec "b", "1", nil, "lib/b.rb"
68
+ c = util_spec "c", "1", nil, "lib/c.rb"
69
+
70
+ install_specs a, b, c
71
+
72
+ path = File.join @tempdir, "gem.deps.rb"
73
+
74
+ File.open path, "w" do |f|
75
+ f.puts "gem 'a'"
76
+ f.puts "gem 'b'"
77
+ f.puts "gem 'c'"
78
+ end
79
+
80
+ with_rubygems_gemdeps(path) do
81
+ Gem.use_gemdeps
82
+
83
+ assert_equal add_bundler_full_name(%W[a-1 b-1 c-1]), loaded_spec_names
84
+ end
85
+ end
86
+ end
87
+
88
+ def test_auto_activation_of_used_gemdeps_file
89
+ with_local_bundler_at(Gem.dir) do
90
+ a = util_spec "a", "1", nil, "lib/a.rb"
91
+ b = util_spec "b", "1", nil, "lib/b.rb"
92
+ c = util_spec "c", "1", nil, "lib/c.rb"
93
+
94
+ install_specs a, b, c
95
+
96
+ path = File.join @tempdir, "gem.deps.rb"
97
+
98
+ File.open path, "w" do |f|
99
+ f.puts "gem 'a'"
100
+ f.puts "gem 'b'"
101
+ f.puts "gem 'c'"
102
+ end
103
+
104
+ with_rubygems_gemdeps("-") do
105
+ expected_specs = [a, b, util_spec("bundler", Bundler::VERSION), c].compact.map(&:full_name)
106
+
107
+ Gem.use_gemdeps
108
+
109
+ assert_equal expected_specs, loaded_spec_names
110
+ end
111
+ end
112
+ end
113
+
114
+ def test_looks_for_gemdeps_files_automatically_from_binstubs
115
+ path = File.join(@tempdir, "gd-tmp")
116
+
117
+ with_local_bundler_at(path) do
118
+ a = util_spec "a", "1" do |s|
119
+ s.executables = %w[foo]
120
+ s.bindir = "exe"
121
+ end
122
+
123
+ write_file File.join(@tempdir, "exe", "foo") do |fp|
124
+ fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
125
+ end
126
+
127
+ b = util_spec "b", "1", nil, "lib/b.rb"
128
+ c = util_spec "c", "1", nil, "lib/c.rb"
129
+
130
+ install_specs a, b, c
131
+
132
+ install_gem a, :install_dir => path
133
+ install_gem b, :install_dir => path
134
+ install_gem c, :install_dir => path
135
+
136
+ ENV["GEM_PATH"] = path
137
+
138
+ with_rubygems_gemdeps("-") do
139
+ new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
140
+ new_RUBYOPT = "-I#{rubygems_path} -I#{bundler_path}"
141
+
142
+ path = File.join @tempdir, "gem.deps.rb"
143
+
144
+ File.open path, "w" do |f|
145
+ f.puts "gem 'a'"
146
+ end
147
+ out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
148
+ IO.popen("foo", &:read).split(/\n/)
149
+ end
150
+
151
+ File.open path, "a" do |f|
152
+ f.puts "gem 'b'"
153
+ f.puts "gem 'c'"
154
+ end
155
+ out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
156
+ IO.popen("foo", &:read).split(/\n/)
157
+ end
158
+
159
+ assert_equal ["b-1", "c-1"], out - out0
160
+ end
161
+ end
162
+ end
163
+
164
+ def test_looks_for_gemdeps_files_automatically_from_binstubs_in_parent_dir
165
+ path = File.join(@tempdir, "gd-tmp")
166
+
167
+ with_local_bundler_at(path) do
168
+ pend "IO.popen has issues on JRuby when passed :chdir" if Gem.java_platform?
169
+
170
+ a = util_spec "a", "1" do |s|
171
+ s.executables = %w[foo]
172
+ s.bindir = "exe"
173
+ end
174
+
175
+ write_file File.join(@tempdir, "exe", "foo") do |fp|
176
+ fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
177
+ end
178
+
179
+ b = util_spec "b", "1", nil, "lib/b.rb"
180
+ c = util_spec "c", "1", nil, "lib/c.rb"
181
+
182
+ install_specs a, b, c
183
+
184
+ install_gem a, :install_dir => path
185
+ install_gem b, :install_dir => path
186
+ install_gem c, :install_dir => path
187
+
188
+ ENV["GEM_PATH"] = path
189
+
190
+ with_rubygems_gemdeps("-") do
191
+ Dir.mkdir "sub1"
192
+
193
+ new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
194
+ new_RUBYOPT = "-I#{rubygems_path} -I#{bundler_path}"
195
+
196
+ path = File.join @tempdir, "gem.deps.rb"
197
+
198
+ File.open path, "w" do |f|
199
+ f.puts "gem 'a'"
200
+ end
201
+ out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
202
+ IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
203
+ end
204
+
205
+ File.open path, "a" do |f|
206
+ f.puts "gem 'b'"
207
+ f.puts "gem 'c'"
208
+ end
209
+ out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
210
+ IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
211
+ end
212
+
213
+ Dir.rmdir "sub1"
214
+
215
+ assert_equal ["b-1", "c-1"], out - out0
216
+ end
217
+ end
218
+ end
219
+
220
+ def test_use_gemdeps
221
+ with_local_bundler_at(Gem.dir) do
222
+ gem_deps_file = "gem.deps.rb".tap(&Gem::UNTAINT)
223
+ spec = util_spec "a", 1
224
+ install_specs spec
225
+
226
+ spec = Gem::Specification.find {|s| s == spec }
227
+ refute spec.activated?
228
+
229
+ File.open gem_deps_file, "w" do |io|
230
+ io.write 'gem "a"'
231
+ end
232
+
233
+ assert_nil Gem.gemdeps
234
+
235
+ Gem.use_gemdeps gem_deps_file
236
+
237
+ assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
238
+ refute_nil Gem.gemdeps
239
+ end
240
+ end
241
+
242
+ def test_use_gemdeps_ENV
243
+ with_local_bundler_at(Gem.dir) do
244
+ with_rubygems_gemdeps(nil) do
245
+ spec = util_spec "a", 1
246
+
247
+ refute spec.activated?
248
+
249
+ File.open "gem.deps.rb", "w" do |io|
250
+ io.write 'gem "a"'
251
+ end
252
+
253
+ Gem.use_gemdeps
254
+
255
+ refute spec.activated?
256
+ end
257
+ end
258
+ end
259
+
260
+ def test_use_gemdeps_argument_missing
261
+ with_local_bundler_at(Gem.dir) do
262
+ e = assert_raise ArgumentError do
263
+ Gem.use_gemdeps "gem.deps.rb"
264
+ end
265
+
266
+ assert_equal "Unable to find gem dependencies file at gem.deps.rb",
267
+ e.message
268
+ end
269
+ end
270
+
271
+ def test_use_gemdeps_argument_missing_match_ENV
272
+ with_local_bundler_at(Gem.dir) do
273
+ with_rubygems_gemdeps("gem.deps.rb") do
274
+ e = assert_raise ArgumentError do
275
+ Gem.use_gemdeps "gem.deps.rb"
276
+ end
277
+
278
+ assert_equal "Unable to find gem dependencies file at gem.deps.rb",
279
+ e.message
280
+ end
281
+ end
282
+ end
283
+
284
+ def test_use_gemdeps_automatic
285
+ with_local_bundler_at(Gem.dir) do
286
+ with_rubygems_gemdeps("-") do
287
+ spec = util_spec "a", 1
288
+ install_specs spec
289
+ spec = Gem::Specification.find {|s| s == spec }
290
+
291
+ refute spec.activated?
292
+
293
+ File.open "Gemfile", "w" do |io|
294
+ io.write 'gem "a"'
295
+ end
296
+
297
+ Gem.use_gemdeps
298
+
299
+ assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
300
+ end
301
+ end
302
+ end
303
+
304
+ def test_use_gemdeps_automatic_missing
305
+ with_local_bundler_at(Gem.dir) do
306
+ with_rubygems_gemdeps("-") do
307
+ Gem.use_gemdeps
308
+
309
+ assert true # count
310
+ end
311
+ end
312
+ end
313
+
314
+ def test_use_gemdeps_disabled
315
+ with_local_bundler_at(Gem.dir) do
316
+ with_rubygems_gemdeps("") do
317
+ spec = util_spec "a", 1
318
+
319
+ refute spec.activated?
320
+
321
+ File.open "gem.deps.rb", "w" do |io|
322
+ io.write 'gem "a"'
323
+ end
324
+
325
+ Gem.use_gemdeps
326
+
327
+ refute spec.activated?
328
+ end
329
+ end
330
+ end
331
+
332
+ def test_use_gemdeps_missing_gem
333
+ with_local_bundler_at(Gem.dir) do
334
+ with_rubygems_gemdeps("x") do
335
+ File.open "x", "w" do |io|
336
+ io.write 'gem "a"'
337
+ end
338
+
339
+ expected = <<-EXPECTED
340
+ Could not find gem 'a' in locally installed gems.
341
+ You may need to `bundle install` to install missing gems
342
+
343
+ EXPECTED
344
+
345
+ Gem::Deprecate.skip_during do
346
+ actual_stdout, actual_stderr = capture_output do
347
+ Gem.use_gemdeps
348
+ end
349
+ assert_empty actual_stdout
350
+ assert_equal(expected, actual_stderr)
351
+ end
352
+ end
353
+ end
354
+ end
355
+
356
+ def test_use_gemdeps_specific
357
+ with_local_bundler_at(Gem.dir) do
358
+ with_rubygems_gemdeps("x") do
359
+ spec = util_spec "a", 1
360
+ install_specs spec
361
+
362
+ spec = Gem::Specification.find {|s| s == spec }
363
+ refute spec.activated?
364
+
365
+ File.open "x", "w" do |io|
366
+ io.write 'gem "a"'
367
+ end
368
+
369
+ Gem.use_gemdeps
370
+
371
+ assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
372
+ end
373
+ end
374
+ end
375
+
376
+ private
377
+
378
+ def add_bundler_full_name(names)
379
+ names << "bundler-#{Bundler::VERSION}".freeze
380
+ names.sort!
381
+ names
382
+ end
383
+
384
+ def with_path_and_rubyopt(path_value, rubyopt_value)
385
+ path, ENV["PATH"] = ENV["PATH"], path_value
386
+ rubyopt, ENV["RUBYOPT"] = ENV["RUBYOPT"], rubyopt_value
387
+
388
+ yield
389
+ ensure
390
+ ENV["PATH"] = path
391
+ ENV["RUBYOPT"] = rubyopt
392
+ end
393
+
394
+ def with_rubygems_gemdeps(value)
395
+ rubygems_gemdeps, ENV["RUBYGEMS_GEMDEPS"] = ENV["RUBYGEMS_GEMDEPS"], value
396
+
397
+ yield
398
+ ensure
399
+ ENV["RUBYGEMS_GEMDEPS"] = rubygems_gemdeps
400
+ end
401
+
402
+ def with_local_bundler_at(path)
403
+ require "bundler"
404
+
405
+ # If bundler gemspec exists, pretend it's installed
406
+ bundler_gemspec = File.expand_path("../../bundler/bundler.gemspec", __dir__)
407
+ if File.exist?(bundler_gemspec)
408
+ target_gemspec_location = "#{path}/specifications/bundler-#{Bundler::VERSION}.gemspec"
409
+
410
+ FileUtils.mkdir_p File.dirname(target_gemspec_location)
411
+
412
+ File.write target_gemspec_location, Gem::Specification.load(bundler_gemspec).to_ruby_for_cache
413
+ end
414
+
415
+ yield
416
+ ensure
417
+ Bundler.reset!
418
+ end
419
+ end