aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/pathname/test_pathname.rb6
-rw-r--r--test/ruby/test_file.rb20
2 files changed, 24 insertions, 2 deletions
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index a9f7149633..5dfd9c6e31 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -288,8 +288,8 @@ class TestPathname < Test::Unit::TestCase
return true
end
- def realpath(path)
- Pathname.new(path).realpath.to_s
+ def realpath(path, basedir=nil)
+ Pathname.new(path).realpath(basedir).to_s
end
def test_realpath
@@ -301,6 +301,7 @@ class TestPathname < Test::Unit::TestCase
File.symlink("loop", "#{dir}/loop")
assert_raise(Errno::ELOOP) { realpath("#{dir}/loop") }
+ assert_raise(Errno::ELOOP) { realpath("#{dir}/loop", dir) }
File.symlink("../#{File.basename(dir)}/./not-exist-target", "#{dir}/not-exist2")
assert_raise(Errno::ENOENT) { realpath("#{dir}/not-exist2") }
@@ -314,6 +315,7 @@ class TestPathname < Test::Unit::TestCase
Dir.mkdir("exist")
assert_equal("#{dir}/exist", realpath("exist"))
+ assert_raise(Errno::ELOOP) { realpath("../loop", "#{dir}/exist") }
File.symlink("loop1/loop1", "loop1")
assert_raise(Errno::ELOOP) { realpath("#{dir}/loop1") }
diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb
index b8ba9a4b19..90f2ec1f53 100644
--- a/test/ruby/test_file.rb
+++ b/test/ruby/test_file.rb
@@ -157,4 +157,24 @@ class TestFile < Test::Unit::TestCase
assert_raise(TypeError) { File::Stat.allocate.readable? }
assert_nothing_raised { File::Stat.allocate.inspect }
end
+
+ def test_realpath
+ Dir.mktmpdir('rubytest-realpath') {|tmpdir|
+ realdir = File.realpath(tmpdir)
+ tst = realdir.sub(/#{Regexp.escape(File::SEPARATOR)}/, '\0\0\0')
+ assert_equal(realdir, File.realpath(tst))
+ assert_equal(realdir, File.realpath(".", tst))
+ }
+ end
+
+ def test_realdirpath
+ Dir.mktmpdir('rubytest-realdirpath') {|tmpdir|
+ realdir = File.realpath(tmpdir)
+ tst = realdir.sub(/#{Regexp.escape(File::SEPARATOR)}/, '\0\0\0')
+ assert_equal(realdir, File.realdirpath(tst))
+ assert_equal(realdir, File.realdirpath(".", tst))
+ assert_equal(File.join(realdir, "foo"), File.realdirpath("foo", tst))
+ }
+ end
+
end