[前][次][番号順一覧][スレッド一覧]

ruby-changes:42814

From: usa <ko1@a...>
Date: Mon, 2 May 2016 22:06:46 +0900 (JST)
Subject: [ruby-changes:42814] usa:r54887 (trunk): * test/ruby/test_file_exhaustive.rb: test UTF-8 filename. see [Bug #12340]

usa	2016-05-02 23:03:21 +0900 (Mon, 02 May 2016)

  New Revision: 54887

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54887

  Log:
    * test/ruby/test_file_exhaustive.rb: test UTF-8 filename.  see [Bug #12340]

  Modified files:
    trunk/test/ruby/test_file_exhaustive.rb
Index: test/ruby/test_file_exhaustive.rb
===================================================================
--- test/ruby/test_file_exhaustive.rb	(revision 54886)
+++ test/ruby/test_file_exhaustive.rb	(revision 54887)
@@ -60,6 +60,13 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L60
     @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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L175
   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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L276
     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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L291
   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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L300
   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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L308
   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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L316
   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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L324
   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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L334
     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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L349
     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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L365
     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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L382
     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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L397
     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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L413
     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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L429
     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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L443
     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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L470
   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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L478
   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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L519
     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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L560
   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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L630
     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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L644
     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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L698
   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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L727
 
   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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L1095
 
   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::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L1104
     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", ".*"))
+      e (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]