Merge rubygems master from upstream.

I picked the commit from 3c469e0da538428a0ddd94f99aa73c32da22e8ba
This commit is contained in:
Hiroshi SHIBATA 2019-06-01 12:45:11 +03:00
Родитель 560cd5b1f0
Коммит 56660de3c6
55 изменённых файлов: 1051 добавлений и 1053 удалений

Просмотреть файл

@ -670,6 +670,21 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
index
end
##
# Add a list of paths to the $LOAD_PATH at the proper place.
def self.add_to_load_path(*paths)
insert_index = load_path_insert_index
if insert_index
# gem directories must come after -I and ENV['RUBYLIB']
$LOAD_PATH.insert(insert_index, *paths)
else
# we are probably testing in core, -I and RUBYLIB don't apply
$LOAD_PATH.unshift(*paths)
end
end
@yaml_loaded = false
##
@ -1083,6 +1098,13 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
@@win_platform
end
##
# Is this a java platform?
def self.java_platform?
RUBY_PLATFORM == "java"
end
##
# Load +plugins+ as Ruby files
@ -1243,7 +1265,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
#
def register_default_spec(spec)
new_format = Gem.default_gems_use_full_paths? || spec.require_paths.any? {|path| spec.files.any? {|f| f.start_with? path } }
new_format = spec.require_paths.any? {|path| spec.files.any? {|f| f.start_with? path } }
if new_format
prefix_group = spec.require_paths.map {|f| f + "/"}.join("|")

Просмотреть файл

@ -104,7 +104,7 @@ extensions will be restored.
end.flatten
end
specs = specs.select{|spec| RUBY_ENGINE == spec.platform || Gem::Platform.local === spec.platform }
specs = specs.select{|spec| RUBY_ENGINE == spec.platform || Gem::Platform.local === spec.platform || spec.platform == Gem::Platform::RUBY }
if specs.to_a.empty?
raise Gem::Exception,

Просмотреть файл

@ -78,47 +78,59 @@ is too hard to use.
end
def execute
exit_code = 0
if options[:args].to_a.empty? and options[:name].source.empty?
name = options[:name]
no_name = true
elsif !options[:name].source.empty?
name = Array(options[:name])
else
args = options[:args].to_a
name = options[:exact] ? args.map{|arg| /\A#{Regexp.escape(arg)}\Z/ } : args.map{|arg| /#{arg}/i }
gem_names = Array(options[:name])
if !args.empty?
gem_names = options[:exact] ? args.map{|arg| /\A#{Regexp.escape(arg)}\Z/ } : args.map{|arg| /#{arg}/i }
end
prerelease = options[:prerelease]
terminate_interaction(check_installed_gems(gem_names)) if check_installed_gems?
unless options[:installed].nil?
if no_name
alert_error "You must specify a gem name"
exit_code |= 4
elsif name.count > 1
alert_error "You must specify only ONE gem!"
exit_code |= 4
else
installed = installed? name.first, options[:version]
installed = !installed unless options[:installed]
if installed
say "true"
else
say "false"
exit_code |= 1
end
end
terminate_interaction exit_code
end
names = Array(name)
names.each { |n| show_gems n, prerelease }
gem_names.each { |n| show_gems(n) }
end
private
def check_installed_gems(gem_names)
exit_code = 0
if args.empty? && !gem_name?
alert_error "You must specify a gem name"
exit_code = 4
elsif gem_names.count > 1
alert_error "You must specify only ONE gem!"
exit_code = 4
else
installed = installed?(gem_names.first, options[:version])
installed = !installed unless options[:installed]
say(installed)
exit_code = 1 if !installed
end
exit_code
end
def check_installed_gems?
!options[:installed].nil?
end
def gem_name?
!options[:name].source.empty?
end
def prerelease
options[:prerelease]
end
def show_prereleases?
prerelease.nil? || prerelease
end
def args
options[:args].to_a
end
def display_header(type)
if (ui.outs.tty? and Gem.configuration.verbose) or both?
say
@ -128,56 +140,57 @@ is too hard to use.
end
#Guts of original execute
def show_gems(name, prerelease)
req = Gem::Requirement.default
# TODO: deprecate for real
dep = Gem::Deprecate.skip_during { Gem::Dependency.new name, req }
dep.prerelease = prerelease
def show_gems(name)
show_local_gems(name) if local?
show_remote_gems(name) if remote?
end
if local?
if prerelease and not both?
alert_warning "prereleases are always shown locally"
end
def show_local_gems(name, req = Gem::Requirement.default)
display_header("LOCAL")
display_header 'LOCAL'
specs = Gem::Specification.find_all do |s|
s.name =~ name and req =~ s.version
end
spec_tuples = specs.map do |spec|
[spec.name_tuple, spec]
end
output_query_results spec_tuples
specs = Gem::Specification.find_all do |s|
s.name =~ name and req =~ s.version
end
if remote?
display_header 'REMOTE'
dep = Gem::Deprecate.skip_during { Gem::Dependency.new name, req }
specs.select! do |s|
dep.match?(s.name, s.version, show_prereleases?)
end
fetcher = Gem::SpecFetcher.fetcher
spec_tuples = specs.map do |spec|
[spec.name_tuple, spec]
end
type = if options[:all]
if options[:prerelease]
:complete
else
:released
end
elsif options[:prerelease]
:prerelease
else
:latest
end
output_query_results(spec_tuples)
end
if name.respond_to?(:source) && name.source.empty?
spec_tuples = fetcher.detect(type) { true }
def show_remote_gems(name)
display_header("REMOTE")
fetcher = Gem::SpecFetcher.fetcher
spec_tuples = if name.respond_to?(:source) && name.source.empty?
fetcher.detect(specs_type) { true }
else
fetcher.detect(specs_type) do |name_tuple|
name === name_tuple.name
end
end
output_query_results(spec_tuples)
end
def specs_type
if options[:all]
if options[:prerelease]
:complete
else
spec_tuples = fetcher.detect(type) do |name_tuple|
name === name_tuple.name
end
:released
end
output_query_results spec_tuples
elsif options[:prerelease]
:prerelease
else
:latest
end
end
@ -235,7 +248,7 @@ is too hard to use.
name_tuple, spec = detail_tuple
spec = spec.fetch_spec name_tuple if spec.respond_to? :fetch_spec
spec = spec.fetch_spec(name_tuple)if spec.respond_to?(:fetch_spec)
entry << "\n"
@ -285,8 +298,8 @@ is too hard to use.
entry = [name_tuples.first.name]
entry_versions entry, name_tuples, platforms, specs
entry_details entry, detail_tuple, specs, platforms
entry_versions(entry, name_tuples, platforms, specs)
entry_details(entry, detail_tuple, specs, platforms)
entry.join
end
@ -337,12 +350,13 @@ is too hard to use.
if platforms.length == 1
title = platforms.values.length == 1 ? 'Platform' : 'Platforms'
entry << " #{title}: #{platforms.values.sort.join ', '}\n"
entry << " #{title}: #{platforms.values.sort.join(', ')}\n"
else
entry << " Platforms:\n"
platforms.sort_by do |version,|
version
end.each do |version, pls|
sorted_platforms = platforms.sort_by { |version,| version }
sorted_platforms.each do |version, pls|
label = " #{version}: "
data = format_text pls.sort.join(', '), 68, label.length
data[0, label.length] = label

Просмотреть файл

@ -429,7 +429,7 @@ By default, this RubyGems will install gem as:
Dir.chdir("bundler") do
built_gem = Gem::Package.build(bundler_spec)
begin
installer = Gem::Installer.at(built_gem, env_shebang: options[:env_shebang], install_as_default: true, bin_dir: bin_dir, wrappers: true)
installer = Gem::Installer.at(built_gem, env_shebang: options[:env_shebang], format_executable: options[:format_executable], install_as_default: true, bin_dir: bin_dir, wrappers: true)
installer.install
ensure
FileUtils.rm_f built_gem

Просмотреть файл

@ -254,9 +254,7 @@ command to remove old versions.
def update_rubygems_arguments # :nodoc:
args = []
args << '--prefix' << Gem.prefix if Gem.prefix
# TODO use --document for >= 1.9 , --no-rdoc --no-ri < 1.9
args << '--no-rdoc' unless options[:document].include? 'rdoc'
args << '--no-ri' unless options[:document].include? 'ri'
args << '--no-document' unless options[:document].include?('rdoc') || options[:document].include?('ri')
args << '--no-format-executable' if options[:no_format_executable]
args << '--previous-version' << Gem::VERSION if
options[:system] == true or

Просмотреть файл

@ -7,9 +7,6 @@
module Kernel
# REFACTOR: This should be pulled out into some kind of hacks file.
remove_method :gem if 'method' == defined? gem # from gem_prelude.rb on 1.9
##
# Use Kernel#gem to activate a specific version of +gem_name+.
#

Просмотреть файл

@ -147,13 +147,6 @@ module Gem
File.join Gem.user_home, ".gem", "gem-public_cert.pem"
end
##
# Whether to expect full paths in default gems - true for non-MRI
# ruby implementations
def self.default_gems_use_full_paths?
ruby_engine != 'ruby'
end
##
# Install extensions into lib as well as into the extension directory.

Просмотреть файл

@ -20,7 +20,7 @@ class Gem::Ext::RakeBuilder < Gem::Ext::Builder
rake = rake.shellsplit
else
begin
rake = [Gem.ruby, "-rrubygems", Gem.bin_path('rake', 'rake')]
rake = [Gem.ruby, "-I#{File.expand_path("..", __dir__)}", "-rrubygems", Gem.bin_path('rake', 'rake')]
rescue Gem::Exception
rake = [Gem.default_exec_format % 'rake']
end

Просмотреть файл

@ -66,44 +66,9 @@ end
class Gem::InstallerTestCase < Gem::TestCase
##
# Creates the following instance variables:
#
# @spec::
# a spec named 'a', intended for regular installs
# @user_spec::
# a spec named 'b', intended for user installs
#
# @gem::
# the path to a built gem from @spec
# @user_spec::
# the path to a built gem from @user_spec
#
# @installer::
# a Gem::Installer for the @spec that installs into @gemhome
# @user_installer::
# a Gem::Installer for the @user_spec that installs into Gem.user_dir
def setup
super
@spec = quick_gem 'a' do |spec|
util_make_exec spec
end
@user_spec = quick_gem 'b' do |spec|
util_make_exec spec
end
util_build_gem @spec
util_build_gem @user_spec
@gem = @spec.cache_file
@user_gem = @user_spec.cache_file
@installer = util_installer @spec, @gemhome
@user_installer = util_installer @user_spec, Gem.user_dir, :user
Gem::Installer.path_warning = false
end
@ -135,6 +100,83 @@ class Gem::InstallerTestCase < Gem::TestCase
end
end
##
# Creates the following instance variables:
#
# @spec::
# a spec named 'a', intended for regular installs
#
# @gem::
# the path to a built gem from @spec
#
# And returns a Gem::Installer for the @spec that installs into @gemhome
def setup_base_installer
@gem = setup_base_gem
util_installer @spec, @gemhome
end
##
# Creates the following instance variables:
#
# @spec::
# a spec named 'a', intended for regular installs
#
# And returns a gem built for the @spec
def setup_base_gem
@spec = setup_base_spec
util_build_gem @spec
@spec.cache_file
end
##
# Sets up a generic specification for testing the rubygems installer
#
# And returns it
def setup_base_spec
quick_gem 'a' do |spec|
util_make_exec spec
end
end
##
# Creates the following instance variables:
#
# @spec::
# a spec named 'a', intended for regular installs
# @user_spec::
# a spec named 'b', intended for user installs
#
# @gem::
# the path to a built gem from @spec
# @user_gem::
# the path to a built gem from @user_spec
#
# And returns a Gem::Installer for the @user_spec that installs into Gem.user_dir
def setup_base_user_installer
@user_spec = quick_gem 'b' do |spec|
util_make_exec spec
end
util_build_gem @user_spec
@user_gem = @user_spec.cache_file
util_installer @user_spec, Gem.user_dir, :user
end
##
# Sets up the base @gem, builds it and returns an installer for it.
#
def util_setup_installer
@gem = setup_base_gem
util_setup_gem
end
##
# Builds the @spec gem and returns an installer for it. The built gem
# includes:
@ -143,7 +185,7 @@ class Gem::InstallerTestCase < Gem::TestCase
# lib/code.rb
# ext/a/mkrf_conf.rb
def util_setup_gem(ui = @ui) # HACK fix use_ui to make this automatic
def util_setup_gem(ui = @ui)
@spec.files << File.join('lib', 'code.rb')
@spec.extensions << File.join('ext', 'a', 'mkrf_conf.rb')
@ -175,7 +217,7 @@ class Gem::InstallerTestCase < Gem::TestCase
end
end
@installer = Gem::Installer.at @gem
Gem::Installer.at @gem
end
##

Просмотреть файл

@ -107,8 +107,8 @@ class Gem::Package::TarHeader
new :name => fields.shift,
:mode => strict_oct(fields.shift),
:uid => strict_oct(fields.shift),
:gid => strict_oct(fields.shift),
:uid => oct_or_256based(fields.shift),
:gid => oct_or_256based(fields.shift),
:size => strict_oct(fields.shift),
:mtime => strict_oct(fields.shift),
:checksum => strict_oct(fields.shift),
@ -130,6 +130,15 @@ class Gem::Package::TarHeader
raise ArgumentError, "#{str.inspect} is not an octal string"
end
def self.oct_or_256based(str)
# \x80 flags a positive 256-based number
# \ff flags a negative 256-based number
# In case we have a match, parse it as a signed binary value
# in big-endian order, except that the high-order bit is ignored.
return str.unpack('N2').last if str =~ /\A[\x80\xff]/n
strict_oct(str)
end
##
# Creates a new TarHeader using +vals+

Просмотреть файл

@ -173,7 +173,7 @@ class Gem::RemoteFetcher
path = source_uri.path
path = File.dirname(path) if File.extname(path) == '.gem'
remote_gem_path = correct_for_windows_path(File.join(path, 'gems', gem_file_name))
remote_gem_path = Gem::Util.correct_for_windows_path(File.join(path, 'gems', gem_file_name))
FileUtils.cp(remote_gem_path, local_gem_path)
rescue Errno::EACCES
@ -210,7 +210,7 @@ class Gem::RemoteFetcher
# File Fetcher. Dispatched by +fetch_path+. Use it instead.
def fetch_file(uri, *_)
Gem.read_binary correct_for_windows_path uri.path
Gem.read_binary Gem::Util.correct_for_windows_path uri.path
end
##
@ -317,14 +317,6 @@ class Gem::RemoteFetcher
response['content-length'].to_i
end
def correct_for_windows_path(path)
if path[0].chr == '/' && path[1].chr =~ /[a-z]/i && path[2].chr == ':'
path[1..-1]
else
path
end
end
##
# Performs a Net::HTTP request of type +request_class+ on +uri+ returning
# a Net::HTTP response object. request maintains a table of persistent

Просмотреть файл

@ -76,9 +76,7 @@ class Gem::Request::ConnectionPools # :nodoc:
end
def net_http_args(uri, proxy_uri)
# URI::Generic#hostname was added in ruby 1.9.3, use it if exists, otherwise
# don't support IPv6 literals and use host.
hostname = uri.respond_to?(:hostname) ? uri.hostname : uri.host
hostname = uri.hostname
net_http_args = [hostname, uri.port]
no_proxy = get_no_proxy_from_env

Просмотреть файл

@ -246,7 +246,7 @@ class Gem::Resolver
sources.each do |source|
groups[source].
sort_by { |spec| [spec.version, Gem::Platform.local =~ spec.platform ? 1 : 0] }.
map { |spec| ActivationRequest.new spec, dependency, [] }.
map { |spec| ActivationRequest.new spec, dependency }.
each { |activation_request| activation_requests << activation_request }
end

Просмотреть файл

@ -18,14 +18,10 @@ class Gem::Resolver::ActivationRequest
##
# Creates a new ActivationRequest that will activate +spec+. The parent
# +request+ is used to provide diagnostics in case of conflicts.
#
# +others_possible+ indicates that other specifications may also match this
# activation request.
def initialize(spec, request, others_possible = true)
def initialize(spec, request)
@spec = spec
@request = request
@others_possible = others_possible
end
def ==(other) # :nodoc:
@ -90,21 +86,8 @@ class Gem::Resolver::ActivationRequest
end
def inspect # :nodoc:
others =
case @others_possible
when true then # TODO remove at RubyGems 3
' (others possible)'
when false then # TODO remove at RubyGems 3
nil
else
unless @others_possible.empty?
others = @others_possible.map { |s| s.full_name }
" (others possible: #{others.join ', '})"
end
end
'#<%s for %p from %s%s>' % [
self.class, @spec, @request, others
'#<%s for %p from %s>' % [
self.class, @spec, @request
]
end
@ -131,19 +114,6 @@ class Gem::Resolver::ActivationRequest
@spec.name
end
##
# Indicate if this activation is one of a set of possible
# requests for the same Dependency request.
def others_possible?
case @others_possible
when true, false then
@others_possible
else
not @others_possible.empty?
end
end
##
# Return the ActivationRequest that contained the dependency
# that we were activated for.
@ -160,19 +130,6 @@ class Gem::Resolver::ActivationRequest
q.breakable
q.text ' for '
q.pp @request
case @others_possible
when false then
when true then
q.breakable
q.text 'others possible'
else
unless @others_possible.empty?
q.breakable
q.text 'others '
q.pp @others_possible.map { |s| s.full_name }
end
end
end
end

Просмотреть файл

@ -743,9 +743,6 @@ class Gem::Specification < Gem::BasicSpecification
def self._all # :nodoc:
unless defined?(@@all) && @@all
@@all = stubs.map(&:to_spec)
if @@all.any?(&:nil?) # TODO: remove once we're happy
raise "pid: #{$$} nil spec! included in #{stubs.inspect}"
end
# After a reset, make sure already loaded specs
# are still marked as activated.
@ -896,7 +893,6 @@ class Gem::Specification < Gem::BasicSpecification
# -- wilsonb
def self.all=(specs)
raise "nil spec!" if specs.any?(&:nil?) # TODO: remove once we're happy
@@stubs_by_name = specs.group_by(&:name)
@@all = @@stubs = specs
end
@ -1498,16 +1494,7 @@ class Gem::Specification < Gem::BasicSpecification
paths = full_require_paths
# gem directories must come after -I and ENV['RUBYLIB']
insert_index = Gem.load_path_insert_index
if insert_index
# gem directories must come after -I and ENV['RUBYLIB']
$LOAD_PATH.insert(insert_index, *paths)
else
# we are probably testing in core, -I and RUBYLIB don't apply
$LOAD_PATH.unshift(*paths)
end
Gem.add_to_load_path(*paths)
end
##
@ -1927,8 +1914,7 @@ class Gem::Specification < Gem::BasicSpecification
end
def gems_dir
# TODO: this logic seems terribly broken, but tests fail if just base_dir
@gems_dir ||= File.join(loaded_from && base_dir || Gem.dir, "gems")
@gems_dir ||= File.join(base_dir, "gems")
end
##

Просмотреть файл

@ -1,5 +1,4 @@
# frozen_string_literal: true
# TODO: $SAFE = 1
require 'rubygems'
@ -27,13 +26,6 @@ begin
rescue LoadError
end
# We have to load these up front because otherwise we'll try to load
# them while we're testing rubygems, and thus we can't actually load them.
unless Gem::Dependency.new('rdoc', '>= 3.10').matching_specs.empty?
gem 'rdoc'
gem 'json'
end
require 'bundler'
require 'minitest/autorun'
@ -91,8 +83,6 @@ end
# gem-related behavior in a sandbox. Through RubyGemTestCase you can install
# and uninstall gems, fetch remote gems through a stub fetcher and be assured
# your normal set of gems is not affected.
#
# Tests are always run at a safe level of 1.
class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Unit::TestCase)
@ -152,6 +142,28 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
end
end
##
# Sets the vendordir entry in RbConfig::CONFIG to +value+ and restores the
# original value when the block ends
#
def vendordir(value)
vendordir = RbConfig::CONFIG['vendordir']
if value
RbConfig::CONFIG['vendordir'] = value
else
RbConfig::CONFIG.delete 'vendordir'
end
yield
ensure
if vendordir
RbConfig::CONFIG['vendordir'] = vendordir
else
RbConfig::CONFIG.delete 'vendordir'
end
end
# TODO: move to minitest
def refute_path_exists(path, msg = nil)
msg = message(msg) { "Expected path '#{path}' to not exist" }
@ -222,8 +234,6 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
@@project_dir = Dir.pwd.untaint unless defined?(@@project_dir)
@@initial_reset = false
##
# #setup prepares a sandboxed location to install gems. All installs are
# directed to a temporary directory. All install plugins are removed.
@ -231,24 +241,11 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
# If the +RUBY+ environment variable is set the given path is used for
# Gem::ruby. The local platform is set to <tt>i386-mswin32</tt> for Windows
# or <tt>i686-darwin8.10.1</tt> otherwise.
#
# If the +KEEP_FILES+ environment variable is set the files will not be
# removed from <tt>/tmp/test_rubygems_#{$$}.#{Time.now.to_i}</tt>.
def setup
super
@orig_gem_home = ENV['GEM_HOME']
@orig_gem_path = ENV['GEM_PATH']
@orig_gem_vendor = ENV['GEM_VENDOR']
@orig_gem_spec_cache = ENV['GEM_SPEC_CACHE']
@orig_rubygems_gemdeps = ENV['RUBYGEMS_GEMDEPS']
@orig_bundle_gemfile = ENV['BUNDLE_GEMFILE']
@orig_rubygems_host = ENV['RUBYGEMS_HOST']
ENV.keys.find_all { |k| k.start_with?('GEM_REQUIREMENT_') }.each do |k|
ENV.delete k
end
@orig_gem_env_requirements = ENV.to_hash
@orig_env = ENV.to_hash
ENV['GEM_VENDOR'] = nil
ENV['SOURCE_DATE_EPOCH'] = nil
@ -256,36 +253,20 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
@current_dir = Dir.pwd
@fetcher = nil
Bundler.ui = Bundler::UI::Silent.new
@back_ui = Gem::DefaultUserInteraction.ui
@ui = Gem::MockGemUi.new
# This needs to be a new instance since we call use_ui(@ui) when we want to
# capture output
Gem::DefaultUserInteraction.ui = Gem::MockGemUi.new
tmpdir = File.expand_path Dir.tmpdir
tmpdir = File.realpath Dir.tmpdir
tmpdir.untaint
if ENV['KEEP_FILES']
@tempdir = File.join(tmpdir, "test_rubygems_#{$$}.#{Time.now.to_i}")
else
@tempdir = File.join(tmpdir, "test_rubygems_#{$$}")
end
@tempdir = File.join(tmpdir, "test_rubygems_#{$$}")
@tempdir.untaint
FileUtils.mkdir_p @tempdir
# This makes the tempdir consistent on OS X.
# File.expand_path Dir.tmpdir #=> "/var/..."
# Dir.chdir Dir.tmpdir do File.expand_path '.' end #=> "/private/var/..."
# TODO use File#realpath above instead of #expand_path once 1.8 support is
# dropped.
Dir.chdir @tempdir do
@tempdir = File.expand_path '.'
@tempdir.untaint
end
# This makes the tempdir consistent on Windows.
# Dir.tmpdir may return short path name, but Dir[Dir.tmpdir] returns long
# path name. https://bugs.ruby-lang.org/issues/10819
@ -343,25 +324,21 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
@default_dir = File.join @tempdir, 'default'
@default_spec_dir = File.join @default_dir, "specifications", "default"
Gem.instance_variable_set :@default_dir, @default_dir
if Gem.java_platform?
@orig_default_gem_home = RbConfig::CONFIG['default_gem_home']
RbConfig::CONFIG['default_gem_home'] = @default_dir
else
Gem.instance_variable_set(:@default_dir, @default_dir)
end
FileUtils.mkdir_p @default_spec_dir
# We use Gem::Specification.reset the first time only so that if there
# are unresolved deps that leak into the whole test suite, they're at least
# reported once.
if @@initial_reset
Gem::Specification.unresolved_deps.clear # done to avoid cross-test warnings
else
@@initial_reset = true
Gem::Specification.reset
end
Gem::Specification.unresolved_deps.clear
Gem.use_paths(@gemhome)
Gem::Security.reset
Gem.loaded_specs.clear
Gem.clear_default_specs
Gem::Specification.unresolved_deps.clear
Bundler.reset!
Gem.configuration.verbose = true
@ -395,7 +372,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
##
# #teardown restores the process to its original state and removes the
# tempdir unless the +KEEP_FILES+ environment variable was set.
# tempdir
def teardown
$LOAD_PATH.replace @orig_LOAD_PATH if @orig_LOAD_PATH
@ -420,33 +397,18 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
Dir.chdir @current_dir
FileUtils.rm_rf @tempdir unless ENV['KEEP_FILES']
FileUtils.rm_rf @tempdir
ENV.clear
@orig_gem_env_requirements.each do |k,v|
ENV[k] = v
end
ENV['GEM_HOME'] = @orig_gem_home
ENV['GEM_PATH'] = @orig_gem_path
ENV['GEM_VENDOR'] = @orig_gem_vendor
ENV['GEM_SPEC_CACHE'] = @orig_gem_spec_cache
ENV['RUBYGEMS_GEMDEPS'] = @orig_rubygems_gemdeps
ENV['BUNDLE_GEMFILE'] = @orig_bundle_gemfile
ENV['RUBYGEMS_HOST'] = @orig_rubygems_host
ENV.replace(@orig_env)
Gem.ruby = @orig_ruby if @orig_ruby
if @orig_ENV_HOME
ENV['HOME'] = @orig_ENV_HOME
if Gem.java_platform?
RbConfig::CONFIG['default_gem_home'] = @orig_default_gem_home
else
ENV.delete 'HOME'
Gem.instance_variable_set :@default_dir, nil
end
Gem.instance_variable_set :@default_dir, nil
ENV['GEM_PRIVATE_KEY_PASSPHRASE'] = @orig_gem_private_key_passphrase
Gem::Specification._clear_load_cache
Gem::Specification.unresolved_deps.clear
Gem::refresh
@ -593,22 +555,6 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
end.new(spec.name, :executables => true, :user_install => true).uninstall
end
##
# creates a temporary directory with hax
# TODO: deprecate and remove
def create_tmpdir
tmpdir = nil
Dir.chdir Dir.tmpdir do
tmpdir = Dir.pwd
end # HACK OSX /private/tmp
tmpdir = File.join tmpdir, "test_rubygems_#{$$}"
FileUtils.mkdir_p tmpdir
return tmpdir
end
##
# Enables pretty-print for all tests
@ -686,21 +632,13 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
io.write spec.to_ruby_for_cache
end
spec.loaded_from = spec.loaded_from = written_path
spec.loaded_from = written_path
Gem::Specification.reset
return spec
end
##
# TODO: remove in RubyGems 4.0
def quick_spec(name, version = '2') # :nodoc:
util_spec name, version
end
deprecate :quick_spec, :util_spec, 2018, 12
##
# Builds a gem from +spec+ and places it in <tt>File.join @gemhome,
# 'cache'</tt>. Automatically creates files based on +spec.files+
@ -744,11 +682,6 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
Gem::Specification.reset
end
def util_clear_default_gems
FileUtils.rm_rf @default_spec_dir
FileUtils.mkdir @default_spec_dir
end
##
# Install the provided specs
@ -802,52 +735,6 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
$LOADED_FEATURES.replace old_loaded_features
end
##
# new_spec is deprecated as it is never used.
#
# TODO: remove in RubyGems 4.0
def new_spec(name, version, deps = nil, *files) # :nodoc:
require 'rubygems/specification'
spec = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = name
s.version = version
s.author = 'A User'
s.email = 'example@example.com'
s.homepage = 'http://example.com'
s.summary = "this is a summary"
s.description = "This is a test description"
Array(deps).each do |n, req|
s.add_dependency n, (req || '>= 0')
end
s.files.push(*files) unless files.empty?
yield s if block_given?
end
spec.loaded_from = spec.spec_file
unless files.empty?
write_file spec.spec_file do |io|
io.write spec.to_ruby_for_cache
end
util_build_gem spec
cache_file = File.join @tempdir, 'gems', "#{spec.full_name}.gem"
FileUtils.mkdir_p File.dirname cache_file
FileUtils.mv spec.cache_file, cache_file
FileUtils.rm spec.spec_file
end
spec
end
deprecate :new_spec, :none, 2018, 12
def new_default_spec(name, version, deps = nil, *files)
spec = util_spec name, version, deps
@ -910,8 +797,6 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni
FileUtils.rm spec.spec_file
end
Gem::Specification.reset
return spec
end
@ -1060,31 +945,6 @@ Also, a list:
platform
end
##
# Sets up a fake fetcher using the gems from #util_make_gems. Optionally
# additional +prerelease+ gems may be included.
#
# Gems created by this method may be fetched using Gem::RemoteFetcher.
def util_setup_fake_fetcher(prerelease = false)
require 'zlib'
require 'socket'
require 'rubygems/remote_fetcher'
@fetcher = Gem::FakeFetcher.new
util_make_gems(prerelease)
Gem::Specification.reset
@all_gems = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2].sort
@all_gem_names = @all_gems.map { |gem| gem.full_name }
gem_names = [@a1.full_name, @a2.full_name, @a3a.full_name, @b2.full_name]
@gem_names = gem_names.sort.join("\n")
Gem::RemoteFetcher.fetcher = @fetcher
end
##
# Add +spec+ to +@fetcher+ serving the data in the file +path+.
# +repo+ indicates which repo to make +spec+ appear to be in.
@ -1096,7 +956,6 @@ Also, a list:
##
# Sets up Gem::SpecFetcher to return information from the gems in +specs+.
# Best used with +@all_gems+ from #util_setup_fake_fetcher.
def util_setup_spec_fetcher(*specs)
all_specs = Gem::Specification.to_a + specs
@ -1163,8 +1022,7 @@ Also, a list:
end
def util_set_RUBY_VERSION(version, patchlevel = nil, revision = nil, description = nil, engine = "ruby", engine_version = nil)
if Gem.instance_variables.include? :@ruby_version or
Gem.instance_variables.include? '@ruby_version'
if Gem.instance_variables.include? :@ruby_version
Gem.send :remove_instance_variable, :@ruby_version
end
@ -1223,6 +1081,20 @@ Also, a list:
Gem.win_platform?
end
##
# Is this test being run on a Java platform?
def self.java_platform?
Gem.java_platform?
end
##
# Is this test being run on a Java platform?
def java_platform?
Gem.java_platform?
end
##
# Returns whether or not we're on a version of Ruby built with VC++ (or
# Borland) versus Cygwin, Mingw, etc.
@ -1623,10 +1495,3 @@ rescue LoadError, Gem::LoadError
end
require 'rubygems/test_utilities'
tmpdirs = []
tmpdirs << (ENV['GEM_HOME'] = Dir.mktmpdir("home"))
tmpdirs << (ENV['GEM_PATH'] = Dir.mktmpdir("path"))
pid = $$
END {tmpdirs.each {|dir| Dir.rmdir(dir)} if $$ == pid}
Gem.clear_paths
Gem.loaded_specs.clear

Просмотреть файл

@ -241,21 +241,22 @@ class Gem::TestCase::SpecFetcherSetup
def execute_operations # :nodoc:
@operations.each do |operation, *arguments|
block = arguments.pop
case operation
when :gem then
spec, gem = @test.util_gem(*arguments, &arguments.pop)
spec, gem = @test.util_gem(*arguments, &block)
write_spec spec
@gems[spec] = gem
@installed << spec
when :download then
spec, gem = @test.util_gem(*arguments, &arguments.pop)
spec, gem = @test.util_gem(*arguments, &block)
@gems[spec] = gem
@downloaded << spec
when :spec then
spec = @test.util_spec(*arguments, &arguments.pop)
spec = @test.util_spec(*arguments, &block)
write_spec spec

Просмотреть файл

@ -44,29 +44,10 @@ module Gem::Util
end
##
# This calls IO.popen where it accepts an array for a +command+ (Ruby 1.9+)
# and implements an IO.popen-like behavior where it does not accept an array
# for a command.
# This calls IO.popen and reads the result
def self.popen(*command)
IO.popen command, &:read
rescue TypeError # ruby 1.8 only supports string command
r, w = IO.pipe
pid = fork do
STDIN.close
STDOUT.reopen w
exec(*command)
end
w.close
begin
return r.read
ensure
Process.wait pid
end
end
##
@ -80,26 +61,7 @@ module Gem::Util
else
cmds = command.dup
end
return system(*(cmds << opt))
rescue TypeError
@silent_mutex ||= Mutex.new
@silent_mutex.synchronize do
begin
stdout = STDOUT.dup
stderr = STDERR.dup
STDOUT.reopen IO::NULL, 'w'
STDERR.reopen IO::NULL, 'w'
return system(*command)
ensure
STDOUT.reopen stdout
STDERR.reopen stderr
stdout.close
stderr.close
end
end
system(*(cmds << opt))
end
##
@ -130,4 +92,16 @@ module Gem::Util
end
end
##
# Corrects +path+ (usually returned by `URI.parse().path` on Windows), that
# comes with a leading slash.
def self.correct_for_windows_path(path)
if path[0].chr == '/' && path[1].chr =~ /[a-z]/i && path[2].chr == ':'
path[1..-1]
else
path
end
end
end

Просмотреть файл

@ -465,55 +465,43 @@ class TestGem < Gem::TestCase
end
def test_default_path
orig_vendordir = RbConfig::CONFIG['vendordir']
RbConfig::CONFIG['vendordir'] = File.join @tempdir, 'vendor'
vendordir(File.join(@tempdir, 'vendor')) do
FileUtils.rm_rf Gem.user_home
FileUtils.rm_rf Gem.user_home
expected = [Gem.default_dir]
expected = [Gem.default_dir]
assert_equal expected, Gem.default_path
ensure
RbConfig::CONFIG['vendordir'] = orig_vendordir
assert_equal expected, Gem.default_path
end
end
def test_default_path_missing_vendor
orig_vendordir = RbConfig::CONFIG['vendordir']
RbConfig::CONFIG.delete 'vendordir'
vendordir(nil) do
FileUtils.rm_rf Gem.user_home
FileUtils.rm_rf Gem.user_home
expected = [Gem.default_dir]
expected = [Gem.default_dir]
assert_equal expected, Gem.default_path
ensure
RbConfig::CONFIG['vendordir'] = orig_vendordir
assert_equal expected, Gem.default_path
end
end
def test_default_path_user_home
orig_vendordir = RbConfig::CONFIG['vendordir']
RbConfig::CONFIG['vendordir'] = File.join @tempdir, 'vendor'
vendordir(File.join(@tempdir, 'vendor')) do
expected = [Gem.user_dir, Gem.default_dir]
expected = [Gem.user_dir, Gem.default_dir]
assert_equal expected, Gem.default_path
ensure
RbConfig::CONFIG['vendordir'] = orig_vendordir
assert_equal expected, Gem.default_path
end
end
def test_default_path_vendor_dir
orig_vendordir = RbConfig::CONFIG['vendordir']
RbConfig::CONFIG['vendordir'] = File.join @tempdir, 'vendor'
vendordir(File.join(@tempdir, 'vendor')) do
FileUtils.mkdir_p Gem.vendor_dir
FileUtils.mkdir_p Gem.vendor_dir
FileUtils.rm_rf Gem.user_home
FileUtils.rm_rf Gem.user_home
expected = [Gem.default_dir, Gem.vendor_dir]
expected = [Gem.default_dir, Gem.vendor_dir]
assert_equal expected, Gem.default_path
ensure
RbConfig::CONFIG['vendordir'] = orig_vendordir
assert_equal expected, Gem.default_path
end
end
def test_self_default_sources
@ -706,7 +694,7 @@ class TestGem < Gem::TestCase
assert_equal expected, Gem.find_files('sff/discover').sort
assert_equal expected, Gem.find_files('sff/**.rb').sort, '[ruby-core:31730]'
ensure
assert_equal cwd, actual_load_path.shift
assert_equal cwd, actual_load_path.shift unless Gem.java_platform?
end
def test_self_find_latest_files
@ -1232,10 +1220,12 @@ class TestGem < Gem::TestCase
refute Gem.try_activate 'nonexistent'
end
expected = "Ignoring ext-1 because its extensions are not built. " +
"Try: gem pristine ext --version 1\n"
unless Gem.java_platform?
expected = "Ignoring ext-1 because its extensions are not built. " +
"Try: gem pristine ext --version 1\n"
assert_equal expected, err
assert_equal expected, err
end
end
def test_self_use_paths_with_nils
@ -1303,7 +1293,6 @@ class TestGem < Gem::TestCase
end
def test_self_needs
util_clear_gems
a = util_spec "a", "1"
b = util_spec "b", "1", "c" => nil
c = util_spec "c", "2"
@ -1322,7 +1311,6 @@ class TestGem < Gem::TestCase
def test_self_needs_picks_up_unresolved_deps
save_loaded_features do
util_clear_gems
a = util_spec "a", "1"
b = util_spec "b", "1", "c" => nil
c = util_spec "c", "2"
@ -1364,11 +1352,13 @@ class TestGem < Gem::TestCase
end
def test_self_vendor_dir
expected =
File.join RbConfig::CONFIG['vendordir'], 'gems',
RbConfig::CONFIG['ruby_version']
vendordir(File.join(@tempdir, 'vendor')) do
expected =
File.join RbConfig::CONFIG['vendordir'], 'gems',
RbConfig::CONFIG['ruby_version']
assert_equal expected, Gem.vendor_dir
assert_equal expected, Gem.vendor_dir
end
end
def test_self_vendor_dir_ENV_GEM_VENDOR
@ -1379,12 +1369,9 @@ class TestGem < Gem::TestCase
end
def test_self_vendor_dir_missing
orig_vendordir = RbConfig::CONFIG['vendordir']
RbConfig::CONFIG.delete 'vendordir'
assert_nil Gem.vendor_dir
ensure
RbConfig::CONFIG['vendordir'] = orig_vendordir
vendordir(nil) do
assert_nil Gem.vendor_dir
end
end
def test_load_plugins
@ -1514,8 +1501,6 @@ class TestGem < Gem::TestCase
end
def test_auto_activation_of_specific_gemdeps_file
util_clear_gems
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"
@ -1538,8 +1523,6 @@ class TestGem < Gem::TestCase
end
def test_auto_activation_of_used_gemdeps_file
util_clear_gems
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"
@ -1571,7 +1554,7 @@ class TestGem < Gem::TestCase
end
def test_looks_for_gemdeps_files_automatically_on_start
util_clear_gems
skip "Requiring bundler messes things up" if Gem.java_platform?
a = util_spec "a", "1", nil, "lib/a.rb"
b = util_spec "b", "1", nil, "lib/b.rb"
@ -1607,7 +1590,7 @@ class TestGem < Gem::TestCase
end
def test_looks_for_gemdeps_files_automatically_on_start_in_parent_dir
util_clear_gems
skip "Requiring bundler messes things up" if Gem.java_platform?
a = util_spec "a", "1", nil, "lib/a.rb"
b = util_spec "b", "1", nil, "lib/b.rb"
@ -1674,33 +1657,6 @@ class TestGem < Gem::TestCase
assert_nil Gem.find_unresolved_default_spec("README")
end
def test_default_gems_use_full_paths
begin
if defined?(RUBY_ENGINE)
engine = RUBY_ENGINE
Object.send :remove_const, :RUBY_ENGINE
end
Object.const_set :RUBY_ENGINE, 'ruby'
refute Gem.default_gems_use_full_paths?
ensure
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, engine if engine
end
begin
if defined?(RUBY_ENGINE)
engine = RUBY_ENGINE
Object.send :remove_const, :RUBY_ENGINE
end
Object.const_set :RUBY_ENGINE, 'jruby'
assert Gem.default_gems_use_full_paths?
ensure
Object.send :remove_const, :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, engine if engine
end
end
def test_use_gemdeps
gem_deps_file = 'gem.deps.rb'.untaint
spec = util_spec 'a', 1

Просмотреть файл

@ -281,7 +281,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_build_signed_gem
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
skip 'openssl is missing' unless defined?(OpenSSL::SSL) && !java_platform?
trust_dir = Gem::Security.trust_dir
@ -308,7 +308,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_build_signed_gem_with_cert_expiration_length_days
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
skip 'openssl is missing' unless defined?(OpenSSL::SSL) && !java_platform?
gem_path = File.join Gem.user_home, ".gem"
Dir.mkdir gem_path
@ -352,7 +352,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_build_auto_resign_cert
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
skip 'openssl is missing' unless defined?(OpenSSL::SSL) && !java_platform?
gem_path = File.join Gem.user_home, ".gem"
Dir.mkdir gem_path
@ -389,7 +389,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
output = @ui.output.split "\n"
assert_equal "INFO: Your certificate has expired, trying to re-sign it...", output.shift
assert_equal "INFO: Your cert: #{tmp_expired_cert_file } has been auto re-signed with the key: #{tmp_private_key_file}", output.shift
assert_match /INFO: Your expired cert will be located at: .+\Wgem-public_cert\.pem\.expired\.[0-9]+/, output.shift
assert_match(/INFO: Your expired cert will be located at: .+\Wgem-public_cert\.pem\.expired\.[0-9]+/, output.shift)
end
end

Просмотреть файл

@ -6,6 +6,10 @@ unless defined?(OpenSSL::SSL)
warn 'Skipping `gem cert` tests. openssl not found.'
end
if Gem.java_platform?
warn 'Skipping `gem cert` tests on jruby.'
end
class TestGemCommandsCertCommand < Gem::TestCase
ALTERNATE_CERT = load_cert 'alternate'
@ -793,4 +797,4 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
e.message
end
end if defined?(OpenSSL::SSL)
end if defined?(OpenSSL::SSL) && !Gem.java_platform?

Просмотреть файл

@ -459,7 +459,28 @@ pl (1 i386-linux)
EOF
assert_equal expected, @stub_ui.output
assert_equal "WARNING: prereleases are always shown locally\n", @stub_ui.error
end
def test_execute_no_prerelease_local
spec_fetcher do |fetcher|
fetcher.legacy_platform
end
@cmd.handle_options %w[-l --no-prerelease]
use_ui @stub_ui do
@cmd.execute
end
expected = <<-EOF
*** LOCAL GEMS ***
a (2, 1)
pl (1 i386-linux)
EOF
assert_equal expected, @stub_ui.output
end
def test_execute_remote
@ -569,7 +590,7 @@ pl (1 i386-linux)
@cmd.options[:domain] = :remote
use_ui @stub_ui do
@cmd.send :show_gems, /a/i, false
@cmd.send :show_gems, /a/i
end
assert_match %r%^a %, @stub_ui.output

Просмотреть файл

@ -189,7 +189,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
assert_path_exists File.join(bin_dir, "#{e}.bat")
end
assert_path_exists File.join bin_dir, e
assert_path_exists File.join bin_dir, Gem.default_exec_format % e
end
default_dir = Gem::Specification.default_specifications_dir
@ -323,4 +323,4 @@ class TestGemCommandsSetupCommand < Gem::TestCase
@ui.outs.set_encoding @default_external if @default_external
end
end
end unless Gem.java_platform?

Просмотреть файл

@ -7,11 +7,17 @@ class TestGemCommandsSourcesCommand < Gem::TestCase
def setup
super
spec_fetcher
@cmd = Gem::Commands::SourcesCommand.new
@new_repo = "http://beta-gems.example.com"
@old_https_proxy_config = Gem.configuration[:http_proxy]
end
def teardown
Gem.configuration[:http_proxy] = @old_https_proxy_config
super
end
def test_initialize_proxy
@ -69,6 +75,8 @@ class TestGemCommandsSourcesCommand < Gem::TestCase
end
def test_execute_add_nonexistent_source
spec_fetcher
uri = "http://beta-gems.example.com/specs.#{@marshal_version}.gz"
@fetcher.data[uri] = proc do
raise Gem::RemoteFetcher::FetchError.new('it died', uri)
@ -92,6 +100,8 @@ Error fetching http://beta-gems.example.com:
end
def test_execute_add_redundant_source
spec_fetcher
@cmd.handle_options %W[--add #{@gem_repo}]
use_ui @ui do
@ -109,6 +119,8 @@ source #{@gem_repo} already present in the cache
end
def test_execute_add_redundant_source_trailing_slash
spec_fetcher
# Remove pre-existing gem source (w/ slash)
repo_with_slash = "http://gems.example.com/"
@cmd.handle_options %W[--remove #{repo_with_slash}]
@ -266,6 +278,8 @@ beta-gems.example.com is not a URI
end
def test_execute_remove_no_network
spec_fetcher
@cmd.handle_options %W[--remove #{@gem_repo}]
@fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do

Просмотреть файл

@ -6,19 +6,13 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
def setup
super
common_installer_setup
build_rake_in do
use_ui @ui do
@installer.install
end
end
@cmd = Gem::Commands::UninstallCommand.new
@executable = File.join(@gemhome, 'bin', 'executable')
end
def test_execute_all_named
initial_install
util_make_gems
default = new_default_spec 'default', '1'
@ -48,6 +42,8 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end
def test_execute_dependency_order
initial_install
c = quick_gem 'c' do |spec|
spec.add_dependency 'a'
end
@ -76,15 +72,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end
def test_execute_removes_executable
ui = Gem::MockGemUi.new
util_setup_gem ui
build_rake_in do
use_ui ui do
@installer.install
end
end
initial_install
if win_platform?
assert File.exist?(@executable)
@ -113,12 +101,14 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end
def test_execute_removes_formatted_executable
installer = setup_base_installer
FileUtils.rm_f @executable # Wish this didn't happen in #setup
Gem::Installer.exec_format = 'foo-%s-bar'
@installer.format_executable = true
@installer.install
installer.format_executable = true
installer.install
formatted_executable = File.join @gemhome, 'bin', 'foo-executable-bar'
assert_equal true, File.exist?(formatted_executable)
@ -137,11 +127,11 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
@gem = File.join @tempdir, @spec.file_name
FileUtils.touch @gem
util_setup_gem
installer = util_setup_gem
build_rake_in do
use_ui @ui do
@installer.install
installer.install
end
end
@ -157,10 +147,11 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end
def test_execute_with_version_leaves_non_matching_versions
initial_install
ui = Gem::MockGemUi.new
util_make_gems
util_setup_gem ui
assert_equal 3, Gem::Specification.find_all_by_name('a').length
@ -178,10 +169,11 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end
def test_execute_with_version_specified_as_colon
initial_install
ui = Gem::MockGemUi.new "y\n"
util_make_gems
util_setup_gem ui
assert_equal 3, Gem::Specification.find_all_by_name('a').length
@ -254,6 +246,8 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end
def test_execute_with_force_and_without_version_uninstalls_everything
initial_install
ui = Gem::MockGemUi.new "y\n"
a_1, = util_gem 'a', 1
@ -262,8 +256,6 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
a_3a, = util_gem 'a', '3.a'
install_gem a_3a
util_setup_gem ui
assert_equal 3, Gem::Specification.find_all_by_name('a').length
@cmd.options[:force] = true
@ -279,10 +271,11 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end
def test_execute_with_force_ignores_dependencies
initial_install
ui = Gem::MockGemUi.new
util_make_gems
util_setup_gem ui
assert Gem::Specification.find_all_by_name('dep_x').length > 0
assert Gem::Specification.find_all_by_name('x').length > 0
@ -359,20 +352,22 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
end
def test_handle_options_vendor
use_ui @ui do
@cmd.handle_options %w[--vendor]
end
vendordir(File.join(@tempdir, 'vendor')) do
use_ui @ui do
@cmd.handle_options %w[--vendor]
end
assert @cmd.options[:vendor]
assert_equal Gem.vendor_dir, @cmd.options[:install_dir]
assert @cmd.options[:vendor]
assert_equal Gem.vendor_dir, @cmd.options[:install_dir]
assert_empty @ui.output
assert_empty @ui.output
expected = <<-EXPECTED
expected = <<-EXPECTED
WARNING: Use your OS package manager to uninstall vendor gems
EXPECTED
EXPECTED
assert_match expected, @ui.error
assert_match expected, @ui.error
end
end
def test_execute_two_version
@ -395,21 +390,17 @@ WARNING: Use your OS package manager to uninstall vendor gems
end
def test_handle_options_vendor_missing
orig_vendordir = RbConfig::CONFIG['vendordir']
RbConfig::CONFIG.delete 'vendordir'
vendordir(nil) do
e = assert_raises OptionParser::InvalidOption do
@cmd.handle_options %w[--vendor]
end
e = assert_raises OptionParser::InvalidOption do
@cmd.handle_options %w[--vendor]
assert_equal 'invalid option: --vendor your platform is not supported',
e.message
refute @cmd.options[:vendor]
refute @cmd.options[:install_dir]
end
assert_equal 'invalid option: --vendor your platform is not supported',
e.message
refute @cmd.options[:vendor]
refute @cmd.options[:install_dir]
ensure
RbConfig::CONFIG['vendordir'] = orig_vendordir
end
def test_execute_with_gem_not_installed
@ -425,6 +416,8 @@ WARNING: Use your OS package manager to uninstall vendor gems
end
def test_execute_with_gem_uninstall_error
initial_install
util_make_gems
@cmd.options[:args] = %w[a]
@ -451,4 +444,17 @@ WARNING: Use your OS package manager to uninstall vendor gems
assert_match %r!Error: unable to successfully uninstall '#{@spec.name}'!, @ui.error
end
private
def initial_install
installer = setup_base_installer
common_installer_setup
build_rake_in do
use_ui @ui do
installer.install
end
end
end
end

Просмотреть файл

@ -504,25 +504,12 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
assert_equal '--prefix', arguments.shift
assert_equal Gem.prefix, arguments.shift
assert_equal '--no-rdoc', arguments.shift
assert_equal '--no-ri', arguments.shift
assert_equal '--no-document', arguments.shift
assert_equal '--previous-version', arguments.shift
assert_equal Gem::VERSION, arguments.shift
assert_empty arguments
end
def test_update_rubygems_arguments_1_8_x
@cmd.options[:system] = '1.8.26'
arguments = @cmd.update_rubygems_arguments
assert_equal '--prefix', arguments.shift
assert_equal Gem.prefix, arguments.shift
assert_equal '--no-rdoc', arguments.shift
assert_equal '--no-ri', arguments.shift
assert_empty arguments
end
def test_explain
spec_fetcher do |fetcher|
fetcher.download 'a', 2

Просмотреть файл

@ -45,7 +45,6 @@ class TestGemDependencyInstaller < Gem::TestCase
s.add_development_dependency 'c'
end
util_clear_gems
util_reset_gems
end
@ -133,7 +132,6 @@ class TestGemDependencyInstaller < Gem::TestCase
p1a, gem = util_gem 'a', '10.a'
util_setup_spec_fetcher(p1a, @a1, @a1_pre)
util_clear_gems
p1a_data = Gem.read_binary(gem)
@ -172,7 +170,6 @@ class TestGemDependencyInstaller < Gem::TestCase
p1a, gem = util_gem 'p', '1.a'
util_setup_spec_fetcher(p1a)
util_clear_gems
p1a_data = Gem.read_binary(gem)
@ -192,7 +189,6 @@ class TestGemDependencyInstaller < Gem::TestCase
util_setup_gems
util_setup_spec_fetcher(@a1, @a1_pre)
util_clear_gems
p1a_data = Gem.read_binary(@a1_gem)
@ -213,8 +209,6 @@ class TestGemDependencyInstaller < Gem::TestCase
s.add_dependency 'b'
end
util_clear_gems
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
FileUtils.mv e1_gem, @tempdir
@ -575,8 +569,6 @@ class TestGemDependencyInstaller < Gem::TestCase
s.add_dependency 'a'
end
util_clear_gems
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
FileUtils.mv b2_gem, @tempdir
@ -877,8 +869,6 @@ class TestGemDependencyInstaller < Gem::TestCase
si = util_setup_spec_fetcher @a1, a2_o
util_clear_gems
@fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
a1_data = nil
@ -1274,8 +1264,6 @@ class TestGemDependencyInstaller < Gem::TestCase
util_setup_spec_fetcher(*[@a1, @a1_pre, @b1, @c1_pre,
@d1, @d2, @x1_m, @x1_o, @w1, @y1,
@y1_1_p, @z1].compact)
util_clear_gems
end
end

Просмотреть файл

@ -7,8 +7,6 @@ class TestGemDependencyList < Gem::TestCase
def setup
super
util_clear_gems
@deplist = Gem::DependencyList.new
# TODO: switch to util_spec
@ -124,8 +122,6 @@ class TestGemDependencyList < Gem::TestCase
end
def test_ok_eh
util_clear_gems
assert @deplist.ok?, 'no dependencies'
@deplist.add @b2
@ -138,8 +134,6 @@ class TestGemDependencyList < Gem::TestCase
end
def test_why_not_ok_eh
util_clear_gems
assert_equal({}, @deplist.why_not_ok?)
@deplist.add @b2
@ -229,8 +223,6 @@ class TestGemDependencyList < Gem::TestCase
end
def test_remove_by_name
util_clear_gems
@deplist.add @a1, @b2
@deplist.remove_by_name "a-1"

Просмотреть файл

@ -329,4 +329,4 @@ install:
assert_equal %w[--with-foo-dir=/nonexistent], builder.build_args
end
end
end unless Gem.java_platform?

Просмотреть файл

@ -10,6 +10,8 @@ class TestGemExtCmakeBuilder < Gem::TestCase
# Details: https://github.com/rubygems/rubygems/issues/1270#issuecomment-177368340
skip "CmakeBuilder doesn't work on Windows." if Gem.win_platform?
skip "CmakeBuilder doesn't work on JRuby." if Gem.java_platform? && ENV["CI"]
system('cmake', out: IO::NULL, err: [:child, :out])
skip 'cmake not present' unless $?.success?

Просмотреть файл

@ -18,6 +18,10 @@ class TestGemExtConfigureBuilder < Gem::TestCase
end
def test_self_build
if java_platform? && ENV["CI"]
skip("failing on jruby")
end
skip("test_self_build skipped on MS Windows (VC++)") if vc_windows?
File.open File.join(@ext, './configure'), 'w' do |configure|
@ -45,6 +49,10 @@ class TestGemExtConfigureBuilder < Gem::TestCase
end
def test_self_build_fail
if java_platform? && ENV["CI"]
skip("failing on jruby")
end
skip("test_self_build_fail skipped on MS Windows (VC++)") if vc_windows?
output = []

Просмотреть файл

@ -17,6 +17,10 @@ class TestGemExtExtConfBuilder < Gem::TestCase
end
def test_class_build
if java_platform? && ENV["CI"]
skip("failing on jruby")
end
if vc_windows? && !nmake_found?
skip("test_class_build skipped - nmake not found")
end
@ -45,6 +49,10 @@ class TestGemExtExtConfBuilder < Gem::TestCase
end
def test_class_build_rbconfig_make_prog
if java_platform? && ENV["CI"]
skip("failing on jruby")
end
configure_args do
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
@ -68,6 +76,10 @@ class TestGemExtExtConfBuilder < Gem::TestCase
env_make = ENV.delete 'MAKE'
ENV['MAKE'] = 'anothermake'
if java_platform? && ENV["CI"]
skip("failing on jruby")
end
configure_args '' do
File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf|
extconf.puts "require 'mkmf'\ncreate_makefile 'foo'"

Просмотреть файл

@ -11,7 +11,6 @@ class TestGemIndexer < Gem::TestCase
def setup
super
util_clear_gems
util_make_gems
@d2_0 = util_spec 'd', '2.0' do |s|
@ -28,30 +27,23 @@ class TestGemIndexer < Gem::TestCase
@default = new_default_spec 'default', 2
install_default_gems @default
@tempdir = File.join(@tempdir, 'indexer')
@indexerdir = File.join(@tempdir, 'indexer')
gems = File.join(@tempdir, 'gems')
gems = File.join(@indexerdir, 'gems')
FileUtils.mkdir_p gems
FileUtils.mv Dir[File.join(@gemhome, "cache", '*.gem')], gems
@indexer = Gem::Indexer.new(@tempdir)
end
def teardown
super
util_clear_gems
util_clear_default_gems
@indexer = Gem::Indexer.new(@indexerdir)
end
def test_initialize
assert_equal @tempdir, @indexer.dest_directory
assert_equal @indexerdir, @indexer.dest_directory
assert_match %r{#{Dir.mktmpdir('gem_generate_index').match(/.*-/)}}, @indexer.directory
indexer = Gem::Indexer.new @tempdir
indexer = Gem::Indexer.new @indexerdir
assert indexer.build_modern
indexer = Gem::Indexer.new @tempdir, :build_modern => true
indexer = Gem::Indexer.new @indexerdir, :build_modern => true
assert indexer.build_modern
end
@ -100,7 +92,7 @@ class TestGemIndexer < Gem::TestCase
@indexer.generate_index
end
quickdir = File.join @tempdir, 'quick'
quickdir = File.join @indexerdir, 'quick'
marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
assert_directory_exists quickdir
@ -111,11 +103,11 @@ class TestGemIndexer < Gem::TestCase
refute_indexed marshal_quickdir, File.basename(@c1_2.spec_file)
assert_indexed @tempdir, "specs.#{@marshal_version}"
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
assert_indexed @indexerdir, "specs.#{@marshal_version}"
assert_indexed @indexerdir, "specs.#{@marshal_version}.gz"
assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
assert_indexed @indexerdir, "latest_specs.#{@marshal_version}"
assert_indexed @indexerdir, "latest_specs.#{@marshal_version}.gz"
end
def test_generate_index_modern
@ -125,12 +117,12 @@ class TestGemIndexer < Gem::TestCase
@indexer.generate_index
end
refute_indexed @tempdir, 'yaml'
refute_indexed @tempdir, 'yaml.Z'
refute_indexed @tempdir, "Marshal.#{@marshal_version}"
refute_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
refute_indexed @indexerdir, 'yaml'
refute_indexed @indexerdir, 'yaml.Z'
refute_indexed @indexerdir, "Marshal.#{@marshal_version}"
refute_indexed @indexerdir, "Marshal.#{@marshal_version}.Z"
quickdir = File.join @tempdir, 'quick'
quickdir = File.join @indexerdir, 'quick'
marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
assert_directory_exists quickdir, 'quickdir should be directory'
@ -156,11 +148,11 @@ class TestGemIndexer < Gem::TestCase
refute_indexed quickdir, "#{File.basename(@c1_2.spec_file)}"
refute_indexed marshal_quickdir, "#{File.basename(@c1_2.spec_file)}"
assert_indexed @tempdir, "specs.#{@marshal_version}"
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
assert_indexed @indexerdir, "specs.#{@marshal_version}"
assert_indexed @indexerdir, "specs.#{@marshal_version}.gz"
assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
assert_indexed @indexerdir, "latest_specs.#{@marshal_version}"
assert_indexed @indexerdir, "latest_specs.#{@marshal_version}.gz"
end
def test_generate_index_modern_back_to_back
@ -170,13 +162,13 @@ class TestGemIndexer < Gem::TestCase
@indexer.generate_index
end
@indexer = Gem::Indexer.new @tempdir
@indexer = Gem::Indexer.new @indexerdir
@indexer.build_modern = true
use_ui @ui do
@indexer.generate_index
end
quickdir = File.join @tempdir, 'quick'
quickdir = File.join @indexerdir, 'quick'
marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
assert_directory_exists quickdir
@ -185,11 +177,11 @@ class TestGemIndexer < Gem::TestCase
assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz"
assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz"
assert_indexed @tempdir, "specs.#{@marshal_version}"
assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
assert_indexed @indexerdir, "specs.#{@marshal_version}"
assert_indexed @indexerdir, "specs.#{@marshal_version}.gz"
assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
assert_indexed @indexerdir, "latest_specs.#{@marshal_version}"
assert_indexed @indexerdir, "latest_specs.#{@marshal_version}.gz"
end
def test_generate_index_ui
@ -215,7 +207,7 @@ class TestGemIndexer < Gem::TestCase
@indexer.generate_index
end
specs_path = File.join @tempdir, "specs.#{@marshal_version}"
specs_path = File.join @indexerdir, "specs.#{@marshal_version}"
specs_dump = Gem.read_binary specs_path
specs = Marshal.load specs_dump
@ -252,7 +244,7 @@ class TestGemIndexer < Gem::TestCase
@indexer.generate_index
end
latest_specs_path = File.join @tempdir, "latest_specs.#{@marshal_version}"
latest_specs_path = File.join @indexerdir, "latest_specs.#{@marshal_version}"
latest_specs_dump = Gem.read_binary latest_specs_path
latest_specs = Marshal.load latest_specs_dump
@ -282,7 +274,7 @@ class TestGemIndexer < Gem::TestCase
@indexer.generate_index
end
prerelease_specs_path = File.join @tempdir, "prerelease_specs.#{@marshal_version}"
prerelease_specs_path = File.join @indexerdir, "prerelease_specs.#{@marshal_version}"
prerelease_specs_dump = Gem.read_binary prerelease_specs_path
prerelease_specs = Marshal.load prerelease_specs_dump
@ -311,7 +303,7 @@ class TestGemIndexer < Gem::TestCase
@indexer.generate_index
end
quickdir = File.join @tempdir, 'quick'
quickdir = File.join @indexerdir, 'quick'
marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
assert_directory_exists quickdir
@ -325,7 +317,7 @@ class TestGemIndexer < Gem::TestCase
util_build_gem @d2_1_a
@d2_1_a_tuple = [@d2_1_a.name, @d2_1_a.version, @d2_1_a.original_platform]
gems = File.join @tempdir, 'gems'
gems = File.join @indexerdir, 'gems'
FileUtils.mv @d2_1.cache_file, gems
FileUtils.mv @d2_1_a.cache_file, gems

Просмотреть файл

@ -26,10 +26,11 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
-f
-i /install_to
-w
--vendor
--post-install-message
]
args.concat %w[--vendor] unless Gem.java_platform?
args.concat %w[-P HighSecurity] if defined?(OpenSSL::SSL)
assert @cmd.handles?(args)
@ -111,6 +112,13 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
end
def test_user_install_enabled
@spec = quick_gem 'a' do |spec|
util_make_exec spec
end
util_build_gem @spec
@gem = @spec.cache_file
@cmd.handle_options %w[--user-install]
assert @cmd.options[:user_install]
@ -122,6 +130,13 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
end
def test_user_install_disabled_read_only
@spec = quick_gem 'a' do |spec|
util_make_exec spec
end
util_build_gem @spec
@gem = @spec.cache_file
if win_platform?
skip('test_user_install_disabled_read_only test skipped on MS Windows')
elsif Process.uid.zero?
@ -145,28 +160,26 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
end
def test_vendor
@cmd.handle_options %w[--vendor]
vendordir(File.join(@tempdir, 'vendor')) do
@cmd.handle_options %w[--vendor]
assert @cmd.options[:vendor]
assert_equal Gem.vendor_dir, @cmd.options[:install_dir]
assert @cmd.options[:vendor]
assert_equal Gem.vendor_dir, @cmd.options[:install_dir]
end
end
def test_vendor_missing
orig_vendordir = RbConfig::CONFIG['vendordir']
RbConfig::CONFIG.delete 'vendordir'
vendordir(nil) do
e = assert_raises OptionParser::InvalidOption do
@cmd.handle_options %w[--vendor]
end
e = assert_raises OptionParser::InvalidOption do
@cmd.handle_options %w[--vendor]
assert_equal 'invalid option: --vendor your platform is not supported',
e.message
refute @cmd.options[:vendor]
refute @cmd.options[:install_dir]
end
assert_equal 'invalid option: --vendor your platform is not supported',
e.message
refute @cmd.options[:vendor]
refute @cmd.options[:install_dir]
ensure
RbConfig::CONFIG['vendordir'] = orig_vendordir
end
def test_post_install_message_no

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -2,7 +2,6 @@
# frozen_string_literal: true
require 'rubygems/package/tar_test_case'
require 'rubygems/simple_gem'
class TestGemPackage < Gem::Package::TarTestCase
@ -24,6 +23,8 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_class_new_old_format
skip "jruby can't require the simple_gem file" if Gem.java_platform?
require_relative "simple_gem"
File.open 'old_format.gem', 'wb' do |io|
io.write SIMPLE_GEM
end
@ -839,6 +840,7 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_verify_corrupt
skip "jruby strips the null byte and does not think it's corrupt" if Gem.java_platform?
tf = Tempfile.open 'corrupt' do |io|
data = Gem::Util.gzip 'a' * 10
io.write \

Просмотреть файл

@ -1,89 +1,92 @@
# frozen_string_literal: true
require 'rubygems/test_case'
require 'rubygems/simple_gem'
class TestGemPackageOld < Gem::TestCase
unless Gem.java_platform? # jruby can't require the simple_gem file
require 'rubygems/simple_gem'
def setup
super
class TestGemPackageOld < Gem::TestCase
File.open 'old_format.gem', 'wb' do |io|
io.write SIMPLE_GEM
def setup
super
File.open 'old_format.gem', 'wb' do |io|
io.write SIMPLE_GEM
end
@package = Gem::Package::Old.new 'old_format.gem'
@destination = File.join @tempdir, 'extract'
FileUtils.mkdir_p @destination
end
@package = Gem::Package::Old.new 'old_format.gem'
@destination = File.join @tempdir, 'extract'
FileUtils.mkdir_p @destination
end
def test_contents
assert_equal %w[lib/foo.rb lib/test.rb lib/test/wow.rb], @package.contents
end
def test_contents_security_policy
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
@package.security_policy = Gem::Security::AlmostNoSecurity
assert_raises Gem::Security::Exception do
@package.contents
def test_contents
assert_equal %w[lib/foo.rb lib/test.rb lib/test/wow.rb], @package.contents
end
end
def test_extract_files
@package.extract_files @destination
def test_contents_security_policy
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
extracted = File.join @destination, 'lib/foo.rb'
assert_path_exists extracted
@package.security_policy = Gem::Security::AlmostNoSecurity
mask = 0100644 & (~File.umask)
assert_raises Gem::Security::Exception do
@package.contents
end
end
assert_equal mask, File.stat(extracted).mode unless win_platform?
end
def test_extract_files_security_policy
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
@package.security_policy = Gem::Security::AlmostNoSecurity
assert_raises Gem::Security::Exception do
def test_extract_files
@package.extract_files @destination
end
end
def test_spec
assert_equal 'testing', @package.spec.name
end
extracted = File.join @destination, 'lib/foo.rb'
assert_path_exists extracted
def test_spec_security_policy
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
mask = 0100644 & (~File.umask)
@package.security_policy = Gem::Security::AlmostNoSecurity
assert_raises Gem::Security::Exception do
@package.spec
end
end
def test_verify
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
assert @package.verify
@package.security_policy = Gem::Security::NoSecurity
assert @package.verify
@package.security_policy = Gem::Security::AlmostNoSecurity
e = assert_raises Gem::Security::Exception do
@package.verify
assert_equal mask, File.stat(extracted).mode unless win_platform?
end
assert_equal 'old format gems do not contain signatures ' +
'and cannot be verified',
e.message
end
def test_extract_files_security_policy
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
@package.security_policy = Gem::Security::AlmostNoSecurity
assert_raises Gem::Security::Exception do
@package.extract_files @destination
end
end
def test_spec
assert_equal 'testing', @package.spec.name
end
def test_spec_security_policy
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
@package.security_policy = Gem::Security::AlmostNoSecurity
assert_raises Gem::Security::Exception do
@package.spec
end
end
def test_verify
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
assert @package.verify
@package.security_policy = Gem::Security::NoSecurity
assert @package.verify
@package.security_policy = Gem::Security::AlmostNoSecurity
e = assert_raises Gem::Security::Exception do
@package.verify
end
assert_equal 'old format gems do not contain signatures ' +
'and cannot be verified',
e.message
end
end
end

Просмотреть файл

@ -164,4 +164,45 @@ group\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000
end
end
def test_big_uid_gid
stream = StringIO.new(
<<-EOF.dup.force_encoding('binary').split("\n").join
GeoIP2-City_20190528/
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x000000755\x00\x80\x00
\x00\x00v\xB2Z\x9E\x80\x00\x00\x00v\xB2Z\x9E00000000000\x0013473270100\x00015424
\x00 5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ustar \x00
tjmather\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00tjmather\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00
EOF
)
tar_header = Gem::Package::TarHeader.from stream
assert_equal 1991400094, tar_header.uid
assert_equal 1991400094, tar_header.gid
assert_equal 'GeoIP2-City_20190528/', tar_header.name
assert_equal 0755, tar_header.mode
assert_equal 0, tar_header.size
assert_equal 1559064640, tar_header.mtime
assert_equal 6932, tar_header.checksum
end
end

Просмотреть файл

@ -76,6 +76,7 @@ class TestGemPackageTarReaderEntry < Gem::Package::TarTestCase
end
def test_full_name_null
skip "jruby strips the null byte and does not think it's corrupt" if Gem.java_platform?
@entry.header.prefix << "\000"
e = assert_raises Gem::Package::TarInvalidError do

Просмотреть файл

@ -40,17 +40,19 @@ class TestGemPathSupport < Gem::TestCase
end
def test_initialize_path
ps = Gem::PathSupport.new ENV.to_hash.merge("GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar].join(Gem.path_separator))
Gem.stub(:path_separator, File::PATH_SEPARATOR) do
ps = Gem::PathSupport.new ENV.to_hash.merge("GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar].join(Gem.path_separator))
assert_equal ENV["GEM_HOME"], ps.home
assert_equal ENV["GEM_HOME"], ps.home
expected = [
File.join(@tempdir, 'foo'),
File.join(@tempdir, 'bar'),
ENV["GEM_HOME"],
]
expected = [
File.join(@tempdir, 'foo'),
File.join(@tempdir, 'bar'),
ENV["GEM_HOME"],
]
assert_equal expected, ps.path
assert_equal expected, ps.path
end
end
def test_initialize_regexp_path_separator
@ -90,13 +92,15 @@ class TestGemPathSupport < Gem::TestCase
end
def test_initialize_home_path
ps = Gem::PathSupport.new("GEM_HOME" => "#{@tempdir}/foo",
"GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar].join(Gem.path_separator))
Gem.stub(:path_separator, File::PATH_SEPARATOR) do
ps = Gem::PathSupport.new("GEM_HOME" => "#{@tempdir}/foo",
"GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar].join(Gem.path_separator))
assert_equal File.join(@tempdir, "foo"), ps.home
assert_equal File.join(@tempdir, "foo"), ps.home
expected = [File.join(@tempdir, 'foo'), File.join(@tempdir, 'bar')]
assert_equal expected, ps.path
expected = [File.join(@tempdir, 'foo'), File.join(@tempdir, 'bar')]
assert_equal expected, ps.path
end
end
def util_path

Просмотреть файл

@ -785,6 +785,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_ssl_client_cert_auth_connection
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
skip 'openssl in jruby fails' if java_platform?
ssl_server = self.class.start_ssl_server({
:SSLVerifyClient =>
@ -1050,12 +1051,4 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
end
def test_correct_for_windows_path
path = "/C:/WINDOWS/Temp/gems"
assert_equal "C:/WINDOWS/Temp/gems", @fetcher.correct_for_windows_path(path)
path = "/home/skillet"
assert_equal "/home/skillet", @fetcher.correct_for_windows_path(path)
end
end if defined?(OpenSSL::SSL)

Просмотреть файл

@ -328,6 +328,7 @@ class TestGemRequest < Gem::TestCase
end
def test_verify_certificate
skip if Gem.java_platform?
store = OpenSSL::X509::Store.new
context = OpenSSL::X509::StoreContext.new store
context.error = OpenSSL::X509::V_ERR_OUT_OF_MEM
@ -341,6 +342,7 @@ class TestGemRequest < Gem::TestCase
end
def test_verify_certificate_extra_message
skip if Gem.java_platform?
store = OpenSSL::X509::Store.new
context = OpenSSL::X509::StoreContext.new store
context.error = OpenSSL::X509::V_ERR_INVALID_CA

Просмотреть файл

@ -856,4 +856,4 @@ end
engine
end
end
end unless Gem.java_platform?

Просмотреть файл

@ -97,7 +97,7 @@ class TestGemResolver < Gem::TestCase
r1 = Gem::Resolver::DependencyRequest.new dep('a', '= 1'), nil
act = Gem::Resolver::ActivationRequest.new a1, r1, false
act = Gem::Resolver::ActivationRequest.new a1, r1
res = Gem::Resolver.new [a1]
@ -118,7 +118,7 @@ class TestGemResolver < Gem::TestCase
r1 = Gem::Resolver::DependencyRequest.new dep('a', '= 1'), nil
act = Gem::Resolver::ActivationRequest.new spec, r1, false
act = Gem::Resolver::ActivationRequest.new spec, r1
res = Gem::Resolver.new [act]
res.development = true
@ -137,7 +137,7 @@ class TestGemResolver < Gem::TestCase
r1 = Gem::Resolver::DependencyRequest.new dep('a', '= 1'), nil
act = Gem::Resolver::ActivationRequest.new a1, r1, false
act = Gem::Resolver::ActivationRequest.new a1, r1
res = Gem::Resolver.new [a1]
res.ignore_dependencies = true

Просмотреть файл

@ -13,11 +13,9 @@ class TestGemResolverActivationRequest < Gem::TestCase
source = Gem::Source::Local.new
platform = Gem::Platform::RUBY
@a1 = @DR::IndexSpecification.new nil, 'a', v(1), source, platform
@a2 = @DR::IndexSpecification.new nil, 'a', v(2), source, platform
@a3 = @DR::IndexSpecification.new nil, 'a', v(3), source, platform
@req = @DR::ActivationRequest.new @a3, @dep, [@a1, @a2]
@req = @DR::ActivationRequest.new @a3, @dep
end
def test_development_eh
@ -25,7 +23,7 @@ class TestGemResolverActivationRequest < Gem::TestCase
dep_req = @DR::DependencyRequest.new dep('a', '>= 0', :development), nil
act_req = @DR::ActivationRequest.new @a3, dep_req, [@a1, @a2]
act_req = @DR::ActivationRequest.new @a3, dep_req
assert act_req.development?
end
@ -33,41 +31,14 @@ class TestGemResolverActivationRequest < Gem::TestCase
def test_inspect
assert_match 'a-3', @req.inspect
assert_match 'from a (>= 0)', @req.inspect
assert_match '(others possible: a-1, a-2)', @req.inspect
end
def test_inspect_legacy
req = @DR::ActivationRequest.new @a3, @dep, true
assert_match '(others possible)', req.inspect
req = @DR::ActivationRequest.new @a3, @dep, false
refute_match '(others possible)', req.inspect
end
def test_installed_eh
v_spec = Gem::Resolver::VendorSpecification.new nil, @a3
@req = @DR::ActivationRequest.new v_spec, @dep, [@a1, @a2]
@req = @DR::ActivationRequest.new v_spec, @dep
assert @req.installed?
end
def test_others_possible_eh
assert @req.others_possible?
req = @DR::ActivationRequest.new @a3, @dep, []
refute req.others_possible?
req = @DR::ActivationRequest.new @a3, @dep, true
assert req.others_possible?
req = @DR::ActivationRequest.new @a3, @dep, false
refute req.others_possible?
end
end

Просмотреть файл

@ -63,6 +63,7 @@ class TestGemResolverGitSpecification < Gem::TestCase
# functional test for Gem::Ext::Builder
def test_install_extension
skip if Gem.java_platform?
name, _, repository, = git_gem 'a', 1 do |s|
s.extensions << 'ext/extconf.rb'
end

Просмотреть файл

@ -6,6 +6,10 @@ unless defined?(OpenSSL::SSL)
warn 'Skipping Gem::Security tests. openssl not found.'
end
if Gem.java_platform?
warn 'Skipping Gem::Security tests on jruby.'
end
class TestGemSecurity < Gem::TestCase
CHILD_KEY = load_key 'child'
@ -307,4 +311,4 @@ class TestGemSecurity < Gem::TestCase
assert_equal key.to_pem, key_from_file.to_pem
end
end if defined?(OpenSSL::SSL)
end if defined?(OpenSSL::SSL) && !Gem.java_platform?

Просмотреть файл

@ -143,6 +143,7 @@ toqvglr0kdbknSRRjBVLK6tsgr07aLT9gNP7mTW2PA==
end
def test_sign_expired_auto_update
skip if Gem.java_platform?
FileUtils.mkdir_p File.join(Gem.user_home, '.gem'), :mode => 0700
private_key_path = File.join(Gem.user_home, '.gem', 'gem-private_key.pem')

Просмотреть файл

@ -236,11 +236,6 @@ class TestGemSourceGit < Gem::TestCase
system @git, 'add', 'b.gemspec'
system @git, 'commit', '--quiet', '-m', 'add b/b.gemspec'
end
FileUtils.touch 'c.gemspec'
system @git, 'add', 'c.gemspec'
system @git, 'commit', '--quiet', '-m', 'add c.gemspec'
end
specs = nil

Просмотреть файл

@ -1441,6 +1441,7 @@ dependencies: []
end
def test_build_args
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
assert_empty @ext.build_args
@ -1459,6 +1460,7 @@ dependencies: []
end
def test_build_extensions
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
refute_path_exists @ext.extension_dir, 'sanity check'
@ -1494,6 +1496,7 @@ dependencies: []
end
def test_build_extensions_built
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
refute_empty @ext.extensions, 'sanity check'
@ -1532,6 +1535,7 @@ dependencies: []
end
def test_build_extensions_error
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
refute_empty @ext.extensions, 'sanity check'
@ -1545,6 +1549,7 @@ dependencies: []
skip 'chmod not supported' if Gem.win_platform?
skip 'skipped in root privilege' if Process.uid.zero?
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
refute_empty @ext.extensions, 'sanity check'
@ -1569,7 +1574,7 @@ dependencies: []
@ext.build_extensions
refute_path_exists @ext.extension_dir
ensure
unless ($DEBUG or win_platform? or Process.uid.zero?)
unless ($DEBUG or win_platform? or Process.uid.zero? or Gem.java_platform?)
FileUtils.chmod 0755, File.join(@ext.base_dir, 'extensions')
FileUtils.chmod 0755, @ext.base_dir
end
@ -1577,7 +1582,7 @@ dependencies: []
def test_build_extensions_no_extensions_dir_unwritable
skip 'chmod not supported' if Gem.win_platform?
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
refute_empty @ext.extensions, 'sanity check'
@ -1616,6 +1621,7 @@ dependencies: []
end
def test_build_extensions_old
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
refute_empty @ext.extensions, 'sanity check'
@ -1629,6 +1635,7 @@ dependencies: []
end
def test_build_extensions_preview
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
@ -1663,6 +1670,7 @@ dependencies: []
end
def test_contains_requirable_file_eh_extension
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
_, err = capture_io do
@ -3623,6 +3631,7 @@ end
end
def test_missing_extensions_eh
skip "extensions don't quite work on jruby" if Gem.java_platform?
ext_spec
assert @ext.missing_extensions?

Просмотреть файл

@ -67,6 +67,7 @@ class TestStubSpecification < Gem::TestCase
end
def test_contains_requirable_file_eh_extension
skip "I guess making the stub match the running platform should work" if Gem.java_platform?
stub_with_extension do |stub|
_, err = capture_io do
refute stub.contains_requirable_file? 'nonexistent'
@ -123,6 +124,7 @@ class TestStubSpecification < Gem::TestCase
end
def test_missing_extensions_eh
skip "I guess making the stub match the running platform should work" if Gem.java_platform?
stub = stub_with_extension do |s|
extconf_rb = File.join s.gem_dir, s.extensions.first
FileUtils.mkdir_p File.dirname extconf_rb

Просмотреть файл

@ -6,6 +6,8 @@ class TestGemUninstaller < Gem::InstallerTestCase
def setup
super
@installer = setup_base_installer
@user_installer = setup_base_user_installer
common_installer_setup
build_rake_in do

Просмотреть файл

@ -5,6 +5,7 @@ require 'rubygems/util'
class TestGemUtil < Gem::TestCase
def test_class_popen
skip "popen with a block does not behave well on jruby" if Gem.java_platform?
assert_equal "0\n", Gem::Util.popen(Gem.ruby, '-I', File.expand_path('../../../lib', __FILE__), '-e', 'p 0')
assert_raises Errno::ECHILD do
@ -13,6 +14,7 @@ class TestGemUtil < Gem::TestCase
end
def test_silent_system
skip if Gem.java_platform?
assert_silent do
Gem::Util.silent_system Gem.ruby, '-I', File.expand_path('../../../lib', __FILE__), '-e', 'puts "hello"; warn "hello"'
end
@ -30,7 +32,7 @@ class TestGemUtil < Gem::TestCase
end
def test_traverse_parents_does_not_crash_on_permissions_error
skip 'skipped on MS Windows (chmod has no effect)' if win_platform?
skip 'skipped on MS Windows (chmod has no effect)' if win_platform? || java_platform?
FileUtils.mkdir_p 'd/e/f'
# remove 'execute' permission from "e" directory and make it
@ -47,7 +49,7 @@ class TestGemUtil < Gem::TestCase
assert_equal File.realpath("..", Dir.tmpdir), paths[3]
ensure
# restore default permissions, allow the directory to be removed
FileUtils.chmod(0775, 'd/e') unless win_platform?
FileUtils.chmod(0775, 'd/e') unless win_platform? || java_platform?
end
def test_linked_list_find
@ -75,4 +77,12 @@ class TestGemUtil < Gem::TestCase
assert_equal expected_paths.to_set, files_with_relative_base.to_set
end
def test_correct_for_windows_path
path = "/C:/WINDOWS/Temp/gems"
assert_equal "C:/WINDOWS/Temp/gems", Gem::Util.correct_for_windows_path(path)
path = "/home/skillet"
assert_equal "/home/skillet", Gem::Util.correct_for_windows_path(path)
end
end

Просмотреть файл

@ -1,14 +1,13 @@
# frozen_string_literal: true
require 'rubygems/test_case'
require "rubygems/simple_gem"
require 'rubygems/validator'
require "rubygems/test_case"
require "rubygems/validator"
class TestGemValidator < Gem::TestCase
def setup
super
@simple_gem = SIMPLE_GEM
@validator = Gem::Validator.new
end

Просмотреть файл

@ -162,6 +162,10 @@ class TestGemRequire < Gem::TestCase
end
def test_activate_via_require_respects_loaded_files
skip "Not sure what's going on. If another spec creates a 'a' gem before
this test, somehow require will load the benchmark in b, and ignore that the
stdlib one is already in $LOADED_FEATURES?. Reproducible by running the
spaceship_specific_file test before this one" if java_platform?
a1 = util_spec "a", "1", {"b" => ">= 1"}, "lib/test_gem_require_a.rb"
b1 = util_spec "b", "1", nil, "lib/benchmark.rb"
b2 = util_spec "b", "2", nil, "lib/benchmark.rb"
@ -431,7 +435,8 @@ class TestGemRequire < Gem::TestCase
end
end
if RUBY_VERSION >= "2.5"
# uplevel is 2.5+ only and jruby has some issues with it
if RUBY_VERSION >= "2.5" && !java_platform?
def test_no_kernel_require_in_warn_with_uplevel
lib = File.realpath("../../../lib", __FILE__)
Dir.mktmpdir("warn_test") do |dir|