diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-06-14 12:55:03 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2021-07-07 10:03:15 +0900 |
commit | d4b4281959d2a9846d766253b5e21e8158948aa7 (patch) | |
tree | 64f45489cd78b781b682e2a94c16a6829b8f2edd /lib/rubygems | |
parent | dd28c03d5fd7a82d1b694a9c2332a55dab81add9 (diff) |
Merge RubyGems-3.2.18 and Bundler-2.2.18
Diffstat (limited to 'lib/rubygems')
-rw-r--r-- | lib/rubygems/ext/ext_conf_builder.rb | 8 | ||||
-rw-r--r-- | lib/rubygems/specification.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/test_case.rb | 120 |
3 files changed, 106 insertions, 24 deletions
diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb index fede270417..1f73796351 100644 --- a/lib/rubygems/ext/ext_conf_builder.rb +++ b/lib/rubygems/ext/ext_conf_builder.rb @@ -23,11 +23,11 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder # spaces do not work. # # Details: https://github.com/rubygems/rubygems/issues/977#issuecomment-171544940 - tmp_dest = get_relative_path(tmp_dest, extension_dir) + tmp_dest_relative = get_relative_path(tmp_dest.clone, extension_dir) Tempfile.open %w[siteconf .rb], extension_dir do |siteconf| siteconf.puts "require 'rbconfig'" - siteconf.puts "dest_path = #{tmp_dest.dump}" + siteconf.puts "dest_path = #{tmp_dest_relative.dump}" %w[sitearchdir sitelibdir].each do |dir| siteconf.puts "RbConfig::MAKEFILE_CONFIG['#{dir}'] = dest_path" siteconf.puts "RbConfig::CONFIG['#{dir}'] = dest_path" @@ -63,8 +63,8 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder make dest_path, results, extension_dir - if tmp_dest - full_tmp_dest = File.join(extension_dir, tmp_dest) + if tmp_dest_relative + full_tmp_dest = File.join(extension_dir, tmp_dest_relative) # TODO remove in RubyGems 3 if Gem.install_extension_in_lib and lib_dir diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 6b569032ba..7206c3eaf0 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -1558,7 +1558,6 @@ class Gem::Specification < Gem::BasicSpecification def build_extensions # :nodoc: return if default_gem? return if extensions.empty? - return if installed_by_version < Gem::Version.new('2.2.0.preview.2') return if File.exist? gem_build_complete_path return if !File.writable?(base_dir) return if !File.exist?(File.join(base_dir, 'extensions')) @@ -2129,7 +2128,6 @@ class Gem::Specification < Gem::BasicSpecification def missing_extensions? return false if default_gem? return false if extensions.empty? - return false if installed_by_version < Gem::Version.new('2.2.0.preview.2') return false if File.exist? gem_build_complete_path true diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index e2763561c6..b3e23360ed 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -12,7 +12,7 @@ if File.exist?(bundler_gemspec) end begin - gem 'minitest', '~> 5.13' + gem 'test-unit', '~> 3.0' rescue Gem::LoadError end @@ -32,16 +32,7 @@ else require 'bundler' end -# Enable server plugin needed for bisection -if ENV["RG_BISECT_SERVER_PLUGIN"] - require ENV["RG_BISECT_SERVER_PLUGIN"] - - Minitest.extensions << "server" -end - -ENV["MT_NO_PLUGINS"] = "true" - -require 'minitest/autorun' +require 'test/unit' ENV["JARS_SKIP"] = "true" if Gem.java_platform? # avoid unnecessary and noisy `jar-dependencies` post install hook @@ -111,7 +102,7 @@ end # and uninstall gems, fetch remote gems through a stub fetcher and be assured # your normal set of gems is not affected. -class Gem::TestCase < Minitest::Test +class Gem::TestCase < Test::Unit::TestCase extend Gem::Deprecate attr_accessor :fetcher # :nodoc: @@ -140,11 +131,48 @@ class Gem::TestCase < Minitest::Test end def assert_directory_exists(path, msg = nil) - msg = message(msg) { "Expected path '#{path}' to be a directory" } - assert_path_exists path + msg = build_message(msg, "Expected path '#{path}' to be a directory") + assert_path_exist path assert File.directory?(path), msg end + # https://github.com/seattlerb/minitest/blob/21d9e804b63c619f602f3f4ece6c71b48974707a/lib/minitest/assertions.rb#L188 + def _synchronize + yield + end + + # https://github.com/seattlerb/minitest/blob/21d9e804b63c619f602f3f4ece6c71b48974707a/lib/minitest/assertions.rb#L546 + def capture_subprocess_io + _synchronize do + begin + require "tempfile" + + captured_stdout, captured_stderr = Tempfile.new("out"), Tempfile.new("err") + + orig_stdout, orig_stderr = $stdout.dup, $stderr.dup + $stdout.reopen captured_stdout + $stderr.reopen captured_stderr + + yield + + $stdout.rewind + $stderr.rewind + + return captured_stdout.read, captured_stderr.read + ensure + captured_stdout.unlink + captured_stderr.unlink + $stdout.reopen orig_stdout + $stderr.reopen orig_stderr + + orig_stdout.close + orig_stderr.close + captured_stdout.close + captured_stderr.close + end + end + end + ## # Sets the ENABLE_SHARED entry in RbConfig::CONFIG to +value+ and restores # the original value when the block ends @@ -262,19 +290,19 @@ class Gem::TestCase < Minitest::Test def assert_contains_make_command(target, output, msg = nil) if output.match(/\n/) - msg = message(msg) do + msg = build_message(msg, "Expected output containing make command \"%s\", but was \n\nBEGIN_OF_OUTPUT\n%sEND_OF_OUTPUT" % [ ('%s %s' % [make_command, target]).rstrip, output, ] - end + ) else - msg = message(msg) do + msg = build_message(msg, 'Expected make command "%s": %s' % [ ('%s %s' % [make_command, target]).rstrip, output, ] - end + ) end assert scan_make_command_lines(output).any? {|line| @@ -664,6 +692,28 @@ class Gem::TestCase < Minitest::Test path end + ## + # Load a YAML string, the psych 3 way + + def load_yaml(yaml) + if YAML.respond_to?(:unsafe_load) + YAML.unsafe_load(yaml) + else + YAML.load(yaml) + end + end + + ## + # Load a YAML file, the psych 3 way + + def load_yaml_file(file) + if YAML.respond_to?(:unsafe_load_file) + YAML.unsafe_load_file(file) + else + YAML.load_file(file) + end + end + def all_spec_names Gem::Specification.map(&:full_name) end @@ -1519,4 +1569,38 @@ Also, a list: end if Gem::HAVE_OPENSSL end +# https://github.com/seattlerb/minitest/blob/13c48a03d84a2a87855a4de0c959f96800100357/lib/minitest/mock.rb#L192 +class Object + def stub(name, val_or_callable, *block_args) + new_name = "__minitest_stub__#{name}" + + metaclass = class << self; self; end + + if respond_to? name and not methods.map(&:to_s).include? name.to_s + metaclass.send :define_method, name do |*args| + super(*args) + end + end + + metaclass.send :alias_method, new_name, name + + metaclass.send :define_method, name do |*args, &blk| + if val_or_callable.respond_to? :call + val_or_callable.call(*args, &blk) + else + blk.call(*block_args) if blk + val_or_callable + end + end + + metaclass.send(:ruby2_keywords, name) if metaclass.respond_to?(:ruby2_keywords, true) + + yield self + ensure + metaclass.send :undef_method, name + metaclass.send :alias_method, name, new_name + metaclass.send :undef_method, new_name + end +end + require 'rubygems/test_utilities' |