2012-05-28 20:43:32 -05:00
|
|
|
require 'testing_env'
|
|
|
|
require 'cleaner'
|
2012-10-25 14:05:41 -05:00
|
|
|
require 'formula'
|
2012-05-28 20:43:32 -05:00
|
|
|
|
2013-12-21 23:28:03 -06:00
|
|
|
class CleanerTests < Test::Unit::TestCase
|
|
|
|
include FileUtils
|
2012-05-28 20:43:32 -05:00
|
|
|
|
2013-12-21 23:28:03 -06:00
|
|
|
def setup
|
|
|
|
@f = formula("cleaner_test") { url 'foo-1.0' }
|
|
|
|
@f.prefix.mkpath
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2013-12-21 23:28:03 -06:00
|
|
|
@f.prefix.rmtree if @f.prefix.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
|
|
|
|
cp "#{TEST_FOLDER}/mach/a.out", @f.bin
|
|
|
|
cp Dir["#{TEST_FOLDER}/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
|
|
|
|
2013-12-21 23:28:03 -06: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
|
2013-12-21 23:28:03 -06:00
|
|
|
assert !@f.prefix.directory?
|
|
|
|
end
|
|
|
|
|
2013-12-21 23:28:03 -06:00
|
|
|
def test_prunes_empty_directories
|
|
|
|
subdir = @f.bin/'subdir'
|
|
|
|
subdir.mkpath
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:03 -06:00
|
|
|
|
|
|
|
assert !@f.bin.directory?
|
|
|
|
assert !subdir.directory?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_skip_clean_empty_directory
|
|
|
|
@f.class.skip_clean 'bin'
|
|
|
|
@f.bin.mkpath
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:03 -06:00
|
|
|
|
|
|
|
assert @f.bin.directory?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_skip_clean_directory_with_empty_subdir
|
|
|
|
@f.class.skip_clean 'bin'
|
|
|
|
subdir = @f.bin/'subdir'
|
|
|
|
subdir.mkpath
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:03 -06:00
|
|
|
|
|
|
|
assert @f.bin.directory?
|
|
|
|
assert subdir.directory?
|
|
|
|
end
|
|
|
|
|
2013-12-21 23:28:04 -06:00
|
|
|
def test_removes_symlink_when_target_was_pruned_first
|
|
|
|
dir = @f.prefix/'b'
|
|
|
|
symlink = @f.prefix/'a'
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
assert !dir.exist?
|
|
|
|
assert !symlink.symlink?
|
|
|
|
assert !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
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:04 -06:00
|
|
|
|
|
|
|
assert !dir.exist?
|
|
|
|
assert !symlink.symlink?
|
|
|
|
assert !symlink.exist?
|
2013-12-21 23:28:03 -06:00
|
|
|
end
|
|
|
|
|
2013-12-21 23:28:04 -06:00
|
|
|
def test_removes_broken_symlinks
|
|
|
|
symlink = @f.prefix/'symlink'
|
|
|
|
ln_s 'target', symlink
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:04 -06:00
|
|
|
|
|
|
|
assert !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
|
|
|
|
@f.class.skip_clean 'symlink'
|
|
|
|
symlink = @f.prefix/'symlink'
|
|
|
|
ln_s 'target', symlink
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:04 -06:00
|
|
|
|
|
|
|
assert 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
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:04 -06:00
|
|
|
|
|
|
|
assert !dir.exist?
|
|
|
|
assert symlink.symlink?
|
|
|
|
assert !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
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-21 23:28:04 -06:00
|
|
|
|
|
|
|
assert !dir.exist?
|
|
|
|
assert symlink.symlink?
|
|
|
|
assert !symlink.exist?
|
2013-12-21 23:28:03 -06:00
|
|
|
end
|
2013-12-22 13:43:00 -06:00
|
|
|
|
|
|
|
def test_removes_la_files
|
|
|
|
file = @f.lib/'foo.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
|
|
|
|
|
|
|
assert !file.exist?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_skip_clean_la
|
|
|
|
file = @f.lib/'foo.la'
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
assert file.exist?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_charset_alias
|
|
|
|
file = @f.lib/'charset.alias'
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
assert !file.exist?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_skip_clean_subdir
|
|
|
|
dir = @f.lib/'subdir'
|
|
|
|
@f.class.skip_clean 'lib/subdir'
|
|
|
|
|
|
|
|
dir.mkpath
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-22 13:43:00 -06:00
|
|
|
|
|
|
|
assert 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
|
|
|
|
|
2014-02-23 11:07:37 -08:00
|
|
|
Cleaner.new(@f).clean
|
2013-12-22 13:43:00 -06:00
|
|
|
|
|
|
|
assert dir1.exist?
|
|
|
|
assert !dir2.exist?
|
|
|
|
end
|
2012-05-28 20:43:32 -05:00
|
|
|
end
|