From eba429d947a59ab4d80ccac0cffbe34b3c75c48d Mon Sep 17 00:00:00 2001 From: Baptiste Fontaine Date: Sun, 7 Feb 2016 12:47:40 +0100 Subject: [PATCH] tests: add leaves & prune integration tests Closes Homebrew/homebrew#48943. Signed-off-by: Baptiste Fontaine --- .../Homebrew/test/test_integration_cmds.rb | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Library/Homebrew/test/test_integration_cmds.rb b/Library/Homebrew/test/test_integration_cmds.rb index 8b1c7ed34a..bca031f5f8 100644 --- a/Library/Homebrew/test/test_integration_cmds.rb +++ b/Library/Homebrew/test/test_integration_cmds.rb @@ -639,6 +639,56 @@ class IntegrationCommandTests < Homebrew::TestCase (HOMEBREW_REPOSITORY/".git").rmtree end + def test_leaves + formula_dir = CoreFormulaRepository.new.formula_dir + formula_file1 = formula_dir/"testball1.rb" + formula_file2 = formula_dir/"testball2.rb" + formula_file1.write <<-EOS.undent + class Testball1 < Formula + url "https://example.com/testball1-0.1.tar.gz" + end + EOS + formula_file2.write <<-EOS.undent + class Testball2 < Formula + url "https://example.com/testball2-0.1.tar.gz" + depends_on "testball1" + end + EOS + assert_equal "", cmd("leaves") + + (HOMEBREW_CELLAR/"testball1/0.1/somedir").mkpath + assert_equal "testball1", cmd("leaves") + + (HOMEBREW_CELLAR/"testball2/0.1/somedir").mkpath + assert_equal "testball2", cmd("leaves") + ensure + (HOMEBREW_CELLAR/"testball1").rmtree + (HOMEBREW_CELLAR/"testball2").rmtree + formula_file1.unlink + formula_file2.unlink + end + + def test_prune + share = (HOMEBREW_PREFIX/"share") + + (share/"pruneable/directory/here").mkpath + (share/"notpruneable/file").write "I'm here" + FileUtils.ln_s "/i/dont/exist/no/really/i/dont", share/"pruneable_symlink" + + assert_match %r{Would remove \(empty directory\): .*/pruneable/directory/here}, + cmd("prune", "--dry-run") + assert_match "Pruned 1 symbolic links and 3 directories", + cmd("prune") + refute (share/"pruneable").directory? + assert (share/"notpruneable").directory? + refute (share/"pruneable_symlink").symlink? + + assert_equal "Nothing pruned", + cmd("prune", "--verbose") + ensure + share.rmtree + end + def test_custom_command mktmpdir do |path| cmd = "int-test-#{rand}"