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
|
|
|
|
2013-12-21 23:28:03 -06:00
|
|
|
Cleaner.new @f
|
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
|
|
|
|
Cleaner.new @f
|
|
|
|
assert !@f.prefix.directory?
|
|
|
|
end
|
|
|
|
|
2013-12-21 23:28:03 -06:00
|
|
|
def test_prunes_empty_directories
|
|
|
|
subdir = @f.bin/'subdir'
|
|
|
|
subdir.mkpath
|
|
|
|
|
|
|
|
Cleaner.new @f
|
|
|
|
|
|
|
|
assert !@f.bin.directory?
|
|
|
|
assert !subdir.directory?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_skip_clean_empty_directory
|
|
|
|
@f.class.skip_clean 'bin'
|
|
|
|
@f.bin.mkpath
|
|
|
|
|
|
|
|
Cleaner.new @f
|
|
|
|
|
|
|
|
assert @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
|
|
|
|
|
|
|
|
assert @f.bin.directory?
|
|
|
|
assert subdir.directory?
|
|
|
|
end
|
|
|
|
|
2013-12-21 23:28:03 -06:00
|
|
|
def test_fails_to_remove_symlink_when_target_was_pruned_first
|
|
|
|
mkpath @f.prefix/'b'
|
|
|
|
ln_s 'b', @f.prefix/'a'
|
|
|
|
assert_raises(Errno::ENOENT) { Cleaner.new @f }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fails_to_remove_symlink_pointing_to_empty_directory
|
|
|
|
mkpath @f.prefix/'b'
|
|
|
|
ln_s 'b', @f.prefix/'c'
|
|
|
|
assert_raises(Errno::ENOTDIR) { Cleaner.new @f }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_fails_to_remove_broken_symlink
|
|
|
|
ln_s 'target', @f.prefix/'symlink'
|
|
|
|
Cleaner.new @f
|
|
|
|
assert @f.prefix.join('symlink').symlink?, "not a symlink"
|
|
|
|
assert !@f.prefix.join('symlink').exist?, "target exists"
|
|
|
|
end
|
2012-05-28 20:43:32 -05:00
|
|
|
end
|