diff options
| author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-29 18:02:25 +0000 |
|---|---|---|
| committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-29 18:02:25 +0000 |
| commit | 27deaf183f122a22d617d331126756ad02328764 (patch) | |
| tree | df3f67989429142186fca7d4387fb7cc3cf76aa2 /test | |
| parent | 6506e90db655873d4a51ca6cb365b980ac53e982 (diff) | |
| download | ruby-27deaf183f122a22d617d331126756ad02328764.tar.gz ruby-27deaf183f122a22d617d331126756ad02328764.tar.xz ruby-27deaf183f122a22d617d331126756ad02328764.zip | |
add tests.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@21885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
| -rw-r--r-- | test/pathname/test_pathname.rb | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb index da12383bd..2b0d8a6a9 100644 --- a/test/pathname/test_pathname.rb +++ b/test/pathname/test_pathname.rb @@ -269,6 +269,15 @@ class TestPathname < Test::Unit::TestCase 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 @@ class TestPathname < Test::Unit::TestCase 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 |
