From 888c44b238b6a5afa705ca46f6a682ac1c4bb729 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Tue, 27 Sep 2016 22:37:03 +0100 Subject: [PATCH] uninstall: fix dependent order bug --- Library/Homebrew/cmd/uninstall.rb | 2 +- Library/Homebrew/test/test_uninstall.rb | 35 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb index 30806942bc..c45e94b79c 100644 --- a/Library/Homebrew/cmd/uninstall.rb +++ b/Library/Homebrew/cmd/uninstall.rb @@ -16,7 +16,7 @@ module Homebrew if !ARGV.force? ARGV.kegs.each do |keg| - dependents = keg.installed_dependents + dependents = keg.installed_dependents - ARGV.kegs if dependents.any? dependents_output = dependents.map { |k| "#{k.name} #{k.version}" }.join(", ") conjugation = dependents.count == 1 ? "is" : "are" diff --git a/Library/Homebrew/test/test_uninstall.rb b/Library/Homebrew/test/test_uninstall.rb index 050934238e..fe14a79c21 100644 --- a/Library/Homebrew/test/test_uninstall.rb +++ b/Library/Homebrew/test/test_uninstall.rb @@ -1,8 +1,43 @@ require "helper/integration_command_test_case" class IntegrationCommandTestUninstall < IntegrationCommandTestCase + def setup + super + @f1_path = setup_test_formula "testball_f1", <<-CONTENT + def install + FileUtils.touch prefix/touch("hello") + end + CONTENT + @f2_path = setup_test_formula "testball_f2", <<-CONTENT + depends_on "testball_f1" + + def install + FileUtils.touch prefix/touch("hello") + end + CONTENT + end + def test_uninstall cmd("install", testball) assert_match "Uninstalling testball", cmd("uninstall", "--force", testball) end + + def test_uninstall_leaving_dependents + cmd("install", "testball_f2") + assert_match "Refusing to uninstall", cmd_fail("uninstall", "testball_f1") + assert_match "Uninstalling #{Formulary.factory(@f2_path).rack}", + cmd("uninstall", "testball_f2") + end + + def test_uninstall_dependent_first + cmd("install", "testball_f2") + assert_match "Uninstalling #{Formulary.factory(@f1_path).rack}", + cmd("uninstall", "testball_f2", "testball_f1") + end + + def test_uninstall_dependent_last + cmd("install", "testball_f2") + assert_match "Uninstalling #{Formulary.factory(@f2_path).rack}", + cmd("uninstall", "testball_f1", "testball_f2") + end end