summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/test_gem_bundler_version_finder.rb1
-rw-r--r--test/rubygems/test_gem_dependency.rb2
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder.rb45
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/src/lib.rs12
-rw-r--r--test/rubygems/test_gem_ext_cargo_builder_link_flag_converter.rb14
-rw-r--r--test/rubygems/test_gem_specification.rb33
-rw-r--r--test/rubygems/test_kernel.rb2
-rw-r--r--test/rubygems/test_require.rb18
8 files changed, 107 insertions, 20 deletions
diff --git a/test/rubygems/test_gem_bundler_version_finder.rb b/test/rubygems/test_gem_bundler_version_finder.rb
index 60e2b65047..fd61000b8a 100644
--- a/test/rubygems/test_gem_bundler_version_finder.rb
+++ b/test/rubygems/test_gem_bundler_version_finder.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
require_relative "helper"
+require "rubygems/bundler_version_finder"
class TestGemBundlerVersionFinder < Gem::TestCase
def setup
diff --git a/test/rubygems/test_gem_dependency.rb b/test/rubygems/test_gem_dependency.rb
index c585e87087..bf0745ddc1 100644
--- a/test/rubygems/test_gem_dependency.rb
+++ b/test/rubygems/test_gem_dependency.rb
@@ -358,6 +358,8 @@ class TestGemDependency < Gem::TestCase
assert_equal [b, b_1], dep.to_specs
+ require "rubygems/bundler_version_finder"
+
Gem::BundlerVersionFinder.stub(:bundler_version, Gem::Version.new("1")) do
assert_equal [b_1, b], dep.to_specs
end
diff --git a/test/rubygems/test_gem_ext_cargo_builder.rb b/test/rubygems/test_gem_ext_cargo_builder.rb
index e5bad0bcbc..9c1ee2ae31 100644
--- a/test/rubygems/test_gem_ext_cargo_builder.rb
+++ b/test/rubygems/test_gem_ext_cargo_builder.rb
@@ -2,6 +2,7 @@
require_relative "helper"
require "rubygems/ext"
+require "open3"
class TestGemExtCargoBuilder < Gem::TestCase
def setup
@@ -22,31 +23,39 @@ class TestGemExtCargoBuilder < Gem::TestCase
FileUtils.cp_r(@fixture_dir.to_s, @ext)
end
- def test_build_staticlib
+ def test_build_cdylib
skip_unsupported_platforms!
setup_rust_gem "rust_ruby_example"
- content = @fixture_dir.join("Cargo.toml").read.gsub("cdylib", "staticlib")
- File.write(File.join(@ext, "Cargo.toml"), content)
-
output = []
Dir.chdir @ext do
ENV.update(@rust_envs)
spec = Gem::Specification.new "rust_ruby_example", "0.1.0"
builder = Gem::Ext::CargoBuilder.new(spec)
- assert_raise(Gem::Ext::CargoBuilder::DylibNotFoundError) do
- builder.build nil, @dest_path, output
- end
+ builder.build nil, @dest_path, output
end
+
+ output = output.join "\n"
+ bundle = File.join(@dest_path, "release/rust_ruby_example.#{RbConfig::CONFIG['DLEXT']}")
+
+ assert_match(/Finished/, output)
+ assert_match(/release/, output)
+ assert_ffi_handle bundle, "Init_rust_ruby_example"
+ rescue Exception => e
+ pp output if output
+
+ raise(e)
end
- def test_build_cdylib
+ def test_rubygems_cfg_passed_to_rustc
skip_unsupported_platforms!
setup_rust_gem "rust_ruby_example"
-
+ version_slug = Gem::VERSION.tr(".", "_")
output = []
+ replace_in_rust_file("src/lib.rs", "rubygems_x_x_x", "rubygems_#{version_slug}")
+
Dir.chdir @ext do
ENV.update(@rust_envs)
spec = Gem::Specification.new "rust_ruby_example", "0.1.0"
@@ -57,9 +66,9 @@ class TestGemExtCargoBuilder < Gem::TestCase
output = output.join "\n"
bundle = File.join(@dest_path, "release/rust_ruby_example.#{RbConfig::CONFIG['DLEXT']}")
- assert_match(/Finished/, output)
- assert_match(/release/, output)
- assert_ffi_handle bundle, "Init_rust_ruby_example"
+ assert_ffi_handle bundle, "hello_from_rubygems"
+ assert_ffi_handle bundle, "hello_from_rubygems_version"
+ refute_ffi_handle bundle, "should_never_exist"
rescue Exception => e
pp output if output
@@ -140,7 +149,6 @@ class TestGemExtCargoBuilder < Gem::TestCase
def skip_unsupported_platforms!
pend "jruby not supported" if java_platform?
pend "truffleruby not supported (yet)" if RUBY_ENGINE == "truffleruby"
- pend "mswin not supported (yet)" if RUBY_PLATFORM.include?("mswin") && ENV.key?("GITHUB_ACTIONS")
system(@rust_envs, "cargo", "-V", out: IO::NULL, err: [:child, :out])
pend "cargo not present" unless $?.success?
pend "ruby.h is not provided by ruby repo" if ruby_repo?
@@ -151,4 +159,15 @@ class TestGemExtCargoBuilder < Gem::TestCase
dylib_handle = Fiddle.dlopen bundle
assert_nothing_raised { dylib_handle[name] }
end
+
+ def refute_ffi_handle(bundle, name)
+ require "fiddle"
+ dylib_handle = Fiddle.dlopen bundle
+ assert_raise { dylib_handle[name] }
+ end
+
+ def replace_in_rust_file(name, from, to)
+ content = @fixture_dir.join(name).read.gsub(from, to)
+ File.write(File.join(@ext, name), content)
+ end
end
diff --git a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/src/lib.rs b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/src/lib.rs
index b2a907c736..0626f04e0f 100644
--- a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/src/lib.rs
+++ b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/src/lib.rs
@@ -21,6 +21,18 @@ unsafe extern "C" fn pub_reverse(_klass: VALUE, mut input: VALUE) -> VALUE {
rb_utf8_str_new(reversed_cstring.as_ptr(), size)
}
+#[cfg(rubygems)]
+#[no_mangle]
+pub extern "C" fn hello_from_rubygems() {}
+
+#[cfg(rubygems_0_0_0)]
+#[no_mangle]
+pub extern "C" fn should_never_exist() {}
+
+#[cfg(rubygems_x_x_x)]
+#[no_mangle]
+pub extern "C" fn hello_from_rubygems_version() {}
+
#[allow(non_snake_case)]
#[no_mangle]
pub extern "C" fn Init_rust_ruby_example() {
diff --git a/test/rubygems/test_gem_ext_cargo_builder_link_flag_converter.rb b/test/rubygems/test_gem_ext_cargo_builder_link_flag_converter.rb
index 92bd893a18..01648605d7 100644
--- a/test/rubygems/test_gem_ext_cargo_builder_link_flag_converter.rb
+++ b/test/rubygems/test_gem_ext_cargo_builder_link_flag_converter.rb
@@ -12,15 +12,15 @@ class TestGemExtCargoBuilderLinkFlagConverter < Gem::TestCase
test_lib_with_nonascii: ["-lws2_32", ["-l", "ws2_32"]],
test_simple_lib_space: ["-l foo", ["-l", "foo"]],
test_verbose_lib_space: ["--library=foo", ["-l", "foo"]],
- test_libstatic_with_colon: ["-l:libssp.a", ["-l", "static=ssp"]],
- test_libstatic_with_colon_space: ["-l :libssp.a", ["-l", "static=ssp"]],
- test_unconventional_lib_with_colon: ["-l:ssp.a", ["-C", "link_arg=-l:ssp.a"]],
- test_dylib_with_colon_space: ["-l :libssp.dylib", ["-l", "dylib=ssp"]],
- test_so_with_colon_space: ["-l :libssp.so", ["-l", "dylib=ssp"]],
- test_dll_with_colon_space: ["-l :libssp.dll", ["-l", "dylib=ssp"]],
+ test_libstatic_with_colon: ["-l:libssp.a", ["-C", "link-args=-l:libssp.a"]],
+ test_libstatic_with_colon_space: ["-l :libssp.a", ["-C", "link-args=-l :libssp.a"]],
+ test_unconventional_lib_with_colon: ["-l:ssp.a", ["-C", "link-args=-l:ssp.a"]],
+ test_dylib_with_colon_space: ["-l :libssp.dylib", ["-C", "link-args=-l :libssp.dylib"]],
+ test_so_with_colon_space: ["-l :libssp.so", ["-C", "link-args=-l :libssp.so"]],
+ test_dll_with_colon_space: ["-l :libssp.dll", ["-C", "link-args=-l :libssp.dll"]],
test_framework: ["-F/some/path", ["-l", "framework=/some/path"]],
test_framework_space: ["-F /some/path", ["-l", "framework=/some/path"]],
- test_non_lib_dash_l: ["test_rubygems_20220413-976-lemgf9/prefix", ["-C", "link_arg=test_rubygems_20220413-976-lemgf9/prefix"]],
+ test_non_lib_dash_l: ["test_rubygems_20220413-976-lemgf9/prefix", ["-C", "link-args=test_rubygems_20220413-976-lemgf9/prefix"]],
}.freeze
CASES.each do |test_name, (arg, expected)|
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index 24a7261466..dda47e6bdf 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -2708,6 +2708,39 @@ duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use:
end
end
+ def test_validate_rust_extension_have_missing_cargo_toml_error
+ util_setup_validate
+
+ Dir.chdir @tempdir do
+ @a1.extensions = ["Cargo.toml"]
+ File.write File.join(@tempdir, "Cargo.toml"), ""
+
+ e = assert_raise Gem::InvalidSpecificationException do
+ use_ui @ui do
+ @a1.validate
+ end
+ end
+
+ assert_match(/but Cargo.lock is not part of the gem files/, e.message)
+ end
+ end
+
+ def test_validate_rust_extension_have_no_missing_cargo_toml_error
+ util_setup_validate
+
+ Dir.chdir @tempdir do
+ @a1.extensions = ["Cargo.toml"]
+ @a1.files << "Cargo.toml"
+ @a1.files << "Cargo.lock"
+ File.write File.join(@tempdir, "Cargo.toml"), ""
+ File.write File.join(@tempdir, "Cargo.lock"), ""
+
+ use_ui @ui do
+ @a1.validate
+ end
+ end
+ end
+
def test_validate_description
util_setup_validate
diff --git a/test/rubygems/test_kernel.rb b/test/rubygems/test_kernel.rb
index 091a5419fb..ce38d92d8d 100644
--- a/test/rubygems/test_kernel.rb
+++ b/test/rubygems/test_kernel.rb
@@ -118,6 +118,8 @@ class TestKernel < Gem::TestCase
end
def test_gem_bundler_inferred_bundler_version
+ require "rubygems/bundler_version_finder"
+
Gem::BundlerVersionFinder.stub(:bundler_version, Gem::Version.new("1")) do
quick_gem "bundler", "1"
quick_gem "bundler", "2.a"
diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb
index fba7f0c8be..43774d638e 100644
--- a/test/rubygems/test_require.rb
+++ b/test/rubygems/test_require.rb
@@ -666,6 +666,24 @@ class TestGemRequire < Gem::TestCase
end
end
+ def test_require_does_not_crash_when_utilizing_bundler_version_finder
+ a1 = util_spec "a", "1.1", { "bundler" => ">= 0" }
+ a2 = util_spec "a", "1.2", { "bundler" => ">= 0" }
+ b1 = util_spec "bundler", "2.3.7"
+ b2 = util_spec "bundler", "2.3.24"
+ c = util_spec "c", "1", { "a" => [">= 1.1", "< 99.0"] }, "lib/test_gem_require_c.rb"
+
+ install_specs a1, a2, b1, b2, c
+
+ cmd = <<-RUBY
+ require "test_gem_require_c"
+ require "json"
+ RUBY
+ out = Gem::Util.popen({ "GEM_HOME" => @gemhome }, *ruby_with_rubygems_in_load_path, "-e", cmd)
+ puts out
+ assert $?.success?
+ end
+
private
def util_install_extension_file(name)