Skip to content

Commit

Permalink
Added a sample test for bundler/bunder#4568
Browse files Browse the repository at this point in the history
  • Loading branch information
asutoshpalai committed May 14, 2016
1 parent 8d3eb4a commit 5368aa1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
30 changes: 30 additions & 0 deletions spec/bundler/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "spec_helper"
require "bundler/cli"

Expand All @@ -13,6 +14,35 @@
expect(exitstatus).to_not be_zero if exitstatus
end

it "accept the signals" do
gemfile "gem 'rack'"
system_gems "rack-1.0.0"

create_file "hi", <<-RUBY
#!/usr/bin/env ruby
begin
Thread.new do
puts 'Started' # For process sync
STDOUT.flush
sleep 1
raise "No Interrupt received" # So that the test fails
end.join
rescue Interrupt
end
puts "foo"
RUBY

bundled_app.join("hi").chmod(0755)

bundle("exec ./hi") 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

it "looks for a binary and executes it if it's named bundler-<task>" do
File.open(tmp("bundler-testtasks"), "w", 0755) do |f|
f.puts "#!/usr/bin/env ruby\nputs 'Hello, world'\n"
Expand Down
6 changes: 3 additions & 3 deletions spec/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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

Expand All @@ -114,7 +114,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 = {})
Expand Down Expand Up @@ -149,7 +149,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
Expand Down

0 comments on commit 5368aa1

Please sign in to comment.