2015-08-03 13:09:07 +01:00
|
|
|
require "testing_env"
|
|
|
|
require "cleaner"
|
|
|
|
require "formula"
|
2012-05-28 20:43:32 -05:00
|
|
|
|
2014-06-18 20:32:51 -05:00
|
|
|
class CleanerTests < Homebrew::TestCase
|
2013-12-21 23:28:03 -06:00
|
|
|
include FileUtils
|
2012-05-28 20:43:32 -05:00
|
|
|
|
2013-12-21 23:28:03 -06:00
|
|
|
def setup
|
2015-08-03 13:09:07 +01:00
|
|
|
@f = formula("cleaner_test") { url "foo-1.0" }
|
2013-12-21 23:28:03 -06:00
|
|
|
@f.prefix.mkpath
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2014-06-23 21:28:40 -05:00
|
|
|
@f.rack.rmtree if @f.rack.exist?
|
2012-05-28 20:43:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_clean_file
|
2013-12-21 23:28:03 -06:00
|
|
|
@f.bin.mkpath
|
|
|
|
@f.lib.mkpath
|
2014-06-10 21:49:41 -05:00
|
|
|
cp "#{TEST_DIRECTORY}/mach/a.out", @f.bin
|
|
|
|
cp Dir["#{TEST_DIRECTORY}/mach/*.dylib"], @f.lib
|
2012-05-28 20:43:32 -05:00
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-10-14 21:46:52 -05:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
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
|
2012-05-28 20:43:32 -05:00
|
|
|
end
|
2013-12-21 23:28:03 -06:00
|
|
|
|
2013-12-21 23:28:03 -06:00
|
|
|
def test_prunes_prefix_if_empty
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2014-06-11 12:21:03 -05:00
|
|
|
refute_predicate @f.prefix, :directory?
|
2013-12-21 23:28:03 -06:00
|
|
|
end
|
|
|
|
|
2013-12-21 23:28:03 -06:00
|
|
|
def test_prunes_empty_directories
|
2015-08-03 13:09:07 +01:00
|
|
|
subdir = @f.bin/"subdir"
|
2013-12-21 23:28:03 -06:00
|
|
|
subdir.mkpath
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:03 -06:00
|
|
|
|
2014-06-11 12:21:03 -05:00
|
|
|
refute_predicate @f.bin, :directory?
|
|
|
|
refute_predicate subdir, :directory?
|
2013-12-21 23:28:03 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_skip_clean_empty_directory
|
2015-08-03 13:09:07 +01:00
|
|
|
@f.class.skip_clean "bin"
|
2013-12-21 23:28:03 -06:00
|
|
|
@f.bin.mkpath
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:03 -06:00
|
|
|
|
2014-06-11 12:21:03 -05:00
|
|
|
assert_predicate @f.bin, :directory?
|
2013-12-21 23:28:03 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_skip_clean_directory_with_empty_subdir
|
2015-08-03 13:09:07 +01:00
|
|
|
@f.class.skip_clean "bin"
|
|
|
|
subdir = @f.bin/"subdir"
|
2013-12-21 23:28:03 -06:00
|
|
|
subdir.mkpath
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:03 -06:00
|
|
|
|
2014-06-11 12:21:03 -05:00
|
|
|
assert_predicate @f.bin, :directory?
|
|
|
|
assert_predicate subdir, :directory?
|
2013-12-21 23:28:03 -06:00
|
|
|
end
|
|
|
|
|
2013-12-21 23:28:04 -06:00
|
|
|
def test_removes_symlink_when_target_was_pruned_first
|
2015-08-03 13:09:07 +01:00
|
|
|
dir = @f.prefix/"b"
|
|
|
|
symlink = @f.prefix/"a"
|
2013-12-21 23:28:04 -06:00
|
|
|
|
|
|
|
dir.mkpath
|
|
|
|
ln_s dir.basename, symlink
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:04 -06:00
|
|
|
|
2014-06-11 12:21:03 -05:00
|
|
|
refute_predicate dir, :exist?
|
|
|
|
refute_predicate symlink, :symlink?
|
|
|
|
refute_predicate symlink, :exist?
|
2013-12-21 23:28:04 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_removes_symlink_pointing_to_empty_directory
|
2015-08-03 13:09:07 +01:00
|
|
|
dir = @f.prefix/"b"
|
|
|
|
symlink = @f.prefix/"c"
|
2013-12-21 23:28:04 -06:00
|
|
|
|
|
|
|
dir.mkpath
|
|
|
|
ln_s dir.basename, symlink
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:04 -06:00
|
|
|
|
2014-06-11 12:21:03 -05:00
|
|
|
refute_predicate dir, :exist?
|
|
|
|
refute_predicate symlink, :symlink?
|
|
|
|
refute_predicate symlink, :exist?
|
2013-12-21 23:28:03 -06:00
|
|
|
end
|
|
|
|
|
2013-12-21 23:28:04 -06:00
|
|
|
def test_removes_broken_symlinks
|
2015-08-03 13:09:07 +01:00
|
|
|
symlink = @f.prefix/"symlink"
|
|
|
|
ln_s "target", symlink
|
2013-12-21 23:28:04 -06:00
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:04 -06:00
|
|
|
|
2014-06-11 12:21:03 -05:00
|
|
|
refute_predicate symlink, :symlink?
|
2013-12-21 23:28:03 -06:00
|
|
|
end
|
|
|
|
|
2013-12-21 23:28:04 -06:00
|
|
|
def test_skip_clean_broken_symlink
|
2015-08-03 13:09:07 +01:00
|
|
|
@f.class.skip_clean "symlink"
|
|
|
|
symlink = @f.prefix/"symlink"
|
|
|
|
ln_s "target", symlink
|
2013-12-21 23:28:04 -06:00
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:04 -06:00
|
|
|
|
2014-06-11 12:21:03 -05:00
|
|
|
assert_predicate symlink, :symlink?
|
2013-12-21 23:28:04 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_skip_clean_symlink_pointing_to_empty_directory
|
2015-08-03 13:09:07 +01:00
|
|
|
@f.class.skip_clean "c"
|
|
|
|
dir = @f.prefix/"b"
|
|
|
|
symlink = @f.prefix/"c"
|
2013-12-21 23:28:04 -06:00
|
|
|
|
|
|
|
dir.mkpath
|
|
|
|
ln_s dir.basename, symlink
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:04 -06:00
|
|
|
|
2014-06-11 12:21:03 -05:00
|
|
|
refute_predicate dir, :exist?
|
|
|
|
assert_predicate symlink, :symlink?
|
|
|
|
refute_predicate symlink, :exist?
|
2013-12-21 23:28:04 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_skip_clean_symlink_when_target_pruned
|
2015-08-03 13:09:07 +01:00
|
|
|
@f.class.skip_clean "a"
|
|
|
|
dir = @f.prefix/"b"
|
|
|
|
symlink = @f.prefix/"a"
|
2013-12-21 23:28:04 -06:00
|
|
|
|
|
|
|
dir.mkpath
|
|
|
|
ln_s dir.basename, symlink
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:04 -06:00
|
|
|
|
2014-06-11 12:21:03 -05:00
|
|
|
refute_predicate dir, :exist?
|
|
|
|
assert_predicate symlink, :symlink?
|
|
|
|
refute_predicate symlink, :exist?
|
2013-12-21 23:28:03 -06:00
|
|
|
end
|
2013-12-22 13:43:00 -06:00
|
|
|
|
|
|
|
def test_removes_la_files
|
2015-08-03 13:09:07 +01:00
|
|
|
file = @f.lib/"foo.la"
|
2013-12-22 13:43:00 -06:00
|
|
|
|
|
|
|
@f.lib.mkpath
|
|
|
|
touch file
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-22 13:43:00 -06:00
|
|
|
|
2014-06-11 12:21:03 -05:00
|
|
|
refute_predicate file, :exist?
|
2013-12-22 13:43:00 -06:00
|
|
|
end
|
|
|
|
|
2016-07-31 02:12:50 +01:00
|
|
|
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
|
|
|
|
|
2013-12-22 13:43:00 -06:00
|
|
|
def test_skip_clean_la
|
2015-08-03 13:09:07 +01:00
|
|
|
file = @f.lib/"foo.la"
|
2013-12-22 13:43:00 -06:00
|
|
|
|
|
|
|
@f.class.skip_clean :la
|
|
|
|
@f.lib.mkpath
|
|
|
|
touch file
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-22 13:43:00 -06:00
|
|
|
|
2014-06-11 12:21:03 -05:00
|
|
|
assert_predicate file, :exist?
|
2013-12-22 13:43:00 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_charset_alias
|
2015-08-03 13:09:07 +01:00
|
|
|
file = @f.lib/"charset.alias"
|
2013-12-22 13:43:00 -06:00
|
|
|
|
|
|
|
@f.lib.mkpath
|
|
|
|
touch file
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-22 13:43:00 -06:00
|
|
|
|
2014-06-11 12:21:03 -05:00
|
|
|
refute_predicate file, :exist?
|
2013-12-22 13:43:00 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_skip_clean_subdir
|
2015-08-03 13:09:07 +01:00
|
|
|
dir = @f.lib/"subdir"
|
|
|
|
@f.class.skip_clean "lib/subdir"
|
2013-12-22 13:43:00 -06:00
|
|
|
|
|
|
|
dir.mkpath
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-22 13:43:00 -06:00
|
|
|
|
2014-06-11 12:21:03 -05:00
|
|
|
assert_predicate dir, :directory?
|
2013-12-22 13:43:00 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_skip_clean_paths_are_anchored_to_prefix
|
2015-08-03 13:09:07 +01:00
|
|
|
dir1 = @f.bin/"a"
|
|
|
|
dir2 = @f.lib/"bin/a"
|
2013-12-22 13:43:00 -06:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
@f.class.skip_clean "bin/a"
|
2013-12-22 13:43:00 -06:00
|
|
|
dir1.mkpath
|
|
|
|
dir2.mkpath
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-22 13:43:00 -06:00
|
|
|
|
2014-06-11 12:21:03 -05:00
|
|
|
assert_predicate dir1, :exist?
|
|
|
|
refute_predicate dir2, :exist?
|
2013-12-22 13:43:00 -06:00
|
|
|
end
|
2012-05-28 20:43:32 -05:00
|
|
|
end
|