diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-11-01 23:29:38 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-11-01 23:29:38 +0000 |
commit | be7b5929126cb3e696ef222339237faba9b8fe5a (patch) | |
tree | 51eae376f93c09bc82dde5a657a91df2c89062e4 /spec/bundler/support/helpers.rb | |
parent | ae49dbd392083f69026f2a0fff4a1d5f42d172a7 (diff) |
Update bundled bundler to 1.16.0.
* lib/bundler, spec/bundler: Merge bundler-1.16.0.
* common.mk: rspec examples of bundler-1.16.0 needs require option.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/bundler/support/helpers.rb')
-rw-r--r-- | spec/bundler/support/helpers.rb | 146 |
1 files changed, 115 insertions, 31 deletions
diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index 192747da05..01ddb49977 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -4,7 +4,7 @@ module Spec module Helpers def reset! Dir.glob("#{tmp}/{gems/*,*}", File::FNM_DOTMATCH).each do |dir| - next if %w(base remote1 gems rubygems . ..).include?(File.basename(dir)) + next if %w[base remote1 gems rubygems . ..].include?(File.basename(dir)) if ENV["BUNDLER_SUDO_TESTS"] `sudo rm -rf "#{dir}"` else @@ -21,23 +21,39 @@ module Spec def self.bang(method) define_method("#{method}!") do |*args, &blk| send(method, *args, &blk).tap do - if exitstatus && exitstatus != 0 - error = out + "\n" + err - error.strip! + unless last_command.success? raise RuntimeError, - "Invoking #{method}!(#{args.map(&:inspect).join(", ")}) failed:\n#{error}", + "Invoking #{method}!(#{args.map(&:inspect).join(", ")}) failed:\n#{last_command.stdboth}", caller.drop_while {|bt| bt.start_with?(__FILE__) } end end end end - attr_reader :out, :err, :exitstatus - def the_bundle(*args) TheBundle.new(*args) end + def last_command + @command_executions.last || raise("There is no last command") + end + + def out + last_command.stdboth + end + + def err + last_command.stderr + end + + def exitstatus + last_command.exitstatus + end + + def bundle_update_requires_all? + Bundler::VERSION.start_with?("1.") ? nil : true + end + def in_app_root(&blk) Dir.chdir(bundled_app, &blk) end @@ -54,7 +70,7 @@ module Spec opts = args.last.is_a?(Hash) ? args.pop : {} groups = args.map(&:inspect).join(", ") setup = "require 'rubygems' ; require 'bundler' ; Bundler.setup(#{groups})\n" - @out = ruby(setup + cmd, opts) + ruby(setup + cmd, opts) end bang :run @@ -83,7 +99,8 @@ module Spec with_sudo = options.delete(:sudo) sudo = with_sudo == :preserve_env ? "sudo -E" : "sudo" if with_sudo - options["no-color"] = true unless options.key?("no-color") || cmd.to_s =~ /\A(e|ex|exe|exec|conf|confi|config)(\s|\z)/ + no_color = options.delete("no-color") { cmd.to_s !~ /\A(e|ex|exe|exec|conf|confi|config)(\s|\z)/ } + options["no-color"] = true if no_color bundle_bin = options.delete("bundle_bin") || bindir.join("bundle") @@ -91,11 +108,23 @@ module Spec bundle_bin = "-S bundle" end + env = options.delete(:env) || {} + env["PATH"].gsub!("#{Path.root}/exe", "") if env["PATH"] && system_bundler + requires = options.delete(:requires) || [] - if artifice = options.delete(:artifice) { "fail" unless RSpec.current_example.metadata[:realworld] } - requires << File.expand_path("../artifice/#{artifice}.rb", __FILE__) - end requires << "support/hax" + + artifice = options.delete(:artifice) do + if RSpec.current_example.metadata[:realworld] + "vcr" + else + "fail" + end + end + if artifice + requires << File.expand_path("../artifice/#{artifice}", __FILE__) + end + requires_str = requires.map {|r| "-r#{r}" }.join(" ") load_path = [] @@ -103,10 +132,19 @@ module Spec load_path << spec load_path_str = "-I#{load_path.join(File::PATH_SEPARATOR)}" - env = (options.delete(:env) || {}).map {|k, v| "#{k}='#{v}'" }.join(" ") - env["PATH"].gsub!(Path.bindir, "") if env["PATH"] && system_bundler + env = env.map {|k, v| "#{k}='#{v}'" }.join(" ") + args = options.map do |k, v| - v == true ? " --#{k}" : " --#{k} #{v}" if v + case v + when nil + next + when true + " --#{k}" + when false + " --no-#{k}" + else + " --#{k} #{v}" + end end.join cmd = "#{env} #{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}" @@ -114,6 +152,24 @@ module Spec end bang :bundle + def forgotten_command_line_options(options) + remembered = Bundler::VERSION.split(".", 2).first == "1" + options = options.map do |k, v| + k = Array(k)[remembered ? 0 : -1] + v = '""' if v && v.to_s.empty? + [k, v] + end + return Hash[options] if remembered + options.each do |k, v| + if v.nil? + bundle! "config --delete #{k}" + else + bundle! "config --local #{k} #{v}" + end + end + {} + end + def bundler(cmd, options = {}) options["bundle_bin"] = bindir.join("bundler") bundle(cmd, options) @@ -171,24 +227,20 @@ module Spec end def sys_exec(cmd) + command_execution = CommandExecution.new(cmd.to_s, Dir.pwd) + Open3.popen3(cmd.to_s) do |stdin, stdout, stderr, wait_thr| yield stdin, stdout, wait_thr if block_given? stdin.close - @exitstatus = wait_thr && wait_thr.value.exitstatus - @out = Thread.new { stdout.read }.value.strip - @err = Thread.new { stderr.read }.value.strip + 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 end - (@all_output ||= String.new) << [ - "$ #{cmd.to_s.strip}", - out, - err, - @exitstatus ? "# $? => #{@exitstatus}" : "", - "\n", - ].reject(&:empty?).join("\n") + (@command_executions ||= []) << command_execution - @out + command_execution.stdout end bang :sys_exec @@ -317,16 +369,32 @@ module Spec end def system_gems(*gems) + opts = gems.last.is_a?(Hash) ? gems.last : {} + path = opts.fetch(:path, system_gem_path) + if path == :bundle_path + path = ruby!(<<-RUBY) + require "bundler" + begin + puts Bundler.bundle_path + rescue Bundler::GemfileNotFound + ENV["BUNDLE_GEMFILE"] = "Gemfile" + retry + end + + RUBY + end gems = gems.flatten - FileUtils.rm_rf(system_gem_path) - FileUtils.mkdir_p(system_gem_path) + unless opts[:keep_path] + FileUtils.rm_rf(path) + FileUtils.mkdir_p(path) + end Gem.clear_paths env_backup = ENV.to_hash - ENV["GEM_HOME"] = system_gem_path.to_s - ENV["GEM_PATH"] = system_gem_path.to_s + ENV["GEM_HOME"] = path.to_s + ENV["GEM_PATH"] = path.to_s ENV["BUNDLER_ORIG_GEM_PATH"] = nil install_gems(*gems) @@ -380,7 +448,7 @@ module Spec def simulate_new_machine system_gems [] - FileUtils.rm_rf default_bundle_path + FileUtils.rm_rf system_gem_path FileUtils.rm_rf bundled_app(".bundle") end @@ -422,6 +490,14 @@ module Spec ENV["BUNDLER_SPEC_VERSION"] = old if block_given? end + def simulate_rubygems_version(version) + old = ENV["BUNDLER_SPEC_RUBYGEMS_VERSION"] + ENV["BUNDLER_SPEC_RUBYGEMS_VERSION"] = version.to_s + yield if block_given? + ensure + ENV["BUNDLER_SPEC_RUBYGEMS_VERSION"] = old if block_given? + end + def simulate_windows old = ENV["BUNDLER_SPEC_WINDOWS"] ENV["BUNDLER_SPEC_WINDOWS"] = "true" @@ -500,5 +576,13 @@ module Spec end port end + + def bundler_fileutils + if RUBY_VERSION >= "2.4" + ::Bundler::FileUtils + else + ::FileUtils + end + end end end |