2011-06-23 18:11:55 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2009-10-02 15:07:55 -04:00
|
|
|
require 'rake/clean'
|
|
|
|
|
2011-06-23 18:11:55 -04:00
|
|
|
class TestRakeClean < Rake::TestCase
|
2009-10-02 15:07:55 -04:00
|
|
|
def test_clean
|
2011-06-23 18:11:55 -04:00
|
|
|
load 'rake/clean.rb', true
|
|
|
|
|
2013-10-11 17:35:01 -04:00
|
|
|
assert Rake::Task['clean'], "Should define clean"
|
|
|
|
assert Rake::Task['clobber'], "Should define clobber"
|
|
|
|
assert Rake::Task['clobber'].prerequisites.include?("clean"),
|
2009-10-02 15:07:55 -04:00
|
|
|
"Clobber should require clean"
|
|
|
|
end
|
2013-10-11 17:35:01 -04:00
|
|
|
|
|
|
|
def test_cleanup
|
|
|
|
file_name = create_undeletable_file
|
|
|
|
|
|
|
|
out, _ = capture_io do
|
2014-07-14 23:07:37 -04:00
|
|
|
Rake::Cleaner.cleanup(file_name, :verbose => false)
|
2013-10-11 17:35:01 -04:00
|
|
|
end
|
|
|
|
assert_match(/failed to remove/i, out)
|
|
|
|
|
|
|
|
ensure
|
|
|
|
remove_undeletable_file
|
|
|
|
end
|
|
|
|
|
2014-07-14 23:07:37 -04:00
|
|
|
def test_cleanup_ignores_missing_files
|
|
|
|
file_name = File.join(@tempdir, "missing_directory", "no_such_file")
|
|
|
|
|
|
|
|
out, _ = capture_io do
|
|
|
|
Rake::Cleaner.cleanup(file_name, :verbose => false)
|
|
|
|
end
|
|
|
|
refute_match(/failed to remove/i, out)
|
|
|
|
end
|
|
|
|
|
2013-10-11 17:35:01 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def create_undeletable_file
|
|
|
|
dir_name = File.join(@tempdir, "deletedir")
|
|
|
|
file_name = File.join(dir_name, "deleteme")
|
|
|
|
FileUtils.mkdir(dir_name)
|
|
|
|
FileUtils.touch(file_name)
|
|
|
|
FileUtils.chmod(0, file_name)
|
|
|
|
FileUtils.chmod(0, dir_name)
|
2013-10-12 23:42:39 -04:00
|
|
|
begin
|
|
|
|
FileUtils.chmod(0644, file_name)
|
|
|
|
rescue
|
|
|
|
file_name
|
|
|
|
else
|
|
|
|
skip "Permission to delete files is different on thie system"
|
|
|
|
end
|
2013-10-11 17:35:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove_undeletable_file
|
|
|
|
dir_name = File.join(@tempdir, "deletedir")
|
|
|
|
file_name = File.join(dir_name, "deleteme")
|
|
|
|
FileUtils.chmod(0777, dir_name)
|
|
|
|
FileUtils.chmod(0777, file_name)
|
2014-07-14 23:07:37 -04:00
|
|
|
Rake::Cleaner.cleanup(file_name, :verbose => false)
|
|
|
|
Rake::Cleaner.cleanup(dir_name, :verbose => false)
|
2013-10-11 17:35:01 -04:00
|
|
|
end
|
2009-10-02 15:07:55 -04:00
|
|
|
end
|