aboutsummaryrefslogtreecommitdiffstats
path: root/test/fileutils/test_fileutils.rb
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-01-01 07:22:04 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-01-01 07:22:04 +0000
commit0a4a9dbaea37782ffe47210b26f2462f42ebff16 (patch)
treee8a708359dfa538585295c003d37eb0cc1beea52 /test/fileutils/test_fileutils.rb
parent41257b6d93728a6fa4ab5a4bf17e7ad20da1d880 (diff)
downloadruby-0a4a9dbaea37782ffe47210b26f2462f42ebff16.tar.gz
* lib/fileutils.rb (copy_stream): use read/write instead of sysread/syswrite, which allows duck typing. [ruby-dev:25369]
* lib/fileutils.rb (copy_stream): does NOT support nonblocking IO. [ruby-dev:25370] * test/fileutils/test_fileutils.rb: test copy_entry, copy_file, copy_stream. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7699 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/fileutils/test_fileutils.rb')
-rw-r--r--test/fileutils/test_fileutils.rb147
1 files changed, 113 insertions, 34 deletions
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb
index a34da88421..18944e913e 100644
--- a/test/fileutils/test_fileutils.rb
+++ b/test/fileutils/test_fileutils.rb
@@ -141,6 +141,16 @@ class TestFileUtils
File.utime t-4, t-4, 'data/newer'
end
+ def each_sample_file
+ TARGETS.each do |srcpath|
+ yield srcpath, "tmp/#{File.basename(srcpath)}"
+ end
+ end
+
+ #
+ # Test Cases
+ #
+
def test_pwd
assert_equal Dir.pwd, pwd()
@@ -176,24 +186,19 @@ end
end
def test_cp
- TARGETS.each do |fname|
- cp fname, 'tmp/cp'
- assert_same_file fname, 'tmp/cp'
+ each_sample_file do |srcpath, destpath|
+ cp srcpath, destpath
+ assert_same_file srcpath, destpath
- cp fname, 'tmp'
- assert_same_file fname, 'tmp/' + File.basename(fname)
+ cp srcpath, File.dirname(destpath)
+ assert_same_file srcpath, destpath
- cp fname, 'tmp/'
- assert_same_file fname, 'tmp/' + File.basename(fname)
+ cp srcpath, File.dirname(destpath) + '/'
+ assert_same_file srcpath, destpath
- cp fname, 'tmp/preserve', :preserve => true
- assert_same_file fname, 'tmp/preserve'
- a = File.stat(fname)
- b = File.stat('tmp/preserve')
- assert_equal a.mode, b.mode
- assert_equal a.mtime, b.mtime
- assert_equal a.uid, b.uid
- assert_equal a.gid, b.gid
+ cp srcpath, destpath, :preserve => true
+ assert_same_file srcpath, destpath
+ assert_same_entry srcpath, destpath
end
# src==dest (1) same path
@@ -673,25 +678,6 @@ end
}
end
- def test_uptodate?
- Dir.chdir('data') {
- assert( uptodate?('newest', %w(old newer notexist)) )
- assert( ! uptodate?('newer', %w(old newest notexist)) )
- assert( ! uptodate?('notexist', %w(old newest newer)) )
- }
-
- # pathname
- touch 'tmp/a'
- touch 'tmp/b'
- touch 'tmp/c'
- assert_nothing_raised {
- uptodate? Pathname.new('tmp/a'), ['tmp/b', 'tmp/c']
- uptodate? 'tmp/a', [Pathname.new('tmp/b'), 'tmp/c']
- uptodate? 'tmp/a', ['tmp/b', Pathname.new('tmp/c')]
- uptodate? Pathname.new('tmp/a'), [Pathname.new('tmp/b'), Pathname.new('tmp/c')]
- }
- end
-
def test_install
File.open('tmp/aaa', 'w') {|f| f.puts 'aaa' }
File.open('tmp/bbb', 'w') {|f| f.puts 'bbb' }
@@ -761,4 +747,97 @@ end
# FIXME
end
+ def test_copy_entry
+ each_sample_file do |srcpath, destpath|
+ copy_entry srcpath, destpath
+ assert_same_file srcpath, destpath
+ assert_same_entry srcpath, destpath
+ end
+if have_symlink?
+ File.symlink 'somewhere', 'tmp/symsrc'
+ copy_entry 'tmp/symsrc', 'tmp/symdest'
+ assert_equal File.lstat('tmp/symsrc').mode, File.lstat('tmp/symdest').mode
+end
+ end
+
+ def test_copy_file
+ each_sample_file do |srcpath, destpath|
+ copy_file srcpath, destpath
+ assert_same_file srcpath, destpath
+ end
+ end
+
+ def test_copy_stream
+ # IO
+ each_sample_file do |srcpath, destpath|
+ File.open(srcpath) {|src|
+ File.open(destpath, 'w') {|dest|
+ copy_stream src, dest
+ }
+ }
+ assert_same_file srcpath, destpath
+ end
+
+ # duck typing test [ruby-dev:25369]
+ rm_rf 'tmp'
+ Dir.mkdir 'tmp'
+ each_sample_file do |srcpath, destpath|
+ File.open(srcpath) {|src|
+ File.open(destpath, 'w') {|dest|
+ copy_stream Stream.new(src), Stream.new(dest)
+ }
+ }
+ assert_same_file srcpath, destpath
+ end
+ end
+
+ def test_remove_file
+ # FIXME
+ end
+
+ def test_remove_dir
+ # FIXME
+ end
+
+ def test_compare_file
+ # FIXME
+ end
+
+ def test_compare_stream
+ # FIXME
+ end
+
+ class Stream
+ def initialize(f)
+ @f = f
+ end
+
+ def read(n)
+ @f.read(n)
+ end
+
+ def write(str)
+ @f.write str
+ end
+ end
+
+ def test_uptodate?
+ Dir.chdir('data') {
+ assert( uptodate?('newest', %w(old newer notexist)) )
+ assert( ! uptodate?('newer', %w(old newest notexist)) )
+ assert( ! uptodate?('notexist', %w(old newest newer)) )
+ }
+
+ # pathname
+ touch 'tmp/a'
+ touch 'tmp/b'
+ touch 'tmp/c'
+ assert_nothing_raised {
+ uptodate? Pathname.new('tmp/a'), ['tmp/b', 'tmp/c']
+ uptodate? 'tmp/a', [Pathname.new('tmp/b'), 'tmp/c']
+ uptodate? 'tmp/a', ['tmp/b', Pathname.new('tmp/c')]
+ uptodate? Pathname.new('tmp/a'), [Pathname.new('tmp/b'), Pathname.new('tmp/c')]
+ }
+ end
+
end