diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2022-06-23 11:22:36 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-06-24 10:52:02 +0900 |
commit | 12a5fa408bd318f8fb242e86beb225f2dcae8df9 (patch) | |
tree | f132650f5999535da69ee998956f260007afd371 /test/rubygems/test_gem_ext_cargo_builder.rb | |
parent | 333754ace8ae9bc5d2dfb4aee160fcfa0f38350d (diff) |
Sync RubyGems & Bundler with upstream repo
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6054
Diffstat (limited to 'test/rubygems/test_gem_ext_cargo_builder.rb')
-rw-r--r-- | test/rubygems/test_gem_ext_cargo_builder.rb | 69 |
1 files changed, 50 insertions, 19 deletions
diff --git a/test/rubygems/test_gem_ext_cargo_builder.rb b/test/rubygems/test_gem_ext_cargo_builder.rb index 559a31f5ad..2da98c03e2 100644 --- a/test/rubygems/test_gem_ext_cargo_builder.rb +++ b/test/rubygems/test_gem_ext_cargo_builder.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative 'helper' require 'rubygems/ext' @@ -7,12 +8,9 @@ class TestGemExtCargoBuilder < Gem::TestCase super @rust_envs = { - 'CARGO_HOME' => File.join(@orig_env['HOME'], '.cargo'), - 'RUSTUP_HOME' => File.join(@orig_env['HOME'], '.rustup'), + 'CARGO_HOME' => ENV.fetch('CARGO_HOME', File.join(@orig_env['HOME'], '.cargo')), + 'RUSTUP_HOME' => ENV.fetch('RUSTUP_HOME', File.join(@orig_env['HOME'], '.rustup')), } - - system(@rust_envs, 'cargo', '-V', out: IO::NULL, err: [:child, :out]) - pend 'cargo not present' unless $?.success? end def setup_rust_gem(name) @@ -57,15 +55,35 @@ class TestGemExtCargoBuilder < Gem::TestCase end output = output.join "\n" - bundle = File.join(@dest_path, "release/rust_ruby_example.#{RbConfig::CONFIG['DLEXT']}") - require(bundle) + assert_match "Finished release [optimized] target(s)", output + assert_ffi_handle bundle, 'Init_rust_ruby_example' + rescue Exception => e + pp output if output + + raise(e) + end - assert_match RustRubyExample.reverse('hello'), 'olleh' + def test_build_dev_profile + skip_unsupported_platforms! + setup_rust_gem "rust_ruby_example" - assert_match "Compiling rust_ruby_example v0.1.0", output - assert_match "Finished release [optimized] target(s)", output + 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) + builder.profile = :dev + builder.build nil, @dest_path, output + end + + output = output.join "\n" + bundle = File.join(@dest_path, "debug/rust_ruby_example.#{RbConfig::CONFIG['DLEXT']}") + + assert_match "Finished dev [unoptimized + debuginfo] target(s)", output + assert_ffi_handle bundle, 'Init_rust_ruby_example' rescue Exception => e pp output if output @@ -98,21 +116,23 @@ class TestGemExtCargoBuilder < Gem::TestCase skip_unsupported_platforms! setup_rust_gem "rust_ruby_example" + require 'open3' + Dir.chdir @ext do require 'tmpdir' - gem = [@rust_envs, *ruby_with_rubygems_in_load_path, File.expand_path('../../bin/gem', __dir__)] + env_for_subprocess = @rust_envs.merge("GEM_HOME" => Gem.paths.home) + gem = [env_for_subprocess, *ruby_with_rubygems_in_load_path, File.expand_path('../../bin/gem', __dir__)] Dir.mktmpdir("rust_ruby_example") do |dir| built_gem = File.expand_path(File.join(dir, "rust_ruby_example.gem")) Open3.capture2e(*gem, "build", "rust_ruby_example.gemspec", "--output", built_gem) Open3.capture2e(*gem, "install", "--verbose", "--local", built_gem, *ARGV) - end - stdout_and_stderr_str, status = Open3.capture2e(@rust_envs, *ruby_with_rubygems_in_load_path, "-rrust_ruby_example", "-e", "puts 'Result: ' + RustRubyExample.reverse('hello world')") - - assert status.success?, stdout_and_stderr_str - assert_match "Result: #{"hello world".reverse}", stdout_and_stderr_str + stdout_and_stderr_str, status = Open3.capture2e(env_for_subprocess, *ruby_with_rubygems_in_load_path, "-rrust_ruby_example", "-e", "puts 'Result: ' + RustRubyExample.reverse('hello world')") + assert status.success?, stdout_and_stderr_str + assert_match "Result: #{"hello world".reverse}", stdout_and_stderr_str + end end end @@ -123,7 +143,8 @@ class TestGemExtCargoBuilder < Gem::TestCase Dir.chdir @ext do require 'tmpdir' - gem = [@rust_envs, *ruby_with_rubygems_in_load_path, File.expand_path('../../bin/gem', __dir__)] + env_for_subprocess = @rust_envs.merge("GEM_HOME" => Gem.paths.home) + gem = [env_for_subprocess, *ruby_with_rubygems_in_load_path, File.expand_path('../../bin/gem', __dir__)] Dir.mktmpdir("custom_name") do |dir| built_gem = File.expand_path(File.join(dir, "custom_name.gem")) @@ -131,17 +152,27 @@ class TestGemExtCargoBuilder < Gem::TestCase Open3.capture2e(*gem, "install", "--verbose", "--local", built_gem, *ARGV) end - stdout_and_stderr_str, status = Open3.capture2e(@rust_envs, *ruby_with_rubygems_in_load_path, "-rcustom_name", "-e", "puts 'Result: ' + CustomName.say_hello") + stdout_and_stderr_str, status = Open3.capture2e(env_for_subprocess, *ruby_with_rubygems_in_load_path, "-rcustom_name", "-e", "puts 'Result: ' + CustomName.say_hello") assert status.success?, stdout_and_stderr_str assert_match "Result: Hello world!", stdout_and_stderr_str end end + private + 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 /mswin/ =~ RUBY_PLATFORM && ENV.key?('GITHUB_ACTIONS') - pend "ruby.h is not provided by ruby repo" if testing_ruby_repo? + 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? + end + + def assert_ffi_handle(bundle, name) + require 'fiddle' + dylib_handle = Fiddle.dlopen bundle + assert_nothing_raised { dylib_handle[name] } end end |