diff options
author | bronzdoc <lsagastume1990@gmail.com> | 2016-10-30 08:56:25 -0600 |
---|---|---|
committer | bronzdoc <lsagastume1990@gmail.com> | 2016-10-30 09:03:42 -0600 |
commit | 909979271a0c2fe0d59f6fc8c4f5a630e597f1ac (patch) | |
tree | d18b5d0e0e7e32ae82b4b7fab103817a677e5830 | |
parent | 7327dc59476c79547170d3ef8162f24b3aea385f (diff) | |
download | bundler-909979271a0c2fe0d59f6fc8c4f5a630e597f1ac.tar.gz |
Warn if executable in bundle exec is empty
-rw-r--r-- | lib/bundler/cli/exec.rb | 6 | ||||
-rw-r--r-- | spec/commands/exec_spec.rb | 15 |
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 } |