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

ruby-changes:10341

From: akr <ko1@a...>
Date: Fri, 30 Jan 2009 03:02:30 +0900 (JST)
Subject: [ruby-changes:10341] Ruby:r21885 (trunk): add tests.

akr	2009-01-30 03:02:25 +0900 (Fri, 30 Jan 2009)

  New Revision: 21885

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21885

  Log:
    add tests.

  Modified files:
    trunk/test/pathname/test_pathname.rb

Index: test/pathname/test_pathname.rb
===================================================================
--- test/pathname/test_pathname.rb	(revision 21884)
+++ test/pathname/test_pathname.rb	(revision 21885)
@@ -269,6 +269,15 @@
   defassert_raise(:relative_path_from, ArgumentError, "a", "..")
   defassert_raise(:relative_path_from, ArgumentError, ".", "..")
 
+  def with_tmpchdir(base=nil)
+    Dir.mktmpdir(base) {|d|
+      d = Pathname.new(d).realpath.to_s
+      Dir.chdir(d) {
+        yield d
+      }
+    }
+  end
+
   def realpath(path)
     Pathname.new(path).realpath.to_s
   end
@@ -280,11 +289,46 @@
       return
     rescue TypeError
     end
-    Dir.mktmpdir('rubytest-pathname') {|dir|
+    with_tmpchdir('rubytest-pathname') {|dir|
       File.symlink("not-exist-target", "#{dir}/not-exist")
       assert_raise(Errno::ENOENT) { realpath("#{dir}/not-exist") }
+
       File.symlink("loop", "#{dir}/loop")
       assert_raise(Errno::ELOOP) { realpath("#{dir}/loop") }
+
+      File.symlink("loop-relative", "loop-relative")
+      assert_raise(Errno::ELOOP) { realpath("#{dir}/loop-relative") }
+
+      Dir.mkdir("exist")
+      assert_equal("#{dir}/exist", realpath("exist"))
+
+      File.symlink("loop1/loop1", "loop1")
+      assert_raise(Errno::ELOOP) { realpath("#{dir}/loop1") }
+
+      File.symlink("loop2", "loop3")
+      File.symlink("loop3", "loop2")
+      assert_raise(Errno::ELOOP) { realpath("#{dir}/loop2") }
+
+      Dir.mkdir("b")
+
+      File.symlink("b", "c")
+      assert_equal("#{dir}/b", realpath("c"))
+      assert_equal("#{dir}/b", realpath("c/../c"))
+      assert_equal("#{dir}/b", realpath("c/../c/../c/."))
+
+      File.symlink("..", "b/d")
+      assert_equal("#{dir}/b", realpath("c/d/c/d/c"))
+
+      File.symlink("#{dir}/b", "e")
+      assert_equal("#{dir}/b", realpath("e"))
+
+      Dir.mkdir("f")
+      Dir.mkdir("f/g")
+      File.symlink("f/g", "h")
+      assert_equal("#{dir}/f/g", realpath("h"))
+      File.chmod(0000, "f")
+      assert_raise(Errno::EACCES) { realpath("h") }
+      File.chmod(0755, "f")
     }
   end
 

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

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