1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/rake/test_rake_clean.rb
nobu e8da08364c test_rake_clean.rb: skip on Windows
* test/rake/test_rake_clean.rb (create_undeletable_file): skip when
  permission to delete files is different.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43271 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-13 03:42:39 +00:00

52 lines
1.3 KiB
Ruby

require File.expand_path('../helper', __FILE__)
require 'rake/clean'
class TestRakeClean < Rake::TestCase
def test_clean
load 'rake/clean.rb', true
assert Rake::Task['clean'], "Should define clean"
assert Rake::Task['clobber'], "Should define clobber"
assert Rake::Task['clobber'].prerequisites.include?("clean"),
"Clobber should require clean"
end
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)
begin
FileUtils.chmod(0644, file_name)
rescue
file_name
else
skip "Permission to delete files is different on thie system"
end
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
end