test and add HOMEBREW_INSTALL_CLEANUP to upgrade

This commit is contained in:
Jarek Wojciechowski 2018-10-20 19:34:26 -04:00
parent 598909577c
commit 18f8adbd5c
3 changed files with 19 additions and 3 deletions

View File

@ -3,7 +3,7 @@
#:
#: Options for the `install` command are also valid here.
#:
#: If `--cleanup` is specified or `HOMEBREW_UPGRADE_CLEANUP` is set then remove
#: If `--cleanup` is specified, `HOMEBREW_INSTALL_CLEANUP` or `HOMEBREW_UPGRADE_CLEANUP` is set then remove
#: previously installed version(s) of upgraded <formulae>.
#:
#: If `--fetch-HEAD` is passed, fetch the upstream repository to detect if
@ -107,7 +107,7 @@ module Homebrew
Migrator.migrate_if_needed(f)
begin
upgrade_formula(f)
next if !ARGV.include?("--cleanup") && !ENV["HOMEBREW_UPGRADE_CLEANUP"]
next if !ARGV.include?("--cleanup") && !ENV["HOMEBREW_UPGRADE_CLEANUP"] && !ENV["HOMEBREW_INSTALL_CLEANUP"]
next unless f.installed?
Cleanup.new.cleanup_formula(f)

View File

@ -8,7 +8,7 @@ describe "brew upgrade", :integration_test do
expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory
end
it "upgrades a Formula and cleans up old versions" do
it "upgrades a Formula and cleans up old versions when `--cleanup` is passed" do
setup_test_formula "testball"
(HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
@ -17,4 +17,17 @@ describe "brew upgrade", :integration_test do
expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory
expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist
end
it "upgrades a Formula and cleans up old versions when `HOMEBREW_INSTALL_CLEANUP` is set" do
setup_test_formula "testball"
# allow(ENV).to receive(:[]).and_call_original
# allow(ENV).to receive(:[]).with("HOMEBREW_INSTALL_CLEANUP").and_return("1")
ENV["HOMEBREW_INSTALL_CLEANUP"] = "1"
(HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
expect { brew "upgrade" }.to be_a_success
expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory
expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist
end
end

View File

@ -1246,6 +1246,9 @@ Note that environment variables must have a value set to be detected. For exampl
* `HOMEBREW_UPGRADE_CLEANUP`:
If set, `brew upgrade` always assumes `--cleanup` has been passed.
* `HOMEBREW_INSTALL_CLEANUP`:
If set, `brew upgrade` always assumes `--cleanup` has been passed.
* `HOMEBREW_VERBOSE`:
If set, Homebrew always assumes `--verbose` when running commands.