From f032fd98ab31a5de3067476544d58786418027cd Mon Sep 17 00:00:00 2001 From: Asutosh Palai Date: Sat, 14 May 2016 15:09:23 +0530 Subject: [PATCH 1/7] Added a failing spec for #4568 --- spec/commands/exec_spec.rb | 25 +++++++++++++++++++++++++ spec/support/helpers.rb | 6 +++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index 52b59e5cdeb..95ebd01bcc2 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -544,5 +544,30 @@ def bin_path(a,b,c) it_behaves_like "it runs" end + + context "accepts the INT signal" do + let(:executable) { strip_whitespace <<-RUBY } + #{shebang} + begin + Thread.new do + puts 'Started' # For process sync + STDOUT.flush + sleep 1 + raise "No Interrupt received" # So that this thread exits + end.join + rescue Interrupt + end + puts "foo" + RUBY + + it do + bundle("exec #{path}") do |_i, 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/support/helpers.rb b/spec/support/helpers.rb index 704e2140f58..eeaaf008903 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -97,7 +97,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 @@ -115,7 +115,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 = {}) @@ -150,7 +150,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 From 17e03e5dadad9f1a9651d011417b1730e51da630 Mon Sep 17 00:00:00 2001 From: Asutosh Palai Date: Mon, 27 Jun 2016 19:09:41 +0530 Subject: [PATCH 2/7] Fixes #4568 --- lib/bundler/cli/exec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index 00e42c9b835..f076e066c07 100644 --- a/lib/bundler/cli/exec.rb +++ b/lib/bundler/cli/exec.rb @@ -60,6 +60,7 @@ def kernel_load(file, *args) ui = Bundler.ui Bundler.ui = nil require "bundler/setup" + trap("INT", "DEFAULT") Kernel.load(file) rescue SystemExit raise From 93e11fc7e3b9d067affe637c0e4c264d5b82bcd1 Mon Sep 17 00:00:00 2001 From: Asutosh Palai Date: Mon, 27 Jun 2016 19:16:02 +0530 Subject: [PATCH 3/7] Wiping all possible signals --- lib/bundler/cli/exec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index f076e066c07..df19b15cc6b 100644 --- a/lib/bundler/cli/exec.rb +++ b/lib/bundler/cli/exec.rb @@ -60,7 +60,7 @@ def kernel_load(file, *args) ui = Bundler.ui Bundler.ui = nil require "bundler/setup" - trap("INT", "DEFAULT") + Signal.list.each {|signal| trap(signal, "DEFAULT") } Kernel.load(file) rescue SystemExit raise From 69a0f915a6e5763f3e5d5029a58301001d3b145a Mon Sep 17 00:00:00 2001 From: Asutosh Palai Date: Mon, 27 Jun 2016 22:00:48 +0530 Subject: [PATCH 4/7] Fixing the reserved signals and hash value --- lib/bundler/cli/exec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index df19b15cc6b..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,7 +62,8 @@ def kernel_load(file, *args) ui = Bundler.ui Bundler.ui = nil require "bundler/setup" - Signal.list.each {|signal| trap(signal, "DEFAULT") } + signals = Signal.list.keys - RESERVED_SIGNALS + signals.each {|s| trap(s, "DEFAULT") } Kernel.load(file) rescue SystemExit raise From 7ab16a7f7b40595d1cfd62205125158bc82605d6 Mon Sep 17 00:00:00 2001 From: Asutosh Palai Date: Mon, 27 Jun 2016 22:19:17 +0530 Subject: [PATCH 5/7] Fixes for quality_spec --- spec/commands/exec_spec.rb | 8 ++++---- spec/quality_spec.rb | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index 95ebd01bcc2..beb1783e9c4 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -552,16 +552,16 @@ def bin_path(a,b,c) Thread.new do puts 'Started' # For process sync STDOUT.flush - sleep 1 - raise "No Interrupt received" # So that this thread exits + sleep 1 # ignore quality_spec + raise "Didn't receive INT at all" end.join rescue Interrupt + puts "foo" end - puts "foo" RUBY it do - bundle("exec #{path}") do |_i, o, thr| + bundle("exec #{path}") do |_, o, thr| o.gets # Consumes 'Started' and ensures that thread has started Process.kill("INT", thr.pid) end diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb index d5178d73be4..eafbf3750b4 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? From 0bff778d42834835fad9c5c3ff312177cd0841c2 Mon Sep 17 00:00:00 2001 From: Asutosh Palai Date: Tue, 28 Jun 2016 11:45:50 +0530 Subject: [PATCH 6/7] Fixes specs for 1.8.7 --- spec/commands/console_spec.rb | 18 +++++++++--------- spec/commands/exec_spec.rb | 2 ++ spec/commands/newgem_spec.rb | 6 +++--- spec/commands/open_spec.rb | 2 +- spec/other/platform_spec.rb | 4 ++-- spec/quality_spec.rb | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) 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 beb1783e9c4..81b2af74131 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -561,6 +561,8 @@ def bin_path(a,b,c) RUBY it 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) 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 eafbf3750b4..41f7d58425b 100644 --- a/spec/quality_spec.rb +++ b/spec/quality_spec.rb @@ -202,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 From 5fcd26d11f29ae03d2f94abf26a4e690e9a4d67c Mon Sep 17 00:00:00 2001 From: Asutosh Palai Date: Tue, 28 Jun 2016 23:03:54 +0530 Subject: [PATCH 7/7] Renamed the spec for signal --- spec/commands/exec_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index 81b2af74131..25b240b0a99 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -545,7 +545,7 @@ def bin_path(a,b,c) it_behaves_like "it runs" end - context "accepts the INT signal" do + context "signals being trapped by bundler" do let(:executable) { strip_whitespace <<-RUBY } #{shebang} begin @@ -560,7 +560,7 @@ def bin_path(a,b,c) end RUBY - it do + 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|