summaryrefslogtreecommitdiff
path: root/test/pathname
diff options
context:
space:
mode:
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 2b0d8a6a99..d979ff7023 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