summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-10-31 02:59:00 +0900
committerHomu <homu@barosl.com>2016-10-31 02:59:00 +0900
commit2483cc7e60df077de7e2c13fee99328328ff297f (patch)
treea770f83b4746f488bc4e3e0d504db72c88b3121e
parentced83655d9643e804079a4f2a6967536a4f8b981 (diff)
parent909979271a0c2fe0d59f6fc8c4f5a630e597f1ac (diff)
downloadbundler-2483cc7e60df077de7e2c13fee99328328ff297f.tar.gz
Auto merge of #5100 - bronzdoc:fix_shebang_check_in_exec, r=segiddins
Warn if executable in bundle exec is empty closes https://github.com/bundler/bundler/issues/5084
-rw-r--r--lib/bundler/cli/exec.rb6
-rw-r--r--spec/commands/exec_spec.rb15
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb
index 4f238bbb59..62f7bc26cb 100644
--- a/lib/bundler/cli/exec.rb
+++ b/lib/bundler/cli/exec.rb
@@ -91,6 +91,12 @@ module Bundler
"#!/usr/bin/env jruby\n",
"#!#{Gem.ruby}\n",
]
+
+ if File.zero?(file)
+ Bundler.ui.warn "#{file} is empty"
+ return false
+ end
+
first_line = File.open(file, "rb") {|f| f.read(possibilities.map(&:size).max) }
possibilities.any? {|shebang| first_line.start_with?(shebang) }
end
diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb
index 4dc47919de..057310d89f 100644
--- a/spec/commands/exec_spec.rb
+++ b/spec/commands/exec_spec.rb
@@ -514,6 +514,21 @@ describe "bundle exec" do
end
end
+ context "the executable is empty" do
+ let(:executable) { "" }
+
+ let(:exit_code) { 0 }
+ let(:expected) { "#{path} is empty" }
+ let(:expected_err) { "" }
+ if LessThanProc.with(RUBY_VERSION).call("1.9")
+ # Kernel#exec in ruby < 1.9 will raise Errno::ENOEXEC if the command content is empty,
+ # even if the command is set as an executable.
+ pending "Kernel#exec is different"
+ else
+ it_behaves_like "it runs"
+ end
+ end
+
context "the executable raises" do
let(:executable) { super() << "\nraise 'ERROR'" }
let(:exit_code) { 1 }