summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2023-02-01 12:05:19 +0900
committerGitHub <noreply@github.com>2023-02-01 12:05:19 +0900
commitf4e6e78410136100ef5f285136a66df8d6004a61 (patch)
treeed1f754dbe1c4b37e3736265a99122e7a12c3b5b /test
parent40e0b1e123503805c16a2a9aafae0a5c302c20d1 (diff)
Merge RubyGems 3.4.6 and Bundler 2.4.6 (#7214)
Merge RubyGems-3.4.6 and Bundler-2.4.6
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/bundler_test_gem.rb419
-rw-r--r--test/rubygems/test_gem.rb412
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder.rb25
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb21
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec6
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.lock (renamed from test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.lock)0
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.toml (renamed from test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.toml)0
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/src/lib.rs (renamed from test/rubygems/test_gem_ext_cargo_builder/custom_name/src/lib.rs)2
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/custom_name/lib/custom_name.rb1
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb21
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder_unit.rb15
11 files changed, 437 insertions, 485 deletions
diff --git a/test/rubygems/bundler_test_gem.rb b/test/rubygems/bundler_test_gem.rb
new file mode 100644
index 0000000000..16a02f343b
--- /dev/null
+++ b/test/rubygems/bundler_test_gem.rb
@@ -0,0 +1,419 @@
+require_relative "helper"
+
+class TestBundlerGem < Gem::TestCase
+ PROJECT_DIR = File.expand_path("../..", __dir__).tap(&Gem::UNTAINT)
+
+ def test_self_use_gemdeps
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps("-") do
+ FileUtils.mkdir_p "detect/a/b"
+ FileUtils.mkdir_p "detect/a/Isolate"
+
+ FileUtils.touch "detect/Isolate"
+
+ begin
+ Dir.chdir "detect/a/b"
+
+ Gem.use_gemdeps
+
+ assert_equal add_bundler_full_name([]), loaded_spec_names
+ ensure
+ Dir.chdir @tempdir
+ end
+ end
+ end
+ end
+
+ def test_self_find_files_with_gemfile
+ with_local_bundler_at(Gem.dir) do
+ cwd = File.expand_path("test/rubygems", PROJECT_DIR)
+ actual_load_path = $LOAD_PATH.unshift(cwd).dup
+
+ discover_path = File.join "lib", "sff", "discover.rb"
+
+ foo1, _ = %w[1 2].map do |version|
+ spec = quick_gem "sff", version do |s|
+ s.files << discover_path
+ end
+
+ write_file(File.join "gems", spec.full_name, discover_path) do |fp|
+ fp.puts "# #{spec.full_name}"
+ end
+
+ spec
+ end
+ Gem.refresh
+
+ write_file(File.join Dir.pwd, "Gemfile") do |fp|
+ fp.puts "source 'https://rubygems.org'"
+ fp.puts "gem '#{foo1.name}', '#{foo1.version}'"
+ end
+ Gem.use_gemdeps(File.join Dir.pwd, "Gemfile")
+
+ expected = [
+ File.expand_path("test/rubygems/sff/discover.rb", PROJECT_DIR),
+ File.join(foo1.full_gem_path, discover_path),
+ ].sort
+
+ assert_equal expected, Gem.find_files("sff/discover").sort
+ assert_equal expected, Gem.find_files("sff/**.rb").sort, "[ruby-core:31730]"
+ assert_equal cwd, actual_load_path.shift
+ end
+ end
+
+ def test_auto_activation_of_specific_gemdeps_file
+ with_local_bundler_at(Gem.dir) do
+ a = util_spec "a", "1", nil, "lib/a.rb"
+ b = util_spec "b", "1", nil, "lib/b.rb"
+ c = util_spec "c", "1", nil, "lib/c.rb"
+
+ install_specs a, b, c
+
+ path = File.join @tempdir, "gem.deps.rb"
+
+ File.open path, "w" do |f|
+ f.puts "gem 'a'"
+ f.puts "gem 'b'"
+ f.puts "gem 'c'"
+ end
+
+ with_rubygems_gemdeps(path) do
+ Gem.use_gemdeps
+
+ assert_equal add_bundler_full_name(%W[a-1 b-1 c-1]), loaded_spec_names
+ end
+ end
+ end
+
+ def test_auto_activation_of_used_gemdeps_file
+ with_local_bundler_at(Gem.dir) do
+ a = util_spec "a", "1", nil, "lib/a.rb"
+ b = util_spec "b", "1", nil, "lib/b.rb"
+ c = util_spec "c", "1", nil, "lib/c.rb"
+
+ install_specs a, b, c
+
+ path = File.join @tempdir, "gem.deps.rb"
+
+ File.open path, "w" do |f|
+ f.puts "gem 'a'"
+ f.puts "gem 'b'"
+ f.puts "gem 'c'"
+ end
+
+ with_rubygems_gemdeps("-") do
+ expected_specs = [a, b, util_spec("bundler", Bundler::VERSION), c].compact.map(&:full_name)
+
+ Gem.use_gemdeps
+
+ assert_equal expected_specs, loaded_spec_names
+ end
+ end
+ end
+
+ def test_looks_for_gemdeps_files_automatically_from_binstubs
+ path = File.join(@tempdir, "gd-tmp")
+
+ with_local_bundler_at(path) do
+ a = util_spec "a", "1" do |s|
+ s.executables = %w[foo]
+ s.bindir = "exe"
+ end
+
+ write_file File.join(@tempdir, "exe", "foo") do |fp|
+ fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
+ end
+
+ b = util_spec "b", "1", nil, "lib/b.rb"
+ c = util_spec "c", "1", nil, "lib/c.rb"
+
+ install_specs a, b, c
+
+ install_gem a, :install_dir => path
+ install_gem b, :install_dir => path
+ install_gem c, :install_dir => path
+
+ ENV["GEM_PATH"] = path
+
+ with_rubygems_gemdeps("-") do
+ new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
+ new_RUBYOPT = "-I#{rubygems_path} -I#{bundler_path}"
+
+ path = File.join @tempdir, "gem.deps.rb"
+
+ File.open path, "w" do |f|
+ f.puts "gem 'a'"
+ end
+ out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+ IO.popen("foo", &:read).split(/\n/)
+ end
+
+ File.open path, "a" do |f|
+ f.puts "gem 'b'"
+ f.puts "gem 'c'"
+ end
+ out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+ IO.popen("foo", &:read).split(/\n/)
+ end
+
+ assert_equal ["b-1", "c-1"], out - out0
+ end
+ end
+ end
+
+ def test_looks_for_gemdeps_files_automatically_from_binstubs_in_parent_dir
+ path = File.join(@tempdir, "gd-tmp")
+
+ with_local_bundler_at(path) do
+ pend "IO.popen has issues on JRuby when passed :chdir" if Gem.java_platform?
+
+ a = util_spec "a", "1" do |s|
+ s.executables = %w[foo]
+ s.bindir = "exe"
+ end
+
+ write_file File.join(@tempdir, "exe", "foo") do |fp|
+ fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
+ end
+
+ b = util_spec "b", "1", nil, "lib/b.rb"
+ c = util_spec "c", "1", nil, "lib/c.rb"
+
+ install_specs a, b, c
+
+ install_gem a, :install_dir => path
+ install_gem b, :install_dir => path
+ install_gem c, :install_dir => path
+
+ ENV["GEM_PATH"] = path
+
+ with_rubygems_gemdeps("-") do
+ Dir.mkdir "sub1"
+
+ new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
+ new_RUBYOPT = "-I#{rubygems_path} -I#{bundler_path}"
+
+ path = File.join @tempdir, "gem.deps.rb"
+
+ File.open path, "w" do |f|
+ f.puts "gem 'a'"
+ end
+ out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+ IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
+ end
+
+ File.open path, "a" do |f|
+ f.puts "gem 'b'"
+ f.puts "gem 'c'"
+ end
+ out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+ IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
+ end
+
+ Dir.rmdir "sub1"
+
+ assert_equal ["b-1", "c-1"], out - out0
+ end
+ end
+ end
+
+ def test_use_gemdeps
+ with_local_bundler_at(Gem.dir) do
+ gem_deps_file = "gem.deps.rb".tap(&Gem::UNTAINT)
+ spec = util_spec "a", 1
+ install_specs spec
+
+ spec = Gem::Specification.find {|s| s == spec }
+ refute spec.activated?
+
+ File.open gem_deps_file, "w" do |io|
+ io.write 'gem "a"'
+ end
+
+ assert_nil Gem.gemdeps
+
+ Gem.use_gemdeps gem_deps_file
+
+ assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
+ refute_nil Gem.gemdeps
+ end
+ end
+
+ def test_use_gemdeps_ENV
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps(nil) do
+ spec = util_spec "a", 1
+
+ refute spec.activated?
+
+ File.open "gem.deps.rb", "w" do |io|
+ io.write 'gem "a"'
+ end
+
+ Gem.use_gemdeps
+
+ refute spec.activated?
+ end
+ end
+ end
+
+ def test_use_gemdeps_argument_missing
+ with_local_bundler_at(Gem.dir) do
+ e = assert_raise ArgumentError do
+ Gem.use_gemdeps "gem.deps.rb"
+ end
+
+ assert_equal "Unable to find gem dependencies file at gem.deps.rb",
+ e.message
+ end
+ end
+
+ def test_use_gemdeps_argument_missing_match_ENV
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps("gem.deps.rb") do
+ e = assert_raise ArgumentError do
+ Gem.use_gemdeps "gem.deps.rb"
+ end
+
+ assert_equal "Unable to find gem dependencies file at gem.deps.rb",
+ e.message
+ end
+ end
+ end
+
+ def test_use_gemdeps_automatic
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps("-") do
+ spec = util_spec "a", 1
+ install_specs spec
+ spec = Gem::Specification.find {|s| s == spec }
+
+ refute spec.activated?
+
+ File.open "Gemfile", "w" do |io|
+ io.write 'gem "a"'
+ end
+
+ Gem.use_gemdeps
+
+ assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
+ end
+ end
+ end
+
+ def test_use_gemdeps_automatic_missing
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps("-") do
+ Gem.use_gemdeps
+
+ assert true # count
+ end
+ end
+ end
+
+ def test_use_gemdeps_disabled
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps("") do
+ spec = util_spec "a", 1
+
+ refute spec.activated?
+
+ File.open "gem.deps.rb", "w" do |io|
+ io.write 'gem "a"'
+ end
+
+ Gem.use_gemdeps
+
+ refute spec.activated?
+ end
+ end
+ end
+
+ def test_use_gemdeps_missing_gem
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps("x") do
+ File.open "x", "w" do |io|
+ io.write 'gem "a"'
+ end
+
+ expected = <<-EXPECTED
+Could not find gem 'a' in locally installed gems.
+You may need to `bundle install` to install missing gems
+
+ EXPECTED
+
+ Gem::Deprecate.skip_during do
+ actual_stdout, actual_stderr = capture_output do
+ Gem.use_gemdeps
+ end
+ assert_empty actual_stdout
+ assert_equal(expected, actual_stderr)
+ end
+ end
+ end
+ end
+
+ def test_use_gemdeps_specific
+ with_local_bundler_at(Gem.dir) do
+ with_rubygems_gemdeps("x") do
+ spec = util_spec "a", 1
+ install_specs spec
+
+ spec = Gem::Specification.find {|s| s == spec }
+ refute spec.activated?
+
+ File.open "x", "w" do |io|
+ io.write 'gem "a"'
+ end
+
+ Gem.use_gemdeps
+
+ assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
+ end
+ end
+ end
+
+ private
+
+ def add_bundler_full_name(names)
+ names << "bundler-#{Bundler::VERSION}".freeze
+ names.sort!
+ names
+ end
+
+ def with_path_and_rubyopt(path_value, rubyopt_value)
+ path, ENV["PATH"] = ENV["PATH"], path_value
+ rubyopt, ENV["RUBYOPT"] = ENV["RUBYOPT"], rubyopt_value
+
+ yield
+ ensure
+ ENV["PATH"] = path
+ ENV["RUBYOPT"] = rubyopt
+ end
+
+ def with_rubygems_gemdeps(value)
+ rubygems_gemdeps, ENV["RUBYGEMS_GEMDEPS"] = ENV["RUBYGEMS_GEMDEPS"], value
+
+ yield
+ ensure
+ ENV["RUBYGEMS_GEMDEPS"] = rubygems_gemdeps
+ end
+
+ def with_local_bundler_at(path)
+ require "bundler"
+
+ # If bundler gemspec exists, pretend it's installed
+ bundler_gemspec = File.expand_path("../../bundler/bundler.gemspec", __dir__)
+ if File.exist?(bundler_gemspec)
+ target_gemspec_location = "#{path}/specifications/bundler-#{Bundler::VERSION}.gemspec"
+
+ FileUtils.mkdir_p File.dirname(target_gemspec_location)
+
+ File.write target_gemspec_location, Gem::Specification.load(bundler_gemspec).to_ruby_for_cache
+ end
+
+ yield
+ ensure
+ Bundler.reset!
+ end
+end
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index ea8aebb785..b572208e6b 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -616,27 +616,6 @@ class TestGem < Gem::TestCase
assert_equal %w[https://rubygems.org/], Gem.default_sources
end
- def test_self_use_gemdeps
- with_local_bundler_at(Gem.dir) do
- with_rubygems_gemdeps("-") do
- FileUtils.mkdir_p "detect/a/b"
- FileUtils.mkdir_p "detect/a/Isolate"
-
- FileUtils.touch "detect/Isolate"
-
- begin
- Dir.chdir "detect/a/b"
-
- Gem.use_gemdeps
-
- assert_equal add_bundler_full_name([]), loaded_spec_names
- ensure
- Dir.chdir @tempdir
- end
- end
- end
- end
-
def test_self_dir
assert_equal @gemhome, Gem.dir
end
@@ -776,43 +755,6 @@ class TestGem < Gem::TestCase
assert_equal cwd, $LOAD_PATH.shift
end
- def test_self_find_files_with_gemfile
- with_local_bundler_at(Gem.dir) do
- cwd = File.expand_path("test/rubygems", PROJECT_DIR)
- actual_load_path = $LOAD_PATH.unshift(cwd).dup
-
- discover_path = File.join "lib", "sff", "discover.rb"
-
- foo1, _ = %w[1 2].map do |version|
- spec = quick_gem "sff", version do |s|
- s.files << discover_path
- end
-
- write_file(File.join "gems", spec.full_name, discover_path) do |fp|
- fp.puts "# #{spec.full_name}"
- end
-
- spec
- end
- Gem.refresh
-
- write_file(File.join Dir.pwd, "Gemfile") do |fp|
- fp.puts "source 'https://rubygems.org'"
- fp.puts "gem '#{foo1.name}', '#{foo1.version}'"
- end
- Gem.use_gemdeps(File.join Dir.pwd, "Gemfile")
-
- expected = [
- File.expand_path("test/rubygems/sff/discover.rb", PROJECT_DIR),
- File.join(foo1.full_gem_path, discover_path),
- ].sort
-
- assert_equal expected, Gem.find_files("sff/discover").sort
- assert_equal expected, Gem.find_files("sff/**.rb").sort, "[ruby-core:31730]"
- assert_equal cwd, actual_load_path.shift
- end
- end
-
def test_self_find_latest_files
cwd = File.expand_path("test/rubygems", PROJECT_DIR)
$LOAD_PATH.unshift cwd
@@ -1640,168 +1582,6 @@ class TestGem < Gem::TestCase
"Wrong spec selected"
end
- def test_auto_activation_of_specific_gemdeps_file
- with_local_bundler_at(Gem.dir) do
- a = util_spec "a", "1", nil, "lib/a.rb"
- b = util_spec "b", "1", nil, "lib/b.rb"
- c = util_spec "c", "1", nil, "lib/c.rb"
-
- install_specs a, b, c
-
- path = File.join @tempdir, "gem.deps.rb"
-
- File.open path, "w" do |f|
- f.puts "gem 'a'"
- f.puts "gem 'b'"
- f.puts "gem 'c'"
- end
-
- with_rubygems_gemdeps(path) do
- Gem.use_gemdeps
-
- assert_equal add_bundler_full_name(%W[a-1 b-1 c-1]), loaded_spec_names
- end
- end
- end
-
- def test_auto_activation_of_used_gemdeps_file
- with_local_bundler_at(Gem.dir) do
- a = util_spec "a", "1", nil, "lib/a.rb"
- b = util_spec "b", "1", nil, "lib/b.rb"
- c = util_spec "c", "1", nil, "lib/c.rb"
-
- install_specs a, b, c
-
- path = File.join @tempdir, "gem.deps.rb"
-
- File.open path, "w" do |f|
- f.puts "gem 'a'"
- f.puts "gem 'b'"
- f.puts "gem 'c'"
- end
-
- with_rubygems_gemdeps("-") do
- expected_specs = [a, b, util_spec("bundler", Bundler::VERSION), c].compact.map(&:full_name)
-
- Gem.use_gemdeps
-
- assert_equal expected_specs, loaded_spec_names
- end
- end
- end
-
- def add_bundler_full_name(names)
- names << "bundler-#{Bundler::VERSION}".freeze
- names.sort!
- names
- end
-
- def test_looks_for_gemdeps_files_automatically_from_binstubs
- path = File.join(@tempdir, "gd-tmp")
-
- with_local_bundler_at(path) do
- a = util_spec "a", "1" do |s|
- s.executables = %w[foo]
- s.bindir = "exe"
- end
-
- write_file File.join(@tempdir, "exe", "foo") do |fp|
- fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
- end
-
- b = util_spec "b", "1", nil, "lib/b.rb"
- c = util_spec "c", "1", nil, "lib/c.rb"
-
- install_specs a, b, c
-
- install_gem a, :install_dir => path
- install_gem b, :install_dir => path
- install_gem c, :install_dir => path
-
- ENV["GEM_PATH"] = path
-
- with_rubygems_gemdeps("-") do
- new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
- new_RUBYOPT = "-I#{rubygems_path} -I#{bundler_path}"
-
- path = File.join @tempdir, "gem.deps.rb"
-
- File.open path, "w" do |f|
- f.puts "gem 'a'"
- end
- out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
- IO.popen("foo", &:read).split(/\n/)
- end
-
- File.open path, "a" do |f|
- f.puts "gem 'b'"
- f.puts "gem 'c'"
- end
- out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
- IO.popen("foo", &:read).split(/\n/)
- end
-
- assert_equal ["b-1", "c-1"], out - out0
- end
- end
- end
-
- def test_looks_for_gemdeps_files_automatically_from_binstubs_in_parent_dir
- path = File.join(@tempdir, "gd-tmp")
-
- with_local_bundler_at(path) do
- pend "IO.popen has issues on JRuby when passed :chdir" if Gem.java_platform?
-
- a = util_spec "a", "1" do |s|
- s.executables = %w[foo]
- s.bindir = "exe"
- end
-
- write_file File.join(@tempdir, "exe", "foo") do |fp|
- fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort"
- end
-
- b = util_spec "b", "1", nil, "lib/b.rb"
- c = util_spec "c", "1", nil, "lib/c.rb"
-
- install_specs a, b, c
-
- install_gem a, :install_dir => path
- install_gem b, :install_dir => path
- install_gem c, :install_dir => path
-
- ENV["GEM_PATH"] = path
-
- with_rubygems_gemdeps("-") do
- Dir.mkdir "sub1"
-
- new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
- new_RUBYOPT = "-I#{rubygems_path} -I#{bundler_path}"
-
- path = File.join @tempdir, "gem.deps.rb"
-
- File.open path, "w" do |f|
- f.puts "gem 'a'"
- end
- out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
- IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
- end
-
- File.open path, "a" do |f|
- f.puts "gem 'b'"
- f.puts "gem 'c'"
- end
- out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
- IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
- end
-
- Dir.rmdir "sub1"
-
- assert_equal ["b-1", "c-1"], out - out0
- end
- end
- end
-
def test_register_default_spec
Gem.clear_default_specs
@@ -1842,162 +1622,6 @@ class TestGem < Gem::TestCase
assert_equal old_style, Gem.find_unresolved_default_spec("foo.rb")
end
- def test_use_gemdeps
- with_local_bundler_at(Gem.dir) do
- gem_deps_file = "gem.deps.rb".tap(&Gem::UNTAINT)
- spec = util_spec "a", 1
- install_specs spec
-
- spec = Gem::Specification.find {|s| s == spec }
- refute spec.activated?
-
- File.open gem_deps_file, "w" do |io|
- io.write 'gem "a"'
- end
-
- assert_nil Gem.gemdeps
-
- Gem.use_gemdeps gem_deps_file
-
- assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
- refute_nil Gem.gemdeps
- end
- end
-
- def test_use_gemdeps_ENV
- with_local_bundler_at(Gem.dir) do
- with_rubygems_gemdeps(nil) do
- spec = util_spec "a", 1
-
- refute spec.activated?
-
- File.open "gem.deps.rb", "w" do |io|
- io.write 'gem "a"'
- end
-
- Gem.use_gemdeps
-
- refute spec.activated?
- end
- end
- end
-
- def test_use_gemdeps_argument_missing
- with_local_bundler_at(Gem.dir) do
- e = assert_raise ArgumentError do
- Gem.use_gemdeps "gem.deps.rb"
- end
-
- assert_equal "Unable to find gem dependencies file at gem.deps.rb",
- e.message
- end
- end
-
- def test_use_gemdeps_argument_missing_match_ENV
- with_local_bundler_at(Gem.dir) do
- with_rubygems_gemdeps("gem.deps.rb") do
- e = assert_raise ArgumentError do
- Gem.use_gemdeps "gem.deps.rb"
- end
-
- assert_equal "Unable to find gem dependencies file at gem.deps.rb",
- e.message
- end
- end
- end
-
- def test_use_gemdeps_automatic
- with_local_bundler_at(Gem.dir) do
- with_rubygems_gemdeps("-") do
- spec = util_spec "a", 1
- install_specs spec
- spec = Gem::Specification.find {|s| s == spec }
-
- refute spec.activated?
-
- File.open "Gemfile", "w" do |io|
- io.write 'gem "a"'
- end
-
- Gem.use_gemdeps
-
- assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
- end
- end
- end
-
- def test_use_gemdeps_automatic_missing
- with_local_bundler_at(Gem.dir) do
- with_rubygems_gemdeps("-") do
- Gem.use_gemdeps
-
- assert true # count
- end
- end
- end
-
- def test_use_gemdeps_disabled
- with_local_bundler_at(Gem.dir) do
- with_rubygems_gemdeps("") do
- spec = util_spec "a", 1
-
- refute spec.activated?
-
- File.open "gem.deps.rb", "w" do |io|
- io.write 'gem "a"'
- end
-
- Gem.use_gemdeps
-
- refute spec.activated?
- end
- end
- end
-
- def test_use_gemdeps_missing_gem
- with_local_bundler_at(Gem.dir) do
- with_rubygems_gemdeps("x") do
- File.open "x", "w" do |io|
- io.write 'gem "a"'
- end
-
- expected = <<-EXPECTED
-Could not find gem 'a' in locally installed gems.
-You may need to `bundle install` to install missing gems
-
- EXPECTED
-
- Gem::Deprecate.skip_during do
- actual_stdout, actual_stderr = capture_output do
- Gem.use_gemdeps
- end
- assert_empty actual_stdout
- assert_equal(expected, actual_stderr)
- end
- end
- end
- end
-
- def test_use_gemdeps_specific
- with_local_bundler_at(Gem.dir) do
- with_rubygems_gemdeps("x") do
- spec = util_spec "a", 1
- install_specs spec
-
- spec = Gem::Specification.find {|s| s == spec }
- refute spec.activated?
-
- File.open "x", "w" do |io|
- io.write 'gem "a"'
- end
-
- Gem.use_gemdeps
-
- assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
- end
- end
- end
-
def test_operating_system_defaults
operating_system_defaults = Gem.operating_system_defaults
@@ -2110,40 +1734,4 @@ You may need to `bundle install` to install missing gems
def util_cache_dir
File.join Gem.dir, "cache"
end
-
- def with_path_and_rubyopt(path_value, rubyopt_value)
- path, ENV["PATH"] = ENV["PATH"], path_value
- rubyopt, ENV["RUBYOPT"] = ENV["RUBYOPT"], rubyopt_value
-
- yield
- ensure
- ENV["PATH"] = path
- ENV["RUBYOPT"] = rubyopt
- end
-
- def with_rubygems_gemdeps(value)
- rubygems_gemdeps, ENV["RUBYGEMS_GEMDEPS"] = ENV["RUBYGEMS_GEMDEPS"], value
-
- yield
- ensure
- ENV["RUBYGEMS_GEMDEPS"] = rubygems_gemdeps
- end
-
- def with_local_bundler_at(path)
- require "bundler"
-
- # If bundler gemspec exists, pretend it's installed
- bundler_gemspec = File.expand_path("../../bundler/bundler.gemspec", __dir__)
- if File.exist?(bundler_gemspec)
- target_gemspec_location = "#{path}/specifications/bundler-#{Bundler::VERSION}.gemspec"
-
- FileUtils.mkdir_p File.dirname(target_gemspec_location)
-
- File.write target_gemspec_location, Gem::Specification.load(bundler_gemspec).to_ruby_for_cache
- end
-
- yield
- ensure
- Bundler.reset!
- end
end
diff --git a/test/rubygems/test_gem_ext_cargo_builder.rb b/test/rubygems/test_gem_ext_cargo_builder.rb
index 9c1ee2ae31..df50150d50 100644
--- a/test/rubygems/test_gem_ext_cargo_builder.rb
+++ b/test/rubygems/test_gem_ext_cargo_builder.rb
@@ -31,13 +31,12 @@ class TestGemExtCargoBuilder < Gem::TestCase
Dir.chdir @ext do
ENV.update(@rust_envs)
- spec = Gem::Specification.new "rust_ruby_example", "0.1.0"
- builder = Gem::Ext::CargoBuilder.new(spec)
- builder.build nil, @dest_path, output
+ builder = Gem::Ext::CargoBuilder.new
+ builder.build "Cargo.toml", @dest_path, output
end
output = output.join "\n"
- bundle = File.join(@dest_path, "release/rust_ruby_example.#{RbConfig::CONFIG['DLEXT']}")
+ bundle = File.join(@dest_path, "rust_ruby_example.#{RbConfig::CONFIG['DLEXT']}")
assert_match(/Finished/, output)
assert_match(/release/, output)
@@ -58,13 +57,12 @@ class TestGemExtCargoBuilder < Gem::TestCase
Dir.chdir @ext do
ENV.update(@rust_envs)
- spec = Gem::Specification.new "rust_ruby_example", "0.1.0"
- builder = Gem::Ext::CargoBuilder.new(spec)
- builder.build nil, @dest_path, output
+ builder = Gem::Ext::CargoBuilder.new
+ builder.build "Cargo.toml", @dest_path, output
end
output = output.join "\n"
- bundle = File.join(@dest_path, "release/rust_ruby_example.#{RbConfig::CONFIG['DLEXT']}")
+ bundle = File.join(@dest_path, "rust_ruby_example.#{RbConfig::CONFIG['DLEXT']}")
assert_ffi_handle bundle, "hello_from_rubygems"
assert_ffi_handle bundle, "hello_from_rubygems_version"
@@ -79,22 +77,17 @@ class TestGemExtCargoBuilder < Gem::TestCase
skip_unsupported_platforms!
setup_rust_gem "rust_ruby_example"
- output = []
-
FileUtils.rm(File.join(@ext, "src/lib.rs"))
error = assert_raise(Gem::InstallError) do
Dir.chdir @ext do
ENV.update(@rust_envs)
- spec = Gem::Specification.new "rust_ruby_example", "0.1.0"
- builder = Gem::Ext::CargoBuilder.new(spec)
- builder.build nil, @dest_path, output
+ builder = Gem::Ext::CargoBuilder.new
+ builder.build "Cargo.toml", @dest_path, []
end
end
- output = output.join "\n"
-
- assert_match "cargo failed", error.message
+ assert_match /cargo\s.*\sfailed/, error.message
end
def test_full_integration
diff --git a/test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb b/test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb
deleted file mode 100644
index 0e04f0de5e..0000000000
--- a/test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-if ENV["RUBYOPT"] || defined? Gem
- ENV.delete "RUBYOPT"
-
- require "rbconfig"
- cmd = [RbConfig.ruby, "--disable-gems", "build.rb", *ARGV]
-
- exec(*cmd)
-end
-
-require "tmpdir"
-
-lp = File.expand_path("../../../../lib", __dir__)
-gem = ["ruby", "-I#{lp}", File.expand_path("../../../../bin/gem", __dir__)]
-gemspec = File.expand_path("custom_name.gemspec", __dir__)
-
-Dir.mktmpdir("custom_name") do |dir|
- built_gem = File.expand_path(File.join(dir, "custom_name.gem"))
- system(*gem, "build", gemspec, "--output", built_gem)
- system(*gem, "install", "--verbose", "--local", built_gem, *ARGV)
- system %q(ruby -rcustom_name -e "puts 'Result: ' + CustomName.say_hello")
-end
diff --git a/test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec b/test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec
index 1f8e270e96..43dddac243 100644
--- a/test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec
+++ b/test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec
@@ -2,9 +2,7 @@ Gem::Specification.new do |s|
s.name = "custom_name"
s.version = "0.1.0"
s.summary = "A Rust extension for Ruby"
- s.extensions = ["Cargo.toml"]
+ s.extensions = ["ext/custom_name_lib/Cargo.toml"]
s.authors = ["Ian Ker-Seymer"]
- s.files = ["Cargo.toml", "Cargo.lock", "src/lib.rs"]
-
- s.metadata["cargo_crate_name"] = "custom-name-ext"
+ s.files = ["lib/custom_name.rb", "ext/custom_name_lib/Cargo.toml", "ext/custom_name_lib/Cargo.lock", "ext/custom_name_lib/src/lib.rs"]
end
diff --git a/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.lock b/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.lock
index e597d1981e..e597d1981e 100644
--- a/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.lock
+++ b/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.lock
diff --git a/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.toml b/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.toml
index 53f0879012..53f0879012 100644
--- a/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.toml
+++ b/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.toml
diff --git a/test/rubygems/test_gem_ext_cargo_builder/custom_name/src/lib.rs b/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/src/lib.rs
index 543ad4a70e..28ba3be564 100644
--- a/test/rubygems/test_gem_ext_cargo_builder/custom_name/src/lib.rs
+++ b/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/src/lib.rs
@@ -12,7 +12,7 @@ unsafe extern "C" fn say_hello(_klass: VALUE) -> VALUE {
#[allow(non_snake_case)]
#[no_mangle]
-pub extern "C" fn Init_custom_name() {
+pub extern "C" fn Init_custom_name_ext() {
let name = CString::new("CustomName").unwrap();
let function_name = CString::new("say_hello").unwrap();
// bindgen does not properly detect the arity of the ruby callback function, so we have to transmute
diff --git a/test/rubygems/test_gem_ext_cargo_builder/custom_name/lib/custom_name.rb b/test/rubygems/test_gem_ext_cargo_builder/custom_name/lib/custom_name.rb
new file mode 100644
index 0000000000..5ae8b00a5f
--- /dev/null
+++ b/test/rubygems/test_gem_ext_cargo_builder/custom_name/lib/custom_name.rb
@@ -0,0 +1 @@
+require "custom_name_lib/custom_name_ext"
diff --git a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb
deleted file mode 100644
index f404aa3468..0000000000
--- a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-if ENV["RUBYOPT"] || defined? Gem
- ENV.delete "RUBYOPT"
-
- require "rbconfig"
- cmd = [RbConfig.ruby, "--disable-gems", "build.rb", *ARGV]
-
- exec(*cmd)
-end
-
-require "tmpdir"
-
-lp = File.expand_path("../../../../lib", __dir__)
-gem = ["ruby", "-I#{lp}", File.expand_path("../../../../bin/gem", __dir__)]
-gemspec = File.expand_path("rust_ruby_example.gemspec", __dir__)
-
-Dir.mktmpdir("rust_ruby_example") do |dir|
- built_gem = File.expand_path(File.join(dir, "rust_ruby_example.gem"))
- system(*gem, "build", gemspec, "--output", built_gem)
- system(*gem, "install", "--verbose", "--local", built_gem, *ARGV)
- system %q(ruby -rrust_ruby_example -e "puts 'Result: ' + RustRubyExample.reverse('hello world')")
-end
diff --git a/test/rubygems/test_gem_ext_cargo_builder_unit.rb b/test/rubygems/test_gem_ext_cargo_builder_unit.rb
index dc9350bb3a..0ca8306842 100644
--- a/test/rubygems/test_gem_ext_cargo_builder_unit.rb
+++ b/test/rubygems/test_gem_ext_cargo_builder_unit.rb
@@ -6,8 +6,7 @@ require "rubygems/ext"
class TestGemExtCargoBuilderUnit < Gem::TestCase
def test_cargo_command_passes_args
skip_unsupported_platforms!
- spec = Gem::Specification.new "rust_ruby_example", "0.1.0"
- builder = Gem::Ext::CargoBuilder.new(spec)
+ builder = Gem::Ext::CargoBuilder.new
command = builder.cargo_command(Dir.pwd, @tempdir, ["--all-features"])
assert_includes command, "--all-features"
@@ -15,8 +14,7 @@ class TestGemExtCargoBuilderUnit < Gem::TestCase
def test_cargo_command_locks_in_release_profile
skip_unsupported_platforms!
- spec = Gem::Specification.new "rust_ruby_example", "0.1.0"
- builder = Gem::Ext::CargoBuilder.new(spec)
+ builder = Gem::Ext::CargoBuilder.new
builder.profile = :release
command = builder.cargo_command(Dir.pwd, @tempdir)
@@ -27,8 +25,7 @@ class TestGemExtCargoBuilderUnit < Gem::TestCase
skip_unsupported_platforms!
old_cargo = ENV["CARGO"]
ENV["CARGO"] = "mycargo"
- spec = Gem::Specification.new "rust_ruby_example", "0.1.0"
- builder = Gem::Ext::CargoBuilder.new(spec)
+ builder = Gem::Ext::CargoBuilder.new
command = builder.cargo_command(Dir.pwd, @tempdir)
assert_includes command, "mycargo"
@@ -38,8 +35,7 @@ class TestGemExtCargoBuilderUnit < Gem::TestCase
def test_build_env_includes_rbconfig
skip_unsupported_platforms!
- spec = Gem::Specification.new "rust_ruby_example", "0.1.0"
- builder = Gem::Ext::CargoBuilder.new(spec)
+ builder = Gem::Ext::CargoBuilder.new
env = builder.build_env
assert_equal env.fetch("RBCONFIG_RUBY_SO_NAME"), RbConfig::CONFIG["RUBY_SO_NAME"]
@@ -49,8 +45,7 @@ class TestGemExtCargoBuilderUnit < Gem::TestCase
skip_unsupported_platforms!
old_cargo = ENV["CARGO_BUILD_TARGET"]
ENV["CARGO_BUILD_TARGET"] = "x86_64-unknown-linux-gnu"
- spec = Gem::Specification.new "rust_ruby_example", "0.1.0"
- builder = Gem::Ext::CargoBuilder.new(spec)
+ builder = Gem::Ext::CargoBuilder.new
command = builder.cargo_command(Dir.pwd, @tempdir, ["--locked"])
assert_includes command, "--target"