summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-27 06:48:08 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-27 06:48:08 +0000
commit5b0f4afc7190d5c27fed0f09dc12c86c094ea360 (patch)
tree9b1abc063115b4cc3cc6ffef688ab8ee5b6fa1b6
parent004db1285a8883a17598cb4cce5489aa8f92863e (diff)
* test/fileutils/fileasserts.rb: sync with HEAD.
* test/fileutils/test_fileutils.rb: ditto. * test/fileutils/test_nowrite.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7665 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--test/fileutils/fileasserts.rb39
-rw-r--r--test/fileutils/test_fileutils.rb141
-rw-r--r--test/fileutils/test_nowrite.rb11
4 files changed, 170 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index 214c91ed62..06a317bbc4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Mon Dec 27 15:47:48 2004 Minero Aoki <aamine@loveruby.net>
+
+ * test/fileutils/fileasserts.rb: sync with HEAD.
+
+ * test/fileutils/test_fileutils.rb: ditto.
+
+ * test/fileutils/test_nowrite.rb: ditto.
+
Mon Dec 27 15:21:07 2004 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb (mv): should raise error when moving a
diff --git a/test/fileutils/fileasserts.rb b/test/fileutils/fileasserts.rb
index 2a96351bc2..ea03534545 100644
--- a/test/fileutils/fileasserts.rb
+++ b/test/fileutils/fileasserts.rb
@@ -1,12 +1,10 @@
-#
-# test/fileutils/fileasserts.rb
-#
+# $Id$
module Test
module Unit
module Assertions # redefine
- def assert_same_file( from, to )
+ def assert_same_file(from, to)
_wrap_assertion {
assert_block("file #{from} != #{to}") {
File.read(from) == File.read(to)
@@ -14,7 +12,22 @@ module Test
}
end
- def assert_file_exist( path )
+ def assert_same_entry(from, to)
+ _wrap_assertion {
+ assert_block("entry #{from} != #{to}") {
+ a = File.stat(from)
+ b = File.stat(to)
+
+ a.mode == b.mode and
+ #a.atime == b.atime and
+ a.mtime == b.mtime and
+ a.uid == b.uid and
+ a.gid == b.gid
+ }
+ }
+ end
+
+ def assert_file_exist(path)
_wrap_assertion {
assert_block("file not exist: #{path}") {
File.exist?(path)
@@ -22,7 +35,7 @@ module Test
}
end
- def assert_file_not_exist( path )
+ def assert_file_not_exist(path)
_wrap_assertion {
assert_block("file not exist: #{path}") {
not File.exist?(path)
@@ -30,7 +43,7 @@ module Test
}
end
- def assert_directory( path )
+ def assert_directory(path)
_wrap_assertion {
assert_block("is not directory: #{path}") {
File.directory?(path)
@@ -38,14 +51,22 @@ module Test
}
end
- def assert_symlink( path )
+ def assert_symlink(path)
_wrap_assertion {
- assert_block("is no symlink: #{path}") {
+ assert_block("is not a symlink: #{path}") {
File.symlink?(path)
}
}
end
+ def assert_not_symlink(path)
+ _wrap_assertion {
+ assert_block("is a symlink: #{path}") {
+ not File.symlink?(path)
+ }
+ }
+ end
+
end
end
end
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb
index 8c06f875b2..8e64b55030 100644
--- a/test/fileutils/test_fileutils.rb
+++ b/test/fileutils/test_fileutils.rb
@@ -1,8 +1,4 @@
-#
-# test/fileutils/test_fileutils.rb
-#
-
-$:.unshift File.dirname(__FILE__)
+# $Id$
require 'fileutils'
require 'fileasserts'
@@ -20,7 +16,7 @@ Dir.mkdir tmproot unless File.directory?(tmproot)
Dir.chdir tmproot
def have_drive_letter?
- /djgpp|mswin(?!ce)|mingw|bcc|emx/ === RUBY_PLATFORM
+ /djgpp|mswin(?!ce)|mingw|bcc|emx/ =~ RUBY_PLATFORM
end
def have_file_perm?
@@ -53,6 +49,18 @@ def have_hardlink?
HAVE_HARDLINK
end
+begin
+ Dir.mkdir("\n")
+ Dir.rmdir("\n")
+ def lf_in_path_allowed?
+ true
+ end
+rescue
+ def lf_in_path_allowed?
+ false
+ end
+end
+
Dir.chdir prevdir
Dir.rmdir tmproot
@@ -60,7 +68,7 @@ class TestFileUtils
include FileUtils
- def my_rm_rf( path )
+ def my_rm_rf(path)
if File.exist?('/bin/rm')
system %Q[/bin/rm -rf "#{path}"]
else
@@ -70,7 +78,7 @@ class TestFileUtils
def setup
@prevdir = Dir.pwd
- tmproot = "#{Dir.tmpdir}/fileutils.rb.#{$$}"
+ tmproot = TMPROOT
Dir.mkdir tmproot unless File.directory?(tmproot)
Dir.chdir tmproot
my_rm_rf 'data'; Dir.mkdir 'data'
@@ -86,13 +94,12 @@ class TestFileUtils
end
- TARGETS = %w( data/same data/all data/random data/zero )
+ TARGETS = %w( data/a data/all data/random data/zero )
def prepare_data_file
- same_chars = 'a' * 50
- File.open('data/same', 'w') {|f|
+ File.open('data/a', 'w') {|f|
32.times do
- f.puts same_chars
+ f.puts 'a' * 50
end
}
@@ -226,6 +233,44 @@ end
assert_same_file fname, "tmp/#{fname}"
end
+ cp_r 'data', 'tmp2', :preserve => true
+ TARGETS.each do |fname|
+ assert_same_entry fname, "tmp2/#{File.basename(fname)}"
+ assert_same_file fname, "tmp2/#{File.basename(fname)}"
+ end
+
+ # a/* -> b/*
+ mkdir 'tmp/cpr_src'
+ mkdir 'tmp/cpr_dest'
+ File.open('tmp/cpr_src/a', 'w') {|f| f.puts 'a' }
+ File.open('tmp/cpr_src/b', 'w') {|f| f.puts 'b' }
+ File.open('tmp/cpr_src/c', 'w') {|f| f.puts 'c' }
+ mkdir 'tmp/cpr_src/d'
+ cp_r 'tmp/cpr_src/.', 'tmp/cpr_dest'
+ assert_same_file 'tmp/cpr_src/a', 'tmp/cpr_dest/a'
+ assert_same_file 'tmp/cpr_src/b', 'tmp/cpr_dest/b'
+ assert_same_file 'tmp/cpr_src/c', 'tmp/cpr_dest/c'
+ assert_directory 'tmp/cpr_dest/d'
+ rm_rf 'tmp/cpr_src'
+ rm_rf 'tmp/cpr_dest'
+
+if have_symlink?
+ # symlink in a directory
+ mkdir 'tmp/cpr_src'
+ ln_s 'SLdest', 'tmp/cpr_src/symlink'
+ cp_r 'tmp/cpr_src', 'tmp/cpr_dest'
+ assert_symlink 'tmp/cpr_dest/symlink'
+ assert_equal 'SLdest', File.readlink('tmp/cpr_dest/symlink')
+
+ # root is a symlink
+ ln_s 'cpr_src', 'tmp/cpr_src2'
+ cp_r 'tmp/cpr_src2', 'tmp/cpr_dest2'
+ assert_directory 'tmp/cpr_dest2'
+ assert_not_symlink 'tmp/cpr_dest2'
+ assert_symlink 'tmp/cpr_dest2/symlink'
+ assert_equal 'SLdest', File.readlink('tmp/cpr_dest2/symlink')
+end
+
# pathname
touch 'tmp/cprtmp'
assert_nothing_raised {
@@ -249,6 +294,17 @@ end
assert_same_file fname, 'tmp/mvdest'
end
+ # [ruby-talk:124368]
+ mkdir 'tmp/tmpdir'
+ mkdir_p 'tmp/dest2/tmpdir'
+ assert_raises(Errno::EISDIR) {
+ mv 'tmp/tmpdir', 'tmp/dest2'
+ }
+ mkdir 'tmp/dest2/tmpdir/junk'
+ assert_raises(Errno::EISDIR) {
+ mv 'tmp/tmpdir', 'tmp/dest2'
+ }
+
# src==dest (1) same path
touch 'tmp/cptmp'
assert_raises(ArgumentError) {
@@ -323,6 +379,14 @@ end
# rm_f 'tmpdatadir'
Dir.rmdir 'tmpdatadir'
+ Dir.mkdir 'tmp/tmpdir'
+ File.open('tmp/tmpdir/a', 'w') {|f| f.puts 'dummy' }
+ File.open('tmp/tmpdir/c', 'w') {|f| f.puts 'dummy' }
+ rm_f ['tmp/tmpdir/a', 'tmp/tmpdir/b', 'tmp/tmpdir/c']
+ assert_file_not_exist 'tmp/tmpdir/a'
+ assert_file_not_exist 'tmp/tmpdir/c'
+ Dir.rmdir 'tmp/tmpdir'
+
# pathname
touch 'tmp/rmtmp1'
touch 'tmp/rmtmp2'
@@ -367,6 +431,23 @@ end
assert_file_not_exist 'tmp/tmpdir'
assert_file_exist 'tmp'
+ Dir.mkdir 'tmp/tmpdir'
+ File.open('tmp/tmpdir/a', 'w') {|f| f.puts 'dummy' }
+ File.open('tmp/tmpdir/c', 'w') {|f| f.puts 'dummy' }
+ rm_r ['tmp/tmpdir/a', 'tmp/tmpdir/b', 'tmp/tmpdir/c'], :force => true
+ assert_file_not_exist 'tmp/tmpdir/a'
+ assert_file_not_exist 'tmp/tmpdir/c'
+ Dir.rmdir 'tmp/tmpdir'
+
+if have_symlink?
+ # [ruby-talk:94635] a symlink to the directory
+ Dir.mkdir 'tmp/tmpdir'
+ File.symlink '..', 'tmp/tmpdir/symlink_to_dir'
+ rm_r 'tmp/tmpdir'
+ assert_file_not_exist 'tmp/tmpdir'
+ assert_file_exist 'tmp'
+end
+
# pathname
Dir.mkdir 'tmp/tmpdir1'; touch 'tmp/tmpdir1/tmp'
Dir.mkdir 'tmp/tmpdir2'; touch 'tmp/tmpdir2/tmp'
@@ -509,6 +590,19 @@ end
assert_equal 0700, (File.stat('tmp/tmp').mode & 0777) if have_file_perm?
Dir.rmdir 'tmp/tmp'
+if have_file_perm?
+ mkdir 'tmp/tmp', :mode => 07777
+ assert_directory 'tmp/tmp'
+ assert_equal 07777, (File.stat('tmp/tmp').mode & 07777)
+ Dir.rmdir 'tmp/tmp'
+end
+
+if lf_in_path_allowed?
+ mkdir "tmp-first-line\ntmp-second-line"
+ assert_directory "tmp-first-line\ntmp-second-line"
+ Dir.rmdir "tmp-first-line\ntmp-second-line"
+end
+
# pathname
assert_nothing_raised {
mkdir Pathname.new('tmp/tmpdirtmp')
@@ -557,6 +651,22 @@ end
assert_equal 0700, (File.stat('tmp/tmp/tmp').mode & 0777) if have_file_perm?
rm_rf 'tmp/tmp'
+ mkdir_p 'tmp/tmp', :mode => 0
+ assert_directory 'tmp/tmp'
+ assert_equal 0, (File.stat('tmp/tmp').mode & 0777) if have_file_perm?
+ # DO NOT USE rm_rf here.
+ # (rm(1) try to chdir to parent directory, it fails to remove directory.)
+ Dir.rmdir 'tmp/tmp'
+ Dir.rmdir 'tmp'
+
+if have_file_perm?
+ mkdir_p 'tmp/tmp/tmp', :mode => 07777
+ assert_directory 'tmp/tmp/tmp'
+ assert_equal 07777, (File.stat('tmp/tmp/tmp').mode & 07777)
+ Dir.rmdir 'tmp/tmp/tmp'
+ Dir.rmdir 'tmp/tmp'
+end
+
# pathname
assert_nothing_raised {
mkdir_p Pathname.new('tmp/tmp/tmp')
@@ -639,4 +749,11 @@ end
}
end
+ def test_chmod
+ # FIXME
+ end
+
+ #def test_chown # 1.8 does not have chown
+ #def test_chown_R # 1.8 does not have chown_R
+
end
diff --git a/test/fileutils/test_nowrite.rb b/test/fileutils/test_nowrite.rb
index 18c00b8e08..2189f5f8da 100644
--- a/test/fileutils/test_nowrite.rb
+++ b/test/fileutils/test_nowrite.rb
@@ -1,20 +1,15 @@
-#
-# test/fileutils/test_nowrite.rb
-#
-
-$:.unshift File.dirname(__FILE__)
+# $Id$
require 'fileutils'
require 'fileasserts'
require 'tmpdir'
require 'test/unit'
-
class TestNoWrite < Test::Unit::TestCase
include FileUtils::NoWrite
- def my_rm_rf( path )
+ def my_rm_rf(path)
if File.exist?('/bin/rm')
system %Q[/bin/rm -rf "#{path}"]
else
@@ -52,7 +47,7 @@ class TestNoWrite < Test::Unit::TestCase
check 'tmp/mv'
end
- def check( dest )
+ def check(dest)
assert_file_not_exist dest
assert_file_exist SRC
assert_same_file SRC, COPY