diff options
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/artifice/compact_index.rb | 2 | ||||
-rw-r--r-- | spec/support/artifice/compact_index_api_missing.rb | 2 | ||||
-rw-r--r-- | spec/support/artifice/compact_index_extra_api_missing.rb | 2 | ||||
-rw-r--r-- | spec/support/artifice/compact_index_extra_missing.rb | 2 | ||||
-rw-r--r-- | spec/support/artifice/endpoint.rb | 2 | ||||
-rw-r--r-- | spec/support/artifice/endpoint_api_missing.rb | 2 | ||||
-rw-r--r-- | spec/support/artifice/endpoint_extra_missing.rb | 2 | ||||
-rw-r--r-- | spec/support/artifice/windows.rb | 2 | ||||
-rw-r--r-- | spec/support/helpers.rb | 11 | ||||
-rw-r--r-- | spec/support/path.rb | 23 | ||||
-rw-r--r-- | spec/support/rubygems_ext.rb | 14 | ||||
-rw-r--r-- | spec/support/rubygems_version_manager.rb | 74 |
12 files changed, 63 insertions, 75 deletions
diff --git a/spec/support/artifice/compact_index.rb b/spec/support/artifice/compact_index.rb index 89362c4dbc..72abf26224 100644 --- a/spec/support/artifice/compact_index.rb +++ b/spec/support/artifice/compact_index.rb @@ -10,7 +10,7 @@ class CompactIndexAPI < Endpoint def load_spec(name, version, platform, gem_repo) full_name = "#{name}-#{version}" full_name += "-#{platform}" if platform != "ruby" - Marshal.load(Bundler.rubygems.inflate(File.open(gem_repo.join("quick/Marshal.4.8/#{full_name}.gemspec.rz")).read)) + Marshal.load(Bundler.rubygems.inflate(File.binread(gem_repo.join("quick/Marshal.4.8/#{full_name}.gemspec.rz")))) end def etag_response diff --git a/spec/support/artifice/compact_index_api_missing.rb b/spec/support/artifice/compact_index_api_missing.rb index fdd342bc08..6514fde01e 100644 --- a/spec/support/artifice/compact_index_api_missing.rb +++ b/spec/support/artifice/compact_index_api_missing.rb @@ -10,7 +10,7 @@ class CompactIndexApiMissing < CompactIndexAPI if params[:id] == "rack-1.0.gemspec.rz" halt 404 else - File.read("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") + File.binread("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") end end end diff --git a/spec/support/artifice/compact_index_extra_api_missing.rb b/spec/support/artifice/compact_index_extra_api_missing.rb index 6bd24ddbb4..b9d757c266 100644 --- a/spec/support/artifice/compact_index_extra_api_missing.rb +++ b/spec/support/artifice/compact_index_extra_api_missing.rb @@ -9,7 +9,7 @@ class CompactIndexExtraAPIMissing < CompactIndexExtraApi if params[:id] == "missing-1.0.gemspec.rz" halt 404 else - File.read("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") + File.binread("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") end end end diff --git a/spec/support/artifice/compact_index_extra_missing.rb b/spec/support/artifice/compact_index_extra_missing.rb index 4758b785ac..ff1e47a1bb 100644 --- a/spec/support/artifice/compact_index_extra_missing.rb +++ b/spec/support/artifice/compact_index_extra_missing.rb @@ -9,7 +9,7 @@ class CompactIndexExtraMissing < CompactIndexExtra if params[:id] == "missing-1.0.gemspec.rz" halt 404 else - File.read("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") + File.binread("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") end end end diff --git a/spec/support/artifice/endpoint.rb b/spec/support/artifice/endpoint.rb index bf26c56503..7bca681e70 100644 --- a/spec/support/artifice/endpoint.rb +++ b/spec/support/artifice/endpoint.rb @@ -68,7 +68,7 @@ class Endpoint < Sinatra::Base def load_spec(name, version, platform, gem_repo) full_name = "#{name}-#{version}" full_name += "-#{platform}" if platform != "ruby" - Marshal.load(Bundler.rubygems.inflate(File.open(gem_repo.join("quick/Marshal.4.8/#{full_name}.gemspec.rz")).read)) + Marshal.load(Bundler.rubygems.inflate(File.binread(gem_repo.join("quick/Marshal.4.8/#{full_name}.gemspec.rz")))) end end diff --git a/spec/support/artifice/endpoint_api_missing.rb b/spec/support/artifice/endpoint_api_missing.rb index 8dafde7362..755c42e836 100644 --- a/spec/support/artifice/endpoint_api_missing.rb +++ b/spec/support/artifice/endpoint_api_missing.rb @@ -10,7 +10,7 @@ class EndpointApiMissing < Endpoint if params[:id] == "rack-1.0.gemspec.rz" halt 404 else - File.read("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") + File.binread("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") end end end diff --git a/spec/support/artifice/endpoint_extra_missing.rb b/spec/support/artifice/endpoint_extra_missing.rb index ee129025ff..5fd9238207 100644 --- a/spec/support/artifice/endpoint_extra_missing.rb +++ b/spec/support/artifice/endpoint_extra_missing.rb @@ -9,7 +9,7 @@ class EndpointExtraMissing < EndpointExtra if params[:id] == "missing-1.0.gemspec.rz" halt 404 else - File.read("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") + File.binread("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") end end end diff --git a/spec/support/artifice/windows.rb b/spec/support/artifice/windows.rb index ce7455b86c..21170c81d9 100644 --- a/spec/support/artifice/windows.rb +++ b/spec/support/artifice/windows.rb @@ -27,7 +27,7 @@ class Windows < Sinatra::Base files.each do |file| get "/#{file}" do - File.read gem_repo.join(file) + File.binread gem_repo.join(file) end end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 911f734d8b..7d1bd65185 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "open3" - require_relative "command_execution" require_relative "the_bundle" @@ -25,9 +23,7 @@ module Spec define_method("#{method}!") do |*args, &blk| send(method, *args, &blk).tap do unless last_command.success? - raise RuntimeError, - "Invoking #{method}!(#{args.map(&:inspect).join(", ")}) failed:\n#{last_command.stdboth}", - caller.drop_while {|bt| bt.start_with?(__FILE__) } + raise "Invoking #{method}!(#{args.map(&:inspect).join(", ")}) failed:\n#{last_command.stdboth}" end end end @@ -174,7 +170,7 @@ module Spec env = options.delete(:env) || {} ruby = ruby.gsub(/["`\$]/) {|m| "\\#{m}" } lib_option = options[:no_lib] ? "" : " -I#{lib_dir}" - sys_exec(%(#{Gem.ruby}#{lib_option} -e "#{ruby}"), env) + sys_exec(%(#{Gem.ruby}#{lib_option} -w -e "#{ruby}"), env) end bang :ruby @@ -209,8 +205,7 @@ module Spec def sys_exec(cmd, env = {}) command_execution = CommandExecution.new(cmd.to_s, Dir.pwd) - env = env.map {|k, v| [k.to_s, v.to_s] }.to_h # convert env keys and values to string - + require "open3" Open3.popen3(env, cmd.to_s) do |stdin, stdout, stderr, wait_thr| yield stdin, stdout, wait_thr if block_given? stdin.close diff --git a/spec/support/path.rb b/spec/support/path.rb index cc5aebb01b..645da52c97 100644 --- a/spec/support/path.rb +++ b/spec/support/path.rb @@ -21,8 +21,12 @@ module Spec @bindir ||= root.join(ruby_core? ? "libexec" : "exe") end + def gem_cmd + @gem_cmd ||= ruby_core? ? root.join("bin/gem") : "gem" + end + def gem_bin - @gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "#{Gem.ruby} -I#{spec_dir}/rubygems -S gem --backtrace" + @gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "gem" end def spec_dir @@ -30,14 +34,20 @@ module Spec end def tracked_files + skip "not in git working directory" unless git_root_dir? + @tracked_files ||= ruby_core? ? `git ls-files -z -- lib/bundler lib/bundler.rb spec/bundler man/bundler*` : `git ls-files -z` end def shipped_files + skip "not in git working directory" unless git_root_dir? + @shipped_files ||= ruby_core? ? `git ls-files -z -- lib/bundler lib/bundler.rb man/bundler* libexec/bundle*` : `git ls-files -z -- lib man exe CHANGELOG.md LICENSE.md README.md bundler.gemspec` end def lib_tracked_files + skip "not in git working directory" unless git_root_dir? + @lib_tracked_files ||= ruby_core? ? `git ls-files -z -- lib/bundler lib/bundler.rb` : `git ls-files -z -- lib` end @@ -94,8 +104,6 @@ module Spec protocol = "file://" root = Gem.win_platform? ? "/" : "" - return protocol + "localhost" + root + path.to_s if RUBY_VERSION < "2.5" - protocol + root + path.to_s end @@ -150,7 +158,8 @@ module Spec def with_root_gemspec if ruby_core? root_gemspec = root.join("bundler.gemspec") - spec = Gem::Specification.load(gemspec.to_s) + # Dir.chdir(root) for Dir.glob in gemspec + spec = Dir.chdir(root) { Gem::Specification.load(gemspec.to_s) } spec.bindir = "libexec" File.open(root_gemspec.to_s, "w") {|f| f.write spec.to_ruby } yield(root_gemspec) @@ -172,5 +181,11 @@ module Spec end extend self + + private + + def git_root_dir? + root.to_s == `git rev-parse --show-toplevel`.chomp + end end end diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb index d237897b67..ee9c750a52 100644 --- a/spec/support/rubygems_ext.rb +++ b/spec/support/rubygems_ext.rb @@ -5,13 +5,13 @@ require_relative "path" module Spec module Rubygems DEV_DEPS = { - "automatiek" => "~> 0.2.0", + "automatiek" => "~> 0.3.0", "parallel_tests" => "~> 2.29", "rake" => "~> 12.0", "ronn" => "~> 0.7.3", "rspec" => "~> 3.8", - "rubocop" => "= 0.74.0", - "rubocop-performance" => "= 1.4.0", + "rubocop" => "= 0.77.0", + "rubocop-performance" => "= 1.5.1", }.freeze DEPS = { @@ -39,7 +39,9 @@ module Spec end def gem_load(gem_name, bin_container) - require_relative "../rubygems/rubygems" + require_relative "rubygems_version_manager" + RubygemsVersionManager.new(ENV["RGV"]).switch + gem_load_and_activate(gem_name, bin_container) end @@ -65,7 +67,7 @@ module Spec FileUtils.mkdir_p(Path.base_system_gems) puts "installing gems for the tests to use..." install_gems(DEPS) - manifest_path.open("w") {|f| f << manifest.join } + manifest_path.open("wb") {|f| f << manifest.join } end FileUtils.mkdir_p(Path.home) @@ -97,7 +99,7 @@ module Spec no_reqs.map!(&:first) reqs.map! {|name, req| "'#{name}:#{req}'" } deps = reqs.concat(no_reqs).join(" ") - gem = Path.gem_bin + gem = ENV["GEM_COMMAND"] || "#{Gem.ruby} -S gem --backtrace" cmd = "#{gem} install #{deps} --no-document --conservative" system(cmd) || raise("Installing gems #{deps} for the tests to use failed!") end diff --git a/spec/support/rubygems_version_manager.rb b/spec/support/rubygems_version_manager.rb index 356d391c08..854bce890d 100644 --- a/spec/support/rubygems_version_manager.rb +++ b/spec/support/rubygems_version_manager.rb @@ -8,27 +8,25 @@ class RubygemsVersionManager include Spec::Helpers include Spec::Path - def initialize(env_version) - @env_version = env_version + def initialize(source) + @source = source end def switch return if use_system? - unrequire_rubygems_if_needed - switch_local_copy_if_needed - prepare_environment + reexec_if_needed end private def use_system? - @env_version.nil? + @source.nil? end - def unrequire_rubygems_if_needed + def reexec_if_needed return unless rubygems_unrequire_needed? require "rbconfig" @@ -37,7 +35,8 @@ private ruby << RbConfig::CONFIG["EXEEXT"] cmd = [ruby, $0, *ARGV].compact - cmd[1, 0] = "--disable-gems" + + ENV["RUBYOPT"] = "-I#{local_copy_path.join("lib")} #{ENV["RUBYOPT"]}" exec(ENV, *cmd) end @@ -47,35 +46,28 @@ private Dir.chdir(local_copy_path) do sys_exec!("git remote update") - sys_exec!("git checkout #{target_tag_version} --quiet") + sys_exec!("git checkout #{target_tag} --quiet") end - end - def prepare_environment - $:.unshift File.expand_path("lib", local_copy_path) + ENV["RGV"] = local_copy_path.to_s end def rubygems_unrequire_needed? - defined?(Gem::VERSION) && Gem::VERSION != target_gem_version + !$LOADED_FEATURES.include?(local_copy_path.join("lib/rubygems.rb").to_s) end def local_copy_switch_needed? - !env_version_is_path? && target_gem_version != local_copy_version - end - - def target_gem_version - @target_gem_version ||= resolve_target_gem_version + !source_is_path? && target_tag != local_copy_tag end - def target_tag_version - @target_tag_version ||= resolve_target_tag_version + def target_tag + @target_tag ||= resolve_target_tag end - def local_copy_version - gemspec_contents = File.read(local_copy_path.join("lib/rubygems.rb")) - version_regexp = /VERSION = ["'](.*)["']/ - - version_regexp.match(gemspec_contents)[1] + def local_copy_tag + Dir.chdir(local_copy_path) do + sys_exec!("git rev-parse --abbrev-ref HEAD") + end end def local_copy_path @@ -83,7 +75,7 @@ private end def resolve_local_copy_path - return expanded_env_version if env_version_is_path? + return expanded_source if source_is_path? rubygems_path = root.join("tmp/rubygems") @@ -95,33 +87,17 @@ private rubygems_path end - def env_version_is_path? - expanded_env_version.directory? + def source_is_path? + expanded_source.directory? end - def expanded_env_version - @expanded_env_version ||= Pathname.new(@env_version).expand_path(root) + def expanded_source + @expanded_source ||= Pathname.new(@source).expand_path(root) end - def resolve_target_tag_version - return "v#{@env_version}" if @env_version.match(/^\d/) - - return "master" if @env_version == master_gem_version - - @env_version - end - - def resolve_target_gem_version - return local_copy_version if env_version_is_path? - - return @env_version[1..-1] if @env_version.match(/^v/) - - return master_gem_version if @env_version == "master" - - @env_version - end + def resolve_target_tag + return "v#{@source}" if @source.match(/^\d/) - def master_gem_version - "3.1.0.pre1" + @source end end |