summaryrefslogtreecommitdiff
path: root/test/fileutils/test_fileutils.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/fileutils/test_fileutils.rb')
-rw-r--r--test/fileutils/test_fileutils.rb99
1 files changed, 87 insertions, 12 deletions
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb
index 36b5d6ef50..481f913d0c 100644
--- a/test/fileutils/test_fileutils.rb
+++ b/test/fileutils/test_fileutils.rb
@@ -317,7 +317,7 @@ class TestFileUtils < Test::Unit::TestCase
def test_cp_preserve_permissions
bug4507 = '[ruby-core:35518]'
touch 'tmp/cptmp'
- chmod 0755, 'tmp/cptmp'
+ chmod 0o755, 'tmp/cptmp'
cp 'tmp/cptmp', 'tmp/cptmp2'
assert_equal_filemode('tmp/cptmp', 'tmp/cptmp2', bug4507, mask: ~File.umask)
@@ -327,9 +327,9 @@ class TestFileUtils < Test::Unit::TestCase
bug7246 = '[ruby-core:48603]'
mkdir 'tmp/cptmp'
mkdir 'tmp/cptmp/d1'
- chmod 0745, 'tmp/cptmp/d1'
+ chmod 0o745, 'tmp/cptmp/d1'
mkdir 'tmp/cptmp/d2'
- chmod 0700, 'tmp/cptmp/d2'
+ chmod 0o700, 'tmp/cptmp/d2'
cp_r 'tmp/cptmp', 'tmp/cptmp2', :preserve => true
assert_equal_filemode('tmp/cptmp/d1', 'tmp/cptmp2/d1', bug7246)
assert_equal_filemode('tmp/cptmp/d2', 'tmp/cptmp2/d2', bug7246)
@@ -472,10 +472,14 @@ class TestFileUtils < Test::Unit::TestCase
else
def test_cp_r_socket
pend "Skipping socket test on JRuby" if RUBY_ENGINE == 'jruby'
+
Dir.mkdir('tmp/cpr_src')
UNIXServer.new('tmp/cpr_src/socket').close
cp_r 'tmp/cpr_src', 'tmp/cpr_dest'
assert_equal(true, File.socket?('tmp/cpr_dest/socket'))
+ rescue Errno::EINVAL => error
+ # On some platforms (windows) sockets cannot be copied by FileUtils.
+ omit error.message
end if defined?(UNIXServer)
end
@@ -750,6 +754,24 @@ class TestFileUtils < Test::Unit::TestCase
assert_file_not_exist 'tmp/tmpdir3'
end
+ def test_rm_r_no_permissions
+ check_singleton :rm_rf
+
+ return if /mswin|mingw/ =~ RUBY_PLATFORM
+
+ mkdir 'tmpdatadir'
+ touch 'tmpdatadir/tmpdata'
+ chmod "-x", 'tmpdatadir'
+
+ begin
+ assert_raise Errno::EACCES do
+ rm_r 'tmpdatadir'
+ end
+ ensure
+ chmod "+x", 'tmpdatadir'
+ end
+ end
+
def test_remove_entry_cjk_path
dir = "tmpdir\u3042"
my_rm_rf dir
@@ -823,7 +845,7 @@ class TestFileUtils < Test::Unit::TestCase
if File.sticky?('tmp/tmpdir')
Dir.mkdir 'tmp/tmpdir/d', 0
assert_raise(Errno::EACCES) {remove_entry_secure 'tmp/tmpdir/d'}
- File.chmod 0777, 'tmp/tmpdir/d'
+ File.chmod 0o777, 'tmp/tmpdir/d'
Dir.rmdir 'tmp/tmpdir/d'
end
end
@@ -980,6 +1002,43 @@ class TestFileUtils < Test::Unit::TestCase
}
end if have_symlink?
+ def test_ln_sr
+ check_singleton :ln_sr
+
+ TARGETS.each do |fname|
+ begin
+ lnfname = 'tmp/lnsdest'
+ ln_sr fname, lnfname
+ assert FileTest.symlink?(lnfname), 'not symlink'
+ assert_equal "../#{fname}", File.readlink(lnfname), fname
+ ensure
+ rm_f lnfname
+ end
+ end
+ mkdir 'data/src'
+ File.write('data/src/xxx', 'ok')
+ File.symlink '../data/src', 'tmp/src'
+ ln_sr 'tmp/src/xxx', 'data'
+ assert File.symlink?('data/xxx')
+ assert_equal 'ok', File.read('data/xxx')
+ end if have_symlink?
+
+ def test_ln_sr_broken_symlink
+ assert_nothing_raised {
+ ln_sr 'tmp/symlink', 'tmp/symlink'
+ }
+ end if have_symlink? and !no_broken_symlink?
+
+ def test_ln_sr_pathname
+ # pathname
+ touch 'tmp/lns_dest'
+ assert_nothing_raised {
+ ln_sr Pathname.new('tmp/lns_dest'), 'tmp/symlink_tmp1'
+ ln_sr 'tmp/lns_dest', Pathname.new('tmp/symlink_tmp2')
+ ln_sr Pathname.new('tmp/lns_dest'), Pathname.new('tmp/symlink_tmp3')
+ }
+ end if have_symlink?
+
def test_mkdir
check_singleton :mkdir
@@ -1098,6 +1157,14 @@ class TestFileUtils < Test::Unit::TestCase
ensure
Dir.rmdir(drive) if drive and File.directory?(drive)
end
+
+ def test_mkdir_p_offline_drive
+ offline_drive = ("A".."Z").to_a.reverse.find {|d| !File.exist?("#{d}:/") }
+
+ assert_raise(Errno::ENOENT) {
+ mkdir_p "#{offline_drive}:/new_dir"
+ }
+ end
end
def test_mkdir_p_file_perm
@@ -1170,6 +1237,14 @@ class TestFileUtils < Test::Unit::TestCase
install Pathname.new('tmp/a'), 'tmp/b'
rm_f 'tmp/a'; touch 'tmp/a'
install Pathname.new('tmp/a'), Pathname.new('tmp/b')
+ my_rm_rf 'tmp/new_dir_end_with_slash'
+ install Pathname.new('tmp/a'), 'tmp/new_dir_end_with_slash/'
+ my_rm_rf 'tmp/new_dir_end_with_slash'
+ my_rm_rf 'tmp/new_dir'
+ install Pathname.new('tmp/a'), 'tmp/new_dir/a'
+ my_rm_rf 'tmp/new_dir'
+ install Pathname.new('tmp/a'), 'tmp/new_dir/new_dir_end_with_slash/'
+ my_rm_rf 'tmp/new_dir'
rm_f 'tmp/a'
touch 'tmp/a'
touch 'tmp/b'
@@ -1227,9 +1302,9 @@ class TestFileUtils < Test::Unit::TestCase
check_singleton :chmod
touch 'tmp/a'
- chmod 0700, 'tmp/a'
+ chmod 0o700, 'tmp/a'
assert_filemode 0700, 'tmp/a'
- chmod 0500, 'tmp/a'
+ chmod 0o500, 'tmp/a'
assert_filemode 0500, 'tmp/a'
end if have_file_perm?
@@ -1333,9 +1408,9 @@ class TestFileUtils < Test::Unit::TestCase
assert_output_lines(["chmod 700 tmp/a", "chmod 500 tmp/a"]) {
touch 'tmp/a'
- chmod 0700, 'tmp/a', verbose: true
+ chmod 0o700, 'tmp/a', verbose: true
assert_filemode 0700, 'tmp/a', mask: 0777
- chmod 0500, 'tmp/a', verbose: true
+ chmod 0o500, 'tmp/a', verbose: true
assert_filemode 0500, 'tmp/a', mask: 0777
}
end if have_file_perm?
@@ -1343,7 +1418,7 @@ class TestFileUtils < Test::Unit::TestCase
def test_s_chmod_verbose
assert_output_lines(["chmod 700 tmp/a"], FileUtils) {
touch 'tmp/a'
- FileUtils.chmod 0700, 'tmp/a', verbose: true
+ FileUtils.chmod 0o700, 'tmp/a', verbose: true
assert_filemode 0700, 'tmp/a', mask: 0777
}
end if have_file_perm?
@@ -1656,7 +1731,7 @@ class TestFileUtils < Test::Unit::TestCase
def test_remove_file_file_perm
File.open('data/tmp', 'w') {|f| f.puts 'dummy' }
- File.chmod 0, 'data/tmp'
+ File.chmod 0o000, 'data/tmp'
remove_file 'data/tmp'
assert_file_not_exist 'data/tmp'
end if have_file_perm?
@@ -1671,7 +1746,7 @@ class TestFileUtils < Test::Unit::TestCase
def test_remove_dir_file_perm
Dir.mkdir 'data/tmpdir'
- File.chmod 0555, 'data/tmpdir'
+ File.chmod 0o555, 'data/tmpdir'
remove_dir 'data/tmpdir'
assert_file_not_exist 'data/tmpdir'
end if have_file_perm?
@@ -1790,7 +1865,7 @@ cd -
return if /mswin|mingw/ =~ RUBY_PLATFORM
mkdir 'tmpdatadir'
- chmod 700, 'tmpdatadir'
+ chmod 0o000, 'tmpdatadir'
rm_rf 'tmpdatadir'
assert_file_not_exist 'tmpdatadir'