diff options
Diffstat (limited to 'test/fileutils/test_fileutils.rb')
-rw-r--r-- | test/fileutils/test_fileutils.rb | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index e1e2a829c3..481f913d0c 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -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 @@ -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' @@ -1790,7 +1865,7 @@ cd - return if /mswin|mingw/ =~ RUBY_PLATFORM mkdir 'tmpdatadir' - chmod 0o700, 'tmpdatadir' + chmod 0o000, 'tmpdatadir' rm_rf 'tmpdatadir' assert_file_not_exist 'tmpdatadir' |