diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-03-19 19:06:14 +0100 |
---|---|---|
committer | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-03-20 14:05:36 +0100 |
commit | 20dd6657062c650505b81343e49febd9ad9461ee (patch) | |
tree | 5048e8ec32da68f814eefbae4f0a294c6eb39d92 | |
parent | c1f2942c7553b488e85bec24d9f0d80218308247 (diff) | |
download | bundler-20dd6657062c650505b81343e49febd9ad9461ee.tar.gz |
Introduce `{original,unbundled}_{system,exec}` helpersclean_env_pass
Because the previous helpers, `clean_exec` and `clean_system`, use
deprecated behavior and thus should be deprecated too.
-rw-r--r-- | lib/bundler.rb | 38 | ||||
-rw-r--r-- | spec/runtime/with_unbundled_env_spec.rb | 88 |
2 files changed, 115 insertions, 11 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 1c6406807d..d500a57861 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -335,12 +335,46 @@ EOF with_env(unbundled_env) { yield } end + # Run subcommand with the environment present before Bundler was activated + def original_system(*args) + with_original_env { Kernel.system(*args) } + end + + # @deprecated Use `unbundled_system` instead def clean_system(*args) - with_clean_env { Kernel.system(*args) } + Bundler::SharedHelpers.major_deprecation( + 2, + "`Bundler.clean_system` has been deprecated in favor of `Bundler.unbundled_system`. " \ + "If you instead want to run the command in the environment before bundler was originally loaded, use `Bundler.original_system`" + ) + + with_env(unbundled_env) { Kernel.system(*args) } + end + + # Run subcommand in an environment with all bundler related variables removed + def unbundled_system(*args) + with_unbundled_env { Kernel.system(*args) } end + # Run a `Kernel.exec` to a subcommand with the environment present before Bundler was activated + def original_exec(*args) + with_original_env { Kernel.exec(*args) } + end + + # @deprecated Use `unbundled_exec` instead def clean_exec(*args) - with_clean_env { Kernel.exec(*args) } + Bundler::SharedHelpers.major_deprecation( + 2, + "`Bundler.clean_exec` has been deprecated in favor of `Bundler.unbundled_exec`. " \ + "If you instead want to exec to a command in the environment before bundler was originally loaded, use `Bundler.original_exec`" + ) + + with_env(unbundled_env) { Kernel.exec(*args) } + end + + # Run a `Kernel.exec` to a subcommand in an environment with all bundler related variables removed + def unbundled_exec(*args) + with_env(unbundled_env) { Kernel.exec(*args) } end def local_platform diff --git a/spec/runtime/with_unbundled_env_spec.rb b/spec/runtime/with_unbundled_env_spec.rb index c47f2912c5..1ed853f467 100644 --- a/spec/runtime/with_unbundled_env_spec.rb +++ b/spec/runtime/with_unbundled_env_spec.rb @@ -188,20 +188,90 @@ RSpec.describe "Bundler.with_env helpers" do end end - describe "Bundler.clean_system", :bundler => "< 2" do + describe "Bundler.original_system" do + it "runs system inside with_original_env" do + code = 'exit Bundler.original_system(%(test "\$BUNDLE_FOO" = "bar"))' + lib = File.expand_path("../../lib", __dir__) + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + expect($?.exitstatus).to eq(0) + end + end + + describe "Bundler.clean_system" do it "runs system inside with_clean_env" do - Bundler.clean_system(%(echo 'if [ "$BUNDLE_PATH" = "" ]; then exit 42; else exit 1; fi' | /bin/sh)) - expect($?.exitstatus).to eq(42) + code = 'exit Bundler.clean_system(%(test "\$BUNDLE_FOO" = "bar"))' + lib = File.expand_path("../../lib", __dir__) + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + expect($?.exitstatus).to eq(1) + end + end + + describe "Bundler.unbundled_system" do + it "runs system inside with_unbundled_env" do + code = 'exit Bundler.clean_system(%(test "\$BUNDLE_FOO" = "bar"))' + lib = File.expand_path("../../lib", __dir__) + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + expect($?.exitstatus).to eq(1) end end - describe "Bundler.clean_exec", :bundler => "< 2" do + describe "Bundler.original_exec" do + let(:code) do + <<~RUBY + Process.fork do + exit Bundler.original_exec(%(test "\$BUNDLE_FOO" = "bar")) + end + + _, status = Process.wait2 + + exit(status.exitstatus) + RUBY + end + + it "runs exec inside with_original_env" do + lib = File.expand_path("../../lib", __dir__) + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + expect($?.exitstatus).to eq(0) + end + end + + describe "Bundler.clean_exec" do + let(:code) do + <<~RUBY + Process.fork do + exit Bundler.clean_exec(%(test "\$BUNDLE_FOO" = "bar")) + end + + _, status = Process.wait2 + + exit(status.exitstatus) + RUBY + end + it "runs exec inside with_clean_env" do - pid = Kernel.fork do - Bundler.clean_exec(%(echo 'if [ "$BUNDLE_PATH" = "" ]; then exit 42; else exit 1; fi' | /bin/sh)) - end - Process.wait(pid) - expect($?.exitstatus).to eq(42) + lib = File.expand_path("../../lib", __dir__) + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + expect($?.exitstatus).to eq(1) + end + end + + describe "Bundler.unbundled_exec" do + let(:code) do + <<~RUBY + Process.fork do + exit Bundler.unbundled_exec(%(test "\$BUNDLE_FOO" = "bar")) + end + + _, status = Process.wait2 + + exit(status.exitstatus) + RUBY + end + + it "runs exec inside with_clean_env" do + lib = File.expand_path("../../lib", __dir__) + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + expect($?.exitstatus).to eq(1) end end end |