aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Library/Homebrew/test/cleaner_spec.rb224
-rw-r--r--Library/Homebrew/test/cleaner_test.rb220
2 files changed, 224 insertions, 220 deletions
diff --git a/Library/Homebrew/test/cleaner_spec.rb b/Library/Homebrew/test/cleaner_spec.rb
new file mode 100644
index 000000000..116f00dff
--- /dev/null
+++ b/Library/Homebrew/test/cleaner_spec.rb
@@ -0,0 +1,224 @@
+require "cleaner"
+require "formula"
+
+describe Cleaner do
+ include FileUtils
+
+ subject { described_class.new(f) }
+ let(:f) { formula("cleaner_test") { url "foo-1.0" } }
+
+ before(:each) do
+ f.prefix.mkpath
+ end
+
+ describe "#clean" do
+ it "cleans files" do
+ f.bin.mkpath
+ f.lib.mkpath
+ cp "#{TEST_FIXTURE_DIR}/mach/a.out", f.bin
+ cp Dir["#{TEST_FIXTURE_DIR}/mach/*.dylib"], f.lib
+
+ subject.clean
+
+ expect((f.bin/"a.out").stat.mode).to eq(0100555)
+ expect((f.lib/"fat.dylib").stat.mode).to eq(0100444)
+ expect((f.lib/"x86_64.dylib").stat.mode).to eq(0100444)
+ expect((f.lib/"i386.dylib").stat.mode).to eq(0100444)
+ end
+
+ it "prunes the prefix if it is empty" do
+ subject.clean
+ expect(f.prefix).not_to be_a_directory
+ end
+
+ it "prunes empty directories" do
+ subdir = f.bin/"subdir"
+ subdir.mkpath
+
+ subject.clean
+
+ expect(f.bin).not_to be_a_directory
+ expect(subdir).not_to be_a_directory
+ end
+
+ it "removes a symlink when its target was pruned before" do
+ dir = f.prefix/"b"
+ symlink = f.prefix/"a"
+
+ dir.mkpath
+ ln_s dir.basename, symlink
+
+ subject.clean
+
+ expect(dir).not_to exist
+ expect(symlink).not_to be_a_symlink
+ expect(symlink).not_to exist
+ end
+
+ it "removes symlinks pointing to an empty directory" do
+ dir = f.prefix/"b"
+ symlink = f.prefix/"c"
+
+ dir.mkpath
+ ln_s dir.basename, symlink
+
+ subject.clean
+
+ expect(dir).not_to exist
+ expect(symlink).not_to be_a_symlink
+ expect(symlink).not_to exist
+ end
+
+ it "removes broken symlinks" do
+ symlink = f.prefix/"symlink"
+ ln_s "target", symlink
+
+ subject.clean
+
+ expect(symlink).not_to be_a_symlink
+ end
+
+ it "removes '.la' files" do
+ file = f.lib/"foo.la"
+
+ f.lib.mkpath
+ touch file
+
+ subject.clean
+
+ expect(file).not_to exist
+ end
+
+ it "removes 'perllocal' files" do
+ file = f.lib/"perl5/darwin-thread-multi-2level/perllocal.pod"
+
+ (f.lib/"perl5/darwin-thread-multi-2level").mkpath
+ touch file
+
+ subject.clean
+
+ expect(file).not_to exist
+ end
+
+ it "removes '.packlist' files" do
+ file = f.lib/"perl5/darwin-thread-multi-2level/auto/test/.packlist"
+
+ (f.lib/"perl5/darwin-thread-multi-2level/auto/test").mkpath
+ touch file
+
+ subject.clean
+
+ expect(file).not_to exist
+ end
+
+ it "removes 'charset.alias' files" do
+ file = f.lib/"charset.alias"
+
+ f.lib.mkpath
+ touch file
+
+ subject.clean
+
+ expect(file).not_to exist
+ end
+ end
+
+ describe "::skip_clean" do
+ it "adds paths that should be skipped" do
+ f.class.skip_clean "bin"
+ f.bin.mkpath
+
+ subject.clean
+
+ expect(f.bin).to be_a_directory
+ end
+
+ it "also skips empty sub-directories under the added paths" do
+ f.class.skip_clean "bin"
+ subdir = f.bin/"subdir"
+ subdir.mkpath
+
+ subject.clean
+
+ expect(f.bin).to be_a_directory
+ expect(subdir).to be_a_directory
+ end
+
+ it "allows skipping broken symlinks" do
+ f.class.skip_clean "symlink"
+ symlink = f.prefix/"symlink"
+ ln_s "target", symlink
+
+ subject.clean
+
+ expect(symlink).to be_a_symlink
+ end
+
+ it "allows skipping symlinks pointing to an empty directory" do
+ f.class.skip_clean "c"
+ dir = f.prefix/"b"
+ symlink = f.prefix/"c"
+
+ dir.mkpath
+ ln_s dir.basename, symlink
+
+ subject.clean
+
+ expect(dir).not_to exist
+ expect(symlink).to be_a_symlink
+ expect(symlink).not_to exist
+ end
+
+ it "allows skipping symlinks whose target was pruned before" do
+ f.class.skip_clean "a"
+ dir = f.prefix/"b"
+ symlink = f.prefix/"a"
+
+ dir.mkpath
+ ln_s dir.basename, symlink
+
+ subject.clean
+
+ expect(dir).not_to exist
+ expect(symlink).to be_a_symlink
+ expect(symlink).not_to exist
+ end
+
+ it "allows skipping '.la' files" do
+ file = f.lib/"foo.la"
+
+ f.class.skip_clean :la
+ f.lib.mkpath
+ touch file
+
+ subject.clean
+
+ expect(file).to exist
+ end
+
+ it "allows skipping sub-directories" do
+ dir = f.lib/"subdir"
+ f.class.skip_clean "lib/subdir"
+
+ dir.mkpath
+
+ subject.clean
+
+ expect(dir).to be_a_directory
+ end
+
+ it "allows skipping paths relative to prefix" do
+ dir1 = f.bin/"a"
+ dir2 = f.lib/"bin/a"
+
+ f.class.skip_clean "bin/a"
+ dir1.mkpath
+ dir2.mkpath
+
+ subject.clean
+
+ expect(dir1).to exist
+ expect(dir2).not_to exist
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cleaner_test.rb b/Library/Homebrew/test/cleaner_test.rb
deleted file mode 100644
index 05a91b90b..000000000
--- a/Library/Homebrew/test/cleaner_test.rb
+++ /dev/null
@@ -1,220 +0,0 @@
-require "testing_env"
-require "cleaner"
-require "formula"
-
-class CleanerTests < Homebrew::TestCase
- include FileUtils
-
- def setup
- super
- @f = formula("cleaner_test") { url "foo-1.0" }
- @f.prefix.mkpath
- end
-
- def test_clean_file
- @f.bin.mkpath
- @f.lib.mkpath
- cp "#{TEST_FIXTURE_DIR}/mach/a.out", @f.bin
- cp Dir["#{TEST_FIXTURE_DIR}/mach/*.dylib"], @f.lib
-
- Cleaner.new(@f).clean
-
- assert_equal 0100555, (@f.bin/"a.out").stat.mode
- assert_equal 0100444, (@f.lib/"fat.dylib").stat.mode
- assert_equal 0100444, (@f.lib/"x86_64.dylib").stat.mode
- assert_equal 0100444, (@f.lib/"i386.dylib").stat.mode
- end
-
- def test_prunes_prefix_if_empty
- Cleaner.new(@f).clean
- refute_predicate @f.prefix, :directory?
- end
-
- def test_prunes_empty_directories
- subdir = @f.bin/"subdir"
- subdir.mkpath
-
- Cleaner.new(@f).clean
-
- refute_predicate @f.bin, :directory?
- refute_predicate subdir, :directory?
- end
-
- def test_skip_clean_empty_directory
- @f.class.skip_clean "bin"
- @f.bin.mkpath
-
- Cleaner.new(@f).clean
-
- assert_predicate @f.bin, :directory?
- end
-
- def test_skip_clean_directory_with_empty_subdir
- @f.class.skip_clean "bin"
- subdir = @f.bin/"subdir"
- subdir.mkpath
-
- Cleaner.new(@f).clean
-
- assert_predicate @f.bin, :directory?
- assert_predicate subdir, :directory?
- end
-
- def test_removes_symlink_when_target_was_pruned_first
- dir = @f.prefix/"b"
- symlink = @f.prefix/"a"
-
- dir.mkpath
- ln_s dir.basename, symlink
-
- Cleaner.new(@f).clean
-
- refute_predicate dir, :exist?
- refute_predicate symlink, :symlink?
- refute_predicate symlink, :exist?
- end
-
- def test_removes_symlink_pointing_to_empty_directory
- dir = @f.prefix/"b"
- symlink = @f.prefix/"c"
-
- dir.mkpath
- ln_s dir.basename, symlink
-
- Cleaner.new(@f).clean
-
- refute_predicate dir, :exist?
- refute_predicate symlink, :symlink?
- refute_predicate symlink, :exist?
- end
-
- def test_removes_broken_symlinks
- symlink = @f.prefix/"symlink"
- ln_s "target", symlink
-
- Cleaner.new(@f).clean
-
- refute_predicate symlink, :symlink?
- end
-
- def test_skip_clean_broken_symlink
- @f.class.skip_clean "symlink"
- symlink = @f.prefix/"symlink"
- ln_s "target", symlink
-
- Cleaner.new(@f).clean
-
- assert_predicate symlink, :symlink?
- end
-
- def test_skip_clean_symlink_pointing_to_empty_directory
- @f.class.skip_clean "c"
- dir = @f.prefix/"b"
- symlink = @f.prefix/"c"
-
- dir.mkpath
- ln_s dir.basename, symlink
-
- Cleaner.new(@f).clean
-
- refute_predicate dir, :exist?
- assert_predicate symlink, :symlink?
- refute_predicate symlink, :exist?
- end
-
- def test_skip_clean_symlink_when_target_pruned
- @f.class.skip_clean "a"
- dir = @f.prefix/"b"
- symlink = @f.prefix/"a"
-
- dir.mkpath
- ln_s dir.basename, symlink
-
- Cleaner.new(@f).clean
-
- refute_predicate dir, :exist?
- assert_predicate symlink, :symlink?
- refute_predicate symlink, :exist?
- end
-
- def test_removes_la_files
- file = @f.lib/"foo.la"
-
- @f.lib.mkpath
- touch file
-
- Cleaner.new(@f).clean
-
- refute_predicate file, :exist?
- end
-
- def test_removes_perllocal_files
- file = @f.lib/"perl5/darwin-thread-multi-2level/perllocal.pod"
-
- (@f.lib/"perl5/darwin-thread-multi-2level").mkpath
- touch file
-
- Cleaner.new(@f).clean
-
- refute_predicate file, :exist?
- end
-
- def test_removes_packlist_files
- file = @f.lib/"perl5/darwin-thread-multi-2level/auto/test/.packlist"
-
- (@f.lib/"perl5/darwin-thread-multi-2level/auto/test").mkpath
- touch file
-
- Cleaner.new(@f).clean
-
- refute_predicate file, :exist?
- end
-
- def test_skip_clean_la
- file = @f.lib/"foo.la"
-
- @f.class.skip_clean :la
- @f.lib.mkpath
- touch file
-
- Cleaner.new(@f).clean
-
- assert_predicate file, :exist?
- end
-
- def test_remove_charset_alias
- file = @f.lib/"charset.alias"
-
- @f.lib.mkpath
- touch file
-
- Cleaner.new(@f).clean
-
- refute_predicate file, :exist?
- end
-
- def test_skip_clean_subdir
- dir = @f.lib/"subdir"
- @f.class.skip_clean "lib/subdir"
-
- dir.mkpath
-
- Cleaner.new(@f).clean
-
- assert_predicate dir, :directory?
- end
-
- def test_skip_clean_paths_are_anchored_to_prefix
- dir1 = @f.bin/"a"
- dir2 = @f.lib/"bin/a"
-
- @f.class.skip_clean "bin/a"
- dir1.mkpath
- dir2.mkpath
-
- Cleaner.new(@f).clean
-
- assert_predicate dir1, :exist?
- refute_predicate dir2, :exist?
- end
-end