From 5335ce0e060c7a2a0b01c57f8f8a64254f2658e1 Mon Sep 17 00:00:00 2001 From: hsbt Date: Wed, 21 Nov 2018 10:20:47 +0000 Subject: Merge master branch from rubygems/rubygems upstream. * Enable Style/MethodDefParentheses in Rubocop https://github.com/rubygems/rubygems/pull/2478 * Enable Style/MultilineIfThen in Rubocop https://github.com/rubygems/rubygems/pull/2479 * Fix required_ruby_version with prereleases and improve error message https://github.com/rubygems/rubygems/pull/2344 * Fix bundler rubygems binstub not properly looking for bundler https://github.com/rubygems/rubygems/pull/2426 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/test_case.rb | 136 ++++++++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 60 deletions(-) (limited to 'lib/rubygems/test_case.rb') diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index fc9456709f..7648ffdc84 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -84,7 +84,7 @@ module Gem # Allows setting path to Ruby. This method is available when requiring # 'rubygems/test_case' - def self.ruby= ruby + def self.ruby=(ruby) @ruby = ruby end @@ -115,7 +115,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni attr_accessor :uri # :nodoc: - def assert_activate expected, *specs + def assert_activate(expected, *specs) specs.each do |spec| case spec when String then @@ -133,7 +133,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni end # TODO: move to minitest - def assert_path_exists path, msg = nil + def assert_path_exists(path, msg = nil) msg = message(msg) { "Expected path '#{path}' to exist" } assert File.exist?(path), msg end @@ -142,13 +142,13 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni # Sets the ENABLE_SHARED entry in RbConfig::CONFIG to +value+ and restores # the original value when the block ends - def enable_shared value + def enable_shared(value) enable_shared = RbConfig::CONFIG['ENABLE_SHARED'] RbConfig::CONFIG['ENABLE_SHARED'] = value yield ensure - if enable_shared then + if enable_shared RbConfig::CONFIG['enable_shared'] = enable_shared else RbConfig::CONFIG.delete 'enable_shared' @@ -156,7 +156,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni end # TODO: move to minitest - def refute_path_exists path, msg = nil + def refute_path_exists(path, msg = nil) msg = message(msg) { "Expected path '#{path}' to not exist" } refute File.exist?(path), msg end @@ -270,7 +270,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni tmpdir = File.expand_path Dir.tmpdir tmpdir.untaint - if ENV['KEEP_FILES'] then + if ENV['KEEP_FILES'] @tempdir = File.join(tmpdir, "test_rubygems_#{$$}.#{Time.now.to_i}") else @tempdir = File.join(tmpdir, "test_rubygems_#{$$}") @@ -304,7 +304,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni @userhome = File.join @tempdir, 'userhome' ENV["GEM_SPEC_CACHE"] = File.join @tempdir, 'spec_cache' - @orig_ruby = if ENV['RUBY'] then + @orig_ruby = if ENV['RUBY'] ruby = Gem.ruby Gem.ruby = ENV['RUBY'] ruby @@ -426,7 +426,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni end RbConfig::CONFIG['arch'] = @orig_arch - if defined? Gem::RemoteFetcher then + if defined? Gem::RemoteFetcher Gem::RemoteFetcher.fetcher = nil end @@ -449,7 +449,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni Gem.ruby = @orig_ruby if @orig_ruby - if @orig_ENV_HOME then + if @orig_ENV_HOME ENV['HOME'] = @orig_ENV_HOME else ENV.delete 'HOME' @@ -513,7 +513,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni # # Yields the +specification+ to the block, if given - def git_gem name = 'a', version = 1 + def git_gem(name = 'a', version = 1) have_git? directory = File.join 'git', name @@ -534,7 +534,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni head = nil Dir.chdir directory do - unless File.exist? '.git' then + unless File.exist? '.git' system @git, 'init', '--quiet' system @git, 'config', 'user.name', 'RubyGems Tests' system @git, 'config', 'user.email', 'rubygems@example' @@ -557,7 +557,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni skip 'cannot find git executable, use GIT environment variable to set' end - def in_path? executable # :nodoc: + def in_path?(executable) # :nodoc: return true if %r%\A([A-Z]:|/)% =~ executable and File.exist? executable ENV['PATH'].split(File::PATH_SEPARATOR).any? do |directory| @@ -568,12 +568,12 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni ## # Builds and installs the Gem::Specification +spec+ - def install_gem spec, options = {} + def install_gem(spec, options = {}) require 'rubygems/installer' gem = File.join @tempdir, "gems", "#{spec.full_name}.gem" - unless File.exist? gem then + unless File.exist? gem use_ui Gem::MockGemUi.new do Dir.chdir @tempdir do Gem::Package.build spec @@ -589,17 +589,17 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni ## # Builds and installs the Gem::Specification +spec+ into the user dir - def install_gem_user spec + def install_gem_user(spec) install_gem spec, :user_install => true end ## # Uninstalls the Gem::Specification +spec+ - def uninstall_gem spec + def uninstall_gem(spec) require 'rubygems/uninstaller' Class.new(Gem::Uninstaller) { - def ask_if_ok spec + def ask_if_ok(spec) true end }.new(spec.name, :executables => true, :user_install => true).uninstall @@ -704,7 +704,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni ## # TODO: remove in RubyGems 4.0 - def quick_spec name, version = '2' # :nodoc: + def quick_spec(name, version = '2') # :nodoc: util_spec name, version end deprecate :quick_spec, :util_spec, 2018, 12 @@ -808,7 +808,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni # # TODO: remove in RubyGems 4.0 - def new_spec name, version, deps = nil, *files # :nodoc: + def new_spec(name, version, deps = nil, *files) # :nodoc: require 'rubygems/specification' spec = Gem::Specification.new do |s| @@ -832,7 +832,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni spec.loaded_from = spec.spec_file - unless files.empty? then + unless files.empty? write_file spec.spec_file do |io| io.write spec.to_ruby_for_cache end @@ -872,7 +872,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni # Creates a spec with +name+, +version+. +deps+ can specify the dependency # or a +block+ can be given for full customization of the specification. - def util_spec name, version = 2, deps = nil, *files # :yields: specification + def util_spec(name, version = 2, deps = nil, *files) # :yields: specification raise "deps or block, not both" if deps and block_given? spec = Gem::Specification.new do |s| @@ -890,7 +890,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni yield s if block_given? end - if deps then + if deps # Since Hash#each is unordered in 1.8, sort the keys and iterate that # way so the tests are deterministic on all implementations. deps.keys.sort.each do |n| @@ -898,7 +898,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni end end - unless files.empty? then + unless files.empty? write_file spec.spec_file do |io| io.write spec.to_ruby_for_cache end @@ -926,7 +926,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni # TODO: deprecate raise "deps or block, not both" if deps and block - if deps then + if deps block = proc do |s| # Since Hash#each is unordered in 1.8, sort # the keys and iterate that way so the tests are @@ -1122,7 +1122,7 @@ Also, a list: end # HACK for test_download_to_cache - unless Gem::RemoteFetcher === @fetcher then + unless Gem::RemoteFetcher === @fetcher v = Gem.marshal_version specs = all.map { |spec| spec.name_tuple } @@ -1161,35 +1161,51 @@ Also, a list: Zlib::Deflate.deflate data end - def util_set_RUBY_VERSION(version, patchlevel = nil, revision = nil) + 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' then + Gem.instance_variables.include? '@ruby_version' Gem.send :remove_instance_variable, :@ruby_version end - @RUBY_VERSION = RUBY_VERSION - @RUBY_PATCHLEVEL = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL) - @RUBY_REVISION = RUBY_REVISION if defined?(RUBY_REVISION) + @RUBY_VERSION = RUBY_VERSION + @RUBY_PATCHLEVEL = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL) + @RUBY_REVISION = RUBY_REVISION if defined?(RUBY_REVISION) + @RUBY_DESCRIPTION = RUBY_DESCRIPTION if defined?(RUBY_DESCRIPTION) + @RUBY_ENGINE = RUBY_ENGINE + @RUBY_ENGINE_VERSION = RUBY_ENGINE_VERSION if defined?(RUBY_ENGINE_VERSION) - Object.send :remove_const, :RUBY_VERSION - Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL) - Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION) + util_clear_RUBY_VERSION - Object.const_set :RUBY_VERSION, version - Object.const_set :RUBY_PATCHLEVEL, patchlevel if patchlevel - Object.const_set :RUBY_REVISION, revision if revision + Object.const_set :RUBY_VERSION, version + Object.const_set :RUBY_PATCHLEVEL, patchlevel if patchlevel + Object.const_set :RUBY_REVISION, revision if revision + Object.const_set :RUBY_DESCRIPTION, description if description + Object.const_set :RUBY_ENGINE, engine + Object.const_set :RUBY_ENGINE_VERSION, engine_version if engine_version end def util_restore_RUBY_VERSION - Object.send :remove_const, :RUBY_VERSION - Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL) - Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION) + util_clear_RUBY_VERSION - Object.const_set :RUBY_VERSION, @RUBY_VERSION - Object.const_set :RUBY_PATCHLEVEL, @RUBY_PATCHLEVEL if + Object.const_set :RUBY_VERSION, @RUBY_VERSION + Object.const_set :RUBY_PATCHLEVEL, @RUBY_PATCHLEVEL if defined?(@RUBY_PATCHLEVEL) - Object.const_set :RUBY_REVISION, @RUBY_REVISION if + Object.const_set :RUBY_REVISION, @RUBY_REVISION if defined?(@RUBY_REVISION) + Object.const_set :RUBY_DESCRIPTION, @RUBY_DESCRIPTION if + defined?(@RUBY_DESCRIPTION) + Object.const_set :RUBY_ENGINE, @RUBY_ENGINE + Object.const_set :RUBY_ENGINE_VERSION, @RUBY_ENGINE_VERSION if + defined?(@RUBY_ENGINE_VERSION) + end + + def util_clear_RUBY_VERSION + Object.send :remove_const, :RUBY_VERSION + Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL) + Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION) + Object.send :remove_const, :RUBY_DESCRIPTION if defined?(RUBY_DESCRIPTION) + Object.send :remove_const, :RUBY_ENGINE + Object.send :remove_const, :RUBY_ENGINE_VERSION if defined?(RUBY_ENGINE_VERSION) end ## @@ -1343,7 +1359,7 @@ Also, a list: ## # Construct a new Gem::Dependency. - def dep name, *requirements + def dep(name, *requirements) Gem::Dependency.new name, *requirements end @@ -1352,10 +1368,10 @@ Also, a list: # Gem::Dependency +dep+, a +from_name+ and +from_version+ requesting the # dependency and a +parent+ DependencyRequest - def dependency_request dep, from_name, from_version, parent = nil + def dependency_request(dep, from_name, from_version, parent = nil) remote = Gem::Source.new @uri - unless parent then + unless parent parent_dep = dep from_name, from_version parent = Gem::Resolver::DependencyRequest.new parent_dep, nil end @@ -1370,7 +1386,7 @@ Also, a list: ## # Constructs a new Gem::Requirement. - def req *requirements + def req(*requirements) return requirements.first if Gem::Requirement === requirements.first Gem::Requirement.create requirements end @@ -1378,7 +1394,7 @@ Also, a list: ## # Constructs a new Gem::Specification. - def spec name, version, &block + def spec(name, version, &block) Gem::Specification.new name, v(version), &block end @@ -1402,7 +1418,7 @@ Also, a list: # end # end - def spec_fetcher repository = @gem_repo + def spec_fetcher(repository = @gem_repo) Gem::TestCase::SpecFetcherSetup.declare self, repository do |spec_fetcher_setup| yield spec_fetcher_setup if block_given? end @@ -1411,7 +1427,7 @@ Also, a list: ## # Construct a new Gem::Version. - def v string + def v(string) Gem::Version.create string end @@ -1421,7 +1437,7 @@ Also, a list: # # Yields the +specification+ to the block, if given - def vendor_gem name = 'a', version = 1 + def vendor_gem(name = 'a', version = 1) directory = File.join 'vendor', name FileUtils.mkdir_p directory @@ -1435,7 +1451,7 @@ Also, a list: # # Yields the +specification+ to the block, if given - def save_gemspec name = 'a', version = 1, directory = '.' + def save_gemspec(name = 'a', version = 1, directory = '.') vendor_spec = Gem::Specification.new name, version do |specification| yield specification if block_given? end @@ -1472,7 +1488,7 @@ Also, a list: ## # Adds +spec+ to this set. - def add spec + def add(spec) @specs << spec end @@ -1496,7 +1512,7 @@ Also, a list: # Loads a Gem::Specification from this set which has the given +name+, # version +ver+, +platform+. The +source+ is ignored. - def load_spec name, ver, platform, source + def load_spec(name, ver, platform, source) dep = Gem::Dependency.new name, ver spec = find_spec dep @@ -1505,14 +1521,14 @@ Also, a list: end end - def prefetch reqs # :nodoc: + def prefetch(reqs) # :nodoc: end end ## # Loads certificate named +cert_name+ from test/rubygems/. - def self.load_cert cert_name + def self.load_cert(cert_name) cert_file = cert_path cert_name cert = File.read cert_file @@ -1524,8 +1540,8 @@ Also, a list: # Returns the path to the certificate named +cert_name+ from # test/rubygems/. - def self.cert_path cert_name - if 32 == (Time.at(2**32) rescue 32) then + def self.cert_path(cert_name) + if 32 == (Time.at(2**32) rescue 32) cert_file = File.expand_path "../../../test/rubygems/#{cert_name}_cert_32.pem", __FILE__ @@ -1539,7 +1555,7 @@ Also, a list: ## # Loads an RSA private key named +key_name+ with +passphrase+ in test/rubygems/ - def self.load_key key_name, passphrase = nil + def self.load_key(key_name, passphrase = nil) key_file = key_path key_name key = File.read key_file @@ -1550,7 +1566,7 @@ Also, a list: ## # Returns the path to the key named +key_name+ from test/rubygems - def self.key_path key_name + def self.key_path(key_name) File.expand_path "../../../test/rubygems/#{key_name}_key.pem", __FILE__ end -- cgit v1.2.3