From 4525cf2cd599389be3fab30ae4c13e22050705b5 Mon Sep 17 00:00:00 2001 From: hsbt Date: Thu, 21 Dec 2017 09:22:15 +0000 Subject: Merge release version of bundler-1.16.1 from upstream. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/bundler/commands/exec_spec.rb | 30 ++++++++----- spec/bundler/commands/newgem_spec.rb | 6 ++- spec/bundler/commands/pristine_spec.rb | 5 ++- spec/bundler/commands/update_spec.rb | 2 +- spec/bundler/install/gemfile/sources_spec.rb | 5 +-- spec/bundler/realworld/double_check_spec.rb | 66 ++++++++++++++-------------- spec/bundler/runtime/gem_tasks_spec.rb | 6 ++- spec/bundler/runtime/require_spec.rb | 6 +-- spec/bundler/runtime/setup_spec.rb | 8 ++-- spec/bundler/runtime/with_clean_env_spec.rb | 39 +++++++++------- spec/bundler/spec_helper.rb | 25 ++++++----- spec/bundler/support/hax.rb | 6 +++ spec/bundler/support/helpers.rb | 2 +- 13 files changed, 116 insertions(+), 90 deletions(-) (limited to 'spec') diff --git a/spec/bundler/commands/exec_spec.rb b/spec/bundler/commands/exec_spec.rb index 077e1b03a2..894db8cb36 100644 --- a/spec/bundler/commands/exec_spec.rb +++ b/spec/bundler/commands/exec_spec.rb @@ -29,7 +29,7 @@ RSpec.describe "bundle exec" do gem "rack" G - bundle "exec 'cd #{tmp("gems")} && rackup'" + bundle "exec 'cd #{tmp("gems")} && rackup'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to include("1.0.0") end @@ -42,7 +42,7 @@ RSpec.describe "bundle exec" do it "works when exec'ing to ruby" do install_gemfile 'gem "rack"' - bundle "exec ruby -e 'puts %{hi}'" + bundle "exec ruby -e 'puts %{hi}'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to eq("hi") end @@ -76,7 +76,9 @@ RSpec.describe "bundle exec" do G install_gemfile "" - sys_exec("#{Gem.ruby} #{command.path}") + with_env_vars "RUBYOPT" => "-r#{spec_dir.join("support/hax")}" do + sys_exec "#{Gem.ruby} #{command.path}" + end if Bundler.current_ruby.ruby_2? expect(out).to eq("") @@ -237,7 +239,7 @@ RSpec.describe "bundle exec" do G [true, false].each do |l| bundle! "config disable_exec_load #{l}" - bundle "exec rackup" + bundle "exec rackup", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(last_command.stderr).to include "rack is not part of the bundle. Add it to your Gemfile." end end @@ -339,14 +341,14 @@ RSpec.describe "bundle exec" do end it "works when unlocked", :ruby_repo do - bundle "exec 'cd #{tmp("gems")} && rackup'" + bundle "exec 'cd #{tmp("gems")} && rackup'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to eq("1.0.0") expect(out).to include("1.0.0") end it "works when locked", :ruby_repo do expect(the_bundle).to be_locked - bundle "exec 'cd #{tmp("gems")} && rackup'" + bundle "exec 'cd #{tmp("gems")} && rackup'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to include("1.0.0") end end @@ -472,7 +474,7 @@ RSpec.describe "bundle exec" do Bundler.rubygems.extend(Monkey) G bundle "install --deployment" - bundle "exec ruby -e '`#{bindir.join("bundler")} -v`; puts $?.success?'" + bundle "exec ruby -e '`#{bindir.join("bundler")} -v`; puts $?.success?'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to match("true") end end @@ -512,7 +514,7 @@ RSpec.describe "bundle exec" do let(:expected) { [exec, args, rack, process].join("\n") } let(:expected_err) { "" } - subject { bundle "exec #{path} arg1 arg2" } + subject { bundle "exec #{path} arg1 arg2", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } } shared_examples_for "it runs" do it "like a normally executed executable" do @@ -550,6 +552,7 @@ RSpec.describe "bundle exec" do ex << "raise SignalException, 'SIGTERM'\n" ex end + let(:expected_err) { ENV["TRAVIS"] ? "Terminated" : "" } let(:exit_code) do # signal mask 128 + plus signal 15 -> TERM # this is specified by C99 @@ -778,10 +781,13 @@ __FILE__: #{path.to_s.inspect} file.chmod(0o777) aggregate_failures do - expect(bundle!("exec #{file}", :system_bundler => true, :artifice => nil)).to eq(expected) - expect(bundle!("exec bundle exec #{file}", :system_bundler => true, :artifice => nil)).to eq(expected) - expect(bundle!("exec ruby #{file}", :system_bundler => true, :artifice => nil)).to eq(expected) - expect(run!(file.read, :no_lib => true, :artifice => nil)).to eq(expected) + expect(bundle!("exec #{file}", :artifice => nil)).to eq(expected) + expect(bundle!("exec bundle exec #{file}", :artifice => nil)).to eq(expected) + expect(bundle!("exec ruby #{file}", :artifice => nil)).to eq(expected) + # Ignore expectaion for default bundler gem conflict. + unless ENV["BUNDLER_SPEC_SUB_VERSION"] + expect(run!(file.read, :no_lib => true, :artifice => nil)).to eq(expected) + end end # sanity check that we get the newer, custom version without bundler diff --git a/spec/bundler/commands/newgem_spec.rb b/spec/bundler/commands/newgem_spec.rb index dcd89391a4..97695cc1cd 100644 --- a/spec/bundler/commands/newgem_spec.rb +++ b/spec/bundler/commands/newgem_spec.rb @@ -191,7 +191,7 @@ RSpec.describe "bundle gem" do it "generates a valid gemspec" do in_app_root - bundle "gem newgem --bin" + bundle! "gem newgem --bin" process_file(bundled_app("newgem", "newgem.gemspec")) do |line| # Simulate replacing TODOs with real values @@ -211,7 +211,9 @@ RSpec.describe "bundle gem" do end Dir.chdir(bundled_app("newgem")) do - system_gems ["rake-10.0.2"], :path => :bundle_path + gems = ["rake-10.0.2", :bundler] + gems.delete(:bundler) if ENV["BUNDLE_RUBY"] && ENV["BUNDLE_GEM"] + system_gems gems, :path => :bundle_path bundle! "exec rake build" end diff --git a/spec/bundler/commands/pristine_spec.rb b/spec/bundler/commands/pristine_spec.rb index ee75934380..24291c1918 100644 --- a/spec/bundler/commands/pristine_spec.rb +++ b/spec/bundler/commands/pristine_spec.rb @@ -41,11 +41,14 @@ RSpec.describe "bundle pristine", :ruby_repo do end it "does not delete the bundler gem", :ruby_repo do + ENV["BUNDLER_SPEC_KEEP_DEFAULT_BUNDLER_GEM"] = "true" system_gems :bundler bundle! "install" bundle! "pristine", :system_bundler => true bundle! "-v", :system_bundler => true - expect(out).to end_with(Bundler::VERSION) + # An old rubygems couldn't handle a correct version of vendoered bundler. + bundler_version = Gem::VERSION < "2.1" ? "1.16.0" : Bundler::VERSION + expect(out).to end_with(bundler_version) end end diff --git a/spec/bundler/commands/update_spec.rb b/spec/bundler/commands/update_spec.rb index a2842f0998..33679dd649 100644 --- a/spec/bundler/commands/update_spec.rb +++ b/spec/bundler/commands/update_spec.rb @@ -657,7 +657,7 @@ RSpec.describe "bundle update --bundler" do source "file:#{gem_repo4}" gem "rack" G - lockfile lockfile.sub(Bundler::VERSION, "1.0.0") + lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, '\11.0.0\2') FileUtils.rm_r gem_repo4 diff --git a/spec/bundler/install/gemfile/sources_spec.rb b/spec/bundler/install/gemfile/sources_spec.rb index 1a4e87514f..8ba3ec2d27 100644 --- a/spec/bundler/install/gemfile/sources_spec.rb +++ b/spec/bundler/install/gemfile/sources_spec.rb @@ -435,12 +435,11 @@ RSpec.describe "bundle install with gems on multiple sources" do end it "does not unlock the non-path gem after install" do - bundle :install + bundle! :install - bundle %(exec ruby -e 'puts "OK"') + bundle! %(exec ruby -e 'puts "OK"'), :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to include("OK") - expect(exitstatus).to eq(0) if exitstatus end end end diff --git a/spec/bundler/realworld/double_check_spec.rb b/spec/bundler/realworld/double_check_spec.rb index 0aa58b3de3..94ab49ba2a 100644 --- a/spec/bundler/realworld/double_check_spec.rb +++ b/spec/bundler/realworld/double_check_spec.rb @@ -1,42 +1,40 @@ # frozen_string_literal: true RSpec.describe "double checking sources", :realworld => true do - if RUBY_VERSION >= "2.2" # rails 5.x and rack 2.x only supports >= Ruby 2.2. - it "finds already-installed gems" do - create_file("rails.gemspec", <<-RUBY) - Gem::Specification.new do |s| - s.name = "rails" - s.version = "5.1.4" - s.summary = "" - s.description = "" - s.author = "" - s.add_dependency "actionpack", "5.1.4" - end - RUBY + it "finds already-installed gems", :ruby => ">= 2.2" do + create_file("rails.gemspec", <<-RUBY) + Gem::Specification.new do |s| + s.name = "rails" + s.version = "5.1.4" + s.summary = "" + s.description = "" + s.author = "" + s.add_dependency "actionpack", "5.1.4" + end + RUBY - create_file("actionpack.gemspec", <<-RUBY) - Gem::Specification.new do |s| - s.name = "actionpack" - s.version = "5.1.4" - s.summary = "" - s.description = "" - s.author = "" - s.add_dependency "rack", "~> 2.0.0" - end - RUBY + create_file("actionpack.gemspec", <<-RUBY) + Gem::Specification.new do |s| + s.name = "actionpack" + s.version = "5.1.4" + s.summary = "" + s.description = "" + s.author = "" + s.add_dependency "rack", "~> 2.0.0" + end + RUBY - cmd = <<-RUBY - require "bundler" - require #{File.expand_path("../../support/artifice/vcr.rb", __FILE__).dump} - require "bundler/inline" - gemfile(true) do - source "https://rubygems.org" - gem "rails", path: "." - end - RUBY + cmd = <<-RUBY + require "bundler" + require #{File.expand_path("../../support/artifice/vcr.rb", __FILE__).dump} + require "bundler/inline" + gemfile(true) do + source "https://rubygems.org" + gem "rails", path: "." + end + RUBY - ruby! cmd - ruby! cmd - end + ruby! cmd + ruby! cmd end end diff --git a/spec/bundler/runtime/gem_tasks_spec.rb b/spec/bundler/runtime/gem_tasks_spec.rb index 500c3128fd..1cf808f35b 100644 --- a/spec/bundler/runtime/gem_tasks_spec.rb +++ b/spec/bundler/runtime/gem_tasks_spec.rb @@ -36,7 +36,9 @@ RSpec.describe "require 'bundler/gem_tasks'" do end it "adds 'pkg' to rake/clean's CLOBBER" do - require "bundler/gem_tasks" - expect(CLOBBER).to include("pkg") + with_gem_path_as(Spec::Path.base_system_gems.to_s) do + sys_exec! %(#{rake} -e 'load "Rakefile"; puts CLOBBER.inspect') + end + expect(last_command.stdout).to eq '["pkg"]' end end diff --git a/spec/bundler/runtime/require_spec.rb b/spec/bundler/runtime/require_spec.rb index 3eccd60fba..0484e38845 100644 --- a/spec/bundler/runtime/require_spec.rb +++ b/spec/bundler/runtime/require_spec.rb @@ -264,13 +264,13 @@ RSpec.describe "Bundler.require" do describe "using bundle exec" do it "requires the locked gems" do - bundle "exec ruby -e 'Bundler.require'" + bundle "exec ruby -e 'Bundler.require'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to eq("two") - bundle "exec ruby -e 'Bundler.require(:bar)'" + bundle "exec ruby -e 'Bundler.require(:bar)'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to eq("baz\nqux") - bundle "exec ruby -e 'Bundler.require(:default, :bar)'" + bundle "exec ruby -e 'Bundler.require(:default, :bar)'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to eq("baz\nqux\ntwo") end end diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index ec2da2be2f..97d2ea1918 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -763,7 +763,7 @@ end G ENV["GEM_HOME"] = "" - bundle %(exec ruby -e "require 'set'") + bundle %(exec ruby -e "require 'set'"), :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(err).to lack_errors end @@ -1078,7 +1078,7 @@ end gem "bundler", :path => "#{File.expand_path("..", lib)}" G - bundle %(exec ruby -e "require 'bundler'; Bundler.setup") + bundle %(exec ruby -e "require 'bundler'; Bundler.setup"), :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(err).to lack_errors end end @@ -1236,6 +1236,7 @@ end end let(:activation_warning_hack) { strip_whitespace(<<-RUBY) } + require #{spec_dir.join("support/hax").to_s.dump} require "rubygems" if Gem::Specification.instance_methods.map(&:to_sym).include?(:activate) @@ -1279,8 +1280,9 @@ end it "activates no gems with bundle exec" do install_gemfile! "" + # ensure we clean out the default gems, bceause bundler's allowed to be activated create_file("script.rb", code) - bundle! "exec ruby ./script.rb", :env => { :RUBYOPT => activation_warning_hack_rubyopt } + bundle! "exec ruby ./script.rb", :env => { :RUBYOPT => activation_warning_hack_rubyopt + " -rbundler/setup" } expect(last_command.stdout).to eq("{}") end diff --git a/spec/bundler/runtime/with_clean_env_spec.rb b/spec/bundler/runtime/with_clean_env_spec.rb index 05b334c28a..c88da3cd02 100644 --- a/spec/bundler/runtime/with_clean_env_spec.rb +++ b/spec/bundler/runtime/with_clean_env_spec.rb @@ -1,6 +1,14 @@ # frozen_string_literal: true RSpec.describe "Bundler.with_env helpers" do + def bundle_exec_ruby!(code, *args) + opts = args.last.is_a?(Hash) ? args.pop : {} + env = opts[:env] ||= {} + env[:RUBYOPT] ||= "-r#{spec_dir.join("support/hax")}" + args.push opts + bundle! "exec '#{Gem.ruby}' -e #{code}", *args + end + describe "Bundler.original_env" do before do bundle "config path vendor/bundle" @@ -12,8 +20,8 @@ RSpec.describe "Bundler.with_env helpers" do code = "print Bundler.original_env['PATH']" path = `getconf PATH`.strip + "#{File::PATH_SEPARATOR}/foo" with_path_as(path) do - result = bundle("exec '#{Gem.ruby}' -e #{code.dump}") - expect(result).to eq(path) + bundle_exec_ruby!(code.dump) + expect(last_command.stdboth).to eq(path) end end @@ -21,8 +29,8 @@ RSpec.describe "Bundler.with_env helpers" do code = "print Bundler.original_env['GEM_PATH']" gem_path = ENV["GEM_PATH"] + ":/foo" with_gem_path_as(gem_path) do - result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") - expect(result).to eq(gem_path) + bundle_exec_ruby!(code.dump) + expect(last_command.stdboth).to eq(gem_path) end end @@ -38,7 +46,7 @@ RSpec.describe "Bundler.with_env helpers" do RB path = `getconf PATH`.strip + File::PATH_SEPARATOR + File.dirname(Gem.ruby) with_path_as(path) do - bundle!("exec '#{Gem.ruby}' #{bundled_app("exe.rb")} 2") + bundle! "exec '#{Gem.ruby}' #{bundled_app("exe.rb")} 2", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } end expect(err).to eq <<-EOS.strip 2 false @@ -48,10 +56,9 @@ RSpec.describe "Bundler.with_env helpers" do end it "removes variables that bundler added", :ruby_repo do - system_gems :bundler - original = ruby!('puts ENV.to_a.map {|e| e.join("=") }.sort.join("\n")') + original = ruby!('puts ENV.to_a.map {|e| e.join("=") }.sort.join("\n")', :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" }) code = 'puts Bundler.original_env.to_a.map {|e| e.join("=") }.sort.join("\n")' - bundle!("exec '#{Gem.ruby}' -e #{code.inspect}", :system_bundler => true) + bundle! "exec '#{Gem.ruby}' -e #{code.dump}", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to eq original end end @@ -66,30 +73,30 @@ RSpec.describe "Bundler.with_env helpers" do it "should delete BUNDLE_PATH" do code = "print Bundler.clean_env.has_key?('BUNDLE_PATH')" ENV["BUNDLE_PATH"] = "./foo" - result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") - expect(result).to eq("false") + bundle_exec_ruby! code.dump + expect(last_command.stdboth).to eq "false" end it "should remove '-rbundler/setup' from RUBYOPT" do code = "print Bundler.clean_env['RUBYOPT']" ENV["RUBYOPT"] = "-W2 -rbundler/setup" - result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") - expect(result).not_to include("-rbundler/setup") + bundle_exec_ruby! code.dump + expect(last_command.stdboth).not_to include("-rbundler/setup") end it "should clean up RUBYLIB", :ruby_repo do code = "print Bundler.clean_env['RUBYLIB']" ENV["RUBYLIB"] = root.join("lib").to_s + File::PATH_SEPARATOR + "/foo" - result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") - expect(result).to eq("/foo") + bundle_exec_ruby! code.dump + expect(last_command.stdboth).to eq("/foo") end it "should restore the original MANPATH" do code = "print Bundler.clean_env['MANPATH']" ENV["MANPATH"] = "/foo" ENV["BUNDLER_ORIG_MANPATH"] = "/foo-original" - result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") - expect(result).to eq("/foo-original") + bundle_exec_ruby! code.dump + expect(last_command.stdboth).to eq("/foo-original") end end diff --git a/spec/bundler/spec_helper.rb b/spec/bundler/spec_helper.rb index 7731435f3b..2cddbf6056 100644 --- a/spec/bundler/spec_helper.rb +++ b/spec/bundler/spec_helper.rb @@ -4,13 +4,16 @@ $:.unshift File.expand_path("..", __FILE__) $:.unshift File.expand_path("../../lib", __FILE__) require "rubygems" -require "bundler/psyched_yaml" -require "bundler/vendored_fileutils" -require "uri" -require "digest" -require File.expand_path("../support/path.rb", __FILE__) +module Gem + if defined?(@path_to_default_spec_map) + @path_to_default_spec_map.delete_if do |_path, spec| + spec.name == "bundler" + end + end +end begin + require File.expand_path("../support/path.rb", __FILE__) spec = Gem::Specification.load(Spec::Path.gemspec.to_s) rspec = spec.dependencies.find {|d| d.name == "rspec" } gem "rspec", rspec.requirement.to_s @@ -20,6 +23,11 @@ rescue LoadError abort "Run rake spec:deps to install development dependencies" end +require "bundler/psyched_yaml" +require "bundler/vendored_fileutils" +require "uri" +require "digest" + if File.expand_path(__FILE__) =~ %r{([^\w/\.:\-])} abort "The bundler specs cannot be run from a path that contains special characters (particularly #{$1.inspect})" end @@ -99,8 +107,6 @@ RSpec.configure do |config| original_wd = Dir.pwd original_env = ENV.to_hash.delete_if {|k, _v| k.start_with?(Bundler::EnvironmentPreserver::BUNDLER_PREFIX) } - original_default_specs = Dir[File.join(Gem.default_dir, "specifications", "default", "bundler*")] - original_site_ruby_dirs = $LOAD_PATH.select {|path| path =~ /site_ruby/ }.map {|path| File.join(path, "bundler*") }.compact.map {|path| Dir[path] }.flatten config.expect_with :rspec do |c| c.syntax = :expect @@ -115,11 +121,6 @@ RSpec.configure do |config| config.before :all do build_repo1 - (original_default_specs + original_site_ruby_dirs).each {|s| FileUtils.mv(s, s + ".org") } - end - - config.after :all do - (original_default_specs + original_site_ruby_dirs).each {|s| FileUtils.mv(s + ".org", s) if File.exist?(s + ".org") } end config.before :each do diff --git a/spec/bundler/support/hax.rb b/spec/bundler/support/hax.rb index aee55a0ac9..b14e4a5943 100644 --- a/spec/bundler/support/hax.rb +++ b/spec/bundler/support/hax.rb @@ -12,6 +12,12 @@ module Gem @local = new(ENV["BUNDLER_SPEC_PLATFORM"]) if ENV["BUNDLER_SPEC_PLATFORM"] end @platforms = [Gem::Platform::RUBY, Gem::Platform.local] + + if defined?(@path_to_default_spec_map) && !ENV["BUNDLER_SPEC_KEEP_DEFAULT_BUNDLER_GEM"] + @path_to_default_spec_map.delete_if do |_path, spec| + spec.name == "bundler" + end + end end if ENV["BUNDLER_SPEC_VERSION"] diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index 01ddb49977..5f77ce6be9 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -220,7 +220,7 @@ module Spec def rake if ENV['BUNDLE_RUBY'] && ENV['BUNDLE_GEM'] - "#{ENV['BUNDLE_RUBY']} #{ENV['GEM_PATH']}/bin/rake" + "'#{ENV['BUNDLE_RUBY']}' -S '#{ENV['GEM_PATH']}/bin/rake'" else 'rake' end -- cgit v1.2.3