Don't touch PATH, GEM_HOME and GEM_PATH when testing formula

This commit is contained in:
Bo Anderson 2021-03-10 04:46:39 +00:00
parent 4524714a7b
commit 769a6cd1f5
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
3 changed files with 15 additions and 4 deletions

View File

@ -35,7 +35,7 @@ module Homebrew
def test
args = test_args.parse
Homebrew.install_bundler_gems!
Homebrew.install_bundler_gems!(setup_path: false)
require "formula_assertions"
require "formula_free_port"

View File

@ -125,7 +125,11 @@ module Homebrew
)
end
def install_bundler_gems!(only_warn_on_failure: false)
def install_bundler_gems!(only_warn_on_failure: false, setup_path: true)
old_path = ENV["PATH"]
old_gem_path = ENV["GEM_PATH"]
old_gem_home = ENV["GEM_HOME"]
install_bundler!
ENV["BUNDLE_GEMFILE"] = File.join(ENV.fetch("HOMEBREW_LIBRARY"), "Homebrew", "Gemfile")
@ -152,5 +156,12 @@ module Homebrew
end
setup_gem_environment!
ensure
unless setup_path
# Reset the paths. We need to have at least temporarily changed them while invoking `bundle`.
ENV["PATH"] = old_path
ENV["GEM_PATH"] = old_gem_path
ENV["GEM_HOME"] = old_gem_home
end
end
end

View File

@ -22,6 +22,6 @@ module Homebrew
sig { void }
def install_bundler!; end
sig { params(only_warn_on_failure: T::Boolean).void }
def install_bundler_gems!(only_warn_on_failure: false); end
sig { params(only_warn_on_failure: T::Boolean, setup_path: T::Boolean).void }
def install_bundler_gems!(only_warn_on_failure: false, setup_path: false); end
end