summaryrefslogtreecommitdiff
path: root/test/pathname
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-30 12:50:55 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-30 12:50:55 +0000
commite94e674d0e8a8ab7641717c2d2ba4b5aac5c7295 (patch)
tree2d743938a5b84a0a802fc32d5f55176d66fdde83 /test/pathname
parent7a4a31064a59eba104d7204a320220a6cdbddf60 (diff)
* lib/pathname.rb (Pathname#realdirpath): new method.
[ruby-dev:36290] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/pathname')
-rw-r--r--test/pathname/test_pathname.rb47
1 files changed, 41 insertions, 6 deletions
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index 2b0d8a6..d979ff7 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -278,24 +278,37 @@ class TestPathname < Test::Unit::TestCase
}
end
- def realpath(path)
- Pathname.new(path).realpath.to_s
- end
-
- def test_realpath
+ def has_symlink?
begin
File.symlink(nil, nil)
rescue NotImplementedError
- return
+ return false
rescue TypeError
end
+ return true
+ end
+
+ def realpath(path)
+ Pathname.new(path).realpath.to_s
+ end
+
+ def test_realpath
+ return if !has_symlink?
with_tmpchdir('rubytest-pathname') {|dir|
+ assert_raise(Errno::ENOENT) { realpath("#{dir}/not-exist") }
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("../#{File.basename(dir)}/./not-exist-target", "#{dir}/not-exist2")
+ assert_raise(Errno::ENOENT) { realpath("#{dir}/not-exist2") }
+
+ File.open("#{dir}/exist-target", "w") {}
+ File.symlink("../#{File.basename(dir)}/./exist-target", "#{dir}/exist2")
+ assert_nothing_raised { realpath("#{dir}/exist2") }
+
File.symlink("loop-relative", "loop-relative")
assert_raise(Errno::ELOOP) { realpath("#{dir}/loop-relative") }
@@ -332,6 +345,28 @@ class TestPathname < Test::Unit::TestCase
}
end
+ def realdirpath(path)
+ Pathname.new(path).realdirpath.to_s
+ end
+
+ def test_realdirpath
+ return if !has_symlink?
+ Dir.mktmpdir('rubytest-pathname') {|dir|
+ rdir = realpath(dir)
+ assert_equal("#{rdir}/not-exist", realdirpath("#{dir}/not-exist"))
+ assert_raise(Errno::ENOENT) { realdirpath("#{dir}/not-exist/not-exist-child") }
+ File.symlink("not-exist-target", "#{dir}/not-exist")
+ assert_equal("#{rdir}/not-exist-target", realdirpath("#{dir}/not-exist"))
+ File.symlink("../#{File.basename(dir)}/./not-exist-target", "#{dir}/not-exist2")
+ assert_equal("#{rdir}/not-exist-target", realdirpath("#{dir}/not-exist2"))
+ File.open("#{dir}/exist-target", "w") {}
+ File.symlink("../#{File.basename(dir)}/./exist-target", "#{dir}/exist")
+ assert_equal("#{rdir}/exist-target", realdirpath("#{dir}/exist"))
+ File.symlink("loop", "#{dir}/loop")
+ assert_raise(Errno::ELOOP) { realdirpath("#{dir}/loop") }
+ }
+ end
+
def descend(path)
Pathname.new(path).enum_for(:descend).map {|v| v.to_s }
end