Skip to content

Commit

Permalink
Merge pull request #10821 from Bo98/test-no-gem-env
Browse files Browse the repository at this point in the history
Don't touch PATH, GEM_HOME and GEM_PATH when testing formula
  • Loading branch information
Bo98 committed Mar 10, 2021
2 parents 4524714 + 769a6cd commit 94431ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_args
def test
args = test_args.parse

Homebrew.install_bundler_gems!
Homebrew.install_bundler_gems!(setup_path: false)

require "formula_assertions"
require "formula_free_port"
Expand Down
13 changes: 12 additions & 1 deletion Library/Homebrew/utils/gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ def install_bundler!
)
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")
Expand All @@ -152,5 +156,12 @@ def install_bundler_gems!(only_warn_on_failure: false)
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
4 changes: 2 additions & 2 deletions Library/Homebrew/utils/gems.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 94431ce

Please sign in to comment.