mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/ruby/test_file_exhaustive.rb: test UTF-8 filename. see [Bug #12340]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d0fbdb005c
commit
42ebe37b88
1 changed files with 215 additions and 86 deletions
|
@ -60,6 +60,13 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
@file
|
||||
end
|
||||
|
||||
def utf8_file
|
||||
return @utf8file if defined? @utf8file
|
||||
@utf8file = make_tmp_filename("\u3066\u3059\u3068")
|
||||
make_file("foo", @utf8file)
|
||||
@utf8file
|
||||
end
|
||||
|
||||
def notownedfile
|
||||
return @notownedfile if defined? @notownedfile
|
||||
if Process.euid != 0
|
||||
|
@ -168,15 +175,15 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_path
|
||||
file = regular_file
|
||||
|
||||
assert_equal(file, File.open(file) {|f| f.path})
|
||||
assert_equal(file, File.path(file))
|
||||
o = Object.new
|
||||
class << o; self; end.class_eval do
|
||||
define_method(:to_path) { file }
|
||||
[regular_file, utf8_file].each do |file|
|
||||
assert_equal(file, File.open(file) {|f| f.path})
|
||||
assert_equal(file, File.path(file))
|
||||
o = Object.new
|
||||
class << o; self; end.class_eval do
|
||||
define_method(:to_path) { file }
|
||||
end
|
||||
assert_equal(file, File.path(o))
|
||||
end
|
||||
assert_equal(file, File.path(o))
|
||||
end
|
||||
|
||||
def assert_integer(n)
|
||||
|
@ -269,12 +276,14 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
assert_file.directory?(@dir)
|
||||
assert_file.not_directory?(@dir+"/...")
|
||||
assert_file.not_directory?(regular_file)
|
||||
assert_file.not_directory?(utf8_file)
|
||||
assert_file.not_directory?(nofile)
|
||||
end
|
||||
|
||||
def test_pipe_p
|
||||
assert_file.not_pipe?(@dir)
|
||||
assert_file.not_pipe?(regular_file)
|
||||
assert_file.not_pipe?(utf8_file)
|
||||
assert_file.not_pipe?(nofile)
|
||||
assert_file.pipe?(fifo) if fifo
|
||||
end
|
||||
|
@ -282,6 +291,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
def test_symlink_p
|
||||
assert_file.not_symlink?(@dir)
|
||||
assert_file.not_symlink?(regular_file)
|
||||
assert_file.not_symlink?(utf8_file)
|
||||
assert_file.symlink?(symlinkfile) if symlinkfile
|
||||
assert_file.not_symlink?(hardlinkfile) if hardlinkfile
|
||||
assert_file.not_symlink?(nofile)
|
||||
|
@ -290,6 +300,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
def test_socket_p
|
||||
assert_file.not_socket?(@dir)
|
||||
assert_file.not_socket?(regular_file)
|
||||
assert_file.not_socket?(utf8_file)
|
||||
assert_file.not_socket?(nofile)
|
||||
assert_file.socket?(socket) if socket
|
||||
end
|
||||
|
@ -297,6 +308,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
def test_blockdev_p
|
||||
assert_file.not_blockdev?(@dir)
|
||||
assert_file.not_blockdev?(regular_file)
|
||||
assert_file.not_blockdev?(utf8_file)
|
||||
assert_file.not_blockdev?(nofile)
|
||||
assert_file.blockdev?(blockdev) if blockdev
|
||||
end
|
||||
|
@ -304,6 +316,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
def test_chardev_p
|
||||
assert_file.not_chardev?(@dir)
|
||||
assert_file.not_chardev?(regular_file)
|
||||
assert_file.not_chardev?(utf8_file)
|
||||
assert_file.not_chardev?(nofile)
|
||||
assert_file.chardev?(chardev) if chardev
|
||||
end
|
||||
|
@ -311,6 +324,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
def test_exist_p
|
||||
assert_file.exist?(@dir)
|
||||
assert_file.exist?(regular_file)
|
||||
assert_file.exist?(utf8_file)
|
||||
assert_file.not_exist?(nofile)
|
||||
end
|
||||
|
||||
|
@ -320,6 +334,12 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
assert_file.not_readable?(regular_file)
|
||||
File.chmod(0600, regular_file)
|
||||
assert_file.readable?(regular_file)
|
||||
|
||||
File.chmod(0200, utf8_file)
|
||||
assert_file.not_readable?(utf8_file)
|
||||
File.chmod(0600, utf8_file)
|
||||
assert_file.readable?(utf8_file)
|
||||
|
||||
assert_file.not_readable?(nofile)
|
||||
end if POSIX
|
||||
|
||||
|
@ -329,6 +349,12 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
assert_file.not_readable_real?(regular_file)
|
||||
File.chmod(0600, regular_file)
|
||||
assert_file.readable_real?(regular_file)
|
||||
|
||||
File.chmod(0200, utf8_file)
|
||||
assert_file.not_readable_real?(utf8_file)
|
||||
File.chmod(0600, utf8_file)
|
||||
assert_file.readable_real?(utf8_file)
|
||||
|
||||
assert_file.not_readable_real?(nofile)
|
||||
end if POSIX
|
||||
|
||||
|
@ -339,6 +365,14 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
assert_file.not_world_readable?(regular_file)
|
||||
File.chmod(0600, regular_file)
|
||||
assert_file.not_world_readable?(regular_file)
|
||||
|
||||
File.chmod(0006, utf8_file)
|
||||
assert_file.world_readable?(utf8_file)
|
||||
File.chmod(0060, utf8_file)
|
||||
assert_file.not_world_readable?(utf8_file)
|
||||
File.chmod(0600, utf8_file)
|
||||
assert_file.not_world_readable?(utf8_file)
|
||||
|
||||
assert_file.not_world_readable?(nofile)
|
||||
end if POSIX
|
||||
|
||||
|
@ -348,6 +382,12 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
assert_file.not_writable?(regular_file)
|
||||
File.chmod(0600, regular_file)
|
||||
assert_file.writable?(regular_file)
|
||||
|
||||
File.chmod(0400, utf8_file)
|
||||
assert_file.not_writable?(utf8_file)
|
||||
File.chmod(0600, utf8_file)
|
||||
assert_file.writable?(utf8_file)
|
||||
|
||||
assert_file.not_writable?(nofile)
|
||||
end if POSIX
|
||||
|
||||
|
@ -357,6 +397,12 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
assert_file.not_writable_real?(regular_file)
|
||||
File.chmod(0600, regular_file)
|
||||
assert_file.writable_real?(regular_file)
|
||||
|
||||
File.chmod(0400, utf8_file)
|
||||
assert_file.not_writable_real?(utf8_file)
|
||||
File.chmod(0600, utf8_file)
|
||||
assert_file.writable_real?(utf8_file)
|
||||
|
||||
assert_file.not_writable_real?(nofile)
|
||||
end if POSIX
|
||||
|
||||
|
@ -367,6 +413,14 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
assert_file.not_world_writable?(regular_file)
|
||||
File.chmod(0600, regular_file)
|
||||
assert_file.not_world_writable?(regular_file)
|
||||
|
||||
File.chmod(0006, utf8_file)
|
||||
assert_file.world_writable?(utf8_file)
|
||||
File.chmod(0060, utf8_file)
|
||||
assert_file.not_world_writable?(utf8_file)
|
||||
File.chmod(0600, utf8_file)
|
||||
assert_file.not_world_writable?(utf8_file)
|
||||
|
||||
assert_file.not_world_writable?(nofile)
|
||||
end if POSIX
|
||||
|
||||
|
@ -375,6 +429,12 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
assert_file.executable?(regular_file)
|
||||
File.chmod(0600, regular_file)
|
||||
assert_file.not_executable?(regular_file)
|
||||
|
||||
File.chmod(0100, utf8_file)
|
||||
assert_file.executable?(utf8_file)
|
||||
File.chmod(0600, utf8_file)
|
||||
assert_file.not_executable?(utf8_file)
|
||||
|
||||
assert_file.not_executable?(nofile)
|
||||
end if POSIX
|
||||
|
||||
|
@ -383,18 +443,26 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
assert_file.executable_real?(regular_file)
|
||||
File.chmod(0600, regular_file)
|
||||
assert_file.not_executable_real?(regular_file)
|
||||
|
||||
File.chmod(0100, utf8_file)
|
||||
assert_file.executable_real?(utf8_file)
|
||||
File.chmod(0600, utf8_file)
|
||||
assert_file.not_executable_real?(utf8_file)
|
||||
|
||||
assert_file.not_executable_real?(nofile)
|
||||
end if POSIX
|
||||
|
||||
def test_file_p
|
||||
assert_file.not_file?(@dir)
|
||||
assert_file.file?(regular_file)
|
||||
assert_file.file?(utf8_file)
|
||||
assert_file.not_file?(nofile)
|
||||
end
|
||||
|
||||
def test_zero_p
|
||||
assert_nothing_raised { File.zero?(@dir) }
|
||||
assert_file.not_zero?(regular_file)
|
||||
assert_file.not_zero?(utf8_file)
|
||||
assert_file.zero?(zerofile)
|
||||
assert_file.not_zero?(nofile)
|
||||
end
|
||||
|
@ -402,6 +470,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
def test_empty_p
|
||||
assert_nothing_raised { File.empty?(@dir) }
|
||||
assert_file.not_empty?(regular_file)
|
||||
assert_file.not_empty?(utf8_file)
|
||||
assert_file.empty?(zerofile)
|
||||
assert_file.not_empty?(nofile)
|
||||
end
|
||||
|
@ -409,31 +478,37 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
def test_size_p
|
||||
assert_nothing_raised { File.size?(@dir) }
|
||||
assert_equal(3, File.size?(regular_file))
|
||||
assert_equal(3, File.size?(utf8_file))
|
||||
assert_file.not_size?(zerofile)
|
||||
assert_file.not_size?(nofile)
|
||||
end
|
||||
|
||||
def test_owned_p
|
||||
assert_file.owned?(regular_file)
|
||||
assert_file.owned?(utf8_file)
|
||||
assert_file.not_owned?(notownedfile) if notownedfile
|
||||
end if POSIX
|
||||
|
||||
def test_grpowned_p ## xxx
|
||||
assert_file.grpowned?(regular_file)
|
||||
assert_file.grpowned?(utf8_file)
|
||||
end if POSIX
|
||||
|
||||
def test_suid
|
||||
assert_file.not_setuid?(regular_file)
|
||||
assert_file.not_setuid?(utf8_file)
|
||||
assert_file.setuid?(suidfile) if suidfile
|
||||
end
|
||||
|
||||
def test_sgid
|
||||
assert_file.not_setgid?(regular_file)
|
||||
assert_file.not_setgid?(utf8_file)
|
||||
assert_file.setgid?(sgidfile) if sgidfile
|
||||
end
|
||||
|
||||
def test_sticky
|
||||
assert_file.not_sticky?(regular_file)
|
||||
assert_file.not_sticky?(utf8_file)
|
||||
assert_file.sticky?(stickyfile) if stickyfile
|
||||
end
|
||||
|
||||
|
@ -444,26 +519,40 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
assert_file.not_identical?(nofile, regular_file)
|
||||
end
|
||||
|
||||
def path_identical_p(file)
|
||||
[regular_file, utf8_file].each do |file|
|
||||
assert_file.identical?(file, file)
|
||||
assert_file.not_identical?(file, zerofile)
|
||||
assert_file.not_identical?(file, nofile)
|
||||
assert_file.not_identical?(nofile, file)
|
||||
end
|
||||
end
|
||||
|
||||
def test_io_identical_p
|
||||
open(regular_file) {|f|
|
||||
assert_file.identical?(f, f)
|
||||
assert_file.identical?(regular_file, f)
|
||||
assert_file.identical?(f, regular_file)
|
||||
}
|
||||
[regular_file, utf8_file].each do |file|
|
||||
open(file) {|f|
|
||||
assert_file.identical?(f, f)
|
||||
assert_file.identical?(file, f)
|
||||
assert_file.identical?(f, file)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_closed_io_identical_p
|
||||
io = open(regular_file) {|f| f}
|
||||
assert_raise(IOError) {
|
||||
File.identical?(regular_file, io)
|
||||
}
|
||||
File.unlink(regular_file)
|
||||
assert_file.not_exist?(regular_file)
|
||||
[regular_file, utf8_file].each do |file|
|
||||
io = open(file) {|f| f}
|
||||
assert_raise(IOError) {
|
||||
File.identical?(file, io)
|
||||
}
|
||||
File.unlink(file)
|
||||
assert_file.not_exist?(file)
|
||||
end
|
||||
end
|
||||
|
||||
def test_s_size
|
||||
assert_integer(File.size(@dir))
|
||||
assert_equal(3, File.size(regular_file))
|
||||
assert_equal(3, File.size(utf8_file))
|
||||
assert_equal(0, File.size(zerofile))
|
||||
assert_raise(Errno::ENOENT) { File.size(nofile) }
|
||||
end
|
||||
|
@ -471,51 +560,62 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
def test_ftype
|
||||
assert_equal("directory", File.ftype(@dir))
|
||||
assert_equal("file", File.ftype(regular_file))
|
||||
assert_equal("file", File.ftype(utf8_file))
|
||||
assert_equal("link", File.ftype(symlinkfile)) if symlinkfile
|
||||
assert_equal("file", File.ftype(hardlinkfile)) if hardlinkfile
|
||||
assert_raise(Errno::ENOENT) { File.ftype(nofile) }
|
||||
end
|
||||
|
||||
def test_atime
|
||||
t1 = File.atime(regular_file)
|
||||
t2 = File.open(regular_file) {|f| f.atime}
|
||||
assert_kind_of(Time, t1)
|
||||
assert_kind_of(Time, t2)
|
||||
assert_equal(t1, t2)
|
||||
[regular_file, utf8_file].each do |file|
|
||||
t1 = File.atime(file)
|
||||
t2 = File.open(file) {|f| f.atime}
|
||||
assert_kind_of(Time, t1)
|
||||
assert_kind_of(Time, t2)
|
||||
assert_equal(t1, t2)
|
||||
end
|
||||
assert_raise(Errno::ENOENT) { File.atime(nofile) }
|
||||
end
|
||||
|
||||
def test_mtime
|
||||
t1 = File.mtime(regular_file)
|
||||
t2 = File.open(regular_file) {|f| f.mtime}
|
||||
assert_kind_of(Time, t1)
|
||||
assert_kind_of(Time, t2)
|
||||
assert_equal(t1, t2)
|
||||
[regular_file, utf8_file].each do |file|
|
||||
t1 = File.mtime(file)
|
||||
t2 = File.open(file) {|f| f.mtime}
|
||||
assert_kind_of(Time, t1)
|
||||
assert_kind_of(Time, t2)
|
||||
assert_equal(t1, t2)
|
||||
end
|
||||
assert_raise(Errno::ENOENT) { File.mtime(nofile) }
|
||||
end
|
||||
|
||||
def test_ctime
|
||||
t1 = File.ctime(regular_file)
|
||||
t2 = File.open(regular_file) {|f| f.ctime}
|
||||
assert_kind_of(Time, t1)
|
||||
assert_kind_of(Time, t2)
|
||||
assert_equal(t1, t2)
|
||||
[regular_file, utf8_file].each do |file|
|
||||
t1 = File.ctime(file)
|
||||
t2 = File.open(file) {|f| f.ctime}
|
||||
assert_kind_of(Time, t1)
|
||||
assert_kind_of(Time, t2)
|
||||
assert_equal(t1, t2)
|
||||
end
|
||||
assert_raise(Errno::ENOENT) { File.ctime(nofile) }
|
||||
end
|
||||
|
||||
def test_chmod
|
||||
assert_equal(1, File.chmod(0444, regular_file))
|
||||
assert_equal(0444, File.stat(regular_file).mode % 01000)
|
||||
assert_equal(0, File.open(regular_file) {|f| f.chmod(0222)})
|
||||
assert_equal(0222, File.stat(regular_file).mode % 01000)
|
||||
File.chmod(0600, regular_file)
|
||||
[regular_file, utf8_file].each do |file|
|
||||
assert_equal(1, File.chmod(0444, file))
|
||||
assert_equal(0444, File.stat(file).mode % 01000)
|
||||
assert_equal(0, File.open(file) {|f| f.chmod(0222)})
|
||||
assert_equal(0222, File.stat(file).mode % 01000)
|
||||
File.chmod(0600, file)
|
||||
end
|
||||
assert_raise(Errno::ENOENT) { File.chmod(0600, nofile) }
|
||||
end if POSIX
|
||||
|
||||
def test_lchmod
|
||||
assert_equal(1, File.lchmod(0444, regular_file))
|
||||
assert_equal(0444, File.stat(regular_file).mode % 01000)
|
||||
File.lchmod(0600, regular_file)
|
||||
[regular_file, utf8_file].each do |file|
|
||||
assert_equal(1, File.lchmod(0444, file))
|
||||
assert_equal(0444, File.stat(file).mode % 01000)
|
||||
File.lchmod(0600, regular_file)
|
||||
end
|
||||
assert_raise(Errno::ENOENT) { File.lchmod(0600, nofile) }
|
||||
rescue NotImplementedError
|
||||
end if POSIX
|
||||
|
@ -530,6 +630,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
return unless symlinkfile
|
||||
assert_equal("link", File.ftype(symlinkfile))
|
||||
assert_raise(Errno::EEXIST) { File.symlink(regular_file, regular_file) }
|
||||
assert_raise(Errno::EEXIST) { File.symlink(utf8_file, utf8_file) }
|
||||
end
|
||||
|
||||
def test_utime
|
||||
|
@ -543,12 +644,14 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
return unless hardlinkfile
|
||||
assert_equal("file", File.ftype(hardlinkfile))
|
||||
assert_raise(Errno::EEXIST) { File.link(regular_file, regular_file) }
|
||||
assert_raise(Errno::EEXIST) { File.link(utf8_file, utf8_file) }
|
||||
end
|
||||
|
||||
def test_readlink
|
||||
return unless symlinkfile
|
||||
assert_equal(regular_file, File.readlink(symlinkfile))
|
||||
assert_raise(Errno::EINVAL) { File.readlink(regular_file) }
|
||||
assert_raise(Errno::EINVAL) { File.readlink(utf8_file) }
|
||||
assert_raise(Errno::ENOENT) { File.readlink(nofile) }
|
||||
if fs = Encoding.find("filesystem")
|
||||
assert_equal(fs, File.readlink(symlinkfile).encoding)
|
||||
|
@ -595,15 +698,21 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
def test_unlink
|
||||
assert_equal(1, File.unlink(regular_file))
|
||||
make_file("foo", regular_file)
|
||||
|
||||
assert_equal(1, File.unlink(utf8_file))
|
||||
make_file("foo", utf8_file)
|
||||
|
||||
assert_raise(Errno::ENOENT) { File.unlink(nofile) }
|
||||
end
|
||||
|
||||
def test_rename
|
||||
assert_equal(0, File.rename(regular_file, nofile))
|
||||
assert_file.not_exist?(regular_file)
|
||||
assert_file.exist?(nofile)
|
||||
assert_equal(0, File.rename(nofile, regular_file))
|
||||
assert_raise(Errno::ENOENT) { File.rename(nofile, regular_file) }
|
||||
[regular_file, utf8_file].each do |file|
|
||||
assert_equal(0, File.rename(file, nofile))
|
||||
assert_file.not_exist?(file)
|
||||
assert_file.exist?(nofile)
|
||||
assert_equal(0, File.rename(nofile, file))
|
||||
assert_raise(Errno::ENOENT) { File.rename(nofile, file) }
|
||||
end
|
||||
end
|
||||
|
||||
def test_umask
|
||||
|
@ -618,10 +727,13 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
|
||||
def test_expand_path
|
||||
assert_equal(regular_file, File.expand_path(File.basename(regular_file), File.dirname(regular_file)))
|
||||
assert_equal(utf8_file, File.expand_path(File.basename(utf8_file), File.dirname(utf8_file)))
|
||||
if NTFS
|
||||
assert_equal(regular_file, File.expand_path(regular_file + " "))
|
||||
assert_equal(regular_file, File.expand_path(regular_file + "."))
|
||||
assert_equal(regular_file, File.expand_path(regular_file + "::$DATA"))
|
||||
[regular_file, utf8_file].each do |file|
|
||||
assert_equal(file, File.expand_path(file + " "))
|
||||
assert_equal(file, File.expand_path(file + "."))
|
||||
assert_equal(file, File.expand_path(file + "::$DATA"))
|
||||
end
|
||||
assert_match(/\Ac:\//i, File.expand_path('c:'), '[ruby-core:31591]')
|
||||
assert_match(/\Ac:\//i, File.expand_path('c:foo', 'd:/bar'))
|
||||
assert_match(/\Ae:\//i, File.expand_path('e:foo', 'd:/bar'))
|
||||
|
@ -983,6 +1095,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
|
||||
def test_basename
|
||||
assert_equal(File.basename(regular_file).sub(/\.test$/, ""), File.basename(regular_file, ".test"))
|
||||
assert_equal(File.basename(utf8_file).sub(/\.test$/, ""), File.basename(utf8_file, ".test"))
|
||||
assert_equal("", s = File.basename(""))
|
||||
assert_not_predicate(s, :frozen?, '[ruby-core:24199]')
|
||||
assert_equal("foo", s = File.basename("foo"))
|
||||
|
@ -991,17 +1104,19 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
assert_equal("foo", File.basename("foo.ext", ".ext"))
|
||||
assert_equal("foo", File.basename("foo.ext", ".*"))
|
||||
if NTFS
|
||||
basename = File.basename(regular_file)
|
||||
assert_equal(basename, File.basename(regular_file + " "))
|
||||
assert_equal(basename, File.basename(regular_file + "."))
|
||||
assert_equal(basename, File.basename(regular_file + "::$DATA"))
|
||||
basename.chomp!(".test")
|
||||
assert_equal(basename, File.basename(regular_file + " ", ".test"))
|
||||
assert_equal(basename, File.basename(regular_file + ".", ".test"))
|
||||
assert_equal(basename, File.basename(regular_file + "::$DATA", ".test"))
|
||||
assert_equal(basename, File.basename(regular_file + " ", ".*"))
|
||||
assert_equal(basename, File.basename(regular_file + ".", ".*"))
|
||||
assert_equal(basename, File.basename(regular_file + "::$DATA", ".*"))
|
||||
[regular_file, utf8_file].each do |file|
|
||||
basename = File.basename(file)
|
||||
assert_equal(basename, File.basename(file + " "))
|
||||
assert_equal(basename, File.basename(file + "."))
|
||||
assert_equal(basename, File.basename(file + "::$DATA"))
|
||||
basename.chomp!(".test")
|
||||
assert_equal(basename, File.basename(file + " ", ".test"))
|
||||
assert_equal(basename, File.basename(file + ".", ".test"))
|
||||
assert_equal(basename, File.basename(file + "::$DATA", ".test"))
|
||||
assert_equal(basename, File.basename(file + " ", ".*"))
|
||||
assert_equal(basename, File.basename(file + ".", ".*"))
|
||||
assert_equal(basename, File.basename(file + "::$DATA", ".*"))
|
||||
end
|
||||
end
|
||||
if File::ALT_SEPARATOR == '\\'
|
||||
a = "foo/\225\\\\"
|
||||
|
@ -1023,6 +1138,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
|
||||
def test_dirname
|
||||
assert_equal(@dir, File.dirname(regular_file))
|
||||
assert_equal(@dir, File.dirname(utf8_file))
|
||||
assert_equal(".", File.dirname(""))
|
||||
assert_incompatible_encoding {|d| File.dirname(d)}
|
||||
if File::ALT_SEPARATOR == '\\'
|
||||
|
@ -1035,6 +1151,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
|
||||
def test_extname
|
||||
assert_equal(".test", File.extname(regular_file))
|
||||
assert_equal(".test", File.extname(utf8_file))
|
||||
prefixes = ["", "/", ".", "/.", "bar/.", "/bar/."]
|
||||
infixes = ["", " ", "."]
|
||||
infixes2 = infixes + [".ext "]
|
||||
|
@ -1061,9 +1178,11 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_split
|
||||
d, b = File.split(regular_file)
|
||||
assert_equal(File.dirname(regular_file), d)
|
||||
assert_equal(File.basename(regular_file), b)
|
||||
[regular_file, utf8_file].each do |file|
|
||||
d, b = File.split(file)
|
||||
assert_equal(File.dirname(file), d)
|
||||
assert_equal(File.basename(file), b)
|
||||
end
|
||||
end
|
||||
|
||||
def test_join
|
||||
|
@ -1106,26 +1225,28 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_truncate
|
||||
assert_equal(0, File.truncate(regular_file, 1))
|
||||
assert_file.exist?(regular_file)
|
||||
assert_equal(1, File.size(regular_file))
|
||||
assert_equal(0, File.truncate(regular_file, 0))
|
||||
assert_file.exist?(regular_file)
|
||||
assert_file.zero?(regular_file)
|
||||
make_file("foo", regular_file)
|
||||
assert_raise(Errno::ENOENT) { File.truncate(nofile, 0) }
|
||||
[regular_file, utf8_file].each do |file|
|
||||
assert_equal(0, File.truncate(file, 1))
|
||||
assert_file.exist?(file)
|
||||
assert_equal(1, File.size(file))
|
||||
assert_equal(0, File.truncate(file, 0))
|
||||
assert_file.exist?(file)
|
||||
assert_file.zero?(file)
|
||||
make_file("foo", file)
|
||||
assert_raise(Errno::ENOENT) { File.truncate(nofile, 0) }
|
||||
|
||||
f = File.new(regular_file, "w")
|
||||
assert_equal(0, f.truncate(2))
|
||||
assert_file.exist?(regular_file)
|
||||
assert_equal(2, File.size(regular_file))
|
||||
assert_equal(0, f.truncate(0))
|
||||
assert_file.exist?(regular_file)
|
||||
assert_file.zero?(regular_file)
|
||||
f.close
|
||||
make_file("foo", regular_file)
|
||||
f = File.new(file, "w")
|
||||
assert_equal(0, f.truncate(2))
|
||||
assert_file.exist?(file)
|
||||
assert_equal(2, File.size(file))
|
||||
assert_equal(0, f.truncate(0))
|
||||
assert_file.exist?(file)
|
||||
assert_file.zero?(file)
|
||||
f.close
|
||||
make_file("foo", file)
|
||||
|
||||
assert_raise(IOError) { File.open(regular_file) {|ff| ff.truncate(0)} }
|
||||
assert_raise(IOError) { File.open(file) {|ff| ff.truncate(0)} }
|
||||
end
|
||||
rescue NotImplementedError
|
||||
end
|
||||
|
||||
|
@ -1245,6 +1366,12 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_stat_new_utf8
|
||||
assert_nothing_raised do
|
||||
File::Stat.new(utf8_file)
|
||||
end
|
||||
end
|
||||
|
||||
def test_stat_ftype
|
||||
assert_equal("directory", File::Stat.new(@dir).ftype)
|
||||
assert_equal("file", File::Stat.new(regular_file).ftype)
|
||||
|
@ -1417,10 +1544,12 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_size
|
||||
assert_equal(3, File.open(regular_file) {|f| f.size })
|
||||
File.open(regular_file, "a") do |f|
|
||||
f.write("bar")
|
||||
assert_equal(6, f.size)
|
||||
[regular_file, utf8_file].each do |file|
|
||||
assert_equal(3, File.open(file) {|f| f.size })
|
||||
File.open(file, "a") do |f|
|
||||
f.write("bar")
|
||||
assert_equal(6, f.size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue