From d928822a17fef3713fd9501fa7a73aa727d08822 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Thu, 14 Apr 2016 19:29:44 -0500 Subject: [Exec] Allow executables to exit non-zero via at_exit --- lib/bundler/cli/exec.rb | 3 +-- spec/commands/exec_spec.rb | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index 3ef2492c2f..00e42c9b83 100644 --- a/lib/bundler/cli/exec.rb +++ b/lib/bundler/cli/exec.rb @@ -21,7 +21,7 @@ module Bundler validate_cmd! SharedHelpers.set_bundle_environment if bin_path = Bundler.which(cmd) - kernel_load(bin_path, *args) if ruby_shebang?(bin_path) + return kernel_load(bin_path, *args) if ruby_shebang?(bin_path) # First, try to exec directly to something in PATH kernel_exec([bin_path, cmd], *args) else @@ -61,7 +61,6 @@ module Bundler Bundler.ui = nil require "bundler/setup" Kernel.load(file) - exit rescue SystemExit raise rescue Exception => e # rubocop:disable Lint/RescueException diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index 29f5927c14..e2ae0aabbb 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -395,7 +395,7 @@ describe "bundle exec" do subject { bundle "exec #{path} arg1 arg2", :expect_err => true } shared_examples_for "it runs" do - it "like a normally executed executable like a normally executed executable" do + it "like a normally executed executable" do subject expect(exitstatus).to eq(exit_code) if exitstatus expect(err).to eq(expected_err) @@ -450,5 +450,12 @@ describe "bundle exec" do it_behaves_like "it runs" end + + context "when the executable exits non-zero via at_exit" do + let(:executable) { super() + "\n\nat_exit { $! ? raise($!) : exit(1) }" } + let(:exit_code) { 1 } + + it_behaves_like "it runs" + end end end -- cgit v1.2.1