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
|
|
|
|
Rake::Cleaner.cleanup(file_name, verbose: false)
|
|
|
|
end
|
|
|
|
assert_match(/failed to remove/i, out)
|
|
|
|
|
|
|
|
ensure
|
|
|
|
remove_undeletable_file
|
|
|
|
end
|
|
|
|
|
|
|
|
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)
|
|
|
|
Rake::Cleaner.cleanup(file_name, verbose: false)
|
|
|
|
Rake::Cleaner.cleanup(dir_name, verbose: false)
|
|
|
|
end
|
2009-10-02 15:07:55 -04:00
|
|
|
end
|