diff options
| author | Mike McQuaid | 2016-11-11 08:23:57 +0000 |
|---|---|---|
| committer | GitHub | 2016-11-11 08:23:57 +0000 |
| commit | 2ce17a11379a45e5de7e09a57681006aca5206bd (patch) | |
| tree | d9a2e67f74825078ffab6f90d40347ad089e76e4 /Library/Homebrew/test | |
| parent | c2815fbb9af4fe4518246cba7df418935fd3b711 (diff) | |
| parent | f3526381c329cb2f274d74d8ff0b149916d29608 (diff) | |
| download | brew-2ce17a11379a45e5de7e09a57681006aca5206bd.tar.bz2 | |
Merge pull request #1082 from alyssais/uninstall_dependancy_error
uninstall: refuse when dependents still installed
Diffstat (limited to 'Library/Homebrew/test')
| -rw-r--r-- | Library/Homebrew/test/helper/integration_command_test_case.rb | 5 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_ARGV.rb | 15 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_keg.rb | 92 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_missing.rb | 27 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_uninstall.rb | 22 |
5 files changed, 151 insertions, 10 deletions
diff --git a/Library/Homebrew/test/helper/integration_command_test_case.rb b/Library/Homebrew/test/helper/integration_command_test_case.rb index 20c0fc48e..2f137e14a 100644 --- a/Library/Homebrew/test/helper/integration_command_test_case.rb +++ b/Library/Homebrew/test/helper/integration_command_test_case.rb @@ -73,10 +73,12 @@ class IntegrationCommandTestCase < Homebrew::TestCase cmd_args << "-rintegration_mocks" cmd_args << (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path.to_s cmd_args += args + developer = ENV["HOMEBREW_DEVELOPER"] Bundler.with_original_env do ENV["HOMEBREW_BREW_FILE"] = HOMEBREW_PREFIX/"bin/brew" ENV["HOMEBREW_INTEGRATION_TEST"] = cmd_id_from_args(args) ENV["HOMEBREW_TEST_TMPDIR"] = TEST_TMPDIR + ENV["HOMEBREW_DEVELOPER"] = developer env.each_pair do |k, v| ENV[k] = v end @@ -127,7 +129,6 @@ class IntegrationCommandTestCase < Homebrew::TestCase sha256 "#{TESTBALL_SHA256}" option "with-foo", "Build with foo" - #{content} def install (prefix/"foo"/"test").write("test") if build.with? "foo" @@ -138,6 +139,8 @@ class IntegrationCommandTestCase < Homebrew::TestCase system ENV.cc, "test.c", "-o", bin/"test" end + #{content} + # something here EOS when "foo" diff --git a/Library/Homebrew/test/test_ARGV.rb b/Library/Homebrew/test/test_ARGV.rb index 39f32f452..6805e0c62 100644 --- a/Library/Homebrew/test/test_ARGV.rb +++ b/Library/Homebrew/test/test_ARGV.rb @@ -62,4 +62,19 @@ class ArgvExtensionTests < Homebrew::TestCase assert !@argv.flag?("--frotz") assert !@argv.flag?("--debug") end + + def test_value + @argv << "--foo=" << "--bar=ab" + assert_equal "", @argv.value("foo") + assert_equal "ab", @argv.value("bar") + assert_nil @argv.value("baz") + end + + def test_values + @argv << "--foo=" << "--bar=a" << "--baz=b,c" + assert_equal [], @argv.values("foo") + assert_equal ["a"], @argv.values("bar") + assert_equal ["b", "c"], @argv.values("baz") + assert_nil @argv.values("qux") + end end diff --git a/Library/Homebrew/test/test_keg.rb b/Library/Homebrew/test/test_keg.rb index 3abf3fc27..7450d9c0f 100644 --- a/Library/Homebrew/test/test_keg.rb +++ b/Library/Homebrew/test/test_keg.rb @@ -5,15 +5,22 @@ require "stringio" class LinkTests < Homebrew::TestCase include FileUtils - def setup - keg = HOMEBREW_CELLAR.join("foo", "1.0") - keg.join("bin").mkpath + def setup_test_keg(name, version) + path = HOMEBREW_CELLAR.join(name, version) + path.join("bin").mkpath %w[hiworld helloworld goodbye_cruel_world].each do |file| - touch keg.join("bin", file) + touch path.join("bin", file) end - @keg = Keg.new(keg) + keg = Keg.new(path) + @kegs ||= [] + @kegs << keg + keg + end + + def setup + @keg = setup_test_keg("foo", "1.0") @dst = HOMEBREW_PREFIX.join("bin", "helloworld") @nonexistent = Pathname.new("/some/nonexistent/path") @@ -27,8 +34,10 @@ class LinkTests < Homebrew::TestCase end def teardown - @keg.unlink - @keg.uninstall + @kegs.each do |keg| + keg.unlink + keg.uninstall + end $stdout = @old_stdout @@ -305,3 +314,72 @@ class LinkTests < Homebrew::TestCase keg.uninstall end end + +class InstalledDependantsTests < LinkTests + def stub_formula_name(name) + stub_formula_loader formula(name) { url "foo-1.0" } + end + + def setup_test_keg(name, version) + stub_formula_name(name) + keg = super + Formula.clear_cache + keg + end + + def setup + super + @dependent = setup_test_keg("bar", "1.0") + end + + def alter_tab(keg = @dependent) + tab = Tab.for_keg(keg) + yield tab + tab.write + end + + def dependencies(deps) + alter_tab do |tab| + tab.tabfile = @dependent.join("INSTALL_RECEIPT.json") + tab.runtime_dependencies = deps + end + end + + def test_no_dependencies_anywhere + dependencies nil + assert_empty @keg.installed_dependents + assert_nil Keg.find_some_installed_dependents([@keg]) + end + + def test_missing_formula_dependency + dependencies nil + Formula["bar"].class.depends_on "foo" + assert_empty @keg.installed_dependents + assert_equal [[@keg], ["bar"]], Keg.find_some_installed_dependents([@keg]) + end + + def test_empty_dependencies_in_tab + dependencies [] + assert_empty @keg.installed_dependents + assert_nil Keg.find_some_installed_dependents([@keg]) + end + + def test_same_name_different_version_in_tab + dependencies [{ "full_name" => "foo", "version" => "1.1" }] + assert_empty @keg.installed_dependents + assert_nil Keg.find_some_installed_dependents([@keg]) + end + + def test_different_name_same_version_in_tab + stub_formula_name("baz") + dependencies [{ "full_name" => "baz", "version" => @keg.version.to_s }] + assert_empty @keg.installed_dependents + assert_nil Keg.find_some_installed_dependents([@keg]) + end + + def test_same_name_and_version_in_tab + dependencies [{ "full_name" => "foo", "version" => "1.0" }] + assert_equal [@dependent], @keg.installed_dependents + assert_equal [[@keg], ["bar 1.0"]], Keg.find_some_installed_dependents([@keg]) + end +end diff --git a/Library/Homebrew/test/test_missing.rb b/Library/Homebrew/test/test_missing.rb index 3a5fd3df0..565f413da 100644 --- a/Library/Homebrew/test/test_missing.rb +++ b/Library/Homebrew/test/test_missing.rb @@ -1,11 +1,34 @@ require "helper/integration_command_test_case" class IntegrationCommandTestMissing < IntegrationCommandTestCase - def test_missing + def setup + super + setup_test_formula "foo" setup_test_formula "bar" + end + + def make_prefix(name) + (HOMEBREW_CELLAR/name/"1.0").mkpath + end + + def test_missing_missing + make_prefix "bar" - (HOMEBREW_CELLAR/"bar/1.0").mkpath assert_match "foo", cmd("missing") end + + def test_missing_not_missing + make_prefix "foo" + make_prefix "bar" + + assert_empty cmd("missing") + end + + def test_missing_hide + make_prefix "foo" + make_prefix "bar" + + assert_match "foo", cmd("missing", "--hide=foo") + end end diff --git a/Library/Homebrew/test/test_uninstall.rb b/Library/Homebrew/test/test_uninstall.rb index 050934238..a7859b7ad 100644 --- a/Library/Homebrew/test/test_uninstall.rb +++ b/Library/Homebrew/test/test_uninstall.rb @@ -1,4 +1,26 @@ require "helper/integration_command_test_case" +require "cmd/uninstall" + +class UninstallTests < Homebrew::TestCase + def test_check_for_testball_f2s_when_developer + refute_predicate Homebrew, :should_check_for_dependents? + end + + def test_check_for_dependents_when_not_developer + run_as_not_developer do + assert_predicate Homebrew, :should_check_for_dependents? + 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? + end + ensure + ARGV.delete("--ignore-dependencies") + end +end class IntegrationCommandTestUninstall < IntegrationCommandTestCase def test_uninstall |
