* test/fileutils/test_fileutils.rb: clear all errors on Windows.
* test/fileutils/test_nowrite.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
11150ba747
commit
0be9d09430
@ -1,3 +1,9 @@
|
|||||||
|
Sat Sep 27 09:44:18 2003 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
|
* test/fileutils/test_fileutils.rb: clear all errors on Windows.
|
||||||
|
|
||||||
|
* test/fileutils/test_nowrite.rb: ditto.
|
||||||
|
|
||||||
Mon Sep 27 04:57:07 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
Mon Sep 27 04:57:07 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
||||||
|
|
||||||
* test/ruby/test_file.rb: new file. only asserts unlink-before-close
|
* test/ruby/test_file.rb: new file. only asserts unlink-before-close
|
||||||
|
@ -9,6 +9,22 @@ require 'test/unit'
|
|||||||
require 'fileasserts'
|
require 'fileasserts'
|
||||||
|
|
||||||
|
|
||||||
|
def windows?
|
||||||
|
/mswin|mingw|bcc|djgpp/ === RUBY_PLATFORM
|
||||||
|
end
|
||||||
|
|
||||||
|
def have_symlink?
|
||||||
|
begin
|
||||||
|
File.symlink 'not_exist', 'not_exist_2'
|
||||||
|
rescue NotImplementedError
|
||||||
|
return false
|
||||||
|
rescue
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
true # never reach
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
class TestFileUtils < Test::Unit::TestCase
|
class TestFileUtils < Test::Unit::TestCase
|
||||||
|
|
||||||
include FileUtils
|
include FileUtils
|
||||||
@ -17,7 +33,7 @@ class TestFileUtils < Test::Unit::TestCase
|
|||||||
if File.exist?('/bin/rm')
|
if File.exist?('/bin/rm')
|
||||||
system "/bin/rm -rf #{path}"
|
system "/bin/rm -rf #{path}"
|
||||||
else
|
else
|
||||||
rm_rf path # use FileUtils.
|
FileUtils.rm_rf path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -85,10 +101,19 @@ class TestFileUtils < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_pwd
|
def test_pwd
|
||||||
assert_equal Dir.pwd, pwd()
|
assert_equal Dir.pwd, pwd()
|
||||||
|
|
||||||
|
cwd = Dir.pwd
|
||||||
|
if windows?
|
||||||
|
cd('C:/') {
|
||||||
|
assert_equal 'C:/', pwd()
|
||||||
|
}
|
||||||
|
assert_equal cwd, pwd()
|
||||||
|
else
|
||||||
cd('/') {
|
cd('/') {
|
||||||
assert_equal '/', pwd()
|
assert_equal '/', pwd()
|
||||||
}
|
}
|
||||||
assert_equal Dir.pwd, pwd()
|
assert_equal cwd, pwd()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cmp
|
def test_cmp
|
||||||
@ -149,11 +174,13 @@ class TestFileUtils < Test::Unit::TestCase
|
|||||||
assert_file_not_exist 'tmp/rmsrc'
|
assert_file_not_exist 'tmp/rmsrc'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if have_symlink?
|
||||||
File.open('tmp/lnf_symlink_src', 'w') {|f| f.puts 'dummy' }
|
File.open('tmp/lnf_symlink_src', 'w') {|f| f.puts 'dummy' }
|
||||||
File.symlink 'tmp/lnf_symlink_src', 'tmp/lnf_symlink_dest'
|
File.symlink 'tmp/lnf_symlink_src', 'tmp/lnf_symlink_dest'
|
||||||
rm_f 'tmp/lnf_symlink_dest'
|
rm_f 'tmp/lnf_symlink_dest'
|
||||||
assert_file_not_exist 'tmp/lnf_symlink_dest'
|
assert_file_not_exist 'tmp/lnf_symlink_dest'
|
||||||
assert_file_exist 'tmp/lnf_symlink_src'
|
assert_file_exist 'tmp/lnf_symlink_src'
|
||||||
|
end
|
||||||
|
|
||||||
rm_f 'notexistdatafile'
|
rm_f 'notexistdatafile'
|
||||||
rm_f 'tmp/notexistdatafile'
|
rm_f 'tmp/notexistdatafile'
|
||||||
@ -224,6 +251,7 @@ class TestFileUtils < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if have_symlink?
|
||||||
def test_ln_s
|
def test_ln_s
|
||||||
TARGETS.each do |fname|
|
TARGETS.each do |fname|
|
||||||
ln_s fname, 'tmp/lnsdest'
|
ln_s fname, 'tmp/lnsdest'
|
||||||
@ -232,7 +260,9 @@ class TestFileUtils < Test::Unit::TestCase
|
|||||||
rm_f 'tmp/lnsdest'
|
rm_f 'tmp/lnsdest'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if have_symlink?
|
||||||
def test_ln_sf
|
def test_ln_sf
|
||||||
TARGETS.each do |fname|
|
TARGETS.each do |fname|
|
||||||
ln_sf fname, 'tmp/lnsdest'
|
ln_sf fname, 'tmp/lnsdest'
|
||||||
@ -242,6 +272,7 @@ class TestFileUtils < Test::Unit::TestCase
|
|||||||
ln_sf fname, 'tmp/lnsdest'
|
ln_sf fname, 'tmp/lnsdest'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_mkdir
|
def test_mkdir
|
||||||
my_rm_rf 'tmpdatadir'
|
my_rm_rf 'tmpdatadir'
|
||||||
@ -255,7 +286,7 @@ class TestFileUtils < Test::Unit::TestCase
|
|||||||
|
|
||||||
mkdir 'tmp/tmp', :mode => 0700
|
mkdir 'tmp/tmp', :mode => 0700
|
||||||
assert_is_directory 'tmp/tmp'
|
assert_is_directory 'tmp/tmp'
|
||||||
assert_equal 0700, (File.stat('tmp/tmp').mode & 0777)
|
assert_equal 0700, (File.stat('tmp/tmp').mode & 0777) unless windows?
|
||||||
Dir.rmdir 'tmp/tmp'
|
Dir.rmdir 'tmp/tmp'
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -291,8 +322,8 @@ class TestFileUtils < Test::Unit::TestCase
|
|||||||
mkdir_p 'tmp/tmp/tmp', :mode => 0700
|
mkdir_p 'tmp/tmp/tmp', :mode => 0700
|
||||||
assert_is_directory 'tmp/tmp'
|
assert_is_directory 'tmp/tmp'
|
||||||
assert_is_directory 'tmp/tmp/tmp'
|
assert_is_directory 'tmp/tmp/tmp'
|
||||||
assert_equal 0700, (File.stat('tmp/tmp').mode & 0777)
|
assert_equal 0700, (File.stat('tmp/tmp').mode & 0777) unless windows?
|
||||||
assert_equal 0700, (File.stat('tmp/tmp/tmp').mode & 0777)
|
assert_equal 0700, (File.stat('tmp/tmp/tmp').mode & 0777) unless windows?
|
||||||
rm_rf 'tmp/tmp'
|
rm_rf 'tmp/tmp'
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -312,12 +343,12 @@ class TestFileUtils < Test::Unit::TestCase
|
|||||||
File.open('tmp/bbb', 'w') {|f| f.puts 'bbb' }
|
File.open('tmp/bbb', 'w') {|f| f.puts 'bbb' }
|
||||||
install 'tmp/aaa', 'tmp/bbb', :mode => 0600
|
install 'tmp/aaa', 'tmp/bbb', :mode => 0600
|
||||||
assert_equal "aaa\n", File.read('tmp/bbb')
|
assert_equal "aaa\n", File.read('tmp/bbb')
|
||||||
assert_equal 0600, (File.stat('tmp/bbb').mode & 0777)
|
assert_equal 0600, (File.stat('tmp/bbb').mode & 0777) unless windows?
|
||||||
|
|
||||||
t = File.mtime('tmp/bbb')
|
t = File.mtime('tmp/bbb')
|
||||||
install 'tmp/aaa', 'tmp/bbb'
|
install 'tmp/aaa', 'tmp/bbb'
|
||||||
assert_equal "aaa\n", File.read('tmp/bbb')
|
assert_equal "aaa\n", File.read('tmp/bbb')
|
||||||
assert_equal 0600, (File.stat('tmp/bbb').mode & 0777)
|
assert_equal 0600, (File.stat('tmp/bbb').mode & 0777) unless windows?
|
||||||
assert_equal t, File.mtime('tmp/bbb')
|
assert_equal t, File.mtime('tmp/bbb')
|
||||||
|
|
||||||
File.unlink 'tmp/aaa'
|
File.unlink 'tmp/aaa'
|
||||||
@ -325,11 +356,3 @@ class TestFileUtils < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
__END__
|
|
||||||
#if $0 == __FILE__
|
|
||||||
# require 'test/unit/ui/console/testrunner'
|
|
||||||
#
|
|
||||||
# Test::Unit::UI::Consle::TestRunner.run(TestFileUtils.suite)
|
|
||||||
end
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
#
|
# test/fileutils/test_nowrite.rb
|
||||||
#
|
#
|
||||||
|
|
||||||
$:.unshift File.dirname(__FILE__)
|
$:.unshift File.dirname(__FILE__)
|
||||||
@ -13,18 +13,27 @@ class TestNoWrite < Test::Unit::TestCase
|
|||||||
|
|
||||||
include FileUtils::NoWrite
|
include FileUtils::NoWrite
|
||||||
|
|
||||||
|
def my_rm_rf( path )
|
||||||
|
if File.exist?('/bin/rm')
|
||||||
|
system "/bin/rm -rf #{path}"
|
||||||
|
else
|
||||||
|
FileUtils.rm_rf path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
SRC = 'data/src'
|
SRC = 'data/src'
|
||||||
COPY = 'data/copy'
|
COPY = 'data/copy'
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
system 'rm -rf data; mkdir data'
|
my_rm_rf 'date'; Dir.mkdir 'data'
|
||||||
system 'rm -rf tmp; mkdir tmp'
|
my_rm_rf 'tmp'; Dir.mkdir 'tmp'
|
||||||
File.open( SRC, 'w' ) {|f| f.puts 'dummy' }
|
File.open(SRC, 'w') {|f| f.puts 'dummy' }
|
||||||
File.open( COPY, 'w' ) {|f| f.puts 'dummy' }
|
File.open(COPY, 'w') {|f| f.puts 'dummy' }
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
system 'rm -rf data tmp'
|
my_rm_rf 'data'
|
||||||
|
my_rm_rf 'tmp'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cp
|
def test_cp
|
||||||
|
Loading…
x
Reference in New Issue
Block a user