From 2bfd5c1a3d9e09f9332da5b57090ebec17f15c74 Mon Sep 17 00:00:00 2001 From: aamine Date: Tue, 18 Nov 2003 05:09:20 +0000 Subject: * lib/fileutils.rb (fu_each_src_dest): raise if src==dest. [ruby-talk:85344] [ruby-core:01699] * lib/fileutils.rb: use Object#is_a? instead of Class#=== to allow e.g. remote objects for receivers. * lib/fileutils.rb: FileTest -> File. * lib/fileutils.rb: put parentheses for arguments of File.xxxx? * test/fileutils/test_fileutils.rb (test_cp): test "cp a a". * test/fileutils/test_fileutils.rb (test_mv): test "mv a a". * test/fileutils/test_fileutils.rb (test_ln): test "ln a a". * test/fileutils/test_fileutils.rb (test_ln_s): test "ln_s a a". * test/fileutils/test_fileutils.rb (test_install): test "install a a". * test/fileutils/fileasserts.rb: new method assert_symlink. * test/fileutils/fileasserts.rb: assert_is_directory -> assert_directory. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/fileutils/fileasserts.rb | 26 ++++++++----- test/fileutils/test_fileutils.rb | 82 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 92 insertions(+), 16 deletions(-) (limited to 'test/fileutils') diff --git a/test/fileutils/fileasserts.rb b/test/fileutils/fileasserts.rb index 0b3d67bd30..2a96351bc2 100644 --- a/test/fileutils/fileasserts.rb +++ b/test/fileutils/fileasserts.rb @@ -14,26 +14,34 @@ module Test } end - def assert_file_exist( file ) + def assert_file_exist( path ) _wrap_assertion { - assert_block("file not exist: #{file}") { - File.exist?(file) + assert_block("file not exist: #{path}") { + File.exist?(path) } } end - def assert_file_not_exist( file ) + def assert_file_not_exist( path ) _wrap_assertion { - assert_block("file not exist: #{file}") { - not File.exist?(file) + assert_block("file not exist: #{path}") { + not File.exist?(path) } } end - def assert_is_directory( file ) + def assert_directory( path ) _wrap_assertion { - assert_block("is not directory: #{file}") { - File.directory?(file) + assert_block("is not directory: #{path}") { + File.directory?(path) + } + } + end + + def assert_symlink( path ) + _wrap_assertion { + assert_block("is no symlink: #{path}") { + File.symlink?(path) } } end diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index 0c81b65675..922c065919 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -142,6 +142,22 @@ end assert_equal a.uid, b.uid assert_equal a.gid, b.gid end + + # src==dest + touch 'tmp/cptmp' + assert_raises(ArgumentError) { + cp 'tmp/cptmp', 'tmp/cptmp' + } +if have_symlink? + File.symlink 'tmp/cptmp', 'tmp/cptmp_symlink' + assert_raises(ArgumentError) { + cp 'tmp/cptmp', 'tmp/cptmp_symlink' + } + File.symlink 'tmp/symlink', 'tmp/symlink' + assert_raises(Errno::ELOOP) { + cp 'tmp/symlink', 'tmp/symlink' + } +end end def test_cp_r @@ -157,6 +173,22 @@ end mv 'tmp/mvsrc', 'tmp/mvdest' assert_same_file fname, 'tmp/mvdest' end + + # src==dest + touch 'tmp/cptmp' + assert_raises(ArgumentError) { + mv 'tmp/cptmp', 'tmp/cptmp' + } +if have_symlink? + File.symlink 'tmp/cptmp', 'tmp/cptmp_symlink' + assert_raises(ArgumentError) { + mv 'tmp/cptmp', 'tmp/cptmp_symlink' + } + File.symlink 'tmp/symlink', 'tmp/symlink' + assert_raises(Errno::ELOOP) { + mv 'tmp/symlink', 'tmp/symlink' + } +end end def test_rm @@ -249,6 +281,22 @@ end TARGETS.each do |fname| File.unlink 'tmp/' + File.basename(fname) end + + # src==dest + touch 'tmp/cptmp' + assert_raises(Errno::EEXIST) { + ln 'tmp/cptmp', 'tmp/cptmp' + } +if have_symlink? + File.symlink 'tmp/cptmp', 'tmp/cptmp_symlink' + assert_raises(Errno::EEXIST) { + ln 'tmp/cptmp', 'tmp/cptmp_symlink' + } + File.symlink 'tmp/symlink', 'tmp/symlink' + assert_raises(Errno::EEXIST) { + ln 'tmp/symlink', 'tmp/symlink' + } +end end if have_symlink? @@ -259,6 +307,10 @@ if have_symlink? assert_equal fname, File.readlink('tmp/lnsdest') rm_f 'tmp/lnsdest' end + assert_nothing_raised { + ln_s 'tmp/symlink', 'tmp/symlink' + } + assert_symlink 'tmp/symlink' end end @@ -277,15 +329,15 @@ end def test_mkdir my_rm_rf 'tmpdatadir' mkdir 'tmpdatadir' - assert_is_directory 'tmpdatadir' + assert_directory 'tmpdatadir' Dir.rmdir 'tmpdatadir' mkdir 'tmp/mkdirdest' - assert_is_directory 'tmp/mkdirdest' + assert_directory 'tmp/mkdirdest' Dir.rmdir 'tmp/mkdirdest' mkdir 'tmp/tmp', :mode => 0700 - assert_is_directory 'tmp/tmp' + assert_directory 'tmp/tmp' assert_equal 0700, (File.stat('tmp/tmp').mode & 0777) unless windows? Dir.rmdir 'tmp/tmp' end @@ -307,7 +359,7 @@ end rm_rf 'tmpdir' dirs.each do |d| mkdir_p d - assert_is_directory d + assert_directory d assert_file_not_exist "#{d}/a" assert_file_not_exist "#{d}/b" assert_file_not_exist "#{d}/c" @@ -315,13 +367,13 @@ end end dirs.each do |d| mkdir_p d - assert_is_directory d + assert_directory d end rm_rf 'tmpdir' mkdir_p 'tmp/tmp/tmp', :mode => 0700 - assert_is_directory 'tmp/tmp' - assert_is_directory 'tmp/tmp/tmp' + assert_directory 'tmp/tmp' + assert_directory 'tmp/tmp/tmp' assert_equal 0700, (File.stat('tmp/tmp').mode & 0777) unless windows? assert_equal 0700, (File.stat('tmp/tmp/tmp').mode & 0777) unless windows? rm_rf 'tmp/tmp' @@ -353,6 +405,22 @@ end File.unlink 'tmp/aaa' File.unlink 'tmp/bbb' + + # src==dest + touch 'tmp/cptmp' + assert_raises(ArgumentError) { + install 'tmp/cptmp', 'tmp/cptmp' + } +if have_symlink? + File.symlink 'tmp/cptmp', 'tmp/cptmp_symlink' + assert_raises(ArgumentError) { + install 'tmp/cptmp', 'tmp/cptmp_symlink' + } + File.symlink 'tmp/symlink', 'tmp/symlink' + assert_raises(Errno::ELOOP) { + install 'tmp/symlink', 'tmp/symlink' + } +end end end -- cgit v1.2.3