diff options
Diffstat (limited to 'test/fileutils')
-rw-r--r-- | test/fileutils/fileasserts.rb | 26 | ||||
-rw-r--r-- | test/fileutils/test_fileutils.rb | 82 |
2 files changed, 92 insertions, 16 deletions
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 |