From 3c310b2e3dd7805b04f48507c65c2c0a856c2aa2 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Fri, 11 Nov 2016 20:08:26 +0000 Subject: Warn developers when uninstalling a dependency Suggested in #1084. Made the existing warning output entirely to STDERR, because previously the first line went to STDERR and subsequent ones went to STDOUT. --- Library/Homebrew/test/test_uninstall.rb | 41 ++++++++++++++++++++++++++++++--- Library/Homebrew/test/test_utils.rb | 4 ++++ 2 files changed, 42 insertions(+), 3 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/test_uninstall.rb b/Library/Homebrew/test/test_uninstall.rb index a7859b7ad..c9b3e0be3 100644 --- a/Library/Homebrew/test/test_uninstall.rb +++ b/Library/Homebrew/test/test_uninstall.rb @@ -2,20 +2,55 @@ require "helper/integration_command_test_case" require "cmd/uninstall" class UninstallTests < Homebrew::TestCase + def setup + @dependency = formula("dependency") { url "f-1" } + @dependent = formula("dependent") do + url "f-1" + depends_on "dependency" + end + + [@dependency, @dependent].each { |f| f.installed_prefix.mkpath } + + tab = Tab.empty + tab.tabfile = @dependent.installed_prefix/Tab::FILENAME + tab.runtime_dependencies = [ + { "full_name" => "dependency", "version" => "1" }, + ] + tab.write + + stub_formula_loader @dependency + stub_formula_loader @dependent + end + + def teardown + Homebrew.failed = false + [@dependency, @dependent].each { |f| f.rack.rmtree } + end + + def handle_unsatisfied_dependents + capture_stderr do + opts = { @dependency.rack => [Keg.new(@dependency.installed_prefix)] } + Homebrew.handle_unsatisfied_dependents(opts) + end + end + def test_check_for_testball_f2s_when_developer - refute_predicate Homebrew, :should_check_for_dependents? + assert_match "Warning", handle_unsatisfied_dependents + refute_predicate Homebrew, :failed? end def test_check_for_dependents_when_not_developer run_as_not_developer do - assert_predicate Homebrew, :should_check_for_dependents? + assert_match "Error", handle_unsatisfied_dependents + assert_predicate Homebrew, :failed? end end def test_check_for_dependents_when_ignore_dependencies ARGV << "--ignore-dependencies" run_as_not_developer do - refute_predicate Homebrew, :should_check_for_dependents? + assert_empty handle_unsatisfied_dependents + refute_predicate Homebrew, :failed? end ensure ARGV.delete("--ignore-dependencies") diff --git a/Library/Homebrew/test/test_utils.rb b/Library/Homebrew/test/test_utils.rb index 11332e450..7c0b6f78a 100644 --- a/Library/Homebrew/test/test_utils.rb +++ b/Library/Homebrew/test/test_utils.rb @@ -174,6 +174,10 @@ class UtilTests < Homebrew::TestCase end end + def test_capture_stderr + assert_equal "test\n", capture_stderr { $stderr.puts "test" } + end + def test_shell_profile ENV["SHELL"] = "/bin/sh" assert_equal "~/.bash_profile", Utils::Shell.shell_profile -- cgit v1.2.3