From 68ddd4d300e9a88737c4f37af74e1a0312949b2f Mon Sep 17 00:00:00 2001 From: hsbt Date: Sun, 14 Apr 2019 06:01:35 +0000 Subject: Merge Bundler 2.1.0.pre.1 as developed version from upstream. https://github.com/bundler/bundler/commit/a53709556b95a914e874b22ed2116a46b0528852 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/bundler/support/artifice/compact_index.rb | 12 ++-- .../support/artifice/compact_index_api_missing.rb | 2 +- .../support/artifice/compact_index_rate_limited.rb | 48 +++++++++++++++ spec/bundler/support/artifice/endpoint.rb | 2 +- .../support/artifice/endpoint_api_missing.rb | 2 +- spec/bundler/support/artifice/vcr.rb | 7 --- spec/bundler/support/builders.rb | 12 ++-- spec/bundler/support/helpers.rb | 72 +++++++++++----------- spec/bundler/support/indexes.rb | 4 +- spec/bundler/support/less_than_proc.rb | 20 ------ spec/bundler/support/matchers.rb | 50 ++++----------- spec/bundler/support/path.rb | 2 +- spec/bundler/support/platforms.rb | 5 +- spec/bundler/support/requirement_checker.rb | 11 ++++ spec/bundler/support/rubygems_ext.rb | 42 +++++-------- 15 files changed, 140 insertions(+), 151 deletions(-) create mode 100644 spec/bundler/support/artifice/compact_index_rate_limited.rb delete mode 100644 spec/bundler/support/less_than_proc.rb create mode 100644 spec/bundler/support/requirement_checker.rb (limited to 'spec/bundler/support') diff --git a/spec/bundler/support/artifice/compact_index.rb b/spec/bundler/support/artifice/compact_index.rb index 01e8eb7837..4f01690ae4 100644 --- a/spec/bundler/support/artifice/compact_index.rb +++ b/spec/bundler/support/artifice/compact_index.rb @@ -21,7 +21,7 @@ class CompactIndexAPI < Endpoint headers "Surrogate-Control" => "max-age=2592000, stale-while-revalidate=60" content_type "text/plain" requested_range_for(response_body) - rescue => e + rescue StandardError => e puts e puts e.backtrace raise @@ -57,11 +57,7 @@ class CompactIndexAPI < Endpoint end def slice_body(body, range) - if body.respond_to?(:byteslice) - body.byteslice(range) - else # pre-1.9.3 - body.unpack("@#{range.first}a#{range.end + 1}").first - end + body.byteslice(range) end def gems(gem_repo = GEM_REPO) @@ -82,8 +78,8 @@ class CompactIndexAPI < Endpoint CompactIndex::Dependency.new(d.name, reqs) end checksum = begin - Digest::SHA256.file("#{GEM_REPO}/gems/#{spec.original_name}.gem").base64digest - rescue + Digest(:SHA256).file("#{GEM_REPO}/gems/#{spec.original_name}.gem").base64digest + rescue StandardError nil end CompactIndex::GemVersion.new(spec.version.version, spec.platform.to_s, checksum, nil, diff --git a/spec/bundler/support/artifice/compact_index_api_missing.rb b/spec/bundler/support/artifice/compact_index_api_missing.rb index d4e68c38e8..94e6b73000 100644 --- a/spec/bundler/support/artifice/compact_index_api_missing.rb +++ b/spec/bundler/support/artifice/compact_index_api_missing.rb @@ -6,7 +6,7 @@ Artifice.deactivate class CompactIndexApiMissing < CompactIndexAPI get "/fetch/actual/gem/:id" do - $stderr.puts params[:id] + warn params[:id] if params[:id] == "rack-1.0.gemspec.rz" halt 404 else diff --git a/spec/bundler/support/artifice/compact_index_rate_limited.rb b/spec/bundler/support/artifice/compact_index_rate_limited.rb new file mode 100644 index 0000000000..d8f4fc941c --- /dev/null +++ b/spec/bundler/support/artifice/compact_index_rate_limited.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require File.expand_path("../compact_index", __FILE__) + +Artifice.deactivate + +class CompactIndexRateLimited < CompactIndexAPI + class RequestCounter + def self.queue + @queue ||= Queue.new + end + + def self.size + @queue.size + end + + def self.enq(name) + @queue.enq(name) + end + + def self.deq + @queue.deq + end + end + + configure do + RequestCounter.queue + end + + get "/info/:name" do + RequestCounter.enq(params[:name]) + + begin + if RequestCounter.size == 1 + etag_response do + gem = gems.find {|g| g.name == params[:name] } + CompactIndex.info(gem ? gem.versions : []) + end + else + status 429 + end + ensure + RequestCounter.deq + end + end +end + +Artifice.activate_with(CompactIndexRateLimited) diff --git a/spec/bundler/support/artifice/endpoint.rb b/spec/bundler/support/artifice/endpoint.rb index 9a0cfae8a2..fcced6ea35 100644 --- a/spec/bundler/support/artifice/endpoint.rb +++ b/spec/bundler/support/artifice/endpoint.rb @@ -59,7 +59,7 @@ class Endpoint < Sinatra::Base :platform => spec.platform.to_s, :dependencies => spec.dependencies.select {|dep| dep.type == :runtime }.map do |dep| [dep.name, dep.requirement.requirements.map {|a| a.join(" ") }.join(", ")] - end + end, } end.compact end diff --git a/spec/bundler/support/artifice/endpoint_api_missing.rb b/spec/bundler/support/artifice/endpoint_api_missing.rb index 95db8e2a7e..2ada0dc553 100644 --- a/spec/bundler/support/artifice/endpoint_api_missing.rb +++ b/spec/bundler/support/artifice/endpoint_api_missing.rb @@ -6,7 +6,7 @@ Artifice.deactivate class EndpointApiMissing < Endpoint get "/fetch/actual/gem/:id" do - $stderr.puts params[:id] + warn params[:id] if params[:id] == "rack-1.0.gemspec.rz" halt 404 else diff --git a/spec/bundler/support/artifice/vcr.rb b/spec/bundler/support/artifice/vcr.rb index edd2f49a91..1e3809ff62 100644 --- a/spec/bundler/support/artifice/vcr.rb +++ b/spec/bundler/support/artifice/vcr.rb @@ -1,13 +1,6 @@ # frozen_string_literal: true require "net/http" -if RUBY_VERSION < "1.9" - begin - require "net/https" - rescue LoadError - nil # net/https or openssl - end -end # but only for 1.8 CASSETTE_PATH = File.expand_path("../vcr_cassettes", __FILE__) CASSETTE_NAME = ENV.fetch("BUNDLER_SPEC_VCR_CASSETTE_NAME") { "realworld" } diff --git a/spec/bundler/support/builders.rb b/spec/bundler/support/builders.rb index 97134a045a..33a81f6f65 100644 --- a/spec/bundler/support/builders.rb +++ b/spec/bundler/support/builders.rb @@ -40,7 +40,7 @@ module Spec build_gem "rails", "2.3.2" do |s| s.executables = "rails" - s.add_dependency "rake", "10.0.2" + s.add_dependency "rake", "12.3.2" s.add_dependency "actionpack", "2.3.2" s.add_dependency "activerecord", "2.3.2" s.add_dependency "actionmailer", "2.3.2" @@ -210,12 +210,7 @@ module Spec # The yard gem iterates over Gem.source_index looking for plugins build_gem "yard" do |s| s.write "lib/yard.rb", <<-Y - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("1.8.10") - specs = Gem::Specification - else - specs = Gem.source_index.find_name('') - end - specs.sort_by(&:name).each do |gem| + Gem::Specification.sort_by(&:name).each do |gem| puts gem.full_name end Y @@ -653,7 +648,8 @@ module Spec `git add *` `git config user.email "lol@wut.com"` `git config user.name "lolwut"` - `git commit -m 'OMG INITIAL COMMIT'` + `git config commit.gpgsign false` + `git commit -m "OMG INITIAL COMMIT"` end end end diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index 89c67c45b7..09e7419a98 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -41,19 +41,25 @@ module Spec end def out - last_command.stdboth + last_command.stdout end def err - last_command.stderr + Bundler.feature_flag.error_on_stderr? ? last_command.stderr : last_command.stdout end - def exitstatus - last_command.exitstatus + MAJOR_DEPRECATION = /^\[DEPRECATED\]\s*/.freeze + + def err_without_deprecations + last_command.stderr.gsub(/#{MAJOR_DEPRECATION}.+[\n]?/, "") end - def bundle_update_requires_all? - Bundler::VERSION.start_with?("2.") ? nil : true + def deprecations + err.split("\n").select {|l| l =~ MAJOR_DEPRECATION }.join("\n").split(MAJOR_DEPRECATION) + end + + def exitstatus + last_command.exitstatus end def in_app_root(&blk) @@ -71,7 +77,7 @@ module Spec def run(cmd, *args) opts = args.last.is_a?(Hash) ? args.pop : {} groups = args.map(&:inspect).join(", ") - setup = "require 'rubygems' ; require 'bundler' ; Bundler.setup(#{groups})\n" + setup = "require 'bundler' ; Bundler.setup(#{groups})\n" ruby(setup + cmd, opts) end bang :run @@ -131,8 +137,6 @@ module Spec load_path << spec load_path_str = "-I#{load_path.join(File::PATH_SEPARATOR)}" - env = env.map {|k, v| "#{k}='#{v}'" }.join(" ") - args = options.map do |k, v| case v when nil @@ -146,13 +150,13 @@ module Spec end end.join - cmd = "#{env} #{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}" - sys_exec(cmd) {|i, o, thr| yield i, o, thr if block_given? } + cmd = "#{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}" + sys_exec(cmd, env) {|i, o, thr| yield i, o, thr if block_given? } end bang :bundle def forgotten_command_line_options(options) - remembered = Bundler.bundler_major_version < 3 + remembered = Bundler::VERSION.split(".", 2).first == "2" options = options.map do |k, v| k = Array(k)[remembered ? 0 : -1] v = '""' if v && v.to_s.empty? @@ -161,9 +165,9 @@ module Spec return Hash[options] if remembered options.each do |k, v| if v.nil? - bundle! "config --delete #{k}" + bundle! "config unset #{k}" else - bundle! "config --local #{k} #{v}" + bundle! "config set --local #{k} #{v}" end end {} @@ -174,11 +178,6 @@ module Spec bundle(cmd, options) end - def bundle_ruby(options = {}) - options["bundle_bin"] = bindir.join("bundle_ruby") - bundle("", options) - end - def ruby(ruby, options = {}) env = (options.delete(:env) || {}).map {|k, v| "#{k}='#{v}' " }.join ruby = ruby.gsub(/["`\$]/) {|m| "\\#{m}" } @@ -221,16 +220,18 @@ module Spec "#{Gem.ruby} -S #{ENV["GEM_PATH"]}/bin/rake" end - def sys_exec(cmd) + def sys_exec(cmd, env = {}) command_execution = CommandExecution.new(cmd.to_s, Dir.pwd) - Open3.popen3(cmd.to_s) do |stdin, stdout, stderr, wait_thr| + env = env.map {|k, v| [k.to_s, v.to_s] }.to_h # convert env keys and values to string + + Open3.popen3(env, cmd.to_s) do |stdin, stdout, stderr, wait_thr| yield stdin, stdout, wait_thr if block_given? stdin.close - command_execution.exitstatus = wait_thr && wait_thr.value.exitstatus command_execution.stdout = Thread.new { stdout.read }.value.strip command_execution.stderr = Thread.new { stderr.read }.value.strip + command_execution.exitstatus = wait_thr && wait_thr.value.exitstatus end (@command_executions ||= []) << command_execution @@ -263,18 +264,22 @@ module Spec end def gemfile(*args) - if args.empty? + contents = args.shift + + if contents.nil? File.open("Gemfile", "r", &:read) else - create_file("Gemfile", *args) + create_file("Gemfile", contents, *args) end end def lockfile(*args) - if args.empty? + contents = args.shift + + if contents.nil? File.open("Gemfile.lock", "r", &:read) else - create_file("Gemfile.lock", *args) + create_file("Gemfile.lock", normalize_uri_file(contents), *args) end end @@ -323,7 +328,7 @@ module Spec Dir.chdir(root) { gem_command! :build, gemspec.to_s } end bundler_path = root + "bundler-#{Bundler::VERSION}.gem" - elsif g.to_s =~ %r{\A/.*\.gem\z} + elsif g.to_s =~ %r{\A(?:[A-Z]:)?/.*\.gem\z} g else "#{gem_repo}/gems/#{g}.gem" @@ -331,11 +336,8 @@ module Spec raise "OMG `#{path}` does not exist!" unless File.exist?(path) - if Gem::VERSION < "2.0.0" - gem_command! :install, "--no-rdoc --no-ri --ignore-dependencies '#{path}'" - else - gem_command! :install, "--no-document --ignore-dependencies '#{path}'" - end + gem_command! :install, "--no-document --ignore-dependencies '#{path}'" + bundler_path && bundler_path.rmtree end end @@ -437,7 +439,7 @@ module Spec ENV["GEM_PATH"] = system_gem_path.to_s gems.each do |gem| - gem_command :install, "--no-rdoc --no-ri #{gem}" + gem_command! :install, "--no-document #{gem}" end return unless block_given? begin @@ -577,7 +579,7 @@ module Spec tries = 0 sleep 0.5 TCPSocket.new(host, port) - rescue => e + rescue StandardError => e raise(e) if tries > (seconds * 2) tries += 1 retry @@ -587,7 +589,7 @@ module Spec port = 21_453 begin port += 1 while TCPSocket.new("127.0.0.1", port) - rescue + rescue StandardError false end port diff --git a/spec/bundler/support/indexes.rb b/spec/bundler/support/indexes.rb index 69f8d9f679..b76f493d01 100644 --- a/spec/bundler/support/indexes.rb +++ b/spec/bundler/support/indexes.rb @@ -77,7 +77,7 @@ module Spec gem "rack-mount", %w[0.4 0.5 0.5.1 0.5.2 0.6] # --- Pre-release support - gem "rubygems\0", ["1.3.2"] + gem "RubyGems\0", ["1.3.2"] # --- Rails versions "1.2.3 2.2.3 2.3.5 3.0.0.beta 3.0.0.beta1" do |version| @@ -414,7 +414,7 @@ module Spec gem("b", %w[0.9.0 1.5.0 2.0.0.pre]) # --- Pre-release support - gem "rubygems\0", ["1.3.2"] + gem "RubyGems\0", ["1.3.2"] end end end diff --git a/spec/bundler/support/less_than_proc.rb b/spec/bundler/support/less_than_proc.rb deleted file mode 100644 index ddac5458b7..0000000000 --- a/spec/bundler/support/less_than_proc.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class LessThanProc < Proc - attr_accessor :present - - def self.with(present) - provided = Gem::Version.new(present.dup) - new do |required| - if required =~ /[=><~]/ - !Gem::Requirement.new(required).satisfied_by?(provided) - else - provided < Gem::Version.new(required) - end - end.tap {|l| l.present = present } - end - - def inspect - "\"=< #{present}\"" - end -end diff --git a/spec/bundler/support/matchers.rb b/spec/bundler/support/matchers.rb index 8e17be3a02..f9efe32a38 100644 --- a/spec/bundler/support/matchers.rb +++ b/spec/bundler/support/matchers.rb @@ -60,36 +60,6 @@ module Spec end end - MAJOR_DEPRECATION = /^\[DEPRECATED FOR 2\.0\]\s*/ - - RSpec::Matchers.define :lack_errors do - diffable - match do |actual| - actual.gsub(/#{MAJOR_DEPRECATION}.+[\n]?/, "") == "" - end - end - - RSpec::Matchers.define :eq_err do |expected| - diffable - match do |actual| - actual.gsub(/#{MAJOR_DEPRECATION}.+[\n]?/, "") == expected - end - end - - RSpec::Matchers.define :have_major_deprecation do |expected| - diffable - match do |actual| - deprecations = actual.split(MAJOR_DEPRECATION) - - return !expected.nil? if deprecations.size <= 1 - return true if expected.nil? - - deprecations.any? do |d| - !d.empty? && values_match?(expected, d.strip) - end - end - end - RSpec::Matchers.define :have_dep do |*args| dep = Bundler::Dependency.new(*args) @@ -128,6 +98,14 @@ module Spec end end + RSpec::Matchers.define :be_well_formed do + match(&:empty?) + + failure_message do |actual| + actual.join("\n") + end + end + define_compound_matcher :read_as, [exist] do |file_contents| diffable @@ -152,10 +130,9 @@ module Spec version_const = name == "bundler" ? "Bundler::VERSION" : Spec::Builders.constantize(name) begin run! "require '#{name}.rb'; puts #{version_const}", *groups - rescue => e + rescue StandardError => e next "#{name} is not installed:\n#{indent(e)}" end - last_command.stdout.gsub!(/#{MAJOR_DEPRECATION}.*$/, "") actual_version, actual_platform = last_command.stdout.strip.split(/\s+/, 2) unless Gem::Version.new(actual_version) == Gem::Version.new(version) next "#{name} was expected to be at version #{version} but was #{actual_version}" @@ -167,10 +144,9 @@ module Spec begin source_const = "#{Spec::Builders.constantize(name)}_SOURCE" run! "require '#{name}/source'; puts #{source_const}", *groups - rescue + rescue StandardError next "#{name} does not have a source defined:\n#{indent(e)}" end - last_command.stdout.gsub!(/#{MAJOR_DEPRECATION}.*$/, "") unless last_command.stdout.strip == source next "Expected #{name} (#{version}) to be installed from `#{source}`, was actually from `#{out}`" end @@ -193,7 +169,7 @@ module Spec puts "WIN" end R - rescue => e + rescue StandardError => e next "checking for #{name} failed:\n#{e}" end next if last_command.stdout == "WIN" @@ -218,7 +194,7 @@ module Spec RSpec::Matchers.alias_matcher :include_gem, :include_gems def have_lockfile(expected) - read_as(strip_whitespace(expected)) + read_as(normalize_uri_file(strip_whitespace(expected))) end def plugin_should_be_installed(*names) @@ -236,7 +212,7 @@ module Spec end def lockfile_should_be(expected) - expect(bundled_app("Gemfile.lock")).to read_as(normalize_uri_file(strip_whitespace(expected))) + expect(bundled_app("Gemfile.lock")).to have_lockfile(expected) end def gemfile_should_be(expected) diff --git a/spec/bundler/support/path.rb b/spec/bundler/support/path.rb index 69efcba051..dc4b3bb6eb 100644 --- a/spec/bundler/support/path.rb +++ b/spec/bundler/support/path.rb @@ -99,7 +99,7 @@ module Spec end def bundler_path - Pathname.new(File.expand_path(root.join("lib"), __FILE__)) + root.join("lib") end def global_plugin_gem(*args) diff --git a/spec/bundler/support/platforms.rb b/spec/bundler/support/platforms.rb index 950311d20e..0a9e4a8cb6 100644 --- a/spec/bundler/support/platforms.rb +++ b/spec/bundler/support/platforms.rb @@ -100,9 +100,8 @@ module Spec 9999 end - def lockfile_platforms(*platforms) - platforms = local_platforms if platforms.empty? - platforms.map(&:to_s).sort.join("\n ") + def lockfile_platforms + local_platforms.map(&:to_s).sort.join("\n ") end def local_platforms diff --git a/spec/bundler/support/requirement_checker.rb b/spec/bundler/support/requirement_checker.rb new file mode 100644 index 0000000000..d8f5fd5e5f --- /dev/null +++ b/spec/bundler/support/requirement_checker.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class RequirementChecker < Proc + def self.against(present) + provided = Gem::Version.new(present) + + new do |required| + !Gem::Requirement.new(required).satisfied_by?(provided) + end + end +end diff --git a/spec/bundler/support/rubygems_ext.rb b/spec/bundler/support/rubygems_ext.rb index 42f887f268..2f3d252865 100644 --- a/spec/bundler/support/rubygems_ext.rb +++ b/spec/bundler/support/rubygems_ext.rb @@ -1,31 +1,25 @@ # frozen_string_literal: true require "rubygems/user_interaction" -require "support/path" unless defined?(Spec::Path) +require "support/path" +require "fileutils" module Spec module Rubygems DEPS = begin - deps = { - # rack 2.x requires Ruby version >= 2.2.2. + { # artifice doesn't support rack 2.x now. - # TODO: revert to `< 2` once https://github.com/rack/rack/issues/1168 is - # addressed - "rack" => "1.6.6", - # rack-test 0.7.0 dropped 1.8.7 support - # https://github.com/rack-test/rack-test/issues/193#issuecomment-314230318 - "rack-test" => "< 0.7.0", + "rack" => "< 2.0", + "rack-test" => "~> 1.1", "artifice" => "~> 0.6.0", "compact_index" => "~> 0.11.0", "sinatra" => "~> 1.4.7", # Rake version has to be consistent for tests to pass - "rake" => "10.0.2", - # 3.0.0 breaks 1.9.2 specs - "builder" => "2.1.2", + "rake" => "12.3.2", + "builder" => "~> 3.2", + # ruby-graphviz is used by the viz tests + "ruby-graphviz" => nil, } - # ruby-graphviz is used by the viz tests - deps["ruby-graphviz"] = nil if RUBY_VERSION >= "1.9.3" - deps end def self.setup @@ -33,17 +27,17 @@ module Spec ENV["BUNDLE_PATH"] = nil ENV["GEM_HOME"] = ENV["GEM_PATH"] = Path.base_system_gems.to_s - ENV["PATH"] = [Path.bindir, "#{Path.system_gem_path}/bin", ENV["PATH"]].join(File::PATH_SEPARATOR) + ENV["PATH"] = [Path.bindir, Path.system_gem_path.join("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR) manifest = DEPS.to_a.sort_by(&:first).map {|k, v| "#{k} => #{v}\n" } - manifest_path = "#{Path.base_system_gems}/manifest.txt" + manifest_path = Path.base_system_gems.join("manifest.txt") # it's OK if there are extra gems - if !File.exist?(manifest_path) || !(manifest - File.readlines(manifest_path)).empty? + if !manifest_path.file? || !(manifest - manifest_path.readlines).empty? FileUtils.rm_rf(Path.base_system_gems) FileUtils.mkdir_p(Path.base_system_gems) puts "installing gems for the tests to use..." install_gems(DEPS) - File.open(manifest_path, "w") {|f| f << manifest.join } + manifest_path.open("w") {|f| f << manifest.join } end ENV["HOME"] = Path.home.to_s @@ -54,17 +48,11 @@ module Spec def self.install_gems(gems) reqs, no_reqs = gems.partition {|_, req| !req.nil? && !req.split(" ").empty? } - # TODO: remove when we drop ruby 1.8.7-2.2.2 support - reqs = reqs.sort_by {|name, _| name == "rack" ? 0 : 1 }.sort_by {|name, _| name =~ /rack/ ? 0 : 1 } no_reqs.map!(&:first) reqs.map! {|name, req| "'#{name}:#{req}'" } deps = reqs.concat(no_reqs).join(" ") - gem = Spec::Path.ruby_core? ? ENV["BUNDLE_GEM"] : "gem" - cmd = if Gem::VERSION < "2.0.0" - "#{gem} install #{deps} --no-rdoc --no-ri --conservative" - else - "#{gem} install #{deps} --no-document --conservative" - end + gem = Spec::Path.ruby_core? ? ENV["BUNDLE_GEM"] : "#{Gem.ruby} -S gem" + cmd = "#{gem} install #{deps} --no-document --conservative" puts cmd system(cmd) || raise("Installing gems #{deps} for the tests to use failed!") end -- cgit v1.2.3