diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index 00e42c9b835..4371887f2ae 100644 --- a/lib/bundler/cli/exec.rb +++ b/lib/bundler/cli/exec.rb @@ -5,6 +5,8 @@ module Bundler class CLI::Exec attr_reader :options, :args, :cmd + RESERVED_SIGNALS = %w(SEGV BUS ILL FPE VTALRM KILL STOP).freeze + def initialize(options, args) @options = options @cmd = args.shift @@ -60,6 +62,8 @@ def kernel_load(file, *args) ui = Bundler.ui Bundler.ui = nil require "bundler/setup" + signals = Signal.list.keys - RESERVED_SIGNALS + signals.each {|s| trap(s, "DEFAULT") } Kernel.load(file) rescue SystemExit raise diff --git a/spec/commands/console_spec.rb b/spec/commands/console_spec.rb index b771c6a9406..b60ac2c9f63 100644 --- a/spec/commands/console_spec.rb +++ b/spec/commands/console_spec.rb @@ -12,7 +12,7 @@ end it "starts IRB with the default group loaded" do - bundle "console" do |input| + bundle "console" do |input, _, _| input.puts("puts RACK") input.puts("exit") end @@ -20,7 +20,7 @@ end it "uses IRB as default console" do - bundle "console" do |input| + bundle "console" do |input, _, _| input.puts("__method__") input.puts("exit") end @@ -34,7 +34,7 @@ G bundle "config console pry" - bundle "console" do |input| + bundle "console" do |input, _, _| input.puts("__method__") input.puts("exit") end @@ -45,7 +45,7 @@ bundle "config console pry" # make sure pry isn't there - bundle "console" do |input| + bundle "console" do |input, _, _| input.puts("__method__") input.puts("exit") end @@ -53,7 +53,7 @@ end it "doesn't load any other groups" do - bundle "console" do |input| + bundle "console" do |input, _, _| input.puts("puts ACTIVESUPPORT") input.puts("exit") end @@ -62,7 +62,7 @@ describe "when given a group" do it "loads the given group" do - bundle "console test" do |input| + bundle "console test" do |input, _, _| input.puts("puts ACTIVESUPPORT") input.puts("exit") end @@ -70,7 +70,7 @@ end it "loads the default group" do - bundle "console test" do |input| + bundle "console test" do |input, _, _| input.puts("puts RACK") input.puts("exit") end @@ -78,7 +78,7 @@ end it "doesn't load other groups" do - bundle "console test" do |input| + bundle "console test" do |input, _, _| input.puts("puts RACK_MIDDLEWARE") input.puts("exit") end @@ -96,7 +96,7 @@ G bundle "config auto_install 1" - bundle :console do |input| + bundle :console do |input, _, _| input.puts("puts 'hello'") input.puts("exit") end diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index 52b59e5cdeb..25b240b0a99 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -544,5 +544,32 @@ def bin_path(a,b,c) it_behaves_like "it runs" end + + context "signals being trapped by bundler" do + let(:executable) { strip_whitespace <<-RUBY } + #{shebang} + begin + Thread.new do + puts 'Started' # For process sync + STDOUT.flush + sleep 1 # ignore quality_spec + raise "Didn't receive INT at all" + end.join + rescue Interrupt + puts "foo" + end + RUBY + + it "receives the signal" do + skip "popen3 doesn't provide a way to get pid " unless RUBY_VERSION >= "1.9.3" + + bundle("exec #{path}") do |_, o, thr| + o.gets # Consumes 'Started' and ensures that thread has started + Process.kill("INT", thr.pid) + end + + expect(out).to eq("foo") + end + end end end diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index 6414a0902e8..cb3c48132a9 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -743,7 +743,7 @@ def create_temporary_dir(dir) it "asks about test framework" do global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__COC" => "false" - bundle "gem foobar" do |input| + bundle "gem foobar" do |input, _, _| input.puts "rspec" end @@ -766,7 +766,7 @@ def create_temporary_dir(dir) bundle :config - bundle "gem foobar" do |input| + bundle "gem foobar" do |input, _, _| input.puts "yes" end @@ -776,7 +776,7 @@ def create_temporary_dir(dir) it "asks about CoC" do global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false" - bundle "gem foobar" do |input| + bundle "gem foobar" do |input, _, _| input.puts "yes" end diff --git a/spec/commands/open_spec.rb b/spec/commands/open_spec.rb index 1776eed6e93..8ae18cea6a8 100644 --- a/spec/commands/open_spec.rb +++ b/spec/commands/open_spec.rb @@ -60,7 +60,7 @@ it "select the gem from many match gems" do env = { "EDITOR" => "echo editor", "VISUAL" => "echo visual", "BUNDLER_EDITOR" => "echo bundler_editor" } - bundle "open active", :env => env do |input| + bundle "open active", :env => env do |input, _, _| input.puts "2" end diff --git a/spec/other/platform_spec.rb b/spec/other/platform_spec.rb index a219853e2fa..c0d121c7b15 100644 --- a/spec/other/platform_spec.rb +++ b/spec/other/platform_spec.rb @@ -929,7 +929,7 @@ def should_be_patchlevel_fixnum #{ruby_version_correct} G - bundle "console" do |input| + bundle "console" do |input, _, _| input.puts("puts RACK") input.puts("exit") end @@ -947,7 +947,7 @@ def should_be_patchlevel_fixnum #{ruby_version_correct_engineless} G - bundle "console" do |input| + bundle "console" do |input, _, _| input.puts("puts RACK") input.puts("exit") end diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb index d5178d73be4..41f7d58425b 100644 --- a/spec/quality_spec.rb +++ b/spec/quality_spec.rb @@ -28,7 +28,9 @@ def check_for_debugging_mechanisms(filename) failing_lines = [] File.readlines(filename).each_with_index do |line, number| - failing_lines << number + 1 if line =~ debugging_mechanisms_regex + if line =~ debugging_mechanisms_regex && !line.end_with?("# ignore quality_spec\n") + failing_lines << number + 1 + end end return if failing_lines.empty? @@ -200,7 +202,7 @@ def check_for_specific_pronouns(filename) lib_files = `git ls-files -z`.split("\x0").grep(/\.rb$/) - exclusions lib_files.reject! {|f| f.start_with?("bundler/vendor") } lib_files.map! {|f| f.chomp(".rb") } - sys_exec("ruby -w -I. ", :expect_err) do |input| + sys_exec("ruby -w -I. ", :expect_err) do |input, _, _| lib_files.each do |f| input.puts "require '#{f}'" end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index d0947272070..f06c488c42b 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -98,7 +98,7 @@ def bundle(cmd, options = {}) end.join cmd = "#{env} #{sudo} #{Gem.ruby} -I#{lib}:#{spec} #{requires_str} #{bundle_bin} #{cmd}#{args}" - sys_exec(cmd, expect_err) {|i| yield i if block_given? } + sys_exec(cmd, expect_err) {|i, o, thr| yield i, o, thr if block_given? } end bang :bundle @@ -116,7 +116,7 @@ def bundle_ruby(options = {}) env = (options.delete(:env) || {}).map {|k, v| "#{k}='#{v}' " }.join cmd = "#{env}#{Gem.ruby} -I#{lib} #{requires_str} #{bundle_bin}" - sys_exec(cmd, expect_err) {|i| yield i if block_given? } + sys_exec(cmd, expect_err) {|i, o, thr| yield i, o, thr if block_given? } end def ruby(ruby, options = {}) @@ -151,7 +151,7 @@ def gembin(cmd) def sys_exec(cmd, expect_err = false) Open3.popen3(cmd.to_s) do |stdin, stdout, stderr, wait_thr| - yield stdin if block_given? + yield stdin, stdout, wait_thr if block_given? stdin.close @out = Thread.new { stdout.read }.value.strip